-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppDelegate.m
More file actions
172 lines (139 loc) · 5.41 KB
/
AppDelegate.m
File metadata and controls
172 lines (139 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// AppDelegate.m
// Subler
//
// Created by Damiano Galassi on 29/01/09.
// Copyright 2009 Damiano Galassi. All rights reserved.
//
#import "AppDelegate.h"
#import "SBDocument.h"
#import "SBPresetManager.h"
#import "mp4v2.h"
#define DONATE_NAG_TIME (60 * 60 * 24 * 7)
void logCallback(MP4LogLevel loglevel, const char* fmt, va_list ap)
{
const char* level;
switch (loglevel) {
case 0:
level = "None";
break;
case 1:
level = "Error";
break;
case 2:
level = "Warning";
break;
case 3:
level = "Info";
break;
case 4:
level = "Verbose1";
break;
case 5:
level = "Verbose2";
break;
case 6:
level = "Verbose3";
break;
case 7:
level = "Verbose4";
break;
default:
level = "Unknown";
break;
}
printf("%s: ", level);
vprintf(fmt, ap);
printf("\n");
}
@implementation AppDelegate
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
documentController = [[SBDocumentController alloc] init];
MP4SetLogCallback(logCallback);
MP4LogSetLevel(MP4_LOG_ERROR);
}
- (void)applicationWillTerminate:(NSNotification *)notification {
SBPresetManager *presetManager = [SBPresetManager sharedManager];
[presetManager savePresets];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
BOOL firstLaunch = YES;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"FirstLaunch"])
firstLaunch = NO;
if (![[NSUserDefaults standardUserDefaults] valueForKey:@"warningDonate"]) {
NSDate * lastDonateDate = [[NSUserDefaults standardUserDefaults] valueForKey:@"DonateAskDate"];
const BOOL timePassed = !lastDonateDate || (-1 * [lastDonateDate timeIntervalSinceNow]) >= DONATE_NAG_TIME;
if (!firstLaunch && timePassed) {
[[NSUserDefaults standardUserDefaults] setValue:[NSDate date] forKey:@"DonateAskDate"];
NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText: NSLocalizedString(@"Support Subler", "Donation -> title")];
NSString * donateMessage = [NSString stringWithFormat: @"%@",
NSLocalizedString(@" A lot of time and effort have gone into development, coding, and refinement."
" If you enjoy using it, please consider showing your appreciation with a donation.", "Donation -> message")];
[alert setInformativeText:donateMessage];
[alert setAlertStyle: NSInformationalAlertStyle];
[alert addButtonWithTitle: NSLocalizedString(@"Donate", "Donation -> button")];
NSButton * noDonateButton = [alert addButtonWithTitle: NSLocalizedString(@"Nope", "Donation -> button")];
[noDonateButton setKeyEquivalent:@"\e"]; //escape key
const BOOL allowNeverAgain = lastDonateDate != nil; //hide the "don't show again" check the first time - give them time to try the app
[alert setShowsSuppressionButton:allowNeverAgain];
if (allowNeverAgain)
[[alert suppressionButton] setTitle:NSLocalizedString(@"Don't ask me about this ever again.", "Donation -> button")];
const NSInteger donateResult = [alert runModal];
if (donateResult == NSAlertFirstButtonReturn)
[self linkDonate:self];
if (allowNeverAgain)
[[NSUserDefaults standardUserDefaults] setBool:([[alert suppressionButton] state] != NSOnState) forKey:@"WarningDonate"];
[alert release];
}
}
if (firstLaunch)
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FirstLaunch"];
}
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
return NO;
}
- (void) showPrefsWindow: (id) sender;
{
if (!fPrefs) {
fPrefs = [[PrefsController alloc] init];
}
[fPrefs showWindow:self];
}
- (IBAction) donate:(id)sender
{
[self linkDonate:sender];
}
- (IBAction) help:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL
URLWithString:@"http://code.google.com/p/subler/wiki/Documentation"]];
}
- (void) linkDonate:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL
URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YKZHVC6HG6AFQ&lc=EN&item_name=Subler¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"]];
}
@end
@implementation SBDocumentController
- (id) init
{
return [super init];
}
- (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError {
SBDocument* doc = nil;
if ([[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mkv"] == NSOrderedSame ||
[[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mka"] == NSOrderedSame ||
[[[absoluteURL path] pathExtension] caseInsensitiveCompare: @"mov"] == NSOrderedSame) {
doc = [self openUntitledDocumentAndDisplay:YES error:nil];
[doc showImportSheet:[absoluteURL path]];
return doc;
}
else {
return [super openDocumentWithContentsOfURL:absoluteURL display:displayDocument error:outError];
}
}
@end