From 222199ae3f6fa2af492e46d78635af14d7e3049d Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Fri, 11 Nov 2011 11:03:04 +0200 Subject: [PATCH] Made url prefixes user defaults. --- pithos-macos.xcodeproj/project.pbxproj | 1 + pithos-macos/pithos-macos-Info.plist | 14 +---- pithos-macos/pithos_macosAppDelegate.h | 15 +---- pithos-macos/pithos_macosAppDelegate.m | 97 +++++++++++++------------------- 4 files changed, 42 insertions(+), 85 deletions(-) diff --git a/pithos-macos.xcodeproj/project.pbxproj b/pithos-macos.xcodeproj/project.pbxproj index 4985bc2..0e34742 100644 --- a/pithos-macos.xcodeproj/project.pbxproj +++ b/pithos-macos.xcodeproj/project.pbxproj @@ -550,6 +550,7 @@ 610DD2E813E6BB2000ED982F /* Project object */ = { isa = PBXProject; attributes = { + LastUpgradeCheck = 0420; ORGANIZATIONNAME = koomasi; }; buildConfigurationList = 610DD2EB13E6BB2000ED982F /* Build configuration list for PBXProject "pithos-macos" */; diff --git a/pithos-macos/pithos-macos-Info.plist b/pithos-macos/pithos-macos-Info.plist index 7ba208d..3ab699f 100644 --- a/pithos-macos/pithos-macos-Info.plist +++ b/pithos-macos/pithos-macos-Info.plist @@ -24,7 +24,7 @@ CFBundleURLName - Pithos' URL + gr.grnet.pithos-macos CFBundleURLSchemes pithos @@ -39,17 +39,5 @@ MainMenu NSPrincipalClass NSApplication - PithosAboutURL - https://pithos.dev.grnet.gr/docs - PithosLoginURLPrefix - https://pithos.dev.grnet.gr/login - PithosPublicURLPrefix - https://pithos.dev.grnet.gr - PithosStorageURLPrefix - https://pithos.dev.grnet.gr/v1 - PithosSyncContainerName - pithos - PithosSyncTimeInterval - 180 diff --git a/pithos-macos/pithos_macosAppDelegate.h b/pithos-macos/pithos_macosAppDelegate.h index 12d4215..2e6d9c4 100644 --- a/pithos-macos/pithos_macosAppDelegate.h +++ b/pithos-macos/pithos_macosAppDelegate.h @@ -50,13 +50,7 @@ IBOutlet NSMenu *statusMenu; NSStatusItem *statusItem; - NSString *storageURLPrefix; - NSString *publicURLPrefix; - NSString *loginURLPrefix; - NSString *aboutURL; - - NSString *syncContainerName; - NSTimeInterval syncTimeInterval; + NSUserDefaults *userDefaults; } - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent; @@ -68,13 +62,6 @@ - (void)login; - (void)authenticate; -@property (nonatomic, readonly) NSString *storageURLPrefix; -@property (nonatomic, readonly) NSString *publicURLPrefix; -@property (nonatomic, readonly) NSString *loginURLPrefix; -@property (nonatomic, readonly) NSString *aboutURL; -@property (nonatomic, readonly) NSString *syncContainerName; -@property (nonatomic, assign) NSTimeInterval syncTimeInterval; - @property (nonatomic, retain) PithosBrowserController *pithosBrowserController; @property (nonatomic, retain) PithosSyncDaemon *pithosSyncDaemon; @property (nonatomic, assign) BOOL alwaysNo; diff --git a/pithos-macos/pithos_macosAppDelegate.m b/pithos-macos/pithos_macosAppDelegate.m index f7a8af6..efa7a72 100644 --- a/pithos-macos/pithos_macosAppDelegate.m +++ b/pithos-macos/pithos_macosAppDelegate.m @@ -43,53 +43,34 @@ #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 { @@ -102,19 +83,17 @@ 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:) @@ -187,7 +166,6 @@ 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]; @@ -215,7 +193,7 @@ } - (IBAction)aboutPithos:(id)sender { - [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:self.aboutURL]]; + [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[userDefaults stringForKey:@"aboutURL"]]]; } - (IBAction)syncNow:(id)sender { @@ -228,16 +206,19 @@ - (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]; -- 1.7.10.4