-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCouchPreview.m
110 lines (98 loc) · 2.97 KB
/
CouchPreview.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
//
// CouchPreview.m
// CouchPreview
//
// Created by Hugo Camboulive on 21/05/09.
// Copyright 2009 Hugo Camboulive. All rights reserved.
//
#import "CouchPreview.h"
#import "RemoteControlWrapper/RemoteControlContainer.h"
#import "RemoteControlWrapper/AppleRemote.h"
#import "RemoteControlWrapper/KeyspanFrontRowControl.h"
#import "CouchApplication.h"
/* Dumped headers */
#import "PVImageWindowController.h"
#import "IKSlideshow.h"
#import "IKSlideshowController.h"
@implementation CouchPreview
+ (void) load
{
CouchPreview *plugin = [CouchPreview sharedInstance];
/* Handle remotes (Apple + remote for older macs) */
plugin->cont = [[RemoteControlContainer alloc] initWithDelegate: plugin];
[plugin->cont instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]];
[plugin->cont instantiateAndAddRemoteControlDeviceWithClass: [KeyspanFrontRowControl class]];
[plugin->cont startListening: self];
/* reset the delegate so that it get the methods we added */
PVApplication *app = [NSApp delegate];
[NSApp setDelegate: nil];
[NSApp setDelegate: app];
}
+ (CouchPreview *) sharedInstance
{
static CouchPreview* plugin = nil;
if (plugin == nil)
plugin = [[CouchPreview alloc] init];
return plugin;
}
/**
* This function handles whatever happens when a key on the remote is pressed
* or released. Depending on the context, we update the slideshow or the normal view
*/
- (void) sendRemoteButtonEvent: (RemoteControlEventIdentifier)event pressedDown: (BOOL) pressedDown remoteControl: (RemoteControl *)remoteControl
{
NSWindow *w = [NSApp mainWindow];
if (pressedDown == NO)
return;
if (w == nil)
return;
/* We are in normal mode */
if ([w isKindOfClass: NSClassFromString(@"PVWindow")]) {
switch(event) {
case kRemoteButtonRight:
[[w windowController] doGoToNextPage:nil];
break;
case kRemoteButtonLeft:
[[w windowController] doGoToPreviousPage:nil];
break;
case kRemoteButtonMenu:
[[w windowController] slideshow: nil];
break;
case kRemoteButtonLeft_Hold:
[[w windowController] doGoToFirstPage:nil];
break;
case kRemoteButtonRight_Hold:
[[w windowController] doGoToLastPage:nil];
break;
}
}
/* We are in a slideshow. We use IKSlideshow private classes to control this
* (had to run class-dump on the ImageKit library */
if ([w isKindOfClass: NSClassFromString(@"IKSlideshowWindow")]) {
IKSlideshow *sld = [IKSlideshow sharedSlideshow];
IKSlideshowController *ctl = [sld controller];
switch(event) {
case kRemoteButtonMenu:
[sld stopSlideshow: nil];
break;
case kRemoteButtonRight:
[ctl slideshowNext: nil];
break;
case kRemoteButtonLeft:
[ctl slideshowPrev: nil];
break;
case kRemoteButtonPlay:
[ctl slideshowPlay: nil];
break;
case kRemoteButtonRight_Hold:
while([ctl canGoNext])
[ctl gotoNextItem: nil];
break;
case kRemoteButtonLeft_Hold:
while([ctl canGoBack])
[ctl gotoPreviousItem:nil];
break;
}
}
}
@end