Shift-refresh forces no use of cache.
[pithos-macos] / pithos-macos / PithosBrowserController.m
index aaa4e2a..4ec654a 100644 (file)
     [browser loadColumnZero];
     [containersNodeChildren removeAllObjects];
     [outlineView reloadData];
-    
        // Expand the folder outline view
     [outlineView expandItem:nil expandChildren:YES];
        [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
     
     // Refresh account
     [accountNode refresh];
+    [mySharedNode refresh];
+    [othersSharedNode refresh];
 }
 
 - (void)windowDidLoad {
     // Expand the folder outline view
     [outlineView expandItem:nil expandChildren:YES];
     
-    if ((rootNode == containersNode) || (rootNode == sharedNode)) {
+    if ((rootNode == nil) || (rootNode == containersNode) || (rootNode == sharedNode)) {
         rootNode = [containersNodeChildren objectAtIndex:0];
         [browser loadColumnZero];
     }
 #pragma mark Actions
 
 - (IBAction)refresh:(id)sender {
-    if (sender)
-        [accountNode refresh];
-    for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
-        [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];
+    if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) {
+        if (sender)
+            [accountNode forceRefresh];
+        for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
+            PithosNode *node = (PithosNode *)[browser parentForItemsInColumn:column];
+            node.forcedRefresh = YES;
+            [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];                      
+            //[(PithosNode *)[browser parentForItemsInColumn:column] forceRefresh];
+        }        
+    } else {
+        if (sender)
+            [accountNode refresh];
+        for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
+            [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];
+        }
     }
     [browser validateVisibleColumns];
 }
             if ([PithosFileUtilities objectExistsAtContainerName:node.pithosContainer.name 
                                                       objectName:destinationObjectName 
                                                            error:&error 
-                                                     isDirectory:&isDirectory]) {
+                                                     isDirectory:&isDirectory 
+                                                  sharingAccount:nil]) {
                 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
                 [alert setMessageText:@"Name Taken"];
                 [alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
             if ([PithosFileUtilities objectExistsAtContainerName:node.pithosContainer.name 
                                                       objectName:destinationObjectName 
                                                            error:&error 
-                                                     isDirectory:&isDirectory]) {
+                                                     isDirectory:&isDirectory 
+                                                  sharingAccount:nil]) {
                 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
                 [alert setMessageText:@"Name Taken"];
                 [alert setInformativeText:[NSString stringWithFormat:@"The name '%@' is already taken. Please choose a different name", newName]];
@@ -562,13 +576,16 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             if (*row != -1) {
                 // Check if the node is not a folder and if so redirect to the parent item
                 dropNode = [browser itemAtRow:*row inColumn:*column];
-                if ([dropNode class] != [PithosSubdirNode class])
+                if ([dropNode class] == [PithosObjectNode class])
                     *row = -1;
             }
             if (*row == -1)
                 dropNode = [browser parentForItemsInColumn:*column];
             
-            if (!dropNode.shared && !dropNode.sharingAccount) {
+            if (!dropNode.shared && 
+                (!dropNode.sharingAccount || 
+                 ([dropNode class] == [PithosSubdirNode class]) || 
+                 ([dropNode class] == [PithosContainerNode class]))) {
                 *dropOperation = NSBrowserDropOn;
                 result = NSDragOperationCopy;
             }
@@ -583,7 +600,7 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
             if (*row != -1) {
                 // Check if the node is not a folder and if so redirect to the parent item
                 dropNode = [browser itemAtRow:*row inColumn:*column];
-                if ([dropNode class] != [PithosSubdirNode class])
+                if ([dropNode class] == [PithosObjectNode class])
                     *row = -1;
             }
             if (*row == -1)
@@ -664,22 +681,26 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                                        blockHash:blockHash 
                                                                                                                          forFile:filePath 
                                                                                                                    checkIfExists:YES 
-                                                                                                                          hashes:&hashes];
+                                                                                                                          hashes:&hashes 
+                                                                                                                  sharingAccount:node.sharingAccount];
                             if (objectRequest) {
                                 objectRequest.delegate = self;
                                 objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
                                 objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
-                                objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-                                                          containerName, @"containerName", 
-                                                          objectName, @"objectName", 
-                                                          contentType, @"contentType", 
-                                                          [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
-                                                          blockHash, @"blockHash", 
-                                                          filePath, @"filePath", 
-                                                          hashes, @"hashes", 
-                                                          node, @"node", 
-                                                          [NSNumber numberWithUnsignedInteger:10], @"iteration", 
-                                                          nil];
+                                NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                                 containerName, @"containerName", 
+                                                                 objectName, @"objectName", 
+                                                                 contentType, @"contentType", 
+                                                                 [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
+                                                                 blockHash, @"blockHash", 
+                                                                 filePath, @"filePath", 
+                                                                 hashes, @"hashes", 
+                                                                 node, @"node", 
+                                                                 [NSNumber numberWithUnsignedInteger:10], @"iteration", 
+                                                                 nil];
+                                if (node.sharingAccount)
+                                    [userInfo setObject:node.sharingAccount forKey:@"sharingAccount"];
+                                objectRequest.userInfo = userInfo;
                                 [objectRequest startAsynchronous];
                             }
                         });
@@ -710,7 +731,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                            contentTypes:&contentTypes
                                                                                                               filePaths:&filePaths
                                                                                                              hashesArrays:&hashesArrays 
-                                                                                                directoryObjectRequests:&directoryObjectRequests];
+                                                                                                directoryObjectRequests:&directoryObjectRequests 
+                                                                                                         sharingAccount:node.sharingAccount];
                                 for (ASIPithosObjectRequest *objectRequest in directoryObjectRequests) {
                                     objectRequest.delegate = self;
                                     objectRequest.didFinishSelector = @selector(uploadDirectoryObjectFinished:);
@@ -723,16 +745,19 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                         objectRequest.delegate = self;
                                         objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
                                         objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
-                                        objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
-                                                                  containerName, @"containerName", 
-                                                                  [objectNames objectAtIndex:i], @"objectName", 
-                                                                  [contentTypes objectAtIndex:i], @"contentType", 
-                                                                  [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
-                                                                  blockHash, @"blockHash", 
-                                                                  [filePaths objectAtIndex:i], @"filePath", 
-                                                                  [hashesArrays objectAtIndex:i], @"hashes", 
-                                                                  [NSNumber numberWithUnsignedInteger:10], @"iteration", 
-                                                                  nil];
+                                        NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
+                                                                         containerName, @"containerName", 
+                                                                         [objectNames objectAtIndex:i], @"objectName", 
+                                                                         [contentTypes objectAtIndex:i], @"contentType", 
+                                                                         [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize", 
+                                                                         blockHash, @"blockHash", 
+                                                                         [filePaths objectAtIndex:i], @"filePath", 
+                                                                         [hashesArrays objectAtIndex:i], @"hashes", 
+                                                                         [NSNumber numberWithUnsignedInteger:10], @"iteration", 
+                                                                         nil];
+                                        if (node.sharingAccount)
+                                            [userInfo setObject:node.sharingAccount forKey:@"sharingAccount"];
+                                        objectRequest.userInfo = userInfo;
                                         [objectRequest startAsynchronous];
                                     }
                                 }
@@ -963,7 +988,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                       objectName:@".upload" 
                                                                                                        blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
                                                                                                          forFile:[objectRequest.userInfo objectForKey:@"filePath"] 
-                                                                                               missingBlockIndex:missingBlockIndex];
+                                                                                               missingBlockIndex:missingBlockIndex 
+                                                                                                  sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
         newObjectRequest.delegate = self;
         newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:);
         newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:);
@@ -997,7 +1023,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                           blockHash:[objectRequest.userInfo objectForKey:@"blockHash"]
                                                                                                             forFile:[objectRequest.userInfo objectForKey:@"filePath"] 
                                                                                                       checkIfExists:NO 
-                                                                                                             hashes:&hashes];
+                                                                                                             hashes:&hashes 
+                                                                                                     sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
             newObjectRequest.delegate = self;
             newObjectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
             newObjectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
@@ -1010,7 +1037,8 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
                                                                                                           objectName:@".upload" 
                                                                                                            blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
                                                                                                              forFile:[objectRequest.userInfo objectForKey:@"filePath"] 
-                                                                                                   missingBlockIndex:missingBlockIndex];
+                                                                                                   missingBlockIndex:missingBlockIndex 
+                                                                                                      sharingAccount:[objectRequest.userInfo objectForKey:@"sharingAccount"]];
             newObjectRequest.delegate = self;
             newObjectRequest.didFinishSelector = @selector(uploadMissingBlockFinished:);
             newObjectRequest.didFailSelector = @selector(uploadMissingBlockFailed:);