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 */
34 #include <unistd.h> /* execl() */
45 #import "playlistinfo.h"
52 #import "interaction.h"
53 #import "embeddedwindow.h"
55 #import "AppleRemote.h"
57 #import "simple_prefs.h"
61 #import <vlc_interface.h>
62 #import <AddressBook/AddressBook.h>
64 /*****************************************************************************
66 *****************************************************************************/
67 static void Run ( intf_thread_t *p_intf );
69 static void * ManageThread( void *user_data );
71 static unichar VLCKeyToCocoa( unsigned int i_key );
72 static unsigned int VLCModifiersToCocoa( unsigned int i_key );
75 #pragma mark VLC Interface Object Callbacks
77 /*****************************************************************************
78 * OpenIntf: initialize interface
79 *****************************************************************************/
80 int OpenIntf ( vlc_object_t *p_this )
82 intf_thread_t *p_intf = (intf_thread_t*) p_this;
84 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
85 if( p_intf->p_sys == NULL )
90 memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
92 p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
94 // p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
96 p_intf->b_should_run_on_first_thread = true;
101 /*****************************************************************************
102 * CloseIntf: destroy interface
103 *****************************************************************************/
104 void CloseIntf ( vlc_object_t *p_this )
106 intf_thread_t *p_intf = (intf_thread_t*) p_this;
108 // msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
110 [p_intf->p_sys->o_pool release];
112 free( p_intf->p_sys );
115 /*****************************************************************************
117 *****************************************************************************/
120 static void Run( intf_thread_t *p_intf )
124 /* Do it again - for some unknown reason, vlc_thread_create() often
125 * fails to go to real-time priority with the first launched thread
127 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
129 /* Make sure the "force quit" menu item does quit instantly.
130 * VLC overrides SIGTERM which is sent by the "force quit"
131 * menu item to make sure deamon mode quits gracefully, so
132 * we un-override SIGTERM here. */
134 sigaddset( &set, SIGTERM );
135 pthread_sigmask( SIG_UNBLOCK, &set, NULL );
137 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
139 /* Install a jmpbuffer to where we can go back before the NSApp exit
140 * see applicationWillTerminate: */
141 [NSApplication sharedApplication];
143 [[VLCMain sharedInstance] setIntf: p_intf];
144 [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
146 /* Install a jmpbuffer to where we can go back before the NSApp exit
147 * see applicationWillTerminate: */
148 if(setjmp(jmpbuffer) == 0)
155 #pragma mark Variables Callback
157 /*****************************************************************************
158 * playlistChanged: Callback triggered by the intf-change playlist
159 * variable, to let the intf update the playlist.
160 *****************************************************************************/
161 static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
162 vlc_value_t old_val, vlc_value_t new_val, void *param )
164 intf_thread_t * p_intf = VLCIntf;
165 p_intf->p_sys->b_intf_update = true;
166 p_intf->p_sys->b_playlist_update = true;
167 p_intf->p_sys->b_playmode_update = true;
168 p_intf->p_sys->b_current_title_update = true;
172 /*****************************************************************************
173 * ShowController: Callback triggered by the show-intf playlist variable
174 * through the ShowIntf-control-intf, to let us show the controller-win;
175 * usually when in fullscreen-mode
176 *****************************************************************************/
177 static int ShowController( vlc_object_t *p_this, const char *psz_variable,
178 vlc_value_t old_val, vlc_value_t new_val, void *param )
180 intf_thread_t * p_intf = VLCIntf;
181 p_intf->p_sys->b_intf_show = true;
185 /*****************************************************************************
186 * FullscreenChanged: Callback triggered by the fullscreen-change playlist
187 * variable, to let the intf update the controller.
188 *****************************************************************************/
189 static int FullscreenChanged( 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_fullscreen_update = true;
197 /*****************************************************************************
198 * InteractCallback: Callback triggered by the interaction
199 * variable, to let the intf display error and interaction dialogs
200 *****************************************************************************/
201 static int InteractCallback( vlc_object_t *p_this, const char *psz_variable,
202 vlc_value_t old_val, vlc_value_t new_val, void *param )
204 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
205 VLCMain *interface = (VLCMain *)param;
206 interaction_dialog_t *p_dialog = (interaction_dialog_t *)(new_val.p_address);
207 NSValue *o_value = [NSValue valueWithPointer:p_dialog];
209 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList]
210 userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]];
219 @interface VLCMain ()
220 - (void)_removeOldPreferences;
223 /*****************************************************************************
224 * VLCMain implementation
225 *****************************************************************************/
226 @implementation VLCMain
229 #pragma mark Initialization
231 static VLCMain *_o_sharedMainInstance = nil;
233 + (VLCMain *)sharedInstance
235 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
240 if( _o_sharedMainInstance)
243 return _o_sharedMainInstance;
246 _o_sharedMainInstance = [super init];
248 o_about = [[VLAboutBox alloc] init];
250 o_open = [[VLCOpen alloc] init];
251 o_wizard = [[VLCWizard alloc] init];
252 o_vlm = [[VLCVLMController alloc] init];
254 o_bookmarks = [[VLCBookmarks alloc] init];
255 o_embedded_list = [[VLCEmbeddedList alloc] init];
256 o_interaction_list = [[VLCInteractionList alloc] init];
257 o_info = [[VLCInfo alloc] init];
259 o_update = [[VLCUpdate alloc] init];
262 i_lastShownVolume = -1;
264 o_remote = [[AppleRemote alloc] init];
265 [o_remote setClickCountEnabledButtons: kRemoteButtonPlay];
266 [o_remote setDelegate: _o_sharedMainInstance];
268 o_eyetv = [[VLCEyeTVController alloc] init];
270 /* announce our launch to a potential eyetv plugin */
271 [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"VLCOSXGUIInit"
272 object: @"VLCEyeTVSupport"
274 deliverImmediately: YES];
276 return _o_sharedMainInstance;
279 - (void)setIntf: (intf_thread_t *)p_mainintf {
283 - (intf_thread_t *)getIntf {
289 unsigned int i_key = 0;
290 playlist_t *p_playlist;
293 /* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
294 if( nib_main_loaded ) return;
298 [o_window setExcludedFromWindowsMenu: YES];
299 [o_msgs_panel setExcludedFromWindowsMenu: YES];
300 [o_msgs_panel setDelegate: self];
302 /* In code and not in Nib for 10.4 compat */
303 NSToolbar * toolbar = [[[NSToolbar alloc] initWithIdentifier:@"mainControllerToolbar"] autorelease];
304 [toolbar setDelegate:self];
305 [toolbar setShowsBaselineSeparator:NO];
306 [toolbar setAllowsUserCustomization:NO];
307 [toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
308 [toolbar setAutosavesConfiguration:YES];
309 [o_window setToolbar:toolbar];
311 i_key = config_GetInt( p_intf, "key-quit" );
312 [o_mi_quit setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
313 [o_mi_quit setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
314 i_key = config_GetInt( p_intf, "key-play-pause" );
315 [o_mi_play setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
316 [o_mi_play setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
317 i_key = config_GetInt( p_intf, "key-stop" );
318 [o_mi_stop setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
319 [o_mi_stop setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
320 i_key = config_GetInt( p_intf, "key-faster" );
321 [o_mi_faster setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
322 [o_mi_faster setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
323 i_key = config_GetInt( p_intf, "key-slower" );
324 [o_mi_slower setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
325 [o_mi_slower setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
326 i_key = config_GetInt( p_intf, "key-prev" );
327 [o_mi_previous setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
328 [o_mi_previous setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
329 i_key = config_GetInt( p_intf, "key-next" );
330 [o_mi_next setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
331 [o_mi_next setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
332 i_key = config_GetInt( p_intf, "key-jump+short" );
333 [o_mi_fwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
334 [o_mi_fwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
335 i_key = config_GetInt( p_intf, "key-jump-short" );
336 [o_mi_bwd setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
337 [o_mi_bwd setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
338 i_key = config_GetInt( p_intf, "key-jump+medium" );
339 [o_mi_fwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
340 [o_mi_fwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
341 i_key = config_GetInt( p_intf, "key-jump-medium" );
342 [o_mi_bwd1m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
343 [o_mi_bwd1m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
344 i_key = config_GetInt( p_intf, "key-jump+long" );
345 [o_mi_fwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
346 [o_mi_fwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
347 i_key = config_GetInt( p_intf, "key-jump-long" );
348 [o_mi_bwd5m setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
349 [o_mi_bwd5m setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
350 i_key = config_GetInt( p_intf, "key-vol-up" );
351 [o_mi_vol_up setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
352 [o_mi_vol_up setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
353 i_key = config_GetInt( p_intf, "key-vol-down" );
354 [o_mi_vol_down setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
355 [o_mi_vol_down setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
356 i_key = config_GetInt( p_intf, "key-vol-mute" );
357 [o_mi_mute setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
358 [o_mi_mute setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
359 i_key = config_GetInt( p_intf, "key-fullscreen" );
360 [o_mi_fullscreen setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
361 [o_mi_fullscreen setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
362 i_key = config_GetInt( p_intf, "key-snapshot" );
363 [o_mi_snapshot setKeyEquivalent: [NSString stringWithFormat:@"%C", VLCKeyToCocoa( i_key )]];
364 [o_mi_snapshot setKeyEquivalentModifierMask: VLCModifiersToCocoa(i_key)];
366 var_Create( p_intf, "intf-change", VLC_VAR_BOOL );
368 [self setSubmenusEnabled: FALSE];
369 [o_volumeslider setEnabled: YES];
370 [self manageVolumeSlider];
371 [o_window setDelegate: self];
373 b_restore_size = false;
375 // Set that here as IB seems to be buggy
376 [o_window setContentMinSize:NSMakeSize(338., 30.)];
378 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
380 b_small_window = YES;
381 [o_window setFrame: NSMakeRect( [o_window frame].origin.x,
382 [o_window frame].origin.y, [o_window frame].size.width,
383 [o_window minSize].height ) display: YES animate:YES];
384 [o_playlist_view setAutoresizesSubviews: NO];
389 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
390 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
391 [o_playlist_view setNeedsDisplay:YES];
392 [o_playlist_view setAutoresizesSubviews: YES];
393 [[o_window contentView] addSubview: o_playlist_view];
396 [self updateTogglePlaylistState];
398 o_size_with_playlist = [o_window contentRectForFrameRect:[o_window frame]].size;
400 p_playlist = pl_Hold( p_intf );
402 var_Create( p_playlist, "fullscreen", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
405 var_AddCallback( p_playlist, "fullscreen", FullscreenChanged, self);
406 var_AddCallback( p_intf->p_libvlc, "intf-show", ShowController, self);
408 pl_Release( p_intf );
410 var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
411 var_AddCallback( p_intf, "interaction", InteractCallback, self );
412 p_intf->b_interaction = true;
414 /* update the playmode stuff */
415 p_intf->p_sys->b_playmode_update = true;
417 [[NSNotificationCenter defaultCenter] addObserver: self
418 selector: @selector(refreshVoutDeviceMenu:)
419 name: NSApplicationDidChangeScreenParametersNotification
422 o_img_play = [NSImage imageNamed: @"play"];
423 o_img_pause = [NSImage imageNamed: @"pause"];
425 [self controlTintChanged];
427 [[NSNotificationCenter defaultCenter] addObserver: self
428 selector: @selector( controlTintChanged )
429 name: NSControlTintDidChangeNotification
432 nib_main_loaded = TRUE;
435 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
437 o_msg_lock = [[NSLock alloc] init];
438 o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
440 /* FIXME: don't poll */
441 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
442 target: self selector: @selector(manageIntf:)
443 userInfo: nil repeats: FALSE] retain];
445 /* Note: we use the pthread API to support pre-10.5 */
446 pthread_create( &manage_thread, NULL, ManageThread, self );
448 [o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
449 var: "intf-add" selector: @selector(toggleVar:)];
451 /* check whether the user runs a valid version of OSX; alert is auto-released */
452 if( MACOS_VERSION < 10.4f )
456 ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is not supported")
457 defaultButton: _NS("Quit")
458 alternateButton: NULL
460 informativeTextWithFormat: _NS("VLC media player requires Mac OS X 10.4 or higher.")];
461 [ourAlert setAlertStyle: NSCriticalAlertStyle];
462 i_returnValue = [ourAlert runModal];
463 [NSApp terminate: self];
466 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
469 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
471 [self _removeOldPreferences];
474 /* Check for update silently on startup */
475 if( !nib_update_loaded )
476 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
478 if([o_update shouldCheckForUpdate])
479 [NSThread detachNewThreadSelector:@selector(checkForUpdate) toTarget:o_update withObject:nil];
482 /* Handle sleep notification */
483 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(computerWillSleep:)
484 name:NSWorkspaceWillSleepNotification object:nil];
486 [NSThread detachNewThreadSelector:@selector(lookForCrashLog) toTarget:self withObject:nil];
491 [o_window setTitle: _NS("VLC media player")];
492 [self setScrollField:_NS("VLC media player") stopAfter:-1];
494 /* button controls */
495 [o_btn_prev setToolTip: _NS("Previous")];
496 [o_btn_rewind setToolTip: _NS("Rewind")];
497 [o_btn_play setToolTip: _NS("Play")];
498 [o_btn_stop setToolTip: _NS("Stop")];
499 [o_btn_ff setToolTip: _NS("Fast Forward")];
500 [o_btn_next setToolTip: _NS("Next")];
501 [o_btn_fullscreen setToolTip: _NS("Fullscreen")];
502 [o_volumeslider setToolTip: _NS("Volume")];
503 [o_timeslider setToolTip: _NS("Position")];
504 [o_btn_playlist setToolTip: _NS("Playlist")];
507 [o_msgs_panel setTitle: _NS("Messages")];
508 [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog...")];
511 [o_mi_about setTitle: [_NS("About VLC media player") \
512 stringByAppendingString: @"..."]];
513 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
514 [o_mi_prefs setTitle: _NS("Preferences...")];
515 [o_mi_add_intf setTitle: _NS("Add Interface")];
516 [o_mu_add_intf setTitle: _NS("Add Interface")];
517 [o_mi_services setTitle: _NS("Services")];
518 [o_mi_hide setTitle: _NS("Hide VLC")];
519 [o_mi_hide_others setTitle: _NS("Hide Others")];
520 [o_mi_show_all setTitle: _NS("Show All")];
521 [o_mi_quit setTitle: _NS("Quit VLC")];
523 [o_mu_file setTitle: _ANS("1:File")];
524 [o_mi_open_generic setTitle: _NS("Open File...")];
525 [o_mi_open_file setTitle: _NS("Quick Open File...")];
526 [o_mi_open_disc setTitle: _NS("Open Disc...")];
527 [o_mi_open_net setTitle: _NS("Open Network...")];
528 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
529 [o_mi_open_recent setTitle: _NS("Open Recent")];
530 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
531 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
533 [o_mu_edit setTitle: _NS("Edit")];
534 [o_mi_cut setTitle: _NS("Cut")];
535 [o_mi_copy setTitle: _NS("Copy")];
536 [o_mi_paste setTitle: _NS("Paste")];
537 [o_mi_clear setTitle: _NS("Clear")];
538 [o_mi_select_all setTitle: _NS("Select All")];
540 [o_mu_controls setTitle: _NS("Playback")];
541 [o_mi_play setTitle: _NS("Play")];
542 [o_mi_stop setTitle: _NS("Stop")];
543 [o_mi_faster setTitle: _NS("Faster")];
544 [o_mi_slower setTitle: _NS("Slower")];
545 [o_mi_previous setTitle: _NS("Previous")];
546 [o_mi_next setTitle: _NS("Next")];
547 [o_mi_random setTitle: _NS("Random")];
548 [o_mi_repeat setTitle: _NS("Repeat One")];
549 [o_mi_loop setTitle: _NS("Repeat All")];
550 [o_mi_fwd setTitle: _NS("Step Forward")];
551 [o_mi_bwd setTitle: _NS("Step Backward")];
553 [o_mi_program setTitle: _NS("Program")];
554 [o_mu_program setTitle: _NS("Program")];
555 [o_mi_title setTitle: _NS("Title")];
556 [o_mu_title setTitle: _NS("Title")];
557 [o_mi_chapter setTitle: _NS("Chapter")];
558 [o_mu_chapter setTitle: _NS("Chapter")];
560 [o_mu_audio setTitle: _NS("Audio")];
561 [o_mi_vol_up setTitle: _NS("Volume Up")];
562 [o_mi_vol_down setTitle: _NS("Volume Down")];
563 [o_mi_mute setTitle: _NS("Mute")];
564 [o_mi_audiotrack setTitle: _NS("Audio Track")];
565 [o_mu_audiotrack setTitle: _NS("Audio Track")];
566 [o_mi_channels setTitle: _NS("Audio Channels")];
567 [o_mu_channels setTitle: _NS("Audio Channels")];
568 [o_mi_device setTitle: _NS("Audio Device")];
569 [o_mu_device setTitle: _NS("Audio Device")];
570 [o_mi_visual setTitle: _NS("Visualizations")];
571 [o_mu_visual setTitle: _NS("Visualizations")];
573 [o_mu_video setTitle: _NS("Video")];
574 [o_mi_half_window setTitle: _NS("Half Size")];
575 [o_mi_normal_window setTitle: _NS("Normal Size")];
576 [o_mi_double_window setTitle: _NS("Double Size")];
577 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
578 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
579 [o_mi_floatontop setTitle: _NS("Float on Top")];
580 [o_mi_snapshot setTitle: _NS("Snapshot")];
581 [o_mi_videotrack setTitle: _NS("Video Track")];
582 [o_mu_videotrack setTitle: _NS("Video Track")];
583 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
584 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
585 [o_mi_crop setTitle: _NS("Crop")];
586 [o_mu_crop setTitle: _NS("Crop")];
587 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
588 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
589 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
590 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
591 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
592 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
593 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
594 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
595 [o_mi_teletext setTitle: _NS("Teletext")];
596 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
597 [o_mi_teletext_index setTitle: _NS("Index")];
598 [o_mi_teletext_red setTitle: _NS("Red")];
599 [o_mi_teletext_green setTitle: _NS("Green")];
600 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
601 [o_mi_teletext_blue setTitle: _NS("Blue")];
603 [o_mu_window setTitle: _NS("Window")];
604 [o_mi_minimize setTitle: _NS("Minimize Window")];
605 [o_mi_close_window setTitle: _NS("Close Window")];
606 [o_mi_controller setTitle: _NS("Controller...")];
607 [o_mi_equalizer setTitle: _NS("Equalizer...")];
608 [o_mi_extended setTitle: _NS("Extended Controls...")];
609 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
610 [o_mi_playlist setTitle: _NS("Playlist...")];
611 [o_mi_info setTitle: _NS("Media Information...")];
612 [o_mi_messages setTitle: _NS("Messages...")];
613 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
615 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
617 [o_mu_help setTitle: _NS("Help")];
618 [o_mi_help setTitle: _NS("VLC media player Help...")];
619 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
620 [o_mi_license setTitle: _NS("License")];
621 [o_mi_documentation setTitle: _NS("Online Documentation...")];
622 [o_mi_website setTitle: _NS("VideoLAN Website...")];
623 [o_mi_donation setTitle: _NS("Make a donation...")];
624 [o_mi_forum setTitle: _NS("Online Forum...")];
627 [o_dmi_play setTitle: _NS("Play")];
628 [o_dmi_stop setTitle: _NS("Stop")];
629 [o_dmi_next setTitle: _NS("Next")];
630 [o_dmi_previous setTitle: _NS("Previous")];
631 [o_dmi_mute setTitle: _NS("Mute")];
634 [o_vmi_play setTitle: _NS("Play")];
635 [o_vmi_stop setTitle: _NS("Stop")];
636 [o_vmi_prev setTitle: _NS("Previous")];
637 [o_vmi_next setTitle: _NS("Next")];
638 [o_vmi_volup setTitle: _NS("Volume Up")];
639 [o_vmi_voldown setTitle: _NS("Volume Down")];
640 [o_vmi_mute setTitle: _NS("Mute")];
641 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
642 [o_vmi_snapshot setTitle: _NS("Snapshot")];
644 /* crash reporter panel */
645 [o_crashrep_send_btn setTitle: _NS("Send")];
646 [o_crashrep_dontSend_btn setTitle: _NS("Don't Send")];
647 [o_crashrep_title_txt setStringValue: _NS("VLC crashed previously")];
648 [o_crashrep_win setTitle: _NS("VLC crashed previously")];
649 [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, ...")];
650 [o_crashrep_includeEmail_ckb setTitle: _NS("I agree to be possibly contacted about this bugreport.")];
651 [o_crashrep_includeEmail_txt setStringValue: _NS("Only your default E-Mail address will be submitted, including no further information.")];
655 #pragma mark Termination
657 - (void)applicationWillTerminate:(NSNotification *)notification
659 playlist_t * p_playlist;
660 vout_thread_t * p_vout;
661 int returnedValue = 0;
663 msg_Dbg( p_intf, "Terminating" );
665 /* Make sure the manage_thread won't call -terminate: again */
666 pthread_cancel( manage_thread );
668 /* Make sure the intf object is getting killed */
669 vlc_object_kill( p_intf );
671 /* Make sure our manage_thread ends */
672 pthread_join( manage_thread, NULL );
674 /* Make sure the interfaceTimer is destroyed */
675 [interfaceTimer invalidate];
676 [interfaceTimer release];
677 interfaceTimer = nil;
679 /* make sure that the current volume is saved */
680 config_PutInt( p_intf->p_libvlc, "volume", i_lastShownVolume );
682 /* save the prefs if they were changed in the extended panel */
683 if(o_extended && [o_extended getConfigChanged])
685 [o_extended savePrefs];
688 p_intf->b_interaction = false;
689 var_DelCallback( p_intf, "interaction", InteractCallback, self );
691 /* remove global observer watching for vout device changes correctly */
692 [[NSNotificationCenter defaultCenter] removeObserver: self];
696 /* release some other objects here, because it isn't sure whether dealloc
697 * will be called later on */
699 if( nib_about_loaded )
702 if( nib_prefs_loaded )
708 if( nib_open_loaded )
711 if( nib_extended_loaded )
713 [o_extended release];
716 if( nib_bookmarks_loaded )
717 [o_bookmarks release];
725 if( nib_wizard_loaded )
728 [crashLogURLConnection cancel];
729 [crashLogURLConnection release];
731 [o_embedded_list release];
732 [o_interaction_list release];
735 [o_img_pause_pressed release];
736 [o_img_play_pressed release];
737 [o_img_pause release];
738 [o_img_play release];
740 [o_msg_arr removeAllObjects];
743 [o_msg_lock release];
745 /* write cached user defaults to disk */
746 [[NSUserDefaults standardUserDefaults] synchronize];
748 /* Kill the playlist, so that it doesn't accept new request
749 * such as the play request from vlc.c (we are a blocking interface). */
750 p_playlist = pl_Hold( p_intf );
751 vlc_object_kill( p_playlist );
752 pl_Release( p_intf );
754 vlc_object_kill( p_intf->p_libvlc );
758 /* Go back to Run() and make libvlc exit properly */
760 longjmp( jmpbuffer, 1 );
765 #pragma mark Toolbar delegate
767 /* Our item identifiers */
768 static NSString * VLCToolbarMediaControl = @"VLCToolbarMediaControl";
770 - (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
772 return [NSArray arrayWithObjects:
773 // NSToolbarCustomizeToolbarItemIdentifier,
774 // NSToolbarFlexibleSpaceItemIdentifier,
775 // NSToolbarSpaceItemIdentifier,
776 // NSToolbarSeparatorItemIdentifier,
777 VLCToolbarMediaControl,
781 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
783 return [NSArray arrayWithObjects:
784 VLCToolbarMediaControl,
788 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
790 NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
793 if( [itemIdentifier isEqual: VLCToolbarMediaControl] )
795 [toolbarItem setLabel:@"Media Controls"];
796 [toolbarItem setPaletteLabel:@"Media Controls"];
798 NSSize size = toolbarMediaControl.frame.size;
799 [toolbarItem setView:toolbarMediaControl];
800 [toolbarItem setMinSize:size];
802 [toolbarItem setMaxSize:size];
804 // Hack: For some reason we need to make sure
805 // that the those element are on top
806 // Add them again will put them frontmost
807 [toolbarMediaControl addSubview:o_scrollfield];
808 [toolbarMediaControl addSubview:o_timeslider];
809 [toolbarMediaControl addSubview:o_timefield];
810 [toolbarMediaControl addSubview:o_main_pgbar];
812 /* TODO: setup a menu */
816 /* itemIdentifier referred to a toolbar item that is not
817 * provided or supported by us or Cocoa
818 * Returning nil will inform the toolbar
819 * that this kind of item is not supported */
826 #pragma mark Other notification
828 - (void)controlTintChanged
832 if( [o_btn_play alternateImage] == o_img_play_pressed )
835 if( [NSColor currentControlTint] == NSGraphiteControlTint )
837 o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];
838 o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];
840 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];
841 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];
842 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];
843 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];
844 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];
845 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];
846 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];
847 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];
851 o_img_play_pressed = [NSImage imageNamed: @"play_blue"];
852 o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];
854 [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];
855 [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];
856 [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];
857 [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];
858 [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];
859 [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];
860 [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];
861 [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];
865 [o_btn_play setAlternateImage: o_img_play_pressed];
867 [o_btn_play setAlternateImage: o_img_pause_pressed];
870 /* Listen to the remote in exclusive mode, only when VLC is the active
872 - (void)applicationDidBecomeActive:(NSNotification *)aNotification
874 [o_remote startListening: self];
876 - (void)applicationDidResignActive:(NSNotification *)aNotification
878 [o_remote stopListening: self];
881 /* Triggered when the computer goes to sleep */
882 - (void)computerWillSleep: (NSNotification *)notification
885 if( p_intf->p_sys->i_play_status == PLAYING_S )
888 val.i_int = config_GetInt( p_intf, "key-play-pause" );
889 var_Set( p_intf->p_libvlc, "key-pressed", val );
894 #pragma mark File opening
896 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
898 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
899 NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];
901 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];
903 [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];
908 /* When user click in the Dock icon our double click in the finder */
909 - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows
911 if(!hasVisibleWindows)
912 [o_window makeKeyAndOrderFront:self];
918 #pragma mark Apple Remote Control
920 /* Helper method for the remote control interface in order to trigger forward/backward and volume
921 increase/decrease as long as the user holds the left/right, plus/minus button */
922 - (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber
924 if(b_remote_button_hold)
926 switch([buttonIdentifierNumber intValue])
928 case kRemoteButtonRight_Hold:
929 [o_controls forward: self];
931 case kRemoteButtonLeft_Hold:
932 [o_controls backward: self];
934 case kRemoteButtonVolume_Plus_Hold:
935 [o_controls volumeUp: self];
937 case kRemoteButtonVolume_Minus_Hold:
938 [o_controls volumeDown: self];
941 if(b_remote_button_hold)
944 [self performSelector:@selector(executeHoldActionForRemoteButton:)
945 withObject:buttonIdentifierNumber
951 /* Apple Remote callback */
952 - (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier
953 pressedDown: (BOOL) pressedDown
954 clickCount: (unsigned int) count
956 switch( buttonIdentifier )
958 case kRemoteButtonPlay:
960 [o_controls toogleFullscreen:self];
962 [o_controls play: self];
965 case kRemoteButtonVolume_Plus:
966 [o_controls volumeUp: self];
968 case kRemoteButtonVolume_Minus:
969 [o_controls volumeDown: self];
971 case kRemoteButtonRight:
972 [o_controls next: self];
974 case kRemoteButtonLeft:
975 [o_controls prev: self];
977 case kRemoteButtonRight_Hold:
978 case kRemoteButtonLeft_Hold:
979 case kRemoteButtonVolume_Plus_Hold:
980 case kRemoteButtonVolume_Minus_Hold:
981 /* simulate an event as long as the user holds the button */
982 b_remote_button_hold = pressedDown;
985 NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];
986 [self performSelector:@selector(executeHoldActionForRemoteButton:)
987 withObject:buttonIdentifierNumber];
990 case kRemoteButtonMenu:
991 [o_controls showPosition: self];
994 /* Add here whatever you want other buttons to do */
1000 #pragma mark String utility
1001 // FIXME: this has nothing to do here
1003 - (NSString *)localizedString:(const char *)psz
1005 NSString * o_str = nil;
1009 o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];
1013 msg_Err( VLCIntf, "could not translate: %s", psz );
1019 msg_Warn( VLCIntf, "can't translate empty strings" );
1028 - (char *)delocalizeString:(NSString *)id
1030 NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1031 allowLossyConversion: NO];
1036 o_data = [id dataUsingEncoding: NSUTF8StringEncoding
1037 allowLossyConversion: YES];
1038 psz_string = malloc( [o_data length] + 1 );
1039 [o_data getBytes: psz_string];
1040 psz_string[ [o_data length] ] = '\0';
1041 msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",
1046 psz_string = malloc( [o_data length] + 1 );
1047 [o_data getBytes: psz_string];
1048 psz_string[ [o_data length] ] = '\0';
1054 /* i_width is in pixels */
1055 - (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width
1057 NSMutableString *o_wrapped;
1058 NSString *o_out_string;
1059 NSRange glyphRange, effectiveRange, charRange;
1060 NSRect lineFragmentRect;
1061 unsigned glyphIndex, breaksInserted = 0;
1063 NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string
1064 attributes: [NSDictionary dictionaryWithObjectsAndKeys:
1065 [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];
1066 NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];
1067 NSTextContainer *o_container = [[NSTextContainer alloc]
1068 initWithContainerSize: NSMakeSize(i_width, 2000)];
1070 [o_layout_manager addTextContainer: o_container];
1071 [o_container release];
1072 [o_storage addLayoutManager: o_layout_manager];
1073 [o_layout_manager release];
1075 o_wrapped = [o_in_string mutableCopy];
1076 glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];
1078 for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;
1079 glyphIndex += effectiveRange.length) {
1080 lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex
1081 effectiveRange: &effectiveRange];
1082 charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange
1083 actualGlyphRange: &effectiveRange];
1084 if([o_wrapped lineRangeForRange:
1085 NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {
1086 [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];
1090 o_out_string = [NSString stringWithString: o_wrapped];
1091 [o_wrapped release];
1092 [o_storage release];
1094 return o_out_string;
1099 #pragma mark Key Shortcuts
1104 unsigned int i_vlckey;
1105 } nskeys_to_vlckeys[] =
1107 { NSUpArrowFunctionKey, KEY_UP },
1108 { NSDownArrowFunctionKey, KEY_DOWN },
1109 { NSLeftArrowFunctionKey, KEY_LEFT },
1110 { NSRightArrowFunctionKey, KEY_RIGHT },
1111 { NSF1FunctionKey, KEY_F1 },
1112 { NSF2FunctionKey, KEY_F2 },
1113 { NSF3FunctionKey, KEY_F3 },
1114 { NSF4FunctionKey, KEY_F4 },
1115 { NSF5FunctionKey, KEY_F5 },
1116 { NSF6FunctionKey, KEY_F6 },
1117 { NSF7FunctionKey, KEY_F7 },
1118 { NSF8FunctionKey, KEY_F8 },
1119 { NSF9FunctionKey, KEY_F9 },
1120 { NSF10FunctionKey, KEY_F10 },
1121 { NSF11FunctionKey, KEY_F11 },
1122 { NSF12FunctionKey, KEY_F12 },
1123 { NSInsertFunctionKey, KEY_INSERT },
1124 { NSHomeFunctionKey, KEY_HOME },
1125 { NSEndFunctionKey, KEY_END },
1126 { NSPageUpFunctionKey, KEY_PAGEUP },
1127 { NSPageDownFunctionKey, KEY_PAGEDOWN },
1128 { NSMenuFunctionKey, KEY_MENU },
1129 { NSTabCharacter, KEY_TAB },
1130 { NSCarriageReturnCharacter, KEY_ENTER },
1131 { NSEnterCharacter, KEY_ENTER },
1132 { NSBackspaceCharacter, KEY_BACKSPACE },
1133 { (unichar) ' ', KEY_SPACE },
1134 { (unichar) 0x1b, KEY_ESC },
1138 static unichar VLCKeyToCocoa( unsigned int i_key )
1142 for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )
1144 if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )
1146 return nskeys_to_vlckeys[i].i_nskey;
1149 return (unichar)(i_key & ~KEY_MODIFIER);
1152 unsigned int CocoaKeyToVLC( unichar i_key )
1156 for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )
1158 if( nskeys_to_vlckeys[i].i_nskey == i_key )
1160 return nskeys_to_vlckeys[i].i_vlckey;
1163 return (unsigned int)i_key;
1166 static unsigned int VLCModifiersToCocoa( unsigned int i_key )
1168 unsigned int new = 0;
1169 if( i_key & KEY_MODIFIER_COMMAND )
1170 new |= NSCommandKeyMask;
1171 if( i_key & KEY_MODIFIER_ALT )
1172 new |= NSAlternateKeyMask;
1173 if( i_key & KEY_MODIFIER_SHIFT )
1174 new |= NSShiftKeyMask;
1175 if( i_key & KEY_MODIFIER_CTRL )
1176 new |= NSControlKeyMask;
1180 /*****************************************************************************
1181 * hasDefinedShortcutKey: Check to see if the key press is a defined VLC
1182 * shortcut key. If it is, pass it off to VLC for handling and return YES,
1183 * otherwise ignore it and return NO (where it will get handled by Cocoa).
1184 *****************************************************************************/
1185 - (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
1189 unsigned int i_pressed_modifiers = 0;
1190 struct hotkey *p_hotkeys;
1194 p_hotkeys = p_intf->p_libvlc->p_hotkeys;
1196 i_pressed_modifiers = [o_event modifierFlags];
1198 if( i_pressed_modifiers & NSShiftKeyMask )
1199 val.i_int |= KEY_MODIFIER_SHIFT;
1200 if( i_pressed_modifiers & NSControlKeyMask )
1201 val.i_int |= KEY_MODIFIER_CTRL;
1202 if( i_pressed_modifiers & NSAlternateKeyMask )
1203 val.i_int |= KEY_MODIFIER_ALT;
1204 if( i_pressed_modifiers & NSCommandKeyMask )
1205 val.i_int |= KEY_MODIFIER_COMMAND;
1207 key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
1211 case NSDeleteCharacter:
1212 case NSDeleteFunctionKey:
1213 case NSDeleteCharFunctionKey:
1214 case NSBackspaceCharacter:
1215 case NSUpArrowFunctionKey:
1216 case NSDownArrowFunctionKey:
1217 case NSRightArrowFunctionKey:
1218 case NSLeftArrowFunctionKey:
1219 case NSEnterCharacter:
1220 case NSCarriageReturnCharacter:
1224 val.i_int |= CocoaKeyToVLC( key );
1226 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
1228 if( p_hotkeys[i].i_key == val.i_int )
1230 var_Set( p_intf->p_libvlc, "key-pressed", val );
1239 #pragma mark Other objects getters
1240 // FIXME: this is ugly and does not respect cocoa naming scheme
1250 - (id)getSimplePreferences
1255 if( !nib_prefs_loaded )
1256 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1261 - (id)getPreferences
1266 if( !nib_prefs_loaded )
1267 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
1309 - (id)getEmbeddedList
1311 if( o_embedded_list )
1312 return o_embedded_list;
1317 - (id)getInteractionList
1319 if( o_interaction_list )
1320 return o_interaction_list;
1325 - (id)getMainIntfPgbar
1328 return o_main_pgbar;
1333 - (id)getControllerWindow
1345 - (id)getEyeTVController
1354 #pragma mark Polling
1356 /*****************************************************************************
1357 * ManageThread: An ugly thread that polls
1358 *****************************************************************************/
1359 static void * ManageThread( void *user_data )
1361 id self = user_data;
1368 struct manage_cleanup_stack {
1369 intf_thread_t * p_intf;
1370 input_thread_t ** p_input;
1371 playlist_t * p_playlist;
1375 static void * manage_cleanup( void * args )
1377 struct manage_cleanup_stack * manage_cleanup_stack = args;
1378 intf_thread_t * p_intf = manage_cleanup_stack->p_intf;
1379 input_thread_t * p_input = *manage_cleanup_stack->p_input;
1380 id self = manage_cleanup_stack->self;
1381 playlist_t * p_playlist = manage_cleanup_stack->p_playlist;
1383 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1384 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1385 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1386 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
1387 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1389 pl_Release( p_intf );
1391 if( p_input ) vlc_object_release( p_input );
1397 playlist_t * p_playlist;
1398 input_thread_t * p_input = NULL;
1400 /* new thread requires a new pool */
1402 vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
1404 p_playlist = pl_Hold( p_intf );
1406 var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
1407 var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
1408 var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
1409 var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
1410 var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
1412 struct manage_cleanup_stack stack = { p_intf, &p_input, p_playlist, self };
1413 pthread_cleanup_push(manage_cleanup, &stack);
1417 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
1418 vlc_mutex_lock( &p_intf->change_lock );
1422 p_input = playlist_CurrentInput( p_playlist );
1424 /* Refresh the interface */
1427 msg_Dbg( p_intf, "input has changed, refreshing interface" );
1428 p_intf->p_sys->b_input_update = true;
1431 else if( !vlc_object_alive (p_input) || p_input->b_dead )
1434 p_intf->p_sys->b_intf_update = true;
1435 p_intf->p_sys->i_play_status = END_S;
1436 msg_Dbg( p_intf, "input has stopped, refreshing interface" );
1437 vlc_object_release( p_input );
1440 else if( cachedInputState != input_GetState( p_input ) )
1442 p_intf->p_sys->b_intf_update = true;
1445 /* Manage volume status */
1446 [self manageVolumeSlider];
1448 vlc_mutex_unlock( &p_intf->change_lock );
1450 msleep( INTF_IDLE_SLEEP );
1455 pthread_cleanup_pop(1);
1457 msg_Dbg( p_intf, "Killing the Mac OS X module" );
1459 /* We are dead, terminate */
1460 [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
1463 - (void)manageVolumeSlider
1465 audio_volume_t i_volume;
1466 aout_VolumeGet( p_intf, &i_volume );
1468 if( i_volume != i_lastShownVolume )
1470 i_lastShownVolume = i_volume;
1471 p_intf->p_sys->b_volume_update = TRUE;
1475 - (void)manageIntf:(NSTimer *)o_timer
1478 playlist_t * p_playlist;
1479 input_thread_t * p_input;
1481 if( p_intf->p_sys->b_input_update )
1483 /* Called when new input is opened */
1484 p_intf->p_sys->b_current_title_update = true;
1485 p_intf->p_sys->b_intf_update = true;
1486 p_intf->p_sys->b_input_update = false;
1487 [self setupMenus]; /* Make sure input menu is up to date */
1489 if( p_intf->p_sys->b_intf_update )
1491 bool b_input = false;
1492 bool b_plmul = false;
1493 bool b_control = false;
1494 bool b_seekable = false;
1495 bool b_chapters = false;
1497 playlist_t * p_playlist = pl_Hold( p_intf );
1498 /* TODO: fix i_size use */
1499 b_plmul = p_playlist->items.i_size > 1;
1501 p_input = playlist_CurrentInput( p_playlist );
1502 bool b_buffering = NO;
1504 if( ( b_input = ( p_input != NULL ) ) )
1506 /* seekable streams */
1507 cachedInputState = input_GetState( p_input );
1508 if ( cachedInputState == INIT_S ||
1509 cachedInputState == OPENING_S ||
1510 cachedInputState == BUFFERING_S )
1515 /* seekable streams */
1516 b_seekable = var_GetBool( p_input, "can-seek" );
1518 /* check whether slow/fast motion is possible */
1519 b_control = p_input->b_can_pace_control;
1521 /* chapters & titles */
1522 //b_chapters = p_input->stream.i_area_nb > 1;
1523 vlc_object_release( p_input );
1525 pl_Release( p_intf );
1529 [o_main_pgbar startAnimation:self];
1530 [o_main_pgbar setIndeterminate:YES];
1531 [o_main_pgbar setHidden:NO];
1535 [o_main_pgbar stopAnimation:self];
1536 [o_main_pgbar setHidden:YES];
1539 [o_btn_stop setEnabled: b_input];
1540 [o_btn_ff setEnabled: b_seekable];
1541 [o_btn_rewind setEnabled: b_seekable];
1542 [o_btn_prev setEnabled: (b_plmul || b_chapters)];
1543 [o_btn_next setEnabled: (b_plmul || b_chapters)];
1545 [o_timeslider setFloatValue: 0.0];
1546 [o_timeslider setEnabled: b_seekable];
1547 [o_timefield setStringValue: @"00:00"];
1548 [[[self getControls] getFSPanel] setStreamPos: 0 andTime: @"00:00"];
1549 [[[self getControls] getFSPanel] setSeekable: b_seekable];
1551 [o_embedded_window setSeekable: b_seekable];
1553 p_intf->p_sys->b_current_title_update = true;
1555 p_intf->p_sys->b_intf_update = false;
1558 if( p_intf->p_sys->b_playmode_update )
1560 [o_playlist playModeUpdated];
1561 p_intf->p_sys->b_playmode_update = false;
1563 if( p_intf->p_sys->b_playlist_update )
1565 [o_playlist playlistUpdated];
1566 p_intf->p_sys->b_playlist_update = false;
1569 if( p_intf->p_sys->b_fullscreen_update )
1571 p_intf->p_sys->b_fullscreen_update = false;
1574 if( p_intf->p_sys->b_intf_show )
1576 [o_window makeKeyAndOrderFront: self];
1578 p_intf->p_sys->b_intf_show = false;
1581 p_input = pl_CurrentInput( p_intf );
1582 if( p_input && vlc_object_alive (p_input) )
1586 if( p_intf->p_sys->b_current_title_update )
1589 input_item_t * p_item = input_GetItem( p_input );
1590 char * name = input_item_GetNowPlaying( p_item );
1593 name = input_item_GetName( p_item );
1595 aString = [NSString stringWithUTF8String:name];
1599 [self setScrollField: aString stopAfter:-1];
1600 [[[self getControls] getFSPanel] setStreamTitle: aString];
1602 [[o_controls voutView] updateTitle];
1604 [o_playlist updateRowSelection];
1605 p_intf->p_sys->b_current_title_update = FALSE;
1608 if( [o_timeslider isEnabled] )
1610 /* Update the slider */
1614 char psz_time[MSTRTIME_MAX_SIZE];
1617 var_Get( p_input, "position", &pos );
1618 f_updated = 10000. * pos.f_float;
1619 [o_timeslider setFloatValue: f_updated];
1621 var_Get( p_input, "time", &time );
1623 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1625 [o_timefield setStringValue: o_time];
1626 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1627 [o_embedded_window setTime: o_time position: f_updated];
1630 /* Manage Playing status */
1631 var_Get( p_input, "state", &val );
1632 if( p_intf->p_sys->i_play_status != val.i_int )
1634 p_intf->p_sys->i_play_status = val.i_int;
1635 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1636 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1638 vlc_object_release( p_input );
1642 vlc_object_release( p_input );
1646 p_intf->p_sys->i_play_status = END_S;
1647 [self playStatusUpdated: p_intf->p_sys->i_play_status];
1648 [o_embedded_window playStatusUpdated: p_intf->p_sys->i_play_status];
1649 [self setSubmenusEnabled: FALSE];
1652 if( p_intf->p_sys->b_volume_update )
1655 int i_volume_step = 0;
1656 o_text = [NSString stringWithFormat: _NS("Volume: %d%%"), i_lastShownVolume * 400 / AOUT_VOLUME_MAX];
1657 if( i_lastShownVolume != -1 )
1658 [self setScrollField:o_text stopAfter:1000000];
1659 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1660 [o_volumeslider setFloatValue: (float)i_lastShownVolume / i_volume_step];
1661 [o_volumeslider setEnabled: TRUE];
1662 [[[self getControls] getFSPanel] setVolumeLevel: (float)i_lastShownVolume / i_volume_step];
1663 p_intf->p_sys->b_mute = ( i_lastShownVolume == 0 );
1664 p_intf->p_sys->b_volume_update = FALSE;
1668 [self updateMessageArray];
1670 if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
1671 [self resetScrollField];
1673 [interfaceTimer autorelease];
1675 interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.3
1676 target: self selector: @selector(manageIntf:)
1677 userInfo: nil repeats: FALSE] retain];
1681 #pragma mark Interface update
1685 playlist_t * p_playlist = pl_Hold( p_intf );
1686 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1687 if( p_input != NULL )
1689 [o_controls setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
1690 var: "program" selector: @selector(toggleVar:)];
1692 [o_controls setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
1693 var: "title" selector: @selector(toggleVar:)];
1695 [o_controls setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
1696 var: "chapter" selector: @selector(toggleVar:)];
1698 [o_controls setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
1699 var: "audio-es" selector: @selector(toggleVar:)];
1701 [o_controls setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
1702 var: "video-es" selector: @selector(toggleVar:)];
1704 [o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
1705 var: "spu-es" selector: @selector(toggleVar:)];
1707 aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1709 if( p_aout != NULL )
1711 [o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
1712 var: "audio-channels" selector: @selector(toggleVar:)];
1714 [o_controls setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
1715 var: "audio-device" selector: @selector(toggleVar:)];
1717 [o_controls setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
1718 var: "visual" selector: @selector(toggleVar:)];
1719 vlc_object_release( (vlc_object_t *)p_aout );
1722 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1725 if( p_vout != NULL )
1727 vlc_object_t * p_dec_obj;
1729 [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
1730 var: "aspect-ratio" selector: @selector(toggleVar:)];
1732 [o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
1733 var: "crop" selector: @selector(toggleVar:)];
1735 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1736 var: "video-device" selector: @selector(toggleVar:)];
1738 [o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
1739 var: "deinterlace" selector: @selector(toggleVar:)];
1741 p_dec_obj = (vlc_object_t *)vlc_object_find(
1742 (vlc_object_t *)p_vout,
1745 if( p_dec_obj != NULL )
1747 [o_controls setupVarMenuItem: o_mi_ffmpeg_pp target:
1748 (vlc_object_t *)p_dec_obj var:"ffmpeg-pp-q" selector:
1749 @selector(toggleVar:)];
1751 vlc_object_release(p_dec_obj);
1753 vlc_object_release( (vlc_object_t *)p_vout );
1755 vlc_object_release( p_input );
1757 pl_Release( p_intf );
1760 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
1763 vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1769 /* clean the menu before adding new entries */
1770 if( [o_mi_screen hasSubmenu] )
1772 y = [[o_mi_screen submenu] numberOfItems] - 1;
1773 msg_Dbg( VLCIntf, "%i items in submenu", y );
1776 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
1777 [[o_mi_screen submenu] removeItemAtIndex: x];
1782 [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
1783 var: "video-device" selector: @selector(toggleVar:)];
1784 vlc_object_release( (vlc_object_t *)p_vout );
1787 - (void)setScrollField:(NSString *)o_string stopAfter:(int)timeout
1790 i_end_scroll = mdate() + timeout;
1793 [o_scrollfield setStringValue: o_string];
1796 - (void)resetScrollField
1798 playlist_t * p_playlist = pl_Hold( p_intf );
1799 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1802 if( p_input && vlc_object_alive (p_input) )
1805 playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
1806 if( input_item_GetNowPlaying( p_item->p_input ) )
1807 o_temp = [NSString stringWithUTF8String:input_item_GetNowPlaying( p_item->p_input )];
1809 o_temp = [NSString stringWithUTF8String:p_item->p_input->psz_name];
1810 [self setScrollField: o_temp stopAfter:-1];
1811 [[[self getControls] getFSPanel] setStreamTitle: o_temp];
1812 vlc_object_release( p_input );
1813 pl_Release( p_intf );
1816 pl_Release( p_intf );
1817 [self setScrollField: _NS("VLC media player") stopAfter:-1];
1820 - (void)playStatusUpdated:(int)i_status
1822 if( i_status == PLAYING_S )
1824 [[[self getControls] getFSPanel] setPause];
1825 [o_btn_play setImage: o_img_pause];
1826 [o_btn_play setAlternateImage: o_img_pause_pressed];
1827 [o_btn_play setToolTip: _NS("Pause")];
1828 [o_mi_play setTitle: _NS("Pause")];
1829 [o_dmi_play setTitle: _NS("Pause")];
1830 [o_vmi_play setTitle: _NS("Pause")];
1834 [[[self getControls] getFSPanel] setPlay];
1835 [o_btn_play setImage: o_img_play];
1836 [o_btn_play setAlternateImage: o_img_play_pressed];
1837 [o_btn_play setToolTip: _NS("Play")];
1838 [o_mi_play setTitle: _NS("Play")];
1839 [o_dmi_play setTitle: _NS("Play")];
1840 [o_vmi_play setTitle: _NS("Play")];
1844 - (void)setSubmenusEnabled:(BOOL)b_enabled
1846 [o_mi_program setEnabled: b_enabled];
1847 [o_mi_title setEnabled: b_enabled];
1848 [o_mi_chapter setEnabled: b_enabled];
1849 [o_mi_audiotrack setEnabled: b_enabled];
1850 [o_mi_visual setEnabled: b_enabled];
1851 [o_mi_videotrack setEnabled: b_enabled];
1852 [o_mi_subtitle setEnabled: b_enabled];
1853 [o_mi_channels setEnabled: b_enabled];
1854 [o_mi_deinterlace setEnabled: b_enabled];
1855 [o_mi_ffmpeg_pp setEnabled: b_enabled];
1856 [o_mi_device setEnabled: b_enabled];
1857 [o_mi_screen setEnabled: b_enabled];
1858 [o_mi_aspect_ratio setEnabled: b_enabled];
1859 [o_mi_crop setEnabled: b_enabled];
1862 - (IBAction)timesliderUpdate:(id)sender
1865 playlist_t * p_playlist;
1866 input_thread_t * p_input;
1868 switch( [[NSApp currentEvent] type] )
1871 case NSLeftMouseDown:
1872 case NSLeftMouseDragged:
1873 f_updated = [sender floatValue];
1879 p_playlist = pl_Hold( p_intf );
1880 p_input = playlist_CurrentInput( p_playlist );
1881 if( p_input != NULL )
1886 char psz_time[MSTRTIME_MAX_SIZE];
1888 pos.f_float = f_updated / 10000.;
1889 var_Set( p_input, "position", pos );
1890 [o_timeslider setFloatValue: f_updated];
1892 var_Get( p_input, "time", &time );
1894 o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
1895 [o_timefield setStringValue: o_time];
1896 [[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
1897 [o_embedded_window setTime: o_time position: f_updated];
1898 vlc_object_release( p_input );
1900 pl_Release( p_intf );
1904 #pragma mark Recent Items
1906 - (IBAction)clearRecentItems:(id)sender
1908 [[NSDocumentController sharedDocumentController]
1909 clearRecentDocuments: nil];
1912 - (void)openRecentItem:(id)sender
1914 [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)showVLM:(id)sender
1996 if( !nib_vlm_loaded )
1997 nib_vlm_loaded = [NSBundle loadNibNamed:@"VLM" owner:self];
1999 [o_vlm showVLMWindow];
2002 - (IBAction)showExtended:(id)sender
2004 if( o_extended == nil )
2005 o_extended = [[VLCExtended alloc] init];
2007 if( !nib_extended_loaded )
2008 nib_extended_loaded = [NSBundle loadNibNamed:@"Extended" owner:self];
2010 [o_extended showPanel];
2013 - (IBAction)showBookmarks:(id)sender
2015 /* we need the wizard-nib for the bookmarks's extract functionality */
2016 if( !nib_wizard_loaded )
2018 nib_wizard_loaded = [NSBundle loadNibNamed:@"Wizard" owner:self];
2019 [o_wizard initStrings];
2022 if( !nib_bookmarks_loaded )
2023 nib_bookmarks_loaded = [NSBundle loadNibNamed:@"Bookmarks" owner:self];
2025 [o_bookmarks showBookmarks];
2028 - (IBAction)viewPreferences:(id)sender
2030 if( !nib_prefs_loaded )
2032 nib_prefs_loaded = [NSBundle loadNibNamed:@"Preferences" owner: self];
2033 o_sprefs = [[VLCSimplePrefs alloc] init];
2034 o_prefs= [[VLCPrefs alloc] init];
2037 [o_sprefs showSimplePrefs];
2043 - (IBAction)checkForUpdate:(id)sender
2046 if( !nib_update_loaded )
2047 nib_update_loaded = [NSBundle loadNibNamed:@"Update" owner:self];
2048 [o_update showUpdateWindow];
2050 msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
2051 intf_UserFatal( VLCIntf, false, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
2056 #pragma mark Help and Docs
2058 - (IBAction)viewAbout:(id)sender
2060 if( !nib_about_loaded )
2061 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2063 [o_about showAbout];
2066 - (IBAction)showLicense:(id)sender
2068 if( !nib_about_loaded )
2069 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2071 [o_about showGPL: sender];
2074 - (IBAction)viewHelp:(id)sender
2076 if( !nib_about_loaded )
2078 nib_about_loaded = [NSBundle loadNibNamed:@"About" owner:self];
2085 - (IBAction)openReadMe:(id)sender
2087 NSString * o_path = [[NSBundle mainBundle]
2088 pathForResource: @"README.MacOSX" ofType: @"rtf"];
2090 [[NSWorkspace sharedWorkspace] openFile: o_path
2091 withApplication: @"TextEdit"];
2094 - (IBAction)openDocumentation:(id)sender
2096 NSURL * o_url = [NSURL URLWithString:
2097 @"http://www.videolan.org/doc/"];
2099 [[NSWorkspace sharedWorkspace] openURL: o_url];
2102 - (IBAction)openWebsite:(id)sender
2104 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
2106 [[NSWorkspace sharedWorkspace] openURL: o_url];
2109 - (IBAction)openForum:(id)sender
2111 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
2113 [[NSWorkspace sharedWorkspace] openURL: o_url];
2116 - (IBAction)openDonate:(id)sender
2118 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
2120 [[NSWorkspace sharedWorkspace] openURL: o_url];
2124 #pragma mark Crash Log
2125 - (void)sendCrashLog:(NSString *)crashLog withUserComment:(NSString *)userComment
2127 NSString *urlStr = @"http://jones.videolan.org/crashlog/sendcrashreport.php";
2128 NSURL *url = [NSURL URLWithString:urlStr];
2130 NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
2131 [req setHTTPMethod:@"POST"];
2134 if( [o_crashrep_includeEmail_ckb state] == NSOnState )
2136 ABPerson * contact = [[ABAddressBook sharedAddressBook] me];
2137 ABMultiValue *emails = [contact valueForProperty:kABEmailProperty];
2138 email = [emails valueAtIndex:[emails indexForIdentifier:
2139 [emails primaryIdentifier]]];
2142 email = [NSString string];
2145 postBody = [NSString stringWithFormat:@"CrashLog=%@&Comment=%@&Email=%@\r\n",
2146 [crashLog stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2147 [userComment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
2148 [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
2150 [req setHTTPBody:[postBody dataUsingEncoding:NSUTF8StringEncoding]];
2152 /* Released from delegate */
2153 crashLogURLConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
2156 - (void)connectionDidFinishLoading:(NSURLConnection *)connection
2158 NSRunInformationalAlertPanel(_NS("Crash Report successfully sent"),
2159 _NS("Thanks for your report!"),
2160 _NS("OK"), nil, nil, nil);
2161 [crashLogURLConnection release];
2162 crashLogURLConnection = nil;
2165 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
2167 NSRunCriticalAlertPanel(_NS("Error when sending the Crash Report"), [error localizedDescription], @"OK", nil, nil);
2168 [crashLogURLConnection release];
2169 crashLogURLConnection = nil;
2172 - (NSString *)latestCrashLogPathPreviouslySeen:(BOOL)previouslySeen
2174 NSString * crashReporter = [@"~/Library/Logs/CrashReporter" stringByExpandingTildeInPath];
2175 NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager] enumeratorAtPath:crashReporter];
2177 NSString * latestLog = nil;
2178 int year = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"] : 0;
2179 int month = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportMonth"]: 0;
2180 int day = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportDay"] : 0;
2181 int hours = !previouslySeen ? [[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportHours"]: 0;
2183 while (fname = [direnum nextObject])
2185 [direnum skipDescendents];
2186 if([fname hasPrefix:@"VLC"] && [fname hasSuffix:@"crash"])
2188 NSArray * compo = [fname componentsSeparatedByString:@"_"];
2189 if( [compo count] < 3 ) continue;
2190 compo = [[compo objectAtIndex:1] componentsSeparatedByString:@"-"];
2191 if( [compo count] < 4 ) continue;
2194 if( year < [[compo objectAtIndex:0] intValue] ||
2195 (year ==[[compo objectAtIndex:0] intValue] &&
2196 (month < [[compo objectAtIndex:1] intValue] ||
2197 (month ==[[compo objectAtIndex:1] intValue] &&
2198 (day < [[compo objectAtIndex:2] intValue] ||
2199 (day ==[[compo objectAtIndex:2] intValue] &&
2200 hours < [[compo objectAtIndex:3] intValue] ))))))
2202 year = [[compo objectAtIndex:0] intValue];
2203 month = [[compo objectAtIndex:1] intValue];
2204 day = [[compo objectAtIndex:2] intValue];
2205 hours = [[compo objectAtIndex:3] intValue];
2206 latestLog = [crashReporter stringByAppendingPathComponent:fname];
2211 if(!(latestLog && [[NSFileManager defaultManager] fileExistsAtPath:latestLog]))
2214 if( !previouslySeen )
2216 [[NSUserDefaults standardUserDefaults] setInteger:year forKey:@"LatestCrashReportYear"];
2217 [[NSUserDefaults standardUserDefaults] setInteger:month forKey:@"LatestCrashReportMonth"];
2218 [[NSUserDefaults standardUserDefaults] setInteger:day forKey:@"LatestCrashReportDay"];
2219 [[NSUserDefaults standardUserDefaults] setInteger:hours forKey:@"LatestCrashReportHours"];
2224 - (NSString *)latestCrashLogPath
2226 return [self latestCrashLogPathPreviouslySeen:YES];
2229 - (void)lookForCrashLog
2231 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
2232 // This pref key doesn't exists? this VLC is an upgrade, and this crash log come from previous version
2233 BOOL areCrashLogsTooOld = ![[NSUserDefaults standardUserDefaults] integerForKey:@"LatestCrashReportYear"];
2234 NSString * latestLog = [self latestCrashLogPathPreviouslySeen:NO];
2235 if( latestLog && !areCrashLogsTooOld )
2236 [NSApp runModalForWindow: o_crashrep_win];
2240 - (IBAction)crashReporterAction:(id)sender
2242 if( sender == o_crashrep_send_btn )
2243 [self sendCrashLog:[NSString stringWithContentsOfFile: [self latestCrashLogPath]] withUserComment: [o_crashrep_fld string]];
2246 [o_crashrep_win orderOut: sender];
2249 - (IBAction)openCrashLog:(id)sender
2251 NSString * latestLog = [self latestCrashLogPath];
2254 [[NSWorkspace sharedWorkspace] openFile: latestLog withApplication: @"Console"];
2258 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.") );
2263 #pragma mark Remove old prefs
2265 - (void)_removeOldPreferences
2267 static NSString * kVLCPreferencesVersion = @"VLCPreferencesVersion";
2268 static const int kCurrentPreferencesVersion = 1;
2269 int version = [[NSUserDefaults standardUserDefaults] integerForKey:kVLCPreferencesVersion];
2270 if( version >= kCurrentPreferencesVersion ) return;
2272 NSArray *libraries = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
2273 NSUserDomainMask, YES);
2274 if( !libraries || [libraries count] == 0) return;
2275 NSString * preferences = [[libraries objectAtIndex:0] stringByAppendingPathComponent:@"Preferences"];
2277 /* File not found, don't attempt anything */
2278 if(![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"VLC"]] &&
2279 ![[NSFileManager defaultManager] fileExistsAtPath:[preferences stringByAppendingPathComponent:@"org.videolan.vlc.plist"]] )
2281 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2285 int res = NSRunInformationalAlertPanel(_NS("Remove old preferences?"),
2286 _NS("We just found an older version of VLC's preferences files."),
2287 _NS("Move To Trash and Relaunch VLC"), _NS("Ignore"), nil, nil);
2288 if( res != NSOKButton )
2290 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2294 NSArray * ourPreferences = [NSArray arrayWithObjects:@"org.videolan.vlc.plist", @"VLC", nil];
2296 /* Move the file to trash so that user can find them later */
2297 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:preferences destination:nil files:ourPreferences tag:0];
2299 /* really reset the defaults from now on */
2300 [NSUserDefaults resetStandardUserDefaults];
2302 [[NSUserDefaults standardUserDefaults] setInteger:kCurrentPreferencesVersion forKey:kVLCPreferencesVersion];
2303 [[NSUserDefaults standardUserDefaults] synchronize];
2306 const char * path = [[[NSBundle mainBundle] executablePath] UTF8String];
2308 /* For some reason we need to fork(), not just execl(), which reports a ENOTSUP then. */
2314 execl(path, path, NULL);
2318 #pragma mark Errors, warnings and messages
2320 - (IBAction)viewErrorsAndWarnings:(id)sender
2322 [[[self getInteractionList] getErrorPanel] showPanel];
2325 - (IBAction)showMessagesPanel:(id)sender
2327 [o_msgs_panel makeKeyAndOrderFront: sender];
2330 - (IBAction)showInformationPanel:(id)sender
2332 if(! nib_info_loaded )
2333 nib_info_loaded = [NSBundle loadNibNamed:@"MediaInfo" owner: self];
2338 - (void)windowDidBecomeKey:(NSNotification *)o_notification
2340 if( [o_notification object] == o_msgs_panel )
2343 NSEnumerator * o_enum;
2345 [o_messages setString: @""];
2349 o_enum = [o_msg_arr objectEnumerator];
2351 while( ( o_msg = [o_enum nextObject] ) != nil )
2353 [o_messages insertText: o_msg];
2356 [o_msg_lock unlock];
2360 - (void)updateMessageArray
2362 int i_start, i_stop;
2364 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
2365 i_stop = *p_intf->p_sys->p_sub->pi_stop;
2366 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
2368 if( p_intf->p_sys->p_sub->i_start != i_stop )
2370 NSColor *o_white = [NSColor whiteColor];
2371 NSColor *o_red = [NSColor redColor];
2372 NSColor *o_yellow = [NSColor yellowColor];
2373 NSColor *o_gray = [NSColor grayColor];
2375 NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
2376 static const char * ppsz_type[4] = { ": ", " error: ",
2377 " warning: ", " debug: " };
2379 for( i_start = p_intf->p_sys->p_sub->i_start;
2381 i_start = (i_start+1) % VLC_MSG_QSIZE )
2384 NSDictionary *o_attr;
2385 NSAttributedString *o_msg_color;
2387 int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
2391 if( [o_msg_arr count] + 2 > 400 )
2393 unsigned rid[] = { 0, 1 };
2394 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
2395 numIndices: sizeof(rid)/sizeof(rid[0])];
2398 o_attr = [NSDictionary dictionaryWithObject: o_gray
2399 forKey: NSForegroundColorAttributeName];
2400 o_msg = [NSString stringWithFormat: @"%s%s",
2401 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
2403 o_msg_color = [[NSAttributedString alloc]
2404 initWithString: o_msg attributes: o_attr];
2405 [o_msg_arr addObject: [o_msg_color autorelease]];
2407 o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
2408 forKey: NSForegroundColorAttributeName];
2409 o_msg = [[NSString stringWithUTF8String: p_intf->p_sys->p_sub->p_msg[i_start].psz_msg] stringByAppendingString: @"\n"];
2410 o_msg_color = [[NSAttributedString alloc]
2411 initWithString: o_msg attributes: o_attr];
2412 [o_msg_arr addObject: [o_msg_color autorelease]];
2414 [o_msg_lock unlock];
2417 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
2418 p_intf->p_sys->p_sub->i_start = i_start;
2419 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
2425 #pragma mark Playlist toggling
2427 - (IBAction)togglePlaylist:(id)sender
2429 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2430 NSRect o_rect = [o_window contentRectForFrameRect:[o_window frame]];
2431 /*First, check if the playlist is visible*/
2432 if( contentRect.size.height <= 169. )
2434 o_restore_rect = contentRect;
2435 b_restore_size = true;
2436 b_small_window = YES; /* we know we are small, make sure this is actually set (see case below) */
2439 if( o_size_with_playlist.height > 169. )
2440 o_rect.size.height = o_size_with_playlist.height;
2442 o_rect.size.height = 500.;
2444 if( o_size_with_playlist.width >= [o_window contentMinSize].width )
2445 o_rect.size.width = o_size_with_playlist.width;
2447 o_rect.size.width = [o_window contentMinSize].width;
2449 o_rect.origin.x = contentRect.origin.x;
2450 o_rect.origin.y = contentRect.origin.y - o_rect.size.height +
2451 [o_window contentMinSize].height;
2453 o_rect = [o_window frameRectForContentRect:o_rect];
2455 NSRect screenRect = [[o_window screen] visibleFrame];
2456 if( !NSContainsRect( screenRect, o_rect ) ) {
2457 if( NSMaxX(o_rect) > NSMaxX(screenRect) )
2458 o_rect.origin.x = ( NSMaxX(screenRect) - o_rect.size.width );
2459 if( NSMinY(o_rect) < NSMinY(screenRect) )
2460 o_rect.origin.y = ( NSMinY(screenRect) );
2463 [o_btn_playlist setState: YES];
2467 NSSize curSize = o_rect.size;
2468 if( b_restore_size )
2470 o_rect = o_restore_rect;
2471 if( o_rect.size.height < [o_window contentMinSize].height )
2472 o_rect.size.height = [o_window contentMinSize].height;
2473 if( o_rect.size.width < [o_window contentMinSize].width )
2474 o_rect.size.width = [o_window contentMinSize].width;
2478 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2480 o_rect.size.height = [o_window contentMinSize].height;
2481 o_rect.size.width = [o_window contentMinSize].width;
2482 o_rect.origin.x = contentRect.origin.x;
2483 /* Calculate the position of the lower right corner after resize */
2484 o_rect.origin.y = contentRect.origin.y +
2485 contentRect.size.height - [o_window contentMinSize].height;
2488 [o_playlist_view setAutoresizesSubviews: NO];
2489 [o_playlist_view removeFromSuperview];
2490 [o_btn_playlist setState: NO];
2491 b_small_window = NO; /* we aren't small here just yet. we are doing an animated resize after this */
2492 o_rect = [o_window frameRectForContentRect:o_rect];
2495 [o_window setFrame: o_rect display:YES animate: YES];
2498 - (void)updateTogglePlaylistState
2500 if( [o_window contentRectForFrameRect:[o_window frame]].size.height <= 169. )
2502 [o_btn_playlist setState: NO];
2506 [o_btn_playlist setState: YES];
2510 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
2513 /* Not triggered on a window resize or maxification of the window. only by window mouse dragging resize */
2515 /*Stores the size the controller one resize, to be able to restore it when
2516 toggling the playlist*/
2517 o_size_with_playlist = proposedFrameSize;
2520 rect.size = proposedFrameSize;
2521 if( [o_window contentRectForFrameRect:rect].size.height <= 169. )
2523 if( b_small_window == NO )
2525 /* if large and going to small then hide */
2526 b_small_window = YES;
2527 [o_playlist_view setAutoresizesSubviews: NO];
2528 [o_playlist_view removeFromSuperview];
2530 return NSMakeSize( proposedFrameSize.width, [o_window minSize].height);
2532 return proposedFrameSize;
2535 - (void)windowDidMove:(NSNotification *)notif
2537 b_restore_size = false;
2540 - (void)windowDidResize:(NSNotification *)notif
2542 if( [o_window contentRectForFrameRect:[o_window frame]].size.height > 169. && b_small_window )
2544 /* If large and coming from small then show */
2545 [o_playlist_view setAutoresizesSubviews: YES];
2546 NSRect contentRect = [o_window contentRectForFrameRect:[o_window frame]];
2547 [o_playlist_view setFrame: NSMakeRect( 0, 0, contentRect.size.width, contentRect.size.height - [o_window contentMinSize].height )];
2548 [o_playlist_view setNeedsDisplay:YES];
2549 [[o_window contentView] addSubview: o_playlist_view];
2550 b_small_window = NO;
2552 [self updateTogglePlaylistState];
2559 @implementation VLCMain (NSMenuValidation)
2561 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
2563 NSString *o_title = [o_mi title];
2564 BOOL bEnabled = TRUE;
2566 /* Recent Items Menu */
2567 if( [o_title isEqualToString: _NS("Clear Menu")] )
2569 NSMenu * o_menu = [o_mi_open_recent submenu];
2570 int i_nb_items = [o_menu numberOfItems];
2571 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
2572 recentDocumentURLs];
2573 UInt32 i_nb_docs = [o_docs count];
2575 if( i_nb_items > 1 )
2577 while( --i_nb_items )
2579 [o_menu removeItemAtIndex: 0];
2588 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
2594 o_url = [o_docs objectAtIndex: i_nb_docs];
2596 if( [o_url isFileURL] )
2598 o_doc = [o_url path];
2602 o_doc = [o_url absoluteString];
2605 [o_menu insertItemWithTitle: o_doc
2606 action: @selector(openRecentItem:)
2607 keyEquivalent: @"" atIndex: 0];
2609 if( i_nb_docs == 0 )
2625 @implementation VLCMain (Internal)
2627 - (void)handlePortMessage:(NSPortMessage *)o_msg
2632 NSInvocation * o_inv;
2633 NSConditionLock * o_lock;
2635 o_data = [[o_msg components] lastObject];
2636 o_inv = *((NSInvocation **)[o_data bytes]);
2637 [o_inv getArgument: &o_value atIndex: 2];
2638 val = (id **)[o_value pointerValue];
2639 [o_inv setArgument: val[1] atIndex: 2];
2644 [o_lock unlockWithCondition: 1];