Added another popover with some queue’s item info.

This commit is contained in:
Damiano Galassi committed 2014-03-19 12:33:44 +01:00
1 parent e71c5a93cd
commit 75e5b85cfc
11 files changed
+325 -52

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
//
// SBItemViewController.h
// Subler
//
// Created by Damiano Galassi on 19/03/14.
//
//
#import <Cocoa/Cocoa.h>
@class SBQueueItem;
@interface SBItemViewController : NSViewController {
@private
SBQueueItem *_item;
NSTextField *_nameLabel;
NSTextField *_sourceLabel;
NSTextField *_destinationLabel;
NSTextField *_actionsLabel;
}
- (instancetype)initWithItem:(SBQueueItem *)item;
@end
+75
View File
@@ -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<SBQueueActionProtocol> 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
+1
View File
@@ -9,6 +9,7 @@
#import <Cocoa/Cocoa.h>
@interface SBOptionsViewController : NSViewController {
@private
IBOutlet NSPopUpButton *_destButton;
IBOutlet NSPopUpButton *_setsPopup;
+1 -11
View File
@@ -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
+67 -9
View File
@@ -8,6 +8,7 @@
#import "SBQueueController.h"
#import "SBOptionsViewController.h"
#import "SBItemViewController.h"
#import "SBQueueItem.h"
#import "SBDocument.h"
@@ -18,6 +19,7 @@
#import <MP42Foundation/MP42Metadata.h>
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 {
+3 -1
View File
@@ -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;
+7 -2
View File
@@ -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<SBQueueActionProtocol>)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"];