]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainMenu.m
macosx: robustify playlist table columns initialization
[vlc] / modules / gui / macosx / MainMenu.m
index 5ed377f51184765f4688f6c6c1862ff0b31f085a..baa83d2f7fdf98f42f7bf9b56046625bf095cff8 100644 (file)
@@ -45,6 +45,7 @@
 #import "ExtensionsManager.h"
 #import "ConvertAndSave.h"
 #import "DebugMessageVisualizer.h"
+#import "AddonManager.h"
 
 @implementation VLCMainMenu
 static VLCMainMenu *_o_sharedInstance = nil;
@@ -76,11 +77,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;
@@ -289,8 +292,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 +316,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("Addon Manager")];
     [o_mi_add_intf setTitle: _NS("Add Interface")];
     [o_mu_add_intf setTitle: _NS("Add Interface")];
     [o_mi_services setTitle: _NS("Services")];
@@ -325,6 +332,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_open_net setTitle: _NS("Open Network...")];
     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
     [o_mi_open_recent setTitle: _NS("Open Recent")];
+    [o_mi_close_window setTitle: _NS("Close Window")];
     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
     [o_mi_convertandsave setTitle: _NS("Convert / Stream...")];
     [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
@@ -432,8 +440,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_teletext_blue setTitle: _NS("Blue")];
 
     [o_mu_window setTitle: _NS("Window")];
-    [o_mi_minimize setTitle: _NS("Minimize Window")];
-    [o_mi_close_window setTitle: _NS("Close Window")];
+    [o_mi_minimize setTitle: _NS("Minimize")];
+    [o_mi_zoom_window setTitle: _NS("Zoom")];
     [o_mi_player setTitle: _NS("Player...")];
     [o_mi_controller setTitle: _NS("Main Window...")];
     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
@@ -574,11 +582,9 @@ 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
+            [self setupVarMenuItem: o_mi_ffmpeg_pp target: (vlc_object_t *)p_vout
+                               var:"postprocess" selector: @selector(toggleVar:)];
+
             vlc_object_release(p_vout);
 
             [self refreshVoutDeviceMenu:nil];
@@ -591,7 +597,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (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];
@@ -745,16 +751,31 @@ 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 -
 #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);
+}
+
 - (IBAction)toggleRecord:(id)sender
 {
     [[VLCCoreInteraction sharedInstance] toggleRecord];
@@ -975,7 +996,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];
@@ -999,7 +1020,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;
 
@@ -1116,6 +1136,17 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[[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];
@@ -1128,7 +1159,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (IBAction)showPlaylist:(id)sender
 {
-    [[VLCMainWindow sharedInstance] togglePlaylist:sender];
+    [[VLCMainWindow sharedInstance] changePlaylistState: psUserMenuEvent];
 }
 
 #pragma mark -
@@ -1272,6 +1303,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;
     }
 
@@ -1289,9 +1321,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) {
@@ -1501,12 +1532,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;