Improve UUID translation in nodes
[pithos-macos] / pithos-macos / PithosAccount.m
index 5329bcd..0250f15 100644 (file)
@@ -49,7 +49,7 @@
 @end
 
 @implementation PithosAccount
-@synthesize uniqueName, active, name;
+@synthesize uniqueName, active, name, clientVersion;
 @synthesize syncActive, syncDirectoryPath, syncAccountsDictionary, syncSkipHidden, syncLastCompleted, syncDaemon;
 @synthesize serverURL, versionResource, loginResource, publicResource, userCatalogResource;
 @synthesize authUser, authToken, storageURLPrefix, authURL, loginURLPrefix, publicURLPrefix, userCatalogURL, userCatalog;
 + (id)pithosAccount {
     PithosAccount *pithosAccount = [[self alloc] init];
     pithosAccount.uniqueName = [NSString stringWithFormat:@"pithosAccount-%f", [NSDate timeIntervalSinceReferenceDate]];
+    pithosAccount.clientVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
     pithosAccount.syncSkipHidden = YES;
     return pithosAccount;
 }
 
 
 - (NSString *)description {
-    return [NSString stringWithFormat:@"uniqueName: %@, active: %d, name: %@, syncActive: %d, syncDirectoryPath: %@, syncAccountsDictionary: %@, syncSkipHidden: %d, syncLastCompleted: %@, serverURL: %@, versionResource: %@, loginResource: %@, publicResource: %@, userCatalogResource: %@, authUser: %@, authToken: %@, storageURLPrefix: %@, authURL: %@, loginURLPrefix: %@, publicURLPrefix: %@, userCatalogResource: %@",
-            uniqueName, active, name, syncActive, syncDirectoryPath, syncAccountsDictionary, syncSkipHidden, syncLastCompleted, serverURL, versionResource, loginResource, publicResource, userCatalogResource, authUser, authToken, storageURLPrefix, authURL, loginURLPrefix, publicURLPrefix, userCatalogResource];
+    return [NSString stringWithFormat:@"uniqueName: %@, active: %d, name: %@, clientVersion: %@, syncActive: %d, syncDirectoryPath: %@, syncAccountsDictionary: %@, syncSkipHidden: %d, syncLastCompleted: %@, serverURL: %@, versionResource: %@, loginResource: %@, publicResource: %@, userCatalogResource: %@, authUser: %@, authToken: %@, storageURLPrefix: %@, authURL: %@, loginURLPrefix: %@, publicURLPrefix: %@, userCatalogResource: %@",
+            uniqueName, active, name, clientVersion, syncActive, syncDirectoryPath, syncAccountsDictionary, syncSkipHidden, syncLastCompleted, serverURL, versionResource, loginResource, publicResource, userCatalogResource, authUser, authToken, storageURLPrefix, authURL, loginURLPrefix, publicURLPrefix, userCatalogResource];
 }
 
 #pragma mark -
         authURL = nil;
         publicURLPrefix = nil;
         loginURLPrefix = nil;
+        userCatalogURL = nil;
 
         @synchronized(self) {
             updatePithos = YES;
 
 - (PithosAccountNode *)accountNode {
     if (!accountNode) {
-        accountNode = [[PithosAccountNode alloc] initWithPithos:self.pithos];
+        accountNode = [[PithosAccountNode alloc] initWithPithosAccountManager:self andPithos:self.pithos];
         accountNode.childrenUpdatedNotificationName = nil;
         accountNode.inheritChildrenUpdatedNotificationName = YES;
-        accountNode.pithosAccountManager = self;
     }
     return accountNode;
 }
 
 - (PithosSharingAccountsNode *)sharingAccountsNode {
     if (!sharingAccountsNode) {
-        sharingAccountsNode = [[PithosSharingAccountsNode alloc] initWithPithos:self.pithos];
+        sharingAccountsNode = [[PithosSharingAccountsNode alloc] initWithPithosAccountManager:self andPithos:self.pithos];
         sharingAccountsNode.childrenUpdatedNotificationName = nil;
         sharingAccountsNode.inheritChildrenUpdatedNotificationName = YES;
     }
         self.syncActive = NO;
         // XXX Show preferences with self as the selected account?
     } else  {
+        [self updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:authUser]];
+        
         self.active = YES;
         if (syncDaemon) {
             self.syncDaemon.pithos = self.pithos;
         }
         if (sharingAccountsNode && self.sharingAccountsNode.children) {
         }
-        
-        [self updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:authUser]];
     }
 }
 
         self.uniqueName = [decoder decodeObjectForKey:@"uniqueName"];
         self.active = [decoder decodeBoolForKey:@"active"];
         name = [decoder decodeObjectForKey:@"name"];
+        self.clientVersion = [decoder decodeObjectForKey:@"clientVersion"];
 
         self.syncActive = [decoder decodeBoolForKey:@"syncActive"];
         self.syncDirectoryPath = [decoder decodeObjectForKey:@"syncDirectoryPath"];
         if (![authUser length] || ![authToken length] || ![self.storageURLPrefix length])
             self.active = NO;
         
-        resetSyncDaemonLocalState = NO;
+        NSString *currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
+        if (!clientVersion || ![clientVersion isEqualToString:currentVersion]) {
+            resetSyncDaemonLocalState = YES;
+            self.clientVersion = currentVersion;
+        } else {
+            resetSyncDaemonLocalState = NO;
+        }
     }
     return self;
 }
     [encoder encodeObject:uniqueName forKey:@"uniqueName"];
     [encoder encodeBool:active forKey:@"active"];
     [encoder encodeObject:name forKey:@"name"];
+    [encoder encodeObject:clientVersion forKey:@"clientVersion"];
     
     [encoder encodeBool:syncActive forKey:@"syncActive"];
     [encoder encodeObject:syncDirectoryPath forKey:@"syncDirectoryPath"];