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