]> git.sesse.net Git - vlc/commitdiff
qt4: Don't create QMenu without parents
authorErwan Tulou <erwan10@videolan.org>
Tue, 6 Apr 2010 14:40:11 +0000 (16:40 +0200)
committerErwan Tulou <erwan10@videolan.org>
Tue, 6 Apr 2010 14:54:06 +0000 (16:54 +0200)
This patch ensures that _all_ menus/actions have got a parent widget that
is guaranteed to be deleted.

This patch
   - solves memory leaks for menus and action(children)
   - solves a side effect (crash) pointed out
     by 193e6eacddb63e8a5bda42395ee79b5b27db6408 where
     some vlc objects were no longer properly released for lack
     of a clean menus/actions release chain.

modules/gui/qt4/components/interface_widgets.cpp
modules/gui/qt4/components/playlist/standardpanel.cpp
modules/gui/qt4/dialogs_provider.cpp
modules/gui/qt4/dialogs_provider.hpp
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/menus.cpp
modules/gui/qt4/menus.hpp

index ce17b9d7f1abe0f4f6531eb09f0b78059eaa7326..29ce6bddec1d67477aea9f33a97250e28104d98f 100644 (file)
@@ -356,7 +356,7 @@ void BackgroundWidget::paintEvent( QPaintEvent *e )
 
 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
 {
-    QVLCMenu::PopupMenu( p_intf, true );
+    QVLCMenu::PopupMenu( p_intf, true, this );
     event->accept();
 }
 
index 6dcf065576c105c913d93277ee2f655153db3ba0..64b5920a34fb210106a01302860f9ac3be6dcf73 100644 (file)
@@ -174,7 +174,7 @@ void StandardPLPanel::popupPlView( const QPoint &point )
     QModelIndexList list = selection->selectedIndexes();
 
     if( !model->popup( index, globalPoint, list ) )
-        QVLCMenu::PopupMenu( p_intf, true );
+        QVLCMenu::PopupMenu( p_intf, true, this );
 }
 
 void StandardPLPanel::popupSelectColumn( QPoint pos )
index 0c6cfdf81c2a1b347c6088d89523d9a09bc7c291..9fb00cdc30c029b5c8a70d9cb9bcefdc34b57ba6 100644 (file)
@@ -83,6 +83,13 @@ 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()
@@ -101,6 +108,8 @@ DialogsProvider::~DialogsProvider()
     delete menusMapper;
     delete menusUpdateMapper;
     delete SDMapper;
+
+    delete root;
 }
 
 void DialogsProvider::quit()
@@ -147,13 +156,13 @@ void DialogsProvider::customEvent( QEvent *event )
            vlmDialog(); break;
 #endif
         case INTF_DIALOG_POPUPMENU:
-           QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
+           QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0), root ); break;
         case INTF_DIALOG_AUDIOPOPUPMENU:
-           QVLCMenu::AudioPopupMenu( p_intf ); break;
+           QVLCMenu::AudioPopupMenu( p_intf, root ); break;
         case INTF_DIALOG_VIDEOPOPUPMENU:
-           QVLCMenu::VideoPopupMenu( p_intf ); break;
+           QVLCMenu::VideoPopupMenu( p_intf, root ); break;
         case INTF_DIALOG_MISCPOPUPMENU:
-           QVLCMenu::MiscPopupMenu( p_intf ); break;
+           QVLCMenu::MiscPopupMenu( p_intf, root ); break;
         case INTF_DIALOG_WIZARD:
         case INTF_DIALOG_STREAMWIZARD:
             openAndStreamingDialogs(); break;
index 8bf708edd564b58219a369a543d3dcade8dea71c..60f1dd8f43c6fd22e6ee33ef6305d4aee86c80fc 100644 (file)
@@ -130,6 +130,7 @@ private:
     static DialogsProvider *instance;
 
     intf_thread_t *p_intf;
+    QWidget* root;
     bool b_isDying;
 
     void openDialog( int );
index 6cba05f53cd5113008815615e2d9a23c04f9131e..13c4555715d8485ba6bf9f04c38ac8bb55c7bec6 100644 (file)
@@ -526,12 +526,12 @@ inline void MainInterface::restoreStackOldWidget()
 
 void MainInterface::destroyPopupMenu()
 {
-    QVLCMenu::PopupMenu( p_intf, false );
+    QVLCMenu::PopupMenu( p_intf, false, this );
 }
 
 void MainInterface::popupMenu( const QPoint &p )
 {
-    QVLCMenu::PopupMenu( p_intf, true );
+    QVLCMenu::PopupMenu( p_intf, true, this );
 }
 
 void MainInterface::toggleFSC()
index b0f42644d30ae5242d9a9567d30cd31cb1e2df18..5991d018fc2aecee691443131af4af6200ba33a4 100644 (file)
@@ -423,9 +423,12 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface
     QAction *action;
     QMenu *menu;
 
+    MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
+    assert( mi );
+
     if( !current )
     {
-        menu = new QMenu( qtr( "&View" ) );
+        menu = new QMenu( qtr( "&View" ), mi );
     }
     else
     {
@@ -442,9 +445,6 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface
         }
     }
 
-    MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
-    assert( mi );
-
     menu->addAction( QIcon( ":/menu/playlist_menu" ),
             qtr( "Play&list" ), mi,
             SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
@@ -885,7 +885,7 @@ void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
 }
 
 /* Video Tracks and Subtitles tracks */
-void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
+void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, QWidget *parent  )
 {
     POPUP_BOILERPLATE;
     if( p_input )
@@ -897,12 +897,12 @@ void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
             vlc_object_release( p_vout );
         }
     }
-    QMenu *menu = new QMenu();
+    QMenu *menu = new QMenu( parent );
     CREATE_POPUP;
 }
 
 /* Audio Tracks */
-void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
+void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, QWidget *parent )
 {
     POPUP_BOILERPLATE;
     if( p_input )
@@ -912,12 +912,12 @@ void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
         if( p_aout )
             vlc_object_release( p_aout );
     }
-    QMenu *menu = new QMenu();
+    QMenu *menu = new QMenu( parent );
     CREATE_POPUP;
 }
 
 /* Navigation stuff, and general menus ( open ), used only for skins */
-void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
+void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, QWidget *parent )
 {
     POPUP_BOILERPLATE;
 
@@ -928,7 +928,7 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
         PUSH_SEPARATOR;
     }
 
-    QMenu *menu = new QMenu();
+    QMenu *menu = new QMenu( parent );
     Populate( p_intf, menu, varnames, objects );
 
     menu->addSeparator();
@@ -947,7 +947,7 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
 }
 
 /* Main Menu that sticks everything together  */
-void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
+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;
@@ -959,7 +959,7 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
     }
 
     /* */
-    QMenu *menu = new QMenu();
+    QMenu *menu = new QMenu( parent );
     QAction *action;
     bool b_isFullscreen = false;
     MainInterface *mi = p_intf->p_sys->p_mi;
index 4a022ce884a9690f141f7cf4d225ab31b6edeea5..1ed42283bede4f44003d4eb4ba39667b04b79e3d 100644 (file)
@@ -79,10 +79,10 @@ public:
     static void createMenuBar( MainInterface *mi, intf_thread_t * );
 
     /* Popups Menus */
-    static void PopupMenu( intf_thread_t *, bool );
-    static void AudioPopupMenu( intf_thread_t * );
-    static void VideoPopupMenu( intf_thread_t * );
-    static void MiscPopupMenu( intf_thread_t * );
+    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 * );
 
     /* Systray */
     static void updateSystrayMenu( MainInterface *, intf_thread_t  *,