]> git.sesse.net Git - vlc/blob - modules/gui/macosx/applescript.m
macosx: fail the video output if Quartz Extreme isn't supported, removed specific...
[vlc] / modules / gui / macosx / applescript.m
1 /*****************************************************************************
2  * applescript.m: MacOS X AppleScript support
3  *****************************************************************************
4  * Copyright (C) 2002-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "intf.h"
28 #include "applescript.h"
29 #include "CoreInteraction.h"
30
31 /*****************************************************************************
32  * VLGetURLScriptCommand implementation
33  *****************************************************************************/
34 @implementation VLGetURLScriptCommand
35
36 - (id)performDefaultImplementation {
37     NSString *o_command = [[self commandDescription] commandName];
38     NSString *o_urlString = [self directParameter];
39
40     if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
41     {
42         intf_thread_t * p_intf = VLCIntf;
43         playlist_t * p_playlist = pl_Get( p_intf );
44         if( p_playlist == NULL )
45         {
46             return nil;
47         }
48
49         if ( o_urlString )
50         {
51             NSURL * o_url;
52             input_item_t *p_input;
53
54             p_input = input_item_New( [o_urlString fileSystemRepresentation],
55                                     [[[NSFileManager defaultManager]
56                                     displayNameAtPath: o_urlString] UTF8String] );
57             /* FIXME: playlist_AddInput() can fail */
58             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
59                                PLAYLIST_END, true, pl_Unlocked );
60
61             vlc_gc_decref( p_input );
62
63             o_url = [NSURL fileURLWithPath: o_urlString];
64             if( o_url != nil )
65             {
66                 [[NSDocumentController sharedDocumentController]
67                     noteNewRecentDocumentURL: o_url];
68             }
69         }
70     }
71     return nil;
72 }
73
74 @end
75
76
77 /*****************************************************************************
78  * VLControlScriptCommand implementation
79  *****************************************************************************/
80 /*
81  * This entire control command needs a better design. more object oriented.
82  * Applescript developers would be very welcome (hartman)
83  */
84 @implementation VLControlScriptCommand
85
86 - (id)performDefaultImplementation {
87     NSString *o_command = [[self commandDescription] commandName];
88
89     intf_thread_t * p_intf = VLCIntf;
90     playlist_t * p_playlist = pl_Get( p_intf );
91     if( p_playlist == NULL )
92     {
93         return nil;
94     }
95  
96     if ( [o_command isEqualToString:@"play"] )
97     {
98         [[VLCCoreInteraction sharedInstance] play];
99     }
100     else if ( [o_command isEqualToString:@"stop"] )
101     {
102         [[VLCCoreInteraction sharedInstance] stop];
103     }
104     else if ( [o_command isEqualToString:@"previous"] )
105     {
106         [[VLCCoreInteraction sharedInstance] previous];
107     }
108     else if ( [o_command isEqualToString:@"next"] )
109     {
110         [[VLCCoreInteraction sharedInstance] next];
111     }
112     else if ( [o_command isEqualToString:@"fullscreen"] )
113     {
114         [[VLCCoreInteraction sharedInstance] toggleFullscreen];
115     }
116     else if ( [o_command isEqualToString:@"mute"] )
117     {
118         [[VLCCoreInteraction sharedInstance] mute];
119     }
120     else if ( [o_command isEqualToString:@"volumeUp"] )
121     {
122         [[VLCCoreInteraction sharedInstance] volumeUp];
123     }
124     else if ( [o_command isEqualToString:@"volumeDown"] )
125     {
126         [[VLCCoreInteraction sharedInstance] volumeDown];
127     }
128     return nil;
129 }
130
131 @end
132
133 /*****************************************************************************
134  * Category that adds AppleScript support to NSApplication
135  *****************************************************************************/
136 @implementation NSApplication(ScriptSupport)
137
138 - (BOOL) scriptFullscreenMode {    
139     vout_thread_t * p_vout = getVout();
140     if( !p_vout )
141         return NO;
142     BOOL b_value = var_GetBool( p_vout, "fullscreen");
143     vlc_object_release( p_vout );
144     return b_value;
145 }
146 - (void) setScriptFullscreenMode: (BOOL) mode {
147     vout_thread_t * p_vout = getVout();
148     if( !p_vout )
149         return;
150     if (var_GetBool( p_vout, "fullscreen") == mode)
151     {
152         vlc_object_release( p_vout );
153         return;
154     }
155     vlc_object_release( p_vout );
156     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
157 }
158
159 @end