From d401d749a4f5d5de9fcf45e429d46e9b3f95fb8f Mon Sep 17 00:00:00 2001
From: Erwan Tulou <erwan10@videolan.org>
Date: Wed, 7 Apr 2010 14:46:24 +0200
Subject: [PATCH] qt4: reimplement p_popup_menu (to really prevent accumulation of QMenus)

This variable as implemented today fails to do what it is intended for

This patch does the following :
    - remove this p_popup_menu variable
    - add a static local variable to track QMenu
      and ensure that a previous instance is deleted before creating
      a new one for all 4 independent popupmenus
      (PopupMenu, VideoPopupMenu, AudioPopupMenu and MiscPopupMenu)
---
 modules/gui/qt4/menus.cpp |   34 ++++++++++++----------------------
 modules/gui/qt4/qt4.cpp   |    1 -
 modules/gui/qt4/qt4.hpp   |    1 -
 3 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index 5991d01..651c1e7 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -763,16 +763,17 @@ QMenu *QVLCMenu::HelpMenu( QWidget *parent )
  * Popup menus - Right Click menus                                           *
  *****************************************************************************/
 #define POPUP_BOILERPLATE \
+    static QMenu* menu = NULL;  \
+    delete menu; menu = NULL; \
     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( parent ); \
     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,
@@ -887,7 +888,7 @@ void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
 /* Video Tracks and Subtitles tracks */
 void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, QWidget *parent  )
 {
-    POPUP_BOILERPLATE;
+    POPUP_BOILERPLATE
     if( p_input )
     {
         vout_thread_t *p_vout = THEMIM->getVout();
@@ -897,14 +898,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 )
 {
-    POPUP_BOILERPLATE;
+    POPUP_BOILERPLATE
     if( p_input )
     {
         aout_instance_t *p_aout = THEMIM->getAout();
@@ -912,14 +912,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 )
 {
-    POPUP_BOILERPLATE;
+    POPUP_BOILERPLATE
 
     if( p_input )
     {
@@ -928,7 +927,7 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, QWidget *parent )
         PUSH_SEPARATOR;
     }
 
-    QMenu *menu = new QMenu( parent );
+    menu = new QMenu( parent );
     Populate( p_intf, menu, varnames, objects );
 
     menu->addSeparator();
@@ -941,31 +940,23 @@ 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 )
 {
-    /* Delete old popup if there is one */
-    delete p_intf->p_sys->p_popup_menu;
+    POPUP_BOILERPLATE
 
     if( !show )
-    {
-        p_intf->p_sys->p_popup_menu = NULL;
         return;
-    }
 
     /* */
-    QMenu *menu = new QMenu( parent );
+    menu = new QMenu( parent );
     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,8 +1047,7 @@ 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
diff --git a/modules/gui/qt4/qt4.cpp b/modules/gui/qt4/qt4.cpp
index 4be129b..fe7ea7d 100644
--- a/modules/gui/qt4/qt4.cpp
+++ b/modules/gui/qt4/qt4.cpp
@@ -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 );
 
diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp
index 15c0a34..64f5821 100644
--- a/modules/gui/qt4/qt4.hpp
+++ b/modules/gui/qt4/qt4.hpp
@@ -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
-- 
1.5.6.5

