]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/prefs.m
macosx gui: use vlc_path2uri.
[vlc] / modules / gui / macosx / prefs.m
index f22ed19f9467022ce318fe99c3ceb65b9a7779f8..ae4812be8ef64511836c13720e9388fc1cf53465 100644 (file)
@@ -1,11 +1,12 @@
 /*****************************************************************************
  * prefs.m: MacOS X module for vlc
  *****************************************************************************
- * Copyright (C) 2002-2006 the VideoLAN team
+ * Copyright (C) 2002-2012 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Derk-Jan Hartman <hartman at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <vlc_common.h>
 #include <vlc_config_cat.h>
 
+#import "CompatibilityFixes.h"
 #import "intf.h"
 #import "prefs.h"
 #import "simple_prefs.h"
 #import "prefs_widgets.h"
-#import "vlc_keys.h"
+#import "CoreInteraction.h"
+#import <vlc_keys.h>
+#import <vlc_modules.h>
+#import <vlc_plugin.h>
 
 /* /!\ Warning: Unreadable code :/ */
 
     NSMutableArray *_children;
     NSMutableArray *_options;
     NSMutableArray *_subviews;
-    module_config_t * _configItem;
 }
-- (id)initWithConfigItem:(module_config_t *)configItem;
 
-- (id)initWithName:(NSString*)name andConfigItem:(module_config_t *)configItem;
+- (id)initWithName:(NSString*)name;
 
 - (int)numberOfChildren;
-- (VLCTreeItem *)childAtIndex:(int)i_index;
-
-- (module_config_t *)configItem;
+- (VLCTreeItem *)childAtIndex:(NSInteger)i_index;
 
 - (NSString *)name;
 - (NSMutableArray *)children;
 /* Plugin daughters */
 @interface VLCTreePluginItem : VLCTreeItem
 {
+    module_config_t * _configItems;
+    unsigned int _configSize;
 }
 + (VLCTreePluginItem *)pluginTreeItemWithPlugin:(module_t *)plugin;
 - (id)initWithPlugin:(module_t *)plugin;
+
+- (module_config_t *)configItems;
+- (unsigned int)configSize;
 @end
 
 /* CONFIG_CAT */
 }
 + (VLCTreeCategoryItem *)categoryTreeItemWithCategory:(int)category;
 - (id)initWithCategory:(int)category;
+
 - (int)category;
 - (VLCTreeSubCategoryItem *)itemRepresentingSubCategory:(int)category;
 @end
 
 /* individual options. */
 @interface VLCTreeLeafItem : VLCTreeItem
-{ }
+{
+    module_config_t * _configItem;
+}
+- (id)initWithConfigItem:(module_config_t *)configItem;
+
+- (module_config_t *)configItem;
 @end
 
-@interface VLCTreeMainItem : VLCTreeItem
+@interface VLCTreeMainItem : VLCTreePluginItem
 {
-    module_config_t * _configItems;
 }
 - (VLCTreeCategoryItem *)itemRepresentingCategory:(int)category;
 @end
@@ -168,12 +179,15 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 {
     p_intf = VLCIntf;
 
+    if (OSX_LION)
+        [o_prefs_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
+
     [self initStrings];
     [o_prefs_view setBorderType: NSGrooveBorder];
     [o_prefs_view setHasVerticalScroller: YES];
     [o_prefs_view setDrawsBackground: NO];
     [o_prefs_view setDocumentView: o_empty_view];
-    [o_tree selectRow:0 byExtendingSelection:NO];
+    [o_tree selectRowIndexes: [NSIndexSet indexSetWithIndex: 0] byExtendingSelection: NO];
 }
 
 - (void)setTitle: (NSString *) o_title_name
@@ -181,13 +195,12 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     [o_title setStringValue: o_title_name];
 }
 
-- (void)showPrefs
+- (void)showPrefsWithLevel:(NSInteger)i_window_level
 {
-    [[o_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
-    [[o_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
-    
+    [o_prefs_window setLevel: i_window_level];
     [o_prefs_window center];
     [o_prefs_window makeKeyAndOrderFront:self];
+    [_rootTreeItem resetView];
 }
 
 - (void)initStrings
@@ -196,15 +209,15 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     [o_save_btn setTitle: _NS("Save")];
     [o_cancel_btn setTitle: _NS("Cancel")];
     [o_reset_btn setTitle: _NS("Reset All")];
-    [[o_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
-    [[o_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
+    [o_showBasic_btn setTitle: _NS("Show Basic")];
 }
 
 - (IBAction)savePrefs: (id)sender
 {
     /* TODO: call savePrefs on Root item */
     [_rootTreeItem applyChanges];
-    config_SaveConfigFile( p_intf, NULL );
+    [[VLCCoreInteraction sharedInstance] fixPreferences];
+    config_SaveConfigFile( p_intf );
     [o_prefs_window orderOut:self];
 }
 
@@ -227,19 +240,14 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 {
     if( i_return == NSAlertAlternateReturn )
     {
-        [o_prefs_view setDocumentView: o_empty_view];
         config_ResetAll( p_intf );
         [_rootTreeItem resetView];
-        [[o_tree itemAtRow:[o_tree selectedRow]]
-            showView:o_prefs_view];
     }
 }
 
 - (IBAction)buttonAction: (id)sender
 {
     [o_prefs_window orderOut: self];
-    [[o_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
-    [[o_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
 }
 
@@ -255,6 +263,7 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
 {
     [[o_tree itemAtRow:[o_tree selectedRow]] showView: o_prefs_view];
+    [o_tree expandItem:[o_tree itemAtRow:[o_tree selectedRow]]];
 }
 
 @end
@@ -289,7 +298,8 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 
 - (VLCTreeCategoryItem *)itemRepresentingCategory:(int)category
 {
-    for( int i = 0; i < [[self children] count]; i++ )
+    NSUInteger childrenCount = [[self children] count];
+    for( int i = 0; i < childrenCount; i++ )
     {
         VLCTreeCategoryItem * categoryItem = [[self children] objectAtIndex:i];
         if( [categoryItem category] == category )
@@ -298,12 +308,6 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     return nil;
 }
 
-- (void)dealloc
-{
-    module_config_free( _configItems );
-    [super dealloc];
-}
-
 - (bool)isSubCategoryGeneral:(int)category
 {
     if(category == SUBCAT_VIDEO_GENERAL ||
@@ -337,34 +341,43 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     /* Add the capabilities */
     for( i = 0; i < count; i++ )
     {
-        module_t * p_module = modules[i];
-
-        /* Exclude empty plugins (submodules don't have config */
-        /* options, they are stored in the parent module) */
-        unsigned int confsize;
-        _configItems = module_config_get( p_module, &confsize );
-
         VLCTreeCategoryItem * categoryItem = nil;
         VLCTreeSubCategoryItem * subCategoryItem = nil;
         VLCTreePluginItem * pluginItem = nil;
+        module_config_t *p_configs = NULL;
         int lastsubcat = 0;
+        unsigned int confsize;
+
+        module_t * p_module = modules[i];
+
+        /* Exclude empty plugins (submodules don't have config */
+        /* options, they are stored in the parent module) */
+        if( module_is_main( p_module ) ) {
+            pluginItem = self;
+            _configItems = module_config_get( p_module, &confsize );
+            _configSize = confsize;
+        } else {
+            pluginItem = [VLCTreePluginItem pluginTreeItemWithPlugin: p_module];
+            confsize = [pluginItem configSize];
+        }
+        p_configs = [pluginItem configItems];
 
         unsigned int j;
         for( j = 0; j < confsize; j++ )
         {
-            int configType = _configItems[j].i_type;
+            int configType = p_configs[j].i_type;
             if( configType == CONFIG_CATEGORY )
             {
-                categoryItem = [self itemRepresentingCategory:_configItems[j].value.i];
+                categoryItem = [self itemRepresentingCategory:p_configs[j].value.i];
                 if(!categoryItem)
                 {
-                    categoryItem = [VLCTreeCategoryItem categoryTreeItemWithCategory:_configItems[j].value.i];
+                    categoryItem = [VLCTreeCategoryItem categoryTreeItemWithCategory:p_configs[j].value.i];
                     if(categoryItem) [[self children] addObject:categoryItem];
                 }
             }
             else if( configType == CONFIG_SUBCATEGORY )
             {
-                lastsubcat = _configItems[j].value.i;
+                lastsubcat = p_configs[j].value.i;
                 if( categoryItem && ![self isSubCategoryGeneral:lastsubcat] )
                 {
                     subCategoryItem = [categoryItem itemRepresentingSubCategory:lastsubcat];
@@ -375,27 +388,26 @@ static VLCPrefs *_o_sharedMainInstance = nil;
                     }
                 }
             }
-            
-            if( module_is_main( p_module) && (configType & CONFIG_ITEM) )
+
+            if( module_is_main( p_module) && CONFIG_ITEM(configType) )
             {
                 if( categoryItem && [self isSubCategoryGeneral:lastsubcat] )
                 {
-                    [[categoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&_configItems[j]]];
+                    [[categoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&p_configs[j]]];
                 }
                 else if( subCategoryItem )
                 {
-                    [[subCategoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&_configItems[j]]];
+                    [[subCategoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&p_configs[j]]];
                 }
             }
-            else if( !module_is_main( p_module) && (configType & CONFIG_ITEM))
+            else if( !module_is_main( p_module) && CONFIG_ITEM(configType))
             {
-                if( !pluginItem )
+                if( ![[subCategoryItem children] containsObject: pluginItem] )
                 {
-                    pluginItem = [VLCTreePluginItem pluginTreeItemWithPlugin: p_module];
-                    if(pluginItem) [[subCategoryItem children] addObject:pluginItem];
+                    [[subCategoryItem children] addObject:pluginItem];
                 }
                 if( pluginItem )
-                    [[pluginItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&_configItems[j]]];
+                    [[pluginItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&p_configs[j]]];
             }
         }
     }
@@ -408,16 +420,16 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 @implementation VLCTreeCategoryItem
 + (VLCTreeCategoryItem *)categoryTreeItemWithCategory:(int)category
 {
+    if(!config_CategoryNameGet( category )) return nil;
     return [[[[self class] alloc] initWithCategory:category] autorelease];
 }
 - (id)initWithCategory:(int)category
 {
-    if(!config_CategoryNameGet( category )) return nil;
-    NSString * name = [[VLCMain sharedInstance] localizedString: config_CategoryNameGet( category )];
-    if(self = [super initWithName:name andConfigItem:nil])
+    NSString * name = _NS(config_CategoryNameGet( category ));
+    if(self = [super initWithName:name])
     {
         _category = category;
-        //_help = [[[VLCMain sharedInstance] localizedString: config_CategoryHelpGet( category )] retain];
+        //_help = [_NS(config_CategoryHelpGet( category )) retain];
     }
     return self;
 }
@@ -425,7 +437,8 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 - (VLCTreeSubCategoryItem *)itemRepresentingSubCategory:(int)subCategory
 {
     assert( [self isKindOfClass:[VLCTreeCategoryItem class]] );
-    for( int i = 0; i < [[self children] count]; i++ )
+    NSUInteger childrenCount = [[self children] count];
+    for( NSUInteger i = 0; i < childrenCount; i++ )
     {
         VLCTreeSubCategoryItem * subCategoryItem = [[self children] objectAtIndex:i];
         if( [subCategoryItem subCategory] == subCategory )
@@ -444,18 +457,18 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 @implementation VLCTreeSubCategoryItem
 - (id)initWithSubCategory:(int)subCategory
 {
-    if(!config_CategoryNameGet( subCategory )) return nil;
-    NSString * name = [[VLCMain sharedInstance] localizedString: config_CategoryNameGet( subCategory )];
-    if(self = [super initWithName:name andConfigItem:NULL])
+    NSString * name = _NS(config_CategoryNameGet( subCategory ));
+    if(self = [super initWithName:name])
     {
         _subCategory = subCategory;
-        //_help = [[[VLCMain sharedInstance] localizedString: config_CategoryHelpGet( subCategory )] retain];
+        //_help = [_NS(config_CategoryHelpGet( subCategory )) retain];
     }
     return self;
 }
 
 + (VLCTreeSubCategoryItem *)subCategoryTreeItemWithSubCategory:(int)subCategory
 {
+    if(!config_CategoryNameGet( subCategory )) return nil;
     return [[[[self class] alloc] initWithSubCategory:subCategory] autorelease];
 }
 
@@ -470,11 +483,12 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 @implementation VLCTreePluginItem
 - (id)initWithPlugin:(module_t *)plugin
 {
-    NSString * name = [[VLCMain sharedInstance] localizedString: module_get_name( plugin, false )];
-    if(self = [super initWithName:name andConfigItem:NULL])
+    NSString * name = _NS( module_get_name( plugin, false )?:"" );
+    if(self = [super initWithName:name])
     {
+        _configItems = module_config_get( plugin, &_configSize );
         //_plugin = plugin;
-        //_help = [[[VLCMain sharedInstance] localizedString: config_CategoryHelpGet( subCategory )] retain];
+        //_help = [_NS(config_CategoryHelpGet( subCategory )) retain];
     }
     return self;
 }
@@ -484,29 +498,55 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     return [[[[self class] alloc] initWithPlugin:plugin] autorelease];
 }
 
+- (void)dealloc
+{
+    module_config_free( _configItems );
+    [super dealloc];
+}
+
+- (module_config_t *)configItems
+{
+    return _configItems;
+}
+
+- (unsigned int)configSize
+{
+    return _configSize;
+}
+
 @end
 
 #pragma mark -
 @implementation VLCTreeLeafItem
+
+- (id)initWithConfigItem: (module_config_t *) configItem
+{
+    NSString * name = _NS(configItem->psz_name);
+    self = [super initWithName:name];
+    [name release];
+    if( self != nil )
+    {
+        _configItem = configItem;
+    }
+    return self;
+}
+
+- (module_config_t *)configItem
+{
+    return _configItem;
+}
 @end
 
 #pragma mark -
 #pragma mark (Root class for all TreeItems)
 @implementation VLCTreeItem
 
-- (id)initWithConfigItem: (module_config_t *) configItem
-{
-    NSString * name = [[VLCMain sharedInstance] localizedString:configItem->psz_name];
-    return [self initWithName:name andConfigItem:configItem];
-}
-
-- (id)initWithName:(NSString*)name andConfigItem:(module_config_t *)configItem
+- (id)initWithName:(NSString*)name
 {
     self = [super init];
     if( self != nil )
     {
         _name = [name retain];
-        _configItem = configItem;
     }
     return self;
 }
@@ -520,7 +560,7 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     [super dealloc];
 }
 
-- (VLCTreeItem *)childAtIndex:(int)i_index
+- (VLCTreeItem *)childAtIndex:(NSInteger)i_index
 {
     return [[self children] objectAtIndex:i_index];
 }
@@ -549,10 +589,10 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     {
         _subviews = [[NSMutableArray alloc] initWithCapacity:10];
 
-        long i;
-        for( i = 0; i < [[self options] count]; i++)
+        NSUInteger count = [[self options] count];
+        for( NSUInteger i = 0; i < count; i++)
         {
-            VLCTreeItem * item = [[self options] objectAtIndex:i];
+            VLCTreeLeafItem * item = [[self options] objectAtIndex:i];
 
             VLCConfigControl *control;
             control = [VLCConfigControl newControl:[item configItem] withView:view];
@@ -565,7 +605,7 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     }
 
     assert(view);
-    
+
     int i_lastItem = 0;
     int i_yPos = -2;
     int i_max_label = 0;
@@ -603,22 +643,31 @@ static VLCPrefs *_o_sharedMainInstance = nil;
 
 - (void)applyChanges
 {
-    unsigned int i;
-    for( i = 0 ; i < [_subviews count] ; i++ )
+    NSUInteger i;
+    NSUInteger count = [_subviews count];
+    for( i = 0 ; i < count ; i++ )
         [[_subviews objectAtIndex:i] applyChanges];
 
-    for( i = 0 ; i < [_children count] ; i++ )
+    count = [_children count];
+    for( i = 0 ; i < count ; i++ )
         [[_children objectAtIndex:i] applyChanges];
 }
 
 - (void)resetView
 {
-    [_subviews release];
-    _subviews = nil;
+    NSUInteger i;
+    NSUInteger count = [_subviews count];
+    for( i = 0 ; i < count ; i++ )
+        [[_subviews objectAtIndex:i] resetValues];
+
+    count = [_options count];
+    for( i = 0 ; i < count ; i++ )
+        [[_options objectAtIndex:i] resetView];
 
-    unsigned int i;
-    for( i = 0 ; i < [_children count] ; i++ )
+    count = [_children count];
+    for( i = 0 ; i < count ; i++ )
         [[_children objectAtIndex:i] resetView];
+
 }
 
 - (NSMutableArray *)children
@@ -632,11 +681,6 @@ static VLCPrefs *_o_sharedMainInstance = nil;
     if(!_options) _options = [[NSMutableArray alloc] init];
     return _options;
 }
-
-- (module_config_t *)configItem
-{
-    return _configItem;
-}
 @end
 
 #pragma mark -