[vlc-devel] commit: Qt menu: fix navigation, delete non static entries ( Jean-Philippe Andre )

git version control git at videolan.org
Tue Jun 17 05:36:13 CEST 2008


vlc | branch: master | Jean-Philippe Andre <jpeg at via.ecp.fr> | Mon Jun 16 21:05:41 2008 +0200| [68b2161a58257620fce16fb034b6fd16f0294694]

Qt menu: fix navigation, delete non static entries

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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=68b2161a58257620fce16fb034b6fd16f0294694
---

 modules/gui/qt4/menus.cpp |   65 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index 7c4ec1e..605595b 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -113,6 +113,24 @@ void EnableDPStaticEntries( QMenu *menu, bool enable = true )
     }
 }
 
+/**
+ * \return Number of static entries
+ */
+int DeleteNonStaticEntries( QMenu *menu )
+{
+    int i_ret = 0;
+    QAction *action;
+    if( !menu )
+        return VLC_EGENERIC;
+    Q_FOREACH( action, menu->actions() )
+    {
+        if( action->data().toString() != "_static_" )
+            delete action;
+        else
+            i_ret++;
+    }
+}
+
 /*****************************************************************************
  * Definitions of variables for the dynamic menus
  *****************************************************************************/
@@ -460,8 +478,9 @@ QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
         QMenu *submenu = new QMenu( qtr( "&Subtitles Track" ), current );
         action = current->addMenu( submenu );
         action->setData( "spu-es" );
-        submenu->addAction( qfu( "Load File..." ), THEDP,
-                            SLOT( loadSubtitlesFile() ) );
+        action =  submenu->addAction( qfu( "Load File..." ), THEDP,
+                                      SLOT( loadSubtitlesFile() ) );
+        action->setData( "_static_" );
 
         ACT_ADD( current, "fullscreen", qtr( "&Fullscreen" ) );
         ACT_ADD( current, "zoom", qtr( "&Zoom" ) );
@@ -503,9 +522,19 @@ QMenu *QVLCMenu::NavigMenu( intf_thread_t *p_intf, QMenu *menu )
     if( !menu )
     {
         menu = new QMenu();
+    }
+
+    if( menu->isEmpty() )
+    {
         addDPStaticEntry( menu, qtr( I_MENU_GOTOTIME ), "","",
                           SLOT( gotoTimeDialog() ), "Ctrl+T" );
         menu->addSeparator();
+
+        ACT_ADD( menu, "bookmark", qtr( "&Bookmarks" ) );
+        ACT_ADD( menu, "title", qtr( "&Title" ) );
+        ACT_ADD( menu, "chapter", qtr( "&Chapter" ) );
+        ACT_ADD( menu, "program", qtr( "&Program" ) );
+        ACT_ADD( menu, "navigation", qtr( "&Navigation" ) );
     }
 
     p_object = ( vlc_object_t * )vlc_object_find( p_intf, VLC_OBJECT_INPUT,
@@ -858,15 +887,6 @@ QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,
             }
         }
 
-        /* Some specific stuff */
-        if( p_object && !strcmp( varnames[i], "spu-es" ) )
-        {
-            vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_object,
-                                        VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
-            if( !p_vout )
-                continue;
-        }
-
         /* Ugly specific stuff */
         if( strstr( varnames[i], "intf-add" ) )
             UpdateItem( p_intf, menu, varnames[i], p_object, false );
@@ -934,11 +954,12 @@ void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
     vlc_value_t val, text;
     int i_type;
 
+    QAction *action = FindActionWithVar( menu, psz_var );
+    if( action )
+        DeleteNonStaticEntries( action->menu() );
+
     if( !p_object )
-    {
-        /* Nothing to do */
         return;
-    }
 
     /* Check the type of the object variable */
     if( !strcmp( psz_var, "audio-es" )
@@ -972,7 +993,6 @@ void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
         text.psz_string = NULL;
     }
 
-    QAction *action = FindActionWithVar( menu, psz_var );
     if( !action )
     {
         action = new QAction( TEXT_OR_VAR, menu );
@@ -980,6 +1000,17 @@ void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
         action->setData( psz_var );
     }
 
+    /* Some specific stuff */
+    bool forceDisabled = false;
+    if( !strcmp( psz_var, "spu-es" ) )
+    {
+        vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,
+                                    VLC_OBJECT_VOUT, FIND_ANYWHERE ) );
+        forceDisabled = ( p_vout == NULL );
+        if( p_vout )
+            vlc_object_release( p_vout );
+    }
+
     if( i_type & VLC_VAR_HASCHOICE )
     {
         /* Append choices menu */
@@ -994,7 +1025,9 @@ void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,
             }
 
             action->setEnabled(
-                   CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
+               CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );
+            if( forceDisabled )
+                action->setEnabled( false );
         }
         else
             CreateChoicesMenu( menu, psz_var, p_object, true );




More information about the vlc-devel mailing list