[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt: use smart pointers to tracks contextual menus from the DialogProvider
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Mon Dec 6 15:31:30 UTC 2021
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
25b908b2 by Pierre Lamot at 2021-12-06T14:40:57+00:00
qt: use smart pointers to tracks contextual menus from the DialogProvider
- - - - -
d9d428c7 by Pierre Lamot at 2021-12-06T14:40:57+00:00
qt: fix resource leak when opening a contextual menu
"View" menu parent was unset that led the menu and the associated resources
being leaked, notably an observer on the "intf-add" variable which asserted on
quit.
- - - - -
62d69bac by Pierre Lamot at 2021-12-06T14:40:57+00:00
qt: remove unused condition while creating "View" menu
VLCMenuBar::ViewMenu is never called without an existing menu
- - - - -
c7685d7c by Pierre Lamot at 2021-12-06T14:40:57+00:00
qt: make menu creation function return void
These functions populate the menu given in parameter and were always returning
it, this made confusing code where the return value was used like a different
menu from the incoming.
- - - - -
d2e59e71 by Pierre Lamot at 2021-12-06T14:40:57+00:00
qt: remove dead code in menus.cpp
- - - - -
4 changed files:
- modules/gui/qt/dialogs/dialogs_provider.cpp
- modules/gui/qt/dialogs/dialogs_provider.hpp
- modules/gui/qt/menus/menus.cpp
- modules/gui/qt/menus/menus.hpp
Changes:
=====================================
modules/gui/qt/dialogs/dialogs_provider.cpp
=====================================
@@ -68,12 +68,8 @@
DialogsProvider* DialogsProvider::instance = NULL;
-DialogsProvider::DialogsProvider( qt_intf_t *_p_intf ) :
- QObject( NULL ), p_intf( _p_intf ),
- popupMenu( NULL ),
- videoPopupMenu( NULL ),
- audioPopupMenu( NULL ),
- miscPopupMenu( NULL )
+DialogsProvider::DialogsProvider( qt_intf_t *_p_intf )
+ : QObject( NULL ), p_intf( _p_intf )
{
b_isDying = false;
}
@@ -101,11 +97,6 @@ DialogsProvider::~DialogsProvider()
ErrorsDialog::killInstance();
FirstRunWizard::killInstance();
- delete popupMenu;
- delete videoPopupMenu;
- delete audioPopupMenu;
- delete miscPopupMenu;
-
/* free parentless menus */
VLCMenuBar::freeRendererMenu();
}
@@ -201,39 +192,39 @@ void DialogsProvider::customEvent( QEvent *event )
#endif
case INTF_DIALOG_POPUPMENU:
{
- delete popupMenu; popupMenu = NULL;
+ popupMenu.reset();
bool show = (de->i_arg != 0);
if( show )
{
//popping a QMenu prevents mouse release events to be received,
//this ensures the coherency of the vout mouse state.
emit releaseMouseEvents();
- popupMenu = VLCMenuBar::PopupMenu( p_intf, true );
+ popupMenu.reset(VLCMenuBar::PopupMenu( p_intf, true ));
}
break;
}
case INTF_DIALOG_AUDIOPOPUPMENU:
{
- delete audioPopupMenu; audioPopupMenu = NULL;
+ audioPopupMenu.reset();
bool show = (de->i_arg != 0);
if( show )
- audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
+ audioPopupMenu.reset(VLCMenuBar::AudioPopupMenu( p_intf, show ));
break;
}
case INTF_DIALOG_VIDEOPOPUPMENU:
{
- delete videoPopupMenu; videoPopupMenu = NULL;
+ videoPopupMenu.reset();
bool show = (de->i_arg != 0);
if( show )
- videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
+ videoPopupMenu.reset(VLCMenuBar::VideoPopupMenu( p_intf, show ));
break;
}
case INTF_DIALOG_MISCPOPUPMENU:
{
- delete miscPopupMenu; miscPopupMenu = NULL;
+ miscPopupMenu.reset();
bool show = (de->i_arg != 0);
if( show )
- miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
+ miscPopupMenu.reset(VLCMenuBar::MiscPopupMenu( p_intf, show ));
break;
}
case INTF_DIALOG_WIZARD:
@@ -404,14 +395,12 @@ void DialogsProvider::epgDialog()
void DialogsProvider::setPopupMenu()
{
- delete popupMenu;
- popupMenu = VLCMenuBar::PopupMenu( p_intf, true );
+ popupMenu.reset(VLCMenuBar::PopupMenu( p_intf, true ));
}
void DialogsProvider::destroyPopupMenu()
{
- delete popupMenu;
- popupMenu = NULL;
+ popupMenu.reset();
}
/* Generic open file */
@@ -873,11 +862,11 @@ void DialogsProvider::sendKey( int key )
// translate from a vlc keycode into a Qt sequence
QKeySequence kseq0( VLCKeyToString( key, true ) );
- if( popupMenu == NULL )
+ if( !popupMenu )
{
// make sure at least a non visible popupmenu is available
- popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
- if( unlikely( popupMenu == NULL ) )
+ popupMenu.reset(VLCMenuBar::PopupMenu( p_intf, false ));
+ if( unlikely( !popupMenu ) )
return;
}
=====================================
modules/gui/qt/dialogs/dialogs_provider.hpp
=====================================
@@ -118,10 +118,10 @@ private:
qt_intf_t *p_intf;
- QMenu* popupMenu;
- QMenu* videoPopupMenu;
- QMenu* audioPopupMenu;
- QMenu* miscPopupMenu;
+ std::unique_ptr<QMenu> popupMenu;
+ std::unique_ptr<QMenu> videoPopupMenu;
+ std::unique_ptr<QMenu> audioPopupMenu;
+ std::unique_ptr<QMenu> miscPopupMenu;
QWidget* root;
bool b_isDying;
=====================================
modules/gui/qt/menus/menus.cpp
=====================================
@@ -171,7 +171,7 @@ VLCMenuBar::VLCMenuBar(QObject* parent)
* Media ( File ) Menu
* Opening, streaming and quit
**/
-QMenu *VLCMenuBar::FileMenu(qt_intf_t *p_intf, QMenu *menu)
+void VLCMenuBar::FileMenu(qt_intf_t *p_intf, QMenu *menu)
{
auto mi = p_intf->p_mi;
QAction *action;
@@ -230,13 +230,12 @@ QMenu *VLCMenuBar::FileMenu(qt_intf_t *p_intf, QMenu *menu)
addDPStaticEntry( menu, qtr( "&Quit" ) ,
":/menu/exit.svg", &DialogsProvider::quit, "Ctrl+Q" );
- return menu;
}
/**
* Tools, like Media Information, Preferences or Messages
**/
-QMenu *VLCMenuBar::ToolsMenu( qt_intf_t *p_intf, QMenu *menu )
+void VLCMenuBar::ToolsMenu( qt_intf_t *p_intf, QMenu *menu )
{
addDPStaticEntry( menu, qtr( "&Effects and Filters"), ":/menu/settings.svg",
&DialogsProvider::extendedDialog, "Ctrl+E" );
@@ -271,8 +270,6 @@ QMenu *VLCMenuBar::ToolsMenu( qt_intf_t *p_intf, QMenu *menu )
addDPStaticEntry( menu, qtr( "&Preferences" ),
":/menu/preferences.svg", &DialogsProvider::prefsDialog, "Ctrl+P", QAction::PreferencesRole );
-
- return menu;
}
/**
@@ -280,32 +277,23 @@ QMenu *VLCMenuBar::ToolsMenu( qt_intf_t *p_intf, QMenu *menu )
* Interface modification, load other interfaces, activate Extensions
* \param current, set to NULL for menu creation, else for menu update
**/
-QMenu *VLCMenuBar::ViewMenu( qt_intf_t *p_intf, QMenu *current )
+void VLCMenuBar::ViewMenu( qt_intf_t *p_intf, QMenu *menu )
{
QAction *action;
- QMenu *menu;
MainCtx *mi = p_intf->p_mi;
assert( mi );
+ assert(menu);
- if( !current )
+ //menu->clear();
+ //HACK menu->clear() does not delete submenus
+ QList<QAction*> actions = menu->actions();
+ foreach( QAction *a, actions )
{
- menu = new QMenu( qtr( "&View" ) );
- menu->setAttribute(Qt::WA_DeleteOnClose);
- }
- else
- {
- menu = current;
- //menu->clear();
- //HACK menu->clear() does not delete submenus
- QList<QAction*> actions = menu->actions();
- foreach( QAction *a, actions )
- {
- QMenu *m = a->menu();
- if( a->parent() == menu ) delete a;
- else menu->removeAction( a );
- if( m && m->parent() == menu ) delete m;
- }
+ QMenu *m = a->menu();
+ if( a->parent() == menu ) delete a;
+ else menu->removeAction( a );
+ if( m && m->parent() == menu ) delete m;
}
action = menu->addAction(
@@ -344,7 +332,7 @@ QMenu *VLCMenuBar::ViewMenu( qt_intf_t *p_intf, QMenu *current )
action->setCheckable( true );
action->setChecked( mi->hasGridView() );
- menu->addMenu( new CheckableListMenu(qtr( "&Color Scheme" ), mi->getColorScheme(), CheckableListMenu::GROUPED, current) );
+ menu->addMenu( new CheckableListMenu(qtr( "&Color Scheme" ), mi->getColorScheme(), CheckableListMenu::GROUPED, menu) );
menu->addSeparator();
@@ -353,20 +341,17 @@ QMenu *VLCMenuBar::ViewMenu( qt_intf_t *p_intf, QMenu *current )
/* Extensions */
ExtensionsMenu( p_intf, menu );
-
- return menu;
}
/**
* Interface Sub-Menu, to list extras interface and skins
**/
-QMenu *VLCMenuBar::InterfacesMenu( qt_intf_t *p_intf, QMenu *current )
+void VLCMenuBar::InterfacesMenu( qt_intf_t *p_intf, QMenu *current )
{
assert(current);
VLCVarChoiceModel* model = new VLCVarChoiceModel(VLC_OBJECT(p_intf->intf), "intf-add", current);
CheckableListMenu* submenu = new CheckableListMenu(qtr("Interfaces"), model, CheckableListMenu::UNGROUPED, current);
current->addMenu(submenu);
- return current;
}
/**
@@ -405,7 +390,7 @@ static inline void VolumeEntries( qt_intf_t *p_intf, QMenu *current )
/**
* Main Audio Menu
**/
-QMenu *VLCMenuBar::AudioMenu( qt_intf_t *p_intf, QMenu * current )
+void VLCMenuBar::AudioMenu( qt_intf_t *p_intf, QMenu * current )
{
if( current->isEmpty() )
{
@@ -429,12 +414,10 @@ QMenu *VLCMenuBar::AudioMenu( qt_intf_t *p_intf, QMenu * current )
current->addMenu( new CheckableListMenu(qtr( "&Visualizations" ), THEMIM->getAudioVisualizations(), CheckableListMenu::GROUPED, current) );
VolumeEntries( p_intf, current );
}
-
- return current;
}
/* Subtitles */
-QMenu *VLCMenuBar::SubtitleMenu( qt_intf_t *p_intf, QMenu *current, bool b_popup )
+void VLCMenuBar::SubtitleMenu( qt_intf_t *p_intf, QMenu *current, bool b_popup )
{
if( current->isEmpty() || b_popup )
{
@@ -443,14 +426,13 @@ QMenu *VLCMenuBar::SubtitleMenu( qt_intf_t *p_intf, QMenu *current, bool b_popup
current->addMenu(new CheckableListMenu(qtr( "Sub &Track" ), THEMIM->getSubtitleTracks(), CheckableListMenu::GROUPED, current));
current->addSeparator();
}
- return current;
}
/**
* Main Video Menu
* Subtitles are part of Video.
**/
-QMenu *VLCMenuBar::VideoMenu( qt_intf_t *p_intf, QMenu *current )
+void VLCMenuBar::VideoMenu( qt_intf_t *p_intf, QMenu *current )
{
if( current->isEmpty() )
{
@@ -482,15 +464,13 @@ QMenu *VLCMenuBar::VideoMenu( qt_intf_t *p_intf, QMenu *current )
connect(snapshotAction, &QAction::triggered, THEMIM, &PlayerController::snapshot);
current->addAction(snapshotAction);
}
-
- return current;
}
/**
* Navigation Menu
* For DVD, MP4, MOV and other chapter based format
**/
-QMenu *VLCMenuBar::NavigMenu( qt_intf_t *p_intf, QMenu *menu )
+void VLCMenuBar::NavigMenu( qt_intf_t *p_intf, QMenu *menu )
{
QAction *action;
QMenu *submenu;
@@ -523,10 +503,10 @@ QMenu *VLCMenuBar::NavigMenu( qt_intf_t *p_intf, QMenu *menu )
PopupMenuControlEntries( menu, p_intf );
- return RebuildNavigMenu( p_intf, menu );
+ RebuildNavigMenu( p_intf, menu );
}
-QMenu *VLCMenuBar::RebuildNavigMenu( qt_intf_t *p_intf, QMenu *menu )
+void VLCMenuBar::RebuildNavigMenu( qt_intf_t *p_intf, QMenu *menu )
{
QAction* action;
@@ -544,14 +524,12 @@ QMenu *VLCMenuBar::RebuildNavigMenu( qt_intf_t *p_intf, QMenu *menu )
#undef ADD_ACTION
PopupMenuPlaylistEntries( menu, p_intf );
-
- return menu;
}
/**
* Help/About Menu
**/
-QMenu *VLCMenuBar::HelpMenu( QMenu *menu )
+void VLCMenuBar::HelpMenu( QMenu *menu )
{
addDPStaticEntry( menu, qtr( "&Help" ) ,
":/menu/help.svg", &DialogsProvider::helpDialog, "F1" );
@@ -562,19 +540,11 @@ QMenu *VLCMenuBar::HelpMenu( QMenu *menu )
menu->addSeparator();
addDPStaticEntry( menu, qfut( I_MENU_ABOUT ), ":/menu/info.svg",
&DialogsProvider::aboutDialog, "Shift+F1", QAction::AboutRole );
- return menu;
}
/*****************************************************************************
* Popup menus - Right Click menus *
*****************************************************************************/
-#define POPUP_BOILERPLATE \
- QMenu* menu;
-
-#define CREATE_POPUP \
- menu = new QMenu(); \
- if( show ) \
- menu->popup( QCursor::pos() ); \
void VLCMenuBar::PopupMenuPlaylistEntries( QMenu *menu, qt_intf_t *p_intf )
{
@@ -699,11 +669,6 @@ void VLCMenuBar::PopupMenuStaticEntries( QMenu *menu )
menu->addMenu( openmenu );
menu->addSeparator();
-#if 0
- QMenu *helpmenu = HelpMenu( menu );
- helpmenu->setTitle( qtr( "Help" ) );
- menu->addMenu( helpmenu );
-#endif
addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/exit.svg",
&DialogsProvider::quit, "Ctrl+Q", QAction::QuitRole );
@@ -756,7 +721,6 @@ QMenu* VLCMenuBar::PopupMenu( qt_intf_t *p_intf, bool show )
input_item_t* p_input = THEMIM->getInput();
QAction *action;
bool b_isFullscreen = false;
- MainCtx *mi = p_intf->p_mi;
PopupMenuPlaylistEntries( menu, p_intf );
menu->addSeparator();
@@ -782,26 +746,30 @@ QMenu* VLCMenuBar::PopupMenu( qt_intf_t *p_intf, bool show )
/* Audio menu */
submenu = new QMenu( menu );
- action = menu->addMenu( AudioMenu( p_intf, submenu ) );
+ AudioMenu( p_intf, submenu );
+ action = menu->addMenu( submenu );
action->setText( qtr( "&Audio" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
/* Video menu */
submenu = new QMenu( menu );
- action = menu->addMenu( VideoMenu( p_intf, submenu ) );
+ VideoMenu( p_intf, submenu );
+ action = menu->addMenu( submenu );
action->setText( qtr( "&Video" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
/* Subtitles menu */
submenu = new QMenu( menu );
- action = menu->addMenu( SubtitleMenu( p_intf, submenu, true ) );
+ SubtitleMenu( p_intf, submenu, true );
+ action = menu->addMenu( submenu );
action->setText( qtr( "Subti&tle") );
/* Playback menu for chapters */
submenu = new QMenu( menu );
- action = menu->addMenu( NavigMenu( p_intf, submenu ) );
+ NavigMenu( p_intf, submenu );
+ action = menu->addMenu( submenu );
action->setText( qtr( "&Playback" ) );
if( action->menu()->isEmpty() )
action->setEnabled( false );
@@ -812,22 +780,14 @@ QMenu* VLCMenuBar::PopupMenu( qt_intf_t *p_intf, bool show )
/* Add some special entries for windowed mode: Interface Menu */
if( !b_isFullscreen )
{
- QMenu *submenu = new QMenu( qtr( "Tool&s" ), menu );
- /*QMenu *tools =*/ ToolsMenu( p_intf, submenu );
- submenu->addSeparator();
-
- if( mi )
- {
- QMenu* viewMenu = ViewMenu( p_intf, NULL );
- viewMenu->setTitle( qtr( "V&iew" ) );
- submenu->addMenu( viewMenu );
- }
-
- /* In skins interface, append some items */
if( p_intf->b_isDialogProvider )
{
+ // same as Tool menu but with extra entries
+ QMenu* submenu = new QMenu( qtr( "Interface" ), menu );
+ ToolsMenu( p_intf, submenu );
+ submenu->addSeparator();
+
vlc_object_t* p_object = vlc_object_parent(p_intf->intf);
- submenu->setTitle( qtr( "Interface" ) );
/* Open skin dialog box */
if (var_Type(p_object, "intf-skins-interactive") & VLC_VAR_ISCOMMAND)
@@ -848,22 +808,33 @@ QMenu* VLCMenuBar::PopupMenu( qt_intf_t *p_intf, bool show )
/* list of extensions */
ExtensionsMenu( p_intf, submenu );
+
+ menu->addMenu( submenu );
}
+ else
+ {
+ QMenu* toolsMenu = new QMenu( qtr( "Tool&s" ), menu );
+ ToolsMenu( p_intf, toolsMenu );
+ menu->addMenu( toolsMenu );
- menu->addMenu( submenu );
+ QMenu* viewMenu = new QMenu( qtr( "V&iew" ), menu );
+ ViewMenu( p_intf, viewMenu );
+ menu->addMenu( viewMenu );
+ }
}
/* Static entries for ending, like open */
if( p_intf->b_isDialogProvider )
{
- QMenu *openmenu = FileMenu( p_intf, menu );
- openmenu->setTitle( qtr( "Open Media" ) );
+
+ QMenu* openmenu = new QMenu( qtr( "Open Media" ), menu );
+ FileMenu( p_intf, openmenu );
menu->addMenu( openmenu );
menu->addSeparator();
- QMenu *helpmenu = HelpMenu( menu );
- helpmenu->setTitle( qtr( "Help" ) );
+ QMenu* helpmenu = new QMenu( qtr( "Help" ), menu );
+ HelpMenu( helpmenu );
menu->addMenu( helpmenu );
addDPStaticEntry( menu, qtr( "Quit" ), ":/menu/exit.svg",
@@ -877,10 +848,6 @@ QMenu* VLCMenuBar::PopupMenu( qt_intf_t *p_intf, bool show )
return menu;
}
-#undef CREATE_POPUP
-#undef POPUP_BOILERPLATE
-#undef BAR_DADD
-
/************************************************************************
* Systray Menu *
************************************************************************/
=====================================
modules/gui/qt/menus/menus.hpp
=====================================
@@ -57,26 +57,26 @@ public:
protected:
/* All main Menus */
- static QMenu *FileMenu( qt_intf_t *, QMenu * );
+ static void FileMenu( qt_intf_t *, QMenu * );
- static QMenu *ToolsMenu( qt_intf_t *, QMenu * );
+ static void ToolsMenu( qt_intf_t *, QMenu * );
- static QMenu *ViewMenu( qt_intf_t *, QMenu *);
+ static void ViewMenu( qt_intf_t *, QMenu *);
- static QMenu *InterfacesMenu( qt_intf_t *p_intf, QMenu * );
+ static void InterfacesMenu( qt_intf_t *p_intf, QMenu * );
static void ExtensionsMenu( qt_intf_t *p_intf, QMenu * );
- static QMenu *NavigMenu( qt_intf_t *, QMenu * );
+ static void NavigMenu( qt_intf_t *, QMenu * );
- static QMenu *RebuildNavigMenu(qt_intf_t *, QMenu *);
+ static void RebuildNavigMenu(qt_intf_t *, QMenu *);
- static QMenu *VideoMenu( qt_intf_t *, QMenu * );
+ static void VideoMenu( qt_intf_t *, QMenu * );
- static QMenu *SubtitleMenu( qt_intf_t *, QMenu *current, bool b_popup = false );
+ static void SubtitleMenu( qt_intf_t *, QMenu *current, bool b_popup = false );
- static QMenu *AudioMenu( qt_intf_t *, QMenu * );
+ static void AudioMenu( qt_intf_t *, QMenu * );
- static QMenu *HelpMenu( QMenu *menu );
+ static void HelpMenu( QMenu *menu );
/* Popups Menus */
static void PopupMenuStaticEntries( QMenu *menu );
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b1e3ca3b0f7a1de47cf4a914cf47a7f0dd0cd60e...d2e59e71553fba1b7aa8e2587f385bb966a3067f
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b1e3ca3b0f7a1de47cf4a914cf47a7f0dd0cd60e...d2e59e71553fba1b7aa8e2587f385bb966a3067f
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list