]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/prefs.m
* VLCPrefs's delloc method got accidentally removed while splitting the nibs. Re...
[vlc] / modules / gui / macosx / prefs.m
index 542e115d6b35906941babdb95eac4c706cbc38d0..f8bce768905cc953d7fe02a16098bfaa7049ba33 100644 (file)
@@ -2,7 +2,7 @@
  * prefs.m: MacOS X module for vlc
  *****************************************************************************
  * Copyright (C) 2002-2004 VideoLAN
- * $Id: prefs.m,v 1.41 2004/02/19 19:38:58 hartman Exp $
+ * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Derk-Jan Hartman <hartman at videolan dot org>
  *****************************************************************************/
 @implementation VLCPrefs
 
-- (id)init
+static VLCPrefs *_o_sharedMainInstance = nil;
+
++ (VLCPrefs *)sharedInstance
 {
-    self = [super init];
+    return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
+}
 
-    if( self != nil )
-    {
-        o_empty_view = [[NSView alloc] init];
-        o_save_prefs = [[NSMutableDictionary alloc] init];
+- (id)init
+{
+    if( _o_sharedMainInstance) {
+        [self dealloc];
+    } else {
+        _o_sharedMainInstance = [super init];
     }
-
-    return( self );
+    
+    return _o_sharedMainInstance;
 }
 
 - (void)dealloc
     [super dealloc];
 }
 
-- (void)awakeFromNib
+- (void)showPrefs
 {
-    p_intf = [NSApp getIntf];
+    /* load our nib */
+    [NSBundle loadNibNamed:@"Preferences" owner:self];
+    
+    /* from "init" =< r8571 */
+    o_empty_view = [[NSView alloc] init];
+    o_save_prefs = [[NSMutableDictionary alloc] init];
+
+    /* from "awakeFromNib" =< r8571 */
+    p_intf = VLCIntf;
     b_advanced = config_GetInt( p_intf, "advanced" );
 
     [self initStrings];
     [o_prefs_view setRulersVisible: NO];
     [o_prefs_view setDocumentView: o_empty_view];
     [o_tree selectRow:0 byExtendingSelection:NO];
+    /* end of the previous "awakeFromNib" method */
+
+    [o_save_prefs release];
+    o_save_prefs = [[NSMutableDictionary alloc] init];
+    [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
+        andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
+    [o_prefs_window center];
+    [o_prefs_window makeKeyAndOrderFront:self];
 }
 
 - (void)initStrings
     [o_advanced_ckb setTitle: _NS("Advanced")];
 }
 
-- (void)showPrefs
-{
-    [o_save_prefs release];
-    o_save_prefs = [[NSMutableDictionary alloc] init];
-    [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
-        andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
-    [o_prefs_window center];
-    [o_prefs_window makeKeyAndOrderFront:self];
-}
-
 - (IBAction)savePrefs: (id)sender
 {
     id o_vlc_config;
             break;
     
         case CONFIG_ITEM_STRING:
+            {
+                char *psz_value;
+                NSString *o_value = [o_vlc_config stringValue];
+                psz_value = (char *)[o_value UTF8String];
+    
+                config_PutPsz( p_intf, psz_name, psz_value );
+            }
+            break;
+
         case CONFIG_ITEM_FILE:
         case CONFIG_ITEM_DIRECTORY:
             {
                 char *psz_value;
                 NSString *o_value = [o_vlc_config stringValue];
-                psz_value = (char *)[o_value UTF8String];
+                psz_value = (char *)[o_value fileSystemRepresentation];
     
                 config_PutPsz( p_intf, psz_name, psz_value );
             }
     if( p_parser->i_object_type != VLC_OBJECT_MODULE )
     {
         /* 0OOoo something went really bad */
+        vlc_list_release( p_list );
         return;
     }
     
         if ( label ) \
         { \
             [o_text_field setStringValue: \
-                [NSApp localizedString: label]]; \
+                [[VLCMain sharedInstance] localizedString: label]]; \
         } \
         [o_text_field sizeToFit]; \
         [o_view addSubview: [o_text_field autorelease]]; \
         [o_text_field msg: param]; \
         if ( psz_duptip != NULL ) \
         { \
-            [o_text_field setToolTip: [NSApp wrapString: [NSApp localizedString: \
+            [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: \
                                        psz_duptip] toWidth: PREFS_WRAP ]]; \
             free(psz_duptip);\
         } \
         if( p_item->i_type == CONFIG_HINT_CATEGORY )
         {
             if( !strcmp( p_parser->psz_object_name, "main" ) &&
-                [o_item_name isEqualToString: [NSApp localizedString: p_item->psz_text]] )
+                [o_item_name isEqualToString: [[VLCMain sharedInstance] localizedString: p_item->psz_text]] )
             {
                 b_right_cat = TRUE;
             } else if( strcmp( p_parser->psz_object_name, "main" ) )
                 
                 if ( psz_duptip != NULL )
                 {
-                    [o_modules setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
+                    [o_modules setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
                     free( psz_duptip );
                 }
                 [o_view addSubview: [o_modules autorelease]];
                         if( !strcmp( p_a_module->psz_capability,
                                     p_item->psz_type ) )
                         {
-                            NSString *o_description = [NSApp
+                            NSString *o_description = [[VLCMain sharedInstance]
                                 localizedString: p_a_module->psz_longname];
                             [o_modules addItemWithTitle: o_description];
                             [[o_modules lastItem] setTag: p_a_module->i_object_id];
                 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc];
                 CONTROL_CONFIG( o_text_field, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
 
-                [o_text_field setStringValue: [NSApp localizedString: psz_value]];
+                [o_text_field setStringValue: [[VLCMain sharedInstance] localizedString: psz_value]];
                 if ( psz_duptip != NULL )
                 {
-                    [o_text_field setToolTip: [NSApp wrapString: [NSApp localizedString:
+                    [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString:
                                             psz_duptip] toWidth: PREFS_WRAP ]];
                     free(psz_duptip);
                 }
                                     p_item->psz_value : "";
     
                     INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
-                                        [NSApp localizedString: psz_value],
+                                        [[VLCMain sharedInstance] localizedString: psz_value],
                                         p_item->psz_longtext );
                 }
                 else
 
                     if ( psz_duptip != NULL )
                     {
-                        [o_combo_box setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
+                        [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
                         free( psz_duptip );
                     }
                     [o_view addSubview: [o_combo_box autorelease]];
                     for( i=0; p_item->ppsz_list[i]; i++ )
                     {
                         [o_combo_box addItemWithObjectValue:
-                            [NSApp localizedString: p_item->ppsz_list[i]]];
+                            [[VLCMain sharedInstance] localizedString: p_item->ppsz_list[i]]];
                     }
-                    [o_combo_box setStringValue: [NSApp localizedString: 
+                    [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString: 
                         p_item->psz_value ? p_item->psz_value : ""]];
     
                     CONTROL_LABEL( p_item->psz_text );
 
                     if ( psz_duptip != NULL )
                     {
-                        [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
+                        [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
                         free( psz_duptip );
                     }
                     [o_slider setTarget: self];
 
                     if ( psz_duptip != NULL )
                     {
-                        [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
+                        [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
                         free( psz_duptip );
                     }
                     [o_slider setTarget: self];
                 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
                 [o_btn_bool setButtonType: NSSwitchButton];
                 [o_btn_bool setIntValue: p_item->i_value];
-                [o_btn_bool setTitle: [NSApp localizedString: p_item->psz_text]];
+                [o_btn_bool setTitle: [[VLCMain sharedInstance] localizedString: p_item->psz_text]];
                 if ( psz_duptip != NULL )
                 {
-                    [o_btn_bool setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
+                    [o_btn_bool setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
                     free( psz_duptip );
                 }
                 [o_btn_bool setTarget: self];
                     [o_current_cell setControlSize: NSSmallControlSize];
                     if( psz_duptip != NULL )
                     {
-                        [o_matrix setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
+                        [o_matrix setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
                     }
                     switch( i )
                     {
 
                 if ( psz_duptip != NULL )
                 {
-                    [o_combo_box setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
+                    [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
                 }
                 [o_view addSubview: [o_combo_box autorelease]];
                 
                 {
                     
                     if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
-                    [o_combo_box addItemWithObjectValue: [NSApp localizedString:vlc_keys[i].psz_key_string]];
+                    [o_combo_box addItemWithObjectValue: [[VLCMain sharedInstance] localizedString:vlc_keys[i].psz_key_string]];
                 }
                 
-                [o_combo_box setStringValue: [NSApp localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
+                [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
                 
                 s_rc.origin.y += s_rc.size.height;
                 s_rc.origin.x = X_ORIGIN;
     #undef X_ORIGIN
         }
         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
+        vlc_object_release( p_parser );
         vlc_list_release( p_list );
     
     [o_prefs_view setDocumentView: o_view];
@@ -886,7 +908,7 @@ static VLCTreeItem *o_root_item = nil;
  * Loads children incrementally */
 - (NSArray *)children {
     if (o_children == NULL) {
-        intf_thread_t *p_intf = [NSApp getIntf];
+        intf_thread_t *p_intf = VLCIntf;
         vlc_list_t      *p_list;
         module_t        *p_module = NULL;
         module_config_t *p_item;
@@ -928,7 +950,7 @@ static VLCTreeItem *o_root_item = nil;
                     switch( p_item->i_type )
                     {
                     case CONFIG_HINT_CATEGORY:
-                        o_child_name = [NSApp localizedString: p_item->psz_text];
+                        o_child_name = [[VLCMain sharedInstance] localizedString: p_item->psz_text];
                         [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
                             ID: p_module->i_object_id parent:self]];
                         break;
@@ -970,7 +992,7 @@ static VLCTreeItem *o_root_item = nil;
         
                 /* Create the capability tree if it doesn't already exist */
                 NSString *o_capability;
-                o_capability = [NSApp localizedString: p_module->psz_capability];
+                o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
                 if( !p_module->psz_capability || !*p_module->psz_capability )
                 {
                     /* Empty capability ? Let's look at the submodules */
@@ -980,7 +1002,7 @@ static VLCTreeItem *o_root_item = nil;
                         p_submodule = (module_t*)p_module->pp_children[ j ];
                         if( p_submodule->psz_capability && *p_submodule->psz_capability )
                         {
-                            o_capability = [NSApp localizedString: p_submodule->psz_capability];
+                            o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
                             BOOL b_found = FALSE;
                             for( j = 0; j < (int)[o_children count]; j++ )
                             {
@@ -1040,7 +1062,7 @@ static VLCTreeItem *o_root_item = nil;
         
                 /* Check the capability */
                 NSString *o_capability;
-                o_capability = [NSApp localizedString: p_module->psz_capability];
+                o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
                 if( !p_module->psz_capability || !*p_module->psz_capability )
                 {
                     /* Empty capability ? Let's look at the submodules */
@@ -1050,11 +1072,11 @@ static VLCTreeItem *o_root_item = nil;
                         p_submodule = (module_t*)p_module->pp_children[ j ];
                         if( p_submodule->psz_capability && *p_submodule->psz_capability )
                         {
-                            o_capability = [NSApp localizedString: p_submodule->psz_capability];
+                            o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
                             if( [o_capability isEqualToString: [self getName]] )
                             {
                             [o_children addObject:[[VLCTreeItem alloc] initWithName:
-                                [NSApp localizedString: p_module->psz_object_name ]
+                                [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
                                 ID: p_module->i_object_id parent:self]];
                             }
                         }
@@ -1063,7 +1085,7 @@ static VLCTreeItem *o_root_item = nil;
                 else if( [o_capability isEqualToString: [self getName]] )
                 {
                     [o_children addObject:[[VLCTreeItem alloc] initWithName:
-                        [NSApp localizedString: p_module->psz_object_name ]
+                        [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
                         ID: p_module->i_object_id parent:self]];
                 }
             }
@@ -1073,6 +1095,7 @@ static VLCTreeItem *o_root_item = nil;
             /* all the other stuff are leafs */
             o_children = IsALeafNode;
         }
+        vlc_list_release( p_list );
     }
     return o_children;
 }
@@ -1098,7 +1121,7 @@ static VLCTreeItem *o_root_item = nil;
 
 - (BOOL)hasPrefs:(NSString *)o_module_name
 {
-    intf_thread_t *p_intf = [NSApp getIntf];
+    intf_thread_t *p_intf = VLCIntf;
     module_t *p_parser;
     vlc_list_t *p_list;
     char *psz_module_name;