Changeset 9034


Ignore:
Timestamp:
Sep 4, 2009, 4:10:46 AM (13 years ago)
Author:
livings124
Message:

draft #1 of #2369 - use public API for QuickLook? on 10.6 (and drop the hack for 10.5-support)

Location:
trunk
Files:
2 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Transmission.xcodeproj/project.pbxproj

    r9029 r9034  
    212212                A2DA362C0CBC674900C2ED41 /* InfoPeers.png in Resources */ = {isa = PBXBuildFile; fileRef = A2DA36290CBC674900C2ED41 /* InfoPeers.png */; };
    213213                A2DF37070C220D03006523C1 /* CreatorWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A2DF37050C220D03006523C1 /* CreatorWindowController.m */; };
    214                 A2DF57740DE46A6A000795D5 /* QuickLookController.m in Sources */ = {isa = PBXBuildFile; fileRef = A2DF57730DE46A6A000795D5 /* QuickLookController.m */; };
    215214                A2DF58580DE4B2B0000795D5 /* JSON_parser.c in Sources */ = {isa = PBXBuildFile; fileRef = A2DF576A0DE468C6000795D5 /* JSON_parser.c */; };
    216215                A2DF58590DE4B2B1000795D5 /* JSON_parser.h in Headers */ = {isa = PBXBuildFile; fileRef = A2DF576B0DE468C6000795D5 /* JSON_parser.h */; };
     
    702701                A2DF576A0DE468C6000795D5 /* JSON_parser.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = JSON_parser.c; path = libtransmission/JSON_parser.c; sourceTree = "<group>"; };
    703702                A2DF576B0DE468C6000795D5 /* JSON_parser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSON_parser.h; path = libtransmission/JSON_parser.h; sourceTree = "<group>"; };
    704                 A2DF57720DE46A6A000795D5 /* QuickLookController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QuickLookController.h; path = macosx/QuickLookController.h; sourceTree = "<group>"; };
    705                 A2DF57730DE46A6A000795D5 /* QuickLookController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QuickLookController.m; path = macosx/QuickLookController.m; sourceTree = "<group>"; };
    706703                A2E23AC30CB5E1930002BB25 /* InfoTabButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = InfoTabButtonCell.h; path = macosx/InfoTabButtonCell.h; sourceTree = "<group>"; };
    707704                A2E23AC40CB5E1930002BB25 /* InfoTabButtonCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = InfoTabButtonCell.m; path = macosx/InfoTabButtonCell.m; sourceTree = "<group>"; };
     
    969966                                A222EA790E6C32C4009FB003 /* BlocklistScheduler.h */,
    970967                                A222EA7A0E6C32C4009FB003 /* BlocklistScheduler.m */,
    971                                 A2DF57720DE46A6A000795D5 /* QuickLookController.h */,
    972                                 A2DF57730DE46A6A000795D5 /* QuickLookController.m */,
    973968                        );
    974969                        name = Sources;
     
    19831978                                A2FB701C0D95CAEA0001F331 /* GroupsController.m in Sources */,
    19841979                                A2D307A40D9EC6870051FD27 /* BlocklistDownloader.m in Sources */,
    1985                                 A2DF57740DE46A6A000795D5 /* QuickLookController.m in Sources */,
    19861980                                A2725B6E0DE5C4F5003445E7 /* FileListNode.m in Sources */,
    19871981                                A2725D5D0DE7507C003445E7 /* TrackerTableView.m in Sources */,
  • trunk/macosx/Controller.h

    r8842 r9034  
    248248- (void) showMainWindow: (id) sender;
    249249
    250 - (NSArray *) quickLookURLs;
    251 - (BOOL) canQuickLook;
    252 - (BOOL) canQuickLookTorrent: (Torrent *) torrent;
    253 - (NSRect) quickLookFrameWithURL: (NSURL*) url;
    254250- (void) toggleQuickLook: (id) sender;
    255251
  • trunk/macosx/Controller.m

    r9016 r9034  
    3434#import "CreatorWindowController.h"
    3535#import "StatsWindowController.h"
    36 #import "QuickLookController.h"
    3736#import "GroupsController.h"
    3837#import "AboutWindowController.h"
     
    294293        [PrefsController setHandle: fLib];
    295294        fPrefsController = [[PrefsController alloc] init];
    296        
    297         [QuickLookController quickLookControllerInitializeWithController: self infoController: fInfoController];
    298295       
    299296        fSoundPlaying = NO;
     
    14771474{
    14781475    [fInfoController setInfoForTorrents: [fTableView selectedTorrents]];
    1479     [[QuickLookController quickLook] updateQuickLook];
     1476   
     1477    if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible])
     1478        [[QLPreviewPanel sharedPreviewPanel] reloadData];
    14801479}
    14811480
     
    33673366        return YES;
    33683367    }
    3369    
    3370     //enable quicklook item
    3371     if ([ident isEqualToString: TOOLBAR_QUICKLOOK])
    3372         return [[QuickLookController quickLook] canQuickLook];
    33733368
    33743369    return YES;
     
    35653560        return [fWindow isVisible] && ![fFilterBar isHidden];
    35663561   
    3567     //enable quicklook item
    3568     if (action == @selector(toggleQuickLook:))
    3569         return [[QuickLookController quickLook] canQuickLook];
    3570    
    35713562    //enable reveal in finder
    35723563    if (action == @selector(revealFile:))
     
    39723963}
    39733964
    3974 - (NSArray *) quickLookURLs
    3975 {
    3976     NSArray * selectedTorrents = [fTableView selectedTorrents];
    3977     NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]];
    3978    
    3979     for (Torrent * torrent in selectedTorrents)
    3980         if ([self canQuickLookTorrent: torrent])
    3981             [urlArray addObject: [NSURL fileURLWithPath: [torrent dataLocation]]];
    3982    
    3983     return urlArray;
    3984 }
    3985 
    3986 - (BOOL) canQuickLook
    3987 {
    3988     for (Torrent * torrent in [fTableView selectedTorrents])
    3989         if ([self canQuickLookTorrent: torrent])
    3990             return YES;
    3991    
    3992     return NO;
    3993 }
    3994 
    3995 - (BOOL) canQuickLookTorrent: (Torrent *) torrent
    3996 {
    3997     if (![[NSFileManager defaultManager] fileExistsAtPath: [torrent dataLocation]])
    3998         return NO;
    3999    
    4000     return [torrent isFolder] || [torrent isComplete];
    4001 }
    4002 
    4003 - (NSRect) quickLookFrameWithURL: (NSURL *) url
    4004 {
    4005     if ([fWindow isVisible])
    4006     {
    4007         NSString * fullPath = [url path];
    4008         NSRange visibleRows = [fTableView rowsInRect: [fTableView bounds]];
    4009        
    4010         for (NSInteger row = 0; row < NSMaxRange(visibleRows); row++)
    4011         {
    4012             id item = [fTableView itemAtRow: row];
    4013             if ([item isKindOfClass: [Torrent class]] && [[(Torrent *)item dataLocation] isEqualToString: fullPath])
    4014             {
    4015                 NSRect frame = [fTableView iconRectForRow: row];
    4016                 frame.origin = [fTableView convertPoint: frame.origin toView: nil];
    4017                 frame.origin = [fWindow convertBaseToScreen: frame.origin];
    4018                 frame.origin.y -= frame.size.height;
    4019                 return frame;
    4020             }
    4021         }
    4022     }
    4023    
    4024     return NSZeroRect;
    4025 }
    4026 
    40273965- (void) toggleQuickLook: (id) sender
    40283966{
    4029     [[QuickLookController quickLook] toggleQuickLook];
     3967    if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible])
     3968        [[QLPreviewPanel sharedPreviewPanel] orderOut: nil];
     3969    else
     3970        [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront: nil];
    40303971}
    40313972
  • trunk/macosx/FileOutlineController.m

    r9016 r9034  
    2929#import "FileListNode.h"
    3030#import "NSApplicationAdditions.h"
    31 #import "QuickLookController.h"
     31#import <Quartz/Quartz.h>
    3232
    3333#define ROW_SMALL_HEIGHT 18.0
     
    133133- (void) outlineViewSelectionDidChange: (NSNotification *) notification
    134134{
    135     [[QuickLookController quickLook] updateQuickLook];
     135    if ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible])
     136        [[QLPreviewPanel sharedPreviewPanel] reloadData];
    136137}
    137138
  • trunk/macosx/FileOutlineView.m

    r8533 r9034  
    2929#import "Torrent.h"
    3030#import "FileListNode.h"
    31 #import "QuickLookController.h"
    3231
    3332@implementation FileOutlineView
     
    8483    [[self window] makeKeyWindow];
    8584    [super mouseDown: event];
    86 }
    87 
    88 - (void) keyDown: (NSEvent *) event
    89 {
    90     const unichar firstChar = [[event charactersIgnoringModifiers] characterAtIndex: 0];
    91    
    92     //don't allow quick look on add window
    93     if (firstChar == ' ' && [[[self window] windowController] isKindOfClass: [InfoWindowController class]])
    94         [[QuickLookController quickLook] toggleQuickLook];
    95     else if (firstChar == NSRightArrowFunctionKey)
    96         [[QuickLookController quickLook] pressRight];
    97     else if (firstChar == NSLeftArrowFunctionKey)
    98         [[QuickLookController quickLook] pressLeft];
    99     else;
    100    
    101     [super keyDown: event]; 
    10285}
    10386
  • trunk/macosx/InfoWindowController.h

    r8841 r9034  
    2525#import <Cocoa/Cocoa.h>
    2626#import <transmission.h>
     27#import <Quartz/Quartz.h>
    2728
    2829@class Torrent;
     
    3132@class PiecesView;
    3233
    33 @interface InfoWindowController : NSWindowController
     34@interface InfoWindowController : NSWindowController <QLPreviewPanelDataSource, QLPreviewPanelDelegate>
    3435{
    3536    NSArray * fTorrents;
     
    7879   
    7980    NSString * fInitialString;
     81   
     82    QLPreviewPanel * fPreviewPanel;
    8083}
    8184
     
    9194- (void) addRemoveTracker: (id) sender;
    9295
    93 - (BOOL) shouldQuickLookFileView;
    9496- (NSArray *) quickLookURLs;
    9597- (BOOL) canQuickLook;
  • trunk/macosx/InfoWindowController.m

    r9016 r9034  
    3232#import "TrackerTableView.h"
    3333#import "PiecesView.h"
    34 #import "QuickLookController.h"
    3534#import "NSApplicationAdditions.h"
    3635#import "NSStringAdditions.h"
     
    228227   
    229228    [fWebSeedTableAnimation release];
     229   
     230    [fPreviewPanel release];
    230231   
    231232    [super dealloc];
     
    686687- (void) setTab: (id) sender
    687688{
    688     NSInteger oldTabTag = fCurrentTabTag;
     689    const NSInteger oldTabTag = fCurrentTabTag;
    689690    fCurrentTabTag = [fTabMatrix selectedTag];
    690691    if (fCurrentTabTag == oldTabTag)
     
    725726           
    726727            case TAB_FILES_TAG:
    727                 [[QuickLookController quickLook] updateQuickLook];
    728                
    729728                oldResizeSaveKey = @"InspectorContentHeightFiles";
    730729                break;
     
    822821    [view setHidden: NO];
    823822   
    824     if (fCurrentTabTag == TAB_FILES_TAG)
    825         [[QuickLookController quickLook] updateQuickLook];
     823    if (fCurrentTabTag == TAB_FILES_TAG || oldTabTag == TAB_FILES_TAG
     824        && ([QLPreviewPanel sharedPreviewPanelExists] && [[QLPreviewPanel sharedPreviewPanel] isVisible]))
     825        [[QLPreviewPanel sharedPreviewPanel] reloadData];
    826826}
    827827
     
    11031103}
    11041104
    1105 - (BOOL) shouldQuickLookFileView
    1106 {
    1107     return [[self window] isVisible] && fCurrentTabTag == TAB_FILES_TAG && [[fFileController outlineView] numberOfSelectedRows] > 0;
    1108 }
    1109 
     1105
     1106
     1107
     1108
     1109
     1110- (BOOL) acceptsPreviewPanelControl: (QLPreviewPanel *) panel
     1111{
     1112    return fCurrentTabTag == TAB_FILES_TAG && [[fFileController outlineView] numberOfSelectedRows] > 0;
     1113}
     1114
     1115- (void) beginPreviewPanelControl: (QLPreviewPanel *) panel
     1116{
     1117    fPreviewPanel = [panel retain];
     1118    fPreviewPanel.delegate = self;
     1119    fPreviewPanel.dataSource = self;
     1120}
     1121
     1122- (void) endPreviewPanelControl: (QLPreviewPanel *) panel
     1123{
     1124    [fPreviewPanel release];
     1125    fPreviewPanel = nil;
     1126}
     1127
     1128- (NSInteger) numberOfPreviewItemsInPreviewPanel: (QLPreviewPanel *) panel
     1129{
     1130    return [[self quickLookURLs] count];
     1131}
     1132
     1133- (id <QLPreviewItem>) previewPanel: (QLPreviewPanel *)panel previewItemAtIndex: (NSInteger) index
     1134{
     1135    return [[self quickLookURLs] objectAtIndex: index];
     1136}
     1137
     1138- (BOOL) previewPanel: (QLPreviewPanel *) panel handleEvent: (NSEvent *) event
     1139{
     1140    if ([event type] == NSKeyDown)
     1141    {
     1142        [super keyDown: event];
     1143        return YES;
     1144    }
     1145   
     1146    return NO;
     1147}
     1148
     1149#warning fix!
     1150- (NSRect) previewPanel: (QLPreviewPanel *) panel sourceFrameOnScreenForPreviewItem: (id <QLPreviewItem>) item
     1151{
     1152    const NSInteger row = [[fFileController outlineView] rowForItem: item];
     1153    if (row == -1)
     1154        return NSZeroRect;
     1155   
     1156    NSRect frame = [[fFileController outlineView] iconRectForRow: row];
     1157    frame.origin = [[fFileController outlineView] convertPoint: frame.origin toView: nil];
     1158    frame.origin = [[self window] convertBaseToScreen: frame.origin];
     1159    frame.origin.y -= frame.size.height;
     1160    return frame;
     1161}
     1162
     1163
     1164
     1165
     1166
     1167#warning private
    11101168- (NSArray *) quickLookURLs
    11111169{
     
    11261184}
    11271185
     1186#warning need? private?
    11281187- (BOOL) canQuickLook
    11291188{
     
    11381197}
    11391198
    1140 - (NSRect) quickLookFrameWithURL: (NSURL *) url
    1141 {
    1142     FileOutlineView * fileOutlineView = [fFileController outlineView];
    1143    
    1144     NSString * fullPath = [url path];
    1145     NSString * folder = [[fTorrents objectAtIndex: 0] downloadFolder];
    1146     NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
    1147    
    1148     for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
    1149     {
    1150         FileListNode * rowItem = [fileOutlineView itemAtRow: row];
    1151         if ([[folder stringByAppendingPathComponent: [rowItem fullPath]] isEqualToString: fullPath])
    1152         {
    1153             NSRect frame = [fileOutlineView iconRectForRow: row];
    1154             frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil];
    1155             frame.origin = [[self window] convertBaseToScreen: frame.origin];
    1156             frame.origin.y -= frame.size.height;
    1157             return frame;
    1158         }
    1159     }
    1160    
    1161     return NSZeroRect;
    1162 }
     1199
     1200
    11631201
    11641202- (void) setPiecesView: (id) sender
  • trunk/macosx/Torrent.m

    r9016 r9034  
    15581558{
    15591559    return fHandle;
     1560}
     1561
     1562- (NSURL *) previewItemURL
     1563{
     1564    return [NSURL fileURLWithPath: [self dataLocation]];
     1565}
     1566
     1567- (NSString *) previewItemTitle
     1568{
     1569    return [self name];
    15601570}
    15611571
  • trunk/macosx/TorrentTableView.h

    r8261 r9034  
    2626#import <transmission.h>
    2727#import "Controller.h"
     28#import <Quartz/Quartz.h>
    2829
    2930@class TorrentCell;
     
    3132#define GROUP_SEPARATOR_HEIGHT 18.0
    3233
    33 @interface TorrentTableView : NSOutlineView
     34@interface TorrentTableView : NSOutlineView <QLPreviewPanelDataSource, QLPreviewPanelDelegate>
    3435{
    3536    IBOutlet Controller * fController;
     
    5253    CGFloat fPiecesBarPercent;
    5354    NSAnimation * fPiecesBarAnimation;
     55   
     56    QLPreviewPanel * fPreviewPanel;
    5457}
    5558
  • trunk/macosx/TorrentTableView.m

    r9018 r9034  
    2929#import "FileListNode.h"
    3030#import "NSApplicationAdditions.h"
    31 #import "QuickLookController.h"
    3231
    3332#define MAX_GROUP 999999
     
    5352
    5453- (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files;
     54
     55- (NSArray *) quickLookableTorrents;
    5556
    5657@end
     
    8788- (void) dealloc
    8889{
     90    [fPreviewPanel release];
     91   
    8992    [fCollapsedGroups release];
    9093   
     
    498501    if (firstChar == 'f' && [event modifierFlags] & NSAlternateKeyMask && [event modifierFlags] & NSCommandKeyMask)
    499502        [fController focusFilterField];
     503    else if (firstChar == ' ')
     504        [fController toggleQuickLook: self];
    500505    else
    501     {
    502         //handle quicklook
    503         if (firstChar == ' ')
    504             [[QuickLookController quickLook] toggleQuickLook];
    505         else if (firstChar == NSRightArrowFunctionKey)
    506             [[QuickLookController quickLook] pressRight];
    507         else if (firstChar == NSLeftArrowFunctionKey)
    508             [[QuickLookController quickLook] pressLeft];
    509         else;
    510        
    511506        [super keyDown: event];
    512     }
    513507}
    514508
     
    876870}
    877871
     872
     873
     874
     875
     876
     877
     878
     879
     880- (BOOL) acceptsPreviewPanelControl: (QLPreviewPanel *) panel
     881{
     882    return YES;
     883}
     884
     885- (void) beginPreviewPanelControl: (QLPreviewPanel *) panel
     886{
     887    fPreviewPanel = [panel retain];
     888    fPreviewPanel.delegate = self;
     889    fPreviewPanel.dataSource = self;
     890}
     891
     892- (void) endPreviewPanelControl: (QLPreviewPanel *) panel
     893{
     894    [fPreviewPanel release];
     895    fPreviewPanel = nil;
     896}
     897
     898- (NSInteger) numberOfPreviewItemsInPreviewPanel: (QLPreviewPanel *) panel
     899{
     900    return [[self quickLookableTorrents] count];
     901}
     902
     903- (id <QLPreviewItem>) previewPanel: (QLPreviewPanel *)panel previewItemAtIndex: (NSInteger) index
     904{
     905    return [[self quickLookableTorrents] objectAtIndex: index];
     906}
     907
     908- (BOOL) previewPanel: (QLPreviewPanel *) panel handleEvent: (NSEvent *) event
     909{
     910    if ([event type] == NSKeyDown)
     911    {
     912        [super keyDown: event];
     913        return YES;
     914    }
     915   
     916    return NO;
     917}
     918
     919- (NSRect) previewPanel: (QLPreviewPanel *) panel sourceFrameOnScreenForPreviewItem: (id <QLPreviewItem>) item
     920{
     921    const NSInteger row = [self rowForItem: item];
     922    if (row == -1)
     923        return NSZeroRect;
     924   
     925    NSRect frame = [self iconRectForRow: row];
     926    frame.origin = [self convertPoint: frame.origin toView: nil];
     927    frame.origin = [[self window] convertBaseToScreen: frame.origin];
     928    frame.origin.y -= frame.size.height;
     929    return frame;
     930}
     931
     932
     933
     934
     935
     936
    878937@end
    879938
     
    9461005}
    9471006
     1007- (NSArray *) quickLookableTorrents
     1008{
     1009    NSArray * selectedTorrents = [self selectedTorrents];
     1010    NSMutableArray * qlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]];
     1011   
     1012    for (Torrent * torrent in selectedTorrents)
     1013        if (([torrent isFolder] || [torrent isComplete]) && [[NSFileManager defaultManager] fileExistsAtPath: [torrent dataLocation]])
     1014            [qlArray addObject: torrent];
     1015   
     1016    return qlArray;
     1017}
     1018
    9481019@end
Note: See TracChangeset for help on using the changeset viewer.