]> git.sesse.net Git - vlc/blob - modules/gui/macosx/eyetv.m
19e5d43cf2fa1f22cfe9dbba4dfcfb953bfd7fd9
[vlc] / modules / gui / macosx / eyetv.m
1 /*****************************************************************************\r
2 * eyetv.m: small class to control the notification parts of the EyeTV plugin\r
3 *****************************************************************************\r
4 * Copyright (C) 2006-2007 the VideoLAN team\r
5 * $Id$\r
6 *\r
7 * Authors: Felix Kühne <fkuehne at videolan dot org>\r
8 *\r
9 * This program is free software; you can redistribute it and/or modify\r
10 * it under the terms of the GNU General Public License as published by\r
11 * the Free Software Foundation; either version 2 of the License, or\r
12 * (at your option) any later version.\r
13 *\r
14 * This program is distributed in the hope that it will be useful,\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17 * GNU General Public License for more details.\r
18 *\r
19 * You should have received a copy of the GNU General Public License\r
20 * along with this program; if not, write to the Free Software\r
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
22 *****************************************************************************/\r
23 \r
24 #import "eyetv.h"
25 /* for apple event interaction [carbon] */\r
26 #import <ApplicationServices/ApplicationServices.h> \r
27 /* for various VLC core related calls */
28 #import "intf.h"\r
29 \r
30 @implementation VLCEyeTVController\r
31 \r
32 static VLCEyeTVController *_o_sharedInstance = nil;\r
33 \r
34 + (VLCEyeTVController *)sharedInstance\r
35 {\r
36     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];\r
37 }\r
38 \r
39 - (id)init \r
40 {\r
41     if (_o_sharedInstance) {\r
42         [self dealloc];\r
43     } else {\r
44         _o_sharedInstance = [super init];\r
45 \r
46         [[NSDistributedNotificationCenter defaultCenter] 
47                     addObserver: self\r
48                        selector: @selector(globalNotificationReceived:)\r
49                            name: NULL\r
50                          object: @"VLCEyeTVSupport"\r
51              suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];\r
52     }\r
53     \r
54     return _o_sharedInstance;\r
55 }\r
56 \r
57 - (void)globalNotificationReceived: (NSNotification *)theNotification\r
58 {\r
59     msg_Dbg( VLCIntf, "notification received in VLC with name %s and object %s",
60              [[theNotification name] UTF8String], [[theNotification object] UTF8String] );\r
61 \r
62     /* update our info on the used device */\r
63     if( [[theNotification name] isEqualToString: @"DeviceAdded"] )\r
64         b_deviceConnected = YES;\r
65     if( [[theNotification name] isEqualToString: @"DeviceRemoved"] )\r
66         b_deviceConnected = NO;\r
67 \r
68     /* is eyetv running? */\r
69     if( [[theNotification name] isEqualToString: @"PluginInit"] )\r
70         b_eyeTVactive = YES;\r
71     if( [[theNotification name] isEqualToString: @"PluginQuit"] )\r
72         b_eyeTVactive = NO;\r
73 }\r
74 \r
75 - (BOOL)isEyeTVrunning\r
76 {\r
77     return b_eyeTVactive;\r
78 }\r
79 \r
80 - (BOOL)isDeviceConnected\r
81 {\r
82     return b_deviceConnected;\r
83 }\r
84 \r
85 \r
86 - (void)launchEyeTV\r
87 {\r
88     OSStatus stat;\r
89     FSRef eyetvPath;\r
90 \r
91     stat = LSFindApplicationForInfo ( 'EyTV',\r
92                                        CFSTR("com.elgato.eyetv"),\r
93                                        NULL,\r
94                                        &eyetvPath,\r
95                                        NULL );\r
96     if( stat != noErr )\r
97         msg_Err( VLCIntf, "finding EyeTV failed with error code %i", (int)stat );\r
98     \r
99     stat = LSOpenFSRef( &eyetvPath, NULL );\r
100     if( stat != noErr )\r
101         msg_Err( VLCIntf, "opening EyeTV failed with error code %i", (int)stat );\r
102     \r
103 }\r
104 \r
105 - (void)switchChannelUp:(BOOL)b_yesOrNo\r
106 {\r
107     OSErr err;\r
108     AppleEvent ourAE = {typeNull, nil};\r
109     AEBuildError theBuildError;\r
110     const OSType eyetvSignature = 'EyTV';   /* carbon FOURCC style */\r
111     OSType eyetvCommand;\r
112     \r
113     if( b_yesOrNo == YES )\r
114     {\r
115         eyetvCommand = 'Chup';     /* same style */\r
116         msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel up" );\r
117     }\r
118     else\r
119     {\r
120         eyetvCommand = 'Chdn';     /* same style again */\r
121         msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel down" );\r
122     }\r
123     \r
124     err = AEBuildAppleEvent(\r
125                             /* EyeTV script suite */ eyetvSignature,\r
126                             /* command */ eyetvCommand,\r
127                             /* signature type */ typeApplSignature,\r
128                             /* signature */ &eyetvSignature,\r
129                             /* signature size */ sizeof(eyetvSignature),\r
130                             /* basic return id */ kAutoGenerateReturnID,\r
131                             /* generic transaction id */ kAnyTransactionID,\r
132                             /* to-be-created AE */ &ourAE,\r
133                             /* get some possible errors */ &theBuildError, \r
134                             /* got no params for now */ "" );\r
135     if( err != aeBuildSyntaxNoErr )\r
136     {\r
137         msg_Err( VLCIntf, "Error %i encountered while trying to the build the AE to launch eyetv.\n" \\r
138                  "additionally, the following info was returned: AEBuildErrorCode:%i at pos:%i", \r
139                  (int)err, theBuildError.fError, theBuildError.fErrorPos);\r
140         return;\r
141     }\r
142     else\r
143         msg_Dbg( VLCIntf, "AE created successfully, trying to send now" );\r
144     \r
145     err = AESendMessage(\r
146                         /* our AE */ &ourAE,\r
147                         /* no need for a response-AE */ NULL,\r
148                         /* we neither want a response nor user interaction */ kAENoReply | kAENeverInteract,\r
149                         /* we don't need a special time-out */ kAEDefaultTimeout );\r
150     if( err != noErr )\r
151         msg_Err( VLCIntf, "Error %i encountered while trying to tell EyeTV to switch channel", (int)err );\r
152     \r
153     err = AEDisposeDesc(&ourAE);\r
154 }\r
155 \r
156 - (void)selectChannel: (int)theChannelNum\r
157 {\r
158 }\r
159 \r
160 - (int)getNumberOfChannels\r
161 {\r
162     return 2;\r
163 }\r
164 \r
165 - (NSString *)getNameOfChannel: (int)theChannelNum\r
166 {\r
167     return @"dummy name";\r
168 }\r
169 \r
170 @end\r