]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_controller.m
076e052515c37c4353cdb8d6bdc87b540e5fb788
[vlc] / plugins / macosx / intf_controller.m
1 /*****************************************************************************
2  * intf_controller.c: MacOS X plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: intf_controller.m,v 1.4 2002/05/20 05:20:12 jlj Exp $
6  *
7  * Authors: Florian G. Pflug <fgp@phlo.org>
8  *          Jon Lech Johansen <jon-vl@nanocrew.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #import <ApplicationServices/ApplicationServices.h>
26
27 #include <videolan/vlc.h>
28
29 #include "interface.h"
30 #include "intf_playlist.h"
31
32 #include "macosx.h"
33 #include "intf_controller.h"
34
35 @implementation Intf_Controller
36
37 /* Initialization & Event-Management */
38
39 - (void)awakeFromNib
40 {
41     NSString *pTitle = [NSString
42         stringWithCString: VOUT_TITLE " (Cocoa)"];
43
44     [o_window setTitle: pTitle];
45 }
46
47 - (void)manage
48 {
49     NSDate *sleepDate;
50     NSAutoreleasePool *o_pool;
51
52     o_pool = [[NSAutoreleasePool alloc] init];
53
54     while( ![o_intf manage] )
55     {
56         if( [o_intf playlistPlaying] )
57         { 
58             [o_time setStringValue: [o_intf getTimeAsString]];
59
60             if( f_slider == f_slider_old )
61             {
62                 float f_updated = [o_intf getTimeAsFloat];
63
64                 if( f_updated != f_slider )
65                 {
66                     if( [o_slider_lock tryLock] )
67                     {
68                         [o_timeslider setFloatValue: f_updated];
69                         [o_slider_lock unlock];
70                     }
71                 }
72             }
73             else
74             {
75                 [o_intf setTimeAsFloat: f_slider];
76                 f_slider_old = f_slider;
77             }
78
79             UpdateSystemActivity( UsrActivity );
80         }
81
82         sleepDate = [NSDate dateWithTimeIntervalSinceNow: 0.5];
83         [NSThread sleepUntilDate: sleepDate];
84     }
85
86     [self terminate];
87
88     [o_pool release];
89 }
90
91 - (void)terminate
92 {
93     NSEvent *pEvent;
94
95     [NSApp stop: nil];
96
97     [o_vout release];
98     [o_intf release];
99
100     /* send a dummy event to break out of the event loop */
101     pEvent = [NSEvent mouseEventWithType: NSLeftMouseDown
102                 location: NSMakePoint( 1, 1 ) modifierFlags: 0
103                 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
104                 context: [NSGraphicsContext currentContext] eventNumber: 1
105                 clickCount: 1 pressure: 0.0];
106     [NSApp postEvent: pEvent atStart: YES];
107 }
108
109 /* NSApplication messages */
110
111 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
112 {
113     o_intf = [[Intf_VLCWrapper instance] retain];
114     o_vout = [[Vout_VLCWrapper instance] retain];
115
116     f_slider = f_slider_old = 0.0;
117     o_slider_lock = [[NSLock alloc] init];
118
119     [NSThread detachNewThreadSelector: @selector(manage)
120         toTarget: self withObject: nil];
121 }
122
123 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
124 {
125     NSArray *o_array;
126
127     o_array = [NSArray arrayWithObject: o_filename];
128     [o_intf openFiles: o_array];
129
130     return( TRUE );
131 }
132
133 /* Functions attached to user interface */
134  
135 - (IBAction)pause:(id)sender
136 {
137     [o_intf playlistPause];
138 }
139
140 - (IBAction)play:(id)sender
141 {
142     [o_intf playlistPlay];
143 }
144
145 - (IBAction)stop:(id)sender
146 {
147     [o_intf playlistStop];
148 }
149
150 - (IBAction)faster:(id)sender
151 {
152     [o_intf playFaster];
153 }
154
155 - (IBAction)slower:(id)sender
156 {
157     [o_intf playSlower];
158 }
159
160 - (IBAction)prev:(id)sender
161 {
162     [o_intf playlistPrev];
163 }
164
165 - (IBAction)next:(id)sender
166 {
167     [o_intf playlistNext];
168 }
169
170 - (IBAction)mute:(id)sender
171 {
172     NSMenuItem * item = (NSMenuItem *)sender;
173
174     [o_intf mute];
175
176     if( p_main->p_intf->p_sys->b_mute )
177     {
178         [item setState:NSOnState];
179     }
180     else
181     {
182         [item setState:NSOffState];
183     }
184 }
185
186 - (IBAction)fullscreen:(id)sender
187 {
188     [o_intf fullscreen];
189 }
190
191 - (IBAction)eject:(id)sender
192 {
193     [o_intf eject];
194 }
195
196 - (IBAction)maxvolume:(id)sender
197 {
198     [o_intf maxvolume];
199 }
200
201 - (IBAction)timesliderUpdate:(id)slider
202 {
203     switch( [[NSApp currentEvent] type] )
204     {
205         case NSLeftMouseDown:
206             [o_slider_lock tryLock];
207             break;
208
209         case NSLeftMouseUp:
210             f_slider = [o_timeslider floatValue];
211             [o_slider_lock unlock];
212             break;
213
214         default:
215             break;
216     }
217 }
218
219 - (IBAction)quit:(id)sender
220 {
221     [o_intf quit];
222 }
223
224 @end
225
226 @implementation Intf_PlaylistDS
227
228 - (id)init
229 {
230     if( [super init] == nil )
231         return( nil );
232
233     o_playlist = nil;
234
235     return( self );
236 }
237
238 - (void)readPlaylist
239 {
240     o_playlist = [[[Intf_VLCWrapper instance] playlistAsArray] retain];
241 }
242
243 - (int)numberOfRowsInTableView:(NSTableView*)o_table
244 {
245     [self readPlaylist];
246     return( [o_playlist count] );
247 }
248     
249 - (id)tableView:(NSTableView *)o_table objectValueForTableColumn:(NSTableColumn*)o_column row:(int)i_row
250 {
251     return( [o_playlist objectAtIndex: i_row] );
252 }
253     
254 - (void)tableView:(NSTableView *)o_table setObjectValue:o_value forTableColumn:(NSTableColumn *)o_column row:(int)i_index
255 {
256 }
257
258 @end