43 |
43 |
#import "ASIDownloadCache.h"
|
44 |
44 |
|
45 |
45 |
@implementation pithos_macosAppDelegate
|
46 |
|
@synthesize storageURLPrefix, publicURLPrefix, loginURLPrefix, aboutURL;
|
47 |
|
@synthesize syncContainerName, syncTimeInterval, pithosBrowserController, pithosSyncDaemon, alwaysNo;
|
|
46 |
@synthesize pithosBrowserController, pithosSyncDaemon, alwaysNo;
|
48 |
47 |
|
49 |
48 |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
|
49 |
userDefaults = [[NSUserDefaults standardUserDefaults] retain];
|
|
50 |
NSString *stringURL;
|
50 |
51 |
NSURL *testURL;
|
51 |
|
storageURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosStorageURLPrefix"];
|
52 |
|
if (!storageURLPrefix) {
|
53 |
|
storageURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/v1"];
|
54 |
|
} else {
|
55 |
|
testURL = [NSURL URLWithString:storageURLPrefix];
|
56 |
|
if (!testURL || !testURL.scheme || !testURL.host)
|
57 |
|
storageURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/v1"];
|
58 |
|
}
|
59 |
|
[storageURLPrefix retain];
|
60 |
|
|
61 |
|
publicURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosPublicURLPrefix"];
|
62 |
|
if (!publicURLPrefix) {
|
63 |
|
publicURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr"];
|
64 |
|
} else {
|
65 |
|
testURL = [NSURL URLWithString:publicURLPrefix];
|
66 |
|
if (!testURL || !testURL.scheme || !testURL.host)
|
67 |
|
publicURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr"];
|
68 |
|
}
|
69 |
|
[publicURLPrefix retain];
|
70 |
52 |
|
71 |
|
loginURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosLoginURLPrefix"];
|
72 |
|
if (!loginURLPrefix) {
|
73 |
|
loginURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/login"];
|
74 |
|
} else {
|
75 |
|
testURL = [NSURL URLWithString:loginURLPrefix];
|
76 |
|
if (!testURL || !testURL.scheme || !testURL.host)
|
77 |
|
loginURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/login"];
|
78 |
|
}
|
79 |
|
[loginURLPrefix retain];
|
80 |
|
|
81 |
|
aboutURL = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosAboutURL"];
|
82 |
|
if (!aboutURL) {
|
83 |
|
aboutURL = [NSString stringWithString:@"https://pithos.dev.grnet.gr/docs"];
|
84 |
|
} else {
|
85 |
|
testURL = [NSURL URLWithString:aboutURL];
|
86 |
|
if (!testURL || !testURL.scheme || !testURL.host)
|
87 |
|
aboutURL = [NSString stringWithString:@"https://pithos.dev.grnet.gr/docs"];
|
88 |
|
}
|
89 |
|
[aboutURL retain];
|
|
53 |
stringURL = [userDefaults stringForKey:@"storageURLPrefix"];
|
|
54 |
testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
|
|
55 |
if (!testURL || !testURL.scheme || !testURL.host)
|
|
56 |
[userDefaults setObject:@"https://plus.pithos.grnet.gr/v1" forKey:@"storageURLPrefix"];
|
|
57 |
|
|
58 |
stringURL = [userDefaults stringForKey:@"publicURLPrefix"];
|
|
59 |
testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
|
|
60 |
if (!testURL || !testURL.scheme || !testURL.host)
|
|
61 |
[userDefaults setObject:@"https://plus.pithos.grnet.gr" forKey:@"publicURLPrefix"];
|
|
62 |
|
|
63 |
stringURL = [userDefaults stringForKey:@"loginURLPrefix"];
|
|
64 |
testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
|
|
65 |
if (!testURL || !testURL.scheme || !testURL.host)
|
|
66 |
[userDefaults setObject:@"https://plus.pithos.grnet.gr/login" forKey:@"loginURLPrefix"];
|
|
67 |
|
|
68 |
stringURL = [userDefaults stringForKey:@"aboutURL"];
|
|
69 |
testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
|
|
70 |
if (!testURL || !testURL.scheme || !testURL.host)
|
|
71 |
[userDefaults setObject:@"https://pithos.dev.grnet.gr/docs" forKey:@"aboutURL"];
|
90 |
72 |
|
91 |
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
92 |
|
NSString *syncDirectoryPath = [userDefaults stringForKey:@"pithosSyncDirectoryPath"];
|
|
73 |
NSString *syncDirectoryPath = [userDefaults stringForKey:@"syncDirectoryPath"];
|
93 |
74 |
if (!syncDirectoryPath || ![syncDirectoryPath length]) {
|
94 |
75 |
syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"];
|
95 |
76 |
} else {
|
... | ... | |
102 |
83 |
syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"];
|
103 |
84 |
}
|
104 |
85 |
}
|
105 |
|
[userDefaults setObject:syncDirectoryPath forKey:@"pithosSyncDirectoryPath"];
|
106 |
|
[userDefaults synchronize];
|
|
86 |
[userDefaults setObject:syncDirectoryPath forKey:@"syncDirectoryPath"];
|
107 |
87 |
|
108 |
|
syncContainerName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncContainerName"];
|
109 |
|
if (!syncContainerName || ![syncContainerName length] || [syncContainerName isEqualToString:@"trash"]) {
|
110 |
|
syncContainerName = [NSString stringWithString:@"pithos"];
|
111 |
|
}
|
112 |
|
[syncContainerName retain];
|
|
88 |
NSString *syncContainerName = [userDefaults stringForKey:@"syncContainerName"];
|
|
89 |
if (!syncContainerName || ![syncContainerName length] || [syncContainerName isEqualToString:@"trash"])
|
|
90 |
[userDefaults setObject:@"pithos" forKey:@"syncContainerName"];
|
113 |
91 |
|
114 |
|
syncTimeInterval = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncTimeInterval"] doubleValue];
|
115 |
|
if (syncTimeInterval <= 0) {
|
116 |
|
syncTimeInterval = 180.0;
|
117 |
|
}
|
|
92 |
double syncTimeInterval = [userDefaults doubleForKey:@"syncTimeInteral"];
|
|
93 |
if (syncTimeInterval <= 0)
|
|
94 |
[userDefaults setDouble:180.0 forKey:@"syncTimeInteral"];
|
|
95 |
|
|
96 |
[userDefaults synchronize];
|
118 |
97 |
|
119 |
98 |
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
|
120 |
99 |
andSelector:@selector(handleAppleEvent:withReplyEvent:)
|
... | ... | |
187 |
166 |
|
188 |
167 |
NSLog(@"query authUser: '%@', authToken: '%@'", authUser, authToken);
|
189 |
168 |
if ([authUser length] && [authToken length]) {
|
190 |
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
191 |
169 |
[userDefaults setObject:authUser forKey:@"authUser"];
|
192 |
170 |
[userDefaults setObject:authToken forKey:@"authToken"];
|
193 |
171 |
[userDefaults synchronize];
|
... | ... | |
215 |
193 |
}
|
216 |
194 |
|
217 |
195 |
- (IBAction)aboutPithos:(id)sender {
|
218 |
|
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:self.aboutURL]];
|
|
196 |
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[userDefaults stringForKey:@"aboutURL"]]];
|
219 |
197 |
}
|
220 |
198 |
|
221 |
199 |
- (IBAction)syncNow:(id)sender {
|
... | ... | |
228 |
206 |
- (void)login {
|
229 |
207 |
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
230 |
208 |
NSString *loginURL = [NSString stringWithFormat:@"%@?next=pithos://%@_%d",
|
231 |
|
loginURLPrefix, [processInfo processName], [processInfo processIdentifier]];
|
|
209 |
[userDefaults stringForKey:@"loginURLPrefix"], [processInfo processName], [processInfo processIdentifier]];
|
232 |
210 |
NSLog(@"loginURL: %@", loginURL);
|
233 |
211 |
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:loginURL]];
|
234 |
212 |
}
|
235 |
213 |
|
236 |
214 |
- (void)authenticate {
|
237 |
|
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
238 |
215 |
NSString *authUser = [userDefaults stringForKey:@"authUser"];
|
239 |
216 |
NSString *authToken = [userDefaults stringForKey:@"authToken"];
|
240 |
|
NSString *syncDirectoryPath = [userDefaults stringForKey:@"pithosSyncDirectoryPath"];
|
|
217 |
NSString *storageURLPrefix = [userDefaults stringForKey:@"storageURLPrefix"];
|
|
218 |
NSString *publicURLPrefix = [userDefaults stringForKey:@"publicURLPrefix"];
|
|
219 |
NSString *syncDirectoryPath = [userDefaults stringForKey:@"syncDirectoryPath"];
|
|
220 |
NSString *syncContainerName = [userDefaults stringForKey:@"syncContainerName"];
|
|
221 |
double syncTimeInterval = [userDefaults doubleForKey:@"syncTimeInterval"];
|
241 |
222 |
NSLog(@"Authentication - storageURLPrefix:%@, authUser:%@, authToken:%@", storageURLPrefix, authUser, authToken);
|
242 |
223 |
if (([authUser length] == 0) || ([authToken length] == 0)) {
|
243 |
224 |
[self showPithosPreferences:self];
|