#import "ASIDownloadCache.h"
@implementation pithos_macosAppDelegate
-@synthesize storageURLPrefix, publicURLPrefix, loginURLPrefix, aboutURL;
-@synthesize syncContainerName, syncTimeInterval, pithosBrowserController, pithosSyncDaemon, alwaysNo;
+@synthesize pithosBrowserController, pithosSyncDaemon, alwaysNo;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+ userDefaults = [[NSUserDefaults standardUserDefaults] retain];
+ NSString *stringURL;
NSURL *testURL;
- storageURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosStorageURLPrefix"];
- if (!storageURLPrefix) {
- storageURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/v1"];
- } else {
- testURL = [NSURL URLWithString:storageURLPrefix];
- if (!testURL || !testURL.scheme || !testURL.host)
- storageURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/v1"];
- }
- [storageURLPrefix retain];
-
- publicURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosPublicURLPrefix"];
- if (!publicURLPrefix) {
- publicURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr"];
- } else {
- testURL = [NSURL URLWithString:publicURLPrefix];
- if (!testURL || !testURL.scheme || !testURL.host)
- publicURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr"];
- }
- [publicURLPrefix retain];
- loginURLPrefix = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosLoginURLPrefix"];
- if (!loginURLPrefix) {
- loginURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/login"];
- } else {
- testURL = [NSURL URLWithString:loginURLPrefix];
- if (!testURL || !testURL.scheme || !testURL.host)
- loginURLPrefix = [NSString stringWithString:@"https://pithos.dev.grnet.gr/login"];
- }
- [loginURLPrefix retain];
-
- aboutURL = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosAboutURL"];
- if (!aboutURL) {
- aboutURL = [NSString stringWithString:@"https://pithos.dev.grnet.gr/docs"];
- } else {
- testURL = [NSURL URLWithString:aboutURL];
- if (!testURL || !testURL.scheme || !testURL.host)
- aboutURL = [NSString stringWithString:@"https://pithos.dev.grnet.gr/docs"];
- }
- [aboutURL retain];
+ stringURL = [userDefaults stringForKey:@"storageURLPrefix"];
+ testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
+ if (!testURL || !testURL.scheme || !testURL.host)
+ [userDefaults setObject:@"https://plus.pithos.grnet.gr/v1" forKey:@"storageURLPrefix"];
+
+ stringURL = [userDefaults stringForKey:@"publicURLPrefix"];
+ testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
+ if (!testURL || !testURL.scheme || !testURL.host)
+ [userDefaults setObject:@"https://plus.pithos.grnet.gr" forKey:@"publicURLPrefix"];
+
+ stringURL = [userDefaults stringForKey:@"loginURLPrefix"];
+ testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
+ if (!testURL || !testURL.scheme || !testURL.host)
+ [userDefaults setObject:@"https://plus.pithos.grnet.gr/login" forKey:@"loginURLPrefix"];
+
+ stringURL = [userDefaults stringForKey:@"aboutURL"];
+ testURL = (stringURL) ? [NSURL URLWithString:stringURL] : nil;
+ if (!testURL || !testURL.scheme || !testURL.host)
+ [userDefaults setObject:@"https://pithos.dev.grnet.gr/docs" forKey:@"aboutURL"];
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
- NSString *syncDirectoryPath = [userDefaults stringForKey:@"pithosSyncDirectoryPath"];
+ NSString *syncDirectoryPath = [userDefaults stringForKey:@"syncDirectoryPath"];
if (!syncDirectoryPath || ![syncDirectoryPath length]) {
syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"];
} else {
syncDirectoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Pithos"];
}
}
- [userDefaults setObject:syncDirectoryPath forKey:@"pithosSyncDirectoryPath"];
- [userDefaults synchronize];
+ [userDefaults setObject:syncDirectoryPath forKey:@"syncDirectoryPath"];
- syncContainerName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncContainerName"];
- if (!syncContainerName || ![syncContainerName length] || [syncContainerName isEqualToString:@"trash"]) {
- syncContainerName = [NSString stringWithString:@"pithos"];
- }
- [syncContainerName retain];
+ NSString *syncContainerName = [userDefaults stringForKey:@"syncContainerName"];
+ if (!syncContainerName || ![syncContainerName length] || [syncContainerName isEqualToString:@"trash"])
+ [userDefaults setObject:@"pithos" forKey:@"syncContainerName"];
- syncTimeInterval = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"PithosSyncTimeInterval"] doubleValue];
- if (syncTimeInterval <= 0) {
- syncTimeInterval = 180.0;
- }
+ double syncTimeInterval = [userDefaults doubleForKey:@"syncTimeInteral"];
+ if (syncTimeInterval <= 0)
+ [userDefaults setDouble:180.0 forKey:@"syncTimeInteral"];
+
+ [userDefaults synchronize];
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(handleAppleEvent:withReplyEvent:)
NSLog(@"query authUser: '%@', authToken: '%@'", authUser, authToken);
if ([authUser length] && [authToken length]) {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:authUser forKey:@"authUser"];
[userDefaults setObject:authToken forKey:@"authToken"];
[userDefaults synchronize];
}
- (IBAction)aboutPithos:(id)sender {
- [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:self.aboutURL]];
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[userDefaults stringForKey:@"aboutURL"]]];
}
- (IBAction)syncNow:(id)sender {
- (void)login {
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
NSString *loginURL = [NSString stringWithFormat:@"%@?next=pithos://%@_%d",
- loginURLPrefix, [processInfo processName], [processInfo processIdentifier]];
+ [userDefaults stringForKey:@"loginURLPrefix"], [processInfo processName], [processInfo processIdentifier]];
NSLog(@"loginURL: %@", loginURL);
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:loginURL]];
}
- (void)authenticate {
- NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *authUser = [userDefaults stringForKey:@"authUser"];
NSString *authToken = [userDefaults stringForKey:@"authToken"];
- NSString *syncDirectoryPath = [userDefaults stringForKey:@"pithosSyncDirectoryPath"];
+ NSString *storageURLPrefix = [userDefaults stringForKey:@"storageURLPrefix"];
+ NSString *publicURLPrefix = [userDefaults stringForKey:@"publicURLPrefix"];
+ NSString *syncDirectoryPath = [userDefaults stringForKey:@"syncDirectoryPath"];
+ NSString *syncContainerName = [userDefaults stringForKey:@"syncContainerName"];
+ double syncTimeInterval = [userDefaults doubleForKey:@"syncTimeInterval"];
NSLog(@"Authentication - storageURLPrefix:%@, authUser:%@, authToken:%@", storageURLPrefix, authUser, authToken);
if (([authUser length] == 0) || ([authToken length] == 0)) {
[self showPithosPreferences:self];