macosx: added a URI column to the playlist table
[vlc.git] / modules / gui / macosx / MainMenu.m
1 /*****************************************************************************
2  * MainMenu.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011-2012 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #import "MainMenu.h"
25 #import <vlc_common.h>
26 #import <vlc_playlist.h>
27
28 #import "intf.h"
29 #import "open.h"
30 #import "wizard.h"
31 #import "about.h"
32 #import "AudioEffects.h"
33 #import "TrackSynchronization.h"
34 #import "VideoEffects.h"
35 #import "bookmarks.h"
36 #import "simple_prefs.h"
37 #import "coredialogs.h"
38 #import "controls.h"
39 #import "playlist.h"
40 #import "playlistinfo.h"
41 #import "VideoView.h"
42 #import "CoreInteraction.h"
43 #import "MainWindow.h"
44 #import "ExtensionsManager.h"
45 #import "ConvertAndSave.h"
46
47 @implementation VLCMainMenu
48 static VLCMainMenu *_o_sharedInstance = nil;
49
50 + (VLCMainMenu *)sharedInstance
51 {
52     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
53 }
54
55 #pragma mark -
56 #pragma mark Initialization
57
58 - (id)init
59 {
60     if( _o_sharedInstance)
61     {
62         [self dealloc];
63         return _o_sharedInstance;
64     }
65     else
66     {
67         _o_sharedInstance = [super init];
68     }
69
70     return _o_sharedInstance;
71 }
72
73 - (void)dealloc
74 {
75     [[NSNotificationCenter defaultCenter] removeObserver: self];
76
77     if (b_nib_about_loaded)
78         [o_about release];
79
80     if (b_nib_videoeffects_loaded)
81         [o_videoeffects release];
82
83     if (b_nib_audioeffects_loaded)
84         [o_audioeffects release];
85
86     if (b_nib_tracksynchro_loaded)
87         [o_trackSynchronization release];
88
89     if (b_nib_convertandsave_loaded)
90         [o_convertandsave release];
91
92     [o_extMgr release];
93
94     [super dealloc];
95 }
96
97 - (void)awakeFromNib
98 {
99     [[NSNotificationCenter defaultCenter] addObserver: self
100                                              selector: @selector(applicationWillFinishLaunching:)
101                                                  name: NSApplicationWillFinishLaunchingNotification
102                                                object: nil];
103 }
104
105 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
106 {
107     p_intf = VLCIntf;
108
109     NSString* o_key;
110     playlist_t *p_playlist;
111     vlc_value_t val;
112     id o_vlcmain = [VLCMain sharedInstance];
113     char * key;
114
115     /* Check if we already did this once. Opening the other nibs calls it too,
116      because VLCMain is the owner */
117     if( b_mainMenu_setup ) return;
118
119     /* Get ExtensionsManager */
120     o_extMgr = [ExtensionsManager getInstance:p_intf];
121     [o_extMgr retain];
122
123     [self initStrings];
124
125     key = config_GetPsz( p_intf, "key-quit" );
126     o_key = [NSString stringWithFormat:@"%s", key];
127     [o_mi_quit setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
128     [o_mi_quit setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
129     FREENULL( key );
130
131     key = config_GetPsz( p_intf, "key-play-pause" );
132     o_key = [NSString stringWithFormat:@"%s", key];
133     [o_mi_play setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
134     [o_mi_play setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
135     FREENULL( key );
136
137     key = config_GetPsz( p_intf, "key-stop" );
138     o_key = [NSString stringWithFormat:@"%s", key];
139     [o_mi_stop setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
140     [o_mi_stop setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
141     FREENULL( key );
142
143     key = config_GetPsz( p_intf, "key-prev" );
144     o_key = [NSString stringWithFormat:@"%s", key];
145     [o_mi_previous setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
146     [o_mi_previous setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
147     FREENULL( key );
148
149     key = config_GetPsz( p_intf, "key-next" );
150     o_key = [NSString stringWithFormat:@"%s", key];
151     [o_mi_next setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
152     [o_mi_next setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
153     FREENULL( key );
154
155     key = config_GetPsz( p_intf, "key-jump+short" );
156     o_key = [NSString stringWithFormat:@"%s", key];
157     [o_mi_fwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
158     [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
159     FREENULL( key );
160
161     key = config_GetPsz( p_intf, "key-jump-short" );
162     o_key = [NSString stringWithFormat:@"%s", key];
163     [o_mi_bwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
164     [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
165     FREENULL( key );
166
167     key = config_GetPsz( p_intf, "key-vol-up" );
168     o_key = [NSString stringWithFormat:@"%s", key];
169     [o_mi_vol_up setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
170     [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
171     FREENULL( key );
172
173     key = config_GetPsz( p_intf, "key-vol-down" );
174     o_key = [NSString stringWithFormat:@"%s", key];
175     [o_mi_vol_down setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
176     [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
177     FREENULL( key );
178
179     key = config_GetPsz( p_intf, "key-vol-mute" );
180     o_key = [NSString stringWithFormat:@"%s", key];
181     [o_mi_mute setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
182     [o_mi_mute setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
183     FREENULL( key );
184
185     key = config_GetPsz( p_intf, "key-toggle-fullscreen" );
186     o_key = [NSString stringWithFormat:@"%s", key];
187     [o_mi_fullscreen setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
188     [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
189     FREENULL( key );
190
191     key = config_GetPsz( p_intf, "key-snapshot" );
192     o_key = [NSString stringWithFormat:@"%s", key];
193     [o_mi_snapshot setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
194     [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
195     FREENULL( key );
196
197     key = config_GetPsz( p_intf, "key-random" );
198     o_key = [NSString stringWithFormat:@"%s", key];
199     [o_mi_random setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
200     [o_mi_random setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
201     FREENULL( key );
202
203     key = config_GetPsz( p_intf, "key-zoom-half" );
204     o_key = [NSString stringWithFormat:@"%s", key];
205     [o_mi_half_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
206     [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
207     FREENULL( key );
208
209     key = config_GetPsz( p_intf, "key-zoom-original" );
210     o_key = [NSString stringWithFormat:@"%s", key];
211     [o_mi_normal_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
212     [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
213     FREENULL( key );
214
215     key = config_GetPsz( p_intf, "key-zoom-double" );
216     o_key = [NSString stringWithFormat:@"%s", key];
217     [o_mi_double_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
218     [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
219     FREENULL( key );
220
221     [self setSubmenusEnabled: FALSE];
222
223     [[NSNotificationCenter defaultCenter] addObserver: self
224                                              selector: @selector(refreshVoutDeviceMenu:)
225                                                  name: NSApplicationDidChangeScreenParametersNotification
226                                                object: nil];
227
228     /* we're done */
229     b_mainMenu_setup = YES;
230
231     [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
232                              var: "intf-add" selector: @selector(toggleVar:)];
233
234     [self setupExtensionsMenu];
235 }
236
237 - (void)initStrings
238 {
239     /* main menu */
240     [o_mi_about setTitle: [_NS("About VLC media player") \
241                            stringByAppendingString: @"..."]];
242     [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
243     [o_mi_prefs setTitle: _NS("Preferences...")];
244     [o_mi_extensions setTitle: _NS("Extensions")];
245     [o_mu_extensions setTitle: _NS("Extensions")];
246     [o_mi_add_intf setTitle: _NS("Add Interface")];
247     [o_mu_add_intf setTitle: _NS("Add Interface")];
248     [o_mi_services setTitle: _NS("Services")];
249     [o_mi_hide setTitle: _NS("Hide VLC")];
250     [o_mi_hide_others setTitle: _NS("Hide Others")];
251     [o_mi_show_all setTitle: _NS("Show All")];
252     [o_mi_quit setTitle: _NS("Quit VLC")];
253
254     [o_mu_file setTitle: _ANS("1:File")];
255     [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
256     [o_mi_open_file setTitle: _NS("Open File...")];
257     [o_mi_open_disc setTitle: _NS("Open Disc...")];
258     [o_mi_open_net setTitle: _NS("Open Network...")];
259     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
260     [o_mi_open_recent setTitle: _NS("Open Recent")];
261     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
262     [o_mi_convertandsave setTitle: _NS("Convert / Save...")];
263
264     [o_mu_edit setTitle: _NS("Edit")];
265     [o_mi_cut setTitle: _NS("Cut")];
266     [o_mi_copy setTitle: _NS("Copy")];
267     [o_mi_paste setTitle: _NS("Paste")];
268     [o_mi_clear setTitle: _NS("Clear")];
269     [o_mi_select_all setTitle: _NS("Select All")];
270
271     [o_mu_controls setTitle: _NS("Playback")];
272     [o_mi_play setTitle: _NS("Play")];
273     [o_mi_stop setTitle: _NS("Stop")];
274     [o_mi_record setTitle: _NS("Record")];
275     [o_mi_rate setView: o_mi_rate_view];
276     [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
277     [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
278     [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
279     [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
280     [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
281     [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
282     [o_mi_previous setTitle: _NS("Previous")];
283     [o_mi_next setTitle: _NS("Next")];
284     [o_mi_random setTitle: _NS("Random")];
285     [o_mi_repeat setTitle: _NS("Repeat One")];
286     [o_mi_loop setTitle: _NS("Repeat All")];
287     [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
288     [o_mi_fwd setTitle: _NS("Step Forward")];
289     [o_mi_bwd setTitle: _NS("Step Backward")];
290     [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
291     [o_mi_toggleJumpButtons setState: config_GetInt( VLCIntf, "macosx-show-playback-buttons")];
292     [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
293     [o_mi_togglePlaymodeButtons setState: config_GetInt( VLCIntf, "macosx-show-playmode-buttons")];
294     [o_mu_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
295     [o_mi_ptc_tracknum setTitle: _NS("Track Number")];
296     [o_mi_ptc_title setTitle: _NS("Title")];
297     [o_mi_ptc_artist setTitle: _NS("Artist")];
298     [o_mi_ptc_duration setTitle: _NS("Duration")];
299     [o_mi_ptc_genre setTitle: _NS("Genre")];
300     [o_mi_ptc_album setTitle: _NS("Album")];
301     [o_mi_ptc_description setTitle: _NS("Description")];
302     [o_mi_ptc_date setTitle: _NS("Date")];
303     [o_mi_ptc_language setTitle: _NS("Language")];
304     [o_mi_ptc_uri setTitle: _NS("URI")];
305
306     [o_mi_program setTitle: _NS("Program")];
307     [o_mu_program setTitle: _NS("Program")];
308     [o_mi_title setTitle: _NS("Title")];
309     [o_mu_title setTitle: _NS("Title")];
310     [o_mi_chapter setTitle: _NS("Chapter")];
311     [o_mu_chapter setTitle: _NS("Chapter")];
312
313     [o_mu_audio setTitle: _NS("Audio")];
314     [o_mi_vol_up setTitle: _NS("Increase Volume")];
315     [o_mi_vol_down setTitle: _NS("Decrease Volume")];
316     [o_mi_mute setTitle: _NS("Mute")];
317     [o_mi_audiotrack setTitle: _NS("Audio Track")];
318     [o_mu_audiotrack setTitle: _NS("Audio Track")];
319     [o_mi_channels setTitle: _NS("Audio Channels")];
320     [o_mu_channels setTitle: _NS("Audio Channels")];
321     [o_mi_device setTitle: _NS("Audio Device")];
322     [o_mu_device setTitle: _NS("Audio Device")];
323     [o_mi_visual setTitle: _NS("Visualizations")];
324     [o_mu_visual setTitle: _NS("Visualizations")];
325
326     [o_mu_video setTitle: _NS("Video")];
327     [o_mi_half_window setTitle: _NS("Half Size")];
328     [o_mi_normal_window setTitle: _NS("Normal Size")];
329     [o_mi_double_window setTitle: _NS("Double Size")];
330     [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
331     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
332     [o_mi_floatontop setTitle: _NS("Float on Top")];
333     [o_mi_snapshot setTitle: _NS("Snapshot")];
334     [o_mi_videotrack setTitle: _NS("Video Track")];
335     [o_mu_videotrack setTitle: _NS("Video Track")];
336     [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
337     [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
338     [o_mi_crop setTitle: _NS("Crop")];
339     [o_mu_crop setTitle: _NS("Crop")];
340     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
341     [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
342     [o_mi_subtitle setTitle: _NS("Subtitles Track")];
343     [o_mu_subtitle setTitle: _NS("Subtitles Track")];
344     [o_mi_addSub setTitle: _NS("Open File...")];
345     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
346     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
347     [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
348     [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
349     [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
350     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
351     [o_mi_teletext setTitle: _NS("Teletext")];
352     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
353     [o_mi_teletext_index setTitle: _NS("Index")];
354     [o_mi_teletext_red setTitle: _NS("Red")];
355     [o_mi_teletext_green setTitle: _NS("Green")];
356     [o_mi_teletext_yellow setTitle: _NS("Yellow")];
357     [o_mi_teletext_blue setTitle: _NS("Blue")];
358
359     [o_mu_window setTitle: _NS("Window")];
360     [o_mi_minimize setTitle: _NS("Minimize Window")];
361     [o_mi_close_window setTitle: _NS("Close Window")];
362     [o_mi_player setTitle: _NS("Player...")];
363     [o_mi_controller setTitle: _NS("Main Window...")];
364     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
365     [o_mi_videoeffects setTitle: _NS("Video Filters...")];
366     [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
367     [o_mi_playlist setTitle: _NS("Playlist...")];
368     [o_mi_info setTitle: _NS("Media Information...")];
369     [o_mi_messages setTitle: _NS("Messages...")];
370     [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
371
372     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
373
374     [o_mu_help setTitle: _NS("Help")];
375     [o_mi_help setTitle: _NS("VLC media player Help...")];
376     [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
377     [o_mi_license setTitle: _NS("License")];
378     [o_mi_documentation setTitle: _NS("Online Documentation...")];
379     [o_mi_website setTitle: _NS("VideoLAN Website...")];
380     [o_mi_donation setTitle: _NS("Make a donation...")];
381     [o_mi_forum setTitle: _NS("Online Forum...")];
382
383     /* dock menu */
384     [o_dmi_play setTitle: _NS("Play")];
385     [o_dmi_stop setTitle: _NS("Stop")];
386     [o_dmi_next setTitle: _NS("Next")];
387     [o_dmi_previous setTitle: _NS("Previous")];
388     [o_dmi_mute setTitle: _NS("Mute")];
389
390     /* vout menu */
391     [o_vmi_play setTitle: _NS("Play")];
392     [o_vmi_stop setTitle: _NS("Stop")];
393     [o_vmi_prev setTitle: _NS("Previous")];
394     [o_vmi_next setTitle: _NS("Next")];
395     [o_vmi_volup setTitle: _NS("Volume Up")];
396     [o_vmi_voldown setTitle: _NS("Volume Down")];
397     [o_vmi_mute setTitle: _NS("Mute")];
398     [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
399     [o_vmi_snapshot setTitle: _NS("Snapshot")];
400 }
401
402 #pragma mark -
403 #pragma mark Termination
404
405 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
406 {
407     if( !p_intf ) return;
408
409     NSArray *menuitems_array = [the_menu itemArray];
410     NSUInteger menuItemCount = [menuitems_array count];
411     for( NSUInteger i=0; i < menuItemCount; i++ )
412     {
413         NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
414         if( [one_item hasSubmenu] )
415             [self releaseRepresentedObjects: [one_item submenu]];
416
417         [one_item setRepresentedObject:NULL];
418     }
419 }
420
421 #pragma mark -
422 #pragma mark Interface update
423
424 - (void)setupMenus
425 {
426     playlist_t * p_playlist = pl_Get( p_intf );
427     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
428     if( p_input != NULL )
429     {
430         [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
431
432         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
433                                  var: "program" selector: @selector(toggleVar:)];
434
435         [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
436                                  var: "title" selector: @selector(toggleVar:)];
437
438         [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
439                                  var: "chapter" selector: @selector(toggleVar:)];
440
441         [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
442                                  var: "audio-es" selector: @selector(toggleVar:)];
443
444         [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
445                                  var: "video-es" selector: @selector(toggleVar:)];
446
447         [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
448                                  var: "spu-es" selector: @selector(toggleVar:)];
449
450         /* special case for "Open File" inside the subtitles menu item */
451         if( [o_mi_videotrack isEnabled] == YES )
452             [o_mi_subtitle setEnabled: YES];
453
454         audio_output_t * p_aout = input_GetAout( p_input );
455         if( p_aout != NULL )
456         {
457             [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
458                                      var: "audio-channels" selector: @selector(toggleVar:)];
459
460             [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
461                                      var: "audio-device" selector: @selector(toggleVar:)];
462
463             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
464                                      var: "visual" selector: @selector(toggleVar:)];
465             vlc_object_release( (vlc_object_t *)p_aout );
466         }
467
468         vout_thread_t * p_vout = input_GetVout( p_input );
469
470         if( p_vout != NULL )
471         {
472             vlc_object_t * p_dec_obj;
473
474             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
475                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
476
477             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
478                                      var: "crop" selector: @selector(toggleVar:)];
479
480             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
481                                      var: "deinterlace" selector: @selector(toggleVar:)];
482
483             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
484                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
485
486 #if 1
487             [self setupVarMenuItem: o_mi_ffmpeg_pp target:
488              (vlc_object_t *)p_vout var:"postprocess" selector:
489              @selector(toggleVar:)];
490 #endif
491             vlc_object_release( (vlc_object_t *)p_vout );
492
493             [self refreshVoutDeviceMenu:nil];
494             [self setSubmenusEnabled: YES];
495         }
496         vlc_object_release( p_input );
497     }
498     else
499     {
500         [o_mi_record setEnabled: NO];
501     }
502 }
503
504 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
505 {
506     NSUInteger count = [o_mu_screen numberOfItems];
507     NSMenu * o_submenu = o_mu_screen;
508     if (count > 0)
509     {
510         if (OSX_LEOPARD)
511         {
512             NSUInteger count = [o_submenu numberOfItems];
513             for( NSUInteger i = 0; i < count; i++ )
514                 [o_submenu removeItemAtIndex: 0];
515         }
516         else
517             [o_submenu removeAllItems];
518     }
519
520     NSArray * o_screens = [NSScreen screens];
521     NSMenuItem * o_mitem;
522     count = [o_screens count];
523     [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
524     o_mitem = [o_submenu itemAtIndex: 0];
525     [o_mitem setTag: 0];
526     [o_mitem setEnabled: YES];
527     [o_mitem setTarget: self];
528     NSRect s_rect;
529     for (NSUInteger i = 0; i < count; i++)
530     {
531         s_rect = [[o_screens objectAtIndex: i] frame];
532         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
533                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
534         o_mitem = [o_submenu itemAtIndex:i+1];
535         [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
536         [o_mitem setEnabled: YES];
537         [o_mitem setTarget: self];
538     }
539     [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
540 }
541
542 - (void)setSubmenusEnabled:(BOOL)b_enabled
543 {
544     [o_mi_program setEnabled: b_enabled];
545     [o_mi_title setEnabled: b_enabled];
546     [o_mi_chapter setEnabled: b_enabled];
547     [o_mi_audiotrack setEnabled: b_enabled];
548     [o_mi_visual setEnabled: b_enabled];
549     [o_mi_videotrack setEnabled: b_enabled];
550     [o_mi_subtitle setEnabled: b_enabled];
551     [o_mi_channels setEnabled: b_enabled];
552     [o_mi_deinterlace setEnabled: b_enabled];
553     [o_mi_deinterlace_mode setEnabled: b_enabled];
554     [o_mi_ffmpeg_pp setEnabled: b_enabled];
555     [o_mi_device setEnabled: b_enabled];
556     [o_mi_screen setEnabled: b_enabled];
557     [o_mi_aspect_ratio setEnabled: b_enabled];
558     [o_mi_crop setEnabled: b_enabled];
559     [o_mi_teletext setEnabled: b_enabled];
560 }
561
562 - (void)setRateControlsEnabled:(BOOL)b_enabled
563 {
564     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
565     [o_mi_rate_sld setEnabled: b_enabled];
566     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
567     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
568     double speed =  pow( 2, (double)i / 17 );
569     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
570     if (b_enabled) {
571         [o_mi_rate_lbl setHidden: NO];
572         [o_mi_rate_lbl_gray setHidden: YES];
573     }
574     else
575     {
576         [o_mi_rate_lbl setHidden: YES];
577         [o_mi_rate_lbl_gray setHidden: NO];
578     }
579     [o_pool release];
580 }
581
582 #pragma mark -
583 #pragma mark Extensions
584
585 - (void)setupExtensionsMenu
586 {
587     /* Load extensions if needed */
588     // TODO: Implement preference for autoloading extensions on mac
589
590     // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
591     //     && ![o_extMgr isLoaded] )
592     // {
593     //     return;
594     // }
595
596     if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
597     {
598         [o_extMgr loadExtensions];
599     }
600
601     /* Let the ExtensionsManager itself build the menu */
602     [o_extMgr buildMenu:o_mu_extensions];
603 }
604
605 #pragma mark -
606 #pragma mark Playback
607 - (IBAction)toggleRecord:(id)sender
608 {
609     [[VLCCoreInteraction sharedInstance] toggleRecord];
610 }
611
612 - (void)updateRecordState:(BOOL)b_value
613 {
614     [o_mi_record setState:b_value];
615 }
616
617 - (IBAction)setPlaybackRate:(id)sender
618 {
619     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
620     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
621     double speed =  pow( 2, (double)i / 17 );
622     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
623 }
624
625 - (void)updatePlaybackRate
626 {
627     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
628     double speed =  pow( 2, (double)i / 17 );
629     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
630     [o_mi_rate_sld setIntValue: i];
631 }
632
633 - (IBAction)toggleJumpButtons:(id)sender
634 {
635     BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playback-buttons" );
636     config_PutInt( VLCIntf, "macosx-show-playback-buttons", b_value );
637     [[[VLCMain sharedInstance] mainWindow] toggleJumpButtons];
638     [o_mi_toggleJumpButtons setState: b_value];
639 }
640
641 - (IBAction)togglePlaymodeButtons:(id)sender
642 {
643     BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playmode-buttons" );
644     config_PutInt( VLCIntf, "macosx-show-playmode-buttons", b_value );
645     [[[VLCMain sharedInstance] mainWindow] togglePlaymodeButtons];
646     [o_mi_togglePlaymodeButtons setState: b_value];
647 }
648
649 - (IBAction)togglePlaylistColumnTable:(id)sender
650 {
651     [sender setState: ![sender state]];
652
653     NSString * o_column;
654
655     if (sender == o_mi_ptc_tracknum)
656         o_column = TRACKNUM_COLUMN;
657     else if (sender == o_mi_ptc_title)
658         o_column = TITLE_COLUMN;
659     else if (sender == o_mi_ptc_artist)
660         o_column = ARTIST_COLUMN;
661     else if (sender == o_mi_ptc_duration)
662         o_column = DURATION_COLUMN;
663     else if (sender == o_mi_ptc_genre)
664         o_column = GENRE_COLUMN;
665     else if (sender == o_mi_ptc_album)
666         o_column = ALBUM_COLUMN;
667     else if (sender == o_mi_ptc_description)
668         o_column = DESCRIPTION_COLUMN;
669     else if (sender == o_mi_ptc_date)
670         o_column = DATE_COLUMN;
671     else if (sender == o_mi_ptc_language)
672         o_column = LANGUAGE_COLUMN;
673     else if (sender == o_mi_ptc_uri)
674         o_column = URI_COLUMN;
675
676     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: [sender state]];
677 }
678
679 - (void)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
680 {
681     if ([o_column isEqualToString: TRACKNUM_COLUMN])
682         [o_mi_ptc_tracknum setState: i_state];
683     else if ([o_column isEqualToString: TITLE_COLUMN])
684         [o_mi_ptc_title setState: i_state];
685     else if ([o_column isEqualToString: ARTIST_COLUMN])
686         [o_mi_ptc_artist setState: i_state];
687     else if ([o_column isEqualToString: DURATION_COLUMN])
688         [o_mi_ptc_duration setState: i_state];
689     else if ([o_column isEqualToString: GENRE_COLUMN])
690         [o_mi_ptc_genre setState: i_state];
691     else if ([o_column isEqualToString: ALBUM_COLUMN])
692         [o_mi_ptc_album setState: i_state];
693     else if ([o_column isEqualToString: DESCRIPTION_COLUMN])
694         [o_mi_ptc_description setState: i_state];
695     else if ([o_column isEqualToString: DATE_COLUMN])
696         [o_mi_ptc_date setState: i_state];
697     else if ([o_column isEqualToString: LANGUAGE_COLUMN])
698         [o_mi_ptc_language setState: i_state];
699     else if ([o_column isEqualToString: URI_COLUMN])
700         [o_mi_ptc_uri setState: i_state];
701 }
702
703 #pragma mark -
704 #pragma mark video menu
705 - (IBAction)toggleFullscreen:(id)sender
706 {
707     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
708 }
709
710 - (IBAction)resizeVideoWindow:(id)sender
711 {
712     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
713     if (p_input)
714     {
715         vout_thread_t *p_vout = getVout();
716         if (p_vout)
717         {
718             if (sender == o_mi_half_window)
719                 var_SetFloat( p_vout, "zoom", 0.5 );
720             else if (sender == o_mi_normal_window)
721                 var_SetFloat( p_vout, "zoom", 1.0 );
722             else if (sender == o_mi_double_window)
723                 var_SetFloat( p_vout, "zoom", 2.0 );
724             else
725             {
726                 [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
727             }
728             vlc_object_release( p_vout );
729         }
730         vlc_object_release( p_input );
731     }
732 }
733
734 - (IBAction)floatOnTop:(id)sender
735 {
736     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
737     if (p_input)
738     {
739         vout_thread_t *p_vout = getVout();
740         if (p_vout)
741         {
742             var_ToggleBool( p_vout, "video-on-top" );
743             vlc_object_release( p_vout );
744         }
745         vlc_object_release( p_input );
746     }
747 }
748
749 - (IBAction)createVideoSnapshot:(id)sender
750 {
751     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
752     if (p_input)
753     {
754         vout_thread_t *p_vout = getVout();
755         if (p_vout)
756         {
757             var_TriggerCallback( p_vout, "video-snapshot" );
758             vlc_object_release( p_vout );
759         }
760         vlc_object_release( p_input );
761     }
762 }
763
764 - (IBAction)toggleFullscreenDevice:(id)sender
765 {
766     config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
767     [self refreshVoutDeviceMenu: nil];
768 }
769
770 - (id)voutMenu
771 {
772     return o_vout_menu;
773 }
774
775 #pragma mark -
776 #pragma mark Panels
777
778 - (IBAction)intfOpenFile:(id)sender
779 {
780     [[[VLCMain sharedInstance] open] openFile];
781 }
782
783 - (IBAction)intfOpenFileGeneric:(id)sender
784 {
785     [[[VLCMain sharedInstance] open] openFileGeneric];
786 }
787
788 - (IBAction)intfOpenDisc:(id)sender
789 {
790     [[[VLCMain sharedInstance] open] openDisc];
791 }
792
793 - (IBAction)intfOpenNet:(id)sender
794 {
795     [[[VLCMain sharedInstance] open] openNet];
796 }
797
798 - (IBAction)intfOpenCapture:(id)sender
799 {
800     [[[VLCMain sharedInstance] open] openCapture];
801 }
802
803 - (IBAction)showWizard:(id)sender
804 {
805     [[[VLCMain sharedInstance] wizard] resetWizard];
806     [[[VLCMain sharedInstance] wizard] showWizard];
807 }
808
809 - (IBAction)showConvertAndSave:(id)sender
810 {
811     if( o_convertandsave == nil )
812         o_convertandsave = [[VLCConvertAndSave alloc] init];
813
814     if( !b_nib_convertandsave_loaded )
815         b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];
816
817     [o_convertandsave toggleWindow];
818 }
819
820 - (IBAction)showVideoEffects:(id)sender
821 {
822     if( o_videoeffects == nil )
823         o_videoeffects = [[VLCVideoEffects alloc] init];
824
825     if( !b_nib_videoeffects_loaded )
826         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
827
828     [o_videoeffects toggleWindow:sender];
829 }
830
831 - (IBAction)showTrackSynchronization:(id)sender
832 {
833     if (!o_trackSynchronization)
834         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
835
836     if (!b_nib_tracksynchro_loaded)
837         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
838
839     [o_trackSynchronization toggleWindow:sender];
840 }
841
842 - (IBAction)showAudioEffects:(id)sender
843 {
844     if (!o_audioeffects)
845         o_audioeffects = [[VLCAudioEffects alloc] init];
846
847     if (!b_nib_audioeffects_loaded)
848         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
849
850     [o_audioeffects toggleWindow:sender];
851 }
852
853 - (IBAction)showBookmarks:(id)sender
854 {
855     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
856 }
857
858 - (IBAction)viewPreferences:(id)sender
859 {
860     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
861 }
862
863 #pragma mark -
864 #pragma mark Help and Docs
865
866 - (void)initAbout
867 {
868     if(! o_about )
869         o_about = [[VLAboutBox alloc] init];
870
871     if( !b_nib_about_loaded )
872         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
873 }
874
875 - (IBAction)viewAbout:(id)sender
876 {
877     [self initAbout];
878     [o_about showAbout];
879 }
880
881 - (IBAction)showLicense:(id)sender
882 {
883     [self initAbout];
884     [o_about showGPL: sender];
885 }
886
887 - (IBAction)viewHelp:(id)sender
888 {
889     [self initAbout];
890     [o_about showHelp];
891 }
892
893 - (IBAction)openReadMe:(id)sender
894 {
895     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
896
897     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
898 }
899
900 - (IBAction)openDocumentation:(id)sender
901 {
902     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
903
904     [[NSWorkspace sharedWorkspace] openURL: o_url];
905 }
906
907 - (IBAction)openWebsite:(id)sender
908 {
909     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
910
911     [[NSWorkspace sharedWorkspace] openURL: o_url];
912 }
913
914 - (IBAction)openForum:(id)sender
915 {
916     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
917
918     [[NSWorkspace sharedWorkspace] openURL: o_url];
919 }
920
921 - (IBAction)openDonate:(id)sender
922 {
923     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
924
925     [[NSWorkspace sharedWorkspace] openURL: o_url];
926 }
927
928 #pragma mark -
929 #pragma mark Errors, warnings and messages
930
931 - (IBAction)viewErrorsAndWarnings:(id)sender
932 {
933     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
934 }
935
936 - (IBAction)showInformationPanel:(id)sender
937 {
938     [[[VLCMain sharedInstance] info] initPanel];
939 }
940
941 #pragma mark -
942 #pragma mark convinience stuff for other objects
943 - (void)setPlay
944 {
945     [o_mi_play setTitle: _NS("Play")];
946     [o_dmi_play setTitle: _NS("Play")];
947     [o_vmi_play setTitle: _NS("Play")];
948 }
949
950 - (void)setPause
951 {
952     [o_mi_play setTitle: _NS("Pause")];
953     [o_dmi_play setTitle: _NS("Pause")];
954     [o_vmi_play setTitle: _NS("Pause")];
955 }
956
957 - (void)setRepeatOne
958 {
959     [o_mi_repeat setState: NSOnState];
960     [o_mi_loop setState: NSOffState];
961 }
962
963 - (void)setRepeatAll
964 {
965     [o_mi_repeat setState: NSOffState];
966     [o_mi_loop setState: NSOnState];
967 }
968
969 - (void)setRepeatOff
970 {
971     [o_mi_repeat setState: NSOffState];
972     [o_mi_loop setState: NSOffState];
973 }
974
975 - (void)setShuffle
976 {
977     bool b_value;
978     playlist_t *p_playlist = pl_Get( VLCIntf );
979     b_value = var_GetBool( p_playlist, "random" );
980
981     [o_mi_random setState: b_value];
982 }
983
984 #pragma mark -
985 #pragma mark Dynamic menu creation and validation
986
987 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
988                   target:(vlc_object_t *)p_object
989                      var:(const char *)psz_variable
990                 selector:(SEL)pf_callback
991 {
992     vlc_value_t val, text;
993     int i_type = var_Type( p_object, psz_variable );
994
995     switch( i_type & VLC_VAR_TYPE )
996     {
997         case VLC_VAR_VOID:
998         case VLC_VAR_BOOL:
999         case VLC_VAR_VARIABLE:
1000         case VLC_VAR_STRING:
1001         case VLC_VAR_INTEGER:
1002             break;
1003         default:
1004             /* Variable doesn't exist or isn't handled */
1005             return;
1006     }
1007
1008     /* Make sure we want to display the variable
1009      * special case for spu-es, which we want to display in any case */
1010     if( i_type & VLC_VAR_HASCHOICE && strcmp( psz_variable, "spu-es" ) )
1011     {
1012         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1013         if( val.i_int == 0 )
1014             return;
1015         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1016             return;
1017     }
1018
1019     /* Get the descriptive name of the variable */
1020     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
1021     [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
1022
1023     if( i_type & VLC_VAR_HASCHOICE )
1024     {
1025         NSMenu *o_menu = [o_mi submenu];
1026
1027         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
1028                        var:psz_variable selector:pf_callback];
1029
1030         free( text.psz_string );
1031         return;
1032     }
1033
1034     if( var_Get( p_object, psz_variable, &val ) < 0 )
1035     {
1036         return;
1037     }
1038
1039     VLCAutoGeneratedMenuContent *o_data;
1040     switch( i_type & VLC_VAR_TYPE )
1041     {
1042         case VLC_VAR_VOID:
1043             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1044                                                                       andValue: val ofType: i_type];
1045             [o_mi setRepresentedObject: [o_data autorelease]];
1046             break;
1047
1048         case VLC_VAR_BOOL:
1049             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1050                                                                       andValue: val ofType: i_type];
1051             [o_mi setRepresentedObject: [o_data autorelease]];
1052             if( !( i_type & VLC_VAR_ISCOMMAND ) )
1053                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
1054             break;
1055
1056         default:
1057             break;
1058     }
1059
1060     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
1061     free( text.psz_string );
1062 }
1063
1064
1065 - (void)setupVarMenu:(NSMenu *)o_menu
1066          forMenuItem: (NSMenuItem *)o_parent
1067               target:(vlc_object_t *)p_object
1068                  var:(const char *)psz_variable
1069             selector:(SEL)pf_callback
1070 {
1071     vlc_value_t val, val_list, text_list;
1072     int i_type, i;
1073
1074     /* remove previous items */
1075     if (OSX_LEOPARD)
1076     {
1077         int i_nb_items;
1078         i_nb_items = [o_menu numberOfItems];
1079         for( i = 0; i < i_nb_items; i++ )
1080             [o_menu removeItemAtIndex: 0];
1081     }
1082     else
1083     {
1084         /* this is more efficient then the legacy code, but 10.6+ only */
1085         [o_menu removeAllItems];
1086     }
1087
1088     /* Aspect Ratio */
1089     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
1090     {
1091         NSMenuItem *o_lmi_tmp2;
1092         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1093         [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1094         [o_lmi_tmp2 setEnabled: YES];
1095         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1096         [o_parent setEnabled: YES];
1097         [o_menu addItem: [NSMenuItem separatorItem]];
1098     }
1099
1100     /* special case for the subtitles item */
1101     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1102     {
1103         NSMenuItem * o_lmi_tmp;
1104         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1105         [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
1106         [o_lmi_tmp setEnabled: YES];
1107         [o_parent setEnabled: YES];
1108     }
1109
1110     /* Check the type of the object variable */
1111     i_type = var_Type( p_object, psz_variable );
1112
1113     /* Make sure we want to display the variable */
1114     if( i_type & VLC_VAR_HASCHOICE )
1115     {
1116         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1117         if( val.i_int == 0 ) return;
1118         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1119             return;
1120     }
1121     else
1122         return;
1123
1124     switch( i_type & VLC_VAR_TYPE )
1125     {
1126         case VLC_VAR_VOID:
1127         case VLC_VAR_BOOL:
1128         case VLC_VAR_VARIABLE:
1129         case VLC_VAR_STRING:
1130         case VLC_VAR_INTEGER:
1131             break;
1132         default:
1133             /* Variable doesn't exist or isn't handled */
1134             return;
1135     }
1136
1137     if( var_Get( p_object, psz_variable, &val ) < 0 )
1138     {
1139         return;
1140     }
1141
1142     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1143                    &val_list, &text_list ) < 0 )
1144     {
1145         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1146         return;
1147     }
1148
1149     /* make (un)sensitive */
1150     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1151
1152     /* another special case for the subtitles item */
1153     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1154         [o_menu addItem: [NSMenuItem separatorItem]];
1155
1156     for( i = 0; i < val_list.p_list->i_count; i++ )
1157     {
1158         NSMenuItem * o_lmi;
1159         NSString *o_title = @"";
1160         VLCAutoGeneratedMenuContent *o_data;
1161
1162         switch( i_type & VLC_VAR_TYPE )
1163         {
1164             case VLC_VAR_STRING:
1165
1166                 o_title = _NS( text_list.p_list->p_values[i].psz_string ? text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string );
1167
1168                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1169                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1170                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1171                 [o_lmi setRepresentedObject: [o_data autorelease]];
1172                 [o_lmi setTarget: self];
1173
1174                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1175                     [o_lmi setState: TRUE ];
1176
1177                 break;
1178
1179             case VLC_VAR_INTEGER:
1180
1181                 o_title = text_list.p_list->p_values[i].psz_string ?
1182                 _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1183
1184                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1185                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1186                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1187                 [o_lmi setRepresentedObject: [o_data autorelease]];
1188                 [o_lmi setTarget: self];
1189
1190                 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1191                     [o_lmi setState: TRUE ];
1192                 break;
1193
1194             default:
1195                 break;
1196         }
1197     }
1198
1199     /* special case for the subtitles sub-menu
1200      * In case that we don't have any subs, we don't want a separator item at the end */
1201     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1202     {
1203         if( [o_menu numberOfItems] == 2 )
1204             [o_menu removeItemAtIndex: 1];
1205     }
1206
1207     /* clean up everything */
1208     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1209     var_FreeList( &val_list, &text_list );
1210 }
1211
1212 - (IBAction)toggleVar:(id)sender
1213 {
1214     NSMenuItem *o_mi = (NSMenuItem *)sender;
1215     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1216     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1217                              toTarget: self withObject: o_data];
1218
1219     return;
1220 }
1221
1222 - (int)toggleVarThread: (id)data
1223 {
1224     vlc_object_t *p_object;
1225     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1226
1227     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1228     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1229
1230     /* Preserve settings across vouts via the playlist object: */
1231     if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
1232         var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
1233
1234     /* save our audio device across multiple sessions */
1235     if( !strcmp( [menuContent name], "audio-device" ) )
1236         config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
1237
1238     p_object = [menuContent vlcObject];
1239
1240     if( p_object != NULL )
1241     {
1242         var_Set( p_object, [menuContent name], [menuContent value] );
1243         vlc_object_release( p_object );
1244         [o_pool release];
1245         return true;
1246     }
1247     [o_pool release];
1248     return VLC_EGENERIC;
1249 }
1250
1251 @end
1252
1253 @implementation VLCMainMenu (NSMenuValidation)
1254
1255 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1256 {
1257     NSString *o_title = [o_mi title];
1258     BOOL bEnabled = TRUE;
1259     vlc_value_t val;
1260     playlist_t * p_playlist = pl_Get( p_intf );
1261     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1262
1263     if( [o_title isEqualToString: _NS("Stop")] )
1264     {
1265         if( p_input == NULL )
1266         {
1267             bEnabled = FALSE;
1268         }
1269         [self setupMenus]; /* Make sure input menu is up to date */
1270     }
1271     else if( [o_title isEqualToString: _NS("Previous")] ||
1272             [o_title isEqualToString: _NS("Next")] )
1273     {
1274         PL_LOCK;
1275         bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1276         PL_UNLOCK;
1277     }
1278     else if( [o_title isEqualToString: _NS("Random")] )
1279     {
1280         int i_state;
1281         var_Get( p_playlist, "random", &val );
1282         i_state = val.b_bool ? NSOnState : NSOffState;
1283         [o_mi setState: i_state];
1284     }
1285     else if( [o_title isEqualToString: _NS("Repeat One")] )
1286     {
1287         int i_state;
1288         var_Get( p_playlist, "repeat", &val );
1289         i_state = val.b_bool ? NSOnState : NSOffState;
1290         [o_mi setState: i_state];
1291     }
1292     else if( [o_title isEqualToString: _NS("Repeat All")] )
1293     {
1294         int i_state;
1295         var_Get( p_playlist, "loop", &val );
1296         i_state = val.b_bool ? NSOnState : NSOffState;
1297         [o_mi setState: i_state];
1298     }
1299     else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1300     {
1301         int i_state;
1302         var_Get( p_playlist, "play-and-exit", &val );
1303         i_state = val.b_bool ? NSOnState : NSOffState;
1304         [o_mi setState: i_state];
1305     }
1306     else if( [o_title isEqualToString: _NS("Step Forward")] ||
1307             [o_title isEqualToString: _NS("Step Backward")] ||
1308             [o_title isEqualToString: _NS("Jump To Time")])
1309     {
1310         if( p_input != NULL )
1311         {
1312             var_Get( p_input, "can-seek", &val);
1313             bEnabled = val.b_bool;
1314         }
1315         else bEnabled = FALSE;
1316     }
1317     else if( [o_title isEqualToString: _NS("Mute")] )
1318     {
1319         [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1320         [self setupMenus]; /* Make sure audio menu is up to date */
1321     }
1322     else if( [o_title isEqualToString: _NS("Half Size")] ||
1323             [o_title isEqualToString: _NS("Normal Size")] ||
1324             [o_title isEqualToString: _NS("Double Size")] ||
1325             [o_title isEqualToString: _NS("Fit to Screen")] ||
1326             [o_title isEqualToString: _NS("Snapshot")] ||
1327             [o_title isEqualToString: _NS("Fullscreen")] ||
1328             [o_title isEqualToString: _NS("Float on Top")] )
1329     {
1330         bEnabled = FALSE;
1331
1332         if( p_input != NULL )
1333         {
1334             vout_thread_t *p_vout = input_GetVout( p_input );
1335             if( p_vout != NULL )
1336             {
1337                 if( [o_title isEqualToString: _NS("Float on Top")] )
1338                 {
1339                     [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1340                 }
1341
1342                 bEnabled = TRUE;
1343
1344                 vlc_object_release( (vlc_object_t *)p_vout );
1345             }
1346         }
1347         if( [o_title isEqualToString: _NS("Fullscreen")] )
1348         {
1349         [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1350             bEnabled = TRUE;
1351         }
1352         [self setupMenus]; /* Make sure video menu is up to date */
1353     }
1354
1355     /* Special case for telx menu */
1356     if( [o_title isEqualToString: _NS("Normal Size")] )
1357     {
1358         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1359
1360
1361 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1362
1363         [[item submenu] setAutoenablesItems:NO];
1364         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1365         {
1366             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1367         }
1368     }
1369
1370     if( p_input ) vlc_object_release( p_input );
1371
1372     return( bEnabled );
1373 }
1374
1375 @end
1376
1377
1378 /*****************************************************************************
1379  * VLCAutoGeneratedMenuContent implementation
1380  *****************************************************************************
1381  * Object connected to a playlistitem which remembers the data belonging to
1382  * the variable of the autogenerated menu
1383  *****************************************************************************/
1384 @implementation VLCAutoGeneratedMenuContent
1385
1386 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1387                   andValue:(vlc_value_t)val ofType:(int)type
1388 {
1389     self = [super init];
1390
1391     if( self != nil )
1392     {
1393         _vlc_object = vlc_object_hold( object );
1394         psz_name = strdup( name );
1395         i_type = type;
1396         value = val;
1397         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1398             value.psz_string = strdup( val.psz_string );
1399     }
1400
1401     return( self );
1402 }
1403
1404 - (void)dealloc
1405 {
1406     vlc_object_release( _vlc_object );
1407     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1408         free( value.psz_string );
1409     free( psz_name );
1410     [super dealloc];
1411 }
1412
1413 - (const char *)name
1414 {
1415     return psz_name;
1416 }
1417
1418 - (vlc_value_t)value
1419 {
1420     return value;
1421 }
1422
1423 - (vlc_object_t *)vlcObject
1424 {
1425     return vlc_object_hold( _vlc_object );
1426 }
1427
1428
1429 - (int)type
1430 {
1431     return i_type;
1432 }
1433
1434 @end