]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainMenu.m
macosx: do not allow playlist item deletion for sd modules
[vlc] / modules / gui / macosx / MainMenu.m
index 2e38a46f20ede537ff4b502e7077ea5d2d587ef2..2fda43e98586e745e27d4e2f68ea1ef82e911ab6 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * MainMenu.m: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2011-2013 Felix Paul Kühne
+ * Copyright (C) 2011-2014 Felix Paul Kühne
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
  *****************************************************************************/
 
 #import "MainMenu.h"
+#import "intf.h"
+
 #import <vlc_common.h>
 #import <vlc_playlist.h>
+#import <vlc_input.h>
 
-#import "intf.h"
 #import "open.h"
 #import "wizard.h"
 #import "about.h"
@@ -45,6 +47,7 @@
 #import "ExtensionsManager.h"
 #import "ConvertAndSave.h"
 #import "DebugMessageVisualizer.h"
+#import "AddonManager.h"
 
 @implementation VLCMainMenu
 static VLCMainMenu *_o_sharedInstance = nil;
@@ -54,8 +57,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
 }
 
-#pragma mark -
-#pragma mark Initialization
+#pragma mark - Initialization
 
 - (id)init
 {
@@ -76,11 +78,13 @@ static VLCMainMenu *_o_sharedInstance = nil;
                       _NS("Date"),          DATE_COLUMN,
                       _NS("Language"),      LANGUAGE_COLUMN,
                       _NS("URI"),           URI_COLUMN,
+                      _NS("File Size"),     FILESIZE_COLUMN,
                       nil];
         // this array also assigns tags (index) to type of menu item
         o_ptc_menuorder = [[NSArray alloc] initWithObjects: TRACKNUM_COLUMN, TITLE_COLUMN,
                            ARTIST_COLUMN, DURATION_COLUMN, GENRE_COLUMN, ALBUM_COLUMN,
-                           DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN, nil];
+                           DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN,
+                           FILESIZE_COLUMN,nil];
     }
 
     return _o_sharedInstance;
@@ -261,7 +265,46 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
                              var: "intf-add" selector: @selector(toggleVar:)];
 
-    [self setupExtensionsMenu];
+    /* setup extensions menu */
+    // FIXME: Implement preference for autoloading extensions on mac
+    if (![o_extMgr isLoaded] && ![o_extMgr cannotLoad])
+        [o_extMgr loadExtensions];
+
+    /* Let the ExtensionsManager itself build the menu */
+    [o_extMgr buildMenu:o_mu_extensions];
+    [o_mi_extensions setEnabled: ([o_mu_extensions numberOfItems] > 0)];
+
+    /* setup post-proc menu */
+    NSUInteger count = (NSUInteger) [o_mu_ffmpeg_pp numberOfItems];
+    if (count > 0)
+        [o_mu_ffmpeg_pp removeAllItems];
+
+    NSMenuItem * o_mitem;
+    [o_mu_ffmpeg_pp setAutoenablesItems: YES];
+    [o_mu_ffmpeg_pp addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
+    o_mitem = [o_mu_ffmpeg_pp itemAtIndex: 0];
+    [o_mitem setTag: -1];
+    [o_mitem setEnabled: YES];
+    [o_mitem setTarget: self];
+    for (NSUInteger x = 1; x < 7; x++) {
+        [o_mu_ffmpeg_pp addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
+                                               action:@selector(togglePostProcessing:)
+                                        keyEquivalent:@""];
+        o_mitem = [o_mu_ffmpeg_pp itemAtIndex:x];
+        [o_mitem setEnabled:YES];
+        [o_mitem setTag:x];
+        [o_mitem setTarget:self];
+    }
+    char *psz_config = config_GetPsz(p_intf, "video-filter");
+    if (psz_config) {
+        if (!strstr(psz_config, "postproc"))
+            [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
+        else
+            [[o_mu_ffmpeg_pp itemWithTag:config_GetInt(p_intf, "postproc-q")] setState:NSOnState];
+        free(psz_config);
+    } else
+        [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
+    [o_mi_ffmpeg_pp setEnabled: NO];
 
     [self refreshAudioDeviceList];
 
@@ -289,8 +332,11 @@ static VLCMainMenu *_o_sharedInstance = nil;
             mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
         else if (p_item->list.i[i])
             mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
-        else
+        else {
             msg_Err(p_intf, "item %d of pref %s failed to be created", i, psz_name);
+            continue;
+        }
+
         [mi setTarget:self];
         [mi setAction:selector];
         [mi setTag:p_item->list.i[i]];
@@ -310,6 +356,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_prefs setTitle: _NS("Preferences...")];
     [o_mi_extensions setTitle: _NS("Extensions")];
     [o_mu_extensions setTitle: _NS("Extensions")];
+    [o_mi_addonManager setTitle: _NS("Addons Manager")];
     [o_mi_add_intf setTitle: _NS("Add Interface")];
     [o_mu_add_intf setTitle: _NS("Add Interface")];
     [o_mi_services setTitle: _NS("Services")];
@@ -504,8 +551,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     return [o_context_menu autorelease];
 }
 
-#pragma mark -
-#pragma mark Termination
+#pragma mark - Termination
 
 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
 {
@@ -522,8 +568,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     }
 }
 
-#pragma mark -
-#pragma mark Interface update
+#pragma mark - Interface update
 
 - (void)setupMenus
 {
@@ -575,24 +620,21 @@ static VLCMainMenu *_o_sharedInstance = nil;
             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
 
-#if 1
-            [self setupVarMenuItem: o_mi_ffmpeg_pp target:
-             (vlc_object_t *)p_vout var:"postprocess" selector:
-             @selector(toggleVar:)];
-#endif
             vlc_object_release(p_vout);
 
             [self refreshVoutDeviceMenu:nil];
         }
+        [o_mi_ffmpeg_pp setEnabled:YES];
         vlc_object_release(p_input);
-    }
-    else
+    } else {
         [o_mi_record setEnabled: NO];
+        [o_mi_ffmpeg_pp setEnabled:NO];
+    }
 }
 
 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
 {
-    NSUInteger count = [o_mu_screen numberOfItems];
+    NSUInteger count = (NSUInteger) [o_mu_screen numberOfItems];
     NSMenu * o_submenu = o_mu_screen;
     if (count > 0)
         [o_submenu removeAllItems];
@@ -631,7 +673,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_channels setEnabled: b_enabled];
     [o_mi_deinterlace setEnabled: b_enabled];
     [o_mi_deinterlace_mode setEnabled: b_enabled];
-    [o_mi_ffmpeg_pp setEnabled: b_enabled];
     [o_mi_screen setEnabled: b_enabled];
     [o_mi_aspect_ratio setEnabled: b_enabled];
     [o_mi_crop setEnabled: b_enabled];
@@ -670,31 +711,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_pool release];
 }
 
-#pragma mark -
-#pragma mark Extensions
-
-- (void)setupExtensionsMenu
-{
-    /* Load extensions if needed */
-    // TODO: Implement preference for autoloading extensions on mac
-
-    // if (!var_InheritBool(p_intf, "qt-autoload-extensions")
-    //     && ![o_extMgr isLoaded])
-    // {
-    //     return;
-    // }
-
-    if (![o_extMgr isLoaded] && ![o_extMgr cannotLoad]) {
-        [o_extMgr loadExtensions];
-    }
-
-    /* Let the ExtensionsManager itself build the menu */
-    [o_extMgr buildMenu:o_mu_extensions];
-    [o_mi_extensions setEnabled: ([o_mu_extensions numberOfItems] > 0)];
-}
-
-#pragma mark -
-#pragma mark View
+#pragma mark - View
 
 - (IBAction)toggleEffectsButton:(id)sender
 {
@@ -746,16 +763,30 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
 }
 
-- (void)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
+- (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
 {
-    NSInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
+    NSUInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
+    // prevent setting unknown columns
+    if(i_tag == NSNotFound)
+        return NO;
+
     [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_state];
     [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_state translationDict: o_ptc_translation_dict];
+
+    return YES;
+}
+
+#pragma mark - Playback
+
+- (IBAction)quitAfterPlayback:(id)sender
+{
+    playlist_t *p_playlist = pl_Get(VLCIntf);
+    bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
+    var_SetBool(p_playlist, "play-and-exit", b_value);
+    config_PutInt(p_intf, "play-and-exit", b_value);
 }
 
-#pragma mark -
-#pragma mark Playback
 - (IBAction)toggleRecord:(id)sender
 {
     [[VLCCoreInteraction sharedInstance] toggleRecord];
@@ -787,8 +818,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[VLCCoreInteraction sharedInstance] setAtoB];
 }
 
-#pragma mark -
-#pragma mark audio menu
+#pragma mark - audio menu
+
 - (void)refreshAudioDeviceList
 {
     char **ids, **names;
@@ -851,8 +882,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [self refreshAudioDeviceList];
 }
 
-#pragma mark -
-#pragma mark video menu
+#pragma mark - video menu
 
 - (IBAction)toggleFullscreen:(id)sender
 {
@@ -887,7 +917,9 @@ static VLCMainMenu *_o_sharedInstance = nil;
     if (p_input) {
         vout_thread_t *p_vout = getVoutForActiveWindow();
         if (p_vout) {
-            var_ToggleBool(p_vout, "video-on-top");
+            BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
+            var_SetBool(pl_Get(p_intf), "video-on-top", b_fs);
+
             vlc_object_release(p_vout);
         }
         vlc_object_release(p_input);
@@ -907,6 +939,34 @@ static VLCMainMenu *_o_sharedInstance = nil;
     }
 }
 
+- (void)_disablePostProcessing
+{
+    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
+}
+
+- (void)_enablePostProcessing
+{
+    [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
+}
+
+- (IBAction)togglePostProcessing:(id)sender
+{
+    char *psz_name = "postproc";
+    NSInteger count = [o_mu_ffmpeg_pp numberOfItems];
+    for (NSUInteger x = 0; x < count; x++)
+        [[o_mu_ffmpeg_pp itemAtIndex:x] setState:NSOffState];
+
+    if ([sender tag] == -1) {
+        [self _disablePostProcessing];
+        [sender setState:NSOnState];
+    } else {
+        [self _enablePostProcessing];
+        [sender setState:NSOnState];
+
+        [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" integer:[sender tag]];
+    }
+}
+
 - (IBAction)toggleFullscreenDevice:(id)sender
 {
     config_PutInt(VLCIntf, "macosx-vdev", [sender tag]);
@@ -919,6 +979,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 }
 
 #pragma mark - Subtitles Menu
+
 - (IBAction)addSubtitleFile:(id)sender
 {
     NSInteger i_returnValue = 0;
@@ -948,24 +1009,12 @@ static VLCMainMenu *_o_sharedInstance = nil;
     o_url = [o_url URLByDeletingLastPathComponent];
     [openPanel setDirectoryURL: o_url];
     free(path);
+    vlc_object_release(p_input);
 
     i_returnValue = [openPanel runModal];
 
-    if (i_returnValue == NSOKButton) {
-        NSUInteger c = 0;
-        if (!p_input)
-            return;
-
-        c = [[openPanel URLs] count];
-
-        for (int i = 0; i < c ; i++) {
-            msg_Dbg(VLCIntf, "loading subs from %s", [[[[openPanel URLs] objectAtIndex:i] path] UTF8String]);
-            if (input_AddSubtitle(p_input, [[[[openPanel URLs] objectAtIndex:i] path] UTF8String], TRUE))
-                msg_Warn(VLCIntf, "unable to load subtitles from '%s'",
-                         [[[[openPanel URLs] objectAtIndex:i] path] UTF8String]);
-        }
-    }
-    vlc_object_release(p_input);
+    if (i_returnValue == NSOKButton)
+        [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
 }
 
 - (IBAction)switchSubtitleOption:(id)sender
@@ -976,7 +1025,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     config_PutInt(p_intf, [representedObject UTF8String], intValue);
 
     NSMenu *menu = [sender menu];
-    NSUInteger count = [menu numberOfItems];
+    NSUInteger count = (NSUInteger) [menu numberOfItems];
     for (NSUInteger x = 0; x < count; x++)
         [[menu itemAtIndex:x] setState:NSOffState];
     [[menu itemWithTag:intValue] setState:NSOnState];
@@ -1000,7 +1049,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (IBAction)telxNavLink:(id)sender
 {
-    intf_thread_t * p_intf = VLCIntf;
     vlc_object_t *p_vbi;
     int i_page = 0;
 
@@ -1023,8 +1071,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     }
 }
 
-#pragma mark -
-#pragma mark Panels
+#pragma mark - Panels
 
 - (IBAction)intfOpenFile:(id)sender
 {
@@ -1113,10 +1160,21 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (IBAction)viewPreferences:(id)sender
 {
-    NSInteger i_level = [[[VLCMain sharedInstance] voutController] currentWindowLevel];
+    NSInteger i_level = [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel];
     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
 }
 
+- (IBAction)openAddonManager:(id)sender
+{
+    if (!o_addonManager)
+        o_addonManager = [[VLCAddonManager alloc] init];
+
+    if (!b_nib_addonmanager_loaded)
+        b_nib_addonmanager_loaded = [NSBundle loadNibNamed:@"AddonManager" owner:NSApp];
+
+    [o_addonManager showWindow];
+}
+
 - (IBAction)showMessagesPanel:(id)showMessagesPanel
 {
     [[VLCDebugMessageVisualizer sharedInstance] showPanel];
@@ -1132,8 +1190,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[VLCMainWindow sharedInstance] changePlaylistState: psUserMenuEvent];
 }
 
-#pragma mark -
-#pragma mark Help and Docs
+#pragma mark - Help and Docs
 
 - (void)initAbout
 {
@@ -1197,8 +1254,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[NSWorkspace sharedWorkspace] openURL: o_url];
 }
 
-#pragma mark -
-#pragma mark Errors, warnings and messages
+#pragma mark - Errors, warnings and messages
 
 - (IBAction)viewErrorsAndWarnings:(id)sender
 {
@@ -1210,8 +1266,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[[VLCMain sharedInstance] info] initPanel];
 }
 
-#pragma mark -
-#pragma mark convinience stuff for other objects
+#pragma mark - convinience stuff for other objects
+
 - (void)setPlay
 {
     [o_mi_play setTitle: _NS("Play")];
@@ -1253,8 +1309,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_random setState: b_value];
 }
 
-#pragma mark -
-#pragma mark Dynamic menu creation and validation
+#pragma mark - Dynamic menu creation and validation
 
 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
                   target:(vlc_object_t *)p_object
@@ -1273,6 +1328,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
             break;
         default:
             /* Variable doesn't exist or isn't handled */
+            msg_Warn(p_object, "variable %s doesn't exist or isn't handled", psz_variable);
             return;
     }
 
@@ -1290,9 +1346,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
         return;
     }
 
-    if (var_Get(p_object, psz_variable, &val) < 0) {
+    if (var_Get(p_object, psz_variable, &val) < 0)
         return;
-    }
 
     VLCAutoGeneratedMenuContent *o_data;
     switch(i_type & VLC_VAR_TYPE) {
@@ -1375,7 +1430,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
         return;
     }
 
-    if (var_Change(p_object, psz_variable, VLC_VAR_GETLIST,
+    if (var_Change(p_object, psz_variable, VLC_VAR_GETCHOICES,
                    &val_list, &text_list) < 0) {
         if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
         return;
@@ -1448,10 +1503,6 @@ static VLCMainMenu *_o_sharedInstance = nil;
     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
 
-    /* Preserve settings across vouts via the playlist object: */
-    if (!strcmp([menuContent name], "fullscreen") || !strcmp([menuContent name], "video-on-top"))
-        var_Set(pl_Get(VLCIntf), [menuContent name] , [menuContent value]);
-
     p_object = [menuContent vlcObject];
 
     if (p_object != NULL) {
@@ -1502,12 +1553,12 @@ static VLCMainMenu *_o_sharedInstance = nil;
         [o_mi setState: i_state];
     } else if ([o_title isEqualToString: _NS("Quit after Playback")]) {
         int i_state;
-        var_Get(p_playlist, "play-and-exit", &val);
-        i_state = val.b_bool ? NSOnState : NSOffState;
+        bool b_value = var_InheritBool(p_playlist, "play-and-exit");
+        i_state = b_value ? NSOnState : NSOffState;
         [o_mi setState: i_state];
     } else if ([o_title isEqualToString: _NS("Step Forward")] ||
                [o_title isEqualToString: _NS("Step Backward")] ||
-               [o_title isEqualToString: _NS("Jump To Time")]) {
+               [o_title isEqualToString: _NS("Jump to Time")]) {
         if (p_input != NULL) {
             var_Get(p_input, "can-seek", &val);
             bEnabled = val.b_bool;