forked from mus1cjunk1e/NativaPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuickLookController.m
178 lines (139 loc) · 4.36 KB
/
QuickLookController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/******************************************************************************
* Nativa - MacOS X UI for rtorrent
* http://www.aramzamzam.net
*
* Copyright Solomenchuk V. 2010.
* Solomenchuk Vladimir <[email protected]>
*
* Licensed under the GPL, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#import "QuickLookController.h"
#include "TorrentTableView.h"
#include "Torrent.h"
#include "DownloadsController.h"
#include "TorrentTableView.h"
#include <QuickLook/QuickLook.h>
#include "SynthesizeSingleton.h"
@interface TorrentTableView (QLPreviewPanelController)
@end
@implementation TorrentTableView (QLPreviewPanelController)
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel *)panel
{
return YES;
}
- (void)beginPreviewPanelControl:(QLPreviewPanel *)panel
{
[[QuickLookController sharedQuickLookController] beginPanel:panel window:[self window] view:self];
}
- (void)endPreviewPanelControl:(QLPreviewPanel *)panel
{
[[QuickLookController sharedQuickLookController] endPanel];
}
@end
@interface Torrent (QLPreviewItem) <QLPreviewItem>
@end
@implementation Torrent (QLPreviewItem)
- (NSURL *)previewItemURL
{
NSString *location = [[DownloadsController sharedDownloadsController] findLocation:self];
return (location==nil?nil:[NSURL fileURLWithPath: location]);
}
- (NSString *)previewItemTitle
{
return self.name;
}
@end
@implementation QuickLookController
SYNTHESIZE_SINGLETON_FOR_CLASS(QuickLookController);
+(void) show
{
if ([[QLPreviewPanel sharedPreviewPanel] isVisible])
[[QLPreviewPanel sharedPreviewPanel] orderOut: nil];
else
[[QLPreviewPanel sharedPreviewPanel] makeKeyAndOrderFront: nil];
}
@synthesize isVisible = _isVisible;
-(void) beginPanel:(QLPreviewPanel*) panel window:(NSWindow*)window view:(TorrentTableView*) view
{
_window = window;
_view = view;
if (_torrents == nil)
{
_torrents = [[NSMutableArray alloc] init];
[_torrents retain];
}
[_torrents removeAllObjects];
for (Torrent * torrent in [_view selectedTorrents])
{
if ([[DownloadsController sharedDownloadsController] findLocation:torrent] != nil)
[_torrents addObject:torrent];
}
self.isVisible = YES;
_panel = [panel retain];
_panel.delegate = self;
_panel.dataSource = self;
}
-(void) endPanel;
{
self.isVisible = NO;
[_panel release];
_panel = nil;
}
// Quick Look panel support
- (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel *)panel;
{
return YES;
}
// Quick Look panel data source
- (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel
{
return [_torrents count];
}
- (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index
{
return [_torrents objectAtIndex:index];
}
// Quick Look panel delegate
- (BOOL)previewPanel:(QLPreviewPanel *)panel handleEvent:(NSEvent *)event
{
// redirect all key down events to the table view
if ([event type] == NSKeyDown)
{
[_view keyDown:event];
return NO;
}
return YES;
}
// This delegate method provides the rect on screen from which the panel will zoom.
- (NSRect)previewPanel:(QLPreviewPanel *)panel sourceFrameOnScreenForPreviewItem:(id <QLPreviewItem>)item
{
if (![_window isVisible])
return NSZeroRect;
const NSInteger row = [_view rowForItem: item];
if (row == -1)
return NSZeroRect;
NSRect frame = [_view iconRectForRow: row];
if (!NSIntersectsRect([_view visibleRect], frame))
return NSZeroRect;
frame.origin = [_view convertPoint: frame.origin toView: nil];
frame.origin = [_window convertBaseToScreen: frame.origin];
frame.origin.y -= frame.size.height;
return frame;
}
// This delegate method provides a transition image between the table view and the preview panel
- (id)previewPanel:(QLPreviewPanel *)panel transitionImageForPreviewItem:(id <QLPreviewItem>)item contentRect:(NSRect *)contentRect
{
Torrent* torrent = (Torrent *)item;
return [torrent icon];
}
@end