]> git.sesse.net Git - vlc/commitdiff
qt4: rework popupmenus
authorErwan Tulou <erwan10@videolan.org>
Wed, 7 Apr 2010 15:07:41 +0000 (17:07 +0200)
committerErwan Tulou <erwan10@videolan.org>
Wed, 7 Apr 2010 15:52:07 +0000 (17:52 +0200)
This patch
   - ensures no accumulation of QMenus
   - removes the root Widget for dialog_provider
   - unifies all four popupmenus in term of API

For skins, it also fixes bugs when trying to hide popupmenus
(Video, Audio and Misc). These were never implemented at the
 qt4 level, but used at the skins level.

modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/menus.cpp
modules/gui/qt4/menus.hpp
modules/gui/qt4/qt4.cpp
modules/gui/qt4/qt4.hpp

index 9fb00cdc30c029b5c8a70d9cb9bcefdc34b57ba6..13dbbfa86a924d4c4f736f2700162957174b6372 100644 (file)
@@ -83,13 +83,6 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
     CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
 
     new DialogHandler (p_intf, this );
-
-    /* a root widget intended to be the ancestor of all
-       menus/actions created by the dialog_provider methods.
-       At destruction time, deleting this fake widget ensures
-       all child menus/actions are also deleted
-     */
-    root = new QWidget();
 }
 
 DialogsProvider::~DialogsProvider()
@@ -109,7 +102,10 @@ DialogsProvider::~DialogsProvider()
     delete menusUpdateMapper;
     delete SDMapper;
 
-    delete root;
+    QVLCMenu::PopupMenu( p_intf, false );
+    QVLCMenu::AudioPopupMenu( p_intf, false );
+    QVLCMenu::VideoPopupMenu( p_intf, false );
+    QVLCMenu::MiscPopupMenu( p_intf, false );
 }
 
 void DialogsProvider::quit()
@@ -156,13 +152,13 @@ void DialogsProvider::customEvent( QEvent *event )
            vlmDialog(); break;
 #endif
         case INTF_DIALOG_POPUPMENU:
-           QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0), root ); break;
+           QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
         case INTF_DIALOG_AUDIOPOPUPMENU:
-           QVLCMenu::AudioPopupMenu( p_intf, root ); break;
+           QVLCMenu::AudioPopupMenu( p_intf, (de->i_arg != 0) ); break;
         case INTF_DIALOG_VIDEOPOPUPMENU:
-           QVLCMenu::VideoPopupMenu( p_intf, root ); break;
+           QVLCMenu::VideoPopupMenu( p_intf, (de->i_arg != 0) ); break;
         case INTF_DIALOG_MISCPOPUPMENU:
-           QVLCMenu::MiscPopupMenu( p_intf, root ); break;
+           QVLCMenu::MiscPopupMenu( p_intf, (de->i_arg != 0) ); break;
         case INTF_DIALOG_WIZARD:
         case INTF_DIALOG_STREAMWIZARD:
             openAndStreamingDialogs(); break;
index 5991d018fc2aecee691443131af4af6200ba33a4..da1b3fb4a035b288437f1f38694c092ccf0865b2 100644 (file)
@@ -763,16 +763,19 @@ QMenu *QVLCMenu::HelpMenu( QWidget *parent )
  * Popup menus - Right Click menus                                           *
  *****************************************************************************/
 #define POPUP_BOILERPLATE \
+    static QMenu* menu = NULL;  \
+    delete menu; menu = NULL; \
+    if( !show ) \
+        return; \
     unsigned int i_last_separator = 0; \
     vector<vlc_object_t *> objects; \
     vector<const char *> varnames; \
     input_thread_t *p_input = THEMIM->getInput();
 
 #define CREATE_POPUP \
+    menu = new QMenu(); \
     Populate( p_intf, menu, varnames, objects ); \
-    p_intf->p_sys->p_popup_menu = menu; \
     menu->popup( QCursor::pos() ); \
-    p_intf->p_sys->p_popup_menu = NULL; \
     i_last_separator = 0;
 
 void QVLCMenu::PopupPlayEntries( QMenu *menu,
@@ -885,9 +888,9 @@ void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
 }
 
 /* Video Tracks and Subtitles tracks */
-void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, QWidget *parent  )
+void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, bool show )
 {
-    POPUP_BOILERPLATE;
+    POPUP_BOILERPLATE
     if( p_input )
     {
         vout_thread_t *p_vout = THEMIM->getVout();
@@ -897,14 +900,13 @@ void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, QWidget *parent  )
             vlc_object_release( p_vout );
         }
     }
-    QMenu *menu = new QMenu( parent );
-    CREATE_POPUP;
+    CREATE_POPUP
 }
 
 /* Audio Tracks */
-void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, QWidget *parent )
+void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, bool show )
 {
-    POPUP_BOILERPLATE;
+    POPUP_BOILERPLATE
     if( p_input )
     {
         aout_instance_t *p_aout = THEMIM->getAout();
@@ -912,14 +914,13 @@ void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, QWidget *parent )
         if( p_aout )
             vlc_object_release( p_aout );
     }
-    QMenu *menu = new QMenu( parent );
-    CREATE_POPUP;
+    CREATE_POPUP
 }
 
 /* Navigation stuff, and general menus ( open ), used only for skins */
-void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, QWidget *parent )
+void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, bool show )
 {
-    POPUP_BOILERPLATE;
+    POPUP_BOILERPLATE
 
     if( p_input )
     {
@@ -928,7 +929,7 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, QWidget *parent )
         PUSH_SEPARATOR;
     }
 
-    QMenu *menu = new QMenu( parent );
+    menu = new QMenu();
     Populate( p_intf, menu, varnames, objects );
 
     menu->addSeparator();
@@ -941,31 +942,20 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, QWidget *parent )
     menu->addSeparator();
     PopupMenuStaticEntries( menu );
 
-    p_intf->p_sys->p_popup_menu = menu;
     menu->popup( QCursor::pos() );
-    p_intf->p_sys->p_popup_menu = NULL;
 }
 
 /* Main Menu that sticks everything together  */
-void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show, QWidget *parent )
+void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
 {
-    /* Delete old popup if there is one */
-    delete p_intf->p_sys->p_popup_menu;
-
-    if( !show )
-    {
-        p_intf->p_sys->p_popup_menu = NULL;
-        return;
-    }
+    POPUP_BOILERPLATE
 
     /* */
-    QMenu *menu = new QMenu( parent );
+    menu = new QMenu( );
     QAction *action;
     bool b_isFullscreen = false;
     MainInterface *mi = p_intf->p_sys->p_mi;
 
-    POPUP_BOILERPLATE;
-
     PopupPlayEntries( menu, p_intf, p_input );
     PopupMenuPlaylistControlEntries( menu, p_intf );
     menu->addSeparator();
@@ -1056,14 +1046,16 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show, QWidget *parent )
     /* Static entries for ending, like open */
     PopupMenuStaticEntries( menu );
 
-    p_intf->p_sys->p_popup_menu = menu;
-    p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );
+    menu->popup( QCursor::pos() );
 }
 
 #undef ACT_ADD
 #undef ACT_ADDMENU
 #undef ACT_ADDCHECK
 
+#undef CREATE_POPUP
+#undef POPUP_BOILERPLATE
+
 #ifndef HAVE_MAEMO
 /************************************************************************
  * Systray Menu                                                         *
@@ -1073,7 +1065,10 @@ void QVLCMenu::updateSystrayMenu( MainInterface *mi,
                                   intf_thread_t *p_intf,
                                   bool b_force_visible )
 {
-    POPUP_BOILERPLATE;
+    unsigned int i_last_separator = 0;
+    vector<vlc_object_t *> objects;
+    vector<const char *> varnames;
+    input_thread_t *p_input = THEMIM->getInput();
 
     /* Get the systray menu and clean it */
     QMenu *sysMenu = mi->getSysTrayMenu();
@@ -1109,8 +1104,6 @@ void QVLCMenu::updateSystrayMenu( MainInterface *mi,
 }
 #endif
 
-#undef CREATE_POPUP
-#undef POPUP_BOILERPLATE
 
 #undef PUSH_VAR
 #undef PUSH_SEPARATOR
index 1ed42283bede4f44003d4eb4ba39667b04b79e3d..f1d89f218e2b7a4d822be6bbb0bb887cc7afd574 100644 (file)
@@ -79,10 +79,10 @@ public:
     static void createMenuBar( MainInterface *mi, intf_thread_t * );
 
     /* Popups Menus */
-    static void PopupMenu( intf_thread_t *, bool, QWidget * );
-    static void AudioPopupMenu( intf_thread_t *, QWidget * );
-    static void VideoPopupMenu( intf_thread_t *, QWidget * );
-    static void MiscPopupMenu( intf_thread_t *, QWidget * );
+    static void PopupMenu( intf_thread_t *, bool );
+    static void AudioPopupMenu( intf_thread_t *, bool );
+    static void VideoPopupMenu( intf_thread_t *, bool );
+    static void MiscPopupMenu( intf_thread_t *, bool );
 
     /* Systray */
     static void updateSystrayMenu( MainInterface *, intf_thread_t  *,
index 4be129b24856d736998f60bfd030241a4c7d1cd4..fe7ea7d61abffb925248519240c19a637c5bfe60 100644 (file)
@@ -315,7 +315,6 @@ static int Open( vlc_object_t *p_this, bool isDialogProvider )
     /* Allocations of p_sys */
     intf_sys_t *p_sys = p_intf->p_sys = new intf_sys_t;
     p_intf->p_sys->b_isDialogProvider = isDialogProvider;
-    p_sys->p_popup_menu = NULL;
     p_sys->p_mi = NULL;
     p_sys->p_playlist = pl_Get( p_intf );
 
index 15c0a34a276ba8d863af739f2215982d0fdca32d..64f58212b70815b1c5abb2edfcff5cc2f75a1e5c 100644 (file)
@@ -74,7 +74,6 @@ struct intf_sys_t
 
     QString filepath;        /* Last path used in dialogs */
 
-    QMenu * p_popup_menu;    /* The right click menu */
 };
 
 #define THEPL p_intf->p_sys->p_playlist