diff --git a/Classes/SBOptionsViewController.h b/Classes/SBOptionsViewController.h index 699f384..79858ea 100644 --- a/Classes/SBOptionsViewController.h +++ b/Classes/SBOptionsViewController.h @@ -9,11 +9,6 @@ #import @interface SBOptionsViewController : NSViewController { - IBOutlet NSButton *_optimizeOption; - IBOutlet NSButton *_metadataOption; - IBOutlet NSButton *_organizeGroupsOption; - IBOutlet NSButton *_autoStartOption; - IBOutlet NSPopUpButton *_destButton; NSMutableDictionary *_options; diff --git a/Classes/SBOptionsViewController.m b/Classes/SBOptionsViewController.m index 8606e7d..422eea5 100644 --- a/Classes/SBOptionsViewController.m +++ b/Classes/SBOptionsViewController.m @@ -40,40 +40,15 @@ - (void)loadView { [super loadView]; [self prepareDestPopup]; - //[self prepareOptions]; -} - -- (void)prepareOptions { - if (self.options) { - [_optimizeOption setState:[[self.options objectForKey:@"Optimize"] boolValue]]; - [_metadataOption setState:[[self.options objectForKey:@"Metadata"] boolValue]]; - [_organizeGroupsOption setState:[[self.options objectForKey:@"Organize"] boolValue]]; - [_autoStartOption setState:[[self.options objectForKey:@"AutoStart"] boolValue]]; - } } - (void)prepareDestPopup { NSMenuItem *folderItem = nil; - if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]) { - _destination = [[NSURL fileURLWithPath:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]] retain]; + if ([self.options valueForKey:@"SBQueueDestination"]) { + _destination = [[self.options valueForKey:@"SBQueueDestination"] retain]; -#ifdef SB_SANDBOX - if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestinationBookmark"]) { - BOOL bookmarkDataIsStale; - NSError *error; - NSData *bookmarkData = [[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestinationBookmark"]; - - [destination release]; - destination = [[NSURL - URLByResolvingBookmarkData:bookmarkData - options:NSURLBookmarkResolutionWithSecurityScope - relativeToURL:nil - bookmarkDataIsStale:&bookmarkDataIsStale - error:&error] retain]; - } -#endif - if (![[NSFileManager defaultManager] fileExistsAtPath:[_destination path] isDirectory:nil]) + if (![[NSFileManager defaultManager] fileExistsAtPath:[_destination path] isDirectory:nil]) _destination = nil; } @@ -128,21 +103,7 @@ [_destButton selectItem:folderItem]; _customDestination = YES; -#ifdef SB_SANDBOX - NSData *bookmark = nil; - NSError *error = nil; - bookmark = [[panel URL] bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope - includingResourceValuesForKeys:nil - relativeToURL:nil // Make it app-scoped - error:&error]; - if (error) { - NSLog(@"Error creating bookmark for URL (%@): %@", [panel URL], error); - [NSApp presentError:error]; - } - - [[NSUserDefaults standardUserDefaults] setValue:bookmark forKey:@"SBQueueDestinationBookmark"]; -#endif - [[NSUserDefaults standardUserDefaults] setValue:[[panel URL] path] forKey:@"SBQueueDestination"]; + [self.options setValue:[panel URL] forKey:@"SBQueueDestination"]; [[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"SBQueueDestinationSelected"]; } else diff --git a/Classes/SBQueue.m b/Classes/SBQueue.m index b270f71..f26b226 100644 --- a/Classes/SBQueue.m +++ b/Classes/SBQueue.m @@ -227,7 +227,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; [self saveQueueToDisk]; // Get the first item available in the queue - self.currentItem = [[self firstItemInQueue] retain]; + self.currentItem = [self firstItemInQueue]; if (!self.currentItem) { break; @@ -242,7 +242,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; // Check results if (self.cancelled) { self.currentItem.status = SBQueueItemStatusCancelled; - [self.currentItem release]; + self.currentItem = nil; [self handleSBStatusCancelled]; break; } @@ -254,7 +254,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; [self handleSBStatusFailed:outError]; } - [self.currentItem release]; + self.currentItem = nil; } if (self.status == SBQueueStatusCancelled) { diff --git a/Classes/SBQueueController.h b/Classes/SBQueueController.h index 10bf0d0..7573778 100755 --- a/Classes/SBQueueController.h +++ b/Classes/SBQueueController.h @@ -7,7 +7,6 @@ // #import -#import #import "SBQueue.h" @@ -25,11 +24,11 @@ IBOutlet NSScrollView *_tableScrollView; IBOutlet SBTableView *_tableView; - NSMutableDictionary *_options; + IBOutlet NSWindow *_detachedWindow; NSPopover *_popover; + NSMutableDictionary *_options; NSImage *_docImg; - NSURL *_destination; SBQueue *_queue; } diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index 1745297..c71f2d7 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -110,21 +110,50 @@ static NSString *fileType = @"mp4"; - (void)initOptions { _options = [[NSMutableDictionary alloc] init]; - [_options setObject:@YES forKey:@"Organize"]; - [_options setObject:@YES forKey:@"Metadata"]; - [_options setObject:@NO forKey:@"AutoStart"]; - [_options setObject:@YES forKey:@"Optimize"]; + [_options setObject:@YES forKey:@"SBQueueOrganize"]; + [_options setObject:@YES forKey:@"SBQueueMetadata"]; + [_options setObject:@NO forKey:@"SBQueueAutoStart"]; + [_options setObject:@YES forKey:@"SBQueueOptimize"]; + + if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]) { + [_options setObject:[NSURL fileURLWithPath:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]] forKey:@"SBQueueDestination"]; + } else { + [_options setObject:nil forKey:@"SBQueueDestination"]; + } } -- (void)createPopover -{ +- (NSURL *)queueURL { + NSURL *appSupportURL = nil; + NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, + NSUserDomainMask, + YES); + if ([allPaths count]) { + appSupportURL = [NSURL fileURLWithPath:[[[allPaths lastObject] stringByAppendingPathComponent:@"Subler"] + stringByAppendingPathComponent:@"queue.sbqueue"] isDirectory:YES]; + return appSupportURL; + } else { + return nil; + } +} + +- (SBQueueStatus)status { + return self.queue.status; +} + +- (BOOL)saveQueueToDisk { + return [self.queue saveQueueToDisk]; +} + +#pragma mark - NSPopover delegate + +- (void)createPopover { if (self.popover == nil) { // create and setup our popover _popover = [[NSPopover alloc] init]; // the popover retains us and we retain the popover, // we drop the popover whenever it is closed to avoid a cycle - self.popover.contentViewController = [[SBOptionsViewController alloc] initWithOptions:self.options]; + self.popover.contentViewController = [[[SBOptionsViewController alloc] initWithOptions:self.options] autorelease]; self.popover.appearance = NSPopoverAppearanceMinimal; self.popover.animates = YES; @@ -139,32 +168,17 @@ static NSString *fileType = @"mp4"; } - (NSWindow *)detachableWindowForPopover:(NSPopover *)popover { - NSWindow *window = [[NSWindow alloc] init]; - window.contentView = popover.contentViewController.view; + _detachedWindow.contentView = [[SBOptionsViewController alloc] initWithOptions:self.options].view; - return window; + return _detachedWindow; } -- (NSURL *)queueURL { - NSURL *appSupportURL = nil; - NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, - NSUserDomainMask, - YES); - if ([allPaths count]) { - appSupportURL = [NSURL fileURLWithPath:[[[allPaths lastObject] stringByAppendingPathComponent:@"Subler"] stringByAppendingPathComponent:@"queue.sbqueue"] isDirectory:YES]; - return appSupportURL; - } else { - return nil; - } +- (void)popoverDidClose:(NSNotification *)notification { + self.popover = nil; } -- (SBQueueStatus)status { - return self.queue.status; -} +#pragma mark - UI methods -- (BOOL)saveQueueToDisk { - return [self.queue saveQueueToDisk]; -} - (void)updateDockTile { NSUInteger count = [self.queue readyCount]; @@ -247,9 +261,6 @@ static NSString *fileType = @"mp4"; [items release]; [self updateUI]; - - //if ([_autoStartOption state]) - // [self start:self]; } }]; } @@ -476,19 +487,20 @@ static NSString *fileType = @"mp4"; - (SBQueueItem *)createItemWithURL:(NSURL *)url { SBQueueItem *item = [SBQueueItem itemWithURL:url]; - if ([[self.options objectForKey:@"Metadata"] boolValue]) { + if ([[self.options objectForKey:@"SBQueueMetadata"] boolValue]) { [item addAction:[[[SBQueueMetadataAction alloc] init] autorelease]]; [item addAction:[[[SBQueueSubtitlesAction alloc] init] autorelease]]; } - if ([[self.options objectForKey:@"Organize"] boolValue]) { + if ([[self.options objectForKey:@"SBQueueOrganize"] boolValue]) { [item addAction:[[[SBQueueOrganizeGroupsAction alloc] init] autorelease]]; } - if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]) { - _destination = [NSURL fileURLWithPath:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]]; + NSURL *destination = [self.options objectForKey:@"SBQueueDestination"]; + if (destination) { + destination = [[[destination URLByAppendingPathComponent:[url lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType]; } - item.destURL = [[[_destination URLByAppendingPathComponent:[url lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType]; + item.destURL = destination; return item; } @@ -524,7 +536,7 @@ static NSString *fileType = @"mp4"; if ([undo isUndoing] || [undo isRedoing]) [self updateUI]; - if ([[self.options objectForKey:@"Autostart"] boolValue]) + if ([[self.options objectForKey:@"SBQueueAutoStart"] boolValue]) [self start:self]; [mutableIndexes release]; diff --git a/English.lproj/Queue.xib b/English.lproj/Queue.xib index 6014a9b..b10fff5 100755 --- a/English.lproj/Queue.xib +++ b/English.lproj/Queue.xib @@ -8,6 +8,7 @@ + @@ -181,6 +182,16 @@ + + + + + + + + + + diff --git a/English.lproj/QueueOptions.xib b/English.lproj/QueueOptions.xib index 863f20b..58b5379 100644 --- a/English.lproj/QueueOptions.xib +++ b/English.lproj/QueueOptions.xib @@ -5,31 +5,27 @@ - + - - - - - + - + - + - + - + + + + + @@ -101,10 +101,28 @@ - + - - + + + + + + + + + + + + + + + + + + + +