1 /*****************************************************************************
2 * intf.m: MacOS X interface plugin
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: intf.m,v 1.95 2003/09/20 13:46:00 hartman Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <thedj@users.sourceforge.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include <stdlib.h> /* malloc(), free() */
30 #include <sys/param.h> /* for MAXPATHLEN */
40 /*****************************************************************************
42 *****************************************************************************/
43 static void Run ( intf_thread_t *p_intf );
45 /*****************************************************************************
46 * OpenIntf: initialize interface
47 *****************************************************************************/
48 int E_(OpenIntf) ( vlc_object_t *p_this )
50 intf_thread_t *p_intf = (intf_thread_t*) p_this;
52 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
53 if( p_intf->p_sys == NULL )
58 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
60 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
62 /* Put Cocoa into multithread mode as soon as possible.
63 * http://developer.apple.com/techpubs/macosx/Cocoa/
64 * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html
65 * This thread does absolutely nothing at all. */
66 [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
68 p_intf->p_sys->o_sendport = [[NSPort port] retain];
69 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
72 [[VLCApplication sharedApplication] autorelease];
73 [NSApp setIntf: p_intf];
75 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
80 /*****************************************************************************
81 * CloseIntf: destroy interface
82 *****************************************************************************/
83 void E_(CloseIntf) ( vlc_object_t *p_this )
85 intf_thread_t *p_intf = (intf_thread_t*) p_this;
87 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
89 [p_intf->p_sys->o_sendport release];
90 [p_intf->p_sys->o_pool release];
92 free( p_intf->p_sys );
95 /*****************************************************************************
97 *****************************************************************************/
98 static void Run( intf_thread_t *p_intf )
100 /* Do it again - for some unknown reason, vlc_thread_create() often
101 * fails to go to real-time priority with the first launched thread
103 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
108 /*****************************************************************************
109 * VLCApplication implementation
110 *****************************************************************************/
111 @implementation VLCApplication
113 - (NSString *)localizedString:(char *)psz
115 NSString * o_str = nil;
119 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
123 msg_Err( p_intf, "could not translate: %s", psz );
129 - (char *)delocalizeString:(NSString *)id
131 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
132 allowLossyConversion: NO];
137 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
138 allowLossyConversion: YES];
139 psz_string = malloc( [o_data length] + 1 );
140 [o_data getBytes: psz_string];
141 psz_string[ [o_data length] ] = '\0';
142 msg_Err( p_intf, "cannot convert to wanted encoding: %s",
147 psz_string = malloc( [o_data length] + 1 );
148 [o_data getBytes: psz_string];
149 psz_string[ [o_data length] ] = '\0';
155 /* i_width is in pixels */
156 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
158 NSMutableString *o_wrapped;
159 NSString *o_out_string;
160 NSRange glyphRange, effectiveRange, charRange;
161 NSRect lineFragmentRect;
162 unsigned glyphIndex, breaksInserted = 0;
164 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
165 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
166 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
167 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
168 NSTextContainer *o_container = [[NSTextContainer alloc]
169 initWithContainerSize: NSMakeSize(i_width, 2000)];
171 [o_layout_manager addTextContainer: o_container];
172 [o_container release];
173 [o_storage addLayoutManager: o_layout_manager];
174 [o_layout_manager release];
176 o_wrapped = [o_in_string mutableCopy];
177 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
179 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
180 glyphIndex += effectiveRange.length) {
181 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
182 effectiveRange: &effectiveRange];
183 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
184 actualGlyphRange: &effectiveRange];
185 if ([o_wrapped lineRangeForRange:
186 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
187 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
191 o_out_string = [NSString stringWithString: o_wrapped];
198 - (void)setIntf:(intf_thread_t *)_p_intf
203 - (intf_thread_t *)getIntf
208 - (void)terminate:(id)sender
210 p_intf->p_vlc->b_die = VLC_TRUE;
215 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
219 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
221 if( [target respondsToSelector: @selector(performSelectorOnMainThread:
222 withObject:waitUntilDone:)] )
224 [target performSelectorOnMainThread: sel
225 withObject: [NSValue valueWithPointer: p_arg]
228 else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] )
233 NSPort * o_recv_port;
234 NSInvocation * o_inv;
235 NSPortMessage * o_msg;
236 intf_thread_t * p_intf;
237 NSConditionLock * o_lock;
238 NSMethodSignature * o_sig;
240 id * val[] = { &o_lock, &o_v2 };
242 p_intf = (intf_thread_t *)[NSApp getIntf];
244 o_recv_port = [[NSPort port] retain];
245 o_v1 = [NSValue valueWithPointer: val];
246 o_v2 = [NSValue valueWithPointer: p_arg];
248 o_sig = [target methodSignatureForSelector: sel];
249 o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
250 [o_inv setArgument: &o_v1 atIndex: 2];
251 [o_inv setTarget: target];
252 [o_inv setSelector: sel];
254 o_array = [NSArray arrayWithObject:
255 [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
256 o_msg = [[NSPortMessage alloc]
257 initWithSendPort: p_intf->p_sys->o_sendport
258 receivePort: o_recv_port components: o_array];
260 o_lock = [[NSConditionLock alloc] initWithCondition: 0];
261 [o_msg sendBeforeDate: [NSDate distantPast]];
262 [o_lock lockWhenCondition: 1];
267 [o_recv_port release];
279 /*****************************************************************************
280 * playlistChanged: Callback triggered by the intf-change playlist
281 * variable, to let the intf update the playlist.
282 *****************************************************************************/
283 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
284 vlc_value_t old_val, vlc_value_t new_val, void *param )
286 intf_thread_t * p_intf = [NSApp getIntf];
287 p_intf->p_sys->b_playlist_update = VLC_TRUE;
288 p_intf->p_sys->b_intf_update = VLC_TRUE;
292 /*****************************************************************************
293 * VLCMain implementation
294 *****************************************************************************/
295 @implementation VLCMain
299 [o_window setTitle: _NS("VLC - Controller")];
300 [o_window setExcludedFromWindowsMenu: TRUE];
302 /* button controls */
303 [o_btn_playlist setToolTip: _NS("Playlist")];
304 [o_btn_prev setToolTip: _NS("Previous")];
305 [o_btn_slower setToolTip: _NS("Slower")];
306 [o_btn_play setToolTip: _NS("Play")];
307 [o_btn_stop setToolTip: _NS("Stop")];
308 [o_btn_faster setToolTip: _NS("Faster")];
309 [o_btn_next setToolTip: _NS("Next")];
310 [o_btn_prefs setToolTip: _NS("Preferences")];
311 [o_volumeslider setToolTip: _NS("Volume")];
312 [o_timeslider setToolTip: _NS("Position")];
315 [o_msgs_panel setDelegate: self];
316 [o_msgs_panel setTitle: _NS("Messages")];
317 [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
318 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
321 [o_mi_about setTitle: _NS("About VLC media player")];
322 [o_mi_prefs setTitle: _NS("Preferences...")];
323 [o_mi_hide setTitle: _NS("Hide VLC")];
324 [o_mi_hide_others setTitle: _NS("Hide Others")];
325 [o_mi_show_all setTitle: _NS("Show All")];
326 [o_mi_quit setTitle: _NS("Quit VLC")];
328 [o_mu_file setTitle: _ANS("1:File")];
329 [o_mi_open_generic setTitle: _NS("Open...")];
330 [o_mi_open_file setTitle: _NS("Open File...")];
331 [o_mi_open_disc setTitle: _NS("Open Disc...")];
332 [o_mi_open_net setTitle: _NS("Open Network...")];
333 [o_mi_open_recent setTitle: _NS("Open Recent")];
334 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
336 [o_mu_edit setTitle: _NS("Edit")];
337 [o_mi_cut setTitle: _NS("Cut")];
338 [o_mi_copy setTitle: _NS("Copy")];
339 [o_mi_paste setTitle: _NS("Paste")];
340 [o_mi_clear setTitle: _NS("Clear")];
341 [o_mi_select_all setTitle: _NS("Select All")];
343 [o_mu_controls setTitle: _NS("Controls")];
344 [o_mi_play setTitle: _NS("Play")];
345 [o_mi_stop setTitle: _NS("Stop")];
346 [o_mi_faster setTitle: _NS("Faster")];
347 [o_mi_slower setTitle: _NS("Slower")];
348 [o_mi_previous setTitle: _NS("Previous")];
349 [o_mi_next setTitle: _NS("Next")];
350 [o_mi_loop setTitle: _NS("Loop")];
351 [o_mi_fwd setTitle: _NS("Step Forward")];
352 [o_mi_bwd setTitle: _NS("Step Backward")];
353 [o_mi_program setTitle: _NS("Program")];
354 [o_mu_program setTitle: _NS("Program")];
355 [o_mi_title setTitle: _NS("Title")];
356 [o_mu_title setTitle: _NS("Title")];
357 [o_mi_chapter setTitle: _NS("Chapter")];
358 [o_mu_chapter setTitle: _NS("Chapter")];
360 [o_mu_audio setTitle: _NS("Audio")];
361 [o_mi_vol_up setTitle: _NS("Volume Up")];
362 [o_mi_vol_down setTitle: _NS("Volume Down")];
363 [o_mi_mute setTitle: _NS("Mute")];
364 [o_mi_audiotrack setTitle: _NS("Audio track")];
365 [o_mu_audiotrack setTitle: _NS("Audio track")];
366 [o_mi_channels setTitle: _NS("Audio channels")];
367 [o_mu_channels setTitle: _NS("Audio channels")];
368 [o_mi_device setTitle: _NS("Audio device")];
369 [o_mu_device setTitle: _NS("Audio device")];
371 [o_mu_video setTitle: _NS("Video")];
372 [o_mi_half_window setTitle: _NS("Half Size")];
373 [o_mi_normal_window setTitle: _NS("Normal Size")];
374 [o_mi_double_window setTitle: _NS("Double Size")];
375 [o_mi_fittoscreen setTitle: _NS("Fit To Screen")];
376 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
377 [o_mi_floatontop setTitle: _NS("Float On Top")];
378 [o_mi_videotrack setTitle: _NS("Video track")];
379 [o_mu_videotrack setTitle: _NS("Video track")];
380 [o_mi_screen setTitle: _NS("Video device")];
381 [o_mu_screen setTitle: _NS("Video device")];
382 [o_mi_subtitle setTitle: _NS("Subtitles track")];
383 [o_mu_subtitle setTitle: _NS("Subtitles track")];
384 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
385 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
387 [o_mu_window setTitle: _NS("Window")];
388 [o_mi_minimize setTitle: _NS("Minimize Window")];
389 [o_mi_close_window setTitle: _NS("Close Window")];
390 [o_mi_controller setTitle: _NS("Controller")];
391 [o_mi_playlist setTitle: _NS("Playlist")];
392 [o_mi_info setTitle: _NS("Info")];
393 [o_mi_messages setTitle: _NS("Messages")];
395 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
397 [o_mu_help setTitle: _NS("Help")];
398 [o_mi_readme setTitle: _NS("ReadMe...")];
399 [o_mi_documentation setTitle: _NS("Online Documentation")];
400 [o_mi_reportabug setTitle: _NS("Report a Bug")];
401 [o_mi_website setTitle: _NS("VideoLAN Website")];
402 [o_mi_license setTitle: _NS("License")];
405 [o_dmi_play setTitle: _NS("Play")];
406 [o_dmi_stop setTitle: _NS("Stop")];
407 [o_dmi_next setTitle: _NS("Next")];
408 [o_dmi_previous setTitle: _NS("Previous")];
411 [o_error setTitle: _NS("Error")];
412 [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
413 [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")];
414 [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
415 [o_err_btn_dismiss setTitle: _NS("Dismiss")];
417 [o_info_window setTitle: _NS("Info")];
419 [self setSubmenusEnabled: FALSE];
420 [self manageVolumeSlider];
423 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
425 intf_thread_t * p_intf = [NSApp getIntf];
427 o_msg_lock = [[NSLock alloc] init];
428 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
430 o_img_play = [[NSImage imageNamed: @"play"] retain];
431 o_img_pause = [[NSImage imageNamed: @"pause"] retain];
433 [p_intf->p_sys->o_sendport setDelegate: self];
434 [[NSRunLoop currentRunLoop]
435 addPort: p_intf->p_sys->o_sendport
436 forMode: NSDefaultRunLoopMode];
438 [NSTimer scheduledTimerWithTimeInterval: 0.5
439 target: self selector: @selector(manageIntf:)
440 userInfo: nil repeats: FALSE];
442 [NSThread detachNewThreadSelector: @selector(manage)
443 toTarget: self withObject: nil];
445 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
448 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
450 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
451 [o_playlist appendArray:
452 [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
468 NSDate * o_sleep_date;
469 intf_thread_t * p_intf = [NSApp getIntf];
470 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
472 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
474 while( !p_intf->b_die )
476 playlist_t * p_playlist;
478 vlc_mutex_lock( &p_intf->change_lock );
480 p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
483 if( p_playlist != NULL )
485 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
486 #define p_input p_playlist->p_input
490 if( !p_input->b_die )
494 /* New input or stream map change */
495 if( p_input->stream.b_changed )
497 msg_Dbg( p_intf, "stream has changed, refreshing interface" );
498 p_intf->p_sys->b_playing = TRUE;
499 p_intf->p_sys->b_current_title_update = 1;
500 p_input->stream.b_changed = 0;
501 p_intf->p_sys->b_intf_update = TRUE;
504 if( var_Get( (vlc_object_t *)p_input, "intf-change", &val )
507 p_intf->p_sys->b_input_update = TRUE;
511 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
513 p_intf->p_sys->b_playing = FALSE;
514 p_intf->p_sys->b_intf_update = TRUE;
518 vlc_object_release( p_playlist );
521 vlc_mutex_unlock( &p_intf->change_lock );
523 o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
524 [NSThread sleepUntilDate: o_sleep_date];
531 - (void)manageIntf:(NSTimer *)o_timer
533 intf_thread_t * p_intf = [NSApp getIntf];
535 if( p_intf->p_vlc->b_die == VLC_TRUE )
537 [o_timer invalidate];
541 playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
544 if( p_playlist == NULL )
549 if ( p_intf->p_sys->b_playlist_update )
551 [o_playlist playlistUpdated];
552 p_intf->p_sys->b_playlist_update = VLC_FALSE;
555 if( p_intf->p_sys->b_current_title_update )
557 vout_thread_t *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
562 NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
564 while( ( o_vout_wnd = [o_enum nextObject] ) )
566 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
568 [o_vout_wnd updateTitle];
571 vlc_object_release( (vlc_object_t *)p_vout );
573 [o_playlist updateRowSelection];
576 p_intf->p_sys->b_current_title_update = FALSE;
579 vlc_mutex_lock( &p_playlist->object_lock );
581 #define p_input p_playlist->p_input
583 if( p_intf->p_sys->b_intf_update )
585 vlc_bool_t b_input = VLC_FALSE;
586 vlc_bool_t b_plmul = VLC_FALSE;
587 vlc_bool_t b_control = VLC_FALSE;
588 vlc_bool_t b_seekable = VLC_FALSE;
589 vlc_bool_t b_chapters = VLC_FALSE;
592 b_plmul = p_playlist->i_size > 1;
594 if( ( b_input = ( p_input != NULL ) ) )
596 vlc_mutex_lock( &p_input->stream.stream_lock );
598 /* seekable streams */
599 b_seekable = p_input->stream.b_seekable;
601 /* control buttons for free pace streams */
602 b_control = p_input->stream.b_pace_control;
604 /* chapters & titles */
605 b_chapters = p_input->stream.i_area_nb > 1;
607 vlc_mutex_unlock( &p_input->stream.stream_lock );
610 var_Get( p_input, "state", &val );
611 p_intf->p_sys->b_play_status = val.i_int != PAUSE_S;
616 p_intf->p_sys->b_play_status = FALSE;
617 [self setSubmenusEnabled: FALSE];
620 [self playStatusUpdated: p_intf->p_sys->b_play_status];
622 [o_btn_stop setEnabled: b_input];
623 [o_btn_faster setEnabled: b_control];
624 [o_btn_slower setEnabled: b_control];
625 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
626 [o_btn_next setEnabled: (b_plmul || b_chapters)];
628 [o_timeslider setFloatValue: 0.0];
629 [o_timeslider setEnabled: b_seekable];
630 [o_timefield setStringValue: @"0:00:00"];
632 [self manageVolumeSlider];
634 p_intf->p_sys->b_intf_update = VLC_FALSE;
637 if( p_intf->p_sys->b_playing && p_input != NULL )
639 vlc_value_t time, val;
642 var_Get( p_input, "state", &val );
644 if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
645 ( val.i_int != PAUSE_S ) ) )
647 p_intf->p_sys->b_play_status =
648 !p_intf->p_sys->b_play_status;
650 [self playStatusUpdated: p_intf->p_sys->b_play_status];
653 if( p_input->stream.b_seekable )
658 var_Get( p_input, "position", &pos );
659 f_updated = 10000. * pos.f_float;
661 if( f_slider != f_updated )
663 [o_timeslider setFloatValue: f_updated];
667 var_Get( p_input, "time", &time );
668 i_seconds = time.i_time / 1000000;
670 o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
671 (int) (i_seconds / (60 * 60)),
672 (int) (i_seconds / 60 % 60),
673 (int) (i_seconds % 60)];
674 [o_timefield setStringValue: o_time];
676 /* disable screen saver */
677 UpdateSystemActivity( UsrActivity );
682 vlc_mutex_unlock( &p_playlist->object_lock );
683 vlc_object_release( p_playlist );
685 [self updateMessageArray];
687 [NSTimer scheduledTimerWithTimeInterval: 0.5
688 target: self selector: @selector(manageIntf:)
689 userInfo: nil repeats: FALSE];
694 intf_thread_t * p_intf = [NSApp getIntf];
695 playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
698 if( p_playlist != NULL )
700 #define p_input p_playlist->p_input
701 if( p_input != NULL )
703 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
704 var: "program" selector: @selector(toggleVar:)];
706 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
707 var: "title" selector: @selector(toggleVar:)];
709 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
710 var: "chapter" selector: @selector(toggleVar:)];
712 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
713 var: "audio-es" selector: @selector(toggleVar:)];
715 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
716 var: "video-es" selector: @selector(toggleVar:)];
718 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
719 var: "spu-es" selector: @selector(toggleVar:)];
721 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
723 if ( p_aout != NULL )
725 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
726 var: "audio-channels" selector: @selector(toggleVar:)];
728 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
729 var: "audio-device" selector: @selector(toggleVar:)];
730 vlc_object_release( (vlc_object_t *)p_aout );
733 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
736 if ( p_vout != NULL )
738 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
739 var: "video-device" selector: @selector(toggleVar:)];
741 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
742 var: "deinterlace" selector: @selector(toggleVar:)];
743 vlc_object_release( (vlc_object_t *)p_vout );
748 vlc_object_release( (vlc_object_t *)p_playlist );
751 - (void)updateMessageArray
754 intf_thread_t * p_intf = [NSApp getIntf];
756 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
757 i_stop = *p_intf->p_sys->p_sub->pi_stop;
758 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
760 if( p_intf->p_sys->p_sub->i_start != i_stop )
762 NSColor *o_white = [NSColor whiteColor];
763 NSColor *o_red = [NSColor redColor];
764 NSColor *o_yellow = [NSColor yellowColor];
765 NSColor *o_gray = [NSColor grayColor];
767 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
768 static const char * ppsz_type[4] = { ": ", " error: ",
769 " warning: ", " debug: " };
771 for( i_start = p_intf->p_sys->p_sub->i_start;
773 i_start = (i_start+1) % VLC_MSG_QSIZE )
776 NSDictionary *o_attr;
777 NSAttributedString *o_msg_color;
779 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
783 if( [o_msg_arr count] + 2 > 400 )
785 unsigned rid[] = { 0, 1 };
786 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
787 numIndices: sizeof(rid)/sizeof(rid[0])];
790 o_attr = [NSDictionary dictionaryWithObject: o_gray
791 forKey: NSForegroundColorAttributeName];
792 o_msg = [NSString stringWithFormat: @"%s%s",
793 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
795 o_msg_color = [[NSAttributedString alloc]
796 initWithString: o_msg attributes: o_attr];
797 [o_msg_arr addObject: [o_msg_color autorelease]];
799 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
800 forKey: NSForegroundColorAttributeName];
801 o_msg = [NSString stringWithFormat: @"%s\n",
802 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
803 o_msg_color = [[NSAttributedString alloc]
804 initWithString: o_msg attributes: o_attr];
805 [o_msg_arr addObject: [o_msg_color autorelease]];
811 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
812 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
813 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
815 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
816 [o_err_msg setEditable: YES];
817 [o_err_msg setSelectedRange: s_r];
818 [o_err_msg insertText: o_my_msg];
820 [o_error makeKeyAndOrderFront: self];
821 [o_err_msg setEditable: NO];
825 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
826 p_intf->p_sys->p_sub->i_start = i_start;
827 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
831 - (void)playStatusUpdated:(BOOL)b_pause
835 [o_btn_play setImage: o_img_pause];
836 [o_btn_play setToolTip: _NS("Pause")];
837 [o_mi_play setTitle: _NS("Pause")];
838 [o_dmi_play setTitle: _NS("Pause")];
842 [o_btn_play setImage: o_img_play];
843 [o_btn_play setToolTip: _NS("Play")];
844 [o_mi_play setTitle: _NS("Play")];
845 [o_dmi_play setTitle: _NS("Play")];
849 - (void)setSubmenusEnabled:(BOOL)b_enabled
851 [o_mi_program setEnabled: b_enabled];
852 [o_mi_title setEnabled: b_enabled];
853 [o_mi_chapter setEnabled: b_enabled];
854 [o_mi_audiotrack setEnabled: b_enabled];
855 [o_mi_videotrack setEnabled: b_enabled];
856 [o_mi_subtitle setEnabled: b_enabled];
857 [o_mi_channels setEnabled: b_enabled];
858 [o_mi_deinterlace setEnabled: b_enabled];
859 [o_mi_device setEnabled: b_enabled];
860 [o_mi_screen setEnabled: b_enabled];
863 - (void)manageVolumeSlider
865 audio_volume_t i_volume;
866 intf_thread_t * p_intf = [NSApp getIntf];
868 aout_VolumeGet( p_intf, &i_volume );
870 [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP];
871 [o_volumeslider setEnabled: TRUE];
873 p_intf->p_sys->b_mute = ( i_volume == 0 );
876 - (IBAction)timesliderUpdate:(id)sender
878 intf_thread_t * p_intf;
879 input_thread_t * p_input;
882 switch( [[NSApp currentEvent] type] )
885 case NSLeftMouseDown:
886 case NSLeftMouseDragged:
887 f_updated = [sender floatValue];
894 p_intf = [NSApp getIntf];
895 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
898 if( p_input != NULL )
904 if( p_input->stream.b_seekable )
907 pos.f_float = f_updated / 10000.;
908 if( f_slider != f_updated )
910 var_Set( p_input, "position", pos );
911 [o_timeslider setFloatValue: f_updated];
915 var_Get( p_input, "time", &time );
916 i_seconds = time.i_time / 1000000;
918 o_time = [NSString stringWithFormat: @"%d:%02d:%02d",
919 (int) (i_seconds / (60 * 60)),
920 (int) (i_seconds / 60 % 60),
921 (int) (i_seconds % 60)];
922 [o_timefield setStringValue: o_time];
923 vlc_object_release( p_input );
930 playlist_t * p_playlist;
931 intf_thread_t * p_intf = [NSApp getIntf];
936 msg_Dbg( p_intf, "removing all playlists" );
937 while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
940 vlc_object_detach( p_playlist );
941 vlc_object_release( p_playlist );
942 playlist_Destroy( p_playlist );
945 if( o_img_pause != nil )
947 [o_img_pause release];
951 if( o_img_play != nil )
953 [o_img_play release];
957 if( o_msg_arr != nil )
959 [o_msg_arr removeAllObjects];
964 if( o_msg_lock != nil )
966 [o_msg_lock release];
972 /* write cached user defaults to disk */
973 [[NSUserDefaults standardUserDefaults] synchronize];
975 /* send a dummy event to break out of the event loop */
976 o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
977 location: NSMakePoint( 1, 1 ) modifierFlags: 0
978 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
979 context: [NSGraphicsContext currentContext] eventNumber: 1
980 clickCount: 1 pressure: 0.0];
981 [NSApp postEvent: o_event atStart: YES];
984 - (IBAction)clearRecentItems:(id)sender
986 [[NSDocumentController sharedDocumentController]
987 clearRecentDocuments: nil];
990 - (void)openRecentItem:(id)sender
992 [self application: nil openFile: [sender title]];
995 - (IBAction)viewPreferences:(id)sender
1000 - (IBAction)closeError:(id)sender
1002 [o_err_msg setString: @""];
1003 [o_error performClose: self];
1006 - (IBAction)openReadMe:(id)sender
1008 NSString * o_path = [[NSBundle mainBundle]
1009 pathForResource: @"README.MacOSX" ofType: @"rtf"];
1011 [[NSWorkspace sharedWorkspace] openFile: o_path
1012 withApplication: @"TextEdit"];
1015 - (IBAction)openDocumentation:(id)sender
1017 NSURL * o_url = [NSURL URLWithString:
1018 @"http://www.videolan.org/doc/"];
1020 [[NSWorkspace sharedWorkspace] openURL: o_url];
1023 - (IBAction)reportABug:(id)sender
1025 NSURL * o_url = [NSURL URLWithString:
1026 @"http://www.videolan.org/support/bug-reporting.html"];
1028 [[NSWorkspace sharedWorkspace] openURL: o_url];
1031 - (IBAction)openWebsite:(id)sender
1033 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1035 [[NSWorkspace sharedWorkspace] openURL: o_url];
1038 - (IBAction)openLicense:(id)sender
1040 NSString * o_path = [[NSBundle mainBundle]
1041 pathForResource: @"COPYING" ofType: nil];
1043 [[NSWorkspace sharedWorkspace] openFile: o_path
1044 withApplication: @"TextEdit"];
1047 - (IBAction)openCrashLog:(id)sender
1049 NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1050 stringByExpandingTildeInPath];
1053 if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1055 [[NSWorkspace sharedWorkspace] openFile: o_path
1056 withApplication: @"Console"];
1060 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Either you are running Mac OS X pre 10.2 or you haven't experienced any heavy crashes yet.") );
1065 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1067 if( [o_notification object] == o_msgs_panel )
1070 NSEnumerator * o_enum;
1072 [o_messages setString: @""];
1076 o_enum = [o_msg_arr objectEnumerator];
1078 while( ( o_msg = [o_enum nextObject] ) != nil )
1080 [o_messages insertText: o_msg];
1083 [o_msg_lock unlock];
1089 @implementation VLCMain (NSMenuValidation)
1091 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1093 NSString *o_title = [o_mi title];
1094 BOOL bEnabled = TRUE;
1096 if( [o_title isEqualToString: _NS("License")] )
1098 /* we need to do this only once */
1102 /* Recent Items Menu */
1103 if( [o_title isEqualToString: _NS("Clear Menu")] )
1105 NSMenu * o_menu = [o_mi_open_recent submenu];
1106 int i_nb_items = [o_menu numberOfItems];
1107 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1108 recentDocumentURLs];
1109 UInt32 i_nb_docs = [o_docs count];
1111 if( i_nb_items > 1 )
1113 while( --i_nb_items )
1115 [o_menu removeItemAtIndex: 0];
1124 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1130 o_url = [o_docs objectAtIndex: i_nb_docs];
1132 if( [o_url isFileURL] )
1134 o_doc = [o_url path];
1138 o_doc = [o_url absoluteString];
1141 [o_menu insertItemWithTitle: o_doc
1142 action: @selector(openRecentItem:)
1143 keyEquivalent: @"" atIndex: 0];
1145 if( i_nb_docs == 0 )
1161 @implementation VLCMain (Internal)
1163 - (void)handlePortMessage:(NSPortMessage *)o_msg
1168 NSInvocation * o_inv;
1169 NSConditionLock * o_lock;
1171 o_data = [[o_msg components] lastObject];
1172 o_inv = *((NSInvocation **)[o_data bytes]);
1173 [o_inv getArgument: &o_value atIndex: 2];
1174 val = (id **)[o_value pointerValue];
1175 [o_inv setArgument: val[1] atIndex: 2];
1180 [o_lock unlockWithCondition: 1];