Added a set action. Plus remove some gcd code that had no benefit at all.

This commit is contained in:
Damiano Galassi committed 2014-03-19 08:32:33 +01:00
1 parent 60490b4039
commit 99553b5dfe
9 files changed
+134 -80

No files matched your search

+1
View File
@@ -10,6 +10,7 @@
@interface SBOptionsViewController : NSViewController {
IBOutlet NSPopUpButton *_destButton;
IBOutlet NSPopUpButton *_setsPopup;
NSMutableDictionary *_options;
+51 -1
View File
@@ -7,6 +7,9 @@
//
#import "SBOptionsViewController.h"
#import "SBPresetManager.h"
#import <MP42Foundation/MP42Metadata.h>
@interface SBOptionsViewController ()
@@ -40,6 +43,7 @@
- (void)loadView {
[super loadView];
[self prepareDestPopup];
[self prepareSetsPopup];
}
- (void)prepareDestPopup {
@@ -71,6 +75,47 @@
}
}
- (void)prepareSetsPopup {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateSetsMenu:)
name:@"SBPresetManagerUpdatedNotification" object:nil];
[self updateSetsMenu:self];
}
- (void)updateSetsMenu:(id)sender {
SBPresetManager *presetManager = [SBPresetManager sharedManager];
NSMenu *setListMenu = [_setsPopup menu];
[setListMenu removeAllItems];
NSMenuItem *newItem = nil;
newItem = [[[NSMenuItem alloc] initWithTitle:@"None" action:@selector(applySet:) keyEquivalent:@""] autorelease];
[newItem setTarget:self];
[newItem setTag:0];
[setListMenu addItem:newItem];
NSUInteger i = 0;
for (MP42Metadata *set in [presetManager presets]) {
newItem = [[NSMenuItem alloc] initWithTitle:set.presetName action:@selector(applySet:) keyEquivalent:@""];
[newItem setTarget:self];
[newItem setTag:i++];
[setListMenu addItem:newItem];
[newItem release];
}
if ([self.options objectForKey:@"SBQueueSet"]) {
[_setsPopup selectItemWithTitle:[[self.options objectForKey:@"SBQueueSet"] presetName]];
}
}
- (void)applySet:(id)sender {
[self.options setObject:[[SBPresetManager sharedManager].presets objectAtIndex:[sender tag]] forKey:@"SBQueueSet"];
}
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem {
SEL action = [anItem action];
@@ -79,7 +124,10 @@
if (action == @selector(destination:))
return YES;
if (action == @selector(applySet:))
return YES;
return NO;
}
@@ -134,7 +182,9 @@
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver: self];
[_options release];
[super dealloc];
}
-1
View File
@@ -29,7 +29,6 @@ extern NSString *SBQueueCancelledNotification;
@interface SBQueue : NSObject {
@private
dispatch_queue_t _workQueue;
dispatch_queue_t _itemsQueue;
SBQueueStatus _status;
SBQueueItem *_currentItem;
+26 -63
View File
@@ -32,7 +32,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
@property (atomic) BOOL cancelled;
@property (nonatomic) dispatch_queue_t workQueue;
@property (nonatomic) dispatch_queue_t itemsQueue;
@end
@@ -42,13 +41,12 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
@synthesize optimize = _optimize;
@synthesize currentItem = _currentItem, currentIndex = _currentIndex;
@synthesize cancelled = _cancelled;
@synthesize items = _items, itemsQueue = _itemsQueue, URL = _URL, workQueue = _workQueue;
@synthesize items = _items, URL = _URL, workQueue = _workQueue;
- (instancetype)initWithURL:(NSURL *)queueURL {
self = [super init];
if (self) {
_workQueue = dispatch_queue_create("org.subler.WorkQueue", NULL);
_itemsQueue = dispatch_queue_create("org.subler.ItemsQueue", NULL);
_URL = [queueURL copy];
if ([[NSFileManager defaultManager] fileExistsAtPath:[queueURL path]]) {
@@ -74,21 +72,17 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
}
- (BOOL)saveQueueToDisk {
__block BOOL noErr = YES;
dispatch_sync(self.itemsQueue, ^{
noErr = [NSKeyedArchiver archiveRootObject:self.items toFile:[self.URL path]];
});
return noErr;
return [NSKeyedArchiver archiveRootObject:self.items toFile:[self.URL path]];
}
- (SBQueueItem *)firstItemInQueue
{
- (SBQueueItem *)firstItemInQueue {
__block SBQueueItem *firstItem = nil;
dispatch_sync(self.itemsQueue, ^{
dispatch_sync(dispatch_get_main_queue(), ^{
for (SBQueueItem *item in self.items) {
if ((item.status != SBQueueItemStatusCompleted) && (item.status != SBQueueItemStatusFailed)) {
firstItem = [item retain];
firstItem.status = SBQueueItemStatusWorking;
break;
}
}
@@ -99,93 +93,63 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
#pragma mark - item management
- (void)addItem:(SBQueueItem *)item {
dispatch_sync(self.itemsQueue, ^{
[self.items addObject:item];
});
[self.items addObject:item];
}
- (NSUInteger)count {
__block NSUInteger count = 0;
dispatch_sync(self.itemsQueue, ^{
count = [self.items count];
});
return count;
return [self.items count];
}
- (NSUInteger)readyCount {
__block NSUInteger count = 0;
dispatch_sync(self.itemsQueue, ^{
for (SBQueueItem *item in self.items)
if ([item status] != SBQueueItemStatusCompleted)
count++;
});
NSUInteger count = 0;
for (SBQueueItem *item in self.items)
if ([item status] != SBQueueItemStatusCompleted)
count++;
return count;
}
- (SBQueueItem *)itemAtIndex:(NSUInteger)index {
__block SBQueueItem *item = nil;
dispatch_sync(self.itemsQueue, ^{
item = [self.items objectAtIndex:index];
});
return item;
return [self.items objectAtIndex:index];
}
- (NSArray *)itemsAtIndexes:(NSIndexSet *)indexes {
__block NSArray *items = nil;
dispatch_sync(self.itemsQueue, ^{
items = [self.items objectsAtIndexes:indexes];
});
return items;
return [self.items objectsAtIndexes:indexes];
}
- (NSUInteger)indexOfItem:(SBQueueItem *)item {
__block NSUInteger index = NSNotFound;
dispatch_sync(self.itemsQueue, ^{
index = [self.items indexOfObject:item];
});
return index;
return [self.items indexOfObject:item];
}
- (NSIndexSet *)indexesOfItemsWithStatus:(SBQueueItemStatus)status {
NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
dispatch_sync(self.itemsQueue, ^{
[self.items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (((SBQueueItem *)obj).status == status) {
[indexes addIndex:idx];
}
}];
});
[self.items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (((SBQueueItem *)obj).status == status) {
[indexes addIndex:idx];
}
}];
return indexes;
}
- (void)insertItem:(SBQueueItem *)anItem atIndex:(NSUInteger)index {
dispatch_sync(self.itemsQueue, ^{
[self.items insertObject:anItem atIndex:index];
});
[self.items insertObject:anItem atIndex:index];
}
- (void)removeItemsAtIndexes:(NSIndexSet *)indexes {
dispatch_sync(self.itemsQueue, ^{
[self.items removeObjectsAtIndexes:indexes];
});
[self.items removeObjectsAtIndexes:indexes];
}
- (void)removeItem:(SBQueueItem *)item {
dispatch_sync(self.itemsQueue, ^{
[self.items removeObject:item];
});
[self.items removeObject:item];
}
- (NSIndexSet *)removeCompletedItems {
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
dispatch_sync(self.itemsQueue, ^{
for (SBQueueItem *item in self.items)
if ([item status] == SBQueueItemStatusCompleted)
[indexes addIndex:[self.items indexOfObject:item]];
for (SBQueueItem *item in self.items)
if ([item status] == SBQueueItemStatusCompleted)
[indexes addIndex:[self.items indexOfObject:item]];
[self.items removeObjectsAtIndexes:indexes];
});
[self.items removeObjectsAtIndexes:indexes];
return [indexes autorelease];
}
@@ -381,7 +345,6 @@ NSString *SBQueueCancelledNotification = @"SBQueueCancelledNotification";
- (void)dealloc {
dispatch_release(_workQueue);
dispatch_release(_itemsQueue);
[_items release];
[_URL release];
+5 -1
View File
@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h>
@class SBQueueItem;
@class MP42Metadata;
@protocol SBQueueActionProtocol <NSObject>
- (void)runAction:(SBQueueItem *)item;
@@ -20,7 +21,10 @@
@interface SBQueueSubtitlesAction : NSObject <SBQueueActionProtocol>
@end
@interface SBQueueSetAction : NSObject <SBQueueActionProtocol>
@interface SBQueueSetAction : NSObject <SBQueueActionProtocol> {
MP42Metadata *_set;
}
- (id)initWithSet:(MP42Metadata *)set;
@end
@interface SBQueueOrganizeGroupsAction : NSObject <SBQueueActionProtocol>
+9
View File
@@ -148,7 +148,16 @@
@implementation SBQueueSetAction
- (id)initWithSet:(MP42Metadata *)set {
self = [super init];
if (self) {
_set = [set retain];
}
return self;
}
- (void)runAction:(SBQueueItem *)item {
[item.mp4File.metadata mergeMetadata:_set];
}
@end
+5 -2
View File
@@ -125,8 +125,6 @@ static NSString *fileType = @"mp4";
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]) {
[_options setObject:[NSURL fileURLWithPath:[[NSUserDefaults standardUserDefaults] valueForKey:@"SBQueueDestination"]] forKey:@"SBQueueDestination"];
} else {
[_options setObject:nil forKey:@"SBQueueDestination"];
}
}
@@ -517,6 +515,11 @@ static NSString *fileType = @"mp4";
[item addAction:[[[SBQueueOrganizeGroupsAction alloc] init] autorelease]];
}
if ([self.options objectForKey:@"SBQueueSet"]) {
[item addAction:[[[SBQueueSetAction alloc] initWithSet:[self.options objectForKey:@"SBQueueSet"]] autorelease]];
}
NSURL *destination = [self.options objectForKey:@"SBQueueDestination"];
if (destination) {
destination = [[[destination URLByAppendingPathComponent:[url lastPathComponent]] URLByDeletingPathExtension] URLByAppendingPathExtension:fileType];
+4 -4
View File
@@ -182,13 +182,13 @@
</connections>
</menu>
<userDefaultsController representsSharedInstance="YES" id="46"/>
<window title="Queue Options" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="zHc-NF-Zeh" userLabel="Window - Detached Options">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<window title="Queue Options" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="zHc-NF-Zeh" userLabel="Window - Detached Options" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES" utility="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="283" y="305" width="316" height="133"/>
<rect key="contentRect" x="283" y="305" width="321" height="173"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/>
<view key="contentView" id="hhb-jZ-DWa">
<rect key="frame" x="0.0" y="0.0" width="316" height="133"/>
<rect key="frame" x="0.0" y="0.0" width="321" height="173"/>
<autoresizingMask key="autoresizingMask"/>
</view>
</window>
+33 -8
View File
@@ -8,13 +8,14 @@
<customObject id="-2" userLabel="File's Owner" customClass="SBOptionsViewController">
<connections>
<outlet property="_destButton" destination="86l-GG-SpO" id="bE1-31-17X"/>
<outlet property="_setsPopup" destination="DVM-Js-DwK" id="971-id-uEe"/>
<outlet property="view" destination="UlG-O3-eNc" id="hzl-ex-WZi"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application"/>
<customView id="UlG-O3-eNc" userLabel="OptionsView">
<rect key="frame" x="0.0" y="0.0" width="321" height="143"/>
<rect key="frame" x="0.0" y="0.0" width="321" height="173"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button id="zEH-aV-Tl7">
@@ -33,7 +34,7 @@
</connections>
</button>
<button id="9GN-f6-r2j">
<rect key="frame" x="111" y="107" width="103" height="18"/>
<rect key="frame" x="111" y="137" width="103" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Fetch Metadata" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" state="on" inset="2" id="QNO-e1-WUJ">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -63,7 +64,7 @@
</connections>
</button>
<button id="ccd-Xn-Dj3">
<rect key="frame" x="111" y="89" width="112" height="18"/>
<rect key="frame" x="111" y="119" width="112" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Organize Groups" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" state="on" inset="2" id="240-c7-2UW">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
@@ -78,12 +79,12 @@
</connections>
</button>
<popUpButton verticalHuggingPriority="750" id="86l-GG-SpO">
<rect key="frame" x="171" y="65" width="133" height="22"/>
<rect key="frame" x="171" y="95" width="133" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="8bb-Gy-KAS">
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" autoenablesItems="NO" id="8bb-Gy-KAS">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<menu key="menu" title="OtherViews" id="BBw-yf-xUC">
<menu key="menu" title="OtherViews" autoenablesItems="NO" id="BBw-yf-xUC">
<items>
<menuItem title="Same as file" id="WKY-e5-5Mn">
<connections>
@@ -101,7 +102,7 @@
</popUpButtonCell>
</popUpButton>
<textField verticalHuggingPriority="750" id="vJ5-JB-k1m">
<rect key="frame" x="112" y="70" width="56" height="14"/>
<rect key="frame" x="112" y="100" width="56" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Location:" id="17e-9u-rVn">
<font key="font" metaFont="smallSystemBold"/>
@@ -109,6 +110,15 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" id="NhN-Lg-awX">
<rect key="frame" x="112" y="74" width="61" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Apply Set:" id="9gt-mI-zIV">
<font key="font" metaFont="smallSystemBold"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" id="Uoo-hZ-D1f">
<rect key="frame" x="18" y="37" width="90" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -119,7 +129,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" id="S7L-mA-j3Y">
<rect key="frame" x="49" y="109" width="59" height="14"/>
<rect key="frame" x="49" y="139" width="59" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Add item:" id="9ls-xq-YGz">
<font key="font" metaFont="smallSystemBold"/>
@@ -127,6 +137,21 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<popUpButton verticalHuggingPriority="750" id="DVM-Js-DwK">
<rect key="frame" x="176" y="69" width="128" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" controlSize="small" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="w3H-dW-Kp2" id="bQx-xN-b3H">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<menu key="menu" title="OtherViews" id="4en-ZA-qlS">
<items>
<menuItem title="Item 1" state="on" id="w3H-dW-Kp2"/>
<menuItem title="Item 2" id="fk2-Cj-YDq"/>
<menuItem title="Item 3" id="Zeq-hi-goU"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
</subviews>
</customView>
</objects>