Commit 8d8bd806 authored by Erwan Tulou's avatar Erwan Tulou

qt4: Don't create QMenu without parents

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 193e6eac where
     some vlc objects were no longer properly released for lack
     of a clean menus/actions release chain.
parent c9742171
......@@ -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();
}
......
......@@ -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 )
......
......@@ -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;
......
......@@ -130,6 +130,7 @@ private:
static DialogsProvider *instance;
intf_thread_t *p_intf;
QWidget* root;
bool b_isDying;
void openDialog( int );
......
......@@ -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()
......
......@@ -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;
......
......@@ -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 *,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment