]> git.sesse.net Git - vlc/blob - modules/gui/macosx/applescript.m
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / modules / gui / macosx / applescript.m
1 /*****************************************************************************
2  * applescript.m: MacOS X AppleScript support
3  *****************************************************************************
4  * Copyright (C) 2002-2003, 2005, 2007 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 "controls.h"
30 #include "open.h"
31
32 /*****************************************************************************
33  * VLGetURLScriptCommand implementation
34  *****************************************************************************/
35 @implementation VLGetURLScriptCommand
36
37 - (id)performDefaultImplementation {
38     NSString *o_command = [[self commandDescription] commandName];
39     NSString *o_urlString = [self directParameter];
40
41     if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
42     {
43         intf_thread_t * p_intf = VLCIntf;
44         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
45                                                         FIND_ANYWHERE );
46         if( p_playlist == NULL )
47         {
48             return nil;
49         }
50
51         if ( o_urlString )
52         {
53             NSURL * o_url;
54             input_item_t *p_input;
55
56             p_input = input_ItemNew( p_playlist,
57                                     [o_urlString fileSystemRepresentation],
58                                     [[[NSFileManager defaultManager]
59                                     displayNameAtPath: o_urlString] UTF8String] );
60             /* FIXME: playlist_AddInput() can fail */
61             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
62                                PLAYLIST_END, true, false );
63
64             vlc_gc_decref( p_input );
65
66             o_url = [NSURL fileURLWithPath: o_urlString];
67             if( o_url != nil )
68             {
69                 [[NSDocumentController sharedDocumentController]
70                     noteNewRecentDocumentURL: o_url];
71             }
72         }
73         vlc_object_release( p_playlist );
74     }
75     return nil;
76 }
77
78 @end
79
80
81 /*****************************************************************************
82  * VLControlScriptCommand implementation
83  *****************************************************************************/
84 /*
85  * This entire control command needs a better design. more object oriented.
86  * Applescript developers would be very welcome (hartman)
87  */
88 @implementation VLControlScriptCommand
89
90 - (id)performDefaultImplementation {
91     NSString *o_command = [[self commandDescription] commandName];
92
93     intf_thread_t * p_intf = VLCIntf;
94     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
95                                                     FIND_ANYWHERE );
96     if( p_playlist == NULL )
97     {
98         return nil;
99     }
100  
101     VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
102  
103     if ( o_controls )
104     {
105         if ( [o_command isEqualToString:@"play"] )
106         {
107             [o_controls play:self];
108             return nil;
109         }
110         else if ( [o_command isEqualToString:@"stop"] )
111         {
112             [o_controls stop:self];
113             return nil;
114         }
115         else if ( [o_command isEqualToString:@"previous"] )
116         {
117             [o_controls prev:self];
118             return nil;
119         }
120         else if ( [o_command isEqualToString:@"next"] )
121         {
122             [o_controls next:self];
123             return nil;
124         }
125         else if ( [o_command isEqualToString:@"fullscreen"] )
126         {
127             [o_controls toogleFullscreen: self];
128             return nil;
129         }
130         else if ( [o_command isEqualToString:@"mute"] )
131         {
132             [o_controls mute:self];
133             return nil;
134         }
135         else if ( [o_command isEqualToString:@"volumeUp"] )
136         {
137             [o_controls volumeUp:self];
138             return nil;
139         }
140         else if ( [o_command isEqualToString:@"volumeDown"] )
141         {
142             [o_controls volumeDown:self];
143             return nil;
144         }
145     }
146     vlc_object_release( p_playlist );
147     return nil;
148 }
149
150 @end
151
152 /*****************************************************************************
153  * Category that adds AppleScript support to NSApplication
154  *****************************************************************************/
155 @implementation NSApplication(ScriptSupport)
156
157 - (BOOL) scriptFullscreenMode {    
158     VLCControls * o_controls = (VLCControls *)[[self delegate] getControls];
159
160     return [o_controls isFullscreen];
161 }
162 - (void) setScriptFullscreenMode: (BOOL) mode {
163     VLCControls * o_controls = (VLCControls *)[[self delegate] getControls];
164     if (mode == [o_controls isFullscreen]) return;
165     [o_controls toogleFullscreen: self];
166 }
167
168 @end