X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Fprefs_widgets.m;h=68f2c40b3affa232d4357f9ef19a9dce5ec27038;hb=3147cc20d467e776b8996268e04352729c26a66d;hp=d4f979d87560f89c70dcb59307eed18a28858042;hpb=53aab25130560e9c218a85400a10c340f02ae086;p=vlc diff --git a/modules/gui/macosx/prefs_widgets.m b/modules/gui/macosx/prefs_widgets.m index d4f979d875..68f2c40b3a 100644 --- a/modules/gui/macosx/prefs_widgets.m +++ b/modules/gui/macosx/prefs_widgets.m @@ -11,7 +11,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -28,8 +28,12 @@ #include /* malloc(), free() */ #include -#include -#include "vlc_keys.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include "intf.h" #include "prefs_widgets.h" @@ -38,7 +42,7 @@ #define OFFSET_RIGHT 20 #define OFFSET_BETWEEN 2 -#define UPWARDS_WHITE_ARROW "\xE2\x87\xA7" +#define UPWARDS_WHITE_ARROW "\xE2\x87\xA7" #define OPTION_KEY "\xE2\x8C\xA5" #define UP_ARROWHEAD "\xE2\x8C\x83" #define PLACE_OF_INTEREST_SIGN "\xE2\x8C\x98" @@ -244,7 +248,8 @@ [o_menu addItem: o_mi]; \ } -#define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label ) \ +#define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label, \ + tooltip ) \ { \ NSRect s_rc = superFrame; \ s_rc.size.height = 17; \ @@ -256,6 +261,7 @@ [o_label setEditable: NO]; \ [o_label setSelectable: NO]; \ [o_label setStringValue: label]; \ + [o_label setToolTip: tooltip]; \ [o_label setFont:[NSFont systemFontOfSize:0]]; \ [o_label sizeToFit]; \ } @@ -274,6 +280,20 @@ [o_textfield setStringValue: init_value]; \ } +#define ADD_SECURETEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset, \ +my_width, tooltip, init_value ) \ +{ \ +NSRect s_rc = superFrame; \ +s_rc.origin.x = x_offset; \ +s_rc.origin.y = my_y_offset; \ +s_rc.size.height = 22; \ +s_rc.size.width = my_width; \ +o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \ +[o_textfield setFont:[NSFont systemFontOfSize:0]]; \ +[o_textfield setToolTip: tooltip]; \ +[o_textfield setStringValue: init_value]; \ +} + #define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset, \ tooltip ) \ { \ @@ -392,7 +412,7 @@ if( self != nil ) { p_item = _p_item; - psz_name = strdup( p_item->psz_name ); + psz_name = p_item->psz_name; o_label = NULL; i_type = p_item->i_type; i_view_type = 0; @@ -409,20 +429,10 @@ [self setFrame:frame]; } -#if GC_ENABLED -- (void)finalize -{ - /* since dealloc isn't called on 10.5 if GC is enabled and since GC is - * Obj-C only, we need to do this: */ - if( psz_name ) free( psz_name ); - [super finalize]; -} -#endif - - (void)dealloc { if( o_label ) [o_label release]; - if( psz_name ) free( psz_name ); + free( psz_name ); [super dealloc]; } @@ -432,9 +442,11 @@ switch( i_curItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 8; break; case CONFIG_ITEM_STRING_LIST: @@ -455,9 +467,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 6; break; @@ -473,6 +482,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 8; break; case CONFIG_ITEM_STRING_LIST: @@ -493,9 +503,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 6; break; @@ -511,6 +518,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 13; break; case CONFIG_ITEM_STRING_LIST: @@ -531,9 +539,6 @@ case CONFIG_ITEM_BOOL: i_margin = 10; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 10; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 9; break; @@ -549,6 +554,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 8; break; case CONFIG_ITEM_STRING_LIST: @@ -569,9 +575,6 @@ case CONFIG_ITEM_BOOL: i_margin = 8; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 8; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 7; break; @@ -587,6 +590,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 8; break; case CONFIG_ITEM_STRING_LIST: @@ -607,9 +611,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 6; break; @@ -625,6 +626,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 8; break; case CONFIG_ITEM_STRING_LIST: @@ -645,9 +647,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 6; break; @@ -663,6 +662,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 10; break; case CONFIG_ITEM_STRING_LIST: @@ -683,9 +683,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 5; break; @@ -697,48 +694,11 @@ break; } break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - switch( i_lastItem ) - { - case CONFIG_ITEM_STRING: - i_margin = 6; - break; - case CONFIG_ITEM_STRING_LIST: - i_margin = 5; - break; - case CONFIG_ITEM_FILE: - i_margin = 4; - break; - case CONFIG_ITEM_MODULE: - i_margin = 2; - break; - case CONFIG_ITEM_INTEGER: - i_margin = 5; - break; - case CONFIG_ITEM_RANGED_INTEGER: - i_margin = 3; - break; - case CONFIG_ITEM_BOOL: - i_margin = 3; - break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 10; - break; - case CONFIG_ITEM_KEY_AFTER_10_3: - i_margin = 6; - break; - case CONFIG_ITEM_MODULE_LIST: - i_margin = 6; - break; - default: - i_margin = 18; - break; - } - break; case CONFIG_ITEM_KEY_AFTER_10_3: switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 8; break; case CONFIG_ITEM_STRING_LIST: @@ -759,9 +719,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 8; break; @@ -777,6 +734,7 @@ switch( i_lastItem ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: i_margin = 10; break; case CONFIG_ITEM_STRING_LIST: @@ -797,9 +755,6 @@ case CONFIG_ITEM_BOOL: i_margin = 7; break; - case CONFIG_ITEM_KEY_BEFORE_10_3: - i_margin = 7; - break; case CONFIG_ITEM_KEY_AFTER_10_3: i_margin = 5; break; @@ -822,15 +777,11 @@ withView: (NSView *)o_parent_view { VLCConfigControl *p_control = NULL; - /* Skip depracated options */ - if( _p_item->psz_current ) - { - return NULL; - } switch( _p_item->i_type ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: if( !_p_item->i_list ) { p_control = [[StringConfigControl alloc] @@ -912,17 +863,17 @@ 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; } @@ -953,6 +904,7 @@ switch( p_item->i_type ) { case CONFIG_ITEM_STRING: + case CONFIG_ITEM_PASSWORD: case CONFIG_ITEM_FILE: case CONFIG_ITEM_DIRECTORY: case CONFIG_ITEM_MODULE: @@ -974,7 +926,11 @@ } } -- (int)getLabelSize +- (void)resetValues +{ +} + +- (int)labelSize { return [o_label frame].size.width; } @@ -999,30 +955,45 @@ if( [super initWithFrame: mainFrame item: _p_item] != nil ) { - i_view_type = CONFIG_ITEM_STRING; + if( p_item->i_type == CONFIG_ITEM_PASSWORD ) + i_view_type = CONFIG_ITEM_PASSWORD; + else + i_view_type = CONFIG_ITEM_STRING; + + o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext] + toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the textfield */ - o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext] - toWidth: PREFS_WRAP]; if( p_item->value.psz ) o_textfieldString = [[VLCMain sharedInstance] localizedString: (char *)p_item->value.psz]; else o_textfieldString = [NSString stringWithString: @""]; - ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2, - 0, mainFrame.size.width - [o_label frame].size.width - - 2, o_textfieldTooltip, o_textfieldString ) + if( p_item->i_type == CONFIG_ITEM_PASSWORD ) + { + ADD_SECURETEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2, + 0, mainFrame.size.width - [o_label frame].size.width - + 2, o_textfieldTooltip, o_textfieldString ) + } + else + { + ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2, + 0, mainFrame.size.width - [o_label frame].size.width - + 2, o_textfieldTooltip, o_textfieldString ) + } [o_textfield setAutoresizingMask:NSViewWidthSizable ]; + [self addSubview: o_textfield]; } return self; @@ -1050,8 +1021,21 @@ - (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 @@ -1070,20 +1054,22 @@ { int i_index; i_view_type = CONFIG_ITEM_STRING_LIST; + + o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the textfield */ - o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width, -2, 0, o_textfieldTooltip ) [o_combo setAutoresizingMask:NSViewWidthSizable ]; @@ -1124,15 +1110,30 @@ 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 && + !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] ) { @@ -1148,8 +1149,7 @@ withView: (NSView *)o_parent_view { NSRect mainFrame = [o_parent_view frame]; - NSString *o_labelString, *o_buttonTooltip, *o_textfieldString; - NSString *o_textfieldTooltip; + NSString *o_labelString, *o_itemTooltip, *o_textfieldString; mainFrame.size.height = 46; mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN; mainFrame.origin.x = LEFTMARGIN; @@ -1159,8 +1159,12 @@ { i_view_type = CONFIG_ITEM_FILE; + o_itemTooltip = [[VLCMain sharedInstance] + wrapString: [[VLCMain sharedInstance] + 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 ) @@ -1168,30 +1172,24 @@ localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString, o_itemTooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the button */ - o_buttonTooltip = [[VLCMain sharedInstance] - wrapString: [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; - ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_buttonTooltip, + ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_itemTooltip, _NS("Browse...") ) [o_button setAutoresizingMask:NSViewMinXMargin ]; [self addSubview: o_button]; /* build the textfield */ - o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; if( p_item->value.psz ) o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz]; else o_textfieldString = [NSString stringWithString: @""]; ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width - 8 - [o_button frame].size.width, - o_textfieldTooltip, o_textfieldString ) + o_itemTooltip, o_textfieldString ) [o_textfield setAutoresizingMask:NSViewWidthSizable ]; [self addSubview: o_textfield]; } @@ -1225,7 +1223,7 @@ types:nil modalForWindow:[sender window] modalDelegate: self - didEndSelector: @selector(pathChosenInPanel: + didEndSelector: @selector(pathChosenInPanel: withReturn: contextInfo:) contextInfo: nil]; @@ -1248,6 +1246,19 @@ 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 @@ -1263,25 +1274,23 @@ if( [super initWithFrame: mainFrame item: _p_item] != nil ) { - int i_index; - vlc_list_t *p_list; - module_t *p_parser; i_view_type = CONFIG_ITEM_MODULE; + o_popupTooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_popupTooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the popup */ - o_popupTooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width, -2, 0, o_popupTooltip ) [o_popup setAutoresizingMask:NSViewWidthSizable ]; @@ -1289,52 +1298,7 @@ [[o_popup lastItem] setTag: -1]; [o_popup selectItem: [o_popup lastItem]]; - /* build a list of available modules */ - p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); - for( i_index = 0; i_index < p_list->i_count; i_index++ ) - { - p_parser = (module_t *)p_list->p_values[i_index].p_object; - - if( p_item->i_type == CONFIG_ITEM_MODULE ) - { - if( !strcmp( p_parser->psz_capability, - p_item->psz_type ) ) - { - NSString *o_description = [[VLCMain sharedInstance] - localizedString: (char *)p_parser->psz_longname]; - [o_popup addItemWithTitle: o_description]; - - if( p_item->value.psz && - !strcmp( p_item->value.psz, p_parser->psz_object_name ) ) - [o_popup selectItem:[o_popup lastItem]]; - } - } - else - { - int i; - - if( !strcmp( p_parser->psz_object_name, "main" ) ) - continue; - - for ( i = 0; i < p_parser->confsize; i++ ) - { - module_config_t *p_config = p_parser->p_config + 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: (char *)p_parser->psz_longname]; - [o_popup addItemWithTitle: o_description]; - - if( p_item->value.psz && !strcmp(p_item->value.psz, - p_parser->psz_object_name) ) - [o_popup selectItem:[o_popup lastItem]]; - } - } - } - } - vlc_list_release( p_list ); + [self resetValues]; [self addSubview: o_popup]; } return self; @@ -1364,25 +1328,23 @@ { NSString *newval = [o_popup titleOfSelectedItem]; char *returnval = NULL; - int i_module_index; - vlc_list_t *p_list; - module_t *p_parser; + size_t i_module_index; + module_t *p_parser, **p_list; - p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); - for( i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) + p_list = module_list_get( NULL ); + for( i_module_index = 0; p_list[i_module_index]; i_module_index++ ) { - p_parser = (module_t *)p_list->p_values[i_module_index].p_object; + p_parser = p_list[i_module_index]; if( p_item->i_type == CONFIG_ITEM_MODULE ) { - if( !strcmp( p_parser->psz_capability, - p_item->psz_type ) ) + if( module_provides( p_parser, p_item->psz_type ) ) { NSString *o_description = [[VLCMain sharedInstance] - localizedString: (char *)p_parser->psz_longname]; + localizedString: module_GetLongName( p_parser )]; if( [newval isEqualToString: o_description] ) { - returnval = strdup(p_parser->psz_object_name); + returnval = strdup( module_get_object( p_parser )); break; } } @@ -1391,30 +1353,93 @@ { int i; - if( !strcmp( p_parser->psz_object_name, "main" ) ) + if( module_is_main( p_parser) ) continue; - - for ( i = 0; i < p_parser->confsize; i++ ) + unsigned int confsize, unused; + module_config_get( p_parser, &confsize ); + for ( i = 0; i < confsize; i++ ) { - module_config_t *p_config = p_parser->p_config + 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: (char *)p_parser->psz_longname]; + localizedString: module_GetLongName( p_parser )]; if( [newval isEqualToString: o_description] ) { - returnval = strdup(p_parser->psz_object_name); + returnval = strdup(module_get_object( p_parser )); break; } } } } } - vlc_list_release( p_list ); + 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 @@ -1442,13 +1467,13 @@ localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the stepper */ ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19, - 0, o_tooltip, -1600, 1600) + 0, o_tooltip, -100000, 100000) [o_stepper setIntValue: p_item->value.i]; [o_stepper setAutoresizingMask:NSViewMaxXMargin ]; [self addSubview: o_stepper]; @@ -1505,6 +1530,12 @@ return [o_textfield intValue]; } +-(void)resetValues +{ + [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)]; + [super resetValues]; +} + @end @implementation IntegerListConfigControl @@ -1524,20 +1555,21 @@ int i_index; i_view_type = CONFIG_ITEM_STRING_LIST; + o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the textfield */ - o_textfieldTooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width, -2, 0, o_textfieldTooltip ) [o_combo setAutoresizingMask:NSViewWidthSizable ]; @@ -1580,15 +1612,29 @@ 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] @@ -1613,20 +1659,21 @@ { i_view_type = CONFIG_ITEM_RANGED_INTEGER; + o_tooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the textfield */ - o_tooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2, 28, 49, o_tooltip, @"" ) [o_textfield setIntValue: p_item->value.i]; @@ -1639,7 +1686,7 @@ [self addSubview: o_textfield]; /* build the mintextfield */ - ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" ) + ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" ) [o_textfield_min setIntValue: p_item->min.i]; [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ]; [o_textfield_min setAlignment:NSRightTextAlignment]; @@ -1647,7 +1694,7 @@ /* build the maxtextfield */ ADD_LABEL( o_textfield_max, mainFrame, - mainFrame.size.width - 31, -30, @"8888" ) + mainFrame.size.width - 31, -30, @"8888", @"" ) [o_textfield_max setIntValue: p_item->max.i]; [o_textfield_max setAutoresizingMask:NSViewMinXMargin ]; [self addSubview: o_textfield_max]; @@ -1706,6 +1753,14 @@ { 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 @@ -1733,13 +1788,13 @@ localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the stepper */ ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19, - 0, o_tooltip, -1600, 1600) + 0, o_tooltip, -100000, 100000) [o_stepper setFloatValue: p_item->value.f]; [o_stepper setAutoresizingMask:NSViewMaxXMargin ]; [self addSubview: o_stepper]; @@ -1796,6 +1851,12 @@ { return [o_stepper floatValue]; } + +- (void)resetValues +{ + [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)]; + [super resetValues]; +} @end @implementation RangedFloatConfigControl @@ -1813,20 +1874,21 @@ { i_view_type = CONFIG_ITEM_RANGED_INTEGER; + o_tooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the textfield */ - o_tooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2, 28, 49, o_tooltip, @"" ) [o_textfield setFloatValue: p_item->value.f]; @@ -1839,7 +1901,7 @@ [self addSubview: o_textfield]; /* build the mintextfield */ - ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" ) + ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" ) [o_textfield_min setFloatValue: p_item->min.f]; [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ]; [o_textfield_min setAlignment:NSRightTextAlignment]; @@ -1847,7 +1909,7 @@ /* build the maxtextfield */ ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31, - -30, @"8888" ) + -30, @"8888", @"" ) [o_textfield_max setFloatValue: p_item->max.f]; [o_textfield_max setAutoresizingMask:NSViewMinXMargin ]; [self addSubview: o_textfield_max]; @@ -1907,6 +1969,12 @@ 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 @@ -1939,7 +2007,7 @@ localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString ) + ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; } @@ -1957,6 +2025,11 @@ return [o_checkbox intValue]; } +- (void)resetValues +{ + [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)]; + [super resetValues]; +} @end @implementation KeyConfigControl @@ -1974,20 +2047,21 @@ { i_view_type = CONFIG_ITEM_KEY_AFTER_10_3; + o_tooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the popup */ - o_tooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x + [o_label frame].size.width + 3, -2, 0, o_tooltip ) @@ -1998,9 +2072,9 @@ unsigned int i; o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"]; for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++) - if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string ) + if( vlc_keys[i].psz_key_string ) POPULATE_A_KEY( o_keys_menu, - [NSString stringWithCString:vlc_keys[i].psz_key_string] + [NSString stringWithUTF8String:vlc_keys[i].psz_key_string] , vlc_keys[i].i_key_code) } [o_popup setMenu:[o_keys_menu copyWithZone:nil]]; @@ -2035,37 +2109,46 @@ { 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; //Fill our array to know how may items we have... - vlc_list_t *p_list; - module_t *p_parser; - int i_module_index; + module_t *p_parser, **p_list; + size_t i_module_index; NSRect mainFrame = [o_parent_view frame]; NSString *o_labelString, *o_textfieldString, *o_tooltip; o_modulearray = [[NSMutableArray alloc] initWithCapacity:10]; /* build a list of available modules */ - p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); - for( i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) + p_list = module_list_get( NULL ); + for( i_module_index = 0; p_list[i_module_index]; i_module_index++ ) { int i; - p_parser = (module_t *)p_list->p_values[i_module_index].p_object; + p_parser = p_list[i_module_index]; - if( !strcmp( p_parser->psz_object_name, "main" ) ) + if( module_is_main( p_parser ) ) continue; - for ( i = 0; i < p_parser->confsize; i++ ) + unsigned int confsize; + module_config_t *p_configlist = module_config_get( p_parser, &confsize ); + + for ( i = 0; i < confsize; i++ ) { - module_config_t *p_config = p_parser->p_config + i; + unsigned int unused; + module_config_t *p_config = &p_configlist[i]; NSString *o_modulelongname, *o_modulename; NSNumber *o_moduleenabled = nil; @@ -2074,12 +2157,12 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) p_config->value.i == _p_item->min.i ) { o_modulelongname = [NSString stringWithUTF8String: - p_parser->psz_longname]; + module_GetLongName( p_parser )]; o_modulename = [NSString stringWithUTF8String: - p_parser->psz_object_name]; + module_get_object( p_parser )]; if( _p_item->value.psz && - strstr( _p_item->value.psz, p_parser->psz_object_name ) ) + strstr( _p_item->value.psz, module_get_object( p_parser ) ) ) o_moduleenabled = [NSNumber numberWithBool:YES]; else o_moduleenabled = [NSNumber numberWithBool:NO]; @@ -2089,8 +2172,9 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) o_moduleenabled, nil]]; } } + module_config_free( p_configlist ); } - vlc_list_release( p_list ); + module_list_free( p_list ); mainFrame.size.height = 30 + 18 * [o_modulearray count]; mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN; @@ -2100,20 +2184,21 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) { i_view_type = CONFIG_ITEM_MODULE_LIST; + o_tooltip = [[VLCMain sharedInstance] wrapString: + [[VLCMain sharedInstance] + localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; + /* add the label */ if( p_item->psz_text ) o_labelString = [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_text]; else o_labelString = [NSString stringWithString:@""]; - ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString ) + ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip ) [o_label setAutoresizingMask:NSViewNotSizable ]; [self addSubview: o_label]; /* build the textfield */ - o_tooltip = [[VLCMain sharedInstance] wrapString: - [[VLCMain sharedInstance] - localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP]; if( p_item->value.psz ) o_textfieldString = [[VLCMain sharedInstance] localizedString: (char *)p_item->value.psz]; @@ -2151,7 +2236,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) [o_dataCell setTitle:@""]; [o_dataCell setFont:[NSFont systemFontOfSize:0]]; NSTableColumn *o_tableColumn = [[NSTableColumn alloc] - initWithIdentifier:[NSString stringWithCString: "Enabled"]]; + initWithIdentifier:@"Enabled"]; [o_tableColumn setHeaderCell: o_headerCell]; [o_tableColumn setDataCell: o_dataCell]; [o_tableColumn setWidth:17]; @@ -2161,7 +2246,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) o_dataCell = [[NSTextFieldCell alloc] init]; [o_dataCell setFont:[NSFont systemFontOfSize:12]]; o_tableColumn = [[NSTableColumn alloc] - initWithIdentifier:[NSString stringWithCString: "Module"]]; + initWithIdentifier:@"Module"]; [o_tableColumn setHeaderCell: o_headerCell]; [o_tableColumn setDataCell: o_dataCell]; [o_tableColumn setWidth:388 - 17]; @@ -2215,7 +2300,14 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) - (char *)stringValue { - return strdup( [[o_textfield stringValue] cString] ); + 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 @@ -2241,7 +2333,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) } - (NSDragOperation)tableView:(NSTableView*)table - validateDrop:(id )info proposedRow:(int)row + validateDrop:(id )info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)op { // Make drops at the end of the table go to the end. @@ -2259,7 +2351,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST ) } - (BOOL)tableView:(NSTableView*)table acceptDrop:(id )info - row:(int)dropRow dropOperation:(NSTableViewDropOperation)op; + row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op; { NSPasteboard *pb = [info draggingPasteboard]; NSDragOperation srcMask = [info draggingSourceOperationMask]; @@ -2313,26 +2405,24 @@ 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: - [NSString stringWithCString:"Enabled"]] ) + if( [[aTableColumn identifier] isEqualToString: @"Enabled"] ) return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2]; - if( [[aTableColumn identifier] isEqualToString: - [NSString stringWithCString:"Module"]] ) + if( [[aTableColumn identifier] isEqualToString: @"Module"] ) return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1]; return nil; } - (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];