]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_controller.m
* Fixed some compile issues with what I checked in.
[vlc] / plugins / macosx / intf_controller.m
1 /*****************************************************************************
2  * intf_controller.m: MacOS X plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: intf_controller.m,v 1.9 2002/06/08 19:32:19 sam 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 <vlc/vlc.h>
28 #include <vlc/intf.h>
29
30 #include "macosx.h"
31 #include "intf_controller.h"
32
33 @implementation Intf_Controller
34
35 /* Initialization & Event-Management */
36
37 - (void)awakeFromNib
38 {
39     NSString *pTitle = [NSString
40         stringWithCString: VOUT_TITLE " (Cocoa)"];
41
42     [o_window setTitle: pTitle];
43 }
44
45 - (void)manage
46 {
47     NSDate *sleepDate;
48     NSAutoreleasePool *o_pool;
49
50     o_pool = [[NSAutoreleasePool alloc] init];
51
52     while( ![o_intf manage] )
53     {
54         if( [o_intf playlistPlaying] )
55         { 
56             [o_time setStringValue: [o_intf getTimeAsString]];
57
58             if( f_slider == f_slider_old )
59             {
60                 float f_updated = [o_intf getTimeAsFloat];
61
62                 if( f_updated != f_slider )
63                 {
64                     if( [o_slider_lock tryLock] )
65                     {
66                         [o_timeslider setFloatValue: f_updated];
67                         [o_slider_lock unlock];
68                     }
69                 }
70             }
71             else
72             {
73                 [o_intf setTimeAsFloat: f_slider];
74                 f_slider_old = f_slider;
75             }
76
77             UpdateSystemActivity( UsrActivity );
78         }
79
80         sleepDate = [NSDate dateWithTimeIntervalSinceNow: 0.5];
81         [NSThread sleepUntilDate: sleepDate];
82     }
83
84     [self terminate];
85
86     [o_pool release];
87 }
88
89 - (void)terminate
90 {
91     NSEvent *pEvent;
92
93     [NSApp stop: nil];
94
95     [o_vout release];
96     [o_intf release];
97
98     /* send a dummy event to break out of the event loop */
99     pEvent = [NSEvent mouseEventWithType: NSLeftMouseDown
100                 location: NSMakePoint( 1, 1 ) modifierFlags: 0
101                 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
102                 context: [NSGraphicsContext currentContext] eventNumber: 1
103                 clickCount: 1 pressure: 0.0];
104     [NSApp postEvent: pEvent atStart: YES];
105 }
106
107 /* NSApplication messages */
108
109 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
110 {
111     o_intf = [[Intf_VLCWrapper instance] retain];
112     o_vout = [[Vout_VLCWrapper instance] retain];
113
114     f_slider = f_slider_old = 0.0;
115     o_slider_lock = [[NSLock alloc] init];
116
117     [NSThread detachNewThreadSelector: @selector(manage)
118         toTarget: self withObject: nil];
119 }
120
121 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
122 {
123     NSArray *o_array;
124
125     o_array = [NSArray arrayWithObject: o_filename];
126     [o_intf openFiles: o_array];
127
128     return( TRUE );
129 }
130
131 /* Functions attached to user interface */
132  
133 - (IBAction)pause:(id)sender
134 {
135     [o_intf playlistPause];
136 }
137
138 - (IBAction)play:(id)sender
139 {
140     [o_intf playlistPlay];
141 }
142
143 - (IBAction)stop:(id)sender
144 {
145     [o_intf playlistStop];
146 }
147
148 - (IBAction)faster:(id)sender
149 {
150     [o_intf playFaster];
151 }
152
153 - (IBAction)slower:(id)sender
154 {
155     [o_intf playSlower];
156 }
157
158 - (IBAction)prev:(id)sender
159 {
160     [o_intf playlistPrev];
161 }
162
163 - (IBAction)next:(id)sender
164 {
165     [o_intf playlistNext];
166 }
167
168 - (IBAction)prevChannel:(id)sender
169 {
170     [o_intf channelPrev];
171 }
172
173 - (IBAction)nextChannel:(id)sender
174 {
175     [o_intf channelNext];
176 }
177
178 - (IBAction)loop:(id)sender
179 {
180     NSMenuItem * item = (NSMenuItem *)sender;
181
182     [o_intf loop];
183
184     if( p_main->p_intf->p_sys->b_loop )
185     {
186         [item setState:NSOnState];
187     }
188     else
189     {
190         [item setState:NSOffState];
191     }
192 }
193
194 - (IBAction)mute:(id)sender
195 {
196     NSMenuItem * item = (NSMenuItem *)sender;
197
198     [o_intf mute];
199
200     if( p_main->p_intf->p_sys->b_mute )
201     {
202         [item setState:NSOnState];
203     }
204     else
205     {
206         [item setState:NSOffState];
207     }
208 }
209
210 - (IBAction)fullscreen:(id)sender
211 {
212     [o_intf fullscreen];
213 }
214
215 - (IBAction)eject:(id)sender
216 {
217     [o_intf eject];
218 }
219
220 - (IBAction)maxvolume:(id)sender
221 {
222     [o_intf maxvolume];
223 }
224
225 - (IBAction)timesliderUpdate:(id)slider
226 {
227     switch( [[NSApp currentEvent] type] )
228     {
229         case NSLeftMouseDown:
230             [o_slider_lock tryLock];
231             break;
232
233         case NSLeftMouseUp:
234             f_slider = [o_timeslider floatValue];
235             [o_slider_lock unlock];
236             break;
237
238         default:
239             break;
240     }
241 }
242
243 - (IBAction)quit:(id)sender
244 {
245     [o_intf quit];
246 }
247
248 - (BOOL)validateMenuItem:(id)sender
249 {
250     NSMenuItem * o_item = (NSMenuItem *)sender;
251     int tag = [o_item tag];
252
253     if ( tag == 12 || tag == 13 )
254     {
255         if( !config_GetIntVariable( "network-channel" ) )
256         {
257             return NO;
258         }
259         if ( tag == 12 && !p_main->p_intf->p_sys->i_channel )
260         {
261             return NO;
262         }
263     }
264         
265     return YES;
266 }
267
268 @end
269
270 @implementation Intf_PlaylistDS
271
272 - (id)init
273 {
274     if( [super init] == nil )
275         return( nil );
276
277     o_playlist = nil;
278
279     return( self );
280 }
281
282 - (void)readPlaylist
283 {
284     o_playlist = [[[Intf_VLCWrapper instance] playlistAsArray] retain];
285 }
286
287 - (int)numberOfRowsInTableView:(NSTableView*)o_table
288 {
289     [self readPlaylist];
290     return( [o_playlist count] );
291 }
292     
293 - (id)tableView:(NSTableView *)o_table objectValueForTableColumn:(NSTableColumn*)o_column row:(int)i_row
294 {
295     return( [o_playlist objectAtIndex: i_row] );
296 }
297     
298 - (void)tableView:(NSTableView *)o_table setObjectValue:o_value forTableColumn:(NSTableColumn *)o_column row:(int)i_index
299 {
300 }
301
302 @end