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