phase one of moving quicklook into the controller - it's not as pretty code-wise but the behavior is a lot more consistent

This commit is contained in:
Mitchell Livingston 2009-10-11 23:16:46 +00:00
parent 53273caef2
commit 1af529aa96
6 changed files with 125 additions and 149 deletions

View File

@ -24,6 +24,7 @@
#import <Cocoa/Cocoa.h>
#import <transmission.h>
#import <Quartz/Quartz.h>
#import <Growl/Growl.h>
@class AddWindowController;
@ -46,7 +47,8 @@ typedef enum
ADD_CREATED
} addType;
@interface Controller : NSObject <GrowlApplicationBridgeDelegate>
#warning uncomment
@interface Controller : NSObject <GrowlApplicationBridgeDelegate> //, 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;

View File

@ -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 /*<QLPreviewItem>*/) 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 /*<QLPreviewItem>*/) 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];

View File

@ -24,7 +24,6 @@
#import <Cocoa/Cocoa.h>
#import <transmission.h>
#import <Quartz/Quartz.h>
@class Torrent;
@class TrackerTableView;
@ -32,8 +31,7 @@
@class FileOutlineController;
@class PiecesView;
#warning uncomment
@interface InfoWindowController : NSWindowController //<QLPreviewPanelDataSource, QLPreviewPanelDelegate>
@interface InfoWindowController : NSWindowController
{
NSArray * fTorrents;
@ -94,6 +92,10 @@
- (void) addRemoveTracker: (id) sender;
- (NSArray *) quickLookURLs;
- (BOOL) canQuickLook;
- (NSRect) quickLookSourceFrameForPreviewItem: (id /*<QLPreviewItem>*/) item;
- (void) setPiecesView: (id) sender;
- (void) setPiecesViewForAvailable: (BOOL) available;

View File

@ -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 /*<QLPreviewItem>*/) 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 /*<QLPreviewItem>*/) item
#warning uncomment (in header too)
- (NSRect) quickLookSourceFrameForPreviewItem: (id /*<QLPreviewItem>*/) 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

View File

@ -24,7 +24,6 @@
#import <Cocoa/Cocoa.h>
#import <transmission.h>
#import <Quartz/Quartz.h>
@class Controller;
@class Torrent;
@ -32,8 +31,7 @@
#define GROUP_SEPARATOR_HEIGHT 18.0
#warning uncomment
@interface TorrentTableView : NSOutlineView //<QLPreviewPanelDataSource, QLPreviewPanelDelegate>
@interface TorrentTableView : NSOutlineView
{
IBOutlet Controller * fController;
@ -54,9 +52,6 @@
CGFloat fPiecesBarPercent;
NSAnimation * fPiecesBarAnimation;
#warning change to QLPreviewPanel
id fPreviewPanel;
}
- (BOOL) isGroupCollapsed: (NSInteger) value;

View File

@ -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 /*<QLPreviewItem>*/) 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 /*<QLPreviewItem>*/) 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