]> git.sesse.net Git - vlc/blob - modules/gui/macosx/MainMenu.m
5f84d1712df633ca47c636e4b0b31f84cb14bb0b
[vlc] / modules / gui / macosx / MainMenu.m
1 /*****************************************************************************
2  * MainMenu.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011-2014 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 "intf.h"
26
27 #import <vlc_common.h>
28 #import <vlc_playlist.h>
29 #import <vlc_input.h>
30
31 #import "open.h"
32 #import "wizard.h"
33 #import "about.h"
34 #import "AudioEffects.h"
35 #import "TrackSynchronization.h"
36 #import "VideoEffects.h"
37 #import "bookmarks.h"
38 #import "simple_prefs.h"
39 #import "coredialogs.h"
40 #import "controls.h"
41 #import "playlist.h"
42 #import "playlistinfo.h"
43 #import "VideoView.h"
44 #import "CoreInteraction.h"
45 #import "MainWindow.h"
46 #import "ControlsBar.h"
47 #import "ExtensionsManager.h"
48 #import "ConvertAndSave.h"
49 #import "DebugMessageVisualizer.h"
50 #import "AddonManager.h"
51
52 @implementation VLCMainMenu
53 static VLCMainMenu *_o_sharedInstance = nil;
54
55 + (VLCMainMenu *)sharedInstance
56 {
57     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
58 }
59
60 #pragma mark - Initialization
61
62 - (id)init
63 {
64     if (_o_sharedInstance) {
65         [self dealloc];
66         return _o_sharedInstance;
67     } else {
68         _o_sharedInstance = [super init];
69
70         o_ptc_translation_dict = [[NSDictionary alloc] initWithObjectsAndKeys:
71                       _NS("Track Number"),  TRACKNUM_COLUMN,
72                       _NS("Title"),         TITLE_COLUMN,
73                       _NS("Author"),        ARTIST_COLUMN,
74                       _NS("Duration"),      DURATION_COLUMN,
75                       _NS("Genre"),         GENRE_COLUMN,
76                       _NS("Album"),         ALBUM_COLUMN,
77                       _NS("Description"),   DESCRIPTION_COLUMN,
78                       _NS("Date"),          DATE_COLUMN,
79                       _NS("Language"),      LANGUAGE_COLUMN,
80                       _NS("URI"),           URI_COLUMN,
81                       _NS("File Size"),     FILESIZE_COLUMN,
82                       nil];
83         // this array also assigns tags (index) to type of menu item
84         o_ptc_menuorder = [[NSArray alloc] initWithObjects: TRACKNUM_COLUMN, TITLE_COLUMN,
85                            ARTIST_COLUMN, DURATION_COLUMN, GENRE_COLUMN, ALBUM_COLUMN,
86                            DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN,
87                            FILESIZE_COLUMN,nil];
88     }
89
90     return _o_sharedInstance;
91 }
92
93 - (void)dealloc
94 {
95     [[NSNotificationCenter defaultCenter] removeObserver: self];
96
97     if (b_nib_about_loaded)
98         [o_about release];
99
100     if (b_nib_videoeffects_loaded)
101         [o_videoeffects release];
102
103     if (b_nib_audioeffects_loaded)
104         [o_audioeffects release];
105
106     if (b_nib_tracksynchro_loaded)
107         [o_trackSynchronization release];
108
109     if (b_nib_convertandsave_loaded)
110         [o_convertandsave release];
111
112     [o_extMgr release];
113
114     if (o_mu_playlistTableColumnsContextMenu)
115         [o_mu_playlistTableColumnsContextMenu release];
116
117     [self releaseRepresentedObjects:[NSApp mainMenu]];
118
119     [o_ptc_translation_dict release];
120     [o_ptc_menuorder release];
121
122     [super dealloc];
123 }
124
125 - (void)awakeFromNib
126 {
127     [[NSNotificationCenter defaultCenter] addObserver: self
128                                              selector: @selector(applicationWillFinishLaunching:)
129                                                  name: NSApplicationWillFinishLaunchingNotification
130                                                object: nil];
131
132     /* check whether the user runs OSX with a RTL language */
133     NSArray* languages = [NSLocale preferredLanguages];
134     NSString* preferredLanguage = [languages objectAtIndex:0];
135
136     if ([NSLocale characterDirectionForLanguage:preferredLanguage] == NSLocaleLanguageDirectionRightToLeft) {
137         msg_Dbg(VLCIntf, "adapting interface since '%s' is a RTL language", [preferredLanguage UTF8String]);
138         [o_mi_rate_fld setAlignment: NSLeftTextAlignment];
139     }
140 }
141
142 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
143 {
144     p_intf = VLCIntf;
145
146     NSString* o_key;
147     playlist_t *p_playlist;
148     vlc_value_t val;
149     id o_vlcstringutility = [VLCStringUtility sharedInstance];
150     char * key;
151
152     /* Check if we already did this once. Opening the other nibs calls it too,
153      because VLCMain is the owner */
154     if (b_mainMenu_setup)
155         return;
156
157     /* Get ExtensionsManager */
158     o_extMgr = [ExtensionsManager getInstance:p_intf];
159     [o_extMgr retain];
160
161     [self initStrings];
162
163     key = config_GetPsz(p_intf, "key-quit");
164     o_key = [NSString stringWithFormat:@"%s", key];
165     [o_mi_quit setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
166     [o_mi_quit setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
167     FREENULL(key);
168
169     // do not assign play/pause key
170
171     key = config_GetPsz(p_intf, "key-stop");
172     o_key = [NSString stringWithFormat:@"%s", key];
173     [o_mi_stop setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
174     [o_mi_stop setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
175     FREENULL(key);
176
177     key = config_GetPsz(p_intf, "key-prev");
178     o_key = [NSString stringWithFormat:@"%s", key];
179     [o_mi_previous setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
180     [o_mi_previous setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
181     FREENULL(key);
182
183     key = config_GetPsz(p_intf, "key-next");
184     o_key = [NSString stringWithFormat:@"%s", key];
185     [o_mi_next setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
186     [o_mi_next setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
187     FREENULL(key);
188
189     key = config_GetPsz(p_intf, "key-jump+short");
190     o_key = [NSString stringWithFormat:@"%s", key];
191     [o_mi_fwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
192     [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
193     FREENULL(key);
194
195     key = config_GetPsz(p_intf, "key-jump-short");
196     o_key = [NSString stringWithFormat:@"%s", key];
197     [o_mi_bwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
198     [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
199     FREENULL(key);
200
201     key = config_GetPsz(p_intf, "key-vol-up");
202     o_key = [NSString stringWithFormat:@"%s", key];
203     [o_mi_vol_up setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
204     [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
205     FREENULL(key);
206
207     key = config_GetPsz(p_intf, "key-vol-down");
208     o_key = [NSString stringWithFormat:@"%s", key];
209     [o_mi_vol_down setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
210     [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
211     FREENULL(key);
212
213     key = config_GetPsz(p_intf, "key-vol-mute");
214     o_key = [NSString stringWithFormat:@"%s", key];
215     [o_mi_mute setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
216     [o_mi_mute setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
217     FREENULL(key);
218
219     key = config_GetPsz(p_intf, "key-toggle-fullscreen");
220     o_key = [NSString stringWithFormat:@"%s", key];
221     [o_mi_fullscreen setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
222     [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
223     FREENULL(key);
224
225     key = config_GetPsz(p_intf, "key-snapshot");
226     o_key = [NSString stringWithFormat:@"%s", key];
227     [o_mi_snapshot setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
228     [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
229     FREENULL(key);
230
231     key = config_GetPsz(p_intf, "key-random");
232     o_key = [NSString stringWithFormat:@"%s", key];
233     [o_mi_random setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
234     [o_mi_random setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
235     FREENULL(key);
236
237     key = config_GetPsz(p_intf, "key-zoom-half");
238     o_key = [NSString stringWithFormat:@"%s", key];
239     [o_mi_half_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
240     [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
241     FREENULL(key);
242
243     key = config_GetPsz(p_intf, "key-zoom-original");
244     o_key = [NSString stringWithFormat:@"%s", key];
245     [o_mi_normal_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
246     [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
247     FREENULL(key);
248
249     key = config_GetPsz(p_intf, "key-zoom-double");
250     o_key = [NSString stringWithFormat:@"%s", key];
251     [o_mi_double_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
252     [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
253     FREENULL(key);
254
255     [self setSubmenusEnabled: FALSE];
256
257     [[NSNotificationCenter defaultCenter] addObserver: self
258                                              selector: @selector(refreshVoutDeviceMenu:)
259                                                  name: NSApplicationDidChangeScreenParametersNotification
260                                                object: nil];
261
262     /* we're done */
263     b_mainMenu_setup = YES;
264
265     [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
266                              var: "intf-add" selector: @selector(toggleVar:)];
267
268     /* setup extensions menu */
269     // FIXME: Implement preference for autoloading extensions on mac
270     if (![o_extMgr isLoaded] && ![o_extMgr cannotLoad])
271         [o_extMgr loadExtensions];
272
273     /* Let the ExtensionsManager itself build the menu */
274     [o_extMgr buildMenu:o_mu_extensions];
275     [o_mi_extensions setEnabled: ([o_mu_extensions numberOfItems] > 0)];
276
277     /* setup post-proc menu */
278     NSUInteger count = (NSUInteger) [o_mu_ffmpeg_pp numberOfItems];
279     if (count > 0)
280         [o_mu_ffmpeg_pp removeAllItems];
281
282     NSMenuItem * o_mitem;
283     [o_mu_ffmpeg_pp setAutoenablesItems: YES];
284     [o_mu_ffmpeg_pp addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
285     o_mitem = [o_mu_ffmpeg_pp itemAtIndex: 0];
286     [o_mitem setTag: -1];
287     [o_mitem setEnabled: YES];
288     [o_mitem setTarget: self];
289     for (NSUInteger x = 1; x < 7; x++) {
290         [o_mu_ffmpeg_pp addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
291                                                action:@selector(togglePostProcessing:)
292                                         keyEquivalent:@""];
293         o_mitem = [o_mu_ffmpeg_pp itemAtIndex:x];
294         [o_mitem setEnabled:YES];
295         [o_mitem setTag:x];
296         [o_mitem setTarget:self];
297     }
298     char *psz_config = config_GetPsz(p_intf, "video-filter");
299     if (psz_config) {
300         if (!strstr(psz_config, "postproc"))
301             [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
302         else
303             [[o_mu_ffmpeg_pp itemWithTag:config_GetInt(p_intf, "postproc-q")] setState:NSOnState];
304         free(psz_config);
305     } else
306         [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
307     [o_mi_ffmpeg_pp setEnabled: NO];
308
309     [self refreshAudioDeviceList];
310
311     /* setup subtitles menu */
312     [self setupMenu: o_mu_subtitle_size withIntList:"freetype-rel-fontsize" andSelector:@selector(switchSubtitleOption:)];
313     [self setupMenu: o_mu_subtitle_textcolor withIntList:"freetype-color" andSelector:@selector(switchSubtitleOption:)];
314     [o_mi_subtitle_bgopacity_sld setIntValue: config_GetInt(VLC_OBJECT(p_intf), "freetype-background-opacity")];
315     [self setupMenu: o_mu_subtitle_bgcolor withIntList:"freetype-background-color" andSelector:@selector(switchSubtitleOption:)];
316     [self setupMenu: o_mu_subtitle_outlinethickness withIntList:"freetype-outline-thickness" andSelector:@selector(switchSubtitleOption:)];
317 }
318
319 - (void)setupMenu: (NSMenu*)menu withIntList: (char *)psz_name andSelector:(SEL)selector
320 {
321     module_config_t *p_item;
322
323     [menu removeAllItems];
324     p_item = config_FindConfig(VLC_OBJECT(p_intf), psz_name);
325
326     /* serious problem, if no item found */
327     assert(p_item);
328
329     for (int i = 0; i < p_item->list_count; i++) {
330         NSMenuItem *mi;
331         if (p_item->list_text != NULL)
332             mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
333         else if (p_item->list.i[i])
334             mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
335         else {
336             msg_Err(p_intf, "item %d of pref %s failed to be created", i, psz_name);
337             continue;
338         }
339
340         [mi setTarget:self];
341         [mi setAction:selector];
342         [mi setTag:p_item->list.i[i]];
343         [mi setRepresentedObject:[NSString stringWithUTF8String:psz_name]];
344         [menu addItem: [mi autorelease]];
345         if (p_item->value.i == p_item->list.i[i])
346             [mi setState:NSOnState];
347     }
348 }
349
350 - (void)initStrings
351 {
352     /* main menu */
353     [o_mi_about setTitle: [_NS("About VLC media player") \
354                            stringByAppendingString: @"..."]];
355     [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
356     [o_mi_prefs setTitle: _NS("Preferences...")];
357     [o_mi_extensions setTitle: _NS("Extensions")];
358     [o_mu_extensions setTitle: _NS("Extensions")];
359     [o_mi_addonManager setTitle: _NS("Addons Manager")];
360     [o_mi_add_intf setTitle: _NS("Add Interface")];
361     [o_mu_add_intf setTitle: _NS("Add Interface")];
362     [o_mi_services setTitle: _NS("Services")];
363     [o_mi_hide setTitle: _NS("Hide VLC")];
364     [o_mi_hide_others setTitle: _NS("Hide Others")];
365     [o_mi_show_all setTitle: _NS("Show All")];
366     [o_mi_quit setTitle: _NS("Quit VLC")];
367
368     [o_mu_file setTitle: _ANS("1:File")];
369     [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
370     [o_mi_open_file setTitle: _NS("Open File...")];
371     [o_mi_open_disc setTitle: _NS("Open Disc...")];
372     [o_mi_open_net setTitle: _NS("Open Network...")];
373     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
374     [o_mi_open_recent setTitle: _NS("Open Recent")];
375     [o_mi_close_window setTitle: _NS("Close Window")];
376     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
377     [o_mi_convertandsave setTitle: _NS("Convert / Stream...")];
378     [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
379
380     [o_mu_edit setTitle: _NS("Edit")];
381     [o_mi_cut setTitle: _NS("Cut")];
382     [o_mi_copy setTitle: _NS("Copy")];
383     [o_mi_paste setTitle: _NS("Paste")];
384     [o_mi_clear setTitle: _NS("Clear")];
385     [o_mi_select_all setTitle: _NS("Select All")];
386
387     [o_mu_view setTitle: _NS("View")];
388     [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
389     [o_mi_toggleJumpButtons setState: config_GetInt(VLCIntf, "macosx-show-playback-buttons")];
390     [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
391     [o_mi_togglePlaymodeButtons setState: config_GetInt(VLCIntf, "macosx-show-playmode-buttons")];
392     [o_mi_toggleEffectsButton setTitle: _NS("Show Audio Effects Button")];
393     [o_mi_toggleEffectsButton setState: config_GetInt(VLCIntf, "macosx-show-effects-button")];
394     [o_mi_toggleSidebar setTitle: _NS("Show Sidebar")];
395     [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
396     [o_mu_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
397     [o_mi_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
398
399     [o_mu_controls setTitle: _NS("Playback")];
400     [o_mi_play setTitle: _NS("Play")];
401     [o_mi_stop setTitle: _NS("Stop")];
402     [o_mi_record setTitle: _NS("Record")];
403     [o_mi_rate setView: o_mi_rate_view];
404     [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
405     [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
406     [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
407     [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
408     [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
409     [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
410     [o_mi_previous setTitle: _NS("Previous")];
411     [o_mi_next setTitle: _NS("Next")];
412     [o_mi_random setTitle: _NS("Random")];
413     [o_mi_repeat setTitle: _NS("Repeat One")];
414     [o_mi_loop setTitle: _NS("Repeat All")];
415     [o_mi_AtoBloop setTitle: _NS("A→B Loop")];
416     [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
417     [o_mi_fwd setTitle: _NS("Step Forward")];
418     [o_mi_bwd setTitle: _NS("Step Backward")];
419
420     [o_mi_program setTitle: _NS("Program")];
421     [o_mu_program setTitle: _NS("Program")];
422     [o_mi_title setTitle: _NS("Title")];
423     [o_mu_title setTitle: _NS("Title")];
424     [o_mi_chapter setTitle: _NS("Chapter")];
425     [o_mu_chapter setTitle: _NS("Chapter")];
426
427     [o_mu_audio setTitle: _NS("Audio")];
428     [o_mi_vol_up setTitle: _NS("Increase Volume")];
429     [o_mi_vol_down setTitle: _NS("Decrease Volume")];
430     [o_mi_mute setTitle: _NS("Mute")];
431     [o_mi_audiotrack setTitle: _NS("Audio Track")];
432     [o_mu_audiotrack setTitle: _NS("Audio Track")];
433     [o_mi_channels setTitle: _NS("Stereo audio mode")];
434     [o_mu_channels setTitle: _NS("Stereo audio mode")];
435     [o_mi_device setTitle: _NS("Audio Device")];
436     [o_mu_device setTitle: _NS("Audio Device")];
437     [o_mi_visual setTitle: _NS("Visualizations")];
438     [o_mu_visual setTitle: _NS("Visualizations")];
439
440     [o_mu_video setTitle: _NS("Video")];
441     [o_mi_half_window setTitle: _NS("Half Size")];
442     [o_mi_normal_window setTitle: _NS("Normal Size")];
443     [o_mi_double_window setTitle: _NS("Double Size")];
444     [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
445     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
446     [o_mi_floatontop setTitle: _NS("Float on Top")];
447     [o_mi_snapshot setTitle: _NS("Snapshot")];
448     [o_mi_videotrack setTitle: _NS("Video Track")];
449     [o_mu_videotrack setTitle: _NS("Video Track")];
450     [o_mi_aspect_ratio setTitle: _NS("Aspect ratio")];
451     [o_mu_aspect_ratio setTitle: _NS("Aspect ratio")];
452     [o_mi_crop setTitle: _NS("Crop")];
453     [o_mu_crop setTitle: _NS("Crop")];
454     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
455     [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
456     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
457     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
458     [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
459     [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
460     [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
461     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
462
463     [o_mu_subtitles setTitle:_NS("Subtitles")];
464     [o_mi_openSubtitleFile setTitle: _NS("Add Subtitle File...")];
465     [o_mi_subtitle_track setTitle: _NS("Subtitles Track")];
466     [o_mu_subtitle_tracks setTitle: _NS("Subtitles Track")];
467     [o_mi_subtitle_size setTitle: _NS("Text Size")];
468     [o_mi_subtitle_textcolor setTitle: _NS("Text Color")];
469     [o_mi_subtitle_outlinethickness setTitle: _NS("Outline Thickness")];
470     [o_mi_subtitle_bgopacity setView: o_mi_subtitle_bgopacity_view];
471     [o_mi_subtitle_bgopacity_lbl setStringValue: _NS("Background Opacity")];
472     [o_mi_subtitle_bgopacity_lbl_gray setStringValue: _NS("Background Opacity")];
473     [o_mi_subtitle_bgcolor setTitle: _NS("Background Color")];
474     [o_mi_teletext setTitle: _NS("Teletext")];
475     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
476     [o_mi_teletext_index setTitle: _NS("Index")];
477     [o_mi_teletext_red setTitle: _NS("Red")];
478     [o_mi_teletext_green setTitle: _NS("Green")];
479     [o_mi_teletext_yellow setTitle: _NS("Yellow")];
480     [o_mi_teletext_blue setTitle: _NS("Blue")];
481
482     [o_mu_window setTitle: _NS("Window")];
483     [o_mi_minimize setTitle: _NS("Minimize")];
484     [o_mi_zoom_window setTitle: _NS("Zoom")];
485     [o_mi_player setTitle: _NS("Player...")];
486     [o_mi_controller setTitle: _NS("Main Window...")];
487     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
488     [o_mi_videoeffects setTitle: _NS("Video Effects...")];
489     [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
490     [o_mi_playlist setTitle: _NS("Playlist...")];
491     [o_mi_info setTitle: _NS("Media Information...")];
492     [o_mi_messages setTitle: _NS("Messages...")];
493     [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
494
495     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
496
497     [o_mu_help setTitle: _NS("Help")];
498     [o_mi_help setTitle: _NS("VLC media player Help...")];
499     [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
500     [o_mi_license setTitle: _NS("License")];
501     [o_mi_documentation setTitle: _NS("Online Documentation...")];
502     [o_mi_website setTitle: _NS("VideoLAN Website...")];
503     [o_mi_donation setTitle: _NS("Make a donation...")];
504     [o_mi_forum setTitle: _NS("Online Forum...")];
505
506     /* dock menu */
507     [o_dmi_play setTitle: _NS("Play")];
508     [o_dmi_stop setTitle: _NS("Stop")];
509     [o_dmi_next setTitle: _NS("Next")];
510     [o_dmi_previous setTitle: _NS("Previous")];
511     [o_dmi_mute setTitle: _NS("Mute")];
512
513     /* vout menu */
514     [o_vmi_play setTitle: _NS("Play")];
515     [o_vmi_stop setTitle: _NS("Stop")];
516     [o_vmi_prev setTitle: _NS("Previous")];
517     [o_vmi_next setTitle: _NS("Next")];
518     [o_vmi_volup setTitle: _NS("Volume Up")];
519     [o_vmi_voldown setTitle: _NS("Volume Down")];
520     [o_vmi_mute setTitle: _NS("Mute")];
521     [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
522     [o_vmi_snapshot setTitle: _NS("Snapshot")];
523 }
524
525 - (NSMenu *)setupPlaylistTableColumnsMenu
526 {
527     NSMenu *o_context_menu = [[NSMenu alloc] init];
528
529     NSMenuItem *o_mi_tmp;
530     NSUInteger count = [o_ptc_menuorder count];
531     for (NSUInteger i = 0; i < count; i++) {
532         NSString *o_title = [o_ptc_translation_dict objectForKey:[o_ptc_menuorder objectAtIndex:i]];
533         o_mi_tmp = [o_mu_playlistTableColumns addItemWithTitle:o_title
534                                                         action:@selector(togglePlaylistColumnTable:)
535                                                  keyEquivalent:@""];
536         /* don't set a valid target for the title column selector, since we want it to be disabled */
537         if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
538             [o_mi_tmp setTarget:self];
539         [o_mi_tmp setTag:i];
540
541         o_mi_tmp = [o_context_menu addItemWithTitle:o_title
542                                              action:@selector(togglePlaylistColumnTable:)
543                                       keyEquivalent:@""];
544         /* don't set a valid target for the title column selector, since we want it to be disabled */
545         if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
546             [o_mi_tmp setTarget:self];
547         [o_mi_tmp setTag:i];
548     }
549     if (!o_mu_playlistTableColumnsContextMenu)
550         o_mu_playlistTableColumnsContextMenu = [o_context_menu retain];
551     return [o_context_menu autorelease];
552 }
553
554 #pragma mark - Termination
555
556 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
557 {
558     if (!p_intf) return;
559
560     NSArray *menuitems_array = [the_menu itemArray];
561     NSUInteger menuItemCount = [menuitems_array count];
562     for (NSUInteger i=0; i < menuItemCount; i++) {
563         NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
564         if ([one_item hasSubmenu])
565             [self releaseRepresentedObjects: [one_item submenu]];
566
567         [one_item setRepresentedObject:NULL];
568     }
569 }
570
571 #pragma mark - Interface update
572
573 - (void)setupMenus
574 {
575     playlist_t * p_playlist = pl_Get(p_intf);
576     input_thread_t * p_input = playlist_CurrentInput(p_playlist);
577     if (p_input != NULL) {
578         [o_mi_record setEnabled: var_GetBool(p_input, "can-record")];
579
580         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
581                                  var: "program" selector: @selector(toggleVar:)];
582
583         [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
584                                  var: "title" selector: @selector(toggleVar:)];
585
586         [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
587                                  var: "chapter" selector: @selector(toggleVar:)];
588
589         [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
590                                  var: "audio-es" selector: @selector(toggleVar:)];
591
592         [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
593                                  var: "video-es" selector: @selector(toggleVar:)];
594
595         [self setupVarMenuItem: o_mi_subtitle_track target: (vlc_object_t *)p_input
596                                  var: "spu-es" selector: @selector(toggleVar:)];
597
598         audio_output_t * p_aout = playlist_GetAout(p_playlist);
599         if (p_aout != NULL) {
600             [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
601                                      var: "stereo-mode" selector: @selector(toggleVar:)];
602
603             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
604                                      var: "visual" selector: @selector(toggleVar:)];
605             vlc_object_release(p_aout);
606         }
607
608         vout_thread_t * p_vout = getVoutForActiveWindow();
609
610         if (p_vout != NULL) {
611             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
612                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
613
614             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
615                                      var: "crop" selector: @selector(toggleVar:)];
616
617             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
618                                      var: "deinterlace" selector: @selector(toggleVar:)];
619
620             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
621                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
622
623             vlc_object_release(p_vout);
624
625             [self refreshVoutDeviceMenu:nil];
626         }
627         [o_mi_ffmpeg_pp setEnabled:YES];
628         vlc_object_release(p_input);
629     } else {
630         [o_mi_record setEnabled: NO];
631         [o_mi_ffmpeg_pp setEnabled:NO];
632     }
633 }
634
635 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
636 {
637     NSUInteger count = (NSUInteger) [o_mu_screen numberOfItems];
638     NSMenu * o_submenu = o_mu_screen;
639     if (count > 0)
640         [o_submenu removeAllItems];
641
642     NSArray * o_screens = [NSScreen screens];
643     NSMenuItem * o_mitem;
644     count = [o_screens count];
645     [o_mi_screen setEnabled: YES];
646     [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
647     o_mitem = [o_submenu itemAtIndex: 0];
648     [o_mitem setTag: 0];
649     [o_mitem setEnabled: YES];
650     [o_mitem setTarget: self];
651     NSRect s_rect;
652     for (NSUInteger i = 0; i < count; i++) {
653         s_rect = [[o_screens objectAtIndex:i] frame];
654         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
655                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
656         o_mitem = [o_submenu itemAtIndex:i+1];
657         [o_mitem setTag: (int)[[o_screens objectAtIndex:i] displayID]];
658         [o_mitem setEnabled: YES];
659         [o_mitem setTarget: self];
660     }
661     [[o_submenu itemWithTag: var_InheritInteger(VLCIntf, "macosx-vdev")] setState: NSOnState];
662 }
663
664 - (void)setSubmenusEnabled:(BOOL)b_enabled
665 {
666     [o_mi_program setEnabled: b_enabled];
667     [o_mi_title setEnabled: b_enabled];
668     [o_mi_chapter setEnabled: b_enabled];
669     [o_mi_audiotrack setEnabled: b_enabled];
670     [o_mi_visual setEnabled: b_enabled];
671     [o_mi_videotrack setEnabled: b_enabled];
672     [o_mi_subtitle_track setEnabled: b_enabled];
673     [o_mi_channels setEnabled: b_enabled];
674     [o_mi_deinterlace setEnabled: b_enabled];
675     [o_mi_deinterlace_mode setEnabled: b_enabled];
676     [o_mi_screen setEnabled: b_enabled];
677     [o_mi_aspect_ratio setEnabled: b_enabled];
678     [o_mi_crop setEnabled: b_enabled];
679 }
680
681 - (void)setSubtitleMenuEnabled:(BOOL)b_enabled
682 {
683     [o_mi_openSubtitleFile setEnabled: b_enabled];
684     if (b_enabled) {
685         [o_mi_subtitle_bgopacity_lbl_gray setHidden: YES];
686         [o_mi_subtitle_bgopacity_lbl setHidden: NO];
687     } else {
688         [o_mi_subtitle_bgopacity_lbl_gray setHidden: NO];
689         [o_mi_subtitle_bgopacity_lbl setHidden: YES];
690     }
691     [o_mi_subtitle_bgopacity_sld setEnabled: b_enabled];
692     [o_mi_teletext setEnabled: b_enabled];
693 }
694
695 - (void)setRateControlsEnabled:(BOOL)b_enabled
696 {
697     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
698     [o_mi_rate_sld setEnabled: b_enabled];
699     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
700     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
701     double speed =  pow(2, (double)i / 17);
702     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
703     if (b_enabled) {
704         [o_mi_rate_lbl setHidden: NO];
705         [o_mi_rate_lbl_gray setHidden: YES];
706     } else {
707         [o_mi_rate_lbl setHidden: YES];
708         [o_mi_rate_lbl_gray setHidden: NO];
709     }
710     [self setSubtitleMenuEnabled: b_enabled];
711     [o_pool release];
712 }
713
714 #pragma mark - View
715
716 - (IBAction)toggleEffectsButton:(id)sender
717 {
718     BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-effects-button");
719     config_PutInt(VLCIntf, "macosx-show-effects-button", b_value);
720     [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleEffectsButton];
721     [o_mi_toggleEffectsButton setState: b_value];
722 }
723
724 - (IBAction)toggleJumpButtons:(id)sender
725 {
726     BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playback-buttons");
727     config_PutInt(VLCIntf, "macosx-show-playback-buttons", b_value);
728
729     [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleJumpButtons];
730     [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
731         [[o_window controlsBar] toggleForwardBackwardMode: b_value];
732     }];
733
734     [o_mi_toggleJumpButtons setState: b_value];
735 }
736
737 - (IBAction)togglePlaymodeButtons:(id)sender
738 {
739     BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playmode-buttons");
740     config_PutInt(VLCIntf, "macosx-show-playmode-buttons", b_value);
741     [[[[VLCMain sharedInstance] mainWindow] controlsBar] togglePlaymodeButtons];
742     [o_mi_togglePlaymodeButtons setState: b_value];
743 }
744
745 - (IBAction)toggleSidebar:(id)sender
746 {
747     [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
748 }
749
750 - (void)updateSidebarMenuItem
751 {
752     [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
753 }
754
755 - (IBAction)togglePlaylistColumnTable:(id)sender
756 {
757     NSInteger i_new_state = ![sender state];
758     NSInteger i_tag = [sender tag];
759     [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_new_state];
760     [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_new_state];
761
762     NSString *o_column = [o_ptc_menuorder objectAtIndex:i_tag];
763     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
764 }
765
766 - (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
767 {
768     NSUInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
769     // prevent setting unknown columns
770     if(i_tag == NSNotFound)
771         return NO;
772
773     [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_state];
774     [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
775     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_state translationDict: o_ptc_translation_dict];
776
777     return YES;
778 }
779
780 #pragma mark - Playback
781
782 - (IBAction)quitAfterPlayback:(id)sender
783 {
784     playlist_t *p_playlist = pl_Get(VLCIntf);
785     bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
786     var_SetBool(p_playlist, "play-and-exit", b_value);
787     config_PutInt(p_intf, "play-and-exit", b_value);
788 }
789
790 - (IBAction)toggleRecord:(id)sender
791 {
792     [[VLCCoreInteraction sharedInstance] toggleRecord];
793 }
794
795 - (void)updateRecordState:(BOOL)b_value
796 {
797     [o_mi_record setState:b_value];
798 }
799
800 - (IBAction)setPlaybackRate:(id)sender
801 {
802     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
803     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
804     double speed =  pow(2, (double)i / 17);
805     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
806 }
807
808 - (void)updatePlaybackRate
809 {
810     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
811     double speed =  pow(2, (double)i / 17);
812     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
813     [o_mi_rate_sld setIntValue: i];
814 }
815
816 - (IBAction)toggleAtoBloop:(id)sender
817 {
818     [[VLCCoreInteraction sharedInstance] setAtoB];
819 }
820
821 #pragma mark - audio menu
822
823 - (void)refreshAudioDeviceList
824 {
825     char **ids, **names;
826     char *currentDevice;
827
828     [o_mu_device removeAllItems];
829
830     audio_output_t * p_aout = getAout();
831     if (!p_aout)
832         return;
833
834     int n = aout_DevicesList(p_aout, &ids, &names);
835     if (n == -1) {
836         vlc_object_release(p_aout);
837         return;
838     }
839
840     currentDevice = aout_DeviceGet(p_aout);
841     NSMenuItem * o_mi_tmp;
842
843     for (NSUInteger x = 0; x < n; x++) {
844         o_mi_tmp = [o_mu_device addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
845         [o_mi_tmp setTarget:self];
846         [o_mi_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
847     }
848     vlc_object_release(p_aout);
849
850     [[o_mu_device itemWithTag:[[NSString stringWithFormat:@"%s", currentDevice] intValue]] setState:NSOnState];
851
852     free(currentDevice);
853
854     for (NSUInteger x = 0; x < n; x++) {
855         free(ids[x]);
856         free(names[x]);
857     }
858     free(ids);
859     free(names);
860
861     [o_mu_device setAutoenablesItems:YES];
862     [o_mi_device setEnabled:YES];
863 }
864
865 - (IBAction)toggleAudioDevice:(id)sender
866 {
867     audio_output_t * p_aout = getAout();
868     if (!p_aout)
869         return;
870
871     int returnValue = 0;
872
873     if ([sender tag] > 0)
874         returnValue = aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
875     else
876         returnValue = aout_DeviceSet(p_aout, NULL);
877
878     if (returnValue != 0)
879         msg_Warn(VLCIntf, "failed to set audio device %li", [sender tag]);
880
881     vlc_object_release(p_aout);
882     [self refreshAudioDeviceList];
883 }
884
885 #pragma mark - video menu
886
887 - (IBAction)toggleFullscreen:(id)sender
888 {
889     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
890 }
891
892 - (IBAction)resizeVideoWindow:(id)sender
893 {
894     input_thread_t *p_input = pl_CurrentInput(VLCIntf);
895     if (p_input) {
896         vout_thread_t *p_vout = getVoutForActiveWindow();
897         if (p_vout) {
898             if (sender == o_mi_half_window)
899                 var_SetFloat(p_vout, "zoom", 0.5);
900             else if (sender == o_mi_normal_window)
901                 var_SetFloat(p_vout, "zoom", 1.0);
902             else if (sender == o_mi_double_window)
903                 var_SetFloat(p_vout, "zoom", 2.0);
904             else
905             {
906                 [[NSApp keyWindow] performZoom:sender];
907             }
908             vlc_object_release(p_vout);
909         }
910         vlc_object_release(p_input);
911     }
912 }
913
914 - (IBAction)floatOnTop:(id)sender
915 {
916     input_thread_t *p_input = pl_CurrentInput(VLCIntf);
917     if (p_input) {
918         vout_thread_t *p_vout = getVoutForActiveWindow();
919         if (p_vout) {
920             BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
921             var_SetBool(pl_Get(p_intf), "video-on-top", b_fs);
922
923             vlc_object_release(p_vout);
924         }
925         vlc_object_release(p_input);
926     }
927 }
928
929 - (IBAction)createVideoSnapshot:(id)sender
930 {
931     input_thread_t *p_input = pl_CurrentInput(VLCIntf);
932     if (p_input) {
933         vout_thread_t *p_vout = getVoutForActiveWindow();
934         if (p_vout) {
935             var_TriggerCallback(p_vout, "video-snapshot");
936             vlc_object_release(p_vout);
937         }
938         vlc_object_release(p_input);
939     }
940 }
941
942 - (void)_disablePostProcessing
943 {
944     [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
945 }
946
947 - (void)_enablePostProcessing
948 {
949     [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
950 }
951
952 - (IBAction)togglePostProcessing:(id)sender
953 {
954     char *psz_name = "postproc";
955     NSInteger count = [o_mu_ffmpeg_pp numberOfItems];
956     for (NSUInteger x = 0; x < count; x++)
957         [[o_mu_ffmpeg_pp itemAtIndex:x] setState:NSOffState];
958
959     if ([sender tag] == -1) {
960         [self _disablePostProcessing];
961         [sender setState:NSOnState];
962     } else {
963         [self _enablePostProcessing];
964         [sender setState:NSOnState];
965
966         [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" integer:[sender tag]];
967     }
968 }
969
970 - (IBAction)toggleFullscreenDevice:(id)sender
971 {
972     config_PutInt(VLCIntf, "macosx-vdev", [sender tag]);
973     [self refreshVoutDeviceMenu: nil];
974 }
975
976 - (id)voutMenu
977 {
978     return o_vout_menu;
979 }
980
981 #pragma mark - Subtitles Menu
982
983 - (IBAction)addSubtitleFile:(id)sender
984 {
985     NSInteger i_returnValue = 0;
986     input_thread_t * p_input = pl_CurrentInput(VLCIntf);
987     if (!p_input)
988         return;
989
990     input_item_t *p_item = input_GetItem(p_input);
991     if (!p_item) {
992         vlc_object_release(p_input);
993         return;
994     }
995
996     char *path = input_item_GetURI(p_item);
997
998     if (!path)
999         path = strdup("");
1000
1001     NSOpenPanel * openPanel = [NSOpenPanel openPanel];
1002     [openPanel setCanChooseFiles: YES];
1003     [openPanel setCanChooseDirectories: NO];
1004     [openPanel setAllowsMultipleSelection: YES];
1005
1006     [openPanel setAllowedFileTypes: [NSArray arrayWithObjects:@"cdg",@"idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil",nil]];
1007
1008     NSURL *o_url = [NSURL URLWithString:[[NSString stringWithUTF8String:path] stringByExpandingTildeInPath]];
1009     o_url = [o_url URLByDeletingLastPathComponent];
1010     [openPanel setDirectoryURL: o_url];
1011     free(path);
1012     vlc_object_release(p_input);
1013
1014     i_returnValue = [openPanel runModal];
1015
1016     if (i_returnValue == NSOKButton)
1017         [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
1018 }
1019
1020 - (IBAction)switchSubtitleOption:(id)sender
1021 {
1022     int intValue = [sender tag];
1023     NSString *representedObject = [sender representedObject];
1024
1025     config_PutInt(p_intf, [representedObject UTF8String], intValue);
1026
1027     NSMenu *menu = [sender menu];
1028     NSUInteger count = (NSUInteger) [menu numberOfItems];
1029     for (NSUInteger x = 0; x < count; x++)
1030         [[menu itemAtIndex:x] setState:NSOffState];
1031     [[menu itemWithTag:intValue] setState:NSOnState];
1032 }
1033
1034 - (IBAction)switchSubtitleBackgroundOpacity:(id)sender
1035 {
1036     config_PutInt(p_intf, "freetype-background-opacity", [sender intValue]);
1037 }
1038
1039 - (IBAction)telxTransparent:(id)sender
1040 {
1041     vlc_object_t *p_vbi;
1042     p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
1043     if (p_vbi) {
1044         var_SetBool(p_vbi, "vbi-opaque", [sender state]);
1045         [sender setState: ![sender state]];
1046         vlc_object_release(p_vbi);
1047     }
1048 }
1049
1050 - (IBAction)telxNavLink:(id)sender
1051 {
1052     vlc_object_t *p_vbi;
1053     int i_page = 0;
1054
1055     if ([[sender title] isEqualToString: _NS("Index")])
1056         i_page = 'i' << 16;
1057     else if ([[sender title] isEqualToString: _NS("Red")])
1058         i_page = 'r' << 16;
1059     else if ([[sender title] isEqualToString: _NS("Green")])
1060         i_page = 'g' << 16;
1061     else if ([[sender title] isEqualToString: _NS("Yellow")])
1062         i_page = 'y' << 16;
1063     else if ([[sender title] isEqualToString: _NS("Blue")])
1064         i_page = 'b' << 16;
1065     if (i_page == 0) return;
1066
1067     p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
1068     if (p_vbi) {
1069         var_SetInteger(p_vbi, "vbi-page", i_page);
1070         vlc_object_release(p_vbi);
1071     }
1072 }
1073
1074 #pragma mark - Panels
1075
1076 - (IBAction)intfOpenFile:(id)sender
1077 {
1078     [[[VLCMain sharedInstance] open] openFile];
1079 }
1080
1081 - (IBAction)intfOpenFileGeneric:(id)sender
1082 {
1083     [[[VLCMain sharedInstance] open] openFileGeneric];
1084 }
1085
1086 - (IBAction)intfOpenDisc:(id)sender
1087 {
1088     [[[VLCMain sharedInstance] open] openDisc];
1089 }
1090
1091 - (IBAction)intfOpenNet:(id)sender
1092 {
1093     [[[VLCMain sharedInstance] open] openNet];
1094 }
1095
1096 - (IBAction)intfOpenCapture:(id)sender
1097 {
1098     [[[VLCMain sharedInstance] open] openCapture];
1099 }
1100
1101 - (IBAction)showWizard:(id)sender
1102 {
1103     [[[VLCMain sharedInstance] wizard] resetWizard];
1104     [[[VLCMain sharedInstance] wizard] showWizard];
1105 }
1106
1107 - (IBAction)savePlaylist:(id)sender
1108 {
1109     [[[VLCMain sharedInstance] playlist] savePlaylist:sender];
1110 }
1111
1112 - (IBAction)showConvertAndSave:(id)sender
1113 {
1114     if (o_convertandsave == nil)
1115         o_convertandsave = [[VLCConvertAndSave alloc] init];
1116
1117     if (!b_nib_convertandsave_loaded)
1118         b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];
1119
1120     [o_convertandsave toggleWindow];
1121 }
1122
1123 - (IBAction)showVideoEffects:(id)sender
1124 {
1125     if (o_videoeffects == nil)
1126         o_videoeffects = [[VLCVideoEffects alloc] init];
1127
1128     if (!b_nib_videoeffects_loaded)
1129         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
1130
1131     [o_videoeffects toggleWindow:sender];
1132 }
1133
1134 - (IBAction)showTrackSynchronization:(id)sender
1135 {
1136     if (!o_trackSynchronization)
1137         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
1138
1139     if (!b_nib_tracksynchro_loaded)
1140         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
1141
1142     [o_trackSynchronization toggleWindow:sender];
1143 }
1144
1145 - (IBAction)showAudioEffects:(id)sender
1146 {
1147     if (!o_audioeffects)
1148         o_audioeffects = [[VLCAudioEffects alloc] init];
1149
1150     if (!b_nib_audioeffects_loaded)
1151         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
1152
1153     [o_audioeffects toggleWindow:sender];
1154 }
1155
1156 - (IBAction)showBookmarks:(id)sender
1157 {
1158     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
1159 }
1160
1161 - (IBAction)viewPreferences:(id)sender
1162 {
1163     NSInteger i_level = [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel];
1164     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
1165 }
1166
1167 - (IBAction)openAddonManager:(id)sender
1168 {
1169     if (!o_addonManager)
1170         o_addonManager = [[VLCAddonManager alloc] init];
1171
1172     if (!b_nib_addonmanager_loaded)
1173         b_nib_addonmanager_loaded = [NSBundle loadNibNamed:@"AddonManager" owner:NSApp];
1174
1175     [o_addonManager showWindow];
1176 }
1177
1178 - (IBAction)showMessagesPanel:(id)showMessagesPanel
1179 {
1180     [[VLCDebugMessageVisualizer sharedInstance] showPanel];
1181 }
1182
1183 - (IBAction)showMainWindow:(id)sender
1184 {
1185     [[VLCMainWindow sharedInstance] makeKeyAndOrderFront:sender];
1186 }
1187
1188 - (IBAction)showPlaylist:(id)sender
1189 {
1190     [[VLCMainWindow sharedInstance] changePlaylistState: psUserMenuEvent];
1191 }
1192
1193 #pragma mark - Help and Docs
1194
1195 - (void)initAbout
1196 {
1197     if (! o_about)
1198         o_about = [[VLAboutBox alloc] init];
1199
1200     if (!b_nib_about_loaded)
1201         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
1202 }
1203
1204 - (IBAction)viewAbout:(id)sender
1205 {
1206     [self initAbout];
1207     [o_about showAbout];
1208 }
1209
1210 - (IBAction)showLicense:(id)sender
1211 {
1212     [self initAbout];
1213     [o_about showGPL];
1214 }
1215
1216 - (IBAction)viewHelp:(id)sender
1217 {
1218     [self initAbout];
1219     [o_about showHelp];
1220 }
1221
1222 - (IBAction)openReadMe:(id)sender
1223 {
1224     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
1225
1226     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
1227 }
1228
1229 - (IBAction)openDocumentation:(id)sender
1230 {
1231     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
1232
1233     [[NSWorkspace sharedWorkspace] openURL: o_url];
1234 }
1235
1236 - (IBAction)openWebsite:(id)sender
1237 {
1238     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
1239
1240     [[NSWorkspace sharedWorkspace] openURL: o_url];
1241 }
1242
1243 - (IBAction)openForum:(id)sender
1244 {
1245     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
1246
1247     [[NSWorkspace sharedWorkspace] openURL: o_url];
1248 }
1249
1250 - (IBAction)openDonate:(id)sender
1251 {
1252     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
1253
1254     [[NSWorkspace sharedWorkspace] openURL: o_url];
1255 }
1256
1257 #pragma mark - Errors, warnings and messages
1258
1259 - (IBAction)viewErrorsAndWarnings:(id)sender
1260 {
1261     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
1262 }
1263
1264 - (IBAction)showInformationPanel:(id)sender
1265 {
1266     [[[VLCMain sharedInstance] info] initPanel];
1267 }
1268
1269 #pragma mark - convinience stuff for other objects
1270
1271 - (void)setPlay
1272 {
1273     [o_mi_play setTitle: _NS("Play")];
1274     [o_dmi_play setTitle: _NS("Play")];
1275     [o_vmi_play setTitle: _NS("Play")];
1276 }
1277
1278 - (void)setPause
1279 {
1280     [o_mi_play setTitle: _NS("Pause")];
1281     [o_dmi_play setTitle: _NS("Pause")];
1282     [o_vmi_play setTitle: _NS("Pause")];
1283 }
1284
1285 - (void)setRepeatOne
1286 {
1287     [o_mi_repeat setState: NSOnState];
1288     [o_mi_loop setState: NSOffState];
1289 }
1290
1291 - (void)setRepeatAll
1292 {
1293     [o_mi_repeat setState: NSOffState];
1294     [o_mi_loop setState: NSOnState];
1295 }
1296
1297 - (void)setRepeatOff
1298 {
1299     [o_mi_repeat setState: NSOffState];
1300     [o_mi_loop setState: NSOffState];
1301 }
1302
1303 - (void)setShuffle
1304 {
1305     bool b_value;
1306     playlist_t *p_playlist = pl_Get(VLCIntf);
1307     b_value = var_GetBool(p_playlist, "random");
1308
1309     [o_mi_random setState: b_value];
1310 }
1311
1312 #pragma mark - Dynamic menu creation and validation
1313
1314 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
1315                   target:(vlc_object_t *)p_object
1316                      var:(const char *)psz_variable
1317                 selector:(SEL)pf_callback
1318 {
1319     vlc_value_t val, text;
1320     int i_type = var_Type(p_object, psz_variable);
1321
1322     switch(i_type & VLC_VAR_TYPE) {
1323         case VLC_VAR_VOID:
1324         case VLC_VAR_BOOL:
1325         case VLC_VAR_VARIABLE:
1326         case VLC_VAR_STRING:
1327         case VLC_VAR_INTEGER:
1328             break;
1329         default:
1330             /* Variable doesn't exist or isn't handled */
1331             msg_Warn(p_object, "variable %s doesn't exist or isn't handled", psz_variable);
1332             return;
1333     }
1334
1335     /* Get the descriptive name of the variable */
1336     var_Change(p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL);
1337     [o_mi setTitle: _NS(text.psz_string ? text.psz_string : psz_variable)];
1338
1339     if (i_type & VLC_VAR_HASCHOICE) {
1340         NSMenu *o_menu = [o_mi submenu];
1341
1342         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
1343                        var:psz_variable selector:pf_callback];
1344
1345         free(text.psz_string);
1346         return;
1347     }
1348
1349     if (var_Get(p_object, psz_variable, &val) < 0)
1350         return;
1351
1352     VLCAutoGeneratedMenuContent *o_data;
1353     switch(i_type & VLC_VAR_TYPE) {
1354         case VLC_VAR_VOID:
1355             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1356                                                                       andValue: val ofType: i_type];
1357             [o_mi setRepresentedObject: [o_data autorelease]];
1358             break;
1359
1360         case VLC_VAR_BOOL:
1361             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1362                                                                       andValue: val ofType: i_type];
1363             [o_mi setRepresentedObject: [o_data autorelease]];
1364             if (!(i_type & VLC_VAR_ISCOMMAND))
1365                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
1366             break;
1367
1368         default:
1369             break;
1370     }
1371
1372     if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1373     free(text.psz_string);
1374 }
1375
1376
1377 - (void)setupVarMenu:(NSMenu *)o_menu
1378          forMenuItem: (NSMenuItem *)o_parent
1379               target:(vlc_object_t *)p_object
1380                  var:(const char *)psz_variable
1381             selector:(SEL)pf_callback
1382 {
1383     vlc_value_t val, val_list, text_list;
1384     int i_type, i;
1385
1386     /* remove previous items */
1387     [o_menu removeAllItems];
1388
1389     /* we disable everything here, and enable it again when needed, below */
1390     [o_parent setEnabled:NO];
1391
1392     /* Aspect Ratio */
1393     if ([[o_parent title] isEqualToString: _NS("Aspect ratio")] == YES) {
1394         NSMenuItem *o_lmi_tmp2;
1395         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1396         [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1397         [o_lmi_tmp2 setEnabled: YES];
1398         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1399         [o_parent setEnabled: YES];
1400         [o_menu addItem: [NSMenuItem separatorItem]];
1401     }
1402
1403     /* Check the type of the object variable */
1404     i_type = var_Type(p_object, psz_variable);
1405
1406     /* Make sure we want to display the variable */
1407     if (i_type & VLC_VAR_HASCHOICE) {
1408         var_Change(p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL);
1409         if (val.i_int == 0)
1410             return;
1411         if ((i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1)
1412             return;
1413     }
1414     else
1415         return;
1416
1417     switch(i_type & VLC_VAR_TYPE) {
1418         case VLC_VAR_VOID:
1419         case VLC_VAR_BOOL:
1420         case VLC_VAR_VARIABLE:
1421         case VLC_VAR_STRING:
1422         case VLC_VAR_INTEGER:
1423             break;
1424         default:
1425             /* Variable doesn't exist or isn't handled */
1426             return;
1427     }
1428
1429     if (var_Get(p_object, psz_variable, &val) < 0) {
1430         return;
1431     }
1432
1433     if (var_Change(p_object, psz_variable, VLC_VAR_GETLIST,
1434                    &val_list, &text_list) < 0) {
1435         if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1436         return;
1437     }
1438
1439     /* make (un)sensitive */
1440     [o_parent setEnabled: (val_list.p_list->i_count > 1)];
1441
1442     for (i = 0; i < val_list.p_list->i_count; i++) {
1443         NSMenuItem * o_lmi;
1444         NSString *o_title = @"";
1445         VLCAutoGeneratedMenuContent *o_data;
1446
1447         switch(i_type & VLC_VAR_TYPE) {
1448             case VLC_VAR_STRING:
1449
1450                 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);
1451
1452                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1453                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1454                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1455                 [o_lmi setRepresentedObject: [o_data autorelease]];
1456                 [o_lmi setTarget: self];
1457
1458                 if (!strcmp(val.psz_string, val_list.p_list->p_values[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
1459                     [o_lmi setState: TRUE ];
1460
1461                 break;
1462
1463             case VLC_VAR_INTEGER:
1464
1465                 o_title = text_list.p_list->p_values[i].psz_string ?
1466                 _NS(text_list.p_list->p_values[i].psz_string) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1467
1468                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1469                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1470                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1471                 [o_lmi setRepresentedObject: [o_data autorelease]];
1472                 [o_lmi setTarget: self];
1473
1474                 if (val_list.p_list->p_values[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
1475                     [o_lmi setState: TRUE ];
1476                 break;
1477
1478             default:
1479                 break;
1480         }
1481     }
1482
1483     /* clean up everything */
1484     if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1485     var_FreeList(&val_list, &text_list);
1486 }
1487
1488 - (IBAction)toggleVar:(id)sender
1489 {
1490     NSMenuItem *o_mi = (NSMenuItem *)sender;
1491     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1492     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1493                              toTarget: self withObject: o_data];
1494
1495     return;
1496 }
1497
1498 - (int)toggleVarThread: (id)data
1499 {
1500     vlc_object_t *p_object;
1501     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1502
1503     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1504     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1505
1506     p_object = [menuContent vlcObject];
1507
1508     if (p_object != NULL) {
1509         var_Set(p_object, [menuContent name], [menuContent value]);
1510         vlc_object_release(p_object);
1511         [o_pool release];
1512         return true;
1513     }
1514     [o_pool release];
1515     return VLC_EGENERIC;
1516 }
1517
1518 @end
1519
1520 @implementation VLCMainMenu (NSMenuValidation)
1521
1522 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1523 {
1524     NSString *o_title = [o_mi title];
1525     BOOL bEnabled = TRUE;
1526     vlc_value_t val;
1527     playlist_t * p_playlist = pl_Get(p_intf);
1528     input_thread_t * p_input = playlist_CurrentInput(p_playlist);
1529
1530     if ([o_title isEqualToString: _NS("Stop")]) {
1531         if (!p_input)
1532             bEnabled = FALSE;
1533         [self setupMenus]; /* Make sure input menu is up to date */
1534     } else if ([o_title isEqualToString: _NS("Previous")] ||
1535             [o_title isEqualToString: _NS("Next")]) {
1536         PL_LOCK;
1537         bEnabled = playlist_CurrentSize(p_playlist) > 1;
1538         PL_UNLOCK;
1539     } else if ([o_title isEqualToString: _NS("Random")]) {
1540         int i_state;
1541         var_Get(p_playlist, "random", &val);
1542         i_state = val.b_bool ? NSOnState : NSOffState;
1543         [o_mi setState: i_state];
1544     } else if ([o_title isEqualToString: _NS("Repeat One")]) {
1545         int i_state;
1546         var_Get(p_playlist, "repeat", &val);
1547         i_state = val.b_bool ? NSOnState : NSOffState;
1548         [o_mi setState: i_state];
1549     } else if ([o_title isEqualToString: _NS("Repeat All")]) {
1550         int i_state;
1551         var_Get(p_playlist, "loop", &val);
1552         i_state = val.b_bool ? NSOnState : NSOffState;
1553         [o_mi setState: i_state];
1554     } else if ([o_title isEqualToString: _NS("Quit after Playback")]) {
1555         int i_state;
1556         bool b_value = var_InheritBool(p_playlist, "play-and-exit");
1557         i_state = b_value ? NSOnState : NSOffState;
1558         [o_mi setState: i_state];
1559     } else if ([o_title isEqualToString: _NS("Step Forward")] ||
1560                [o_title isEqualToString: _NS("Step Backward")] ||
1561                [o_title isEqualToString: _NS("Jump to Time")]) {
1562         if (p_input != NULL) {
1563             var_Get(p_input, "can-seek", &val);
1564             bEnabled = val.b_bool;
1565         }
1566         else bEnabled = FALSE;
1567     } else if ([o_title isEqualToString: _NS("Mute")]) {
1568         [o_mi setState: [[VLCCoreInteraction sharedInstance] mute] ? NSOnState : NSOffState];
1569         [self setupMenus]; /* Make sure audio menu is up to date */
1570         [self refreshAudioDeviceList];
1571     } else if ([o_title isEqualToString: _NS("Half Size")] ||
1572                [o_title isEqualToString: _NS("Normal Size")] ||
1573                [o_title isEqualToString: _NS("Double Size")] ||
1574                [o_title isEqualToString: _NS("Fit to Screen")] ||
1575                [o_title isEqualToString: _NS("Snapshot")] ||
1576                [o_title isEqualToString: _NS("Fullscreen")] ||
1577                [o_title isEqualToString: _NS("Float on Top")]) {
1578         bEnabled = FALSE;
1579
1580         if (p_input != NULL) {
1581             vout_thread_t *p_vout = getVoutForActiveWindow();
1582             if (p_vout != NULL) {
1583                 if ([o_title isEqualToString: _NS("Float on Top")])
1584                     [o_mi setState: var_GetBool(p_vout, "video-on-top")];
1585
1586                 if ([o_title isEqualToString: _NS("Fullscreen")])
1587                     [o_mi setState: var_GetBool(p_vout, "fullscreen")];
1588
1589                 bEnabled = TRUE;
1590                 vlc_object_release(p_vout);
1591             }
1592         }
1593
1594         [self setupMenus]; /* Make sure video menu is up to date */
1595
1596     } else if ([o_title isEqualToString: _NS("Add Subtitle File...")]) {
1597         bEnabled = [o_mi isEnabled];
1598         [self setupMenus]; /* Make sure subtitles menu is up to date */
1599     } else {
1600         NSMenuItem *o_mi_parent = [o_mi parentItem];
1601         if (o_mi_parent == o_mi_subtitle_size || o_mi == o_mi_subtitle_size ||
1602             o_mi_parent == o_mi_subtitle_textcolor || o_mi == o_mi_subtitle_textcolor ||
1603             o_mi_parent == o_mi_subtitle_bgcolor || o_mi == o_mi_subtitle_bgcolor ||
1604             o_mi_parent == o_mi_subtitle_bgopacity || o_mi == o_mi_subtitle_bgopacity ||
1605             o_mi_parent == o_mi_subtitle_outlinethickness || o_mi == o_mi_subtitle_outlinethickness ||
1606             o_mi_parent == o_mi_teletext || o_mi == o_mi_teletext)
1607             bEnabled = o_mi_openSubtitleFile.isEnabled;
1608     }
1609
1610     /* Special case for telx menu */
1611     if ([o_title isEqualToString: _NS("Normal Size")]) {
1612         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1613         bool b_telx = p_input && var_GetInteger(p_input, "teletext-es") >= 0;
1614
1615         [[item submenu] setAutoenablesItems:NO];
1616
1617         for (int k=0; k < [[item submenu] numberOfItems]; k++)
1618             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1619     }
1620
1621     if (p_input)
1622         vlc_object_release(p_input);
1623
1624     return bEnabled;
1625 }
1626
1627 @end
1628
1629
1630 /*****************************************************************************
1631  * VLCAutoGeneratedMenuContent implementation
1632  *****************************************************************************
1633  * Object connected to a playlistitem which remembers the data belonging to
1634  * the variable of the autogenerated menu
1635  *****************************************************************************/
1636 @implementation VLCAutoGeneratedMenuContent
1637
1638 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1639                   andValue:(vlc_value_t)val ofType:(int)type
1640 {
1641     self = [super init];
1642
1643     if (self != nil) {
1644         _vlc_object = vlc_object_hold(object);
1645         psz_name = strdup(name);
1646         i_type = type;
1647         value = val;
1648         if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1649             value.psz_string = strdup(val.psz_string);
1650     }
1651
1652     return(self);
1653 }
1654
1655 - (void)dealloc
1656 {
1657     if (_vlc_object)
1658         vlc_object_release(_vlc_object);
1659     if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1660         free(value.psz_string);
1661     free(psz_name);
1662     [super dealloc];
1663 }
1664
1665 - (const char *)name
1666 {
1667     return psz_name;
1668 }
1669
1670 - (vlc_value_t)value
1671 {
1672     return value;
1673 }
1674
1675 - (vlc_object_t *)vlcObject
1676 {
1677     return vlc_object_hold(_vlc_object);
1678 }
1679
1680
1681 - (int)type
1682 {
1683     return i_type;
1684 }
1685
1686 @end