]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/prefs_widgets.m
Qt: correctly handle Unicode in Win7 jump lists
[vlc] / modules / gui / macosx / prefs_widgets.m
index 40e6670b28f5b7ecdb575c7350636433fedc671b..d444d176fdb29af7604d2e01dac18f87c3ca34b4 100644 (file)
@@ -33,7 +33,7 @@
 #endif
 
 #include <vlc_common.h>
-#include "vlc_keys.h"
+#include <vlc_keys.h>
 
 #include "intf.h"
 #include "prefs_widgets.h"
@@ -478,41 +478,6 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
             break;
         }
         break;
-        switch( i_lastItem )
-        {
-        case CONFIG_ITEM_STRING:
-        case CONFIG_ITEM_PASSWORD:
-            i_margin = 8;
-            break;
-        case CONFIG_ITEM_STRING_LIST:
-            i_margin = 7;
-            break;
-        case CONFIG_ITEM_FILE:
-            i_margin = 8;
-            break;
-        case CONFIG_ITEM_MODULE:
-            i_margin = 4;
-            break;
-        case CONFIG_ITEM_INTEGER:
-            i_margin = 7;
-            break;
-        case CONFIG_ITEM_RANGED_INTEGER:
-            i_margin = 5;
-            break;
-        case CONFIG_ITEM_BOOL:
-            i_margin = 7;
-            break;
-        case CONFIG_ITEM_KEY_AFTER_10_3:
-            i_margin = 6;
-            break;
-        case CONFIG_ITEM_MODULE_LIST:
-            i_margin = 8;
-            break;
-        default:
-            i_margin = 20;
-            break;
-        }
-        break;
     case CONFIG_ITEM_STRING_LIST:
         switch( i_lastItem )
         {
@@ -898,17 +863,17 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     return p_control;
 }
 
-- (NSString *)getName
+- (NSString *)name
 {
     return [[VLCMain sharedInstance] localizedString: psz_name];
 }
 
-- (int)getType
+- (int)type
 {
     return i_type;
 }
 
-- (int)getViewType
+- (int)viewType
 {
     return i_view_type;
 }
@@ -961,7 +926,11 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     }
 }
 
-- (int)getLabelSize
+- (void)resetValues
+{
+}
+
+- (int)labelSize
 {
     return [o_label frame].size.width;
 }
@@ -1052,8 +1021,21 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
 
 - (char *)stringValue
 {
-    return strdup( [[VLCMain sharedInstance] delocalizeString:
-                        [o_textfield stringValue]] );
+    return [[VLCMain sharedInstance] delocalizeString:
+                        [o_textfield stringValue]];
+}
+
+- (void)resetValues
+{
+    NSString *o_textfieldString;
+    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
+    if( psz_value )
+        o_textfieldString = [[VLCMain sharedInstance]
+                                localizedString: psz_value];
+    else
+        o_textfieldString = [NSString stringWithString: @""];
+    free( psz_value );
+    [super resetValues];
 }
 @end
 
@@ -1092,9 +1074,13 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
             -2, 0, o_textfieldTooltip )
         [o_combo setAutoresizingMask:NSViewWidthSizable ];
         for( i_index = 0; i_index < p_item->i_list; i_index++ )
-            if( p_item->value.psz &&
+        {
+            if( !p_item->value.psz && !p_item->ppsz_list[i_index] )
+                [o_combo selectItemAtIndex: i_index];
+            else if( p_item->value.psz && p_item->ppsz_list[i_index] &&
                 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
                 [o_combo selectItemAtIndex: i_index];
+       }
         [self addSubview: o_combo];
     }
     return self;
@@ -1128,15 +1114,34 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
         return strdup( [[VLCMain sharedInstance]
                             delocalizeString: [o_combo stringValue]] );
 }
+
+- (void)resetValues
+{
+    int i_index;
+    [o_combo reloadData];
+    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
+
+    for( i_index = 0; i_index < p_item->i_list; i_index++ )
+    {
+        if( !psz_value && !p_item->ppsz_list[i_index] )
+            [o_combo selectItemAtIndex: i_index];
+        else if( psz_value && p_item->ppsz_list[i_index] &&
+            !strcmp( psz_value, p_item->ppsz_list[i_index] ) )
+            [o_combo selectItemAtIndex: i_index];
+    }
+
+    free( psz_value );
+    [super resetValues];
+}
 @end
 
 @implementation StringListConfigControl (NSComboBoxDataSource)
-- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
+- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
 {
         return p_item->i_list;
 }
 
-- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
+- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
 {
     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
     {
@@ -1167,7 +1172,7 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
                                         localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
 
         /* is it a directory */
-        b_directory = ( [self getType] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
+        b_directory = ( [self type] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
 
         /* add the label */
         if( p_item->psz_text )
@@ -1249,6 +1254,19 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     else
         return NULL;
 }
+
+-(void)resetValues
+{
+    NSString *o_textfieldString;
+    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
+    if( psz_value )
+        o_textfieldString = [NSString stringWithFormat: @"%s", psz_value];
+    else
+        o_textfieldString = [NSString stringWithString: @""];
+
+    free(psz_value);
+    [super resetValues];
+}
 @end
 
 @implementation ModuleConfigControl
@@ -1264,8 +1282,6 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
 
     if( [super initWithFrame: mainFrame item: _p_item] != nil )
     {
-        size_t i_index;
-        module_t *p_parser, **p_list;
         i_view_type = CONFIG_ITEM_MODULE;
 
         o_popupTooltip = [[VLCMain sharedInstance] wrapString:
@@ -1290,53 +1306,7 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
         [[o_popup lastItem] setTag: -1];
         [o_popup selectItem: [o_popup lastItem]];
 
-        /* build a list of available modules */
-        p_list = module_list_get( NULL );
-        for( i_index = 0; p_list[i_index]; i_index++ )
-        {
-            p_parser = p_list[i_index];
-
-            if( p_item->i_type == CONFIG_ITEM_MODULE )
-            {
-                if( module_provides( p_parser, p_item->psz_type ) )
-                {
-                    NSString *o_description = [[VLCMain sharedInstance]
-                        localizedString: module_GetLongName( p_parser )];
-                    [o_popup addItemWithTitle: o_description];
-
-                    if( p_item->value.psz &&
-                !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
-                        [o_popup selectItem:[o_popup lastItem]];
-                }
-            }
-            else
-            {
-                int i;
-
-                if( module_is_main( p_parser ) )
-                    continue;
-                unsigned int confsize;
-                unsigned int unused;
-                module_config_get( p_parser, &confsize );
-                for ( i = 0; i < confsize; i++ )
-                {
-                    module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
-                    /* Hack: required subcategory is stored in i_min */
-                    if( p_config->i_type == CONFIG_SUBCATEGORY &&
-                        p_config->value.i == p_item->min.i )
-                    {
-                        NSString *o_description = [[VLCMain sharedInstance]
-                            localizedString: module_GetLongName( p_parser )];
-                        [o_popup addItemWithTitle: o_description];
-
-                        if( p_item->value.psz && !strcmp(p_item->value.psz,
-                                                module_get_object( p_parser )) )
-                            [o_popup selectItem:[o_popup lastItem]];
-                    }
-                }
-            }
-        }
-        module_list_free( p_list );
+        [self resetValues];
         [self addSubview: o_popup];
     }
     return self;
@@ -1416,6 +1386,68 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     module_list_free( p_list );
     return returnval;
 }
+
+-(void)resetValues
+{
+    /* build a list of available modules */
+    size_t i_index;
+    module_t *p_parser, **p_list;
+
+    p_list = module_list_get( NULL );
+    for( i_index = 0; p_list[i_index]; i_index++ )
+    {
+        p_parser = p_list[i_index];
+
+        if( p_item->i_type == CONFIG_ITEM_MODULE )
+        {
+            if( module_provides( p_parser, p_item->psz_type ) )
+            {
+                NSString *o_description = [[VLCMain sharedInstance]
+                    localizedString: module_GetLongName( p_parser )];
+                [o_popup addItemWithTitle: o_description];
+                char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
+
+                if( psz_value &&
+                    !strcmp( psz_value, module_get_object( p_parser ) ) )
+                    [o_popup selectItem:[o_popup lastItem]];
+
+                free(psz_value);
+            }
+        }
+        else
+        {
+            int i;
+
+            if( module_is_main( p_parser ) )
+                continue;
+            unsigned int confsize;
+            unsigned int unused;
+            module_config_t *p_configlist = module_config_get( p_parser, &confsize );
+            for ( i = 0; i < confsize; i++ )
+            {
+                module_config_t *p_config = &p_configlist[i];
+                /* Hack: required subcategory is stored in i_min */
+                if( p_config->i_type == CONFIG_SUBCATEGORY &&
+                    config_GetInt( VLCIntf, p_item->psz_name) == p_item->min.i )
+                {
+                    NSString *o_description = [[VLCMain sharedInstance]
+                        localizedString: module_GetLongName( p_parser )];
+                    [o_popup addItemWithTitle: o_description];
+                    char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
+
+                    if( psz_value && !strcmp(psz_value,
+                                            module_get_object( p_parser )) )
+                        [o_popup selectItem:[o_popup lastItem]];
+
+                    free( psz_value );
+                }
+            }
+            module_config_free( p_configlist );
+        }
+    }
+    module_list_free( p_list );
+    [super resetValues];
+}
 @end
 
 @implementation IntegerConfigControl
@@ -1506,6 +1538,12 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     return [o_textfield intValue];
 }
 
+-(void)resetValues
+{
+    [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)];
+    [super resetValues];
+}
+
 @end
 
 @implementation IntegerListConfigControl
@@ -1582,15 +1620,29 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     else
         return [o_combo intValue];
 }
+
+-(void)resetValues
+{
+    int i_index;
+    [o_combo reloadData];
+    for( i_index = 0; i_index < p_item->i_list; i_index++ )
+    {
+        if( config_GetInt( VLCIntf, p_item->psz_name) == p_item->pi_list[i_index] )
+        {
+            [o_combo selectItemAtIndex: i_index];
+        }
+    }
+
+}
 @end
 
 @implementation IntegerListConfigControl (NSComboBoxDataSource)
-- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
+- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
 {
     return p_item->i_list;
 }
 
-- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
+- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
 {
     if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
         return [[VLCMain sharedInstance]
@@ -1709,6 +1761,14 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
 {
     return [o_slider intValue];
 }
+
+- (void)resetValues
+{
+    int value = config_GetInt( VLCIntf, p_item->psz_name );
+    [o_textfield setIntValue:value];
+    [o_slider setIntValue:value];
+    [super resetValues];
+}
 @end
 
 @implementation FloatConfigControl
@@ -1799,6 +1859,12 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
 {
     return [o_stepper floatValue];
 }
+
+- (void)resetValues
+{
+    [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)];
+    [super resetValues];
+}
 @end
 
 @implementation RangedFloatConfigControl
@@ -1911,6 +1977,12 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     return [o_slider floatValue];
 }
 
+- (void)resetValues
+{
+    [o_textfield setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
+    [o_slider setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
+    [super resetValues];
+}
 @end
 
 @implementation BoolConfigControl
@@ -1961,6 +2033,11 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
     return [o_checkbox intValue];
 }
 
+- (void)resetValues
+{
+    [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)];
+    [super resetValues];
+}
 @end
 
 @implementation KeyConfigControl
@@ -2002,11 +2079,14 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
         {
             unsigned int i;
             o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
+#warning This does not work anymore. FIXME.
+#if 0
             for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
                 if( vlc_keys[i].psz_key_string )
                     POPULATE_A_KEY( o_keys_menu,
                         [NSString stringWithUTF8String:vlc_keys[i].psz_key_string]
                         , vlc_keys[i].i_key_code)
+#endif
         }
         [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
         [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
@@ -2040,13 +2120,19 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain];       \
 {
     return [o_popup selectedTag];
 }
+
+- (void)resetValues
+{
+    [o_popup selectItem:[[o_popup menu] itemWithTag:config_GetInt( VLCIntf, p_item->psz_name )]];
+    [super resetValues];
+}
 @end
 
 @implementation ModuleListConfigControl
 - (id) initWithItem: (module_config_t *)_p_item
            withView: (NSView *)o_parent_view
 {
-if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
+    if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
 //TODO....
         return nil;
 
@@ -2068,12 +2154,12 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
             continue;
 
         unsigned int confsize;
-        module_config_get( p_parser, &confsize );
+        module_config_t *p_configlist = module_config_get( p_parser, &confsize );
 
         for ( i = 0; i < confsize; i++ )
         {
             unsigned int unused;
-            module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
+            module_config_t *p_config = &p_configlist[i];
             NSString *o_modulelongname, *o_modulename;
             NSNumber *o_moduleenabled = nil;
 
@@ -2097,6 +2183,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
                     o_moduleenabled, nil]];
             }
         }
+        module_config_free( p_configlist );
     }
     module_list_free( p_list );
 
@@ -2227,6 +2314,13 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
     return strdup( [[o_textfield stringValue] UTF8String] );
 }
 
+-(void)resetValues
+{
+#warning Reset prefs of the module selector is broken atm. 
+    NSLog( @"don't forget about modulelistconfig" );
+    [super resetValues];
+}
+
 @end
 
 @implementation ModuleListConfigControl (NSTableDataSource)
@@ -2250,7 +2344,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
 }
 
 - (NSDragOperation)tableView:(NSTableView*)table
-    validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row
+    validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
     proposedDropOperation:(NSTableViewDropOperation)op
 {
     // Make drops at the end of the table go to the end.
@@ -2268,7 +2362,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
 }
 
 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
-    row:(int)dropRow dropOperation:(NSTableViewDropOperation)op;
+    row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
 {
     NSPasteboard    *pb = [info draggingPasteboard];
     NSDragOperation srcMask = [info draggingSourceOperationMask];
@@ -2322,13 +2416,13 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
     return accepted;
 }
 
-- (int)numberOfRowsInTableView:(NSTableView *)aTableView
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
 {
     return [o_modulearray count];
 }
 
 - (id)tableView:(NSTableView *)aTableView
-    objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
+    objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
 {
     if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
         return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
@@ -2339,7 +2433,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
 }
 
 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
-    forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
+    forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
 {
     [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
         withObject: anObject];