]> git.sesse.net Git - vlc/blob - modules/gui/macosx/applescript.m
0f4a8794128508e21bb8e2b3e6e3040900705070
[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 "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 = pl_Hold( p_intf );
45         if( p_playlist == NULL )
46         {
47             return nil;
48         }
49
50         if ( o_urlString )
51         {
52             NSURL * o_url;
53             input_item_t *p_input;
54
55             p_input = input_item_New( p_playlist,
56                                     [o_urlString fileSystemRepresentation],
57                                     [[[NSFileManager defaultManager]
58                                     displayNameAtPath: o_urlString] UTF8String] );
59             /* FIXME: playlist_AddInput() can fail */
60             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
61                                PLAYLIST_END, true, pl_Unlocked );
62
63             vlc_gc_decref( p_input );
64
65             o_url = [NSURL fileURLWithPath: o_urlString];
66             if( o_url != nil )
67             {
68                 [[NSDocumentController sharedDocumentController]
69                     noteNewRecentDocumentURL: o_url];
70             }
71         }
72         pl_Release( p_intf );
73     }
74     return nil;
75 }
76
77 @end
78
79
80 /*****************************************************************************
81  * VLControlScriptCommand implementation
82  *****************************************************************************/
83 /*
84  * This entire control command needs a better design. more object oriented.
85  * Applescript developers would be very welcome (hartman)
86  */
87 @implementation VLControlScriptCommand
88
89 - (id)performDefaultImplementation {
90     NSString *o_command = [[self commandDescription] commandName];
91
92     intf_thread_t * p_intf = VLCIntf;
93     playlist_t * p_playlist = pl_Hold( p_intf );
94     if( p_playlist == NULL )
95     {
96         return nil;
97     }
98  
99     VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
100  
101     if ( o_controls )
102     {
103         if ( [o_command isEqualToString:@"play"] )
104         {
105             [o_controls play:self];
106         }
107         else if ( [o_command isEqualToString:@"stop"] )
108         {
109             [o_controls stop:self];
110         }
111         else if ( [o_command isEqualToString:@"previous"] )
112         {
113             [o_controls prev:self];
114         }
115         else if ( [o_command isEqualToString:@"next"] )
116         {
117             [o_controls next:self];
118         }
119         else if ( [o_command isEqualToString:@"fullscreen"] )
120         {
121             [o_controls toogleFullscreen: self];
122         }
123         else if ( [o_command isEqualToString:@"mute"] )
124         {
125             [o_controls mute:self];
126         }
127         else if ( [o_command isEqualToString:@"volumeUp"] )
128         {
129             [o_controls volumeUp:self];
130         }
131         else if ( [o_command isEqualToString:@"volumeDown"] )
132         {
133             [o_controls volumeDown:self];
134         }
135     }
136     pl_Release( p_intf );
137     return nil;
138 }
139
140 @end
141
142 /*****************************************************************************
143  * Category that adds AppleScript support to NSApplication
144  *****************************************************************************/
145 @implementation NSApplication(ScriptSupport)
146
147 - (BOOL) scriptFullscreenMode {    
148     VLCControls * o_controls = (VLCControls *)[[self delegate] getControls];
149
150     return [o_controls isFullscreen];
151 }
152 - (void) setScriptFullscreenMode: (BOOL) mode {
153     VLCControls * o_controls = (VLCControls *)[[self delegate] getControls];
154     if (mode == [o_controls isFullscreen]) return;
155     [o_controls toogleFullscreen: self];
156 }
157
158 @end