Commit 01f2d198 authored by Erwan Tulou's avatar Erwan Tulou

Qt(Dialog provider): Add support for key accelerators

parent cfedc940
......@@ -172,6 +172,7 @@ typedef enum vlc_dialog {
INTF_DIALOG_FILE_GENERIC = 30,
INTF_DIALOG_INTERACTION = 50,
INTF_DIALOG_SENDKEY = 51,
INTF_DIALOG_UPDATEVLC = 90,
INTF_DIALOG_VLM,
......
......@@ -34,6 +34,7 @@
#include "menus.hpp"
#include "recents.hpp"
#include "util/qt_dirs.hpp"
#include "util/customwidgets.hpp" /* VLCKeyToString() */
#include "main_interface.hpp"
/* The dialogs */
......@@ -68,7 +69,11 @@
DialogsProvider* DialogsProvider::instance = NULL;
DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
QObject( NULL ), p_intf( _p_intf )
QObject( NULL ), p_intf( _p_intf ),
popupMenu( NULL ),
videoPopupMenu( NULL ),
audioPopupMenu( NULL ),
miscPopupMenu( NULL )
{
b_isDying = false;
......@@ -103,10 +108,10 @@ DialogsProvider::~DialogsProvider()
delete menusUpdateMapper;
delete SDMapper;
VLCMenuBar::PopupMenu( p_intf, false );
VLCMenuBar::AudioPopupMenu( p_intf, false );
VLCMenuBar::VideoPopupMenu( p_intf, false );
VLCMenuBar::MiscPopupMenu( p_intf, false );
delete popupMenu;
delete videoPopupMenu;
delete audioPopupMenu;
delete miscPopupMenu;
}
void DialogsProvider::quit()
......@@ -148,18 +153,44 @@ void DialogsProvider::customEvent( QEvent *event )
bookmarksDialog(); break;
case INTF_DIALOG_EXTENDED:
extendedDialog(); break;
case INTF_DIALOG_SENDKEY:
sendKey( de->i_arg ); break;
#ifdef ENABLE_VLM
case INTF_DIALOG_VLM:
vlmDialog(); break;
#endif
case INTF_DIALOG_POPUPMENU:
VLCMenuBar::PopupMenu( p_intf, (de->i_arg != 0) ); break;
{
delete popupMenu; popupMenu = NULL;
bool show = (de->i_arg != 0);
if( show )
popupMenu = VLCMenuBar::PopupMenu( p_intf, show );
break;
}
case INTF_DIALOG_AUDIOPOPUPMENU:
VLCMenuBar::AudioPopupMenu( p_intf, (de->i_arg != 0) ); break;
{
delete audioPopupMenu; audioPopupMenu = NULL;
bool show = (de->i_arg != 0);
if( show )
audioPopupMenu = VLCMenuBar::AudioPopupMenu( p_intf, show );
break;
}
case INTF_DIALOG_VIDEOPOPUPMENU:
VLCMenuBar::VideoPopupMenu( p_intf, (de->i_arg != 0) ); break;
{
delete videoPopupMenu; videoPopupMenu = NULL;
bool show = (de->i_arg != 0);
if( show )
videoPopupMenu = VLCMenuBar::VideoPopupMenu( p_intf, show );
break;
}
case INTF_DIALOG_MISCPOPUPMENU:
VLCMenuBar::MiscPopupMenu( p_intf, (de->i_arg != 0) ); break;
{
delete miscPopupMenu; miscPopupMenu = NULL;
bool show = (de->i_arg != 0);
if( show )
miscPopupMenu = VLCMenuBar::MiscPopupMenu( p_intf, show );
break;
}
case INTF_DIALOG_WIZARD:
case INTF_DIALOG_STREAMWIZARD:
openAndStreamingDialogs(); break;
......@@ -760,3 +791,32 @@ void DialogsProvider::SDMenuAction( const QString& data )
playlist_ServicesDiscoveryRemove( THEPL, qtu( data ) );
}
void DialogsProvider::sendKey( int key )
{
// translate from a vlc keycode into a Qt sequence
QKeySequence kseq0( VLCKeyToString( key, true ) );
if( popupMenu == NULL )
{
// make sure at least a non visible popupmenu is available
popupMenu = VLCMenuBar::PopupMenu( p_intf, false );
if( unlikely( popupMenu == NULL ) )
return;
}
// test against key accelerators from the popupmenu
QList<QAction*> actions = popupMenu->findChildren<QAction*>();
for( int i = 0; i < actions.size(); i++ )
{
QAction* action = actions.at(i);
QKeySequence kseq = action->shortcut();
if( kseq == kseq0 )
{
action->trigger();
return;
}
}
// forward key to vlc core when not a key accelerator
var_SetInteger( p_intf->p_libvlc, "key-pressed", key );
}
......@@ -104,6 +104,12 @@ private:
static DialogsProvider *instance;
intf_thread_t *p_intf;
QMenu* popupMenu;
QMenu* videoPopupMenu;
QMenu* audioPopupMenu;
QMenu* miscPopupMenu;
QWidget* root;
bool b_isDying;
......@@ -120,6 +126,7 @@ public slots:
void extendedDialog();
void synchroDialog();
void messagesDialog();
void sendKey( int key );
#ifdef ENABLE_VLM
void vlmDialog();
#endif
......
......@@ -396,7 +396,7 @@ QMenu *VLCMenuBar::FileMenu( intf_thread_t *p_intf, QWidget *parent, MainInterfa
action->setCheckable( true );
action->setChecked( THEMIM->getPlayExitState() );
if( mi->getSysTray() )
if( mi && mi->getSysTray() )
{
action = menu->addAction( qtr( "Close to systray"), mi,
SLOT( toggleUpdateSystrayMenu() ) );
......@@ -786,10 +786,7 @@ QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
* Popup menus - Right Click menus *
*****************************************************************************/
#define POPUP_BOILERPLATE \
static QMenu* menu = NULL; \
delete menu; menu = NULL; \
if( !show ) \
return; \
QMenu* menu; \
QVector<vlc_object_t *> objects; \
QVector<const char *> varnames; \
input_thread_t *p_input = THEMIM->getInput();
......@@ -797,7 +794,8 @@ QMenu *VLCMenuBar::HelpMenu( QWidget *parent )
#define CREATE_POPUP \
menu = new QMenu(); \
Populate( p_intf, menu, varnames, objects ); \
menu->popup( QCursor::pos() ); \
if( show ) \
menu->popup( QCursor::pos() ); \
void VLCMenuBar::PopupMenuPlaylistEntries( QMenu *menu,
intf_thread_t *p_intf,
......@@ -944,25 +942,27 @@ void VLCMenuBar::PopupMenuStaticEntries( QMenu *menu )
}
/* Video Tracks and Subtitles tracks */
void VLCMenuBar::VideoPopupMenu( intf_thread_t *p_intf, bool show )
QMenu* VLCMenuBar::VideoPopupMenu( intf_thread_t *p_intf, bool show )
{
POPUP_BOILERPLATE
if( p_input )
VideoAutoMenuBuilder( THEPL, p_input, objects, varnames );
CREATE_POPUP
return menu;
}
/* Audio Tracks */
void VLCMenuBar::AudioPopupMenu( intf_thread_t *p_intf, bool show )
QMenu* VLCMenuBar::AudioPopupMenu( intf_thread_t *p_intf, bool show )
{
POPUP_BOILERPLATE
if( p_input )
AudioAutoMenuBuilder( p_input, objects, varnames );
CREATE_POPUP
return menu;
}
/* Navigation stuff, and general menus ( open ), used only for skins */
void VLCMenuBar::MiscPopupMenu( intf_thread_t *p_intf, bool show )
QMenu* VLCMenuBar::MiscPopupMenu( intf_thread_t *p_intf, bool show )
{
POPUP_BOILERPLATE
......@@ -984,11 +984,13 @@ void VLCMenuBar::MiscPopupMenu( intf_thread_t *p_intf, bool show )
menu->addSeparator();
PopupMenuStaticEntries( menu );
menu->popup( QCursor::pos() );
if( show )
menu->popup( QCursor::pos() );
return menu;
}
/* Main Menu that sticks everything together */
void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
QMenu* VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
{
POPUP_BOILERPLATE
......@@ -1113,7 +1115,9 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
/* Static entries for ending, like open */
PopupMenuStaticEntries( menu );
menu->popup( QCursor::pos() );
if( show )
menu->popup( QCursor::pos() );
return menu;
}
#undef CREATE_POPUP
......
......@@ -78,10 +78,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 *, bool );
static void VideoPopupMenu( intf_thread_t *, bool );
static void MiscPopupMenu( intf_thread_t *, bool );
static QMenu* PopupMenu( intf_thread_t *, bool );
static QMenu* AudioPopupMenu( intf_thread_t *, bool );
static QMenu* VideoPopupMenu( intf_thread_t *, bool );
static QMenu* MiscPopupMenu( intf_thread_t *, bool );
/* 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