Commit 67c51e4b authored by Jean-Philippe André's avatar Jean-Philippe André

Qt/Menu: ViewMenu is now dynamic (uses aboutToShow)

parent 1ce616c7
...@@ -294,7 +294,7 @@ void QVLCMenu::createMenuBar( MainInterface *mi, ...@@ -294,7 +294,7 @@ void QVLCMenu::createMenuBar( MainInterface *mi,
BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 ); BAR_DADD( VideoMenu( p_intf, bar ), qtr( "&Video" ), 2 );
BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) ); BAR_ADD( ToolsMenu( bar ), qtr( "&Tools" ) );
BAR_ADD( ViewMenu( p_intf, mi ), qtr( "V&iew" ) ); BAR_ADD( ViewMenu( p_intf, bar ), qtr( "V&iew" ) );
BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) ); BAR_ADD( HelpMenu( bar ), qtr( "&Help" ) );
} }
#undef BAR_ADD #undef BAR_ADD
...@@ -397,19 +397,40 @@ QMenu *QVLCMenu::ToolsMenu( QWidget *parent ) ...@@ -397,19 +397,40 @@ QMenu *QVLCMenu::ToolsMenu( QWidget *parent )
return ToolsMenu( new QMenu( parent ) ); return ToolsMenu( new QMenu( parent ) );
} }
/**
* Dynamic View Menu
* Connect signal "aboutToShow" to the creation of the View Menu
**/
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QWidget* parent )
{
QMenu *viewMenu = new QMenu( parent );
MenuFunc *f = new MenuFunc( viewMenu, 4 );
CONNECT( viewMenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
THEDP->menusUpdateMapper->setMapping( viewMenu, f );
return viewMenu;
}
/** /**
* View Menu * View Menu
* Interface Modification * Interface modification, load other interfaces, activate Extensions
**/ **/
QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
MainInterface *mi, QMenu *current,
bool with_intf ) bool with_intf )
{ {
QAction *action; QAction *action;
assert( mi ); QMenu *menu;
if( !with_intf )
menu = new QMenu( qtr( "&View" ), current );
else
{
menu = current;
menu->clear();
}
QMenu *menu = new QMenu( qtr( "V&iew" ), mi ); MainInterface *mi = p_intf->p_sys->p_mi;
assert( mi );
menu->addAction( QIcon( ":/menu/playlist_menu" ), menu->addAction( QIcon( ":/menu/playlist_menu" ),
qtr( "Play&list" ), mi, qtr( "Play&list" ), mi,
...@@ -424,9 +445,6 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, ...@@ -424,9 +445,6 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
if( with_intf ) if( with_intf )
{ {
QMenu *intfmenu = InterfacesMenu( p_intf, menu ); QMenu *intfmenu = InterfacesMenu( p_intf, menu );
MenuFunc *f = new MenuFunc( intfmenu, 4 );
CONNECT( intfmenu, aboutToShow(), THEDP->menusUpdateMapper, map() );
THEDP->menusUpdateMapper->setMapping( intfmenu, f );
menu->addSeparator(); menu->addSeparator();
} }
...@@ -473,14 +491,11 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, ...@@ -473,14 +491,11 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf,
menu->addSeparator(); menu->addSeparator();
addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ), addDPStaticEntry( menu, qtr( "Customi&ze Interface..." ),
":/menu/preferences", SLOT( toolbarDialog() ) ); ":/menu/preferences", SLOT( toolbarDialog() ) );
menu->addSeparator();
/* Extensions */ /* Extensions */
/// @todo Check configuration variable "auto load extensions"
menu->addSeparator(); menu->addSeparator();
QMenu *extmenu = ExtensionsMenu( p_intf, menu ); ExtensionsMenu( p_intf, menu );
MenuFunc *f = new MenuFunc( menu, 5 );
CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() );
THEDP->menusUpdateMapper->setMapping( menu, f );
return menu; return menu;
} }
...@@ -499,41 +514,19 @@ QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current ) ...@@ -499,41 +514,19 @@ QMenu *QVLCMenu::InterfacesMenu( intf_thread_t *p_intf, QMenu *current )
} }
/** /**
* Extensions Sub-Menu * Extensions menu: populate the current menu with extensions
* EXPERIMENTAL
**/ **/
QMenu *QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *current ) void QVLCMenu::ExtensionsMenu( intf_thread_t *p_intf, QMenu *extMenu )
{ {
QAction *extAction = NULL; /* Get ExtensionsManager and load extensions if needed */
foreach( QAction *action, current->actions() )
{
if( action->text() == qtr( "&Extensions" ) )
{
extAction = action;
break;
}
}
ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf ); ExtensionsManager *extMgr = ExtensionsManager::getInstance( p_intf );
if( !extMgr->isLoaded() && !extMgr->cannotLoad() )
QMenu *extMenu = new QMenu( qtr( "&Extensions" ), current );
if( extMgr->isLoaded() )
{
/* Let the ExtensionsManager build itself the menu */
extMgr->menu( extMenu );
}
else
{ {
extMenu->addAction( qtr( "&Load extensions" ), extMgr->loadExtensions();
extMgr, SLOT( loadExtensions() ) );
} }
if( extAction ) /* Let the ExtensionsManager build itself the menu */
extAction->setMenu( extMenu ); extMgr->menu( extMenu );
else
current->addMenu( extMenu );
return extMenu;
} }
/** /**
...@@ -1035,7 +1028,7 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show ) ...@@ -1035,7 +1028,7 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
msg_Warn( p_intf, "could not find parent interface" ); msg_Warn( p_intf, "could not find parent interface" );
} }
else else
menu->addMenu( ViewMenu( p_intf, mi, false )); menu->addMenu( ViewMenu( p_intf, menu, false ));
menu->addMenu( submenu ); menu->addMenu( submenu );
} }
......
...@@ -106,10 +106,11 @@ private: ...@@ -106,10 +106,11 @@ private:
static QMenu *ToolsMenu( QMenu * ); static QMenu *ToolsMenu( QMenu * );
static QMenu *ToolsMenu( QWidget * ); static QMenu *ToolsMenu( QWidget * );
static QMenu *ViewMenu( intf_thread_t *, MainInterface *, static QMenu *ViewMenu( intf_thread_t *, QWidget *parent );
bool with = true ); static QMenu *ViewMenu( intf_thread_t *, QMenu *, bool with_intf );
static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * ); static QMenu *InterfacesMenu( intf_thread_t *p_intf, QMenu * );
static QMenu *ExtensionsMenu( intf_thread_t *p_intf, QMenu * ); static void ExtensionsMenu( intf_thread_t *p_intf, QMenu * );
static QMenu *NavigMenu( intf_thread_t *, QMenu * ); static QMenu *NavigMenu( intf_thread_t *, QMenu * );
static QMenu *NavigMenu( intf_thread_t *, QWidget * ); static QMenu *NavigMenu( intf_thread_t *, QWidget * );
...@@ -163,8 +164,7 @@ public: ...@@ -163,8 +164,7 @@ public:
case 1: QVLCMenu::AudioMenu( p_intf, menu ); break; case 1: QVLCMenu::AudioMenu( p_intf, menu ); break;
case 2: QVLCMenu::VideoMenu( p_intf, menu ); break; case 2: QVLCMenu::VideoMenu( p_intf, menu ); break;
case 3: QVLCMenu::RebuildNavigMenu( p_intf, menu ); break; case 3: QVLCMenu::RebuildNavigMenu( p_intf, menu ); break;
case 4: QVLCMenu::InterfacesMenu( p_intf, menu ); break; case 4: QVLCMenu::ViewMenu( p_intf, menu, true ); break;
case 5: QVLCMenu::ExtensionsMenu( p_intf, menu ); break;
} }
} }
private: private:
......
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