]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_controller.m
* ALL: the first libvlc commit.
[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.5 2002/06/01 12:32:00 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)mute:(id)sender
169 {
170     NSMenuItem * item = (NSMenuItem *)sender;
171
172     [o_intf mute];
173
174     if( p_main->p_intf->p_sys->b_mute )
175     {
176         [item setState:NSOnState];
177     }
178     else
179     {
180         [item setState:NSOffState];
181     }
182 }
183
184 - (IBAction)fullscreen:(id)sender
185 {
186     [o_intf fullscreen];
187 }
188
189 - (IBAction)eject:(id)sender
190 {
191     [o_intf eject];
192 }
193
194 - (IBAction)maxvolume:(id)sender
195 {
196     [o_intf maxvolume];
197 }
198
199 - (IBAction)timesliderUpdate:(id)slider
200 {
201     switch( [[NSApp currentEvent] type] )
202     {
203         case NSLeftMouseDown:
204             [o_slider_lock tryLock];
205             break;
206
207         case NSLeftMouseUp:
208             f_slider = [o_timeslider floatValue];
209             [o_slider_lock unlock];
210             break;
211
212         default:
213             break;
214     }
215 }
216
217 - (IBAction)quit:(id)sender
218 {
219     [o_intf quit];
220 }
221
222 @end
223
224 @implementation Intf_PlaylistDS
225
226 - (id)init
227 {
228     if( [super init] == nil )
229         return( nil );
230
231     o_playlist = nil;
232
233     return( self );
234 }
235
236 - (void)readPlaylist
237 {
238     o_playlist = [[[Intf_VLCWrapper instance] playlistAsArray] retain];
239 }
240
241 - (int)numberOfRowsInTableView:(NSTableView*)o_table
242 {
243     [self readPlaylist];
244     return( [o_playlist count] );
245 }
246     
247 - (id)tableView:(NSTableView *)o_table objectValueForTableColumn:(NSTableColumn*)o_column row:(int)i_row
248 {
249     return( [o_playlist objectAtIndex: i_row] );
250 }
251     
252 - (void)tableView:(NSTableView *)o_table setObjectValue:o_value forTableColumn:(NSTableColumn *)o_column row:(int)i_index
253 {
254 }
255
256 @end