1 /*****************************************************************************
2 * applescript.m: MacOS X AppleScript support
3 *****************************************************************************
4 * Copyright (C) 2002-2009 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include "applescript.h"
29 #include "CoreInteraction.h"
30 #include "vlc_aout_intf.h"
32 /*****************************************************************************
33 * VLGetURLScriptCommand implementation
34 *****************************************************************************/
35 @implementation VLGetURLScriptCommand
37 - (id)performDefaultImplementation {
38 NSString *o_command = [[self commandDescription] commandName];
39 NSString *o_urlString = [self directParameter];
41 if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
43 intf_thread_t * p_intf = VLCIntf;
44 playlist_t * p_playlist = pl_Get( p_intf );
45 if( p_playlist == NULL )
53 input_item_t *p_input;
55 p_input = input_item_New( [o_urlString fileSystemRepresentation],
56 [[[NSFileManager defaultManager]
57 displayNameAtPath: o_urlString] UTF8String] );
58 /* FIXME: playlist_AddInput() can fail */
59 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
60 PLAYLIST_END, true, pl_Unlocked );
62 vlc_gc_decref( p_input );
64 o_url = [NSURL fileURLWithPath: o_urlString];
67 [[NSDocumentController sharedDocumentController]
68 noteNewRecentDocumentURL: o_url];
78 /*****************************************************************************
79 * VLControlScriptCommand implementation
80 *****************************************************************************/
82 * This entire control command needs a better design. more object oriented.
83 * Applescript developers would be very welcome (hartman)
85 @implementation VLControlScriptCommand
87 - (id)performDefaultImplementation {
88 NSString *o_command = [[self commandDescription] commandName];
89 NSString *o_parameter = [self directParameter];
91 intf_thread_t * p_intf = VLCIntf;
92 playlist_t * p_playlist = pl_Get( p_intf );
93 if( p_playlist == NULL )
98 if ( [o_command isEqualToString:@"play"] )
100 [[VLCCoreInteraction sharedInstance] play];
102 else if ( [o_command isEqualToString:@"stop"] )
104 [[VLCCoreInteraction sharedInstance] stop];
106 else if ( [o_command isEqualToString:@"previous"] )
108 [[VLCCoreInteraction sharedInstance] previous];
110 else if ( [o_command isEqualToString:@"next"] )
112 [[VLCCoreInteraction sharedInstance] next];
114 else if ( [o_command isEqualToString:@"fullscreen"] )
116 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
118 else if ( [o_command isEqualToString:@"mute"] )
120 [[VLCCoreInteraction sharedInstance] mute];
122 else if ( [o_command isEqualToString:@"volumeUp"] )
124 [[VLCCoreInteraction sharedInstance] volumeUp];
126 else if ( [o_command isEqualToString:@"volumeDown"] )
128 [[VLCCoreInteraction sharedInstance] volumeDown];
130 else if ( [o_command isEqualToString:@"stepForward"] )
132 //default: forwardShort
135 int i_parameter = [o_parameter intValue];
139 [[VLCCoreInteraction sharedInstance] forwardExtraShort];
142 [[VLCCoreInteraction sharedInstance] forwardShort];
145 [[VLCCoreInteraction sharedInstance] forwardMedium];
148 [[VLCCoreInteraction sharedInstance] forwardLong];
151 [[VLCCoreInteraction sharedInstance] forwardShort];
157 [[VLCCoreInteraction sharedInstance] forwardShort];
160 else if ( [o_command isEqualToString:@"stepBackward"] )
162 //default: backwardShort
165 int i_parameter = [o_parameter intValue];
169 [[VLCCoreInteraction sharedInstance] backwardExtraShort];
172 [[VLCCoreInteraction sharedInstance] backwardShort];
175 [[VLCCoreInteraction sharedInstance] backwardMedium];
178 [[VLCCoreInteraction sharedInstance] backwardLong];
181 [[VLCCoreInteraction sharedInstance] backwardShort];
187 [[VLCCoreInteraction sharedInstance] backwardShort];
195 /*****************************************************************************
196 * Category that adds AppleScript support to NSApplication
197 *****************************************************************************/
198 @implementation NSApplication(ScriptSupport)
200 - (BOOL) scriptFullscreenMode {
201 vout_thread_t * p_vout = getVout();
204 BOOL b_value = var_GetBool( p_vout, "fullscreen");
205 vlc_object_release( p_vout );
208 - (void) setScriptFullscreenMode: (BOOL) mode {
209 vout_thread_t * p_vout = getVout();
212 if (var_GetBool( p_vout, "fullscreen") == mode)
214 vlc_object_release( p_vout );
217 vlc_object_release( p_vout );
218 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
222 return [[VLCCoreInteraction sharedInstance] isMuted];
226 return [[VLCCoreInteraction sharedInstance] isPlaying];
229 - (int) audioVolume {
230 return ( [[VLCCoreInteraction sharedInstance] volume] );
233 - (void) setAudioVolume: (int) i_audioVolume {
234 [[VLCCoreInteraction sharedInstance] setVolume:(int)i_audioVolume];
237 - (int) currentTime {
238 return [[VLCCoreInteraction sharedInstance] currentTime];
241 - (void) setCurrentTime: (int) i_currentTime {
243 [[VLCCoreInteraction sharedInstance] setCurrentTime:i_currentTime];
247 //TODO:whenever VLC should implement NSDocument, the methods below should move or be additionaly implemented in the NSDocument category
248 - (int) durationOfCurrentItem {
249 return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
252 - (NSString*) pathOfCurrentItem {
253 return [[[VLCCoreInteraction sharedInstance] URLOfCurrentPlaylistItem] path];
256 - (NSString*) nameOfCurrentItem {
257 return [[VLCCoreInteraction sharedInstance] nameOfCurrentPlaylistItem];