]> git.sesse.net Git - vlc/blob - modules/gui/macosx/eyetv.m
macosx: fix wrong size of playlist when using podcast and minimal view
[vlc] / modules / gui / macosx / eyetv.m
1 /*****************************************************************************
2 * eyetv.m: small class to control the notification parts of the EyeTV plugin
3 *****************************************************************************
4 * Copyright (C) 2006-2011 VLC authors and VideoLAN
5 * $Id$
6 *
7 * Authors: Felix Kühne <fkuehne at videolan dot org>
8 *          Damien Fouilleul <damienf at videolan dot org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
24
25 #import "eyetv.h"
26 /* for apple event interaction [carbon] */
27 //#import <Foundation/NSAppleScript>
28 /* for various VLC core related calls */
29 #import "intf.h"
30
31 @implementation VLCEyeTVController
32
33 @synthesize eyeTVRunning = b_eyeTVactive, deviceConnected = b_deviceConnected;
34
35 static VLCEyeTVController *_o_sharedInstance = nil;
36
37 + (VLCEyeTVController *)sharedInstance
38 {
39     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
40 }
41
42 - (id)init
43 {
44     if (_o_sharedInstance)
45         [self dealloc];
46     else {
47         _o_sharedInstance = [super init];
48
49         [[NSDistributedNotificationCenter defaultCenter]
50                     addObserver: self
51                        selector: @selector(globalNotificationReceived:)
52                            name: NULL
53                          object: @"VLCEyeTVSupport"
54              suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
55     }
56
57     return _o_sharedInstance;
58 }
59
60 - (void)globalNotificationReceived: (NSNotification *)theNotification
61 {
62     /* update our info on the used device */
63     if ([[theNotification name] isEqualToString: @"DeviceAdded"])
64         b_deviceConnected = YES;
65     if ([[theNotification name] isEqualToString: @"DeviceRemoved"])
66         b_deviceConnected = NO;
67
68     /* is eyetv running? */
69     if ([[theNotification name] isEqualToString: @"PluginInit"])
70         b_eyeTVactive = YES;
71     if ([[theNotification name] isEqualToString: @"PluginQuit"])
72         b_eyeTVactive = NO;
73 }
74
75 - (void)launchEyeTV
76 {
77     NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
78                 @"tell application \"EyeTV\"\n"
79                    "launch with server mode\n"
80                  "end tell"];
81     NSDictionary *errorDict;
82     NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
83     if (nil == descriptor) {
84         NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
85         NSLog(@"opening EyeTV failed with error status '%@'", errorString);
86     }
87     [script release];
88 }
89
90 - (int)channel
91 {
92     int currentChannel = 0;
93     NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
94             @"tell application \"EyeTV\" to get current channel"];
95     NSDictionary *errorDict;
96     NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
97     if (nil == descriptor) {
98         NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
99         NSLog(@"EyeTV channel inventory failed with error status '%@'", errorString);
100     } else
101         currentChannel = (int)[descriptor int32Value];
102     [script release];
103     return currentChannel;
104 }
105
106 - (int)switchChannelUp:(BOOL)b_yesOrNo
107 {
108     int currentChannel = 0;
109     NSAppleScript *script;
110     NSDictionary *errorDict;
111     NSAppleEventDescriptor *descriptor;
112
113     if (b_yesOrNo == YES) {
114         script = [[NSAppleScript alloc] initWithSource:
115                     @"tell application \"EyeTV\"\n"
116                        "channel_up\n"
117                        "get current channel\n"
118                      "end tell"];
119         NSLog(@"telling eyetv to switch 1 channel up");
120     } else {
121         script = [[NSAppleScript alloc] initWithSource:
122                     @"tell application \"EyeTV\"\n"
123                        "channel_down\n"
124                        "get current channel\n"
125                      "end tell"];
126         NSLog(@"telling eyetv to switch 1 channel down");
127     }
128
129     descriptor = [script executeAndReturnError:&errorDict];
130     if (nil == descriptor) {
131         NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
132         NSLog(@"EyeTV channel change failed with error status '%@'", errorString);
133     } else
134         currentChannel = (int)[descriptor int32Value];
135
136     [script release];
137     return currentChannel;
138 }
139
140 - (void)setChannel: (int)theChannelNum
141 {
142     NSAppleScript *script;
143     switch(theChannelNum) {
144         case -2: // Composite
145             script = [[NSAppleScript alloc] initWithSource:
146                         @"tell application \"EyeTV\"\n"
147                          "  input_change input source composite video input\n"
148                          "  show player_window\n"
149                          "end tell"];
150             break;
151         case -1: // S-Video
152             script = [[NSAppleScript alloc] initWithSource:
153                         @"tell application \"EyeTV\"\n"
154                          "  input_change input source S video input\n"
155                          "  show player_window\n"
156                          "end tell"];
157             break;
158         case 0: // Last
159             script = [[NSAppleScript alloc] initWithSource:
160                         @"tell application \"EyeTV\"\n"
161                          "  show player_window\n"
162                          "end tell"];
163             break;
164         default:
165             if (theChannelNum > 0) {
166                 NSString *channel_change = [NSString stringWithFormat:
167                     @"tell application \"EyeTV\"\n"
168                      "  channel_change channel number %d\n"
169                      "  show player_window\n"
170                      "end tell", theChannelNum];
171                 script = [[NSAppleScript alloc] initWithSource:channel_change];
172             }
173             else
174                 return;
175     }
176     NSDictionary *errorDict;
177     NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
178     if (nil == descriptor) {
179         NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
180         NSLog(@"EyeTV source change failed with error status '%@'", errorString);
181     }
182     [script release];
183 }
184
185 - (NSEnumerator *)allChannels
186 {
187     NSEnumerator *channels = nil;
188     NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
189             @"tell application \"EyeTV\" to get name of every channel"];
190     NSDictionary *errorDict;
191     NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
192     if (nil == descriptor) {
193         NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
194         NSLog(@"EyeTV channel inventory failed with error status '%@'", errorString);
195     } else {
196         int count = [descriptor numberOfItems];
197         int x=0;
198         NSMutableArray *channelArray = [NSMutableArray arrayWithCapacity:count];
199         while(x++ < count)
200             [channelArray addObject:[[descriptor descriptorAtIndex:x] stringValue]];
201
202         channels = [channelArray objectEnumerator];
203     }
204     [script release];
205     return channels;
206 }
207
208 @end