Revision 0224a49f pithos-macos/pithos_macosAppDelegate.m
b/pithos-macos/pithos_macosAppDelegate.m | ||
---|---|---|
38 | 38 |
#import "pithos_macosAppDelegate.h" |
39 | 39 |
#import "PithosBrowserController.h" |
40 | 40 |
#import "PithosPreferencesController.h" |
41 |
#import "PithosSyncDaemon.h" |
|
41 | 42 |
#import "ASIPithosRequest.h" |
42 | 43 |
#import "ASIDownloadCache.h" |
43 | 44 |
|
44 | 45 |
@implementation pithos_macosAppDelegate |
45 | 46 |
@synthesize storageURLPrefix, publicURLPrefix, loginURLPrefix, aboutURL; |
47 |
@synthesize syncDirectoryPath, syncContainerName, syncTimeInterval; |
|
46 | 48 |
|
47 | 49 |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { |
48 | 50 |
NSURL *testURL; |
49 |
storageURLPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"PithosStorageURLPrefix"];
|
|
51 |
storageURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosStorageURLPrefix"];
|
|
50 | 52 |
if (!storageURLPrefix) { |
51 | 53 |
storageURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/v1"]; |
52 | 54 |
} else { |
... | ... | |
56 | 58 |
} |
57 | 59 |
[storageURLPrefix retain]; |
58 | 60 |
|
59 |
publicURLPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"PithosPublicURLPrefix"];
|
|
61 |
publicURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosPublicURLPrefix"];
|
|
60 | 62 |
if (!publicURLPrefix) { |
61 | 63 |
publicURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr"]; |
62 | 64 |
} else { |
... | ... | |
66 | 68 |
} |
67 | 69 |
[publicURLPrefix retain]; |
68 | 70 |
|
69 |
loginURLPrefix = [[NSUserDefaults standardUserDefaults] stringForKey:@"PithosLoginURLPrefix"];
|
|
71 |
loginURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosLoginURLPrefix"];
|
|
70 | 72 |
if (!loginURLPrefix) { |
71 | 73 |
loginURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/login"]; |
72 | 74 |
} else { |
... | ... | |
76 | 78 |
} |
77 | 79 |
[loginURLPrefix retain]; |
78 | 80 |
|
79 |
aboutURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"PithosAboutURL"];
|
|
81 |
aboutURL = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosAboutURL"];
|
|
80 | 82 |
if (!aboutURL) { |
81 | 83 |
aboutURL = [NSString stringWithString:@"https://pithos.dev.grnet.gr/docs"]; |
82 | 84 |
} else { |
... | ... | |
86 | 88 |
} |
87 | 89 |
[aboutURL retain]; |
88 | 90 |
|
91 |
syncDirectoryPath = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncDirectoryPath"]; |
|
92 |
if (!syncDirectoryPath || ![syncDirectoryPath length]) { |
|
93 |
syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"]; |
|
94 |
} else { |
|
95 |
BOOL isDirectory; |
|
96 |
if ([[NSFileManager defaultManager] fileExistsAtPath:syncDirectoryPath isDirectory:&isDirectory] && !isDirectory) |
|
97 |
syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"]; |
|
98 |
} |
|
99 |
[syncDirectoryPath retain]; |
|
100 |
|
|
101 |
syncContainerName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncContainerName"]; |
|
102 |
if (!syncContainerName || ![syncContainerName length]) { |
|
103 |
syncContainerName = [NSString stringWithString:@"pithos"]; |
|
104 |
} |
|
105 |
[syncContainerName retain]; |
|
106 |
|
|
107 |
syncTimeInterval = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncTimeInterval"] doubleValue]; |
|
108 |
if (syncTimeInterval <= 0) { |
|
109 |
syncTimeInterval = 180.0; |
|
110 |
} |
|
111 |
|
|
89 | 112 |
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self |
90 | 113 |
andSelector:@selector(handleAppleEvent:withReplyEvent:) |
91 | 114 |
forEventClass:kInternetEventClass |
... | ... | |
185 | 208 |
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:self.aboutURL]]; |
186 | 209 |
} |
187 | 210 |
|
211 |
- (IBAction)syncNow:(id)sender { |
|
212 |
[pithosSyncDaemon sync]; |
|
213 |
} |
|
214 |
|
|
188 | 215 |
#pragma mark - |
189 | 216 |
#pragma Authentication |
190 | 217 |
|
191 | 218 |
- (void)authenticateWithAuthUser:(NSString *)authUser authToken:(NSString *)authToken { |
192 | 219 |
NSLog(@"Authentication - storageURLPrefix:%@, authUser:%@, authToken:%@", storageURLPrefix, authUser, authToken); |
193 |
if ([authUser length] && [authToken length]) { |
|
220 |
if ([authUser length] && [authToken length] && |
|
221 |
(![[ASIPithosRequest authUser] isEqualToString:authUser] || ![[ASIPithosRequest authToken] isEqualToString:authToken])) { |
|
194 | 222 |
[[ASIDownloadCache sharedCache] clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy]; |
195 | 223 |
[[ASIPithosRequest sharedQueue] cancelAllOperations]; |
224 |
|
|
196 | 225 |
[ASIPithosRequest setAuthURL:storageURLPrefix]; |
197 | 226 |
[ASIPithosRequest setStorageURLPrefix:storageURLPrefix]; |
198 | 227 |
[ASIPithosRequest setAuthUser:authUser]; |
199 | 228 |
[ASIPithosRequest setAuthToken:authToken]; |
200 | 229 |
[ASIPithosRequest setPublicURLPrefix:publicURLPrefix]; |
201 | 230 |
|
231 |
[self startSyncWithDirectoryPath:syncDirectoryPath containerName:syncContainerName]; |
|
232 |
|
|
202 | 233 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAuthenticationCredentialsUpdated" object:self]; |
203 | 234 |
} |
204 | 235 |
} |
205 | 236 |
|
237 |
- (void)startSyncWithDirectoryPath:(NSString *)directoryPath containerName:(NSString *)containerName { |
|
238 |
[pithosSyncDaemon release]; |
|
239 |
pithosSyncDaemon = [[PithosSyncDaemon alloc] initWithDirectoryPath:syncDirectoryPath |
|
240 |
containerName:syncContainerName |
|
241 |
timeInterval:syncTimeInterval]; |
|
242 |
} |
|
243 |
|
|
206 | 244 |
@end |
Also available in: Unified diff