Changeset 5ec2ab65b9da97c218818273f7a8e62cd7eaee09

Show
Ignore:
Timestamp:
17/06/08 04:58:33 (6 months ago)
Author:
Jean-Baptiste Kempf <jb@videolan.org>
git-committer:
Jean-Baptiste Kempf <jb@videolan.org> 1213671513 -0700
git-parent:

[514a804f231641c2ca86d96281939df2a3843721]

git-author:
Jean-Philippe Andre <jpeg@via.ecp.fr> 1213623610 +0200
Message:

Qt4 menus: start fixing ticket 1602

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/gui/qt4/menus.cpp

    re00ed66 r5ec2ab6  
    2323 *****************************************************************************/ 
    2424 
     25/** \todo 
     26 * - Remove static currentGroup 
     27 */ 
     28 
    2529#ifdef HAVE_CONFIG_H 
    2630# include "config.h" 
     
    98102 *****************************************************************************/ 
    99103#define PUSH_VAR( var ) varnames.push_back( var ); \ 
    100     objects.push_back( p_object->i_object_id ) 
     104    objects.push_back( p_object ? p_object->i_object_id : 0 ) 
     105 
     106#define PUSH_INPUTVAR( var ) varnames.push_back( var ); \ 
     107    objects.push_back( p_input ? p_input->i_object_id : 0 ); 
    101108 
    102109#define PUSH_SEPARATOR if( objects.size() != i_last_separator ) { \ 
     
    118125 
    119126static int VideoAutoMenuBuilder( vlc_object_t *p_object, 
     127        input_thread_t *p_input, 
    120128        vector<int> &objects, 
    121129        vector<const char *> &varnames ) 
    122130{ 
     131    PUSH_INPUTVAR( "video-es" ); 
     132    PUSH_INPUTVAR( "spu-es" ); 
    123133    PUSH_VAR( "fullscreen" ); 
    124134    PUSH_VAR( "zoom" ); 
     
    130140    PUSH_VAR( "video-snapshot" ); 
    131141 
    132     vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object, 
    133             VLC_OBJECT_DECODER, 
    134             FIND_PARENT ); 
    135     if( p_dec_obj != NULL ) 
    136     { 
    137         vlc_object_t *p_object = p_dec_obj; 
    138         PUSH_VAR( "ffmpeg-pp-q" ); 
    139         vlc_object_release( p_dec_obj ); 
     142    if( p_object ) 
     143    { 
     144        vlc_object_t *p_dec_obj = ( vlc_object_t * )vlc_object_find( p_object, 
     145                VLC_OBJECT_DECODER, 
     146                FIND_PARENT ); 
     147        if( p_dec_obj ) 
     148        { 
     149            vlc_object_t *p_object = p_dec_obj; 
     150            PUSH_VAR( "ffmpeg-pp-q" ); 
     151            vlc_object_release( p_dec_obj ); 
     152        } 
    140153    } 
    141154    return VLC_SUCCESS; 
     
    143156 
    144157static int AudioAutoMenuBuilder( vlc_object_t *p_object, 
     158        input_thread_t *p_input, 
    145159        vector<int> &objects, 
    146160        vector<const char *> &varnames ) 
    147161{ 
     162    PUSH_INPUTVAR( "audio-es" ); 
    148163    PUSH_VAR( "audio-device" ); 
    149164    PUSH_VAR( "audio-channels" ); 
     
    153168} 
    154169 
     170static QAction * FindActionWithVar( QMenu *menu, const char *psz_var ) 
     171{ 
     172    QAction *action; 
     173    Q_FOREACH( action, menu->actions() ) 
     174    { 
     175        if( action->data().toString() == psz_var ) 
     176            return action; 
     177    } 
     178    return NULL; 
     179} 
     180 
     181static QAction * FindActionWithText( QMenu *menu, QString &text ) 
     182{ 
     183    QAction *action; 
     184    Q_FOREACH( action, menu->actions() ) 
     185    { 
     186        if( action->text() == text ) 
     187            return action; 
     188    } 
     189    return NULL; 
     190} 
     191 
    155192/***************************************************************************** 
    156193 * All normal menus 
     
    159196 
    160197#define BAR_ADD( func, title ) { \ 
    161     QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); } 
     198    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); } 
    162199 
    163200#define BAR_DADD( func, title, id ) { \ 
    164     QMenu *menu = func; menu->setTitle( title ); bar->addMenu( menu ); \ 
    165     MenuFunc *f = new MenuFunc( menu, id ); \ 
    166     CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \ 
    167     THEDP->menusUpdateMapper->setMapping( menu, f ); } 
     201    QMenu *_menu = func; _menu->setTitle( title ); bar->addMenu( _menu ); \ 
     202    MenuFunc *f = new MenuFunc( _menu, id ); \ 
     203    CONNECT( _menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \ 
     204    THEDP->menusUpdateMapper->setMapping( _menu, f ); } 
     205 
     206#define ACT_ADD( _menu, val, title ) { \ 
     207    QAction *_action = new QAction( title, _menu ); _action->setData( val ); \ 
     208    _menu->addAction( _action ); } 
    168209 
    169210/** 
     
    182223    BAR_ADD( ToolsMenu( p_intf, NULL, mi, visual_selector_enabled, true ), 
    183224             qtr( "&Tools" ) ); 
    184     BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 2 ); 
    185     BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 1 ); 
     225    BAR_DADD( AudioMenu( p_intf, NULL ), qtr( "&Audio" ), 1 ); 
     226    BAR_DADD( VideoMenu( p_intf, NULL ), qtr( "&Video" ), 2 ); 
    186227    BAR_DADD( NavigMenu( p_intf, NULL ), qtr( "&Playback" ), 3 ); 
    187  
    188228    BAR_ADD( HelpMenu( NULL ), qtr( "&Help" ) ); 
    189229} 
     
    350390    vector<int> objects; 
    351391    vector<const char *> varnames; 
    352  
    353     vlc_object_t *p_object = ( vlc_object_t * )vlc_object_find( p_intf, 
    354             VLC_OBJECT_INPUT, FIND_ANYWHERE ); 
    355     if( p_object != NULL ) 
    356     { 
    357         PUSH_VAR( "audio-es" ); 
     392    vlc_object_t *p_object; 
     393    input_thread_t *p_input; 
     394 
     395    if( !current ) 
     396        current = new QMenu(); 
     397 
     398    if( current->isEmpty() ) 
     399    { 
     400        ACT_ADD( current, "audio-es", qtr( "Audio &Track" ) ); 
     401        ACT_ADD( current, "audio-device", qtr( "Audio &Device" ) ); 
     402        ACT_ADD( current, "audio-channels", qtr( "Audio &Channels" ) ); 
     403        ACT_ADD( current, "visual", qtr( "&Visualizations" ) ); 
     404        ACT_ADD( current, "equalizer", qtr( "&Equalizer" ) ); 
     405    } 
     406 
     407    p_input = THEMIM->getInput(); 
     408    if( p_input ) 
     409        vlc_object_yield( p_input ); 
     410    p_object = ( vlc_object_t * ) vlc_object_find( p_intf, 
     411                                                   VLC_OBJECT_AOUT, 
     412                                                   FIND_ANYWHERE ); 
     413 
     414    AudioAutoMenuBuilder( p_object, p_input, objects, varnames ); 
     415 
     416    if( p_object ) 
    358417        vlc_object_release( p_object ); 
    359     } 
    360  
    361     p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_AOUT, 
    362             FIND_ANYWHERE ); 
    363     if( p_object ) 
    364     { 
    365         AudioAutoMenuBuilder( p_object, objects, varnames ); 
    366         vlc_object_release( p_object ); 
    367     } 
     418    if( p_input ) 
     419        vlc_object_release( p_input ); 
     420 
    368421    return Populate( p_intf, current, varnames, objects ); 
    369422} 
     
    376429{ 
    377430    vlc_object_t *p_object; 
     431    input_thread_t *p_input; 
    378432    vector<int> objects; 
    379433    vector<const char *> varnames; 
    380434 
    381     p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT, 
    382             FIND_ANYWHERE ); 
    383     if( p_object != NULL ) 
    384     { 
    385         PUSH_VAR( "video-es" ); 
    386         PUSH_VAR( "spu-es" ); 
    387         vlc_object_release( p_object ); 
    388     } 
    389  
     435    if( !current ) 
     436        current = new QMenu(); 
     437 
     438    if( current->isEmpty() ) 
     439    { 
     440        ACT_ADD( current, "video-es", qtr( "Video &Track" ) ); 
     441        ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) ); 
     442        ACT_ADD( current, "zoom", qtr( "&Zoom" ) ); 
     443        ACT_ADD( current, "deinterlace", qtr( "&Deinterlace" ) ); 
     444        ACT_ADD( current, "aspect-ratio", qtr( "&Aspect Ratio" ) ); 
     445        ACT_ADD( current, "crop", qtr( "&Crop" ) ); 
     446        ACT_ADD( current, "video-on-top", qtr( "Always &On Top" ) ); 
     447        ACT_ADD( current, "directx-wallpaper", qtr( "&DirectX Wallpaper" ) ); /* FIXME */ 
     448        ACT_ADD( current, "video-snapshot", qtr( "&Snapshot" ) ); 
     449        ACT_ADD( current, "ffmpeg-pp-q", qtr( "D&ecoder" ) ); /* FIXME */ 
     450    } 
     451 
     452    p_input = THEMIM->getInput(); 
     453    if( p_input ) 
     454        vlc_object_yield( p_input ); 
    390455    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT, 
    391456            FIND_ANYWHERE ); 
    392     if( p_object != NULL ) 
    393     { 
    394         VideoAutoMenuBuilder( p_object, objects, varnames ); 
     457 
     458    VideoAutoMenuBuilder( p_object, p_input, objects, varnames ); 
     459 
     460    if( p_object ) 
    395461        vlc_object_release( p_object ); 
    396     } 
     462    if( p_input ) 
     463        vlc_object_release( p_input ); 
     464 
    397465    return Populate( p_intf, current, varnames, objects ); 
    398466} 
     
    410478    p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT, 
    411479            FIND_ANYWHERE ); 
    412     if( p_object != NULL ) 
    413     { 
    414         InputAutoMenuBuilder(  p_object, objects, varnames ); 
    415         PUSH_VAR( "prev-title" ); PUSH_VAR ( "next-title" ); 
    416         PUSH_VAR( "prev-chapter" ); PUSH_VAR( "next-chapter" ); 
     480    InputAutoMenuBuilder(  p_object, objects, varnames ); 
     481    PUSH_VAR( "prev-title" ); 
     482    PUSH_VAR( "next-title" ); 
     483    PUSH_VAR( "prev-chapter" ); 
     484    PUSH_VAR( "next-chapter" ); 
     485    if( p_object ) 
    417486        vlc_object_release( p_object ); 
    418     } 
    419487    QMenu *navMenu = new QMenu( menu ); 
    420488    addDPStaticEntry( navMenu, qtr( I_MENU_GOTOTIME ), "","", 
     
    479547} 
    480548 
     549#undef ACT_ADD 
    481550 
    482551/***************************************************************************** 
     
    555624    { 
    556625        vlc_object_yield( p_input ); 
    557         varnames.push_back( "video-es" ); 
    558         objects.push_back( p_input->i_object_id ); 
    559         varnames.push_back( "spu-es" ); 
    560         objects.push_back( p_input->i_object_id ); 
    561626        vlc_object_t *p_vout = ( vlc_object_t * )vlc_object_find( p_input, 
    562627                VLC_OBJECT_VOUT, FIND_CHILD ); 
    563628        if( p_vout ) 
    564629        { 
    565             VideoAutoMenuBuilder( p_vout, objects, varnames ); 
     630            VideoAutoMenuBuilder( p_vout, p_input, objects, varnames ); 
    566631            vlc_object_release( p_vout ); 
    567632        } 
     
    579644    { 
    580645        vlc_object_yield( p_input ); 
    581         varnames.push_back( "audio-es" ); 
    582         objects.push_back( p_input->i_object_id ); 
    583646        vlc_object_t *p_aout = ( vlc_object_t * )vlc_object_find( p_input, 
    584647                VLC_OBJECT_AOUT, FIND_ANYWHERE ); 
     648        AudioAutoMenuBuilder( p_aout, p_input, objects, varnames ); 
    585649        if( p_aout ) 
    586         { 
    587             AudioAutoMenuBuilder( p_aout, objects, varnames ); 
    588650            vlc_object_release( p_aout ); 
    589         } 
    590651        vlc_object_release( p_input ); 
    591652    } 
     
    638699                /* Audio menu */ 
    639700                PUSH_SEPARATOR; 
    640                 varnames.push_back( "audio-es" ); 
    641                 objects.push_back( p_input->i_object_id ); 
    642701                vlc_object_t *p_aout = ( vlc_object_t * ) 
    643702                    vlc_object_find( p_input, VLC_OBJECT_AOUT, FIND_ANYWHERE ); 
     703                AudioAutoMenuBuilder( p_aout, p_input, objects, varnames ); 
    644704                if( p_aout ) 
    645                 { 
    646                     AudioAutoMenuBuilder( p_aout, objects, varnames ); 
    647705                    vlc_object_release( p_aout ); 
    648                 } 
    649706 
    650707                /* Video menu */ 
    651708                PUSH_SEPARATOR; 
    652                 varnames.push_back( "video-es" ); 
    653                 objects.push_back( p_input->i_object_id ); 
    654                 varnames.push_back( "spu-es" ); 
    655                 objects.push_back( p_input->i_object_id ); 
    656709                vlc_object_t *p_vout = ( vlc_object_t * ) 
    657710                    vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD ); 
     711                    VideoAutoMenuBuilder( p_vout, p_input, objects, varnames ); 
    658712                if( p_vout ) 
    659                 { 
    660                     VideoAutoMenuBuilder( p_vout, objects, varnames ); 
    661713                    vlc_object_release( p_vout ); 
    662                 } 
    663714 
    664715                vlc_object_release( p_input ); 
     
    727778#undef PUSH_VAR 
    728779#undef PUSH_SEPARATOR 
    729  
    730780 
    731781/************************************************************************* 
     
    741791    if( !menu ) 
    742792        menu = new QMenu(); 
    743     else if( !append ) 
    744         menu->clear(); 
     793 
     794    QAction *p_action; 
     795    Q_FOREACH( p_action, menu->actions() ) 
     796    { 
     797        p_action->setEnabled( false ); 
     798    } 
    745799 
    746800    currentGroup = NULL; 
    747801 
    748802    vlc_object_t *p_object; 
    749     bool b_section_empty = false; 
    750803    int i; 
    751  
    752 #define APPEND_EMPTY { QAction *action = menu->addAction( qtr( "Empty" ) ); \ 
    753     action->setEnabled( false ); } 
    754804 
    755805    for( i = 0; i < ( int )objects.size() ; i++ ) 
     
    757807        if( !varnames[i] || !*varnames[i] ) 
    758808        { 
    759             if( b_section_empty ) 
    760                 APPEND_EMPTY; 
    761809            menu->addSeparator(); 
    762             b_section_empty = true; 
    763810            continue; 
    764811        } 
     
    766813        if( objects[i] == 0 ) 
    767814        { 
    768             /// \bug What is this ? 
    769             // Append( menu, varnames[i], NULL ); 
    770             b_section_empty = false; 
    771815            continue; 
    772816        } 
    773  
    774         p_object = ( vlc_object_t * )vlc_object_get( objects[i] ); 
    775         if( p_object == NULL ) continue; 
    776  
    777         b_section_empty = false; 
     817        else 
     818        { 
     819            p_object = ( vlc_object_t * )vlc_object_get( objects[i] ); 
     820            if( !p_object ) 
     821            { 
     822                msg_Dbg( p_intf, "object %d not found !", objects[i] ); 
     823                continue; 
     824            } 
     825        } 
     826 
    778827        /* Ugly specific stuff */ 
    779828        if( strstr( varnames[i], "intf-add" ) ) 
    780             CreateItem( menu, varnames[i], p_object, false ); 
     829            UpdateItem( p_intf, menu, varnames[i], p_object, false ); 
    781830        else 
    782             CreateItem( menu, varnames[i], p_object, true ); 
    783         vlc_object_release( p_object ); 
    784     } 
    785  
    786     /* Special case for empty menus */ 
    787     if( menu->actions().size() == 0 || b_section_empty ) 
    788         APPEND_EMPTY 
    789  
     831            UpdateItem( p_intf, menu, varnames[i], p_object, true ); 
     832        if( p_object ) 
     833            vlc_object_release( p_object ); 
     834    } 
    790835    return menu; 
    791836} 
    792 #undef APPEND_EMPTY 
    793837 
    794838/***************************************************************************** 
     
    840884} 
    841885 
    842 void QVLCMenu::CreateItem( QMenu *menu, const char *psz_var, 
    843         vlc_object_t *p_object, bool b_submenu ) 
     886#define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var ) 
     887 
     888void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu, 
     889        const char *psz_var, vlc_object_t *p_object, bool b_submenu ) 
    844890{ 
    845891    vlc_value_t val, text; 
    846892    int i_type; 
    847893 
     894    if( !p_object ) 
     895    { 
     896        /* Nothing to do */ 
     897        return; 
     898    } 
     899 
     900    if( !strcmp( psz_var, "spu-es" ) ) 
     901    { 
     902        /* TODO: add a static entry "Load File..." */ 
     903        return; 
     904    } 
     905 
    848906    /* Check the type of the object variable */ 
    849     i_type = var_Type( p_object, psz_var ); 
     907    if( !strcmp( psz_var, "audio-es" ) 
     908     || !strcmp( psz_var, "video-es" ) ) 
     909        i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE; 
     910    else 
     911        i_type = var_Type( p_object, psz_var ); 
    850912 
    851913    switch( i_type & VLC_VAR_TYPE ) 
     
    867929 
    868930    /* Get the descriptive name of the variable */ 
    869     var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL ); 
     931    int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL ); 
     932    if( i_ret != VLC_SUCCESS ) 
     933    { 
     934        text.psz_string = NULL; 
     935    } 
     936 
     937    QAction *action = FindActionWithVar( menu, psz_var ); 
     938    if( !action ) 
     939    { 
     940        action = new QAction( TEXT_OR_VAR, menu ); 
     941        menu->addAction( action ); 
     942    } 
    870943 
    871944    if( i_type & VLC_VAR_HASCHOICE ) 
     
    874947        if( b_submenu ) 
    875948        { 
    876             QMenu *submenu = new QMenu( menu ); 
    877             submenu->setTitle( qfu( text.psz_string ? 
    878                         text.psz_string : psz_var ) ); 
     949            QMenu *submenu; 
     950            action->setEnabled( true ); 
     951            submenu = action->menu(); 
     952            if( !submenu ) 
     953            { 
     954                submenu = new QMenu( menu ); 
     955                action->setMenu( submenu ); 
     956            } 
     957            submenu->setEnabled( true ); 
     958 
    879959            if( CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 ) 
    880960                menu->addMenu( submenu ); 
     
    885965        return; 
    886966    } 
    887  
    888 #define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var ) 
    889967 
    890968    switch( i_type & VLC_VAR_TYPE ) 
     
    10101088        bool checked ) 
    10111089{ 
    1012     QAction *action = new QAction( text, menu ); 
     1090    QAction *action = FindActionWithVar( menu, psz_var ); 
     1091    if( !action ) 
     1092    { 
     1093        /* This is a value */ 
     1094        action = FindActionWithText( menu, text ); 
     1095        if( !action ) 
     1096        { 
     1097            action = new QAction( text, menu ); 
     1098            menu->addAction( action ); 
     1099        } 
     1100    } 
     1101 
    10131102    action->setText( text ); 
    10141103    action->setToolTip( help ); 
     1104 
     1105    action->setEnabled( i_object_id != 0 ); 
    10151106 
    10161107    if( i_item_type == ITEM_CHECK ) 
     
    10261117    } 
    10271118 
    1028     if( checked ) 
    1029     { 
    1030         action->setChecked( true ); 
    1031     } 
     1119    action->setChecked( checked ); 
     1120 
    10321121    MenuItemData *itemData = new MenuItemData( i_object_id, i_val_type, 
    10331122            val, psz_var ); 
  • modules/gui/qt4/menus.hpp

    re00ed66 r5ec2ab6  
    108108    static void CreateAndConnect( QMenu *, const char *, QString, QString, 
    109109                                  int, int, vlc_value_t, int, bool c = false ); 
    110     static void CreateItem( QMenu *, const char *, vlc_object_t *, bool ); 
     110    static void UpdateItem( intf_thread_t *, QMenu *, const char *, 
     111                            vlc_object_t *, bool ); 
    111112    static int CreateChoicesMenu( QMenu *,const char *, vlc_object_t *, bool ); 
    112113}; 
     
    122123        switch( id ) 
    123124        { 
    124         case 1: QVLCMenu::VideoMenu( p_intf, menu ); break; 
    125         case 2: QVLCMenu::AudioMenu( p_intf, menu ); break; 
     125        case 1: QVLCMenu::AudioMenu( p_intf, menu ); break; 
     126        case 2: QVLCMenu::VideoMenu( p_intf, menu ); break; 
    126127        case 3: QVLCMenu::NavigMenu( p_intf, menu ); break; 
    127128        case 4: QVLCMenu::InterfacesMenu( p_intf, menu ); break;