1 /*****************************************************************************
2 * intf.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2002-2008 the VideoLAN team
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Derk-Jan Hartman <hartman at videolan.org>
10 * Felix Paul Kühne <fkuehne at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
31 #include <sys/param.h> /* for MAXPATHLEN */
44 #import "playlistinfo.h"
51 #import "interaction.h"
52 #import "embeddedwindow.h"
54 #import "AppleRemote.h"
56 #import "simple_prefs.h"
59 #import <vlc_interface.h>
60 #import <AddressBook/AddressBook.h>
62 /*****************************************************************************
64 *****************************************************************************/
65 static void Run ( intf_thread_t *p_intf );
68 /*****************************************************************************
69 * VLCApplication implementation (this hack is really disgusting now,
71 *****************************************************************************/
72 @interface VLCApplication : NSApplication
74 libvlc_int_t *o_libvlc;
76 - (void)setVLC: (libvlc_int_t *)p_libvlc;
80 @implementation VLCApplication
81 - (void)setVLC: (libvlc_int_t *) p_libvlc
85 - (void)terminate: (id)sender
87 vlc_object_kill( o_libvlc );
88 [super terminate: sender];
92 /*****************************************************************************
93 * OpenIntf: initialize interface
94 *****************************************************************************/
95 int OpenIntf ( vlc_object_t *p_this )
97 intf_thread_t *p_intf = (intf_thread_t*) p_this;
99 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
100 if( p_intf->p_sys == NULL )
105 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
107 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
109 p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
110 p_intf->pf_run = Run;
111 p_intf->b_should_run_on_first_thread = true;
116 /*****************************************************************************
117 * CloseIntf: destroy interface
118 *****************************************************************************/
119 void CloseIntf ( vlc_object_t *p_this )
121 intf_thread_t *p_intf = (intf_thread_t*) p_this;
123 [[VLCMain sharedInstance] setIntf: nil];
125 msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
127 [p_intf->p_sys->o_pool release];
129 free( p_intf->p_sys );
132 /*****************************************************************************
134 *****************************************************************************/
137 static void Run( intf_thread_t *p_intf )
141 /* Do it again - for some unknown reason, vlc_thread_create() often
142 * fails to go to real-time priority with the first launched thread
144 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
146 /* Make sure the "force quit" menu item does quit instantly.
147 * VLC overrides SIGTERM which is sent by the "force quit"
148 * menu item to make sure deamon mode quits gracefully, so
149 * we un-override SIGTERM here. */
151 sigaddset( &set, SIGTERM );
152 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
154 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
156 /* Install a jmpbuffer to where we can go back before the NSApp exit
157 * see applicationWillTerminate: */
158 /* We need that code to run on main thread */
159 [VLCApplication sharedApplication];
160 [NSApp setVLC: p_intf->p_libvlc];
162 [[VLCMain sharedInstance] setIntf: p_intf];
163 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
165 /* Install a jmpbuffer to where we can go back before the NSApp exit
166 * see applicationWillTerminate: */
167 if(setjmp(jmpbuffer) == 0)
173 /*****************************************************************************
174 * ManageThread: An ugly thread that polls
175 *****************************************************************************/
176 static void * ManageThread( void *user_data )
185 /*****************************************************************************
186 * playlistChanged: Callback triggered by the intf-change playlist
187 * variable, to let the intf update the playlist.
188 *****************************************************************************/
189 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
190 vlc_value_t old_val, vlc_value_t new_val, void *param )
192 intf_thread_t * p_intf = VLCIntf;
193 p_intf->p_sys->b_intf_update = true;
194 p_intf->p_sys->b_playlist_update = true;
195 p_intf->p_sys->b_playmode_update = true;
196 p_intf->p_sys->b_current_title_update = true;
200 /*****************************************************************************
201 * ShowController: Callback triggered by the show-intf playlist variable
202 * through the ShowIntf-control-intf, to let us show the controller-win;
203 * usually when in fullscreen-mode
204 *****************************************************************************/
205 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
206 vlc_value_t old_val, vlc_value_t new_val, void *param )
208 intf_thread_t * p_intf = VLCIntf;
209 p_intf->p_sys->b_intf_show = true;
213 /*****************************************************************************
214 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
215 * variable, to let the intf update the controller.
216 *****************************************************************************/
217 static int FullscreenChanged( vlc_object_t *p_this, const char *psz_variable,
218 vlc_value_t old_val, vlc_value_t new_val, void *param )
220 intf_thread_t * p_intf = VLCIntf;
221 p_intf->p_sys->b_fullscreen_update = true;
225 /*****************************************************************************
226 * InteractCallback: Callback triggered by the interaction
227 * variable, to let the intf display error and interaction dialogs
228 *****************************************************************************/
229 static int InteractCallback( vlc_object_t *p_this, const char *psz_variable,
230 vlc_value_t old_val, vlc_value_t new_val, void *param )
232 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
233 VLCMain *interface = (VLCMain *)param;
234 interaction_dialog_t *p_dialog = (interaction_dialog_t *)(new_val.p_address);
235 NSValue *o_value = [NSValue valueWithPointer:p_dialog];
237 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList]
238 userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]];
247 unsigned int i_vlckey;
248 } nskeys_to_vlckeys[] =
250 { NSUpArrowFunctionKey, KEY_UP },
251 { NSDownArrowFunctionKey, KEY_DOWN },
252 { NSLeftArrowFunctionKey, KEY_LEFT },
253 { NSRightArrowFunctionKey, KEY_RIGHT },
254 { NSF1FunctionKey, KEY_F1 },
255 { NSF2FunctionKey, KEY_F2 },
256 { NSF3FunctionKey, KEY_F3 },
257 { NSF4FunctionKey, KEY_F4 },
258 { NSF5FunctionKey, KEY_F5 },
259 { NSF6FunctionKey, KEY_F6 },
260 { NSF7FunctionKey, KEY_F7 },
261 { NSF8FunctionKey, KEY_F8 },
262 { NSF9FunctionKey, KEY_F9 },
263 { NSF10FunctionKey, KEY_F10 },
264 { NSF11FunctionKey, KEY_F11 },
265 { NSF12FunctionKey, KEY_F12 },
266 { NSInsertFunctionKey, KEY_INSERT },
267 { NSHomeFunctionKey, KEY_HOME },
268 { NSEndFunctionKey, KEY_END },
269 { NSPageUpFunctionKey, KEY_PAGEUP },
270 { NSPageDownFunctionKey, KEY_PAGEDOWN },
271 { NSMenuFunctionKey, KEY_MENU },
272 { NSTabCharacter, KEY_TAB },
273 { NSCarriageReturnCharacter, KEY_ENTER },
274 { NSEnterCharacter, KEY_ENTER },
275 { NSBackspaceCharacter, KEY_BACKSPACE },
276 { (unichar) ' ', KEY_SPACE },
277 { (unichar) 0x1b, KEY_ESC },
281 unichar VLCKeyToCocoa( unsigned int i_key )
285 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
287 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
289 return nskeys_to_vlckeys[i].i_nskey;
292 return (unichar)(i_key & ~KEY_MODIFIER);
295 unsigned int CocoaKeyToVLC( unichar i_key )
299 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
301 if( nskeys_to_vlckeys[i].i_nskey == i_key )
303 return nskeys_to_vlckeys[i].i_vlckey;
306 return (unsigned int)i_key;
309 unsigned int VLCModifiersToCocoa( unsigned int i_key )
311 unsigned int new = 0;
312 if( i_key & KEY_MODIFIER_COMMAND )
313 new |= NSCommandKeyMask;
314 if( i_key & KEY_MODIFIER_ALT )
315 new |= NSAlternateKeyMask;
316 if( i_key & KEY_MODIFIER_SHIFT )
317 new |= NSShiftKeyMask;
318 if( i_key & KEY_MODIFIER_CTRL )
319 new |= NSControlKeyMask;
323 /*****************************************************************************
324 * VLCMain implementation
325 *****************************************************************************/
326 @implementation VLCMain
328 static VLCMain *_o_sharedMainInstance = nil;
330 + (VLCMain *)sharedInstance
332 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
337 if( _o_sharedMainInstance)
340 return _o_sharedMainInstance;
343 _o_sharedMainInstance = [super init];
345 o_about = [[VLAboutBox alloc] init];
347 o_open = [[VLCOpen alloc] init];
348 o_wizard = [[VLCWizard alloc] init];
350 o_bookmarks = [[VLCBookmarks alloc] init];
351 o_embedded_list = [[VLCEmbeddedList alloc] init];
352 o_interaction_list = [[VLCInteractionList alloc] init];
353 o_info = [[VLCInfo alloc] init];
355 o_update = [[VLCUpdate alloc] init];
358 i_lastShownVolume = -1;
360 o_remote = [[AppleRemote alloc] init];
361 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
362 [o_remote setDelegate: _o_sharedMainInstance];
364 o_eyetv = [[VLCEyeTVController alloc] init];
366 /* announce our launch to a potential eyetv plugin */
367 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
368 object: @"VLCEyeTVSupport"
370 deliverImmediately: YES];
372 return _o_sharedMainInstance;
375 - (void)setIntf: (intf_thread_t *)p_mainintf {
379 - (intf_thread_t *)getIntf {
385 unsigned int i_key = 0;
386 playlist_t *p_playlist;
389 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
390 if( nib_main_loaded ) return;
394 [o_window setExcludedFromWindowsMenu: YES];
395 [o_msgs_panel setExcludedFromWindowsMenu: YES];
396 [o_msgs_panel setDelegate: self];
398 /* In code and not in Nib for 10.4 compat */
399 NSToolbar * toolbar = [[[NSToolbar alloc] initWithIdentifier:@"mainControllerToolbar"] autorelease];
400 [toolbar setDelegate:self];
401 [toolbar setShowsBaselineSeparator:NO];
402 [toolbar setAllowsUserCustomization:NO];
403 [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
404 [toolbar setAutosavesConfiguration:YES];
405 [o_window setToolbar:toolbar];
407 i_key = config_GetInt( p_intf, "key-quit" );
408 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
409 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
410 i_key = config_GetInt( p_intf, "key-play-pause" );
411 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
412 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
413 i_key = config_GetInt( p_intf, "key-stop" );
414 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
415 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
416 i_key = config_GetInt( p_intf, "key-faster" );
417 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
418 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
419 i_key = config_GetInt( p_intf, "key-slower" );
420 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
421 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
422 i_key = config_GetInt( p_intf, "key-prev" );
423 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
424 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
425 i_key = config_GetInt( p_intf, "key-next" );
426 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
427 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
428 i_key = config_GetInt( p_intf, "key-jump+short" );
429 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
430 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
431 i_key = config_GetInt( p_intf, "key-jump-short" );
432 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
433 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
434 i_key = config_GetInt( p_intf, "key-jump+medium" );
435 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
436 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
437 i_key = config_GetInt( p_intf, "key-jump-medium" );
438 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
439 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
440 i_key = config_GetInt( p_intf, "key-jump+long" );
441 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
442 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
443 i_key = config_GetInt( p_intf, "key-jump-long" );
444 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
445 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
446 i_key = config_GetInt( p_intf, "key-vol-up" );
447 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
448 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
449 i_key = config_GetInt( p_intf, "key-vol-down" );
450 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
451 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
452 i_key = config_GetInt( p_intf, "key-vol-mute" );
453 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
454 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
455 i_key = config_GetInt( p_intf, "key-fullscreen" );
456 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
457 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
458 i_key = config_GetInt( p_intf, "key-snapshot" );
459 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
460 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
462 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
464 [self setSubmenusEnabled: FALSE];
465 [o_volumeslider setEnabled: YES];
466 [self manageVolumeSlider];
467 [o_window setDelegate: self];
469 b_restore_size = false;
471 // Set that here as IB seems to be buggy
472 [o_window setContentMinSize:NSMakeSize(338., 30.)];
474 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
476 b_small_window = YES;
477 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
478 [o_window frame].origin.y, [o_window frame].size.width,
479 [o_window minSize].height ) display: YES animate:YES];
480 [o_playlist_view setAutoresizesSubviews: NO];
485 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
486 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
487 [o_playlist_view setNeedsDisplay:YES];
488 [o_playlist_view setAutoresizesSubviews: YES];
489 [[o_window contentView] addSubview: o_playlist_view];
492 [self updateTogglePlaylistState];
494 o_size_with_playlist = [o_window contentRectForFrameRect:[o_window frame]].size;
496 p_playlist = pl_Yield( p_intf );
498 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
501 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
502 var_AddCallback( p_intf->p_libvlc, "intf-show", ShowController, self);
504 pl_Release( p_intf );
506 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
507 var_AddCallback( p_intf, "interaction", InteractCallback, self );
508 p_intf->b_interaction = true;
510 /* update the playmode stuff */
511 p_intf->p_sys->b_playmode_update = true;
513 [[NSNotificationCenter defaultCenter] addObserver: self
514 selector: @selector(refreshVoutDeviceMenu:)
515 name: NSApplicationDidChangeScreenParametersNotification
518 o_img_play = [NSImage imageNamed: @"play"];
519 o_img_pause = [NSImage imageNamed: @"pause"];
521 [self controlTintChanged];
523 [[NSNotificationCenter defaultCenter] addObserver: self
524 selector: @selector( controlTintChanged )
525 name: NSControlTintDidChangeNotification
528 nib_main_loaded = TRUE;
531 #pragma mark Toolbar delegate
532 /* Our item identifiers */
533 static NSString * VLCToolbarMediaControl = @"VLCToolbarMediaControl";
535 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
537 return [NSArray arrayWithObjects:
538 // NSToolbarCustomizeToolbarItemIdentifier,
539 // NSToolbarFlexibleSpaceItemIdentifier,
540 // NSToolbarSpaceItemIdentifier,
541 // NSToolbarSeparatorItemIdentifier,
542 VLCToolbarMediaControl,
546 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
548 return [NSArray arrayWithObjects:
549 VLCToolbarMediaControl,
553 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
555 NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
558 if( [itemIdentifier isEqual: VLCToolbarMediaControl] )
560 [toolbarItem setLabel:@"Media Controls"];
561 [toolbarItem setPaletteLabel:@"Media Controls"];
563 NSSize size = toolbarMediaControl.frame.size;
564 [toolbarItem setView:toolbarMediaControl];
565 [toolbarItem setMinSize:size];
567 [toolbarItem setMaxSize:size];
569 // Hack: For some reason we need to make sure
570 // that the those element are on top
571 // Add them again will put them frontmost
572 [toolbarMediaControl addSubview:o_scrollfield];
573 [toolbarMediaControl addSubview:o_timeslider];
574 [toolbarMediaControl addSubview:o_timefield];
575 [toolbarMediaControl addSubview:o_main_pgbar];
577 /* TODO: setup a menu */
581 /* itemIdentifier referred to a toolbar item that is not
582 * provided or supported by us or Cocoa
583 * Returning nil will inform the toolbar
584 * that this kind of item is not supported */
592 - (void)controlTintChanged
596 if( [o_btn_play alternateImage] == o_img_play_pressed )
599 if( [NSColor currentControlTint] == NSGraphiteControlTint )
601 o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];
602 o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];
604 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];
605 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];
606 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];
607 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];
608 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];
609 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
610 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];
611 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];
615 o_img_play_pressed = [NSImage imageNamed: @"play_blue"];
616 o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];
618 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];
619 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];
620 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];
621 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];
622 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];
623 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
624 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];
625 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];
629 [o_btn_play setAlternateImage: o_img_play_pressed];
631 [o_btn_play setAlternateImage: o_img_pause_pressed];
636 [o_window setTitle: _NS("VLC media player")];
637 [self setScrollField:_NS("VLC media player") stopAfter:-1];
639 /* button controls */
640 [o_btn_prev setToolTip: _NS("Previous")];
641 [o_btn_rewind setToolTip: _NS("Rewind")];
642 [o_btn_play setToolTip: _NS("Play")];
643 [o_btn_stop setToolTip: _NS("Stop")];
644 [o_btn_ff setToolTip: _NS("Fast Forward")];
645 [o_btn_next setToolTip: _NS("Next")];
646 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
647 [o_volumeslider setToolTip: _NS("Volume")];
648 [o_timeslider setToolTip: _NS("Position")];
649 [o_btn_playlist setToolTip: _NS("Playlist")];
652 [o_msgs_panel setTitle: _NS("Messages")];
653 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog...")];
656 [o_mi_about setTitle: [_NS("About VLC media player") \
657 stringByAppendingString: @"..."]];
658 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
659 [o_mi_prefs setTitle: _NS("Preferences...")];
660 [o_mi_add_intf setTitle: _NS("Add Interface")];
661 [o_mu_add_intf setTitle: _NS("Add Interface")];
662 [o_mi_services setTitle: _NS("Services")];
663 [o_mi_hide setTitle: _NS("Hide VLC")];
664 [o_mi_hide_others setTitle: _NS("Hide Others")];
665 [o_mi_show_all setTitle: _NS("Show All")];
666 [o_mi_quit setTitle: _NS("Quit VLC")];
668 [o_mu_file setTitle: _ANS("1:File")];
669 [o_mi_open_generic setTitle: _NS("Open File...")];
670 [o_mi_open_file setTitle: _NS("Quick Open File...")];
671 [o_mi_open_disc setTitle: _NS("Open Disc...")];
672 [o_mi_open_net setTitle: _NS("Open Network...")];
673 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
674 [o_mi_open_recent setTitle: _NS("Open Recent")];
675 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
676 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
678 [o_mu_edit setTitle: _NS("Edit")];
679 [o_mi_cut setTitle: _NS("Cut")];
680 [o_mi_copy setTitle: _NS("Copy")];
681 [o_mi_paste setTitle: _NS("Paste")];
682 [o_mi_clear setTitle: _NS("Clear")];
683 [o_mi_select_all setTitle: _NS("Select All")];
685 [o_mu_controls setTitle: _NS("Playback")];
686 [o_mi_play setTitle: _NS("Play")];
687 [o_mi_stop setTitle: _NS("Stop")];
688 [o_mi_faster setTitle: _NS("Faster")];
689 [o_mi_slower setTitle: _NS("Slower")];
690 [o_mi_previous setTitle: _NS("Previous")];
691 [o_mi_next setTitle: _NS("Next")];
692 [o_mi_random setTitle: _NS("Random")];
693 [o_mi_repeat setTitle: _NS("Repeat One")];
694 [o_mi_loop setTitle: _NS("Repeat All")];
695 [o_mi_fwd setTitle: _NS("Step Forward")];
696 [o_mi_bwd setTitle: _NS("Step Backward")];
698 [o_mi_program setTitle: _NS("Program")];
699 [o_mu_program setTitle: _NS("Program")];
700 [o_mi_title setTitle: _NS("Title")];
701 [o_mu_title setTitle: _NS("Title")];
702 [o_mi_chapter setTitle: _NS("Chapter")];
703 [o_mu_chapter setTitle: _NS("Chapter")];
705 [o_mu_audio setTitle: _NS("Audio")];
706 [o_mi_vol_up setTitle: _NS("Volume Up")];
707 [o_mi_vol_down setTitle: _NS("Volume Down")];
708 [o_mi_mute setTitle: _NS("Mute")];
709 [o_mi_audiotrack setTitle: _NS("Audio Track")];
710 [o_mu_audiotrack setTitle: _NS("Audio Track")];
711 [o_mi_channels setTitle: _NS("Audio Channels")];
712 [o_mu_channels setTitle: _NS("Audio Channels")];
713 [o_mi_device setTitle: _NS("Audio Device")];
714 [o_mu_device setTitle: _NS("Audio Device")];
715 [o_mi_visual setTitle: _NS("Visualizations")];
716 [o_mu_visual setTitle: _NS("Visualizations")];
718 [o_mu_video setTitle: _NS("Video")];
719 [o_mi_half_window setTitle: _NS("Half Size")];
720 [o_mi_normal_window setTitle: _NS("Normal Size")];
721 [o_mi_double_window setTitle: _NS("Double Size")];
722 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
723 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
724 [o_mi_floatontop setTitle: _NS("Float on Top")];
725 [o_mi_snapshot setTitle: _NS("Snapshot")];
726 [o_mi_videotrack setTitle: _NS("Video Track")];
727 [o_mu_videotrack setTitle: _NS("Video Track")];
728 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
729 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
730 [o_mi_crop setTitle: _NS("Crop")];
731 [o_mu_crop setTitle: _NS("Crop")];
732 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
733 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
734 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
735 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
736 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
737 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
738 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
739 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
741 [o_mu_window setTitle: _NS("Window")];
742 [o_mi_minimize setTitle: _NS("Minimize Window")];
743 [o_mi_close_window setTitle: _NS("Close Window")];
744 [o_mi_controller setTitle: _NS("Controller...")];
745 [o_mi_equalizer setTitle: _NS("Equalizer...")];
746 [o_mi_extended setTitle: _NS("Extended Controls...")];
747 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
748 [o_mi_playlist setTitle: _NS("Playlist...")];
749 [o_mi_info setTitle: _NS("Media Information...")];
750 [o_mi_messages setTitle: _NS("Messages...")];
751 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
753 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
755 [o_mu_help setTitle: _NS("Help")];
756 [o_mi_help setTitle: _NS("VLC media player Help...")];
757 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
758 [o_mi_license setTitle: _NS("License")];
759 [o_mi_documentation setTitle: _NS("Online Documentation...")];
760 [o_mi_website setTitle: _NS("VideoLAN Website...")];
761 [o_mi_donation setTitle: _NS("Make a donation...")];
762 [o_mi_forum setTitle: _NS("Online Forum...")];
765 [o_dmi_play setTitle: _NS("Play")];
766 [o_dmi_stop setTitle: _NS("Stop")];
767 [o_dmi_next setTitle: _NS("Next")];
768 [o_dmi_previous setTitle: _NS("Previous")];
769 [o_dmi_mute setTitle: _NS("Mute")];
772 [o_vmi_play setTitle: _NS("Play")];
773 [o_vmi_stop setTitle: _NS("Stop")];
774 [o_vmi_prev setTitle: _NS("Previous")];
775 [o_vmi_next setTitle: _NS("Next")];
776 [o_vmi_volup setTitle: _NS("Volume Up")];
777 [o_vmi_voldown setTitle: _NS("Volume Down")];
778 [o_vmi_mute setTitle: _NS("Mute")];
779 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
780 [o_vmi_snapshot setTitle: _NS("Snapshot")];
782 /* crash reporter panel */
783 [o_crashrep_send_btn setTitle: _NS("Send")];
784 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
785 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
786 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
787 [o_crashrep_desc_txt setStringValue: _NS("Do you want to send details on the crash to VLC's development team?\n\nIf you want, you can enter a few lines on what you did before VLC crashed along with other helpful information: a link to download a sample file, a URL of a network stream, ...")];
790 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
792 o_msg_lock = [[NSLock alloc] init];
793 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
795 /* FIXME: don't poll */
796 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
797 target: self selector: @selector(manageIntf:)
798 userInfo: nil repeats: FALSE] retain];
800 /* Note: we use the pthread API to support pre-10.5 */
801 pthread_create( &manage_thread, NULL, ManageThread, self );
803 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
804 var: "intf-add" selector: @selector(toggleVar:)];
806 /* check whether the user runs a valid version of OSX; alert is auto-released */
807 if( MACOS_VERSION < 10.4f )
811 ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is not supported")
812 defaultButton: _NS("Quit")
813 alternateButton: NULL
815 informativeTextWithFormat: _NS("VLC media player requires Mac OS X 10.4 or higher.")];
816 [ourAlert setAlertStyle: NSCriticalAlertStyle];
817 i_returnValue = [ourAlert runModal];
818 [NSApp terminate: self];
821 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
824 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
826 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
827 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
829 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
831 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];
836 - (NSString *)localizedString:(const char *)psz
838 NSString * o_str = nil;
842 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
846 msg_Err( VLCIntf, "could not translate: %s", psz );
852 msg_Warn( VLCIntf, "can't translate empty strings" );
859 /* When user click in the Dock icon our double click in the finder */
860 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
862 if(!hasVisibleWindows)
863 [o_window makeKeyAndOrderFront:self];
868 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
871 /* Check for update silently on startup */
872 if( !nib_update_loaded )
873 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
875 if([o_update shouldCheckForUpdate])
876 [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:nil];
879 /* Handle sleep notification */
880 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
881 name:NSWorkspaceWillSleepNotification object:nil];
883 [NSThread detachNewThreadSelector:@selector(lookForCrashLog) toTarget:self withObject:nil];
886 /* Listen to the remote in exclusive mode, only when VLC is the active
888 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
890 [o_remote startListening: self];
892 - (void)applicationDidResignActive:(NSNotification *)aNotification
894 [o_remote stopListening: self];
897 /* Triggered when the computer goes to sleep */
898 - (void)computerWillSleep: (NSNotification *)notification
901 if( p_intf->p_sys->i_play_status == PLAYING_S )
904 val.i_int = config_GetInt( p_intf, "key-play-pause" );
905 var_Set( p_intf->p_libvlc, "key-pressed", val );
909 /* Helper method for the remote control interface in order to trigger forward/backward and volume
910 increase/decrease as long as the user holds the left/right, plus/minus button */
911 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
913 if(b_remote_button_hold)
915 switch([buttonIdentifierNumber intValue])
917 case kRemoteButtonRight_Hold:
918 [o_controls forward: self];
920 case kRemoteButtonLeft_Hold:
921 [o_controls backward: self];
923 case kRemoteButtonVolume_Plus_Hold:
924 [o_controls volumeUp: self];
926 case kRemoteButtonVolume_Minus_Hold:
927 [o_controls volumeDown: self];
930 if(b_remote_button_hold)
933 [self performSelector:@selector(executeHoldActionForRemoteButton:)
934 withObject:buttonIdentifierNumber
940 /* Apple Remote callback */
941 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
942 pressedDown: (BOOL) pressedDown
943 clickCount: (unsigned int) count
945 switch( buttonIdentifier )
947 case kRemoteButtonPlay:
949 [o_controls toogleFullscreen:self];
951 [o_controls play: self];
954 case kRemoteButtonVolume_Plus:
955 [o_controls volumeUp: self];
957 case kRemoteButtonVolume_Minus:
958 [o_controls volumeDown: self];
960 case kRemoteButtonRight:
961 [o_controls next: self];
963 case kRemoteButtonLeft:
964 [o_controls prev: self];
966 case kRemoteButtonRight_Hold:
967 case kRemoteButtonLeft_Hold:
968 case kRemoteButtonVolume_Plus_Hold:
969 case kRemoteButtonVolume_Minus_Hold:
970 /* simulate an event as long as the user holds the button */
971 b_remote_button_hold = pressedDown;
974 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
975 [self performSelector:@selector(executeHoldActionForRemoteButton:)
976 withObject:buttonIdentifierNumber];
979 case kRemoteButtonMenu:
980 [o_controls showPosition: self];
983 /* Add here whatever you want other buttons to do */
988 - (char *)delocalizeString:(NSString *)id
990 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
991 allowLossyConversion: NO];
996 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
997 allowLossyConversion: YES];
998 psz_string = malloc( [o_data length] + 1 );
999 [o_data getBytes: psz_string];
1000 psz_string[ [o_data length] ] = '\0';
1001 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
1006 psz_string = malloc( [o_data length] + 1 );
1007 [o_data getBytes: psz_string];
1008 psz_string[ [o_data length] ] = '\0';
1014 /* i_width is in pixels */
1015 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
1017 NSMutableString *o_wrapped;
1018 NSString *o_out_string;
1019 NSRange glyphRange, effectiveRange, charRange;
1020 NSRect lineFragmentRect;
1021 unsigned glyphIndex, breaksInserted = 0;
1023 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
1024 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
1025 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
1026 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
1027 NSTextContainer *o_container = [[NSTextContainer alloc]
1028 initWithContainerSize: NSMakeSize(i_width, 2000)];
1030 [o_layout_manager addTextContainer: o_container];
1031 [o_container release];
1032 [o_storage addLayoutManager: o_layout_manager];
1033 [o_layout_manager release];
1035 o_wrapped = [o_in_string mutableCopy];
1036 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
1038 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
1039 glyphIndex += effectiveRange.length) {
1040 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
1041 effectiveRange: &effectiveRange];
1042 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
1043 actualGlyphRange: &effectiveRange];
1044 if([o_wrapped lineRangeForRange:
1045 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
1046 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
1050 o_out_string = [NSString stringWithString: o_wrapped];
1051 [o_wrapped release];
1052 [o_storage release];
1054 return o_out_string;
1058 /*****************************************************************************
1059 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1060 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1061 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1062 *****************************************************************************/
1063 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
1067 unsigned int i_pressed_modifiers = 0;
1068 struct hotkey *p_hotkeys;
1072 p_hotkeys = p_intf->p_libvlc->p_hotkeys;
1074 i_pressed_modifiers = [o_event modifierFlags];
1076 if( i_pressed_modifiers & NSShiftKeyMask )
1077 val.i_int |= KEY_MODIFIER_SHIFT;
1078 if( i_pressed_modifiers & NSControlKeyMask )
1079 val.i_int |= KEY_MODIFIER_CTRL;
1080 if( i_pressed_modifiers & NSAlternateKeyMask )
1081 val.i_int |= KEY_MODIFIER_ALT;
1082 if( i_pressed_modifiers & NSCommandKeyMask )
1083 val.i_int |= KEY_MODIFIER_COMMAND;
1085 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
1089 case NSDeleteCharacter:
1090 case NSDeleteFunctionKey:
1091 case NSDeleteCharFunctionKey:
1092 case NSBackspaceCharacter:
1093 case NSUpArrowFunctionKey:
1094 case NSDownArrowFunctionKey:
1095 case NSRightArrowFunctionKey:
1096 case NSLeftArrowFunctionKey:
1097 case NSEnterCharacter:
1098 case NSCarriageReturnCharacter:
1102 val.i_int |= CocoaKeyToVLC( key );
1104 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1106 if( p_hotkeys[i].i_key == val.i_int )
1108 var_Set( p_intf->p_libvlc, "key-pressed", val );
1124 - (id)getSimplePreferences
1129 if( !nib_prefs_loaded )
1130 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1135 - (id)getPreferences
1140 if( !nib_prefs_loaded )
1141 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1178 - (id)getEmbeddedList
1180 if( o_embedded_list )
1181 return o_embedded_list;
1186 - (id)getInteractionList
1188 if( o_interaction_list )
1189 return o_interaction_list;
1194 - (id)getMainIntfPgbar
1197 return o_main_pgbar;
1202 - (id)getControllerWindow
1214 - (id)getEyeTVController
1224 playlist_t * p_playlist;
1225 input_thread_t * p_input = NULL;
1227 /* new thread requires a new pool */
1228 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1230 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
1232 p_playlist = pl_Yield( p_intf );
1234 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1235 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1236 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1237 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
1238 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1240 pl_Release( p_intf );
1242 vlc_object_lock( p_intf );
1244 while( vlc_object_alive( p_intf ) )
1246 vlc_mutex_lock( &p_intf->change_lock );
1250 p_input = playlist_CurrentInput( p_playlist );
1252 /* Refresh the interface */
1255 msg_Dbg( p_intf, "input has changed, refreshing interface" );
1256 p_intf->p_sys->b_input_update = true;
1259 else if( !vlc_object_alive (p_input) || p_input->b_dead )
1262 p_intf->p_sys->b_intf_update = true;
1263 p_intf->p_sys->i_play_status = END_S;
1264 msg_Dbg( p_intf, "input has stopped, refreshing interface" );
1265 vlc_object_release( p_input );
1268 else if( cachedInputState != input_GetState( p_input ) )
1270 p_intf->p_sys->b_intf_update = true;
1273 /* Manage volume status */
1274 [self manageVolumeSlider];
1276 vlc_mutex_unlock( &p_intf->change_lock );
1278 vlc_object_timedwait( p_intf, 100000 + mdate());
1280 vlc_object_unlock( p_intf );
1283 if( p_input ) vlc_object_release( p_input );
1285 var_DelCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1286 var_DelCallback( p_playlist, "intf-change", PlaylistChanged, self );
1287 var_DelCallback( p_playlist, "item-change", PlaylistChanged, self );
1288 var_DelCallback( p_playlist, "item-append", PlaylistChanged, self );
1289 var_DelCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1291 pthread_testcancel(); /* If we were cancelled stop here */
1293 msg_Dbg( p_intf, "Killing the Mac OS X module" );
1295 /* We are dead, terminate */
1296 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
1299 - (void)manageIntf:(NSTimer *)o_timer
1302 playlist_t * p_playlist;
1303 input_thread_t * p_input;
1305 if( p_intf->p_sys->b_input_update )
1307 /* Called when new input is opened */
1308 p_intf->p_sys->b_current_title_update = true;
1309 p_intf->p_sys->b_intf_update = true;
1310 p_intf->p_sys->b_input_update = false;
1311 [self setupMenus]; /* Make sure input menu is up to date */
1313 if( p_intf->p_sys->b_intf_update )
1315 bool b_input = false;
1316 bool b_plmul = false;
1317 bool b_control = false;
1318 bool b_seekable = false;
1319 bool b_chapters = false;
1321 playlist_t * p_playlist = pl_Yield( p_intf );
1322 /* TODO: fix i_size use */
1323 b_plmul = p_playlist->items.i_size > 1;
1325 p_input = playlist_CurrentInput( p_playlist );
1326 bool b_buffering = NO;
1328 if( ( b_input = ( p_input != NULL ) ) )
1330 /* seekable streams */
1331 cachedInputState = input_GetState( p_input );
1332 if ( cachedInputState == INIT_S ||
1333 cachedInputState == OPENING_S ||
1334 cachedInputState == BUFFERING_S )
1339 /* seekable streams */
1340 b_seekable = var_GetBool( p_input, "seekable" );
1342 /* check whether slow/fast motion is possible */
1343 b_control = p_input->b_can_pace_control;
1345 /* chapters & titles */
1346 //b_chapters = p_input->stream.i_area_nb > 1;
1347 vlc_object_release( p_input );
1349 pl_Release( p_intf );
1353 [o_main_pgbar startAnimation:self];
1354 [o_main_pgbar setIndeterminate:YES];
1355 [o_main_pgbar setHidden:NO];
1359 [o_main_pgbar stopAnimation:self];
1360 [o_main_pgbar setHidden:YES];
1363 [o_btn_stop setEnabled: b_input];
1364 [o_btn_ff setEnabled: b_seekable];
1365 [o_btn_rewind setEnabled: b_seekable];
1366 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
1367 [o_btn_next setEnabled: (b_plmul || b_chapters)];
1369 [o_timeslider setFloatValue: 0.0];
1370 [o_timeslider setEnabled: b_seekable];
1371 [o_timefield setStringValue: @"00:00"];
1372 [[[self getControls] getFSPanel] setStreamPos: 0 andTime: @"00:00"];
1373 [[[self getControls] getFSPanel] setSeekable: b_seekable];
1375 [o_embedded_window setSeekable: b_seekable];
1377 p_intf->p_sys->b_current_title_update = true;
1379 p_intf->p_sys->b_intf_update = false;
1382 if( p_intf->p_sys->b_playmode_update )
1384 [o_playlist playModeUpdated];
1385 p_intf->p_sys->b_playmode_update = false;
1387 if( p_intf->p_sys->b_playlist_update )
1389 [o_playlist playlistUpdated];
1390 p_intf->p_sys->b_playlist_update = false;
1393 if( p_intf->p_sys->b_fullscreen_update )
1395 p_intf->p_sys->b_fullscreen_update = false;
1398 if( p_intf->p_sys->b_intf_show )
1400 [o_window makeKeyAndOrderFront: self];
1402 p_intf->p_sys->b_intf_show = false;
1405 p_input = pl_CurrentInput( p_intf );
1406 if( p_input && vlc_object_alive (p_input) )
1410 if( p_intf->p_sys->b_current_title_update )
1413 input_item_t * p_item = input_GetItem( p_input );
1414 char * name = input_item_GetNowPlaying( p_item );
1417 name = input_item_GetName( p_item );
1419 aString = [NSString stringWithUTF8String:name];
1423 [self setScrollField: aString stopAfter:-1];
1424 [[[self getControls] getFSPanel] setStreamTitle: aString];
1426 [[o_controls getVoutView] updateTitle];
1428 [o_playlist updateRowSelection];
1429 p_intf->p_sys->b_current_title_update = FALSE;
1432 if( [o_timeslider isEnabled] )
1434 /* Update the slider */
1438 char psz_time[MSTRTIME_MAX_SIZE];
1441 var_Get( p_input, "position", &pos );
1442 f_updated = 10000. * pos.f_float;
1443 [o_timeslider setFloatValue: f_updated];
1445 var_Get( p_input, "time", &time );
1447 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1449 [o_timefield setStringValue: o_time];
1450 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1451 [o_embedded_window setTime: o_time position: f_updated];
1454 /* Manage Playing status */
1455 var_Get( p_input, "state", &val );
1456 if( p_intf->p_sys->i_play_status != val.i_int )
1458 p_intf->p_sys->i_play_status = val.i_int;
1459 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1460 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1462 vlc_object_release( p_input );
1466 vlc_object_release( p_input );
1470 p_intf->p_sys->i_play_status = END_S;
1471 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1472 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1473 [self setSubmenusEnabled: FALSE];
1476 if( p_intf->p_sys->b_volume_update )
1479 int i_volume_step = 0;
1480 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1481 if( i_lastShownVolume != -1 )
1482 [self setScrollField:o_text stopAfter:1000000];
1483 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1484 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1485 [o_volumeslider setEnabled: TRUE];
1486 [[[self getControls] getFSPanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
1487 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1488 p_intf->p_sys->b_volume_update = FALSE;
1492 [self updateMessageArray];
1494 if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
1495 [self resetScrollField];
1497 [interfaceTimer autorelease];
1499 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.3
1500 target: self selector: @selector(manageIntf:)
1501 userInfo: nil repeats: FALSE] retain];
1506 playlist_t * p_playlist = pl_Yield( p_intf );
1507 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1508 if( p_input != NULL )
1510 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1511 var: "program" selector: @selector(toggleVar:)];
1513 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1514 var: "title" selector: @selector(toggleVar:)];
1516 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1517 var: "chapter" selector: @selector(toggleVar:)];
1519 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1520 var: "audio-es" selector: @selector(toggleVar:)];
1522 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1523 var: "video-es" selector: @selector(toggleVar:)];
1525 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1526 var: "spu-es" selector: @selector(toggleVar:)];
1528 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1530 if( p_aout != NULL )
1532 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1533 var: "audio-channels" selector: @selector(toggleVar:)];
1535 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1536 var: "audio-device" selector: @selector(toggleVar:)];
1538 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1539 var: "visual" selector: @selector(toggleVar:)];
1540 vlc_object_release( (vlc_object_t *)p_aout );
1543 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1546 if( p_vout != NULL )
1548 vlc_object_t * p_dec_obj;
1550 [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
1551 var: "aspect-ratio" selector: @selector(toggleVar:)];
1553 [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
1554 var: "crop" selector: @selector(toggleVar:)];
1556 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1557 var: "video-device" selector: @selector(toggleVar:)];
1559 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1560 var: "deinterlace" selector: @selector(toggleVar:)];
1562 p_dec_obj = (vlc_object_t *)vlc_object_find(
1563 (vlc_object_t *)p_vout,
1566 if( p_dec_obj != NULL )
1568 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1569 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1570 @selector(toggleVar:)];
1572 vlc_object_release(p_dec_obj);
1574 vlc_object_release( (vlc_object_t *)p_vout );
1576 vlc_object_release( p_input );
1578 pl_Release( p_intf );
1581 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
1584 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1590 /* clean the menu before adding new entries */
1591 if( [o_mi_screen hasSubmenu] )
1593 y = [[o_mi_screen submenu] numberOfItems] - 1;
1594 msg_Dbg( VLCIntf, "%i items in submenu", y );
1597 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
1598 [[o_mi_screen submenu] removeItemAtIndex: x];
1603 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1604 var: "video-device" selector: @selector(toggleVar:)];
1605 vlc_object_release( (vlc_object_t *)p_vout );
1608 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1611 i_end_scroll = mdate() + timeout;
1614 [o_scrollfield setStringValue: o_string];
1617 - (void)resetScrollField
1619 playlist_t * p_playlist = pl_Yield( p_intf );
1620 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1623 if( p_input && vlc_object_alive (p_input) )
1626 if( input_item_GetNowPlaying ( p_playlist->status.p_item->p_input ) )
1627 o_temp = [NSString stringWithUTF8String:
1628 input_item_GetNowPlaying ( p_playlist->status.p_item->p_input )];
1630 o_temp = [NSString stringWithUTF8String:
1631 p_playlist->status.p_item->p_input->psz_name];
1632 [self setScrollField: o_temp stopAfter:-1];
1633 [[[self getControls] getFSPanel] setStreamTitle: o_temp];
1634 vlc_object_release( p_input );
1635 pl_Release( p_intf );
1638 pl_Release( p_intf );
1639 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1642 - (void)updateMessageArray
1644 int i_start, i_stop;
1646 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1647 i_stop = *p_intf->p_sys->p_sub->pi_stop;
1648 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1650 if( p_intf->p_sys->p_sub->i_start != i_stop )
1652 NSColor *o_white = [NSColor whiteColor];
1653 NSColor *o_red = [NSColor redColor];
1654 NSColor *o_yellow = [NSColor yellowColor];
1655 NSColor *o_gray = [NSColor grayColor];
1657 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
1658 static const char * ppsz_type[4] = { ": ", " error: ",
1659 " warning: ", " debug: " };
1661 for( i_start = p_intf->p_sys->p_sub->i_start;
1663 i_start = (i_start+1) % VLC_MSG_QSIZE )
1666 NSDictionary *o_attr;
1667 NSAttributedString *o_msg_color;
1669 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
1673 if( [o_msg_arr count] + 2 > 400 )
1675 unsigned rid[] = { 0, 1 };
1676 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
1677 numIndices: sizeof(rid)/sizeof(rid[0])];
1680 o_attr = [NSDictionary dictionaryWithObject: o_gray
1681 forKey: NSForegroundColorAttributeName];
1682 o_msg = [NSString stringWithFormat: @"%s%s",
1683 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
1685 o_msg_color = [[NSAttributedString alloc]
1686 initWithString: o_msg attributes: o_attr];
1687 [o_msg_arr addObject: [o_msg_color autorelease]];
1689 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
1690 forKey: NSForegroundColorAttributeName];
1691 o_msg = [[NSString stringWithUTF8String: p_intf->p_sys->p_sub->p_msg[i_start].psz_msg] stringByAppendingString: @"\n"];
1692 o_msg_color = [[NSAttributedString alloc]
1693 initWithString: o_msg attributes: o_attr];
1694 [o_msg_arr addObject: [o_msg_color autorelease]];
1696 [o_msg_lock unlock];
1699 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
1700 p_intf->p_sys->p_sub->i_start = i_start;
1701 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
1705 - (void)playStatusUpdated:(int)i_status
1707 if( i_status == PLAYING_S )
1709 [[[self getControls] getFSPanel] setPause];
1710 [o_btn_play setImage: o_img_pause];
1711 [o_btn_play setAlternateImage: o_img_pause_pressed];
1712 [o_btn_play setToolTip: _NS("Pause")];
1713 [o_mi_play setTitle: _NS("Pause")];
1714 [o_dmi_play setTitle: _NS("Pause")];
1715 [o_vmi_play setTitle: _NS("Pause")];
1719 [[[self getControls] getFSPanel] setPlay];
1720 [o_btn_play setImage: o_img_play];
1721 [o_btn_play setAlternateImage: o_img_play_pressed];
1722 [o_btn_play setToolTip: _NS("Play")];
1723 [o_mi_play setTitle: _NS("Play")];
1724 [o_dmi_play setTitle: _NS("Play")];
1725 [o_vmi_play setTitle: _NS("Play")];
1729 - (void)setSubmenusEnabled:(BOOL)b_enabled
1731 [o_mi_program setEnabled: b_enabled];
1732 [o_mi_title setEnabled: b_enabled];
1733 [o_mi_chapter setEnabled: b_enabled];
1734 [o_mi_audiotrack setEnabled: b_enabled];
1735 [o_mi_visual setEnabled: b_enabled];
1736 [o_mi_videotrack setEnabled: b_enabled];
1737 [o_mi_subtitle setEnabled: b_enabled];
1738 [o_mi_channels setEnabled: b_enabled];
1739 [o_mi_deinterlace setEnabled: b_enabled];
1740 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1741 [o_mi_device setEnabled: b_enabled];
1742 [o_mi_screen setEnabled: b_enabled];
1743 [o_mi_aspect_ratio setEnabled: b_enabled];
1744 [o_mi_crop setEnabled: b_enabled];
1747 - (void)manageVolumeSlider
1749 audio_volume_t i_volume;
1750 aout_VolumeGet( p_intf, &i_volume );
1752 if( i_volume != i_lastShownVolume )
1754 i_lastShownVolume = i_volume;
1755 p_intf->p_sys->b_volume_update = TRUE;
1759 - (IBAction)timesliderUpdate:(id)sender
1762 playlist_t * p_playlist;
1763 input_thread_t * p_input;
1765 switch( [[NSApp currentEvent] type] )
1768 case NSLeftMouseDown:
1769 case NSLeftMouseDragged:
1770 f_updated = [sender floatValue];
1776 p_playlist = pl_Yield( p_intf );
1777 p_input = playlist_CurrentInput( p_playlist );
1778 if( p_input != NULL )
1783 char psz_time[MSTRTIME_MAX_SIZE];
1785 pos.f_float = f_updated / 10000.;
1786 var_Set( p_input, "position", pos );
1787 [o_timeslider setFloatValue: f_updated];
1789 var_Get( p_input, "time", &time );
1791 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1792 [o_timefield setStringValue: o_time];
1793 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1794 [o_embedded_window setTime: o_time position: f_updated];
1795 vlc_object_release( p_input );
1797 pl_Release( p_intf );
1800 - (void)applicationWillTerminate:(NSNotification *)notification
1802 playlist_t * p_playlist;
1803 vout_thread_t * p_vout;
1804 int returnedValue = 0;
1806 msg_Dbg( p_intf, "Terminating" );
1808 /* Make sure the manage_thread won't call -terminate: again */
1809 pthread_cancel( manage_thread );
1811 /* Make sure the intf object is getting killed */
1812 vlc_object_kill( p_intf );
1814 /* Make sure our manage_thread ends */
1815 pthread_join( manage_thread, NULL );
1817 /* Make sure the interfaceTimer is destroyed */
1818 [interfaceTimer invalidate];
1819 [interfaceTimer release];
1820 interfaceTimer = nil;
1822 /* make sure that the current volume is saved */
1823 config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );
1824 returnedValue = config_SaveConfigFile( p_intf->p_libvlc, "main" );
1825 if( returnedValue != 0 )
1827 "error while saving volume in osx's terminate method (%i)",
1830 /* save the prefs if they were changed in the extended panel */
1831 if(o_extended && [o_extended getConfigChanged])
1833 [o_extended savePrefs];
1836 p_intf->b_interaction = false;
1837 var_DelCallback( p_intf, "interaction", InteractCallback, self );
1839 /* remove global observer watching for vout device changes correctly */
1840 [[NSNotificationCenter defaultCenter] removeObserver: self];
1842 /* release some other objects here, because it isn't sure whether dealloc
1843 * will be called later on */
1845 if( nib_about_loaded )
1848 if( nib_prefs_loaded )
1854 if( nib_open_loaded )
1857 if( nib_extended_loaded )
1859 [o_extended release];
1862 if( nib_bookmarks_loaded )
1863 [o_bookmarks release];
1867 [o_info stopTimers];
1871 if( nib_wizard_loaded )
1874 [crashLogURLConnection cancel];
1875 [crashLogURLConnection release];
1877 [o_embedded_list release];
1878 [o_interaction_list release];
1881 [o_img_pause_pressed release];
1882 [o_img_play_pressed release];
1883 [o_img_pause release];
1884 [o_img_play release];
1886 [o_msg_arr removeAllObjects];
1887 [o_msg_arr release];
1889 [o_msg_lock release];
1891 /* write cached user defaults to disk */
1892 [[NSUserDefaults standardUserDefaults] synchronize];
1894 /* Kill the playlist, so that it doesn't accept new request
1895 * such as the play request from vlc.c (we are a blocking interface). */
1896 p_playlist = pl_Yield( p_intf );
1897 vlc_object_kill( p_playlist );
1898 pl_Release( p_intf );
1900 vlc_object_kill( p_intf->p_libvlc );
1902 /* Go back to Run() and make libvlc exit properly */
1904 longjmp( jmpbuffer, 1 );
1909 - (IBAction)clearRecentItems:(id)sender
1911 [[NSDocumentController sharedDocumentController]
1912 clearRecentDocuments: nil];
1915 - (void)openRecentItem:(id)sender
1917 [self application: nil openFile: [sender title]];
1920 - (IBAction)intfOpenFile:(id)sender
1922 if( !nib_open_loaded )
1924 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1925 [o_open awakeFromNib];
1932 - (IBAction)intfOpenFileGeneric:(id)sender
1934 if( !nib_open_loaded )
1936 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1937 [o_open awakeFromNib];
1938 [o_open openFileGeneric];
1940 [o_open openFileGeneric];
1944 - (IBAction)intfOpenDisc:(id)sender
1946 if( !nib_open_loaded )
1948 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1949 [o_open awakeFromNib];
1956 - (IBAction)intfOpenNet:(id)sender
1958 if( !nib_open_loaded )
1960 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1961 [o_open awakeFromNib];
1968 - (IBAction)intfOpenCapture:(id)sender
1970 if( !nib_open_loaded )
1972 nib_open_loaded = [NSBundle loadNibNamed:@"Open" owner:self];
1973 [o_open awakeFromNib];
1974 [o_open openCapture];
1976 [o_open openCapture];
1980 - (IBAction)showWizard:(id)sender
1982 if( !nib_wizard_loaded )
1984 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
1985 [o_wizard initStrings];
1986 [o_wizard resetWizard];
1987 [o_wizard showWizard];
1989 [o_wizard resetWizard];
1990 [o_wizard showWizard];
1994 - (IBAction)showExtended:(id)sender
1996 if( o_extended == nil )
1997 o_extended = [[VLCExtended alloc] init];
1999 if( !nib_extended_loaded )
2000 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner:self];
2002 [o_extended showPanel];
2005 - (IBAction)showBookmarks:(id)sender
2007 /* we need the wizard-nib for the bookmarks's extract functionality */
2008 if( !nib_wizard_loaded )
2010 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
2011 [o_wizard initStrings];
2014 if( !nib_bookmarks_loaded )
2015 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner:self];
2017 [o_bookmarks showBookmarks];
2020 - (IBAction)viewAbout:(id)sender
2022 if( !nib_about_loaded )
2023 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2025 [o_about showAbout];
2028 - (IBAction)showLicense:(id)sender
2030 if( !nib_about_loaded )
2031 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2033 [o_about showGPL: sender];
2036 - (IBAction)viewPreferences:(id)sender
2038 if( !nib_prefs_loaded )
2040 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
2041 o_sprefs = [[VLCSimplePrefs alloc] init];
2042 o_prefs= [[VLCPrefs alloc] init];
2045 [o_sprefs showSimplePrefs];
2048 - (IBAction)checkForUpdate:(id)sender
2051 if( !nib_update_loaded )
2052 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
2053 [o_update showUpdateWindow];
2055 msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
2056 intf_UserFatal( VLCIntf, false, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
2060 - (IBAction)viewHelp:(id)sender
2062 if( !nib_about_loaded )
2064 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2071 - (IBAction)openReadMe:(id)sender
2073 NSString * o_path = [[NSBundle mainBundle]
2074 pathForResource: @"README.MacOSX" ofType: @"rtf"];
2076 [[NSWorkspace sharedWorkspace] openFile: o_path
2077 withApplication: @"TextEdit"];
2080 - (IBAction)openDocumentation:(id)sender
2082 NSURL * o_url = [NSURL URLWithString:
2083 @"http://www.videolan.org/doc/"];
2085 [[NSWorkspace sharedWorkspace] openURL: o_url];
2088 - (IBAction)openWebsite:(id)sender
2090 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
2092 [[NSWorkspace sharedWorkspace] openURL: o_url];
2095 - (IBAction)openForum:(id)sender
2097 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
2099 [[NSWorkspace sharedWorkspace] openURL: o_url];
2102 - (IBAction)openDonate:(id)sender
2104 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
2106 [[NSWorkspace sharedWorkspace] openURL: o_url];
2109 #pragma mark Crash Log
2110 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
2112 NSString *urlStr = @"http://jones.videolan.org/crashlog/sendcrashreport.php";
2113 NSURL *url = [NSURL URLWithString:urlStr];
2115 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
2116 [req setHTTPMethod:@"POST"];
2118 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
2120 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
2121 NSString * email = [emails valueAtIndex:[emails indexForIdentifier:
2122 [emails primaryIdentifier]]];
2125 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
2126 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2127 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2128 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
2130 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
2132 /* Released from delegate */
2133 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
2136 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
2138 NSRunInformationalAlertPanel(_NS("Crash Report successfully sent"),
2139 _NS("Thanks for your report!"),
2140 _NS("OK"), nil, nil, nil);
2141 [crashLogURLConnection release];
2142 crashLogURLConnection = nil;
2145 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
2147 NSRunCriticalAlertPanel(_NS("Error when sending the Crash Report"), [error localizedDescription], @"OK", nil, nil);
2148 [crashLogURLConnection release];
2149 crashLogURLConnection = nil;
2152 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
2154 NSString * crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
2155 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
2157 NSString * latestLog = nil;
2158 NSInteger year = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"] : 0;
2159 NSInteger month = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportMonth"]: 0;
2160 NSInteger day = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportDay"] : 0;
2161 NSInteger hours = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportHours"]: 0;
2163 while (fname = [direnum nextObject])
2165 [direnum skipDescendents];
2166 if([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"])
2168 NSArray * compo = [fname componentsSeparatedByString:@"_"];
2169 if( [compo count] < 3 ) continue;
2170 compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
2171 if( [compo count] < 4 ) continue;
2174 if( year < [[compo objectAtIndex:0] intValue] ||
2175 (year ==[[compo objectAtIndex:0] intValue] &&
2176 (month < [[compo objectAtIndex:1] intValue] ||
2177 (month ==[[compo objectAtIndex:1] intValue] &&
2178 (day < [[compo objectAtIndex:2] intValue] ||
2179 (day ==[[compo objectAtIndex:2] intValue] &&
2180 hours < [[compo objectAtIndex:3] intValue] ))))))
2182 year = [[compo objectAtIndex:0] intValue];
2183 month = [[compo objectAtIndex:1] intValue];
2184 day = [[compo objectAtIndex:2] intValue];
2185 hours = [[compo objectAtIndex:3] intValue];
2186 latestLog = [crashReporter stringByAppendingPathComponent:fname];
2191 if(!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
2194 if( !previouslySeen )
2196 [[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"LatestCrashReportYear"];
2197 [[NSUserDefaults standardUserDefaults] setInteger:month forKey:@"LatestCrashReportMonth"];
2198 [[NSUserDefaults standardUserDefaults] setInteger:day forKey:@"LatestCrashReportDay"];
2199 [[NSUserDefaults standardUserDefaults] setInteger:hours forKey:@"LatestCrashReportHours"];
2204 - (NSString *)latestCrashLogPath
2206 return [self latestCrashLogPathPreviouslySeen:YES];
2209 - (void)lookForCrashLog
2211 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
2212 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
2213 BOOL areCrashLogsTooOld = ![[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"];
2214 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
2215 if( latestLog && !areCrashLogsTooOld )
2216 [NSApp runModalForWindow: o_crashrep_win];
2220 - (IBAction)crashReporterAction:(id)sender
2222 if( sender == o_crashrep_send_btn )
2223 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath]] withUserComment: [o_crashrep_fld string]];
2226 [o_crashrep_win orderOut: sender];
2229 - (IBAction)openCrashLog:(id)sender
2231 NSString * latestLog = [self latestCrashLogPath];
2234 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
2238 NSBeginInformationalAlertSheet(_NS("No CrashLog found"), _NS("Continue"), nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Couldn't find any trace of a previous crash.") );
2244 - (IBAction)viewErrorsAndWarnings:(id)sender
2246 [[[self getInteractionList] getErrorPanel] showPanel];
2249 - (IBAction)showMessagesPanel:(id)sender
2251 [o_msgs_panel makeKeyAndOrderFront: sender];
2254 - (IBAction)showInformationPanel:(id)sender
2256 if(! nib_info_loaded )
2257 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: self];
2262 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2264 if( [o_notification object] == o_msgs_panel )
2267 NSEnumerator * o_enum;
2269 [o_messages setString: @""];
2273 o_enum = [o_msg_arr objectEnumerator];
2275 while( ( o_msg = [o_enum nextObject] ) != nil )
2277 [o_messages insertText: o_msg];
2280 [o_msg_lock unlock];
2284 #pragma mark Playlist toggling
2286 - (IBAction)togglePlaylist:(id)sender
2288 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2289 NSRect o_rect = [o_window contentRectForFrameRect:[o_window frame]];
2290 /*First, check if the playlist is visible*/
2291 if( contentRect.size.height <= 169. )
2293 o_restore_rect = contentRect;
2294 b_restore_size = true;
2295 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
2298 if( o_size_with_playlist.height > 169. )
2299 o_rect.size.height = o_size_with_playlist.height;
2301 o_rect.size.height = 500.;
2303 if( o_size_with_playlist.width >= [o_window contentMinSize].width )
2304 o_rect.size.width = o_size_with_playlist.width;
2306 o_rect.size.width = [o_window contentMinSize].width;
2308 o_rect.origin.x = contentRect.origin.x;
2309 o_rect.origin.y = contentRect.origin.y - o_rect.size.height +
2310 [o_window contentMinSize].height;
2312 o_rect = [o_window frameRectForContentRect:o_rect];
2314 NSRect screenRect = [[o_window screen] visibleFrame];
2315 if( !NSContainsRect( screenRect, o_rect ) ) {
2316 if( NSMaxX(o_rect) > NSMaxX(screenRect) )
2317 o_rect.origin.x = ( NSMaxX(screenRect) - o_rect.size.width );
2318 if( NSMinY(o_rect) < NSMinY(screenRect) )
2319 o_rect.origin.y = ( NSMinY(screenRect) );
2322 [o_btn_playlist setState: YES];
2326 NSSize curSize = o_rect.size;
2327 if( b_restore_size )
2329 o_rect = o_restore_rect;
2330 if( o_rect.size.height < [o_window contentMinSize].height )
2331 o_rect.size.height = [o_window contentMinSize].height;
2332 if( o_rect.size.width < [o_window contentMinSize].width )
2333 o_rect.size.width = [o_window contentMinSize].width;
2337 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2339 o_rect.size.height = [o_window contentMinSize].height;
2340 o_rect.size.width = [o_window contentMinSize].width;
2341 o_rect.origin.x = contentRect.origin.x;
2342 /* Calculate the position of the lower right corner after resize */
2343 o_rect.origin.y = contentRect.origin.y +
2344 contentRect.size.height - [o_window contentMinSize].height;
2347 [o_playlist_view setAutoresizesSubviews: NO];
2348 [o_playlist_view removeFromSuperview];
2349 [o_btn_playlist setState: NO];
2350 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
2351 o_rect = [o_window frameRectForContentRect:o_rect];
2354 [o_window setFrame: o_rect display:YES animate: YES];
2357 - (void)updateTogglePlaylistState
2359 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
2361 [o_btn_playlist setState: NO];
2365 [o_btn_playlist setState: YES];
2369 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
2372 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
2374 /*Stores the size the controller one resize, to be able to restore it when
2375 toggling the playlist*/
2376 o_size_with_playlist = proposedFrameSize;
2379 rect.size = proposedFrameSize;
2380 if( [o_window contentRectForFrameRect:rect].size.height <= 169. )
2382 if( b_small_window == NO )
2384 /* if large and going to small then hide */
2385 b_small_window = YES;
2386 [o_playlist_view setAutoresizesSubviews: NO];
2387 [o_playlist_view removeFromSuperview];
2389 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
2391 return proposedFrameSize;
2394 - (void)windowDidMove:(NSNotification *)notif
2396 b_restore_size = false;
2399 - (void)windowDidResize:(NSNotification *)notif
2401 if( [o_window contentRectForFrameRect:[o_window frame]].size.height > 169. && b_small_window )
2403 /* If large and coming from small then show */
2404 [o_playlist_view setAutoresizesSubviews: YES];
2405 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2406 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
2407 [o_playlist_view setNeedsDisplay:YES];
2408 [[o_window contentView] addSubview: o_playlist_view];
2409 b_small_window = NO;
2411 [self updateTogglePlaylistState];
2418 @implementation VLCMain (NSMenuValidation)
2420 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
2422 NSString *o_title = [o_mi title];
2423 BOOL bEnabled = TRUE;
2425 /* Recent Items Menu */
2426 if( [o_title isEqualToString: _NS("Clear Menu")] )
2428 NSMenu * o_menu = [o_mi_open_recent submenu];
2429 int i_nb_items = [o_menu numberOfItems];
2430 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
2431 recentDocumentURLs];
2432 UInt32 i_nb_docs = [o_docs count];
2434 if( i_nb_items > 1 )
2436 while( --i_nb_items )
2438 [o_menu removeItemAtIndex: 0];
2447 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
2453 o_url = [o_docs objectAtIndex: i_nb_docs];
2455 if( [o_url isFileURL] )
2457 o_doc = [o_url path];
2461 o_doc = [o_url absoluteString];
2464 [o_menu insertItemWithTitle: o_doc
2465 action: @selector(openRecentItem:)
2466 keyEquivalent: @"" atIndex: 0];
2468 if( i_nb_docs == 0 )
2484 @implementation VLCMain (Internal)
2486 - (void)handlePortMessage:(NSPortMessage *)o_msg
2491 NSInvocation * o_inv;
2492 NSConditionLock * o_lock;
2494 o_data = [[o_msg components] lastObject];
2495 o_inv = *((NSInvocation **)[o_data bytes]);
2496 [o_inv getArgument: &o_value atIndex: 2];
2497 val = (id **)[o_value pointerValue];
2498 [o_inv setArgument: val[1] atIndex: 2];
2503 [o_lock unlockWithCondition: 1];