]> git.sesse.net Git - vlc/blob - modules/gui/macosx/prefs.m
* Added a Reset prefs option
[vlc] / modules / gui / macosx / prefs.m
1 /*****************************************************************************
2  * prefs.m: MacOS X plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id: prefs.m,v 1.22 2003/05/20 15:23:25 hartman Exp $
6  *
7  * Authors:     Jon Lech Johansen <jon-vl@nanocrew.net>
8  *              Derk-Jan Hartman <thedj at users.sf.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <sys/param.h>                                    /* for MAXPATHLEN */
30 #include <string.h>
31
32 #include "intf.h"
33 #include "prefs.h"
34
35 /*****************************************************************************
36  * VLCPrefs implementation
37  *****************************************************************************/
38 @implementation VLCPrefs
39
40 - (id)init
41 {
42     self = [super init];
43
44     if( self != nil )
45     {
46         o_empty_view = [[NSView alloc] init];
47     }
48
49     return( self );
50 }
51
52 - (void)dealloc
53 {
54     [o_empty_view release];
55     [super dealloc];
56 }
57
58 - (void)awakeFromNib
59 {
60     p_intf = [NSApp getIntf];
61     b_advanced = config_GetInt( p_intf, "advanced" );
62
63     [self initStrings];
64     [o_advanced_ckb setState: b_advanced];
65     [o_prefs_view setBorderType: NSGrooveBorder];
66     [o_prefs_view setHasVerticalScroller: YES];
67     [o_prefs_view setDrawsBackground: NO];
68     [o_prefs_view setRulersVisible: YES];
69     [o_prefs_view setDocumentView: o_empty_view];
70     [o_tree selectRow:0 byExtendingSelection:NO];
71     //[self loadConfigTree];
72 }
73
74 - (void)initStrings
75 {
76     [o_prefs_window setTitle: _NS("Preferences")];
77     [o_save_btn setTitle: _NS("Save")];
78     [o_cancel_btn setTitle: _NS("Cancel")];
79     [o_reset_btn setTitle: _NS("Reset All")];
80     [o_advanced_ckb setTitle: _NS("Advanced")];
81 }
82
83 - (void)showPrefs
84 {
85     [o_prefs_window center];
86     [o_prefs_window makeKeyAndOrderFront:self];
87 }
88
89 - (IBAction)savePrefs: (id)sender
90 {
91     config_SaveConfigFile( p_intf, NULL );
92     [o_prefs_window orderOut:self];
93 }
94
95 - (IBAction)closePrefs: (id)sender
96 {
97     [o_prefs_window orderOut:self];
98 }
99
100 - (IBAction)resetAll: (id)sender
101 {
102     config_ResetAll( p_intf );
103 }
104
105 - (IBAction)advancedToggle: (id)sender
106 {
107     b_advanced = !b_advanced;
108     [o_advanced_ckb setState: b_advanced];
109     [o_tree selectRow: [o_tree selectedRow] byExtendingSelection:NO];
110 }
111
112 - (void)loadConfigTree
113 {
114     
115 }
116
117 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
118 {
119 }
120
121 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
122 {
123     NSLog( [[o_tree itemAtRow:[o_tree selectedRow]] getName] );
124     [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID] andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
125 }
126
127 - (void)configChanged:(id)o_unknown
128 {
129     id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ?
130                       [o_unknown object] : o_unknown;
131
132     NSString *o_module_name = [o_vlc_config moduleName];
133
134     int i_type = [o_vlc_config configType];
135     NSString *o_name = [o_vlc_config configName];
136     NSLog( o_name);
137     char *psz_name = (char *)[o_name UTF8String];
138
139     switch( i_type )
140     {
141
142     case CONFIG_ITEM_MODULE:
143         {
144             char *psz_value;
145             NSString *o_value;
146
147             o_value = [o_vlc_config titleOfSelectedItem];
148             NSLog( o_value);
149             psz_value = (char *)[o_value UTF8String];
150
151             config_PutPsz( p_intf, psz_name, psz_value );
152         }
153         break;
154
155     case CONFIG_ITEM_STRING:
156     case CONFIG_ITEM_FILE:
157     case CONFIG_ITEM_DIRECTORY:
158         {
159             char *psz_value;
160             NSString *o_value;
161
162             o_value = [o_vlc_config stringValue];
163             NSLog( o_value);
164             psz_value = (char *)[o_value UTF8String];
165
166             config_PutPsz( p_intf, psz_name, psz_value );
167         }
168         break;
169
170     case CONFIG_ITEM_INTEGER:
171     case CONFIG_ITEM_BOOL:
172         {
173             int i_value = [o_vlc_config intValue];
174
175             config_PutInt( p_intf, psz_name, i_value );
176         }
177         break;
178
179     case CONFIG_ITEM_FLOAT:
180         {
181             float f_value = [o_vlc_config floatValue];
182
183             config_PutFloat( p_intf, psz_name, f_value );
184         }
185         break;
186
187     }
188 }
189
190 - (void)showViewForID: (int)i_id andName: (NSString *)o_item_name
191 {
192     vlc_list_t *p_list;
193     module_t *p_parser;
194     module_config_t *p_item;
195     
196     int i_pos, i_module_tag, i_index;
197     
198     NSString *o_module_name;
199     NSRect s_rc;                        /* rect                         */
200     NSView *o_view;                     /* view                         */
201     NSRect s_vrc;                       /* view rect                    */
202     VLCTextField *o_text_field;         /* input field / label          */
203     
204     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
205
206     /* Get a pointer to the module */
207     p_parser = (module_t *)vlc_object_get( p_intf, i_id );
208     if( p_parser->i_object_type != VLC_OBJECT_MODULE )
209     {
210         /* 0OOoo something went really bad */
211         return;
212     }
213     
214     /* Enumerate config options and add corresponding config boxes */
215     o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name];
216     p_item = p_parser->p_config;
217
218     i_pos = 0;
219     o_view = nil;
220     i_module_tag = 3;
221
222 #define X_ORIGIN 20
223 #define Y_ORIGIN (X_ORIGIN - 10)
224
225 #define CHECK_VIEW_HEIGHT \
226     { \
227         float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \
228         if( f_new_pos > s_vrc.size.height ) \
229         { \
230             s_vrc.size.height = f_new_pos; \
231             [o_view setFrame: s_vrc]; \
232         } \
233     }
234
235 #define CONTROL_LABEL( label ) \
236     { \
237         s_rc.origin.x += s_rc.size.width + 10; \
238         s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \
239         o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \
240         [o_text_field setDrawsBackground: NO]; \
241         [o_text_field setBordered: NO]; \
242         [o_text_field setEditable: NO]; \
243         [o_text_field setSelectable: NO]; \
244         if ( label ) \
245         { \
246             [o_text_field setStringValue: \
247                 [NSApp localizedString: label]]; \
248         } \
249         [o_text_field sizeToFit]; \
250         [o_view addSubview: [o_text_field autorelease]]; \
251     }
252
253 #define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \
254     { \
255         char * psz_duptip = NULL; \
256         if ( p_item->psz_longtext != NULL && [NSApp getEncoding] == NSISOLatin1StringEncoding ) \
257             psz_duptip = strdup(p_item->psz_longtext); \
258         s_rc.size.height = 25; \
259         s_rc.size.width = w; \
260         s_rc.origin.y += 10; \
261         CHECK_VIEW_HEIGHT; \
262         o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \
263         [o_text_field setAlignment: NSRightTextAlignment]; \
264         CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \
265         [o_text_field msg: param]; \
266         if ( psz_duptip != NULL ) \
267         { \
268             [o_text_field setToolTip: [NSApp localizedString: \
269                                        vlc_wraptext(psz_duptip, PREFS_WRAP)]]; \
270             free(psz_duptip);\
271         } \
272         [o_view addSubview: [o_text_field autorelease]]; \
273         [[NSNotificationCenter defaultCenter] addObserver: self \
274             selector: @selector(configChanged:) \
275             name: NSControlTextDidChangeNotification \
276             object: o_text_field]; \
277         CONTROL_LABEL( label ); \
278         s_rc.origin.y += s_rc.size.height; \
279         s_rc.origin.x = X_ORIGIN; \
280     }
281
282 #define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \
283     INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )
284 #define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \
285     INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )
286 #define INPUT_FIELD_STRING( name, label, w, param, tip ) \
287     INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip )
288
289     /* Init View */
290     s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
291     o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
292     s_rc.origin.x = X_ORIGIN;
293     s_rc.origin.y = Y_ORIGIN;
294     BOOL b_right_cat = FALSE;
295
296     if( p_item ) do
297     {
298         if( p_item->i_type == CONFIG_HINT_CATEGORY )
299         {
300             if( !strcmp( p_parser->psz_object_name, "main" ) &&
301                 [o_item_name isEqualToString: [NSApp localizedString: p_item->psz_text]] )
302             {
303                 b_right_cat = TRUE;
304             } else if( strcmp( p_parser->psz_object_name, "main" ) )
305             {
306                  b_right_cat = TRUE;
307             } else b_right_cat = FALSE; 
308         } else if( p_item->i_type == CONFIG_HINT_END && !strcmp( p_parser->psz_object_name, "main" ) )
309         {
310             b_right_cat = FALSE;
311         }
312         
313         if( (p_item->b_advanced && !b_advanced ) || !b_right_cat )
314         {
315             continue;
316         }
317         switch( p_item->i_type )
318         {
319             case CONFIG_ITEM_MODULE:
320             {
321                 VLCPopUpButton *o_modules;
322                 module_t *p_a_module;
323                 char * psz_duptip = NULL;
324                 if ( p_item->psz_longtext != NULL && [NSApp getEncoding] == NSISOLatin1StringEncoding )
325                     psz_duptip = strdup(p_item->psz_longtext);
326         
327                 s_rc.size.height = 30;
328                 s_rc.size.width = 200;
329                 s_rc.origin.y += 10;
330                 
331                 CHECK_VIEW_HEIGHT;
332     
333                 o_modules = [[VLCPopUpButton alloc] initWithFrame: s_rc];
334                 CONTROL_CONFIG( o_modules, o_module_name,
335                                     CONFIG_ITEM_MODULE, p_item->psz_name );
336                 [o_modules setTarget: self];
337                 [o_modules setAction: @selector(configChanged:)];
338                 [o_modules sendActionOn:NSLeftMouseUpMask];
339                 if ( psz_duptip != NULL )
340                 {
341                     [o_modules setToolTip: [NSApp localizedString:
342                                             vlc_wraptext(psz_duptip, PREFS_WRAP)]];
343                     free( psz_duptip );
344                 }
345                 [o_view addSubview: [o_modules autorelease]];
346
347                 [o_modules addItemWithTitle: _NS("Auto")];
348
349                 /* build a list of available modules */
350                 {
351                     for( i_index = 0; i_index < p_list->i_count; i_index++ )
352                     {
353                         p_a_module = (module_t *)p_list->p_values[i_index].p_object ;
354     
355                         if( !strcmp( p_a_module->psz_capability,
356                                     p_item->psz_type ) )
357                         {
358                             NSString *o_object_name = [NSString
359                                 stringWithCString: p_a_module->psz_object_name];
360                             [o_modules addItemWithTitle: o_object_name];
361                         }
362                     }
363                 }
364     
365                 if( p_item->psz_value != NULL )
366                 {
367                     NSString *o_value =
368                         [NSString stringWithUTF8String: p_item->psz_value];
369     
370                     [o_modules selectItemWithTitle: o_value];
371                 }
372                 else
373                 {
374                     [o_modules selectItemWithTitle: _NS("Auto")];
375                 }
376
377                 CONTROL_LABEL( p_item->psz_text );
378                 s_rc.origin.y += s_rc.size.height;
379                 s_rc.origin.x = X_ORIGIN;
380             }
381             break;
382
383             case CONFIG_ITEM_STRING:
384             case CONFIG_ITEM_FILE:
385             case CONFIG_ITEM_DIRECTORY:
386             {
387     
388                 if( !p_item->ppsz_list )
389                 {
390                     char *psz_value = p_item->psz_value ?
391                                     p_item->psz_value : "";
392     
393                     INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
394                                         [NSString stringWithCString: psz_value],
395                                         p_item->psz_longtext );
396                 }
397                 else
398                 {
399                     int i;
400                     VLCComboBox *o_combo_box;
401                     char * psz_duptip = NULL;
402                     if ( p_item->psz_longtext != NULL && [NSApp getEncoding] == NSISOLatin1StringEncoding )
403                         psz_duptip = strdup(p_item->psz_longtext);
404     
405                     s_rc.size.height = 27;
406                     s_rc.size.width = 200;
407                     s_rc.origin.y += 10;
408     
409                     CHECK_VIEW_HEIGHT;
410     
411                     o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
412                     CONTROL_CONFIG( o_combo_box, o_module_name,
413                                     CONFIG_ITEM_STRING, p_item->psz_name );
414                     [o_combo_box setTarget: self];
415                     [o_combo_box setAction: @selector(configChanged:)];
416                     [o_combo_box sendActionOn:NSLeftMouseUpMask];
417
418                     if ( psz_duptip != NULL )
419                     {
420                         [o_combo_box setToolTip: [NSApp localizedString:
421                                             vlc_wraptext(psz_duptip, PREFS_WRAP)]];
422                         free( psz_duptip );
423                     }
424                     [o_view addSubview: [o_combo_box autorelease]];
425                     
426                     for( i=0; p_item->ppsz_list[i]; i++ )
427                     {
428                         [o_combo_box addItemWithObjectValue:
429                             [NSString stringWithCString: p_item->ppsz_list[i]]];
430                     }
431                     [o_combo_box setStringValue: [NSString stringWithCString: 
432                         p_item->psz_value ? p_item->psz_value : ""]];
433     
434                     CONTROL_LABEL( p_item->psz_text );
435     
436                     s_rc.origin.y += s_rc.size.height;
437                     s_rc.origin.x = X_ORIGIN;
438                 }
439     
440             }
441             break;
442     
443             case CONFIG_ITEM_INTEGER:
444             {
445                 INPUT_FIELD_INTEGER( p_item->psz_name, p_item->psz_text, 70,
446                                     p_item->i_value, p_item->psz_longtext );
447             }
448             break;
449     
450             case CONFIG_ITEM_FLOAT:
451             {
452                 INPUT_FIELD_FLOAT( p_item->psz_name, p_item->psz_text, 70,
453                                 p_item->f_value, p_item->psz_longtext );
454             }
455             break;
456     
457             case CONFIG_ITEM_BOOL:
458             {
459                 VLCButton *o_btn_bool;
460                 char * psz_duptip = NULL;
461                 if ( p_item->psz_longtext != NULL && [NSApp getEncoding] == NSISOLatin1StringEncoding )
462                     psz_duptip = strdup(p_item->psz_longtext);
463     
464                 s_rc.size.height = 27;
465                 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2 - 20;
466                 s_rc.origin.y += 10;
467     
468                 CHECK_VIEW_HEIGHT;
469     
470                 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
471                 [o_btn_bool setButtonType: NSSwitchButton];
472                 [o_btn_bool setIntValue: p_item->i_value];
473                 [o_btn_bool setTitle:
474                     [NSApp localizedString: p_item->psz_text]];
475                 if ( psz_duptip != NULL )
476                 {
477                     [o_btn_bool setToolTip: [NSApp localizedString:
478                                             vlc_wraptext(psz_duptip, PREFS_WRAP)]];
479                     free( psz_duptip );
480                 }
481                 [o_btn_bool setTarget: self];
482                 [o_btn_bool setAction: @selector(configChanged:)];
483                 CONTROL_CONFIG( o_btn_bool, o_module_name,
484                                 CONFIG_ITEM_BOOL, p_item->psz_name );
485                 [o_view addSubview: [o_btn_bool autorelease]];
486     
487                 s_rc.origin.y += s_rc.size.height;
488             }
489             break;
490     
491             }
492     
493     #undef INPUT_FIELD_INTEGER
494     #undef INPUT_FIELD_FLOAT
495     #undef INPUT_FIELD_STRING
496     #undef INPUT_FIELD
497     #undef CHECK_VIEW_HEIGHT
498     #undef CONTROL_LABEL
499     #undef Y_ORIGIN
500     #undef X_ORIGIN
501         }
502         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
503         vlc_list_release( p_list );
504     
505     [o_prefs_view setDocumentView: o_view];
506     [o_prefs_view setNeedsDisplay: TRUE];
507 }
508
509
510 @end
511
512 @implementation VLCPrefs (NSTableDataSource)
513
514 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
515     return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
516 }
517
518 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
519     return (item == nil) ? YES : ([item numberOfChildren] != -1);
520 }
521
522 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
523     return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
524 }
525
526 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
527     return (item == nil) ? @"" : (id)[item getName];
528 }
529
530 @end
531
532 @implementation VLCTreeItem
533
534 static VLCTreeItem *o_root_item = nil;
535
536 #define IsALeafNode ((id)-1)
537
538 - (id)initWithName: (NSString *)o_item_name ID: (int)i_id parent:(VLCTreeItem *)o_parent_item
539 {
540     self = [super init];
541
542     if( self != nil )
543     {
544         o_name = [o_item_name copy];
545         i_object_id = i_id;
546         o_parent = o_parent_item;
547     }
548     return( self );
549 }
550
551 + (VLCTreeItem *)rootItem {
552    if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithName:@"main" ID: 0 parent:nil];
553    return o_root_item;       
554 }
555
556 - (void)dealloc
557 {
558     if (o_children != IsALeafNode) [o_children release];
559     [o_name release];
560     [super dealloc];
561 }
562
563 /* Creates and returns the array of children
564  * Loads children incrementally */
565 - (NSArray *)children {
566     if (o_children == NULL) {
567         intf_thread_t *p_intf = [NSApp getIntf];
568         vlc_list_t      *p_list;
569         module_t        *p_module;
570         module_config_t *p_item;
571         int i_index,j;
572
573         /* List the plugins */
574         p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
575         if( !p_list ) return nil;
576
577         if( [[self getName] isEqualToString: @"main"] )
578         {
579             /*
580             * Build a tree of the main options
581             */
582             for( i_index = 0; i_index < p_list->i_count; i_index++ )
583             {
584                 p_module = (module_t *)p_list->p_values[i_index].p_object;
585                 if( !strcmp( p_module->psz_object_name, "main" ) )
586                     break;
587             }
588             if( i_index < p_list->i_count )
589             {
590                 /* We found the main module */
591         
592                 /* Enumerate config categories and store a reference so we can
593                  * generate their config panel them when it is asked by the user. */
594                 p_item = p_module->p_config;
595                 o_children = [[NSMutableArray alloc] initWithCapacity:10];
596
597                 if( p_item ) do
598                 {
599                     NSString *o_child_name;
600                     
601                     switch( p_item->i_type )
602                     {
603                     case CONFIG_HINT_CATEGORY:
604                         o_child_name = [NSString stringWithUTF8String: p_item->psz_text];
605                         [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
606                             ID: p_module->i_object_id parent:self]];
607                         break;
608                     }
609                 }
610                 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
611                 
612                 /* Add the plugins item */
613                 [o_children addObject:[[VLCTreeItem alloc] initWithName: _NS("Modules")
614                     ID: 0 parent:self]];
615             }
616             else
617             {
618                 o_children = IsALeafNode;
619             }
620         }
621         else if( [[self getName] isEqualToString: _NS("Modules")] )
622         {
623             /* Add the capabilities */
624             o_children = [[NSMutableArray alloc] initWithCapacity:10];
625             for( i_index = 0; i_index < p_list->i_count; i_index++ )
626             {
627                 p_module = (module_t *)p_list->p_values[i_index].p_object;
628         
629                 /* Exclude the main module */
630                 if( !strcmp( p_module->psz_object_name, "main" ) )
631                     continue;
632         
633                 /* Exclude empty plugins */
634                 p_item = p_module->p_config;
635                 if( !p_item ) continue;
636                 do
637                 {
638                     if( p_item->i_type & CONFIG_ITEM )
639                         break;
640                 }
641                 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
642                 if( p_item->i_type == CONFIG_HINT_END ) continue;
643         
644                 /* Create the capability tree if it doesn't already exist */
645                 NSString *o_capability;
646                 o_capability = [NSString stringWithUTF8String: p_module->psz_capability];
647                 if( !p_module->psz_capability || !*p_module->psz_capability )
648                 {
649                     /* Empty capability ? Let's look at the submodules */
650                     module_t * p_submodule;
651                     for( j = 0; j < p_module->i_children; j++ )
652                     {
653                         p_submodule = (module_t*)p_module->pp_children[ j ];
654                         if( p_submodule->psz_capability && *p_submodule->psz_capability )
655                         {
656                             o_capability = [NSString stringWithUTF8String: p_submodule->psz_capability];
657                             BOOL b_found = FALSE;
658                             for( j = 0; j < [o_children count]; j++ )
659                             {
660                                 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
661                                 {
662                                     b_found = TRUE;
663                                     break;
664                                 }
665                             }
666                             if( !b_found )
667                             {
668                                 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
669                                 ID: 0 parent:self]];
670                             }
671                         }
672                     }
673                 }
674
675                 BOOL b_found = FALSE;
676                 for( j = 0; j < [o_children count]; j++ )
677                 {
678                     if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
679                     {
680                         b_found = TRUE;
681                         break;
682                     }
683                 }
684                 if( !b_found )
685                 {
686                     [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
687                     ID: 0 parent:self]];
688                 }
689             }
690         }
691         else if( [[o_parent getName] isEqualToString: _NS("Modules")] )
692         {
693             /* Now add the modules */
694             o_children = [[NSMutableArray alloc] initWithCapacity:10];
695             for( i_index = 0; i_index < p_list->i_count; i_index++ )
696             {
697                 p_module = (module_t *)p_list->p_values[i_index].p_object;
698         
699                 /* Exclude the main module */
700                 if( !strcmp( p_module->psz_object_name, "main" ) )
701                     continue;
702         
703                 /* Exclude empty plugins */
704                 p_item = p_module->p_config;
705                 if( !p_item ) continue;
706                 do
707                 {
708                     if( p_item->i_type & CONFIG_ITEM )
709                         break;
710                 }
711                 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
712                 if( p_item->i_type == CONFIG_HINT_END ) continue;
713         
714                 /* Check the capability */
715                 NSString *o_capability;
716                 o_capability = [NSString stringWithUTF8String: p_module->psz_capability];
717                 if( !p_module->psz_capability || !*p_module->psz_capability )
718                 {
719                     /* Empty capability ? Let's look at the submodules */
720                     module_t * p_submodule;
721                     for( j = 0; j < p_module->i_children; j++ )
722                     {
723                         p_submodule = (module_t*)p_module->pp_children[ j ];
724                         if( p_submodule->psz_capability && *p_submodule->psz_capability )
725                         {
726                             o_capability = [NSString stringWithUTF8String: p_submodule->psz_capability];
727                             if( [o_capability isEqualToString: [self getName]] )
728                             {
729                             [o_children addObject:[[VLCTreeItem alloc] initWithName:
730                                 [NSString stringWithUTF8String: p_module->psz_object_name ]
731                                 ID: p_module->i_object_id parent:self]];
732                             }
733                         }
734                     }
735                 }
736                 else if( [o_capability isEqualToString: [self getName]] )
737                 {
738                     [o_children addObject:[[VLCTreeItem alloc] initWithName:
739                         [NSString stringWithUTF8String: p_module->psz_object_name ]
740                         ID: p_module->i_object_id parent:self]];
741                 }
742             }
743         }
744         else
745         {
746             /* all the other stuff are leafs */
747             o_children = IsALeafNode;
748         }
749     }
750     return o_children;
751 }
752
753 - (int)getObjectID
754 {
755     return i_object_id;
756 }
757
758 - (NSString *)getName
759 {
760     return o_name;
761 }
762
763 - (VLCTreeItem *)childAtIndex:(int)i_index {
764     return [[self children] objectAtIndex:i_index];
765 }
766
767 - (int)numberOfChildren {
768     id i_tmp = [self children];
769     return (i_tmp == IsALeafNode) ? (-1) : [i_tmp count];
770 }
771
772 - (BOOL)hasPrefs:(NSString *)o_module_name
773 {
774     intf_thread_t *p_intf = [NSApp getIntf];
775     module_t *p_parser;
776     vlc_list_t *p_list;
777     char *psz_module_name;
778     int i_index;
779
780     psz_module_name = (char *)[o_module_name lossyCString];
781
782     /* look for module */
783     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
784
785     for( i_index = 0; i_index < p_list->i_count; i_index++ )
786     {
787         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
788
789         if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
790         {
791             BOOL b_has_prefs = p_parser->i_config_items != 0;
792             vlc_list_release( p_list );
793             return( b_has_prefs );
794         }
795     }
796
797     vlc_list_release( p_list );
798
799     return( NO );
800 }
801
802 @end
803
804
805 @implementation VLCFlippedView
806
807 - (BOOL)isFlipped
808 {
809     return( YES );
810 }
811
812 @end
813
814 IMPL_CONTROL_CONFIG(Button);
815 IMPL_CONTROL_CONFIG(PopUpButton);
816 IMPL_CONTROL_CONFIG(ComboBox);
817 IMPL_CONTROL_CONFIG(TextField);