From 75e5b85cfcc8f09af72a7fd0df15ab98c0ef1bab Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Wed, 19 Mar 2014 12:33:44 +0100 Subject: [PATCH] =?UTF-8?q?Added=20another=20popover=20with=20some=20queue?= =?UTF-8?q?=E2=80=99s=20item=20info.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/SBItemViewController.h | 26 +++++++++ Classes/SBItemViewController.m | 75 ++++++++++++++++++++++++++ Classes/SBOptionsViewController.h | 1 + Classes/SBQueueController.h | 12 +---- Classes/SBQueueController.m | 76 ++++++++++++++++++++++---- Classes/SBQueueItem.h | 4 +- Classes/SBQueueItem.m | 9 +++- English.lproj/Queue.xib | 53 +++++++++++------- English.lproj/QueueItem.xib | 89 +++++++++++++++++++++++++++++++ English.lproj/QueueOptions.xib | 14 ++--- Subler.xcodeproj/project.pbxproj | 18 +++++++ 11 files changed, 325 insertions(+), 52 deletions(-) create mode 100644 Classes/SBItemViewController.h create mode 100644 Classes/SBItemViewController.m create mode 100644 English.lproj/QueueItem.xib diff --git a/Classes/SBItemViewController.h b/Classes/SBItemViewController.h new file mode 100644 index 0000000..1e35c55 --- /dev/null +++ b/Classes/SBItemViewController.h @@ -0,0 +1,26 @@ +// +// SBItemViewController.h +// Subler +// +// Created by Damiano Galassi on 19/03/14. +// +// + +#import + +@class SBQueueItem; + +@interface SBItemViewController : NSViewController { + @private + SBQueueItem *_item; + + NSTextField *_nameLabel; + NSTextField *_sourceLabel; + NSTextField *_destinationLabel; + + NSTextField *_actionsLabel; +} + +- (instancetype)initWithItem:(SBQueueItem *)item; + +@end diff --git a/Classes/SBItemViewController.m b/Classes/SBItemViewController.m new file mode 100644 index 0000000..867d5eb --- /dev/null +++ b/Classes/SBItemViewController.m @@ -0,0 +1,75 @@ +// +// SBItemViewController.m +// Subler +// +// Created by Damiano Galassi on 19/03/14. +// +// + +#import "SBItemViewController.h" +#import "SBQueueItem.h" + +@interface SBItemViewController () + +@property SBQueueItem *item; + +@property (assign) IBOutlet NSTextField *nameLabel; +@property (assign) IBOutlet NSTextField *sourceLabel; +@property (assign) IBOutlet NSTextField *destinationLabel; + +@property (assign) IBOutlet NSTextField *actionsLabel; + +@end + +@implementation SBItemViewController + +@synthesize item = _item; + +@synthesize nameLabel = _nameLabel; +@synthesize sourceLabel = _sourceLabel; +@synthesize destinationLabel = _destinationLabel; + +@synthesize actionsLabel = _actionsLabel; + +- (instancetype)initWithItem:(SBQueueItem *)item { + self = [self init]; + if (self) { + _item = [item retain]; + } + return self; +} + +- (instancetype)init { + self = [super initWithNibName:@"QueueItem" bundle:nil]; + return self; +} + +- (void)loadView { + [super loadView]; + + [self.nameLabel setStringValue:[self.item.URL lastPathComponent]]; + [self.sourceLabel setStringValue:[self.item.URL path]]; + [self.destinationLabel setStringValue:[self.item.destURL path]]; + + NSMutableString *actions = [[NSMutableString alloc] init]; + for (id action in self.item.actionsArray) { + [actions appendString:[NSString stringWithFormat:@"%@\n", [action description]]]; + } + + if ([actions length]) { + [self.actionsLabel setStringValue:actions]; + } else { + [self.actionsLabel setStringValue:@"None"]; + } + + NSSize frameSize = self.view.frame.size; + frameSize.height += [self.item.actionsArray count] ? self.actionsLabel.frame.size.height * ([self.item.actionsArray count] - 1) : 0; + [self.view setFrameSize:frameSize]; +} + +- (void)dealloc { + [_item release]; + [super dealloc]; +} + +@end diff --git a/Classes/SBOptionsViewController.h b/Classes/SBOptionsViewController.h index 914838c..98aaef5 100644 --- a/Classes/SBOptionsViewController.h +++ b/Classes/SBOptionsViewController.h @@ -9,6 +9,7 @@ #import @interface SBOptionsViewController : NSViewController { + @private IBOutlet NSPopUpButton *_destButton; IBOutlet NSPopUpButton *_setsPopup; diff --git a/Classes/SBQueueController.h b/Classes/SBQueueController.h index 7573778..6b010cb 100755 --- a/Classes/SBQueueController.h +++ b/Classes/SBQueueController.h @@ -26,6 +26,7 @@ IBOutlet NSWindow *_detachedWindow; NSPopover *_popover; + NSPopover *_itemPopover; NSMutableDictionary *_options; NSImage *_docImg; @@ -41,15 +42,4 @@ - (BOOL)saveQueueToDisk; -- (IBAction)removeSelectedItems:(id)sender; -- (IBAction)removeCompletedItems:(id)sender; - -- (IBAction)edit:(id)sender; -- (IBAction)showInFinder:(id)sender; - -- (IBAction)toggleStartStop:(id)sender; -- (IBAction)toggleOptions:(id)sender; - -- (IBAction)open:(id)sender; - @end diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index 1a72160..4798658 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -8,6 +8,7 @@ #import "SBQueueController.h" #import "SBOptionsViewController.h" +#import "SBItemViewController.h" #import "SBQueueItem.h" #import "SBDocument.h" @@ -18,6 +19,7 @@ #import static NSString *fileType = @"mp4"; +static void *SBQueueContex = &SBQueueContex; #define SublerBatchTableViewDataType @"SublerBatchTableViewDataType" #define kOptionsPanelHeight 88 @@ -26,9 +28,22 @@ static NSString *fileType = @"mp4"; @property (readonly) SBQueue *queue; @property NSPopover *popover; +@property NSPopover *itemPopover; @property NSMutableDictionary *options; +- (IBAction)removeSelectedItems:(id)sender; +- (IBAction)removeCompletedItems:(id)sender; + +- (IBAction)edit:(id)sender; +- (IBAction)showInFinder:(id)sender; + +- (IBAction)toggleStartStop:(id)sender; +- (IBAction)toggleOptions:(id)sender; +- (IBAction)toggleItemsOptions:(id)sender; + +- (IBAction)open:(id)sender; + - (void)start:(id)sender; - (void)stop:(id)sender; @@ -46,6 +61,7 @@ static NSString *fileType = @"mp4"; @synthesize queue = _queue; @synthesize popover = _popover; +@synthesize itemPopover = _itemPopover; @synthesize options = _options; + (SBQueueController *)sharedManager { @@ -71,8 +87,8 @@ static NSString *fileType = @"mp4"; [super windowDidLoad]; [_progressIndicator setHidden:YES]; - [_countLabel setStringValue:@"Empty"]; + // Load a generic movie icon to display in the table view _docImg = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode('MOOV')] retain]; [_docImg setSize:NSMakeSize(16, 16)]; @@ -112,6 +128,7 @@ static NSString *fileType = @"mp4"; [NSApp presentError:[info valueForKey:@"Error"]]; }]; + // Update the UI the first time [self updateUI]; } @@ -158,7 +175,7 @@ static NSString *fileType = @"mp4"; } // Observe the changes to SBQueueOptimize - [self addObserver:self forKeyPath:@"options.SBQueueOptimize" options:NSKeyValueObservingOptionInitial context:NULL]; + [self addObserver:self forKeyPath:@"options.SBQueueOptimize" options:NSKeyValueObservingOptionInitial context:SBQueueContex]; } - (NSURL *)queueURL { @@ -176,8 +193,10 @@ 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]; + if (context == SBQueueContex) { + if ([keyPath isEqualToString:@"options.SBQueueOptimize"]) { + self.queue.optimize = [[self.options objectForKey:@"SBQueueOptimize"] boolValue]; + } } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } @@ -214,14 +233,41 @@ static NSString *fileType = @"mp4"; } } -- (NSWindow *)detachableWindowForPopover:(NSPopover *)popover { - _detachedWindow.contentView = [[SBOptionsViewController alloc] initWithOptions:self.options].view; +- (void)createItemPopover:(SBQueueItem *)item { + _itemPopover = [[NSPopover alloc] init]; - return _detachedWindow; + // the popover retains us and we retain the popover, + // we drop the popover whenever it is closed to avoid a cycle + self.itemPopover.contentViewController = [[[SBItemViewController alloc] initWithItem:item] autorelease]; + self.itemPopover.appearance = NSPopoverAppearanceMinimal; + self.itemPopover.animates = YES; + + // AppKit will close the popover when the user interacts with a user interface element outside the popover. + // note that interacting with menus or panels that become key only when needed will not cause a transient popover to close. + self.itemPopover.behavior = NSPopoverBehaviorSemitransient; + + // so we can be notified when the popover appears or closes + self.itemPopover.delegate = self; + +} + +- (NSWindow *)detachableWindowForPopover:(NSPopover *)popover { + if (popover == self.popover) { + _detachedWindow.contentView = [[SBOptionsViewController alloc] initWithOptions:self.options].view; + return _detachedWindow; + } + return nil; } - (void)popoverDidClose:(NSNotification *)notification { - self.popover = nil; + if (self.popover) { + self.popover.contentViewController = nil; + self.popover = nil; + } + if (self.itemPopover) { + self.itemPopover.contentViewController = nil; + self.itemPopover = nil; + } } #pragma mark - UI methods @@ -255,7 +301,7 @@ static NSString *fileType = @"mp4"; [self.queue start]; } -- (void)progressStatus: (CGFloat)progress { +- (void)progressStatus:(CGFloat)progress { dispatch_async(dispatch_get_main_queue(), ^{ [_progressIndicator setIndeterminate:NO]; [_progressIndicator setDoubleValue:progress]; @@ -285,6 +331,18 @@ static NSString *fileType = @"mp4"; } } +- (IBAction)toggleItemsOptions:(id)sender { + NSInteger clickedRow = [sender clickedRow]; + + [self createItemPopover:[self.queue itemAtIndex:clickedRow]]; + + if (!self.itemPopover.isShown) { + [self.itemPopover showRelativeToRect:[sender frameOfCellAtColumn:2 row:clickedRow] ofView:sender preferredEdge:NSMaxXEdge]; + } else { + [self.itemPopover close]; + } +} + #pragma mark Open methods - (IBAction)open:(id)sender { diff --git a/Classes/SBQueueItem.h b/Classes/SBQueueItem.h index 0578289..b763b58 100755 --- a/Classes/SBQueueItem.h +++ b/Classes/SBQueueItem.h @@ -35,7 +35,9 @@ typedef enum SBQueueItemStatus : NSInteger { @property (nonatomic, readonly) MP42File *mp4File; @property (nonatomic, readonly) NSDictionary *attributes; @property (nonatomic, readonly) NSURL *URL; -@property (nonatomic, copy, readwrite) NSURL *destURL; +@property (nonatomic, copy) NSURL *destURL; + +@property (nonatomic, readonly) NSArray *actionsArray; @property (nonatomic, readwrite) SBQueueItemStatus status; diff --git a/Classes/SBQueueItem.m b/Classes/SBQueueItem.m index 71531df..651ed56 100755 --- a/Classes/SBQueueItem.m +++ b/Classes/SBQueueItem.m @@ -16,7 +16,6 @@ @interface SBQueueItem () @property (nonatomic, readwrite, retain) MP42File *mp4File; - @property (nonatomic, readwrite) NSMutableArray *actions; @end @@ -114,6 +113,10 @@ } } +- (NSArray *)actionsArray { + return [self.actions copy]; +} + - (void)addAction:(id)action { [self.actions addObject:action]; } @@ -176,12 +179,13 @@ } - (void)encodeWithCoder:(NSCoder *)coder { - [coder encodeInt:1 forKey:@"SBQueueItemTagEncodeVersion"]; + [coder encodeInt:2 forKey:@"SBQueueItemTagEncodeVersion"]; [coder encodeObject:_mp4File forKey:@"SBQueueItemMp4File"]; [coder encodeObject:_fileURL forKey:@"SBQueueItemFileURL"]; [coder encodeObject:_destURL forKey:@"SBQueueItemDestURL"]; [coder encodeObject:_attributes forKey:@"SBQueueItemAttributes"]; + [coder encodeObject:_actions forKey:@"SBQueueItemActions"]; [coder encodeInt:_status forKey:@"SBQueueItemStatus"]; } @@ -194,6 +198,7 @@ _fileURL = [[decoder decodeObjectForKey:@"SBQueueItemFileURL"] retain]; _destURL = [[decoder decodeObjectForKey:@"SBQueueItemDestURL"] retain]; _attributes = [[decoder decodeObjectForKey:@"SBQueueItemAttributes"] retain]; + _actions = [[decoder decodeObjectForKey:@"SBQueueItemActions"] retain]; _status = [decoder decodeIntForKey:@"SBQueueItemStatus"]; diff --git a/English.lproj/Queue.xib b/English.lproj/Queue.xib index 5db2d9e..c6be3d3 100755 --- a/English.lproj/Queue.xib +++ b/English.lproj/Queue.xib @@ -23,51 +23,66 @@ - + - + - + - + - + - - + + - + - + - - + + - + + + + + + + + + + + + + + + + @@ -79,7 +94,7 @@ - + - + @@ -104,7 +119,7 @@ - + diff --git a/English.lproj/QueueItem.xib b/English.lproj/QueueItem.xib new file mode 100644 index 0000000..46d4dfa --- /dev/null +++ b/English.lproj/QueueItem.xib @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/English.lproj/QueueOptions.xib b/English.lproj/QueueOptions.xib index b82f199..57cea91 100644 --- a/English.lproj/QueueOptions.xib +++ b/English.lproj/QueueOptions.xib @@ -49,9 +49,9 @@