From 60490b40393fa6bccd4fa865267a87e15b65e3fc Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 18 Mar 2014 20:45:01 +0100 Subject: [PATCH] Fixed the optimize checkbox, the tableview not updating and the skeleton for a new action. --- Classes/SBQueue.m | 9 +++++---- Classes/SBQueueAction.h | 3 +++ Classes/SBQueueAction.m | 9 ++++++++- Classes/SBQueueController.m | 32 +++++++++++++++++++++++++++----- Classes/SBQueueItem.h | 2 +- Classes/SBQueueItem.m | 1 + English.lproj/Queue.xib | 2 +- English.lproj/QueueOptions.xib | 20 ++++++++++---------- 8 files changed, 56 insertions(+), 22 deletions(-) diff --git a/Classes/SBQueue.m b/Classes/SBQueue.m index f26b226..fd7ff96 100644 --- a/Classes/SBQueue.m +++ b/Classes/SBQueue.m @@ -236,7 +236,7 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; self.currentIndex = [self.items indexOfObject:self.currentItem]; self.currentItem.status = SBQueueItemStatusWorking; - [self handleSBStatusWorking:self.currentIndex]; + [self handleSBStatusWorking:0 index:self.currentIndex]; noErr = [self processItem:self.currentItem optimize:self.optimize error:&outError]; // Check results @@ -338,17 +338,18 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification"; } - (void)progressStatus:(CGFloat)progress { - [self handleSBStatusWorking:progress]; + [self handleSBStatusWorking:progress index:-1]; } /** * Processes SBQueueStatusWorking state information. Current implementation just * sends SBQueueWorkingNotification. */ -- (void)handleSBStatusWorking:(CGFloat)progress { +- (void)handleSBStatusWorking:(CGFloat)progress index:(NSInteger)index { NSString *info = [NSString stringWithFormat:@"Processing file %ld of %lu.",(long)self.currentIndex + 1, (unsigned long)[self.items count]]; [[NSNotificationCenter defaultCenter] postNotificationName:SBQueueWorkingNotification object:self userInfo:@{@"ProgressString": info, - @"Progress": @(progress)}]; + @"Progress": @(progress), + @"ItemIndex": @(index)}]; } /** diff --git a/Classes/SBQueueAction.h b/Classes/SBQueueAction.h index 7a5aacc..e16d98d 100644 --- a/Classes/SBQueueAction.h +++ b/Classes/SBQueueAction.h @@ -20,5 +20,8 @@ @interface SBQueueSubtitlesAction : NSObject @end +@interface SBQueueSetAction : NSObject +@end + @interface SBQueueOrganizeGroupsAction : NSObject @end \ No newline at end of file diff --git a/Classes/SBQueueAction.m b/Classes/SBQueueAction.m index 813cf6e..f04ccf3 100644 --- a/Classes/SBQueueAction.m +++ b/Classes/SBQueueAction.m @@ -125,7 +125,7 @@ if (artwork) [metadata.artworks addObject:artwork]; } - + return metadata; } @@ -146,6 +146,13 @@ @end +@implementation SBQueueSetAction + +- (void)runAction:(SBQueueItem *)item { +} + +@end + @implementation SBQueueOrganizeGroupsAction - (void)runAction:(SBQueueItem *)item { diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index c71f2d7..65dc557 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -86,6 +86,10 @@ static NSString *fileType = @"mp4"; [_countLabel setStringValue:[info valueForKey:@"ProgressString"]]; [_progressIndicator setIndeterminate:NO]; [_progressIndicator setDoubleValue:[[info valueForKey:@"Progress"] doubleValue]]; + + if ([[info valueForKey:@"ItemIndex"] integerValue] != -1) { + [self updateUI]; + } }]; [[NSNotificationCenter defaultCenter] addObserverForName:SBQueueCompletedNotification object:self.queue queue:mainQueue usingBlock:^(NSNotification *note) { @@ -110,6 +114,10 @@ static NSString *fileType = @"mp4"; - (void)initOptions { _options = [[NSMutableDictionary alloc] init]; + + // Observe the changes to SBQueueOptimize + [self addObserver:self forKeyPath:@"options.SBQueueOptimize" options:0 context:NULL]; + [_options setObject:@YES forKey:@"SBQueueOrganize"]; [_options setObject:@YES forKey:@"SBQueueMetadata"]; [_options setObject:@NO forKey:@"SBQueueAutoStart"]; @@ -136,6 +144,14 @@ static NSString *fileType = @"mp4"; } } +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if ([keyPath isEqualToString:@"options.SBQueueOptimize"]) { + self.queue.optimize = [[self.options objectForKey:@"SBQueueOptimize"] boolValue]; + } else { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } +} + - (SBQueueStatus)status { return self.queue.status; } @@ -154,7 +170,6 @@ static NSString *fileType = @"mp4"; // 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] autorelease]; - self.popover.appearance = NSPopoverAppearanceMinimal; self.popover.animates = YES; @@ -179,7 +194,6 @@ static NSString *fileType = @"mp4"; #pragma mark - UI methods - - (void)updateDockTile { NSUInteger count = [self.queue readyCount]; @@ -383,9 +397,17 @@ static NSString *fileType = @"mp4"; - (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem { SEL action = [anItem action]; - if (action == @selector(removeSelectedItems:)) - if ([_tableView selectedRow] != -1 || [_tableView clickedRow] != -1) - return YES; + if (action == @selector(removeSelectedItems:)) { + if ([_tableView selectedRow] != -1) { + SBQueueItem *item = [self.queue itemAtIndex:[_tableView selectedRow]]; + if ([item status] != SBQueueItemStatusWorking) + return YES; + } else if ([_tableView clickedRow] != -1) { + SBQueueItem *item = [self.queue itemAtIndex:[_tableView clickedRow]]; + if ([item status] != SBQueueItemStatusWorking) + return YES; + } + } if (action == @selector(showInFinder:)) { if ([_tableView clickedRow] != -1) { diff --git a/Classes/SBQueueItem.h b/Classes/SBQueueItem.h index 524d985..0578289 100755 --- a/Classes/SBQueueItem.h +++ b/Classes/SBQueueItem.h @@ -13,7 +13,7 @@ @class MP42File; typedef enum SBQueueItemStatus : NSInteger { - SBQueueItemtatusUnknown = 0, + SBQueueItemStatusUnknown = 0, SBQueueItemStatusReady, SBQueueItemStatusEditing, SBQueueItemStatusWorking, diff --git a/Classes/SBQueueItem.m b/Classes/SBQueueItem.m index b1e7b9a..71531df 100755 --- a/Classes/SBQueueItem.m +++ b/Classes/SBQueueItem.m @@ -37,6 +37,7 @@ self = [super init]; if (self) { _actions = [[NSMutableArray alloc] init]; + _status = SBQueueItemStatusReady; } return self; } diff --git a/English.lproj/Queue.xib b/English.lproj/Queue.xib index b10fff5..6b62a34 100755 --- a/English.lproj/Queue.xib +++ b/English.lproj/Queue.xib @@ -25,7 +25,7 @@ - + diff --git a/English.lproj/QueueOptions.xib b/English.lproj/QueueOptions.xib index 58b5379..0737706 100644 --- a/English.lproj/QueueOptions.xib +++ b/English.lproj/QueueOptions.xib @@ -14,11 +14,11 @@ - + - + @@ -101,16 +101,16 @@ - + - + - + @@ -119,7 +119,7 @@ - +