From 1af529aa9640868042217038fd6727054a00711c Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 11 Oct 2009 23:16:46 +0000 Subject: [PATCH] phase one of moving quicklook into the controller - it's not as pretty code-wise but the behavior is a lot more consistent --- macosx/Controller.h | 7 ++- macosx/Controller.m | 76 ++++++++++++++++++++++++ macosx/InfoWindowController.h | 8 ++- macosx/InfoWindowController.m | 107 ++++++++++++---------------------- macosx/TorrentTableView.h | 7 +-- macosx/TorrentTableView.m | 69 ---------------------- 6 files changed, 125 insertions(+), 149 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index 490aaf8bd..f95c27d8b 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -24,6 +24,7 @@ #import #import +#import #import @class AddWindowController; @@ -46,7 +47,8 @@ typedef enum ADD_CREATED } addType; -@interface Controller : NSObject +#warning uncomment +@interface Controller : NSObject //, QLPreviewPanelDataSource, QLPreviewPanelDelegate> { tr_session * fLib; @@ -108,6 +110,9 @@ typedef enum NSMutableDictionary * fPendingTorrentDownloads; BOOL fSoundPlaying; + + #warning change to QLPreviewPanel + id fPreviewPanel; } - (void) openFiles: (NSArray *) filenames addType: (addType) type forcePath: (NSString *) path; diff --git a/macosx/Controller.m b/macosx/Controller.m index b0b8c7189..fa901069b 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -3117,6 +3117,82 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy [self toggleFilterBar: self]; } +#warning change from id to QLPreviewPanel +- (BOOL) acceptsPreviewPanelControl: (id) panel +{ + return YES; +} + +- (void) beginPreviewPanelControl: (id) panel +{ + fPreviewPanel = [panel retain]; + [fPreviewPanel setDelegate: self]; + [fPreviewPanel setDataSource: self]; +} + +- (void) endPreviewPanelControl: (id) panel +{ + [fPreviewPanel release]; + fPreviewPanel = nil; +} + +- (NSInteger) numberOfPreviewItemsInPreviewPanel: (id) panel +{ + if ([fInfoController canQuickLook]) + return [[fInfoController quickLookURLs] count]; + else + return [[self quickLookableTorrents] count]; +} + +- (id /**/) previewPanel: (id) panel previewItemAtIndex: (NSInteger) index +{ + if ([fInfoController canQuickLook]) + return [[fInfoController quickLookURLs] objectAtIndex: index]; + else + return [[self quickLookableTorrents] objectAtIndex: index]; +} + +- (BOOL) previewPanel: (id) panel handleEvent: (NSEvent *) event +{ + /*if ([event type] == NSKeyDown) + { + [super keyDown: event]; + return YES; + }*/ + + return NO; +} + +- (NSRect) previewPanel: (id) panel sourceFrameOnScreenForPreviewItem: (id /**/) item +{ + if ([fInfoController canQuickLook]) + return [fInfoController quickLookSourceFrameForPreviewItem: item]; + else + { + const NSInteger row = [fTableView rowForItem: item]; + if (row == -1) + return NSZeroRect; + + NSRect frame = [fTableView iconRectForRow: row]; + frame.origin = [fTableView convertPoint: frame.origin toView: nil]; + frame.origin = [fWindow convertBaseToScreen: frame.origin]; + frame.origin.y -= frame.size.height; + return frame; + } +} + +- (NSArray *) quickLookableTorrents +{ + NSArray * selectedTorrents = [fTableView selectedTorrents]; + NSMutableArray * qlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]]; + + for (Torrent * torrent in selectedTorrents) + if (([torrent isFolder] || [torrent isComplete]) && [[NSFileManager defaultManager] fileExistsAtPath: [torrent dataLocation]]) + [qlArray addObject: torrent]; + + return qlArray; +} + - (ButtonToolbarItem *) standardToolbarButtonWithIdentifier: (NSString *) ident { ButtonToolbarItem * item = [[ButtonToolbarItem alloc] initWithItemIdentifier: ident]; diff --git a/macosx/InfoWindowController.h b/macosx/InfoWindowController.h index e88d3f08f..80436e960 100644 --- a/macosx/InfoWindowController.h +++ b/macosx/InfoWindowController.h @@ -24,7 +24,6 @@ #import #import -#import @class Torrent; @class TrackerTableView; @@ -32,8 +31,7 @@ @class FileOutlineController; @class PiecesView; -#warning uncomment -@interface InfoWindowController : NSWindowController // +@interface InfoWindowController : NSWindowController { NSArray * fTorrents; @@ -94,6 +92,10 @@ - (void) addRemoveTracker: (id) sender; +- (NSArray *) quickLookURLs; +- (BOOL) canQuickLook; +- (NSRect) quickLookSourceFrameForPreviewItem: (id /**/) item; + - (void) setPiecesView: (id) sender; - (void) setPiecesViewForAvailable: (BOOL) available; diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 543b90953..f5bffd8d7 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -86,8 +86,6 @@ typedef enum - (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate; - (NSArray *) peerSortDescriptors; -- (NSArray *) quickLookURLs; -- (BOOL) canQuickLook; - (BOOL) canQuickLookFile: (FileListNode *) item; - (void) addTrackers; @@ -814,6 +812,7 @@ typedef enum [[window contentView] addSubview: view]; [view setHidden: NO]; + #warning take a look at if ([NSApp isOnSnowLeopardOrBetter] && (fCurrentTabTag == TAB_FILES_TAG || oldTabTag == TAB_FILES_TAG) && ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible])) [[QLPreviewPanelSL sharedPreviewPanel] updateController]; @@ -1120,47 +1119,48 @@ typedef enum return [[fTrackers objectAtIndex: i] intValue] == 0; }*/ -#warning change to QLPreviewPanel -- (BOOL) acceptsPreviewPanelControl: (id) panel +- (NSArray *) quickLookURLs { - return fCurrentTabTag == TAB_FILES_TAG && [self canQuickLook]; -} - -- (void) beginPreviewPanelControl: (id) panel -{ - fPreviewPanel = [panel retain]; - [fPreviewPanel setDelegate: self]; - [fPreviewPanel setDataSource: self]; -} - -- (void) endPreviewPanelControl: (id) panel -{ - [fPreviewPanel release]; - fPreviewPanel = nil; -} - -- (NSInteger) numberOfPreviewItemsInPreviewPanel: (id) panel -{ - return [[self quickLookURLs] count]; -} - -- (id /**/) previewPanel: (id)panel previewItemAtIndex: (NSInteger) index -{ - return [[self quickLookURLs] objectAtIndex: index]; -} - -- (BOOL) previewPanel: (id) panel handleEvent: (NSEvent *) event -{ - if ([event type] == NSKeyDown) + FileOutlineView * fileOutlineView = [fFileController outlineView]; + Torrent * torrent = [fTorrents objectAtIndex: 0]; + NSString * folder = [torrent downloadFolder]; + NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; + NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]]; + + for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) { - [super keyDown: event]; - return YES; + FileListNode * item = [fileOutlineView itemAtRow: i]; + if ([self canQuickLookFile: item]) + [urlArray addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [item fullPath]]]]; } + return urlArray; +} + +- (BOOL) canQuickLook +{ + if (fCurrentTabTag != TAB_FILES_TAG || ![NSApp isOnSnowLeopardOrBetter]) + return NO; + + if ([fTorrents count] != 1) + return NO; + + Torrent * torrent = [fTorrents objectAtIndex: 0]; + if (![torrent isFolder]) + return NO; + + FileOutlineView * fileOutlineView = [fFileController outlineView]; + NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; + + for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) + if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]]) + return YES; + return NO; } -- (NSRect) previewPanel: (id) panel sourceFrameOnScreenForPreviewItem: (id /**/) item +#warning uncomment (in header too) +- (NSRect) quickLookSourceFrameForPreviewItem: (id /**/) item { FileOutlineView * fileOutlineView = [fFileController outlineView]; @@ -1652,39 +1652,6 @@ typedef enum return descriptors; } -- (NSArray *) quickLookURLs -{ - FileOutlineView * fileOutlineView = [fFileController outlineView]; - Torrent * torrent = [fTorrents objectAtIndex: 0]; - NSString * folder = [torrent downloadFolder]; - NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; - NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]]; - - for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) - { - FileListNode * item = [fileOutlineView itemAtRow: i]; - if ([self canQuickLookFile: item]) - [urlArray addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [item fullPath]]]]; - } - - return urlArray; -} - -- (BOOL) canQuickLook -{ - if (![NSApp isOnSnowLeopardOrBetter]) - return NO; - - FileOutlineView * fileOutlineView = [fFileController outlineView]; - NSIndexSet * indexes = [fileOutlineView selectedRowIndexes]; - - for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i]) - if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]]) - return YES; - - return NO; -} - - (BOOL) canQuickLookFile: (FileListNode *) item { Torrent * torrent = [fTorrents objectAtIndex: 0]; @@ -1692,7 +1659,7 @@ typedef enum if (![[NSFileManager defaultManager] fileExistsAtPath: [[torrent downloadFolder] stringByAppendingPathComponent: [item fullPath]]]) return NO; - return [item isFolder] || [torrent fileProgress: item] == 1.0; + return [item isFolder] || [torrent fileProgress: item] >= 1.0; } #warning doesn't like blank addresses diff --git a/macosx/TorrentTableView.h b/macosx/TorrentTableView.h index f306c9ef8..1fa42c40c 100644 --- a/macosx/TorrentTableView.h +++ b/macosx/TorrentTableView.h @@ -24,7 +24,6 @@ #import #import -#import @class Controller; @class Torrent; @@ -32,8 +31,7 @@ #define GROUP_SEPARATOR_HEIGHT 18.0 -#warning uncomment -@interface TorrentTableView : NSOutlineView // +@interface TorrentTableView : NSOutlineView { IBOutlet Controller * fController; @@ -54,9 +52,6 @@ CGFloat fPiecesBarPercent; NSAnimation * fPiecesBarAnimation; - - #warning change to QLPreviewPanel - id fPreviewPanel; } - (BOOL) isGroupCollapsed: (NSInteger) value; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index d03b1ed4e..3d9ab2be3 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -50,8 +50,6 @@ - (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files; -- (NSArray *) quickLookableTorrents; - @end @implementation TorrentTableView @@ -85,8 +83,6 @@ - (void) dealloc { - [fPreviewPanel release]; - [fCollapsedGroups release]; [fPiecesBarAnimation release]; @@ -875,59 +871,6 @@ return fPiecesBarPercent; } -#warning change from id to QLPreviewPanel -- (BOOL) acceptsPreviewPanelControl: (id) panel -{ - return YES; -} - -- (void) beginPreviewPanelControl: (id) panel -{ - fPreviewPanel = [panel retain]; - [fPreviewPanel setDelegate: self]; - [fPreviewPanel setDataSource: self]; -} - -- (void) endPreviewPanelControl: (id) panel -{ - [fPreviewPanel release]; - fPreviewPanel = nil; -} - -- (NSInteger) numberOfPreviewItemsInPreviewPanel: (id) panel -{ - return [[self quickLookableTorrents] count]; -} - -- (id /**/) previewPanel: (id) panel previewItemAtIndex: (NSInteger) index -{ - return [[self quickLookableTorrents] objectAtIndex: index]; -} - -- (BOOL) previewPanel: (id) panel handleEvent: (NSEvent *) event -{ - if ([event type] == NSKeyDown) - { - [super keyDown: event]; - return YES; - } - - return NO; -} - -- (NSRect) previewPanel: (id) panel sourceFrameOnScreenForPreviewItem: (id /**/) item -{ - const NSInteger row = [self rowForItem: item]; - if (row == -1) - return NSZeroRect; - - NSRect frame = [self iconRectForRow: row]; - frame.origin = [self convertPoint: frame.origin toView: nil]; - frame.origin = [[self window] convertBaseToScreen: frame.origin]; - frame.origin.y -= frame.size.height; - return frame; -} - @end @implementation TorrentTableView (Private) @@ -987,16 +930,4 @@ } } -- (NSArray *) quickLookableTorrents -{ - NSArray * selectedTorrents = [self selectedTorrents]; - NSMutableArray * qlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]]; - - for (Torrent * torrent in selectedTorrents) - if (([torrent isFolder] || [torrent isComplete]) && [[NSFileManager defaultManager] fileExistsAtPath: [torrent dataLocation]]) - [qlArray addObject: torrent]; - - return qlArray; -} - @end