]> git.sesse.net Git - vlc/blob - modules/gui/macosx/MainMenu.m
3803228ba19071c00f25b810744f7ee9ee8066a9
[vlc] / 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( p_aout );
466         }
467
468         vout_thread_t * p_vout = input_GetVout( p_input );
469
470         if( p_vout != NULL )
471         {
472             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
473                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
474
475             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
476                                      var: "crop" selector: @selector(toggleVar:)];
477
478             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
479                                      var: "deinterlace" selector: @selector(toggleVar:)];
480
481             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
482                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
483
484 #if 1
485             [self setupVarMenuItem: o_mi_ffmpeg_pp target:
486              (vlc_object_t *)p_vout var:"postprocess" selector:
487              @selector(toggleVar:)];
488 #endif
489             vlc_object_release( p_vout );
490
491             [self refreshVoutDeviceMenu:nil];
492         }
493         vlc_object_release( p_input );
494     }
495     else
496     {
497         [o_mi_record setEnabled: NO];
498     }
499 }
500
501 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
502 {
503     NSUInteger count = [o_mu_screen numberOfItems];
504     NSMenu * o_submenu = o_mu_screen;
505     if (count > 0)
506     {
507         if (OSX_LEOPARD)
508         {
509             NSUInteger count = [o_submenu numberOfItems];
510             for( NSUInteger i = 0; i < count; i++ )
511                 [o_submenu removeItemAtIndex: 0];
512         }
513         else
514             [o_submenu removeAllItems];
515     }
516
517     NSArray * o_screens = [NSScreen screens];
518     NSMenuItem * o_mitem;
519     count = [o_screens count];
520     [o_mi_screen setEnabled: YES];
521     [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
522     o_mitem = [o_submenu itemAtIndex: 0];
523     [o_mitem setTag: 0];
524     [o_mitem setEnabled: YES];
525     [o_mitem setTarget: self];
526     NSRect s_rect;
527     for (NSUInteger i = 0; i < count; i++)
528     {
529         s_rect = [[o_screens objectAtIndex: i] frame];
530         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
531                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
532         o_mitem = [o_submenu itemAtIndex:i+1];
533         [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
534         [o_mitem setEnabled: YES];
535         [o_mitem setTarget: self];
536     }
537     [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
538 }
539
540 - (void)setSubmenusEnabled:(BOOL)b_enabled
541 {
542     [o_mi_program setEnabled: b_enabled];
543     [o_mi_title setEnabled: b_enabled];
544     [o_mi_chapter setEnabled: b_enabled];
545     [o_mi_audiotrack setEnabled: b_enabled];
546     [o_mi_visual setEnabled: b_enabled];
547     [o_mi_videotrack setEnabled: b_enabled];
548     [o_mi_subtitle setEnabled: b_enabled];
549     [o_mi_channels setEnabled: b_enabled];
550     [o_mi_deinterlace setEnabled: b_enabled];
551     [o_mi_deinterlace_mode setEnabled: b_enabled];
552     [o_mi_ffmpeg_pp setEnabled: b_enabled];
553     [o_mi_device setEnabled: b_enabled];
554     [o_mi_screen setEnabled: b_enabled];
555     [o_mi_aspect_ratio setEnabled: b_enabled];
556     [o_mi_crop setEnabled: b_enabled];
557     [o_mi_teletext setEnabled: b_enabled];
558 }
559
560 - (void)setRateControlsEnabled:(BOOL)b_enabled
561 {
562     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
563     [o_mi_rate_sld setEnabled: b_enabled];
564     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
565     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
566     double speed =  pow( 2, (double)i / 17 );
567     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
568     if (b_enabled) {
569         [o_mi_rate_lbl setHidden: NO];
570         [o_mi_rate_lbl_gray setHidden: YES];
571     }
572     else
573     {
574         [o_mi_rate_lbl setHidden: YES];
575         [o_mi_rate_lbl_gray setHidden: NO];
576     }
577     [o_pool release];
578 }
579
580 #pragma mark -
581 #pragma mark Extensions
582
583 - (void)setupExtensionsMenu
584 {
585     /* Load extensions if needed */
586     // TODO: Implement preference for autoloading extensions on mac
587
588     // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
589     //     && ![o_extMgr isLoaded] )
590     // {
591     //     return;
592     // }
593
594     if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
595     {
596         [o_extMgr loadExtensions];
597     }
598
599     /* Let the ExtensionsManager itself build the menu */
600     [o_extMgr buildMenu:o_mu_extensions];
601     [o_mi_extensions setEnabled: ( [o_mu_extensions numberOfItems] > 0 )];
602 }
603
604 #pragma mark -
605 #pragma mark Playback
606 - (IBAction)toggleRecord:(id)sender
607 {
608     [[VLCCoreInteraction sharedInstance] toggleRecord];
609 }
610
611 - (void)updateRecordState:(BOOL)b_value
612 {
613     [o_mi_record setState:b_value];
614 }
615
616 - (IBAction)setPlaybackRate:(id)sender
617 {
618     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
619     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
620     double speed =  pow( 2, (double)i / 17 );
621     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
622 }
623
624 - (void)updatePlaybackRate
625 {
626     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
627     double speed =  pow( 2, (double)i / 17 );
628     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
629     [o_mi_rate_sld setIntValue: i];
630 }
631
632 - (IBAction)toggleJumpButtons:(id)sender
633 {
634     BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playback-buttons" );
635     config_PutInt( VLCIntf, "macosx-show-playback-buttons", b_value );
636     [[[VLCMain sharedInstance] mainWindow] toggleJumpButtons];
637     [o_mi_toggleJumpButtons setState: b_value];
638 }
639
640 - (IBAction)togglePlaymodeButtons:(id)sender
641 {
642     BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playmode-buttons" );
643     config_PutInt( VLCIntf, "macosx-show-playmode-buttons", b_value );
644     [[[VLCMain sharedInstance] mainWindow] togglePlaymodeButtons];
645     [o_mi_togglePlaymodeButtons setState: b_value];
646 }
647
648 - (IBAction)togglePlaylistColumnTable:(id)sender
649 {
650     [sender setState: ![sender state]];
651
652     NSString * o_column;
653
654     if (sender == o_mi_ptc_tracknum)
655         o_column = TRACKNUM_COLUMN;
656     else if (sender == o_mi_ptc_title)
657         o_column = TITLE_COLUMN;
658     else if (sender == o_mi_ptc_artist)
659         o_column = ARTIST_COLUMN;
660     else if (sender == o_mi_ptc_duration)
661         o_column = DURATION_COLUMN;
662     else if (sender == o_mi_ptc_genre)
663         o_column = GENRE_COLUMN;
664     else if (sender == o_mi_ptc_album)
665         o_column = ALBUM_COLUMN;
666     else if (sender == o_mi_ptc_description)
667         o_column = DESCRIPTION_COLUMN;
668     else if (sender == o_mi_ptc_date)
669         o_column = DATE_COLUMN;
670     else if (sender == o_mi_ptc_language)
671         o_column = LANGUAGE_COLUMN;
672     else if (sender == o_mi_ptc_uri)
673         o_column = URI_COLUMN;
674
675     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: [sender state]];
676 }
677
678 - (void)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
679 {
680     if ([o_column isEqualToString: TRACKNUM_COLUMN])
681         [o_mi_ptc_tracknum setState: i_state];
682     else if ([o_column isEqualToString: TITLE_COLUMN])
683         [o_mi_ptc_title setState: i_state];
684     else if ([o_column isEqualToString: ARTIST_COLUMN])
685         [o_mi_ptc_artist setState: i_state];
686     else if ([o_column isEqualToString: DURATION_COLUMN])
687         [o_mi_ptc_duration setState: i_state];
688     else if ([o_column isEqualToString: GENRE_COLUMN])
689         [o_mi_ptc_genre setState: i_state];
690     else if ([o_column isEqualToString: ALBUM_COLUMN])
691         [o_mi_ptc_album setState: i_state];
692     else if ([o_column isEqualToString: DESCRIPTION_COLUMN])
693         [o_mi_ptc_description setState: i_state];
694     else if ([o_column isEqualToString: DATE_COLUMN])
695         [o_mi_ptc_date setState: i_state];
696     else if ([o_column isEqualToString: LANGUAGE_COLUMN])
697         [o_mi_ptc_language setState: i_state];
698     else if ([o_column isEqualToString: URI_COLUMN])
699         [o_mi_ptc_uri setState: i_state];
700 }
701
702 #pragma mark -
703 #pragma mark video menu
704 - (IBAction)toggleFullscreen:(id)sender
705 {
706     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
707 }
708
709 - (IBAction)resizeVideoWindow:(id)sender
710 {
711     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
712     if (p_input)
713     {
714         vout_thread_t *p_vout = getVout();
715         if (p_vout)
716         {
717             if (sender == o_mi_half_window)
718                 var_SetFloat( p_vout, "zoom", 0.5 );
719             else if (sender == o_mi_normal_window)
720                 var_SetFloat( p_vout, "zoom", 1.0 );
721             else if (sender == o_mi_double_window)
722                 var_SetFloat( p_vout, "zoom", 2.0 );
723             else
724             {
725                 [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
726             }
727             vlc_object_release( p_vout );
728         }
729         vlc_object_release( p_input );
730     }
731 }
732
733 - (IBAction)floatOnTop:(id)sender
734 {
735     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
736     if (p_input)
737     {
738         vout_thread_t *p_vout = getVout();
739         if (p_vout)
740         {
741             var_ToggleBool( p_vout, "video-on-top" );
742             vlc_object_release( p_vout );
743         }
744         vlc_object_release( p_input );
745     }
746 }
747
748 - (IBAction)createVideoSnapshot:(id)sender
749 {
750     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
751     if (p_input)
752     {
753         vout_thread_t *p_vout = getVout();
754         if (p_vout)
755         {
756             var_TriggerCallback( p_vout, "video-snapshot" );
757             vlc_object_release( p_vout );
758         }
759         vlc_object_release( p_input );
760     }
761 }
762
763 - (IBAction)toggleFullscreenDevice:(id)sender
764 {
765     config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
766     [self refreshVoutDeviceMenu: nil];
767 }
768
769 - (id)voutMenu
770 {
771     return o_vout_menu;
772 }
773
774 #pragma mark -
775 #pragma mark Panels
776
777 - (IBAction)intfOpenFile:(id)sender
778 {
779     [[[VLCMain sharedInstance] open] openFile];
780 }
781
782 - (IBAction)intfOpenFileGeneric:(id)sender
783 {
784     [[[VLCMain sharedInstance] open] openFileGeneric];
785 }
786
787 - (IBAction)intfOpenDisc:(id)sender
788 {
789     [[[VLCMain sharedInstance] open] openDisc];
790 }
791
792 - (IBAction)intfOpenNet:(id)sender
793 {
794     [[[VLCMain sharedInstance] open] openNet];
795 }
796
797 - (IBAction)intfOpenCapture:(id)sender
798 {
799     [[[VLCMain sharedInstance] open] openCapture];
800 }
801
802 - (IBAction)showWizard:(id)sender
803 {
804     [[[VLCMain sharedInstance] wizard] resetWizard];
805     [[[VLCMain sharedInstance] wizard] showWizard];
806 }
807
808 - (IBAction)showConvertAndSave:(id)sender
809 {
810     if( o_convertandsave == nil )
811         o_convertandsave = [[VLCConvertAndSave alloc] init];
812
813     if( !b_nib_convertandsave_loaded )
814         b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];
815
816     [o_convertandsave toggleWindow];
817 }
818
819 - (IBAction)showVideoEffects:(id)sender
820 {
821     if( o_videoeffects == nil )
822         o_videoeffects = [[VLCVideoEffects alloc] init];
823
824     if( !b_nib_videoeffects_loaded )
825         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
826
827     [o_videoeffects toggleWindow:sender];
828 }
829
830 - (IBAction)showTrackSynchronization:(id)sender
831 {
832     if (!o_trackSynchronization)
833         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
834
835     if (!b_nib_tracksynchro_loaded)
836         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
837
838     [o_trackSynchronization toggleWindow:sender];
839 }
840
841 - (IBAction)showAudioEffects:(id)sender
842 {
843     if (!o_audioeffects)
844         o_audioeffects = [[VLCAudioEffects alloc] init];
845
846     if (!b_nib_audioeffects_loaded)
847         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
848
849     [o_audioeffects toggleWindow:sender];
850 }
851
852 - (IBAction)showBookmarks:(id)sender
853 {
854     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
855 }
856
857 - (IBAction)viewPreferences:(id)sender
858 {
859     NSInteger i_level = NSNormalWindowLevel;
860     NSInteger i_video_window_level = [[[[VLCMainWindow sharedInstance] videoView] window] level];
861     if( i_video_window_level == NSStatusWindowLevel )
862         i_level = NSStatusWindowLevel;
863     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
864 }
865
866 #pragma mark -
867 #pragma mark Help and Docs
868
869 - (void)initAbout
870 {
871     if(! o_about )
872         o_about = [[VLAboutBox alloc] init];
873
874     if( !b_nib_about_loaded )
875         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
876 }
877
878 - (IBAction)viewAbout:(id)sender
879 {
880     [self initAbout];
881     [o_about showAbout];
882 }
883
884 - (IBAction)showLicense:(id)sender
885 {
886     [self initAbout];
887     [o_about showGPL: sender];
888 }
889
890 - (IBAction)viewHelp:(id)sender
891 {
892     [self initAbout];
893     [o_about showHelp];
894 }
895
896 - (IBAction)openReadMe:(id)sender
897 {
898     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
899
900     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
901 }
902
903 - (IBAction)openDocumentation:(id)sender
904 {
905     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
906
907     [[NSWorkspace sharedWorkspace] openURL: o_url];
908 }
909
910 - (IBAction)openWebsite:(id)sender
911 {
912     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
913
914     [[NSWorkspace sharedWorkspace] openURL: o_url];
915 }
916
917 - (IBAction)openForum:(id)sender
918 {
919     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
920
921     [[NSWorkspace sharedWorkspace] openURL: o_url];
922 }
923
924 - (IBAction)openDonate:(id)sender
925 {
926     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
927
928     [[NSWorkspace sharedWorkspace] openURL: o_url];
929 }
930
931 #pragma mark -
932 #pragma mark Errors, warnings and messages
933
934 - (IBAction)viewErrorsAndWarnings:(id)sender
935 {
936     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
937 }
938
939 - (IBAction)showInformationPanel:(id)sender
940 {
941     [[[VLCMain sharedInstance] info] initPanel];
942 }
943
944 #pragma mark -
945 #pragma mark convinience stuff for other objects
946 - (void)setPlay
947 {
948     [o_mi_play setTitle: _NS("Play")];
949     [o_dmi_play setTitle: _NS("Play")];
950     [o_vmi_play setTitle: _NS("Play")];
951 }
952
953 - (void)setPause
954 {
955     [o_mi_play setTitle: _NS("Pause")];
956     [o_dmi_play setTitle: _NS("Pause")];
957     [o_vmi_play setTitle: _NS("Pause")];
958 }
959
960 - (void)setRepeatOne
961 {
962     [o_mi_repeat setState: NSOnState];
963     [o_mi_loop setState: NSOffState];
964 }
965
966 - (void)setRepeatAll
967 {
968     [o_mi_repeat setState: NSOffState];
969     [o_mi_loop setState: NSOnState];
970 }
971
972 - (void)setRepeatOff
973 {
974     [o_mi_repeat setState: NSOffState];
975     [o_mi_loop setState: NSOffState];
976 }
977
978 - (void)setShuffle
979 {
980     bool b_value;
981     playlist_t *p_playlist = pl_Get( VLCIntf );
982     b_value = var_GetBool( p_playlist, "random" );
983
984     [o_mi_random setState: b_value];
985 }
986
987 #pragma mark -
988 #pragma mark Dynamic menu creation and validation
989
990 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
991                   target:(vlc_object_t *)p_object
992                      var:(const char *)psz_variable
993                 selector:(SEL)pf_callback
994 {
995     vlc_value_t val, text;
996     int i_type = var_Type( p_object, psz_variable );
997
998     switch( i_type & VLC_VAR_TYPE )
999     {
1000         case VLC_VAR_VOID:
1001         case VLC_VAR_BOOL:
1002         case VLC_VAR_VARIABLE:
1003         case VLC_VAR_STRING:
1004         case VLC_VAR_INTEGER:
1005             break;
1006         default:
1007             /* Variable doesn't exist or isn't handled */
1008             return;
1009     }
1010
1011     /* Get the descriptive name of the variable */
1012     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
1013     [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
1014
1015     if( i_type & VLC_VAR_HASCHOICE )
1016     {
1017         NSMenu *o_menu = [o_mi submenu];
1018
1019         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
1020                        var:psz_variable selector:pf_callback];
1021
1022         free( text.psz_string );
1023         return;
1024     }
1025
1026     if( var_Get( p_object, psz_variable, &val ) < 0 )
1027     {
1028         return;
1029     }
1030
1031     VLCAutoGeneratedMenuContent *o_data;
1032     switch( i_type & VLC_VAR_TYPE )
1033     {
1034         case VLC_VAR_VOID:
1035             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1036                                                                       andValue: val ofType: i_type];
1037             [o_mi setRepresentedObject: [o_data autorelease]];
1038             break;
1039
1040         case VLC_VAR_BOOL:
1041             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1042                                                                       andValue: val ofType: i_type];
1043             [o_mi setRepresentedObject: [o_data autorelease]];
1044             if( !( i_type & VLC_VAR_ISCOMMAND ) )
1045                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
1046             break;
1047
1048         default:
1049             break;
1050     }
1051
1052     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
1053     free( text.psz_string );
1054 }
1055
1056
1057 - (void)setupVarMenu:(NSMenu *)o_menu
1058          forMenuItem: (NSMenuItem *)o_parent
1059               target:(vlc_object_t *)p_object
1060                  var:(const char *)psz_variable
1061             selector:(SEL)pf_callback
1062 {
1063     vlc_value_t val, val_list, text_list;
1064     int i_type, i;
1065
1066     /* remove previous items */
1067     if (OSX_LEOPARD)
1068     {
1069         int i_nb_items;
1070         i_nb_items = [o_menu numberOfItems];
1071         for( i = 0; i < i_nb_items; i++ )
1072             [o_menu removeItemAtIndex: 0];
1073     }
1074     else
1075     {
1076         /* this is more efficient then the legacy code, but 10.6+ only */
1077         [o_menu removeAllItems];
1078     }
1079     /* we disable everything here, and enable it again when needed, below */
1080     [o_parent setEnabled:NO];
1081
1082     /* Aspect Ratio */
1083     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
1084     {
1085         NSMenuItem *o_lmi_tmp2;
1086         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1087         [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1088         [o_lmi_tmp2 setEnabled: YES];
1089         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1090         [o_parent setEnabled: YES];
1091         [o_menu addItem: [NSMenuItem separatorItem]];
1092     }
1093
1094     /* special case for the subtitles item */
1095     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1096     {
1097         NSMenuItem * o_lmi_tmp;
1098         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1099         [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
1100         [o_lmi_tmp setEnabled: YES];
1101         [o_parent setEnabled: YES];
1102     }
1103
1104     /* Check the type of the object variable */
1105     i_type = var_Type( p_object, psz_variable );
1106
1107     /* Make sure we want to display the variable */
1108     if( i_type & VLC_VAR_HASCHOICE )
1109     {
1110         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1111         if( val.i_int == 0 ) 
1112             return;
1113         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1114             return;
1115     }
1116     else
1117         return;
1118
1119     switch( i_type & VLC_VAR_TYPE )
1120     {
1121         case VLC_VAR_VOID:
1122         case VLC_VAR_BOOL:
1123         case VLC_VAR_VARIABLE:
1124         case VLC_VAR_STRING:
1125         case VLC_VAR_INTEGER:
1126             break;
1127         default:
1128             /* Variable doesn't exist or isn't handled */
1129             return;
1130     }
1131
1132     if( var_Get( p_object, psz_variable, &val ) < 0 )
1133     {
1134         return;
1135     }
1136
1137     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1138                    &val_list, &text_list ) < 0 )
1139     {
1140         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1141         return;
1142     }
1143
1144     /* make (un)sensitive */
1145     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1146
1147     /* another special case for the subtitles item */
1148     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1149         [o_menu addItem: [NSMenuItem separatorItem]];
1150
1151     for( i = 0; i < val_list.p_list->i_count; i++ )
1152     {
1153         NSMenuItem * o_lmi;
1154         NSString *o_title = @"";
1155         VLCAutoGeneratedMenuContent *o_data;
1156
1157         switch( i_type & VLC_VAR_TYPE )
1158         {
1159             case VLC_VAR_STRING:
1160
1161                 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 );
1162
1163                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1164                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1165                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1166                 [o_lmi setRepresentedObject: [o_data autorelease]];
1167                 [o_lmi setTarget: self];
1168
1169                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1170                     [o_lmi setState: TRUE ];
1171
1172                 break;
1173
1174             case VLC_VAR_INTEGER:
1175
1176                 o_title = text_list.p_list->p_values[i].psz_string ?
1177                 _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1178
1179                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1180                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1181                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1182                 [o_lmi setRepresentedObject: [o_data autorelease]];
1183                 [o_lmi setTarget: self];
1184
1185                 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1186                     [o_lmi setState: TRUE ];
1187                 break;
1188
1189             default:
1190                 break;
1191         }
1192     }
1193
1194     /* special case for the subtitles sub-menu
1195      * In case that we don't have any subs, we don't want a separator item at the end */
1196     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1197     {
1198         if( [o_menu numberOfItems] == 2 )
1199             [o_menu removeItemAtIndex: 1];
1200     }
1201
1202     /* clean up everything */
1203     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1204     var_FreeList( &val_list, &text_list );
1205 }
1206
1207 - (IBAction)toggleVar:(id)sender
1208 {
1209     NSMenuItem *o_mi = (NSMenuItem *)sender;
1210     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1211     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1212                              toTarget: self withObject: o_data];
1213
1214     return;
1215 }
1216
1217 - (int)toggleVarThread: (id)data
1218 {
1219     vlc_object_t *p_object;
1220     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1221
1222     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1223     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1224
1225     /* Preserve settings across vouts via the playlist object: */
1226     if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
1227         var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
1228
1229     /* save our audio device across multiple sessions */
1230     if( !strcmp( [menuContent name], "audio-device" ) )
1231         config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
1232
1233     p_object = [menuContent vlcObject];
1234
1235     if( p_object != NULL )
1236     {
1237         var_Set( p_object, [menuContent name], [menuContent value] );
1238         vlc_object_release( p_object );
1239         [o_pool release];
1240         return true;
1241     }
1242     [o_pool release];
1243     return VLC_EGENERIC;
1244 }
1245
1246 @end
1247
1248 @implementation VLCMainMenu (NSMenuValidation)
1249
1250 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1251 {
1252     NSString *o_title = [o_mi title];
1253     BOOL bEnabled = TRUE;
1254     vlc_value_t val;
1255     playlist_t * p_playlist = pl_Get( p_intf );
1256     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1257
1258     if( [o_title isEqualToString: _NS("Stop")] )
1259     {
1260         if( p_input == NULL )
1261         {
1262             bEnabled = FALSE;
1263         }
1264         [self setupMenus]; /* Make sure input menu is up to date */
1265     }
1266     else if( [o_title isEqualToString: _NS("Previous")] ||
1267             [o_title isEqualToString: _NS("Next")] )
1268     {
1269         PL_LOCK;
1270         bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1271         PL_UNLOCK;
1272     }
1273     else if( [o_title isEqualToString: _NS("Random")] )
1274     {
1275         int i_state;
1276         var_Get( p_playlist, "random", &val );
1277         i_state = val.b_bool ? NSOnState : NSOffState;
1278         [o_mi setState: i_state];
1279     }
1280     else if( [o_title isEqualToString: _NS("Repeat One")] )
1281     {
1282         int i_state;
1283         var_Get( p_playlist, "repeat", &val );
1284         i_state = val.b_bool ? NSOnState : NSOffState;
1285         [o_mi setState: i_state];
1286     }
1287     else if( [o_title isEqualToString: _NS("Repeat All")] )
1288     {
1289         int i_state;
1290         var_Get( p_playlist, "loop", &val );
1291         i_state = val.b_bool ? NSOnState : NSOffState;
1292         [o_mi setState: i_state];
1293     }
1294     else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1295     {
1296         int i_state;
1297         var_Get( p_playlist, "play-and-exit", &val );
1298         i_state = val.b_bool ? NSOnState : NSOffState;
1299         [o_mi setState: i_state];
1300     }
1301     else if( [o_title isEqualToString: _NS("Step Forward")] ||
1302             [o_title isEqualToString: _NS("Step Backward")] ||
1303             [o_title isEqualToString: _NS("Jump To Time")])
1304     {
1305         if( p_input != NULL )
1306         {
1307             var_Get( p_input, "can-seek", &val);
1308             bEnabled = val.b_bool;
1309         }
1310         else bEnabled = FALSE;
1311     }
1312     else if( [o_title isEqualToString: _NS("Mute")] )
1313     {
1314         [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1315         [self setupMenus]; /* Make sure audio menu is up to date */
1316     }
1317     else if( [o_title isEqualToString: _NS("Half Size")] ||
1318             [o_title isEqualToString: _NS("Normal Size")] ||
1319             [o_title isEqualToString: _NS("Double Size")] ||
1320             [o_title isEqualToString: _NS("Fit to Screen")] ||
1321             [o_title isEqualToString: _NS("Snapshot")] ||
1322             [o_title isEqualToString: _NS("Fullscreen")] ||
1323             [o_title isEqualToString: _NS("Float on Top")] )
1324     {
1325         bEnabled = FALSE;
1326
1327         if( p_input != NULL )
1328         {
1329             vout_thread_t *p_vout = input_GetVout( p_input );
1330             if( p_vout != NULL )
1331             {
1332                 if( [o_title isEqualToString: _NS("Float on Top")] )
1333                     [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1334
1335                 bEnabled = TRUE;
1336
1337                 vlc_object_release( p_vout );
1338             }
1339         }
1340         if( [o_title isEqualToString: _NS("Fullscreen")] )
1341         {
1342         [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1343             bEnabled = TRUE;
1344         }
1345         [self setupMenus]; /* Make sure video menu is up to date */
1346     }
1347
1348     /* Special case for telx menu */
1349     if( [o_title isEqualToString: _NS("Normal Size")] )
1350     {
1351         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1352
1353
1354 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1355
1356         [[item submenu] setAutoenablesItems:NO];
1357         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1358         {
1359             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1360         }
1361     }
1362
1363     if( p_input ) vlc_object_release( p_input );
1364
1365     return( bEnabled );
1366 }
1367
1368 @end
1369
1370
1371 /*****************************************************************************
1372  * VLCAutoGeneratedMenuContent implementation
1373  *****************************************************************************
1374  * Object connected to a playlistitem which remembers the data belonging to
1375  * the variable of the autogenerated menu
1376  *****************************************************************************/
1377 @implementation VLCAutoGeneratedMenuContent
1378
1379 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1380                   andValue:(vlc_value_t)val ofType:(int)type
1381 {
1382     self = [super init];
1383
1384     if( self != nil )
1385     {
1386         _vlc_object = vlc_object_hold( object );
1387         psz_name = strdup( name );
1388         i_type = type;
1389         value = val;
1390         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1391             value.psz_string = strdup( val.psz_string );
1392     }
1393
1394     return( self );
1395 }
1396
1397 - (void)dealloc
1398 {
1399     if( _vlc_object )
1400         vlc_object_release( _vlc_object );
1401     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1402         free( value.psz_string );
1403     free( psz_name );
1404     [super dealloc];
1405 }
1406
1407 - (const char *)name
1408 {
1409     return psz_name;
1410 }
1411
1412 - (vlc_value_t)value
1413 {
1414     return value;
1415 }
1416
1417 - (vlc_object_t *)vlcObject
1418 {
1419     return vlc_object_hold( _vlc_object );
1420 }
1421
1422
1423 - (int)type
1424 {
1425     return i_type;
1426 }
1427
1428 @end