2 // PithosBrowserController.m
5 // Copyright 2011 GRNET S.A. All rights reserved.
7 // Redistribution and use in source and binary forms, with or
8 // without modification, are permitted provided that the following
11 // 1. Redistributions of source code must retain the above
12 // copyright notice, this list of conditions and the following
15 // 2. Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials
18 // provided with the distribution.
20 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
21 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
24 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
33 // The views and conclusions contained in the software and
34 // documentation are those of the authors and should not be
35 // interpreted as representing official policies, either expressed
36 // or implied, of GRNET S.A.
38 #import "PithosBrowserController.h"
39 #import "PithosNode.h"
40 #import "PithosAccountNode.h"
41 #import "PithosContainerNode.h"
42 #import "PithosSubdirNode.h"
43 #import "PithosObjectNode.h"
44 #import "PithosEmptyNode.h"
45 #import "ImageAndTextCell.h"
46 #import "FileSystemBrowserCell.h"
47 #import "ASIPithosRequest.h"
48 #import "ASIPithosContainerRequest.h"
49 #import "ASIPithosObjectRequest.h"
50 #import "ASIPithosContainer.h"
51 #import "ASIPithosObject.h"
52 #import "PithosFileUtilities.h"
54 //@interface PithosBrowserCell : NSBrowserCell {}
55 @interface PithosBrowserCell : FileSystemBrowserCell {}
58 @implementation PithosBrowserCell
61 if ((self = [super init])) {
62 [self setLineBreakMode:NSLineBreakByTruncatingMiddle];
67 - (void)setObjectValue:(id)object {
68 if ([object isKindOfClass:[PithosNode class]]) {
69 PithosNode *node = (PithosNode *)object;
70 [self setStringValue:node.displayName];
71 [self setImage:node.icon];
72 // // All cells are set as leafs because a branchingImage is already set!
73 // // Maybe this cell is already inside an NSBrowserCell
74 // [self setLeaf:YES];
76 [super setObjectValue:object];
82 @interface PithosOutlineViewCell : ImageAndTextCell {}
85 @implementation PithosOutlineViewCell
87 - (void)setObjectValue:(id)object {
88 if ([object isKindOfClass:[PithosNode class]]) {
89 PithosNode *node = (PithosNode *)object;
90 [self setStringValue:node.displayName];
91 [self setImage:node.icon];
92 [self setEditable:NO];
94 [super setObjectValue:object];
100 @interface PithosBrowserController (Private) {}
101 - (void)resetContainers;
102 - (void)getInfo:(NSMenuItem *)sender;
103 - (void)downloadObjectFinished:(ASIPithosObjectRequest *)objectRequest;
104 - (void)downloadObjectFailed:(ASIPithosObjectRequest *)objectRequest;
105 - (void)uploadObjectUsingHashMapFinished:(ASIPithosObjectRequest *)objectRequest;
106 - (void)uploadObjectUsingHashMapFailed:(ASIPithosObjectRequest *)objectRequest;
107 - (void)uploadMissingHashesFinished:(ASIPithosObjectRequest *)objectRequest;
108 - (void)uploadMissingHashesFailed:(ASIPithosObjectRequest *)objectRequest;
111 @implementation PithosBrowserController
112 @synthesize outlineViewDataSourceArray, splitView, outlineView, browser;
115 #pragma Object Lifecycle
118 return [super initWithWindowNibName:@"PithosBrowserController"];
122 [[NSNotificationCenter defaultCenter] removeObserver:self];
123 [browserMenu release];
124 [sharedPreviewController release];
125 [outlineViewDataSourceArray release];
126 [accountNode release];
131 - (void)awakeFromNib {
132 [super awakeFromNib];
134 [browser registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
135 [browser setDraggingSourceOperationMask:NSDragOperationNone forLocal:YES];
136 [browser setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
138 [browser setCellClass:[PithosBrowserCell class]];
140 browserMenu = [[NSMenu alloc] init];
141 [browserMenu setDelegate:self];
142 [browser setMenu:browserMenu];
145 - (void)resetContainers {
147 [browser loadColumnZero];
148 self.outlineViewDataSourceArray = nil;
150 // Create the outlineView tree
152 NSTreeNode *containersTreeNode = [NSTreeNode treeNodeWithRepresentedObject:
153 [[[PithosEmptyNode alloc] initWithDisplayName:@"CONTAINERS" icon:nil] autorelease]];
154 // // CONTAINERS/pithos
155 // [[containersTreeNode mutableChildNodes] addObject:
156 // [NSTreeNode treeNodeWithRepresentedObject:
157 // [[[PithosContainerNode alloc] initWithContainerName:@"pithos"
158 // icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kToolbarHomeIcon)]
160 // // CONTAINERS/trash
161 // [[containersTreeNode mutableChildNodes] addObject:
162 // [NSTreeNode treeNodeWithRepresentedObject:
163 // [[[PithosContainerNode alloc] initWithContainerName:@"trash"
164 // icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kFullTrashIcon)]
167 NSTreeNode *sharedTreeNode = [NSTreeNode treeNodeWithRepresentedObject:
168 [[[PithosEmptyNode alloc] initWithDisplayName:@"SHARED" icon:nil] autorelease]];
170 [[sharedTreeNode mutableChildNodes] addObject:
171 [NSTreeNode treeNodeWithRepresentedObject:
172 [[[PithosEmptyNode alloc] initWithDisplayName:@"my shared"
173 icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kUserIcon)]
175 // SHARED/others shared
176 [[sharedTreeNode mutableChildNodes] addObject:
177 [NSTreeNode treeNodeWithRepresentedObject:
178 [[[PithosEmptyNode alloc] initWithDisplayName:@"others shared"
179 icon:[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGroupIcon)]
182 self.outlineViewDataSourceArray = [NSMutableArray arrayWithObjects:containersTreeNode, sharedTreeNode, nil];
184 // Expand the folder outline view
185 [outlineView expandItem:nil expandChildren:YES];
186 [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
188 // Create accountNode and trigger a refresh
189 accountNode = [[PithosAccountNode alloc] init];
190 accountNode.children;
193 - (void)windowDidLoad {
194 [super windowDidLoad];
196 [[[outlineView tableColumns] objectAtIndex:0] setDataCell:[[[PithosOutlineViewCell alloc] init] autorelease]];
198 // Register for updates
199 [[NSNotificationCenter defaultCenter] addObserver:self
200 selector:@selector(pithosNodeChildrenUpdated:)
201 name:@"PithosContainerNodeChildrenUpdated"
203 [[NSNotificationCenter defaultCenter] addObserver:self
204 selector:@selector(pithosNodeChildrenUpdated:)
205 name:@"PithosSubdirNodeChildrenUpdated"
207 [[NSNotificationCenter defaultCenter] addObserver:self
208 selector:@selector(pithosAccountNodeChildrenUpdated:)
209 name:@"PithosAccountNodeChildrenUpdated"
211 [[NSNotificationCenter defaultCenter] addObserver:self
212 selector:@selector(resetContainers)
213 name:@"PithosAuthenticationCredentialsUpdated"
220 - (void)pithosNodeChildrenUpdated:(NSNotification *)notification {
221 PithosNode *node = (PithosNode *)[notification object];
222 NSInteger lastColumn = [browser lastColumn];
223 for (NSInteger column = lastColumn; column >= 0; column--) {
224 if ([[browser parentForItemsInColumn:column] isEqualTo:node]) {
225 [browser reloadColumn:column];
226 if ((column == lastColumn - 1) && ([[browser parentForItemsInColumn:lastColumn] isLeafItem])) {
227 // This reloads the preview column
228 [browser setLastColumn:column];
236 - (void)pithosAccountNodeChildrenUpdated:(NSNotification *)notification {
237 BOOL containerPithosFound = NO;
238 BOOL containerTrashFound = NO;
239 //NSMutableArray *containersTreeNodeChildren = [[outlineViewDataSourceArray objectAtIndex:0] mutableChildNodes];
240 NSMutableArray *containersTreeNodeChildren = [NSMutableArray array];
241 for (PithosContainerNode *containerNode in accountNode.children) {
242 if ([containerNode.pithosContainer.name isEqualToString:@"pithos"]) {
243 containerNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kToolbarHomeIcon)];
244 [containersTreeNodeChildren insertObject:[NSTreeNode treeNodeWithRepresentedObject:containerNode] atIndex:0];
245 containerPithosFound = YES;
246 } else if ([containerNode.pithosContainer.name isEqualToString:@"trash"]) {
247 containerNode.icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kFullTrashIcon)];
248 NSUInteger insertIndex = 1;
249 if (!containerPithosFound)
251 [containersTreeNodeChildren insertObject:[NSTreeNode treeNodeWithRepresentedObject:containerNode] atIndex:insertIndex];
252 containerTrashFound = YES;
254 [containersTreeNodeChildren addObject:[NSTreeNode treeNodeWithRepresentedObject:containerNode]];
257 BOOL refreshAccountNode = NO;
258 if (!containerPithosFound) {
260 ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest createOrUpdateContainerRequestWithContainerName:@"pithos"];
261 [containerRequest startSynchronous];
262 if ([containerRequest error]) {
263 NSLog(@"error:%@", [containerRequest error]);
264 // XXX do something on error
266 refreshAccountNode = YES;
269 if (!containerTrashFound) {
271 ASIPithosContainerRequest *containerRequest = [ASIPithosContainerRequest createOrUpdateContainerRequestWithContainerName:@"trash"];
272 [containerRequest startSynchronous];
273 if ([containerRequest error]) {
274 NSLog(@"error:%@", [containerRequest error]);
275 // XXX do something on error
277 refreshAccountNode = YES;
280 if (refreshAccountNode) {
281 [accountNode invalidateChildren];
282 accountNode.children;
284 [[[outlineViewDataSourceArray objectAtIndex:0] mutableChildNodes] setArray:containersTreeNodeChildren];
285 self.outlineViewDataSourceArray = outlineViewDataSourceArray;
287 // Expand the folder outline view
288 [outlineView expandItem:nil expandChildren:YES];
289 [outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO];
298 - (IBAction)refresh:(id)sender {
299 for (NSInteger column = [browser lastColumn]; column >= 0; column--) {
300 [(PithosNode *)[browser parentForItemsInColumn:column] invalidateChildren];
302 [browser validateVisibleColumns];
306 #pragma NSBrowserDelegate
308 - (id)rootItemForBrowser:(NSBrowser *)browser {
312 - (NSInteger)browser:(NSBrowser *)browser numberOfChildrenOfItem:(id)item {
313 PithosNode *node = (PithosNode *)item;
314 return node.children.count;
317 - (id)browser:(NSBrowser *)browser child:(NSInteger)index ofItem:(id)item {
318 PithosNode *node = (PithosNode *)item;
319 return [node.children objectAtIndex:index];
322 - (BOOL)browser:(NSBrowser *)browser isLeafItem:(id)item {
323 PithosNode *node = (PithosNode *)item;
324 return node.isLeafItem;
327 - (id)browser:(NSBrowser *)browser objectValueForItem:(id)item {
328 PithosNode *node = (PithosNode *)item;
332 - (NSViewController *)browser:(NSBrowser *)browser previewViewControllerForLeafItem:(id)item {
333 if (sharedPreviewController == nil)
334 sharedPreviewController = [[NSViewController alloc] initWithNibName:@"PithosBrowserPreviewController" bundle:[NSBundle bundleForClass:[self class]]];
335 return sharedPreviewController;
338 //- (CGFloat)browser:(NSBrowser *)browser shouldSizeColumn:(NSInteger)columnIndex forUserResize:(BOOL)forUserResize toWidth:(CGFloat)suggestedWidth {
339 // if (!forUserResize) {
340 // id item = [browser parentForItemsInColumn:columnIndex];
341 // if ([self browser:browser isLeafItem:item]) {
342 // suggestedWidth = 200;
345 // return suggestedWidth;
348 - (BOOL)browser:(NSBrowser *)sender isColumnValid:(NSInteger)column {
352 #pragma mark Drag and Drop source
354 - (BOOL)browser:(NSBrowser *)aBrowser writeRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column
355 toPasteboard:(NSPasteboard *)pasteboard {
356 NSMutableArray *propertyList = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
357 NSIndexPath *baseIndexPath = [browser indexPathForColumn:column];
358 for (NSUInteger i = [rowIndexes firstIndex]; i <= [rowIndexes lastIndex]; i = [rowIndexes indexGreaterThanIndex:i]) {
359 PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:i]];
360 [propertyList addObject:[node.pithosObject.name pathExtension]];
363 [pasteboard declareTypes:[NSArray arrayWithObject:NSFilesPromisePboardType] owner:self];
364 [pasteboard setPropertyList:propertyList forType:NSFilesPromisePboardType];
369 - (NSArray *)browser:(NSBrowser *)aBrowser namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropDestination
370 forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column {
371 NSMutableArray *names = [NSMutableArray arrayWithCapacity:[rowIndexes count]];
372 NSIndexPath *baseIndexPath = [browser indexPathForColumn:column];
373 for (NSUInteger i = [rowIndexes firstIndex]; i <= [rowIndexes lastIndex]; i = [rowIndexes indexGreaterThanIndex:i]) {
374 PithosNode *node = [browser itemAtIndexPath:[baseIndexPath indexPathByAddingIndex:i]];
376 // If the node is a subdir ask if the whole tree should be downloaded
377 if ([node class] == [PithosSubdirNode class]) {
378 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
379 [alert setMessageText:@"Download directory"];
380 [alert setInformativeText:[NSString stringWithFormat:@"'%@' is a directory, do you want to download its contents?", node.displayName]];
381 [alert addButtonWithTitle:@"OK"];
382 [alert addButtonWithTitle:@"Cancel"];
383 NSInteger choice = [alert runModal];
384 if (choice == NSAlertFirstButtonReturn) {
385 NSArray *objectRequests = [PithosFileUtilities objectDataRequestsForSubdirWithContainerName:node.pithosContainer.name
386 objectName:node.pithosObject.name
387 toDirectory:[dropDestination path]
389 if (objectRequests) {
390 for (ASIPithosObjectRequest *objectRequest in objectRequests) {
391 [names addObject:[objectRequest.userInfo valueForKey:@"fileName"]];
392 objectRequest.delegate = self;
393 objectRequest.didFinishSelector = @selector(downloadObjectFinished:);
394 objectRequest.didFailSelector = @selector(downloadObjectFailed:);
395 [objectRequest startAsynchronous];
400 ASIPithosObjectRequest *objectRequest = [PithosFileUtilities objectDataRequestWithContainerName:node.pithosContainer.name
401 objectName:node.pithosObject.name
402 toDirectory:[dropDestination path]
405 [names addObject:[objectRequest.userInfo valueForKey:@"fileName"]];
406 objectRequest.delegate = self;
407 objectRequest.didFinishSelector = @selector(downloadObjectFinished:);
408 objectRequest.didFailSelector = @selector(downloadObjectFailed:);
409 [objectRequest startAsynchronous];
416 #pragma mark Drag and Drop destination
418 - (NSDragOperation)browser:aBrowser
419 validateDrop:(id<NSDraggingInfo>)info
420 proposedRow:(NSInteger *)row
421 column:(NSInteger *)column
422 dropOperation:(NSBrowserDropOperation *)dropOperation {
423 NSDragOperation result = NSDragOperationNone;
424 // Files from the finder are accepted
425 if ([[[info draggingPasteboard] types] indexOfObject:NSFilenamesPboardType] != -1) {
426 // For a between drop, we let the user drop "on" the parent item
427 if (*dropOperation == NSBrowserDropAbove)
429 // Only allow dropping in folders
432 PithosNode *node = [browser itemAtRow:*row inColumn:*column];
433 if ([node class] != [PithosSubdirNode class])
435 *dropOperation = NSBrowserDropOn;
436 result = NSDragOperationCopy;
440 // XXX else local file promises
444 - (BOOL)browser:(NSBrowser *)aBrowser
445 acceptDrop:(id<NSDraggingInfo>)info
447 column:(NSInteger)column
448 dropOperation:(NSBrowserDropOperation)dropOperation {
449 NSArray *filenames = [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType];
450 NSLog(@"drag in filenames: %@", filenames);
451 PithosNode *node = nil;
452 if ((column != -1) && (filenames != nil)) {
454 node = [browser itemAtRow:row inColumn:column];
456 node = [browser parentForItemsInColumn:column];
457 NSLog(@"drag in node: %@", node.url);
458 if (([node class] != [PithosSubdirNode class]) && ([node class] != [PithosContainerNode class]))
461 NSFileManager *defaultManager = [NSFileManager defaultManager];
462 NSString *containerName = [NSString stringWithString:node.pithosContainer.name];
463 NSString *objectNamePrefix;
464 if ([node class] == [PithosSubdirNode class])
465 objectNamePrefix = [NSString stringWithString:node.pithosObject.name];
467 objectNamePrefix = [NSString stringWithString:@""];
468 NSUInteger blockSize = node.pithosContainer.blockSize;
469 NSString *blockHash = node.pithosContainer.blockHash;
471 for (NSString *filePath in filenames) {
473 if ([defaultManager fileExistsAtPath:filePath isDirectory:&isDirectory]) {
476 NSString *objectName = [objectNamePrefix stringByAppendingPathComponent:[filePath lastPathComponent]];
477 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
478 dispatch_async(queue, ^{
479 NSError *error = nil;
480 NSURLResponse *response = nil;
481 [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]
482 cachePolicy:NSURLCacheStorageNotAllowed
484 returningResponse:&response
486 NSString *contentType = [response MIMEType];
487 if (contentType == nil)
488 contentType = @"application/binary";
490 NSLog(@"contentType detection error: %@", error);
491 NSArray *hashes = nil;
492 ASIPithosObjectRequest *objectRequest = [PithosFileUtilities writeObjectDataRequestWithContainerName:containerName
493 objectName:objectName
494 contentType:contentType
501 // XXX set delegates and queue
502 objectRequest.delegate = self;
503 objectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
504 objectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
505 objectRequest.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
506 containerName, @"containerName",
507 objectName, @"objectName",
508 contentType, @"contentType",
509 [NSNumber numberWithUnsignedInteger:blockSize], @"blockSize",
510 blockHash, @"blockHash",
511 filePath, @"filePath",
513 [NSNumber numberWithBool:YES], @"checkIfExists",
515 [NSNumber numberWithUnsignedInteger:0], @"iteration",
517 [objectRequest startAsynchronous];
519 // XXX else show alert?
522 // Upload directory, confirm first
523 // XXX implement this
535 #pragma mark ASIHTTPRequestDelegate
537 - (void)downloadObjectFinished:(ASIPithosObjectRequest *)objectRequest {
538 NSLog(@"download completed: %@", [objectRequest url]);
539 if ([objectRequest bytes] == 0) {
540 NSLog(@"downloaded 0 bytes");
541 NSFileManager *defaultManager = [NSFileManager defaultManager];
542 NSString *filePath = [objectRequest.userInfo objectForKey:@"filePath"];
543 if (![defaultManager fileExistsAtPath:filePath]) {
544 if (![defaultManager createFileAtPath:filePath contents:nil attributes:nil]) {
545 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
546 [alert setMessageText:@"File Creation Error"];
547 [alert setInformativeText:[NSString stringWithFormat:@"Couldn't create zero length file at %@", filePath]];
548 [alert addButtonWithTitle:@"OK"];
555 - (void)downloadObjectFailed:(ASIPithosObjectRequest *)objectRequest {
556 NSLog(@"download failed: %@, error: %@", [objectRequest url], [objectRequest error]);
557 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
558 [alert setMessageText:@"HTTP Request Error"];
559 [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [objectRequest error]]];
560 [alert addButtonWithTitle:@"OK"];
564 - (void)uploadObjectUsingHashMapFinished:(ASIPithosObjectRequest *)objectRequest {
565 NSLog(@"upload using hashmap completed: %@", [objectRequest url]);
566 if (objectRequest.responseStatusCode == 201) {
567 NSLog(@"object created: %@", [objectRequest url]);
568 PithosNode *node = [objectRequest.userInfo objectForKey:@"node"];
569 [node invalidateChildren];
571 } else if (objectRequest.responseStatusCode == 409) {
572 NSUInteger iteration = [[objectRequest.userInfo objectForKey:@"iteration"] unsignedIntegerValue] + 1;
573 if (iteration > 10) {
574 NSLog(@"upload iteration limit reached: %@", [objectRequest url]);
578 NSLog(@"object is missing hashes: %@", [objectRequest url]);
579 ASIPithosObjectRequest *newObjectRequest = [PithosFileUtilities updateObjectDataRequestWithContainerName:[objectRequest.userInfo objectForKey:@"containerName"]
580 objectName:@".upload"
581 contentType:[objectRequest.userInfo objectForKey:@"contentType"]
582 blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
583 forFile:[objectRequest.userInfo objectForKey:@"filePath"]
584 hashes:[objectRequest.userInfo objectForKey:@"hashes"]
585 missingHashesResponse:[objectRequest responseString]
586 checkIfExists:[[objectRequest.userInfo objectForKey:@"checkIfExists"] boolValue]];
587 newObjectRequest.shouldAttemptPersistentConnection = NO;
588 newObjectRequest.delegate = self;
589 newObjectRequest.didFinishSelector = @selector(uploadMissingHashesFinished:);
590 newObjectRequest.didFailSelector = @selector(uploadMissingHashesFailed:);
591 newObjectRequest.userInfo = objectRequest.userInfo;
592 [(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:[NSNumber numberWithBool:NO] forKey:@"checkIfExists"];
593 [(NSMutableDictionary *)(newObjectRequest.userInfo) setObject:[NSNumber numberWithUnsignedInteger:iteration] forKey:@"iteration"];
594 [newObjectRequest startAsynchronous];
596 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
597 [alert setMessageText:@"Unexpected Response Status"];
598 [alert setInformativeText:[NSString stringWithFormat:@"Unexpected response status %d - %@", objectRequest.responseStatusCode, objectRequest.responseStatusMessage]];
599 [alert addButtonWithTitle:@"OK"];
604 - (void)uploadObjectUsingHashMapFailed:(ASIPithosObjectRequest *)objectRequest {
605 NSLog(@"upload failed: %@, error: %@", [objectRequest url], [objectRequest error]);
606 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
607 [alert setMessageText:@"HTTP Request Error"];
608 [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [objectRequest error]]];
609 [alert addButtonWithTitle:@"OK"];
613 - (void)uploadMissingHashesFinished:(ASIPithosObjectRequest *)objectRequest {
614 NSLog(@"upload of missing hashes completed: %@", [objectRequest url]);
615 if ((objectRequest.responseStatusCode == 201) || (objectRequest.responseStatusCode == 204)) {
616 NSArray *hashes = [objectRequest.userInfo objectForKey:@"hashes"];
617 ASIPithosObjectRequest *newObjectRequest = [PithosFileUtilities writeObjectDataRequestWithContainerName:[objectRequest.userInfo objectForKey:@"containerName"]
618 objectName:[objectRequest.userInfo objectForKey:@"objectName"]
619 contentType:[objectRequest.userInfo objectForKey:@"contentType"]
620 blockSize:[[objectRequest.userInfo objectForKey:@"blockSize"] unsignedIntegerValue]
621 blockHash:[objectRequest.userInfo objectForKey:@"blockHash"]
622 forFile:[objectRequest.userInfo objectForKey:@"filePath"]
625 newObjectRequest.delegate = self;
626 newObjectRequest.didFinishSelector = @selector(uploadObjectUsingHashMapFinished:);
627 newObjectRequest.didFailSelector = @selector(uploadObjectUsingHashMapFailed:);
628 newObjectRequest.userInfo = objectRequest.userInfo;
629 [newObjectRequest startAsynchronous];
631 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
632 [alert setMessageText:@"Unexpected Response Status"];
633 [alert setInformativeText:[NSString stringWithFormat:@"Unexpected response status %d - %@", objectRequest.responseStatusCode, objectRequest.responseStatusMessage]];
634 [alert addButtonWithTitle:@"OK"];
639 - (void)uploadMissingHashesFailed:(ASIPithosObjectRequest *)objectRequest {
640 NSLog(@"upload of missing hashes failed: %@, error: %@", [objectRequest url], [objectRequest error]);
641 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
642 [alert setMessageText:@"HTTP Request Error"];
643 [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [objectRequest error]]];
644 [alert addButtonWithTitle:@"OK"];
649 #pragma mark NSSplitViewDelegate
651 - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex {
655 - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex {
660 #pragma mark NSOutlineViewDelegate
662 - (BOOL)outlineView:outlineView shouldSelectItem:(id)item {
663 return ([[item representedObject] isLeaf]);
666 - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item {
667 return (![[item representedObject] isLeaf]);
670 - (void)outlineViewSelectionDidChange:(NSNotification *)notification {
671 PithosNode *node = [[[outlineView itemAtRow:[outlineView selectedRow]] representedObject] representedObject];
674 [browser loadColumnZero];
679 #pragma mark NSMenuDelegate
681 - (void)menuNeedsUpdate:(NSMenu *)menu {
682 NSInteger column = [browser clickedColumn];
683 NSInteger row = [browser clickedRow];
684 [menu removeAllItems];
685 if ((column == -1) || (row == -1)) {
686 // General context menu has 0
688 // PithosNode menu has 1 items
690 NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(getInfo:) keyEquivalent:@""];
691 [menuItem setRepresentedObject:[browser itemAtRow:row inColumn:column]];
692 [menu addItem:menuItem];
697 #pragma mark Menu Actions
699 - (void)getInfo:(NSMenuItem *)sender {
700 [(PithosNode *)[sender representedObject] showPithosNodeInfo:sender];