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 $
7 * Authors: Florian G. Pflug <fgp@phlo.org>
8 * Jon Lech Johansen <jon-vl@nanocrew.net>
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.
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.
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 *****************************************************************************/
25 #import <ApplicationServices/ApplicationServices.h>
27 #include <videolan/vlc.h>
29 #include "interface.h"
30 #include "intf_playlist.h"
33 #include "intf_controller.h"
35 @implementation Intf_Controller
37 /* Initialization & Event-Management */
41 NSString *pTitle = [NSString
42 stringWithCString: VOUT_TITLE " (Cocoa)"];
44 [o_window setTitle: pTitle];
50 NSAutoreleasePool *o_pool;
52 o_pool = [[NSAutoreleasePool alloc] init];
54 while( ![o_intf manage] )
56 if( [o_intf playlistPlaying] )
58 [o_time setStringValue: [o_intf getTimeAsString]];
60 if( f_slider == f_slider_old )
62 float f_updated = [o_intf getTimeAsFloat];
64 if( f_updated != f_slider )
66 if( [o_slider_lock tryLock] )
68 [o_timeslider setFloatValue: f_updated];
69 [o_slider_lock unlock];
75 [o_intf setTimeAsFloat: f_slider];
76 f_slider_old = f_slider;
79 UpdateSystemActivity( UsrActivity );
82 sleepDate = [NSDate dateWithTimeIntervalSinceNow: 0.5];
83 [NSThread sleepUntilDate: sleepDate];
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];
109 /* NSApplication messages */
111 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
113 o_intf = [[Intf_VLCWrapper instance] retain];
114 o_vout = [[Vout_VLCWrapper instance] retain];
116 f_slider = f_slider_old = 0.0;
117 o_slider_lock = [[NSLock alloc] init];
119 [NSThread detachNewThreadSelector: @selector(manage)
120 toTarget: self withObject: nil];
123 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
127 o_array = [NSArray arrayWithObject: o_filename];
128 [o_intf openFiles: o_array];
133 /* Functions attached to user interface */
135 - (IBAction)pause:(id)sender
137 [o_intf playlistPause];
140 - (IBAction)play:(id)sender
142 [o_intf playlistPlay];
145 - (IBAction)stop:(id)sender
147 [o_intf playlistStop];
150 - (IBAction)faster:(id)sender
155 - (IBAction)slower:(id)sender
160 - (IBAction)prev:(id)sender
162 [o_intf playlistPrev];
165 - (IBAction)next:(id)sender
167 [o_intf playlistNext];
170 - (IBAction)mute:(id)sender
172 NSMenuItem * item = (NSMenuItem *)sender;
176 if( p_main->p_intf->p_sys->b_mute )
178 [item setState:NSOnState];
182 [item setState:NSOffState];
186 - (IBAction)fullscreen:(id)sender
191 - (IBAction)eject:(id)sender
196 - (IBAction)maxvolume:(id)sender
201 - (IBAction)timesliderUpdate:(id)slider
203 switch( [[NSApp currentEvent] type] )
205 case NSLeftMouseDown:
206 [o_slider_lock tryLock];
210 f_slider = [o_timeslider floatValue];
211 [o_slider_lock unlock];
219 - (IBAction)quit:(id)sender
226 @implementation Intf_PlaylistDS
230 if( [super init] == nil )
240 o_playlist = [[[Intf_VLCWrapper instance] playlistAsArray] retain];
243 - (int)numberOfRowsInTableView:(NSTableView*)o_table
246 return( [o_playlist count] );
249 - (id)tableView:(NSTableView *)o_table objectValueForTableColumn:(NSTableColumn*)o_column row:(int)i_row
251 return( [o_playlist objectAtIndex: i_row] );
254 - (void)tableView:(NSTableView *)o_table setObjectValue:o_value forTableColumn:(NSTableColumn *)o_column row:(int)i_index