]> git.sesse.net Git - vlc/blob - modules/gui/macosx/applescript.m
Make the playlist info window a new object
[vlc] / modules / gui / macosx / applescript.m
1 /*****************************************************************************
2  * applescript.m: MacOS X AppleScript support
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, 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 = [NSApp getIntf];
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     
56             int i_mode = PLAYLIST_INSERT;
57             
58             playlist_Add( p_playlist, [o_urlString fileSystemRepresentation],
59                           [[o_urlString fileSystemRepresentation] lastPathComponent],
60                           i_mode, PLAYLIST_END );
61
62             o_url = [NSURL fileURLWithPath: o_urlString];
63             if( o_url != nil )
64             { 
65                 [[NSDocumentController sharedDocumentController]
66                     noteNewRecentDocumentURL: o_url]; 
67             }
68         }
69         vlc_object_release( p_playlist );
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 = [NSApp getIntf];
90     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
91                                                     FIND_ANYWHERE );
92     if( p_playlist == NULL )
93     {
94         return nil;
95     }
96     
97     VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
98     
99     if ( o_controls )
100     {
101         if ( [o_command isEqualToString:@"play"] )
102         {
103             [o_controls play:self];
104             return nil;
105         }
106         else if ( [o_command isEqualToString:@"stop"] )
107         {
108             [o_controls stop:self];
109             return nil;
110         }
111         else if ( [o_command isEqualToString:@"previous"] )
112         {
113             [o_controls prev:self];
114             return nil;
115         }
116         else if ( [o_command isEqualToString:@"next"] )
117         {
118             [o_controls next:self];
119             return nil;
120         }
121         else if ( [o_command isEqualToString:@"fullscreen"] )
122         {
123             NSMenuItem *o_mi = [[NSMenuItem alloc] initWithTitle: _NS("Fullscreen") action: nil keyEquivalent:@""];
124             [o_controls windowAction:[o_mi autorelease]];
125             return nil;
126         }
127         else if ( [o_command isEqualToString:@"mute"] )
128         {
129             [o_controls mute:self];
130             return nil;
131         }
132         else if ( [o_command isEqualToString:@"volumeUp"] )
133         {
134             [o_controls volumeUp:self];
135             return nil;
136         }
137         else if ( [o_command isEqualToString:@"volumeDown"] )
138         {
139             [o_controls volumeDown:self];
140             return nil;
141         }
142     }
143     vlc_object_release( p_playlist );
144     return nil;
145 }
146
147 @end