source: trunk/macosx/QuickLookController.m @ 8227

Last change on this file since 8227 was 7659, checked in by livings124, 13 years ago

update the Mac code's copyright dates

  • Property svn:keywords set to Date Rev Author Id
File size: 5.0 KB
Line 
1/******************************************************************************
2 * $Id: QuickLookController.m 7659 2009-01-10 23:37:37Z livings124 $
3 *
4 * Copyright (c) 2008-2009 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "QuickLookController.h"
26#import "QuickLook.h"
27#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")
28
29#import "Controller.h"
30#import "InfoWindowController.h"
31
32@interface QuickLookController (Private)
33
34- (id) initWithMainController: (Controller *) controller infoController: (InfoWindowController *) infoController;
35
36@end
37
38@implementation QuickLookController
39
40QuickLookController * fQuickLookInstance = nil;
41+ (void) quickLookControllerInitializeWithController: (Controller *) controller infoController: (InfoWindowController *) infoController
42{
43    if (!fQuickLookInstance)
44        fQuickLookInstance = [[QuickLookController alloc] initWithMainController: controller infoController: infoController];
45}
46
47+ (QuickLookController *) quickLook
48{
49    return fQuickLookInstance;
50}
51
52//QuickLook delegate method
53//returns the frame for the item represented by the URL, or an empty frame to fade in/out instead
54- (NSRect) previewPanel: (NSPanel *) panel frameForURL: (NSURL *) url
55{
56    if ([fInfoController shouldQuickLookFileView])
57        return [fInfoController quickLookFrameWithURL: url];
58    else
59        return [fMainController quickLookFrameWithURL: url];
60}
61
62- (BOOL) quickLookSelectItems
63{
64    if (!fQuickLookAvailable)
65        return NO;
66   
67    NSArray * urlArray;
68    if ([fInfoController shouldQuickLookFileView])
69        urlArray = [fInfoController quickLookURLs];
70    else
71        urlArray = [fMainController quickLookURLs];
72   
73    if (urlArray && [urlArray count] > 0)
74    {
75        [[QLPreviewPanel sharedPreviewPanel] setURLs: urlArray];
76        return YES;
77    }
78    else
79        return NO;
80}
81
82- (BOOL) canQuickLook
83{
84    if (!fQuickLookAvailable)
85        return NO;
86   
87    if ([fInfoController shouldQuickLookFileView])
88        return [fInfoController canQuickLook];
89    else
90        return [fMainController canQuickLook];
91}
92
93- (void) toggleQuickLook
94{
95    if (!fQuickLookAvailable)
96        return;
97   
98    if ([[QLPreviewPanel sharedPreviewPanel] isOpen])
99        [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 2];
100    else
101    {
102        if ([self quickLookSelectItems])
103        {
104            NSWindow * keyWindow = [NSApp keyWindow];
105           
106            [[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFrontWithEffect: 2];
107           
108            //restore the focus to previous key window
109            [keyWindow makeKeyWindow];
110        }
111    }
112}
113
114- (void) updateQuickLook
115{
116    //only update when window is open or in the middle of opening (visible)
117    if (!fQuickLookAvailable || !([[QLPreviewPanel sharedPreviewPanel] isOpen] || [[QLPreviewPanel sharedPreviewPanel] isVisible]))
118        return;
119   
120    if (![self quickLookSelectItems])
121        [[QLPreviewPanel sharedPreviewPanel] closeWithEffect: 1];
122}
123
124- (void) pressLeft
125{
126    if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen])
127        [[QLPreviewPanel sharedPreviewPanel] selectPreviousItem];
128}
129
130- (void) pressRight
131{
132    if (fQuickLookAvailable && [[QLPreviewPanel sharedPreviewPanel] isOpen])
133        [[QLPreviewPanel sharedPreviewPanel] selectNextItem];
134}
135
136@end
137
138@implementation QuickLookController (Private)
139
140- (id) initWithMainController: (Controller *) controller infoController: (InfoWindowController *) infoController
141{
142    if ((self = [super init]))
143    {
144        fMainController = controller;
145        fInfoController = infoController;
146       
147        //load the QuickLook framework and set the delegate
148        //animation types: 0 = none; 1 = fade; 2 = zoom
149        fQuickLookAvailable = [[NSBundle bundleWithPath: @"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load];
150        if (fQuickLookAvailable)
151            [[[QLPreviewPanel sharedPreviewPanel] windowController] setDelegate: self];
152    }
153   
154    return self;
155}
156
157@end
Note: See TracBrowser for help on using the repository browser.