+/* TODO: move this part to core */
+#define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
+static inline char * __config_GetLabel( vlc_object_t *p_this, const char *psz_name )
+{
+ module_config_t *p_config;
+
+ p_config = config_FindConfig( p_this, psz_name );
+
+ /* sanity checks */
+ if( !p_config )
+ {
+ msg_Err( p_this, "option %s does not exist", psz_name );
+ return NULL;
+ }
+
+ if ( p_config->psz_longtext )
+ return p_config->psz_longtext;
+ else if( p_config->psz_text )
+ return p_config->psz_text;
+ else
+ msg_Warn( p_this, "option %s does not include any help", psz_name );
+
+ return NULL;
+}
+
+- (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
+{
+ module_config_t *p_item;
+
+ [object removeAllItems];
+ p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
+
+ /* serious problem, if no item found */
+ assert( p_item );
+
+ for( int i = 0; i < p_item->i_list; i++ )
+ {
+ NSMenuItem *mi;
+ if( p_item->ppsz_list_text != NULL )
+ mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
+ else if( p_item->ppsz_list[i] && strcmp(p_item->ppsz_list[i],"") == 0 )
+ {
+ [[object menu] addItem: [NSMenuItem separatorItem]];
+ continue;
+ }
+ else if( p_item->ppsz_list[i] )
+ mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
+ else
+ msg_Err( p_intf, "item %d of pref %s failed to be created", i, name );
+ [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
+ [[object menu] addItem: [mi autorelease]];
+ if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
+ [object selectItem:[object lastItem]];
+ }
+ [object setToolTip: _NS( p_item->psz_longtext )];
+}
+
+- (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
+{
+ module_config_t *p_item;
+
+ [object removeAllItems];
+ p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
+
+ /* serious problem, if no item found */
+ assert( p_item );
+
+ for( int i = 0; i < p_item->i_list; i++ )
+ {
+ NSMenuItem *mi;
+ if( p_item->ppsz_list_text != NULL)
+ mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
+ else if( p_item->pi_list[i] )
+ mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
+ else
+ msg_Err( p_intf, "item %d of pref %s failed to be created", i, name);
+ [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
+ [[object menu] addItem: [mi autorelease]];
+ if( p_item->value.i == p_item->pi_list[i] )
+ [object selectItem:[object lastItem]];
+ }
+ [object setToolTip: _NS( p_item->psz_longtext )];
+}
+
+- (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
+{
+ module_config_t *p_item;
+ module_t *p_parser, **p_list;
+ int y = 0;
+
+ [object removeAllItems];
+
+ p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
+ p_list = module_list_get( NULL );
+ if( !p_item ||!p_list )
+ {
+ if( p_list ) module_list_free(p_list);
+ msg_Err( p_intf, "serious problem, item or list not found" );
+ return;
+ }
+
+ [object addItemWithTitle: _NS("Default")];
+ for( size_t i_index = 0; p_list[i_index]; i_index++ )
+ {
+ p_parser = p_list[i_index];
+ if( module_provides( p_parser, p_item->psz_type ) )
+ {
+ [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser ) ?: ""]];
+ if( p_item->value.psz && !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
+ [object selectItem: [object lastItem]];
+ }
+ }
+ module_list_free( p_list );
+ [object setToolTip: _NS(p_item->psz_longtext)];
+}
+
+- (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
+{
+ [object setState: config_GetInt( p_intf, name )];
+ [object setToolTip: [NSString stringWithUTF8String: config_GetLabel( p_intf, name )]];
+}
+
+- (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
+{
+ char *psz_tmp = config_GetPsz( p_intf, psz_option );
+ [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
+ [o_object setToolTip: [NSString stringWithUTF8String: config_GetLabel( p_intf, psz_option )]];
+ free( psz_tmp );
+}
+