Commit f4ea890c authored by Damien Fouilleul's avatar Damien Fouilleul

eyetv: functional GUI panel, replaced Carbon style AppleScript with NSAppleScript

parent 59f74cc4
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
- (void)launchEyeTV; - (void)launchEyeTV;
- (void)switchChannelUp:(BOOL)b_yesOrNo; - (void)switchChannelUp:(BOOL)b_yesOrNo;
- (void)selectChannel:(int)theChannelNum; - (void)selectChannel:(int)theChannelNum;
- (int)getNumberOfChannels; - (NSEnumerator *)getChannels;
- (NSString *)getNameOfChannel:(int)theChannelNum;
@end @end
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#import "eyetv.h" #import "eyetv.h"
/* for apple event interaction [carbon] */ /* for apple event interaction [carbon] */
#import <ApplicationServices/ApplicationServices.h> //#import <Foundation/NSAppleScript>
/* for various VLC core related calls */ /* for various VLC core related calls */
#import "intf.h" #import "intf.h"
...@@ -85,86 +85,106 @@ static VLCEyeTVController *_o_sharedInstance = nil; ...@@ -85,86 +85,106 @@ static VLCEyeTVController *_o_sharedInstance = nil;
- (void)launchEyeTV - (void)launchEyeTV
{ {
OSStatus stat; NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
FSRef eyetvPath; @"tell application \"EyeTV\" to launch with server mode"];
NSDictionary *errorDict;
stat = LSFindApplicationForInfo ( 'EyTV', NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
CFSTR("com.elgato.eyetv"), if( nil == descriptor )
NULL, {
&eyetvPath, NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
NULL ); msg_Err( VLCIntf, "opening EyeTV failed with error code %s", [errorString UTF8String] );
if( stat != noErr ) }
msg_Err( VLCIntf, "finding EyeTV failed with error code %i", (int)stat ); [script release];
stat = LSOpenFSRef( &eyetvPath, NULL );
if( stat != noErr )
msg_Err( VLCIntf, "opening EyeTV failed with error code %i", (int)stat );
} }
- (void)switchChannelUp:(BOOL)b_yesOrNo - (void)switchChannelUp:(BOOL)b_yesOrNo
{ {
OSErr err; NSAppleScript *script;
AppleEvent ourAE = {typeNull, nil}; NSDictionary *errorDict;
AEBuildError theBuildError; NSAppleEventDescriptor *descriptor;
const OSType eyetvSignature = 'EyTV'; /* carbon FOURCC style */
OSType eyetvCommand;
if( b_yesOrNo == YES ) if( b_yesOrNo == YES )
{ {
eyetvCommand = 'Chup'; /* same style */ script = [[NSAppleScript alloc] initWithSource:
@"tell application \"EyeTV\" to channel_up"];
msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel up" ); msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel up" );
} }
else else
{ {
eyetvCommand = 'Chdn'; /* same style again */ script = [[NSAppleScript alloc] initWithSource:@"tell application \"EyeTV\" to channel_down"];
msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel down" ); msg_Dbg( VLCIntf, "telling eyetv to switch 1 channel down" );
} }
err = AEBuildAppleEvent( descriptor = [script executeAndReturnError:&errorDict];
/* EyeTV script suite */ eyetvSignature, if( nil == descriptor )
/* command */ eyetvCommand,
/* signature type */ typeApplSignature,
/* signature */ &eyetvSignature,
/* signature size */ sizeof(eyetvSignature),
/* basic return id */ kAutoGenerateReturnID,
/* generic transaction id */ kAnyTransactionID,
/* to-be-created AE */ &ourAE,
/* get some possible errors */ &theBuildError,
/* got no params for now */ "" );
if( err != aeBuildSyntaxNoErr )
{ {
msg_Err( VLCIntf, "Error %i encountered while trying to the build the AE to launch eyetv.\n" \ NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
"additionally, the following info was returned: AEBuildErrorCode:%i at pos:%i", msg_Err( VLCIntf, "EyeTV channel change failed with error code %s", [errorString UTF8String] );
(int)err, theBuildError.fError, theBuildError.fErrorPos);
return;
} }
else [script release];
msg_Dbg( VLCIntf, "AE created successfully, trying to send now" );
err = AESendMessage(
/* our AE */ &ourAE,
/* no need for a response-AE */ NULL,
/* we neither want a response nor user interaction */ kAENoReply | kAENeverInteract,
/* we don't need a special time-out */ kAEDefaultTimeout );
if( err != noErr )
msg_Err( VLCIntf, "Error %i encountered while trying to tell EyeTV to switch channel", (int)err );
err = AEDisposeDesc(&ourAE);
} }
- (void)selectChannel: (int)theChannelNum - (void)selectChannel: (int)theChannelNum
{ {
NSAppleScript *script;
switch( theChannelNum )
{
case -2: // Composite
script = [[NSAppleScript alloc] initWithSource:
@"tell application \"EyeTV\" to input_change input source composite video input"];
break;
case -1: // S-Video
script = [[NSAppleScript alloc] initWithSource:
@"tell application \"EyeTV\" to input_change input source S video input"];
break;
case 0: // Tuner
script = [[NSAppleScript alloc] initWithSource:
@"tell application \"EyeTV\" to input_change input source tuner input"];
break;
default:
if( theChannelNum > 0 )
{
NSString *channel_change = [NSString stringWithFormat:
@"tell application \"EyeTV\" to channel_change channel number %d", theChannelNum];
script = [[NSAppleScript alloc] initWithSource:channel_change];
}
else
return;
}
NSDictionary *errorDict;
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
if( nil == descriptor )
{
NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
msg_Err( VLCIntf, "EyeTV source change failed with error code %s", [errorString UTF8String] );
}
[script release];
} }
- (int)getNumberOfChannels - (NSEnumerator *)getChannels
{
return 2;
}
- (NSString *)getNameOfChannel: (int)theChannelNum
{ {
return @"dummy name"; NSEnumerator *channels = nil;
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:
@"tell application \"EyeTV\" to get name of every channel"];
NSDictionary *errorDict;
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&errorDict];
if( nil == descriptor )
{
NSString *errorString = [errorDict objectForKey:NSAppleScriptErrorMessage];
msg_Err( VLCIntf, "EyeTV channel inventory failed with error code %s", [errorString UTF8String] );
}
else
{
int count = [descriptor numberOfItems];
int x=0;
NSMutableArray *channelArray = [NSMutableArray arrayWithCapacity:count];
while( x++ < count ) {
[channelArray addObject:[[descriptor descriptorAtIndex:x] stringValue]];
}
channels = [channelArray objectEnumerator];
}
[script release];
return channels;
} }
@end @end
...@@ -804,7 +804,7 @@ static VLCOpen *_o_sharedMainInstance = nil; ...@@ -804,7 +804,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
[[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO]; [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO];
else if( sender == o_eyetv_channels_pop ) else if( sender == o_eyetv_channels_pop )
[[[VLCMain sharedInstance] getEyeTVController] selectChannel: [[[VLCMain sharedInstance] getEyeTVController] selectChannel:
[sender indexOfSelectedItem]]; [[sender selectedItem] tag]];
else else
msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" ); msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
} }
...@@ -856,16 +856,29 @@ static VLCOpen *_o_sharedMainInstance = nil; ...@@ -856,16 +856,29 @@ static VLCOpen *_o_sharedMainInstance = nil;
[o_eyetv_chn_status_txt setHidden: NO]; [o_eyetv_chn_status_txt setHidden: NO];
/* retrieve info */ /* retrieve info */
int x = 0; NSEnumerator *channels = [[[VLCMain sharedInstance] getEyeTVController] getChannels];
int channelCount = ( [[[VLCMain sharedInstance] getEyeTVController] getNumberOfChannels] + 1 ); int x = -2;
while( x != channelCount ) [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Composite input")
action: nil
keyEquivalent: @""] setTag:x++];
[[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
action: nil
keyEquivalent: @""] setTag:x++];
if( channels )
{
NSString *channel;
[[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Tuner")
action: nil
keyEquivalent: @""] setTag:x++];
[[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
while( channel = [channels nextObject] )
{ {
/* we have to add items this way, because we accept duplicates /* we have to add items this way, because we accept duplicates
* additionally, we save a bit of time */ * additionally, we save a bit of time */
[[o_eyetv_channels_pop menu] addItemWithTitle: [[[VLCMain sharedInstance] getEyeTVController] getNameOfChannel: x] [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
action: nil action: nil
keyEquivalent: @""]; keyEquivalent: @""] setTag:x++];
x += 1; }
} }
/* clean up GUI */ /* clean up GUI */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment