Improve code and fix bugs
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Thu, 14 Mar 2013 15:06:02 +0000 (17:06 +0200)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Thu, 14 Mar 2013 15:06:02 +0000 (17:06 +0200)
16 files changed:
pithos-macos/ImageAndTextCell.m
pithos-macos/PithosAccountNode.h
pithos-macos/PithosAccountNode.m
pithos-macos/PithosActivity.h
pithos-macos/PithosActivity.m
pithos-macos/PithosBrowserController.h
pithos-macos/PithosBrowserController.m
pithos-macos/PithosContainerNode.h
pithos-macos/PithosContainerNode.m
pithos-macos/PithosNode.m
pithos-macos/PithosObjectNode.m
pithos-macos/PithosSharingAccountsNode.h
pithos-macos/PithosSharingAccountsNode.m
pithos-macos/PithosSubdirNode.m
pithos-macos/PithosUtilities.m
pithos-macos/pithos_macosAppDelegate.m

index 52baa00..0bb3163 100644 (file)
                imageFrame.origin.y -= kImageOriginYOffset;
         imageFrame.size = imageSize;
                
-        if ([controlView isFlipped])
-            imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
-        else
-            imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
-               [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
+        imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
+        [image drawInRect:imageFrame fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
 
                NSRect newFrame = cellFrame;
                newFrame.origin.x += kTextOriginXOffset;
index ecda291..6be678c 100644 (file)
@@ -44,7 +44,6 @@
     ASIPithos *pithos;
     ASIPithosAccount *pithosAccount;
     
-    NSMutableArray *containers;
     ASIPithosAccountRequest *accountRequest;
     
     ASIPithosAccountRequest *applyMetadataAccountRequest;
index f5768d4..42a210b 100644 (file)
@@ -235,7 +235,6 @@ static NSImage *sharedIcon = nil;
         } else {
             newChildren = nil;
             accountRequest = nil;
-            containers = nil;
             forcedRefresh = NO;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshNeeded;
@@ -251,9 +250,10 @@ static NSImage *sharedIcon = nil;
         if (accountRequest.responseStatusCode == 200) {
             self.pithosAccount = [accountRequest account];
             
+            NSMutableArray *containers = [accountRequest.userInfo objectForKey:@"containers"];
             NSArray *someContainers = [accountRequest containers];
             if (containers == nil) {
-                containers = [[NSMutableArray alloc] initWithArray:someContainers];
+                containers = [NSMutableArray arrayWithArray:someContainers];
             } else {
                 [containers addObjectsFromArray:someContainers];
             }
@@ -291,7 +291,6 @@ static NSImage *sharedIcon = nil;
                 }
                 // Else cache was used and all results were fetched during this request, so existing children can be reused
                 accountRequest = nil;
-                containers = nil;
                 forcedRefresh = NO;
                 @synchronized(self) {
                     freshness = PithosNodeStateRefreshFinished;
@@ -315,14 +314,14 @@ static NSImage *sharedIcon = nil;
                                            [NSNumber numberWithInteger:NSOperationQueuePriorityVeryHigh], @"priority", 
                                            [NSNumber numberWithUnsignedInteger:10], @"retries", 
                                            NSStringFromSelector(@selector(accountRequestFinished:)), @"didFinishSelector", 
-                                           NSStringFromSelector(@selector(accountRequestFailed:)), @"didFailSelector", 
+                                           NSStringFromSelector(@selector(accountRequestFailed:)), @"didFailSelector",
+                                           containers, @"containers",
                                            nil];
                 [[PithosUtilities prepareRequest:accountRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous];
             }
         } else if (accountRequest.responseStatusCode == 304) {
             // Account is not modified, so existing children can be reused
             accountRequest = nil;
-            containers = nil;
             forcedRefresh = NO;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshFinished;
index 0e4614e..bee9998 100644 (file)
@@ -53,7 +53,7 @@ typedef enum  {
     NSString *message;
     NSUInteger totalBytes;
     NSUInteger currentBytes;
-    PithosAccount *__unsafe_unretained pithosAccount;
+    PithosAccount *pithosAccount;
 }
 
 - (id)initWithType:(PithosActivityType)aType pithosAccount:(PithosAccount *)aPithosAccount;
@@ -62,6 +62,6 @@ typedef enum  {
 @property (nonatomic, copy) NSString *message;
 @property (nonatomic, assign) NSUInteger totalBytes;
 @property (nonatomic, assign) NSUInteger currentBytes;
-@property (nonatomic, unsafe_unretained) PithosAccount *pithosAccount;
+@property (nonatomic, strong) PithosAccount *pithosAccount;
 
 @end
index 7ac67b8..b47404d 100644 (file)
@@ -49,7 +49,7 @@
         type = aType;
         totalBytes = 0;
         currentBytes = 0;
-        pithosAccount = aPithosAccount;
+        self.pithosAccount = aPithosAccount;
     }
     return self;
 }
index 4473c55..2454f05 100644 (file)
     
     NSViewController *sharedPreviewController;
     
-    NSSplitView *__unsafe_unretained verticalSplitView;
-    NSSplitView *__unsafe_unretained horizontalSplitView;
-    NSView *__unsafe_unretained leftTopView;
-    NSView *__unsafe_unretained leftBottomView;
-    NSOutlineView *__unsafe_unretained outlineView;
-    NSBrowser *__unsafe_unretained browser;
-    NSMenu *__unsafe_unretained outlineViewMenu;
-    NSMenu *__unsafe_unretained browserMenu;
+    IBOutlet NSSplitView *verticalSplitView;
+    IBOutlet NSSplitView *horizontalSplitView;
+    IBOutlet NSView *leftTopView;
+    IBOutlet NSView *leftBottomView;
+    IBOutlet NSOutlineView *outlineView;
+    IBOutlet NSBrowser *browser;
+    IBOutlet NSMenu *outlineViewMenu;
+    IBOutlet NSMenu *browserMenu;
     
     BOOL editingItem;
     
@@ -81,8 +81,8 @@
     PithosNode *clipboardParentNode;
     BOOL clipboardCopy;
     
-    NSTextField *__unsafe_unretained activityTextField;
-    NSProgressIndicator *__unsafe_unretained activityProgressIndicator;
+    IBOutlet NSTextField *activityTextField;
+    IBOutlet NSProgressIndicator *activityProgressIndicator;
     PithosActivityFacility *activityFacility;
     
     NSTimer *refreshTimer;
 @property (nonatomic, unsafe_unretained) PithosAccount *pithosAccountManager;
 @property (nonatomic, strong) PithosAccountNode *accountNode;
 
-@property (nonatomic, unsafe_unretained) IBOutlet NSSplitView *verticalSplitView;
-@property (nonatomic, unsafe_unretained) IBOutlet NSSplitView *horizontalSplitView;
-@property (nonatomic, unsafe_unretained) IBOutlet NSView *leftTopView;
-@property (nonatomic, unsafe_unretained) IBOutlet NSView *leftBottomView;
-@property (nonatomic, unsafe_unretained) IBOutlet NSOutlineView *outlineView;
-@property (nonatomic, unsafe_unretained) IBOutlet NSBrowser *browser;
-@property (nonatomic, unsafe_unretained) IBOutlet NSMenu *outlineViewMenu;
-@property (nonatomic, unsafe_unretained) IBOutlet NSMenu *browserMenu;
-
 @property (nonatomic, strong) NSArray *draggedNodes;
 @property (nonatomic, strong) PithosNode *draggedParentNode;
 
 @property (nonatomic, strong) PithosNode *clipboardParentNode;
 @property (nonatomic, assign) BOOL clipboardCopy;
 
-@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *activityTextField;
-@property (nonatomic, unsafe_unretained) IBOutlet NSProgressIndicator *activityProgressIndicator;
-
 - (IBAction)forceRefresh:(id)sender;
 - (IBAction)refresh:(id)sender;
 - (void)resetBrowser;
index 205bfb8..17420db 100644 (file)
 @implementation PithosBrowserController
 @synthesize pithos;
 @synthesize pithosAccountManager, accountNode;
-@synthesize verticalSplitView, horizontalSplitView, leftTopView, leftBottomView, outlineView, browser, outlineViewMenu, browserMenu;
 @synthesize draggedNodes, draggedParentNode;
 @synthesize clipboardNodes, clipboardParentNode, clipboardCopy;
-@synthesize activityTextField, activityProgressIndicator;
 
 #pragma mark -
 #pragma Object Lifecycle
     // Request for browser refresh 
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosBrowserRefreshNeeded:) 
-                                                 name:@"PithosBrowserRefreshNeeeded" 
+                                                 name:@"PithosBrowserRefreshNeeded" 
                                                object:nil];
 }
 
 #pragma mark Observers
 
 - (void)pithosNodeChildrenUpdated:(NSNotification *)notification {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(pithosNodeChildrenUpdated:) withObject:notification waitUntilDone:NO];
+        return;
+    }
     PithosNode *node = (PithosNode *)[notification object];
     if ((node == accountNode) || ![node.pithos isEqualTo:pithos])
         return;
 }
 
 - (void)pithosAccountNodeChildrenUpdated:(NSNotification *)notification {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(pithosAccountNodeChildrenUpdated:) withObject:notification waitUntilDone:NO];
+        return;
+    }
     BOOL containerPithosFound = NO;
     BOOL containerTrashFound = NO;
     NSMutableIndexSet *removedContainersNodeChildren = [NSMutableIndexSet indexSet];
 #pragma mark Actions
 
 - (IBAction)forceRefresh:(id)sender {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(forceRefresh:) withObject:sender waitUntilDone:NO];
+        return;
+    }
     if (editingItem)
         return;
     if (sender)
 }
 
 - (IBAction)refresh:(id)sender {
+    if (![NSThread isMainThread]) {
+        [self performSelectorOnMainThread:@selector(refresh:) withObject:sender waitUntilDone:NO];
+        return;
+    }
     if (editingItem)
         return;
     if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) {
index a92c12e..5481d2b 100644 (file)
@@ -44,7 +44,6 @@
     ASIPithos *pithos;
     ASIPithosContainer *pithosContainer;
     
-    NSMutableArray *objects;
     ASIPithosContainerRequest *containerRequest;
     NSString *prefix;
     
index 8336b31..8ec0954 100644 (file)
@@ -227,7 +227,6 @@ static NSImage *sharedIcon = nil;
         } else {
             newChildren = nil;
             containerRequest = nil;
-            objects = nil;
             forcedRefresh = NO;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshNeeded;
@@ -246,9 +245,10 @@ static NSImage *sharedIcon = nil;
                 pithosContainer.blockSize = [containerRequest blockSize];
             }
         
+            NSMutableArray *objects = [containerRequest.userInfo objectForKey:@"objects"];
             NSArray *someObjects = [containerRequest objects];
             if (objects == nil) {
-                objects = [[NSMutableArray alloc] initWithArray:someObjects];
+                objects = [NSMutableArray arrayWithArray:someObjects];
             } else {
                 [objects addObjectsFromArray:someObjects];
             }
@@ -346,7 +346,6 @@ static NSImage *sharedIcon = nil;
                 }
                 // Else cache was used and all results were fetched during this request, so existing children can be reused
                 containerRequest = nil;
-                objects = nil;
                 forcedRefresh = NO;
                 @synchronized(self) {
                     freshness = PithosNodeStateRefreshFinished;
@@ -375,14 +374,14 @@ static NSImage *sharedIcon = nil;
                                              [NSNumber numberWithInteger:NSOperationQueuePriorityVeryHigh], @"priority", 
                                              [NSNumber numberWithUnsignedInteger:10], @"retries", 
                                              NSStringFromSelector(@selector(containerRequestFinished:)), @"didFinishSelector", 
-                                             NSStringFromSelector(@selector(containerRequestFailed:)), @"didFailSelector", 
+                                             NSStringFromSelector(@selector(containerRequestFailed:)), @"didFailSelector",
+                                             objects, @"objects",
                                              nil];
                 [[PithosUtilities prepareRequest:containerRequest priority:NSOperationQueuePriorityVeryHigh] startAsynchronous];
             }
         } else if (containerRequest.responseStatusCode == 304) {
             // Container is not modified, so existing children can be reused
             containerRequest = nil;
-            objects = nil;
             forcedRefresh = NO;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshFinished;
index 99567cf..b7dbd99 100644 (file)
 
 - (void)refresh {
     [self invalidateChildren];
-    self.children;
+    [self children];
 }
 
 - (void)forceRefresh {
         pithosNodeInfoController.node = nil;
         [[pithosNodeInfoController window] close];
     }
-    for (PithosNode *child in children) {
-        [child pithosNodeWillBeRemoved];
-    }
+    [children makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)];
 }
 
 #pragma mark -
index a0d0d97..fc797f1 100644 (file)
     self.isPublic = (pithosObject.publicURI != nil);
     // Refresh browser if the object is in my shared and is no longer shared
     if (shared && !pithosObject.sharing)
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosBrowserRefreshNeeeded" object:self];
+        [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosBrowserRefreshNeeded" object:self];
 }
 
 - (void)setLimitedPithosObject:(ASIPithosObject *)aPithosObject {
index 32add2c..c3d8691 100644 (file)
@@ -42,7 +42,6 @@
 @interface PithosSharingAccountsNode : PithosNode {
     ASIPithos *pithos;
     
-    NSMutableArray *sharingAccounts;
     ASIPithosRequest *sharingAccountsRequest;
     
     BOOL reset;
index b03192d..9059d3f 100644 (file)
         } else {
             newChildren = nil;
             sharingAccountsRequest = nil;
-            sharingAccounts = nil;
             forcedRefresh = NO;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshNeeded;
         DLog(@"List sharing accounts finished: %@", [sharingAccountsRequest url]);
         DLog(@"Cached: %d", [sharingAccountsRequest didUseCachedResponse]);
         if (sharingAccountsRequest.responseStatusCode == 200) {
+            NSMutableArray *sharingAccounts = [sharingAccountsRequest.userInfo objectForKey:@"sharingAccounts"];
             NSArray *someSharingAccounts = [sharingAccountsRequest sharingAccounts];
             if (sharingAccounts == nil) {
-                sharingAccounts = [[NSMutableArray alloc] initWithArray:someSharingAccounts];
+                sharingAccounts = [NSMutableArray arrayWithArray:someSharingAccounts];
             } else {
                 [sharingAccounts addObjectsFromArray:someSharingAccounts];
             }
                     DLog(@"using newChildren");
                     newChildren = [[NSMutableArray alloc] init];
                     NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet];
-                    NSMutableArray *sharingAccountsNames = [NSMutableArray arrayWithCapacity:sharingAccounts.count];
                     for (ASIPithosAccount *account in sharingAccounts) {
-                        [sharingAccountsNames addObject:account.name];
                         if (![account.name isEqualToString:pithos.authUser]) {
                             PithosAccountNode *node = [[PithosAccountNode alloc] initWithPithos:pithos];
                             node.parent = self;
                             [newChildren addObject:node];
                         }
                     }
-                    [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:sharingAccountsNames];
                     [[children objectsAtIndexes:
                       [[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){
                         if ([keptNodes containsIndex:idx])
                     }]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)];
                 }
                 // Else cache was used and all results were fetched during this request, so existing children can be reused
+                // Update user catalog even if cache was used
+                NSMutableArray *sharingAccountsNames = [NSMutableArray arrayWithCapacity:sharingAccounts.count];
+                for (ASIPithosAccount *account in sharingAccounts) {
+                    [sharingAccountsNames addObject:account.name];
+                }
+                [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:sharingAccountsNames];
                 sharingAccountsRequest = nil;
-                sharingAccounts = nil;
                 forcedRefresh = NO;
                 @synchronized(self) {
                     freshness = PithosNodeStateRefreshFinished;
                                                    [NSNumber numberWithInteger:NSOperationQueuePriorityVeryHigh], @"priority", 
                                                    [NSNumber numberWithUnsignedInteger:10], @"retries", 
                                                    NSStringFromSelector(@selector(sharingAccountsRequestFinished:)), @"didFinishSelector", 
-                                                   NSStringFromSelector(@selector(sharingAccountsRequestFailed:)), @"didFailSelector", 
+                                                   NSStringFromSelector(@selector(sharingAccountsRequestFailed:)), @"didFailSelector",
+                                                   sharingAccounts, @"sharingAccounts",
                                                    nil];
 //              if (!forcedRefresh)
 //                  sharingAccountsRequest.downloadCache = [ASIDownloadCache sharedCache];
index 993d627..ba3e492 100644 (file)
@@ -177,7 +177,7 @@ static NSImage *sharedIcon = nil;
     self.isPublic = (pithosObject.publicURI != nil);
     // Refresh browser if the object is in my shared and is no longer shared
     if (shared && !pithosObject.subdir && !pithosObject.sharing) {
-        [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosBrowserRefreshNeeeded" object:self];
+        [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosBrowserRefreshNeeded" object:self];
     }
 }
 
index d48928a..8b42206 100644 (file)
 #pragma mark Request Helper Methods
 
 + (ASIPithosRequest *)prepareRequest:(ASIPithosRequest *)request priority:(NSOperationQueuePriority)priority {
-    [request setTimeOutSeconds:60];
+    request.timeOutSeconds = 60;
     request.numberOfTimesToRetryOnTimeout = 10;
-    [request setQueuePriority:priority];
+    request.queuePriority = priority;
     return request;
 }
 
index 3c78a73..01d4c87 100644 (file)
@@ -134,7 +134,7 @@ currentPithosAccount, pithosAccounts, pithosAccountsDictionary, syncPithosAccoun
     [smallImage lockFocus];
     [[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
     [sourceImage setSize:NSMakeSize(18, 18)];
-    [sourceImage compositeToPoint:NSZeroPoint operation:NSCompositeCopy];
+    [sourceImage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
     [smallImage unlockFocus];
     
     statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];