Made url prefixes user defaults.
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Fri, 11 Nov 2011 09:03:04 +0000 (11:03 +0200)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Fri, 11 Nov 2011 09:03:04 +0000 (11:03 +0200)
pithos-macos.xcodeproj/project.pbxproj
pithos-macos/pithos-macos-Info.plist
pithos-macos/pithos_macosAppDelegate.h
pithos-macos/pithos_macosAppDelegate.m

index 4985bc2..0e34742 100644 (file)
                610DD2E813E6BB2000ED982F /* Project object */ = {
                        isa = PBXProject;
                        attributes = {
+                               LastUpgradeCheck = 0420;
                                ORGANIZATIONNAME = koomasi;
                        };
                        buildConfigurationList = 610DD2EB13E6BB2000ED982F /* Build configuration list for PBXProject "pithos-macos" */;
index 7ba208d..3ab699f 100644 (file)
@@ -24,7 +24,7 @@
        <array>
                <dict>
                        <key>CFBundleURLName</key>
-                       <string>Pithos&apos; URL</string>
+                       <string>gr.grnet.pithos-macos</string>
                        <key>CFBundleURLSchemes</key>
                        <array>
                                <string>pithos</string>
        <string>MainMenu</string>
        <key>NSPrincipalClass</key>
        <string>NSApplication</string>
-       <key>PithosAboutURL</key>
-       <string>https://pithos.dev.grnet.gr/docs</string>
-       <key>PithosLoginURLPrefix</key>
-       <string>https://pithos.dev.grnet.gr/login</string>
-       <key>PithosPublicURLPrefix</key>
-       <string>https://pithos.dev.grnet.gr</string>
-       <key>PithosStorageURLPrefix</key>
-       <string>https://pithos.dev.grnet.gr/v1</string>
-       <key>PithosSyncContainerName</key>
-       <string>pithos</string>
-       <key>PithosSyncTimeInterval</key>
-       <real>180</real>
 </dict>
 </plist>
index 12d4215..2e6d9c4 100644 (file)
     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;
 - (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;
index f7a8af6..efa7a72 100644 (file)
 #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];