]> git.sesse.net Git - vlc/blob - modules/gui/macosx/applescript.m
* Remove some unneeded complexity in playlist and directory
[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 /*****************************************************************************
34  * VLGetURLScriptCommand implementation 
35  *****************************************************************************/
36 @implementation VLGetURLScriptCommand
37
38 - (id)performDefaultImplementation {
39     NSString *o_command = [[self commandDescription] commandName];
40     NSString *o_urlString = [self directParameter];
41
42     if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
43     {
44         intf_thread_t * p_intf = VLCIntf;
45         playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
46                                                         FIND_ANYWHERE );
47         if( p_playlist == NULL )
48         {
49             return nil;
50         }
51
52         if ( o_urlString )
53         {
54             NSURL * o_url;
55             input_item_t *p_input;
56
57             p_input = input_ItemNew( p_playlist,
58                                     [o_urlString fileSystemRepresentation],
59                                     [[[NSFileManager defaultManager]
60                                     displayNameAtPath: o_urlString] UTF8String] );
61             playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
62                                PLAYLIST_END, VLC_TRUE );
63
64
65             o_url = [NSURL fileURLWithPath: o_urlString];
66             if( o_url != nil )
67             {
68                 [[NSDocumentController sharedDocumentController]
69                     noteNewRecentDocumentURL: o_url];
70             }
71         }
72         vlc_object_release( p_playlist );
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 = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
94                                                     FIND_ANYWHERE );
95     if( p_playlist == NULL )
96     {
97         return nil;
98     }
99     
100     VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
101     
102     if ( o_controls )
103     {
104         if ( [o_command isEqualToString:@"play"] )
105         {
106             [o_controls play:self];
107             return nil;
108         }
109         else if ( [o_command isEqualToString:@"stop"] )
110         {
111             [o_controls stop:self];
112             return nil;
113         }
114         else if ( [o_command isEqualToString:@"previous"] )
115         {
116             [o_controls prev:self];
117             return nil;
118         }
119         else if ( [o_command isEqualToString:@"next"] )
120         {
121             [o_controls next:self];
122             return nil;
123         }
124         else if ( [o_command isEqualToString:@"fullscreen"] )
125         {
126             NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
127             [o_controls windowAction:[o_mi autorelease]];
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