]> git.sesse.net Git - vlc/blob - modules/gui/macosx/applescript.m
Removes trailing spaces. Removes tabs.
[vlc] / modules / gui / macosx / applescript.m
1 /*****************************************************************************
2  * applescript.m: MacOS X AppleScript support
3  *****************************************************************************
4  * Copyright (C) 2002-2003 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             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
61                                PLAYLIST_END, VLC_TRUE, VLC_FALSE );
62
63
64             o_url = [NSURL fileURLWithPath: o_urlString];
65             if( o_url != nil )
66             {
67                 [[NSDocumentController sharedDocumentController]
68                     noteNewRecentDocumentURL: o_url];
69             }
70         }
71         vlc_object_release( p_playlist );
72     }
73     return nil;
74 }
75
76 @end
77
78
79 /*****************************************************************************
80  * VLControlScriptCommand implementation
81  *****************************************************************************/
82 /*
83  * This entire control command needs a better design. more object oriented.
84  * Applescript developers would be very welcome (hartman)
85  */
86 @implementation VLControlScriptCommand
87
88 - (id)performDefaultImplementation {
89     NSString *o_command = [[self commandDescription] commandName];
90
91     intf_thread_t * p_intf = VLCIntf;
92     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
93                                                     FIND_ANYWHERE );
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             return nil;
107         }
108         else if ( [o_command isEqualToString:@"stop"] )
109         {
110             [o_controls stop:self];
111             return nil;
112         }
113         else if ( [o_command isEqualToString:@"previous"] )
114         {
115             [o_controls prev:self];
116             return nil;
117         }
118         else if ( [o_command isEqualToString:@"next"] )
119         {
120             [o_controls next:self];
121             return nil;
122         }
123         else if ( [o_command isEqualToString:@"fullscreen"] )
124         {
125             [o_controls toogleFullscreen: self];
126             return nil;
127         }
128         else if ( [o_command isEqualToString:@"mute"] )
129         {
130             [o_controls mute:self];
131             return nil;
132         }
133         else if ( [o_command isEqualToString:@"volumeUp"] )
134         {
135             [o_controls volumeUp:self];
136             return nil;
137         }
138         else if ( [o_command isEqualToString:@"volumeDown"] )
139         {
140             [o_controls volumeDown:self];
141             return nil;
142         }
143     }
144     vlc_object_release( p_playlist );
145     return nil;
146 }
147
148 @end
149
150 /*****************************************************************************
151  * Category that adds AppleScript support to NSApplication
152  *****************************************************************************/
153 @implementation NSApplication(ScriptSupport)
154
155 - (BOOL) scriptFullscreenMode {    
156     VLCControls * o_controls = (VLCControls *)[[self delegate] getControls];
157
158     return [o_controls isFullscreen];
159 }
160 - (void) setScriptFullscreenMode: (BOOL) mode {
161     VLCControls * o_controls = (VLCControls *)[[self delegate] getControls];
162     if (mode == [o_controls isFullscreen]) return;
163     [o_controls toogleFullscreen: self];
164 }
165
166 @end