]> git.sesse.net Git - vlc/blob - plugins/macosx/intf_controller.m
* Fixed menus [Mac OS X port]
[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.1 2002/05/12 20:56:33 massiot 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)applicationDidFinishLaunching:(NSNotification *)o_notification
48 {
49     o_intf = [[Intf_VLCWrapper instance] retain];
50     o_vout = [[Vout_VLCWrapper instance] retain];
51
52     f_slider = f_slider_old = 0.0;
53     o_slider_lock = [[NSLock alloc] init];
54
55     [NSThread detachNewThreadSelector: @selector(manage)
56         toTarget: self withObject: nil];
57 }
58
59 - (void)manage
60 {
61     NSDate *sleepDate;
62     NSAutoreleasePool *o_pool;
63
64     o_pool = [[NSAutoreleasePool alloc] init];
65
66     while( ![o_intf manage] )
67     {
68         if( [o_intf playlistPlaying] )
69         { 
70             [o_time setStringValue: [o_intf getTimeAsString]];
71
72             if( f_slider == f_slider_old )
73             {
74                 float f_updated = [o_intf getTimeAsFloat];
75
76                 if( f_updated != f_slider )
77                 {
78                     if( [o_slider_lock tryLock] )
79                     {
80                         [o_timeslider setFloatValue: f_updated];
81                         [o_slider_lock unlock];
82                     }
83                 }
84             }
85             else
86             {
87                 [o_intf setTimeAsFloat: f_slider];
88                 f_slider_old = f_slider;
89             }
90
91             UpdateSystemActivity( UsrActivity );
92         }
93
94         sleepDate = [NSDate dateWithTimeIntervalSinceNow: 0.5];
95         [NSThread sleepUntilDate: sleepDate];
96     }
97
98     [self terminate];
99
100     [o_pool release];
101 }
102
103 - (void)terminate
104 {
105     NSEvent *pEvent;
106
107     [NSApp stop: nil];
108
109     [o_vout release];
110     [o_intf release];
111
112     /* send a dummy event to break out of the event loop */
113     pEvent = [NSEvent mouseEventWithType: NSLeftMouseDown
114                 location: NSMakePoint( 1, 1 ) modifierFlags: 0
115                 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
116                 context: [NSGraphicsContext currentContext] eventNumber: 1
117                 clickCount: 1 pressure: 0.0];
118     [NSApp postEvent: pEvent atStart: YES];
119 }
120
121 /* Functions attached to user interface */
122  
123 - (IBAction)pause:(id)sender
124 {
125     [o_intf playlistPause];
126 }
127
128 - (IBAction)play:(id)sender
129 {
130     [o_intf playlistPlay];
131 }
132
133 - (IBAction)stop:(id)sender
134 {
135     [o_intf playlistStop];
136 }
137
138 - (IBAction)faster:(id)sender
139 {
140     [o_intf playFaster];
141 }
142
143 - (IBAction)slower:(id)sender
144 {
145     [o_intf playSlower];
146 }
147
148 - (IBAction)prev:(id)sender
149 {
150     [o_intf playlistPrev];
151 }
152
153 - (IBAction)next:(id)sender
154 {
155     [o_intf playlistNext];
156 }
157
158 - (IBAction)mute:(id)sender
159 {
160     NSMenuItem * item = (NSMenuItem *)sender;
161
162     [o_intf mute];
163
164     if( p_main->p_intf->p_sys->b_mute )
165     {
166         [item setState:NSOnState];
167     }
168     else
169     {
170         [item setState:NSOffState];
171     }
172 }
173
174 - (IBAction)fullscreen:(id)sender
175 {
176     [o_intf fullscreen];
177 }
178
179 - (IBAction)eject:(id)sender
180 {
181     [o_intf eject];
182 }
183
184 - (IBAction)timesliderUpdate:(id)slider
185 {
186     switch( [[NSApp currentEvent] type] )
187     {
188         case NSLeftMouseDown:
189             [o_slider_lock lock];
190             break;
191
192         case NSLeftMouseUp:
193             f_slider = [o_timeslider floatValue];
194             [o_slider_lock unlock];
195             break;
196
197         default:
198             break;
199     }
200 }
201
202 - (IBAction)quit:(id)sender
203 {
204     [o_intf quit];
205 }
206
207 @end
208
209 @implementation Intf_PlaylistDS
210
211 - (id)init
212 {
213     if( [super init] == nil )
214         return( nil );
215
216     o_playlist = nil;
217
218     return( self );
219 }
220
221 - (void)readPlaylist
222 {
223     o_playlist = [[[Intf_VLCWrapper instance] playlistAsArray] retain];
224 }
225
226 - (int)numberOfRowsInTableView:(NSTableView*)o_table
227 {
228     [self readPlaylist];
229     return( [o_playlist count] );
230 }
231     
232 - (id)tableView:(NSTableView *)o_table objectValueForTableColumn:(NSTableColumn*)o_column row:(int)i_row
233 {
234     return( [o_playlist objectAtIndex: i_row] );
235 }
236     
237 - (void)tableView:(NSTableView *)o_table setObjectValue:o_value forTableColumn:(NSTableColumn *)o_column row:(int)i_index
238 {
239 }
240
241 @end