Changeset 526bc3ad447242153efb06676f76760b5fd55642

Show
Ignore:
Timestamp:
07/05/08 17:33:48 (2 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1215272028 +0200
git-parent:

[0ea547ed15f5fcaad9cec61bbe4c73e3a0ef2626]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1215270927 +0200
Message:

macosx: Attempt to simplify that ugly code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/gui/macosx/prefs.m

    r6175138 r526bc3a  
    6060#import "vlc_keys.h" 
    6161 
     62/* /!\ Warning: Unreadable code :/ */ 
     63 
    6264/***************************************************************************** 
    6365 * VLCPrefs implementation 
     
    288290        vlc_list_t      *p_list; 
    289291        module_t        *p_module = NULL; 
    290         module_t        *p_parser; 
    291         module_config_t *p_item, 
    292                         *p_end; 
    293         int             i_index = 0; 
    294  
    295         /* List the modules */ 
    296         p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
    297         if( !p_list ) return nil; 
    298  
    299         /* get parser */ 
    300         p_parser = (module_t *)p_list->p_values[i_index].p_object; 
    301  
     292        module_t        *p_main_module; 
     293        module_config_t *p_items; 
     294        int             i = 0; 
    302295        if( [[self getName] isEqualToString: @"main"] ) 
    303296        { 
    304             /* 
    305             * Find the main module 
    306             */ 
    307             for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
     297            p_main_module = module_GetMainModule( p_intf ); 
     298            assert( p_main_module ); 
     299 
     300            /* We found the main module */ 
     301            /* Enumerate config categories and store a reference so we can 
     302             * generate their config panel them when it is asked by the user. */ 
     303            VLCTreeItem *p_last_category = NULL; 
     304            unsigned int i_confsize; 
     305            p_items = module_GetConfig( p_main_module, &i_confsize ); 
     306            o_children = [[NSMutableArray alloc] initWithCapacity:10]; 
     307            for( int i = 0; i < i_confsize; i++ ) 
    308308            { 
    309                 p_module = (module_t *)p_list->p_values[i_index].p_object; 
    310                 if( !strcmp( module_GetObjName( p_module ), "main" ) ) 
     309                NSString *o_child_name; 
     310                NSString *o_child_title; 
     311                NSString *o_child_help; 
     312                switch( p_items[i].i_type ) 
     313                { 
     314                case CONFIG_CATEGORY: 
     315                    if( p_items[i].value.i == -1 ) break; 
     316 
     317                    o_child_name = [[VLCMain sharedInstance] 
     318                        localizedString: config_CategoryNameGet( p_items[i].value.i )]; 
     319                    o_child_title = o_child_name; 
     320                    o_child_help = [[VLCMain sharedInstance] 
     321                        localizedString: config_CategoryHelpGet( p_items[i].value.i )]; 
     322                    p_last_category = [VLCTreeItem alloc]; 
     323                    [o_children addObject:[p_last_category 
     324                        initWithName: o_child_name 
     325                        withTitle: o_child_title 
     326                        withHelp: o_child_help 
     327                        ID: p_items[i].value.i 
     328                        parent:self 
     329                        children:[[NSMutableArray alloc] 
     330                            initWithCapacity:10] 
     331                        whithCategory: p_items[i].i_type]]; 
    311332                    break; 
    312             } 
    313             if( p_module == NULL ) 
    314             { 
    315                 msg_Err( p_intf, 
    316                     "could not load the preferences" ); 
    317                 return nil; 
    318             } 
    319             if( i_index < p_list->i_count ) 
    320             { 
    321                 /* We found the main module */ 
    322                 /* Enumerate config categories and store a reference so we can 
    323                  * generate their config panel them when it is asked by the user. */ 
    324                 VLCTreeItem *p_last_category = NULL; 
    325                 unsigned int i_confsize; 
    326                 p_item = module_GetConfig( p_parser, &i_confsize ); 
    327                 p_end = p_item + i_confsize; 
    328                 o_children = [[NSMutableArray alloc] initWithCapacity:10]; 
    329                 if( p_item ) do 
    330                 { 
    331                     NSString *o_child_name; 
    332                     NSString *o_child_title; 
    333                     NSString *o_child_help; 
    334                     switch( p_item->i_type ) 
     333                case CONFIG_SUBCATEGORY: 
     334                    if( p_items[i].value.i == -1 ) break; 
     335 
     336                    if( p_items[i].value.i != SUBCAT_PLAYLIST_GENERAL && 
     337                        p_items[i].value.i != SUBCAT_VIDEO_GENERAL && 
     338                        p_items[i].value.i != SUBCAT_INPUT_GENERAL && 
     339                        p_items[i].value.i != SUBCAT_INTERFACE_GENERAL && 
     340                        p_items[i].value.i != SUBCAT_SOUT_GENERAL && 
     341                        p_items[i].value.i != SUBCAT_ADVANCED_MISC && 
     342                        p_items[i].value.i != SUBCAT_AUDIO_GENERAL ) 
    335343                    { 
    336                     case CONFIG_CATEGORY: 
    337                         if( p_item->value.i == -1 ) break; 
    338  
    339344                        o_child_name = [[VLCMain sharedInstance] 
    340                             localizedString: config_CategoryNameGet( p_item->value.i )]; 
     345                            localizedString: config_CategoryNameGet( p_items[i].value.i ) ]; 
    341346                        o_child_title = o_child_name; 
    342347                        o_child_help = [[VLCMain sharedInstance] 
    343                             localizedString: config_CategoryHelpGet( p_item->value.i )]; 
    344                         p_last_category = [VLCTreeItem alloc]; 
    345                         [o_children addObject:[p_last_category 
     348                            localizedString: config_CategoryHelpGet( p_items[i].value.i ) ]; 
     349 
     350                        [p_last_category->o_children 
     351                            addObject:[[VLCTreeItem alloc] 
    346352                            initWithName: o_child_name 
    347353                            withTitle: o_child_title 
    348354                            withHelp: o_child_help 
    349                             ID: p_item->value.i 
    350                             parent:self 
     355                            ID: p_items[i].value.i 
     356                            parent:p_last_category 
    351357                            children:[[NSMutableArray alloc] 
    352358                                initWithCapacity:10] 
    353                             whithCategory: p_item - module_GetConfig( p_module, &i_confsize )]]; 
    354                         break; 
    355                     case CONFIG_SUBCATEGORY: 
    356                         if( p_item->value.i == -1 ) break; 
    357  
    358                         if( p_item->value.i != SUBCAT_PLAYLIST_GENERAL && 
    359                             p_item->value.i != SUBCAT_VIDEO_GENERAL && 
    360                             p_item->value.i != SUBCAT_INPUT_GENERAL && 
    361                             p_item->value.i != SUBCAT_INTERFACE_GENERAL && 
    362                             p_item->value.i != SUBCAT_SOUT_GENERAL && 
    363                             p_item->value.i != SUBCAT_ADVANCED_MISC && 
    364                             p_item->value.i != SUBCAT_AUDIO_GENERAL ) 
    365                         { 
    366                             o_child_name = [[VLCMain sharedInstance] 
    367                                 localizedString: config_CategoryNameGet( p_item->value.i ) ]; 
    368                             o_child_title = o_child_name; 
    369                             o_child_help = [[VLCMain sharedInstance] 
    370                                 localizedString: config_CategoryHelpGet( p_item->value.i ) ]; 
    371  
    372                             [p_last_category->o_children 
    373                                 addObject:[[VLCTreeItem alloc] 
    374                                 initWithName: o_child_name 
    375                                 withTitle: o_child_title 
    376                                 withHelp: o_child_help 
    377                                 ID: p_item->value.i 
    378                                 parent:p_last_category 
    379                                 children:[[NSMutableArray alloc] 
    380                                     initWithCapacity:10] 
    381                                 whithCategory: p_item - module_GetConfig( p_parser, &i_confsize )]]; 
    382                         } 
    383   
    384                         break; 
    385                     default: 
    386                         break; 
     359                            whithCategory: p_items[i].i_type]]; 
    387360                    } 
    388                 } while( p_item < p_end && p_item++ ); 
     361 
     362                    break; 
     363                default: 
     364                    break; 
     365                } 
     366                vlc_object_release( (vlc_object_t *)p_main_module ); 
    389367            } 
     368 
     369            /* List the modules */ 
     370            p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
     371            if( !p_list ) return nil; 
    390372 
    391373            /* Build a tree of the plugins */ 
    392374            /* Add the capabilities */ 
    393             for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
     375            for( i = 0; i < p_list->i_count; i++ ) 
    394376            { 
    395377                unsigned int confsize; 
    396                 p_module = (module_t *)p_list->p_values[i_index].p_object; 
     378                p_module = (module_t *)p_list->p_values[i].p_object; 
    397379 
    398380                /* Exclude the main module */ 
    399                 if( !strcmp( module_GetObjName( p_module ), "main" ) ) 
     381                if( module_IsMainModule( p_module ) ) 
    400382                    continue; 
    401383 
     
    405387//                if( modules_IsSubModule( p_module ) ) 
    406388//                    continue; 
    407                 p_item = module_GetConfig( p_module, &confsize ); 
    408  
    409                 if( !p_item ) continue
    410                 if( !p_item->i_type ) break; 
     389                p_items = module_GetConfig( p_module, &confsize ); 
     390 
     391                unsigned int j
     392 
    411393                int i_category = -1; 
    412394                int i_subcategory = -1; 
    413                 int i_options = 0; 
    414                 do 
     395                bool b_item = false; 
     396 
     397                for( j = 0; j < confsize; j++ ) 
    415398                { 
    416                     if( p_item->i_type == CONFIG_CATEGORY ) 
    417                         i_category = p_item->value.i; 
    418                     else if( p_item->i_type == CONFIG_SUBCATEGORY ) 
    419                         i_subcategory = p_item->value.i; 
    420  
    421                     if( p_item->i_type & CONFIG_ITEM ) 
    422                         i_options ++; 
    423                     if( i_options > 0 && i_category >= 0 && i_subcategory >= 0 ) 
     399                    if( p_items[j].i_type == CONFIG_CATEGORY ) 
     400                        i_category = p_items[j].value.i; 
     401                    else if( p_items[j].i_type == CONFIG_SUBCATEGORY ) 
     402                        i_subcategory = p_items[j].value.i; 
     403 
     404                    if( p_items[j].i_type & CONFIG_ITEM ) 
     405                        b_item = true; 
     406             
     407                    if( b_item && i_category >= 0 && i_subcategory >= 0 ) 
    424408                        break; 
    425                 } while( p_item < p_end && p_item++ ); 
    426                 if( !i_options ) continue; 
     409                } 
     410     
     411                if( !b_item ) continue; 
    427412 
    428413                /* Find the right category item */ 
     
    557542        intf_thread_t   *p_intf = VLCIntf; 
    558543        vlc_list_t      *p_list; 
    559         module_t        *p_parser = NULL; 
    560         module_config_t *p_item, 
    561                         *p_end
     544        module_t        *p_module = NULL; 
     545        module_t        *p_main_module; 
     546        module_config_t *p_items
    562547        unsigned int confsize; 
    563548 
     
    566551        if( i_object_category == -1 ) 
    567552        { 
    568             p_parser = (module_t *) vlc_object_get( i_object_id ); 
    569             if( !p_parser ) 
     553            p_module = (module_t *) vlc_object_get( i_object_id ); 
     554            assert( p_module ); 
     555 
     556            p_items = module_GetConfig( p_module, &confsize ); 
     557 
     558            for( unsigned int i = 0; i < confsize; i++ ) 
    570559            { 
    571                 /* 0OOoo something went really bad */ 
    572                 return nil; 
     560                switch( p_items[i].i_type ) 
     561                { 
     562                    case CONFIG_SUBCATEGORY: 
     563                    case CONFIG_CATEGORY: 
     564                    case CONFIG_SECTION: 
     565                    case CONFIG_HINT_USAGE: 
     566                        break; 
     567                    default: 
     568                    { 
     569                        VLCConfigControl *o_control = nil; 
     570                        o_control = [VLCConfigControl newControl:&p_items[i] 
     571                                                      withView:o_view]; 
     572                        if( o_control ) 
     573                        { 
     574                            [o_control setAutoresizingMask: NSViewMaxYMargin | 
     575                                NSViewWidthSizable]; 
     576                            [o_subviews addObject: o_control]; 
     577                        } 
     578                    } 
     579                    break; 
     580                } 
    573581            } 
    574             p_item = module_GetConfig( p_parser, &confsize ); 
    575             p_end = p_item + confsize; 
    576  
    577             do 
     582            vlc_object_release( (vlc_object_t*)p_module ); 
     583        } 
     584        else 
     585        { 
     586            p_main_module = module_GetMainModule( p_intf ); 
     587            assert( !p_main_module ); 
     588            module_config_t *p_items; 
     589 
     590            unsigned int i, confsize; 
     591            p_items = module_GetConfig( p_main_module, &confsize ); 
     592 
     593            for( i = 0; i < confsize; i++ ) 
    578594            { 
    579                 if( !p_item
     595                if( !p_items[i].i_type
    580596                { 
    581597                    msg_Err( p_intf, "invalid preference item found" ); 
    582598                    break; 
    583599                } 
    584                 if( p_item > p_end ) 
    585                     break; 
    586                 switch(p_item->i_type) 
     600 
     601                switch( p_items[i].i_type ) 
    587602                { 
    588                 case CONFIG_SUBCATEGORY: 
    589                     break; 
    590                 case CONFIG_CATEGORY: 
    591                     break; 
    592                 case CONFIG_SECTION: 
    593                     break; 
    594                 case CONFIG_HINT_USAGE: 
    595                     break; 
    596                 default: 
    597                 { 
    598                     VLCConfigControl *o_control = nil; 
    599                     o_control = [VLCConfigControl newControl:p_item 
    600                                                   withView:o_view]; 
    601                     if( o_control != nil ) 
     603                    case CONFIG_SUBCATEGORY: 
     604                    case CONFIG_CATEGORY: 
     605                    case CONFIG_SECTION: 
     606                    case CONFIG_HINT_USAGE: 
     607                        break; 
     608                    default: 
    602609                    { 
    603                         [o_control setAutoresizingMask: NSViewMaxYMargin | 
    604                             NSViewWidthSizable]; 
    605                         [o_subviews addObject: o_control]; 
     610                        VLCConfigControl *o_control = nil; 
     611                        o_control = [VLCConfigControl newControl:&p_items[i] 
     612                                                      withView:o_view]; 
     613                        if( o_control != nil ) 
     614                        { 
     615                            [o_control setAutoresizingMask: NSViewMaxYMargin | 
     616                                                            NSViewWidthSizable]; 
     617                            [o_subviews addObject: o_control]; 
     618                        } 
     619                        break; 
    606620                    } 
    607621                } 
    608                     break; 
    609                 } 
    610             } while( p_item < p_end && p_item++ ); 
    611  
    612             vlc_object_release( (vlc_object_t*)p_parser ); 
    613         } 
    614         else 
    615         { 
    616             int i_index; 
    617             p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
    618             if( !p_list ) return o_view; 
    619  
    620             /* 
    621             * Find the main module 
    622             */ 
    623             for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
    624             { 
    625                 p_parser = (module_t *)p_list->p_values[i_index].p_object; 
    626                 if( !strcmp( module_GetObjName( p_parser ), "main" ) ) 
    627                     break; 
    628622            } 
    629             if( p_parser == NULL ) 
    630             { 
    631                 msg_Err( p_intf, "could not load preferences" ); 
    632                 return o_view; 
    633             } 
    634             unsigned int confsize; 
    635             p_item = module_GetConfig( p_parser, &confsize ); 
    636             p_end = p_item + confsize; 
    637             p_item += i_object_category; 
    638  
    639             if( ( p_item->i_type == CONFIG_CATEGORY ) && 
    640               ( ( p_item->value.i == CAT_PLAYLIST )  || 
    641                 ( p_item->value.i == CAT_AUDIO )  || 
    642                 ( p_item->value.i == CAT_VIDEO ) || 
    643                 ( p_item->value.i == CAT_INTERFACE ) || 
    644                 ( p_item->value.i == CAT_INPUT ) || 
    645                 ( p_item->value.i == CAT_SOUT ) ) ) 
    646                 p_item++; 
    647  
    648             do 
    649             { 
    650                 p_item++; 
    651                 if( !p_item || !p_item->i_type ) 
    652                 { 
    653                     msg_Err( p_intf, "invalid preference item found" ); 
    654                     break; 
    655                 } 
    656                 if( p_item > p_end ) 
    657                     break; 
    658                 switch( p_item->i_type ) 
    659                 { 
    660                 case CONFIG_SUBCATEGORY: 
    661                     break; 
    662                 case CONFIG_CATEGORY: 
    663                     break; 
    664                 case CONFIG_SECTION: 
    665                     break; 
    666                 case CONFIG_HINT_USAGE: 
    667                     break; 
    668                 default: 
    669                 { 
    670                     VLCConfigControl *o_control = nil; 
    671                     o_control = [VLCConfigControl newControl:p_item 
    672                                                   withView:o_view]; 
    673                     if( o_control != nil ) 
    674                     { 
    675                         [o_control setAutoresizingMask: NSViewMaxYMargin | 
    676                                                         NSViewWidthSizable]; 
    677                         [o_subviews addObject: o_control]; 
    678                     } 
    679                     break; 
    680                 } 
    681                 } 
    682             } while ( ( p_item < p_end ) && 
    683                       ( p_item->i_type != CONFIG_SUBCATEGORY ) ); 
    684  
    685             vlc_list_release( p_list ); 
     623            vlc_object_release( (vlc_object_t*)p_main_module ); 
    686624        } 
    687625    }