Convert to Objective-C ARC
[pithos-macos] / pithos-macos / PithosPreferencesController.m
index 3ab435d..c978c02 100644 (file)
@@ -70,7 +70,7 @@
 @synthesize accountsArrayController;
 @synthesize accountRemoveEnable;
 @synthesize serverURL, authUser, authToken, manual, loginEnable, loginCancelEnable;
-@synthesize syncActive, syncDirectoryPath, syncAccountsDictionary, syncApplyEnable, syncCancelEnable, 
+@synthesize syncActive, syncSkipHidden, syncDirectoryPath, syncAccountsDictionary, syncApplyEnable, syncCancelEnable, 
             syncAccountsOutlineView, syncAccountsRootFilesNodes;
 @synthesize groupsDictionaryController, selectedGroupMembersDictionaryController;
 
@@ -91,7 +91,7 @@
 //     // Select the first tab when the window is loaded for the first time.
 //     [[window valueForKeyPath:@"toolbar"] setSelectedItemIdentifier:@"0"];
     
-    [[[syncAccountsOutlineView tableColumns] objectAtIndex:1] setDataCell:[[[PithosPreferencesSyncOutlineViewCell alloc] init] autorelease]];
+    [[[syncAccountsOutlineView tableColumns] objectAtIndex:1] setDataCell:[[PithosPreferencesSyncOutlineViewCell alloc] init]];
     syncAccountsMyAccountNode = [[PithosEmptyNode alloc] initWithDisplayName:@"<my account>" 
                                                                         icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kUserIcon)]];
     
 
 - (void)selectedPithosAccountNodeChildrenUpdated:(NSNotification *)notification {
     [syncAccountsOutlineView reloadData];
-    [syncAccountsOutlineView expandItem:nil expandChildren:YES];
+//    [syncAccountsOutlineView expandItem:nil expandChildren:YES];
 }
 
 #pragma mark -
     BOOL isDirectory;
     self.syncApplyEnable = (selectedPithosAccount.active && 
                             ((selectedPithosAccount.syncActive != syncActive) || 
+                             (selectedPithosAccount.syncSkipHidden != syncSkipHidden) || 
                              (![selectedPithosAccount.syncDirectoryPath isEqualToString:syncDirectoryPath] && 
                               (![[NSFileManager defaultManager] fileExistsAtPath:syncDirectoryPath isDirectory:&isDirectory] || 
                                isDirectory)) ||
                              ![selectedPithosAccount.syncAccountsDictionary isEqualToDictionary:syncAccountsDictionary]));
     self.syncCancelEnable = (selectedPithosAccount.active && 
                              ((selectedPithosAccount.syncActive != syncActive) || 
+                              (selectedPithosAccount.syncSkipHidden != syncSkipHidden) || 
                               ![selectedPithosAccount.syncDirectoryPath isEqualToString:syncDirectoryPath] ||
                               ![selectedPithosAccount.syncAccountsDictionary isEqualToDictionary:syncAccountsDictionary]));
 }
     if (aSelectedPithosAccount && ![aSelectedPithosAccount isEqualTo:selectedPithosAccount]) {
         selectedPithosAccount.accountNode.childrenUpdatedNotificationName = nil;
         selectedPithosAccount.sharingAccountsNode.childrenUpdatedNotificationName = nil;
-        [selectedPithosAccount release];
-        selectedPithosAccount = [aSelectedPithosAccount retain];
+        selectedPithosAccount = aSelectedPithosAccount;
         selectedPithosAccount.accountNode.childrenUpdatedNotificationName = @"SelectedPithosAccountNodeChildrenUpdated";
         selectedPithosAccount.sharingAccountsNode.childrenUpdatedNotificationName = @"SelectedPithosAccountNodeChildrenUpdated";
         
 #pragma Login Properties
 
 - (void)setServerURL:(NSString *)aServerURL {
-    [serverURL release];
     serverURL = [aServerURL copy];
     [self updateLogin];
 }
 
 - (void)setAuthUser:(NSString *)anAuthUser {
-    [authUser release];
     authUser = [anAuthUser copy];
     [self updateLogin];
 }
 
 - (void)setAuthToken:(NSString *)anAuthToken {
-    [authToken release];
     authToken = [anAuthToken copy];
     [self updateLogin];
 }
     [self updateSync];
 }
 
+- (void)setSyncSkipHidden:(BOOL)aSyncSkipHidden {
+    syncSkipHidden = aSyncSkipHidden;
+    [self updateSync];
+    [self selectedPithosAccountNodeChildrenUpdated:nil];
+}
+
 - (void)setSyncDirectoryPath:(NSString *)aSyncDirectoryPath {
-    [syncDirectoryPath release];
     syncDirectoryPath = [aSyncDirectoryPath copy];
     [self updateSync];
 }
 
 - (void)setSyncAccountsDictionary:(NSMutableDictionary *)aSyncAccountsDictionary {
-    [syncAccountsDictionary release];
     syncAccountsDictionary = [[NSMutableDictionary alloc] initWithCapacity:[aSyncAccountsDictionary count]];
     for (NSString *accountName in aSyncAccountsDictionary) {
         NSDictionary *aSyncContainersDictionary = [aSyncAccountsDictionary objectForKey:accountName];
     [self updateAccounts];
     if (!accountRemoveEnable)
         return;
-    PithosAccount *removedPithosAccount = [selectedPithosAccount retain];
+    PithosAccount *removedPithosAccount = selectedPithosAccount;
     pithos_macosAppDelegate *delegate = (pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate];
     if ([delegate.currentPithosAccount isEqualTo:removedPithosAccount] && [delegate.pithosBrowserController operationsPending]) {
-        NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+        NSAlert *alert = [[NSAlert alloc] init];
         [alert setMessageText:@"Operations Pending"];
         [alert setInformativeText:@"There are pending operations in the browser, do you want to remove the account and cancel them?"];
         [alert addButtonWithTitle:@"OK"];
         [alert addButtonWithTitle:@"Cancel"];
         NSInteger choice = [alert runModal];
         if (choice == NSAlertSecondButtonReturn) {
-            [removedPithosAccount release];
             return;
         }
     }
     [delegate.pithosAccountsDictionary removeObjectForKey:removedPithosAccount.name];
     [delegate removedPithosAccount:removedPithosAccount];
     [delegate savePithosAccounts:self];
-    [removedPithosAccount release];
     [self updateAccounts];
 }
 
 #pragma Login Actions
 
 - (IBAction)login:(id)sender {
+    self.syncAccountsRootFilesNodes = [NSMutableDictionary dictionary];
     if (!manual) {
         [selectedPithosAccount loginWithServerURL:serverURL];
     } else {
     self.serverURL = selectedPithosAccount.serverURL;
     self.authUser = selectedPithosAccount.authUser;
     self.authToken = selectedPithosAccount.authToken;
+    self.manual = NO;
 }
 
 #pragma Sync Actions
 - (IBAction)syncApply:(id)sender {
     [selectedPithosAccount updateSyncWithSyncActive:syncActive 
                                   syncDirectoryPath:syncDirectoryPath 
-                           syncAccountsDictionary:syncAccountsDictionary];
+                           syncAccountsDictionary:syncAccountsDictionary 
+                                     syncSkipHidden:syncSkipHidden];
     [self updateSync];
     pithos_macosAppDelegate *delegate = (pithos_macosAppDelegate *)[[NSApplication sharedApplication] delegate];
     [delegate savePithosAccounts:self];
     self.syncDirectoryPath = selectedPithosAccount.syncDirectoryPath;
     self.syncAccountsDictionary = selectedPithosAccount.syncAccountsDictionary;
     self.syncAccountsRootFilesNodes = [NSMutableDictionary dictionary];
-    [self selectedPithosAccountNodeChildrenUpdated:nil];
+    self.syncSkipHidden = selectedPithosAccount.syncSkipHidden;
 }
 
 - (IBAction)syncRefresh:(id)sender {
     if (outlineView == syncAccountsOutlineView) {
         if (item == nil) {
             // root: <my account> + #<sharing account>
+            NSInteger accountsCount = 0;
+            if ([selectedPithosAccount.accountNode.children count])
+                accountsCount = 1;
             if (selectedPithosAccount.sharingAccountsNode.children)
-                return (selectedPithosAccount.sharingAccountsNode.children.count + 1);
-            else
-                return 1;
+                accountsCount += selectedPithosAccount.sharingAccountsNode.children.count;
+            return accountsCount;
         } else if (item == syncAccountsMyAccountNode) {
             // root/<my account>: #<container>
             if (selectedPithosAccount.accountNode.children) {
                 // We add 1 for the root files node
                 NSInteger subdirCount = 1;
                 for (PithosNode *node in containerNode.children) {
-                    if ([node class] == [PithosSubdirNode class])
+                    if (([node class] == [PithosSubdirNode class]) && (!syncSkipHidden || ![node.displayName hasPrefix:@"."]))
                         subdirCount++;
                 }
                 return subdirCount;
     if (outlineView == syncAccountsOutlineView) {
         if (item == nil) {
             // root: [ <my account>, <sharing account>+ ]
-            if (index == 0)
-                return syncAccountsMyAccountNode;
-            else
-                return [selectedPithosAccount.sharingAccountsNode.children objectAtIndex:(index - 1)];
+            if ([selectedPithosAccount.accountNode.children count]) {
+                if (index == 0)
+                    return syncAccountsMyAccountNode;
+                else
+                    return [selectedPithosAccount.sharingAccountsNode.children objectAtIndex:(index - 1)];
+            } else {
+                return [selectedPithosAccount.sharingAccountsNode.children objectAtIndex:index];
+            }
         } else if (item == syncAccountsMyAccountNode) {
             // root/<my account>: [ <container>+ ]
             NSInteger currentContainerIndex = -1;
             PithosContainerNode *containerNode = (PithosContainerNode *)item;
             NSInteger currentSubdirIndex = -1;
             for (PithosNode *node in containerNode.children) {
-                if ([node class] == [PithosSubdirNode class]) {
+                if (([node class] == [PithosSubdirNode class]) && (!syncSkipHidden || ![node.displayName hasPrefix:@"."])) {
                     currentSubdirIndex++;
                     if (currentSubdirIndex == index)
                         return node;
                 if (!rootFilesNode) {
                     if (![syncAccountsRootFilesNodes objectForKey:accountName])
                         [syncAccountsRootFilesNodes setObject:[NSMutableDictionary dictionary] forKey:accountName];
-                    rootFilesNode = [[[PithosEmptyNode alloc] initWithDisplayName:@"<root files>" 
-                                                                             icon:[[NSWorkspace sharedWorkspace] iconForFileType:@""]] 
-                                     autorelease];
+                    rootFilesNode = [[PithosEmptyNode alloc] initWithDisplayName:@"<root files>" 
+                                                                             icon:[[NSWorkspace sharedWorkspace] iconForFileType:@""]];
                     rootFilesNode.parent = containerNode;
                     [[syncAccountsRootFilesNodes objectForKey:accountName] setObject:rootFilesNode forKey:containerNode.displayName];
                 }
                 if (!accountName)
                     accountName = @"";
                 NSMutableSet *containerExcludedDirectories = [[syncAccountsDictionary objectForKey:accountName] 
-                                                                objectForKey:node.displayName];
+                                                              objectForKey:node.displayName];
                 if (containerExcludedDirectories) {
                     if ([containerExcludedDirectories count])
                         return [NSNumber numberWithUnsignedInteger:NSMixedState];
                 if (!accountName)
                     accountName = @"";
                 NSMutableSet *containerExcludedDirectories = [[syncAccountsDictionary objectForKey:accountName] 
-                                                                objectForKey:node.parent.displayName];
+                                                              objectForKey:node.parent.displayName];
                 if (!containerExcludedDirectories || 
                     [containerExcludedDirectories 
                      containsObject:[[node.displayName lowercaseString] stringByReplacingOccurrencesOfString:@"/" withString:@":"]])
                         }
                         NSMutableSet *newContainerExcludeDirectories = [NSMutableSet setWithObject:@""];
                         for (PithosNode *siblingNode in node.parent.children) {
-                            if ([siblingNode class] == [PithosSubdirNode class]) {
+                            if (([siblingNode class] == [PithosSubdirNode class]) && 
+                                (!syncSkipHidden || ![siblingNode.displayName hasPrefix:@"."])) {
                                 NSString *siblingDirectoryName = [[siblingNode.displayName lowercaseString] 
                                                                   stringByReplacingOccurrencesOfString:@"/" withString:@":"];
                                 if (![siblingDirectoryName isEqualToString:directoryName] && 
                         }
                         NSMutableSet *newContainerExcludeDirectories = [NSMutableSet set];
                         for (PithosNode *siblingNode in node.parent.children) {
-                            if ([siblingNode class] == [PithosSubdirNode class]) {
+                            if (([siblingNode class] == [PithosSubdirNode class]) && 
+                                (!syncSkipHidden || ![siblingNode.displayName hasPrefix:@"."])) {
                                 NSString *siblingDirectoryName = [[siblingNode.displayName lowercaseString] 
                                                                   stringByReplacingOccurrencesOfString:@"/" withString:@":"];
                                 if (![newContainerExcludeDirectories containsObject:siblingDirectoryName])