applescript.m 4.73 KB
Newer Older
hartman's avatar
hartman committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*****************************************************************************
 * applescript.m: MacOS X AppleScript support
 *****************************************************************************
 * Copyright (C) 2002-2003 VideoLAN
 * $Id: applescript.m,v 1.1 2003/03/06 11:43:07 hartman Exp $
 *
 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include "intf.h"
#include "applescript.h"
#include "controls.h"
#include "open.h"


/*****************************************************************************
 * VLGetURLScriptCommand implementation 
 *****************************************************************************/
@implementation VLGetURLScriptCommand

- (id)performDefaultImplementation {
    NSString *o_command = [[self commandDescription] commandName];
    NSString *o_urlString = [self directParameter];

    if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
    {
        intf_thread_t * p_intf = [NSApp getIntf];
        playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
        if( p_playlist == NULL )
        {
            return nil;
        }

        if ( o_urlString )
        {
            NSURL * o_url;
    
            int i_mode = PLAYLIST_INSERT | PLAYLIST_GO;
            
            playlist_Add( p_playlist, [o_urlString fileSystemRepresentation],
                                                    i_mode, PLAYLIST_END );

            o_url = [NSURL fileURLWithPath: o_urlString];
            if( o_url != nil )
            { 
                [[NSDocumentController sharedDocumentController]
                    noteNewRecentDocumentURL: o_url]; 
            }
        }
        vlc_object_release( p_playlist );
    }
    return nil;
}

@end


/*****************************************************************************
 * VLControlScriptCommand implementation 
 *****************************************************************************/
/*
 * This entire control command needs a better design. more object oriented.
 * Applescript developers would be very welcome (hartman)
 */
@implementation VLControlScriptCommand

- (id)performDefaultImplementation {
    NSString *o_command = [[self commandDescription] commandName];

    intf_thread_t * p_intf = [NSApp getIntf];
    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
                                                    FIND_ANYWHERE );
    if( p_playlist == NULL )
    {
        return nil;
    }
    
    VLCControls * o_controls = (VLCControls *)[[NSApp delegate] getControls];
    
    if ( o_controls )
    {
        if ( [o_command isEqualToString:@"play"] )
        {
            [o_controls play:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"stop"] )
        {
            [o_controls stop:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"previous"] )
        {
            [o_controls prev:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"next"] )
        {
            [o_controls next:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"fullscreen"] )
        {
            [o_controls fullscreen:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"mute"] )
        {
            [o_controls mute:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"volumeUp"] )
        {
            [o_controls volumeUp:self];
            return nil;
        }
        else if ( [o_command isEqualToString:@"volumeDown"] )
        {
            [o_controls volumeDown:self];
            return nil;
        }
    }
    vlc_object_release( p_playlist );
    return nil;
}

@end