From 5db018499bf3f5cfd82a9e5dbc11df016d1d1f01 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 14 Feb 2009 11:17:11 +0000 Subject: global hotkey support git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@787 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/CMakeLists.txt | 5 + src/plugins/General/General.pro | 3 +- src/plugins/General/hotkey/CMakeLists.txt | 72 ++++++ src/plugins/General/hotkey/hotkey.pro | 43 ++++ src/plugins/General/hotkey/hotkeydialog.cpp | 66 +++++ src/plugins/General/hotkey/hotkeydialog.h | 55 +++++ src/plugins/General/hotkey/hotkeydialog.ui | 120 ++++++++++ src/plugins/General/hotkey/hotkeyfactory.cpp | 64 +++++ src/plugins/General/hotkey/hotkeyfactory.h | 44 ++++ src/plugins/General/hotkey/hotkeymanager.cpp | 266 +++++++++++++++++++++ src/plugins/General/hotkey/hotkeymanager.h | 89 +++++++ src/plugins/General/hotkey/settingsdialog.cpp | 116 +++++++++ src/plugins/General/hotkey/settingsdialog.h | 52 ++++ src/plugins/General/hotkey/settingsdialog.ui | 116 +++++++++ .../hotkey/translations/hotkey_plugin_cs.ts | 108 +++++++++ .../hotkey/translations/hotkey_plugin_de.ts | 108 +++++++++ .../hotkey/translations/hotkey_plugin_ru.ts | 108 +++++++++ .../hotkey/translations/hotkey_plugin_uk_UA.ts | 108 +++++++++ .../hotkey/translations/hotkey_plugin_zh_CN.ts | 108 +++++++++ .../hotkey/translations/hotkey_plugin_zh_TW.ts | 108 +++++++++ .../General/hotkey/translations/translations.qrc | 11 + 21 files changed, 1769 insertions(+), 1 deletion(-) create mode 100644 src/plugins/General/hotkey/CMakeLists.txt create mode 100644 src/plugins/General/hotkey/hotkey.pro create mode 100644 src/plugins/General/hotkey/hotkeydialog.cpp create mode 100644 src/plugins/General/hotkey/hotkeydialog.h create mode 100644 src/plugins/General/hotkey/hotkeydialog.ui create mode 100644 src/plugins/General/hotkey/hotkeyfactory.cpp create mode 100644 src/plugins/General/hotkey/hotkeyfactory.h create mode 100644 src/plugins/General/hotkey/hotkeymanager.cpp create mode 100644 src/plugins/General/hotkey/hotkeymanager.h create mode 100644 src/plugins/General/hotkey/settingsdialog.cpp create mode 100644 src/plugins/General/hotkey/settingsdialog.h create mode 100644 src/plugins/General/hotkey/settingsdialog.ui create mode 100644 src/plugins/General/hotkey/translations/hotkey_plugin_cs.ts create mode 100644 src/plugins/General/hotkey/translations/hotkey_plugin_de.ts create mode 100644 src/plugins/General/hotkey/translations/hotkey_plugin_ru.ts create mode 100644 src/plugins/General/hotkey/translations/hotkey_plugin_uk_UA.ts create mode 100644 src/plugins/General/hotkey/translations/hotkey_plugin_zh_CN.ts create mode 100644 src/plugins/General/hotkey/translations/hotkey_plugin_zh_TW.ts create mode 100644 src/plugins/General/hotkey/translations/translations.qrc (limited to 'src') diff --git a/src/plugins/General/CMakeLists.txt b/src/plugins/General/CMakeLists.txt index c79d34025..8b428c008 100644 --- a/src/plugins/General/CMakeLists.txt +++ b/src/plugins/General/CMakeLists.txt @@ -4,6 +4,7 @@ SET(USE_STATICON TRUE CACHE BOOL "enable/disable status icon plugin") SET(USE_NOTIFIER TRUE CACHE BOOL "enable/disable notifier plugin") SET(USE_LYRICS TRUE CACHE BOOL "enable/disable lyrics version") SET(USE_HAL TRUE CACHE BOOL "enable/disable hal plugin") +SET(USE_HOTKEY TRUE CACHE BOOL "enable/disable global hotkey plugin") IF(USE_MPRIS) add_subdirectory(mpris) @@ -28,3 +29,7 @@ ENDIF(USE_LYRICS) IF(USE_HAL) add_subdirectory(hal) ENDIF(USE_HAL) + +IF(USE_HOTKEY) +add_subdirectory(hotkey) +ENDIF(USE_HOTKEY) diff --git a/src/plugins/General/General.pro b/src/plugins/General/General.pro index ce699c66b..e19fe4b5f 100644 --- a/src/plugins/General/General.pro +++ b/src/plugins/General/General.pro @@ -3,5 +3,6 @@ SUBDIRS += statusicon \ mpris \ notifier \ hal \ - lyrics + lyrics \ + hotkey TEMPLATE = subdirs diff --git a/src/plugins/General/hotkey/CMakeLists.txt b/src/plugins/General/hotkey/CMakeLists.txt new file mode 100644 index 000000000..786f978c1 --- /dev/null +++ b/src/plugins/General/hotkey/CMakeLists.txt @@ -0,0 +1,72 @@ +project(libhotkey) + +cmake_minimum_required(VERSION 2.4.7) +INCLUDE(FindX11) + +if(COMMAND cmake_policy) +cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ +) + +pkg_check_modules(X11 xf86miscproto x11) + +# libqmmpui & libqmmp +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +SET(libhotkey_SRCS + settingsdialog.cpp + hotkeyfactory.cpp + hotkeymanager.cpp + hotkeydialog.cpp +) + +SET(libhotkey_MOC_HDRS + settingsdialog.h + hotkeyfactory.h + hotkeymanager.h + hotkeydialog.h +) + +SET(libhotkey_RCCS + translations/translations.qrc +) + +QT4_ADD_RESOURCES(libhotkey_RCC_SRCS ${libhotkey_RCCS}) + +QT4_WRAP_CPP(libhotkey_MOC_SRCS ${libhotkey_MOC_HDRS}) + +# user interface + + +SET(libhotkey_UIS + settingsdialog.ui + hotkeydialog.ui +) + +QT4_WRAP_UI(libhotkey_UIS_H ${libhotkey_UIS}) +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +IF(X11_FOUND) +ADD_LIBRARY(hotkey SHARED ${libhotkey_SRCS} ${libhotkey_MOC_SRCS} ${libhotkey_UIS_H} ${libhotkey_RCC_SRCS}) +add_dependencies(hotkey qmmpui) +target_link_libraries(hotkey ${QT_LIBRARIES} -lqmmpui -lqmmp) +install(TARGETS hotkey DESTINATION ${LIB_DIR}/qmmp/General) +ENDIF(X11_FOUND) diff --git a/src/plugins/General/hotkey/hotkey.pro b/src/plugins/General/hotkey/hotkey.pro new file mode 100644 index 000000000..8d69f8c70 --- /dev/null +++ b/src/plugins/General/hotkey/hotkey.pro @@ -0,0 +1,43 @@ +include(../../plugins.pri) + +CONFIG += release \ +warn_on \ +plugin \ + lib + +TARGET = $$PLUGINS_PREFIX/General/hotkey +QMAKE_CLEAN = $$PLUGINS_PREFIX/General/libhotkey.so + +TEMPLATE = lib +QMAKE_LIBDIR += ../../../../lib + +TRANSLATIONS = translations/hotkey_plugin_cs.ts \ + translations/hotkey_plugin_de.ts \ + translations/hotkey_plugin_zh_CN.ts \ + translations/hotkey_plugin_zh_TW.ts \ + translations/hotkey_plugin_ru.ts \ + translations/hotkey_plugin_uk_UA.ts +RESOURCES = translations/translations.qrc + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/General +INSTALLS += target + +HEADERS += hotkeyfactory.h \ + hotkeymanager.h \ + settingsdialog.h \ + hotkeydialog.h + +SOURCES += hotkeyfactory.cpp \ + hotkeymanager.cpp \ + settingsdialog.cpp \ + hotkeydialog.cpp + +INCLUDEPATH += ../../../../src + +LIBS += -lqmmpui -lqmmp + +FORMS += settingsdialog.ui \ + hotkeydialog.ui diff --git a/src/plugins/General/hotkey/hotkeydialog.cpp b/src/plugins/General/hotkey/hotkeydialog.cpp new file mode 100644 index 000000000..abc6574fd --- /dev/null +++ b/src/plugins/General/hotkey/hotkeydialog.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include "hotkeymanager.h" +#include "hotkeydialog.h" + +HotkeyDialog::HotkeyDialog(quint32 key, quint32 mod, QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + m_key = key; + m_modifiers = mod; + ui.keyLineEdit->setText(HotkeyManager::getKeyString(m_key, m_modifiers)); +} + +HotkeyDialog::~HotkeyDialog() +{ +} + +void HotkeyDialog::keyPressEvent (QKeyEvent *event) +{ + m_key = event->nativeVirtualKey (); + m_modifiers = event->nativeModifiers (); + foreach(long mask_mod, HotkeyManager::ignModifiersList()) + m_modifiers &= ~mask_mod; //remove ignoried modifiers (num lock, caps lock, etc) + ui.keyLineEdit->setText(HotkeyManager::getKeyString(m_key, m_modifiers)); + QWidget::keyPressEvent(event); +} + +quint32 HotkeyDialog::nativeModifiers () const +{ + return m_modifiers; +} + +quint32 HotkeyDialog::nativeVirtualKey () const +{ + return m_key; +} + +void HotkeyDialog::accept() +{ + if (ui.keyLineEdit->text().isEmpty()) //clear key & modifiers + { + m_key = 0; + m_modifiers = 0; + } + QDialog::accept(); +} diff --git a/src/plugins/General/hotkey/hotkeydialog.h b/src/plugins/General/hotkey/hotkeydialog.h new file mode 100644 index 000000000..a0c96049a --- /dev/null +++ b/src/plugins/General/hotkey/hotkeydialog.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef HOTKEYDIALOG_H +#define HOTKEYDIALOG_H + +#include + +#include "ui_hotkeydialog.h" + +class QKeyEvent; + +/** + @author Ilya Kotov +*/ +class HotkeyDialog : public QDialog +{ + Q_OBJECT +public: + HotkeyDialog(quint32 key, quint32 mod, QWidget *parent = 0); + + ~HotkeyDialog(); + + quint32 nativeModifiers () const; + quint32 nativeVirtualKey () const; + +public slots: + virtual void accept(); + +protected: + virtual void keyPressEvent (QKeyEvent *event); + +private: + Ui::HotkeyDialog ui; + quint32 m_key, m_modifiers; + +}; + +#endif diff --git a/src/plugins/General/hotkey/hotkeydialog.ui b/src/plugins/General/hotkey/hotkeydialog.ui new file mode 100644 index 000000000..fff3429bd --- /dev/null +++ b/src/plugins/General/hotkey/hotkeydialog.ui @@ -0,0 +1,120 @@ + + + HotkeyDialog + + + + 0 + 0 + 310 + 89 + + + + Modify Shortcut + + + + 6 + + + 6 + + + 6 + + + + + Press the key combination you want to assign + + + + + + + true + + + + + + + Clear + + + + + + + Qt::Horizontal + + + + 106 + 20 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + HotkeyDialog + accept() + + + 212 + 70 + + + 192 + 269 + + + + + buttonBox + rejected() + HotkeyDialog + reject() + + + 212 + 70 + + + 246 + 214 + + + + + clearButton + clicked() + keyLineEdit + clear() + + + 195 + 22 + + + 113 + 25 + + + + + diff --git a/src/plugins/General/hotkey/hotkeyfactory.cpp b/src/plugins/General/hotkey/hotkeyfactory.cpp new file mode 100644 index 000000000..afe694fe8 --- /dev/null +++ b/src/plugins/General/hotkey/hotkeyfactory.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include + +#include "settingsdialog.h" +#include "hotkeymanager.h" +#include "hotkeyfactory.h" + +const GeneralProperties HotkeyFactory::properties() const +{ + GeneralProperties properties; + properties.name = tr("Global Hotkey Plugin"); + properties.shortName = "hotkey"; + properties.hasAbout = TRUE; + properties.hasSettings = TRUE; + properties.visibilityControl = FALSE; + return properties; +} + +General *HotkeyFactory::create(QObject *parent) +{ + return new HotkeyManager(parent); +} + +QDialog *HotkeyFactory::createConfigDialog(QWidget *parent) +{ + return new SettingsDialog(parent); +} + +void HotkeyFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About Global Hotkey Plugin"), + tr("Qmmp Global Hotkey Plugin")+"\n"+ + tr("This plugin adds support for multimedia keys or global key combinations")+"\n"+ + tr("Writen by: Ilya Kotov ")); +} + +QTranslator *HotkeyFactory::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = QLocale::system().name(); + translator->load(QString(":/hotkey_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN(HotkeyFactory) diff --git a/src/plugins/General/hotkey/hotkeyfactory.h b/src/plugins/General/hotkey/hotkeyfactory.h new file mode 100644 index 000000000..f1ca46d1f --- /dev/null +++ b/src/plugins/General/hotkey/hotkeyfactory.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef HOTKEYFACTORY_H +#define HOTKEYFACTORY_H + +/** + @author Ilya Kotov +*/ +#include +#include + +#include +#include + +class HotkeyFactory : public QObject, public GeneralFactory +{ +Q_OBJECT +Q_INTERFACES(GeneralFactory); +public: + const GeneralProperties properties() const; + General *create(QObject *parent); + QDialog *createConfigDialog(QWidget *parent); + void showAbout(QWidget *parent); + QTranslator *createTranslator(QObject *parent); +}; + +#endif diff --git a/src/plugins/General/hotkey/hotkeymanager.cpp b/src/plugins/General/hotkey/hotkeymanager.cpp new file mode 100644 index 000000000..5a78c910a --- /dev/null +++ b/src/plugins/General/hotkey/hotkeymanager.cpp @@ -0,0 +1,266 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * Copyright (C) 2003-2007 by Justin Karneges and Michail Pishchagin * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#define Visual XVisual +extern "C" +{ +#include +#include +#include +#include +} +#undef CursorShape +#undef Status +#undef Bool +#undef None +#undef KeyPress +#undef Visual + +#include +#include +#include +#include "hotkeymanager.h" + +quint32 Hotkey::defaultKey() +{ + return defaultKey(action); +} + +quint32 Hotkey::defaultKey(int act) +{ + //default key bindings + QMap keyMap; + keyMap[PLAY] = XF86XK_AudioPlay; + keyMap[STOP] = XF86XK_AudioStop; + keyMap[PAUSE] = XF86XK_AudioPause; + keyMap[PLAY_PAUSE] = 0; + keyMap[NEXT] = XF86XK_AudioNext; + keyMap[PREVIOUS] = XF86XK_AudioPrev; + keyMap[SHOW_HIDE] = 0; + return keyMap[act]; +} + +HotkeyManager::HotkeyManager(QObject *parent) : General(parent) +{ + QCoreApplication::instance()->installEventFilter(this); + WId rootWindow = QX11Info::appRootWindow(); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); //load settings + settings.beginGroup("Hotkey"); + for (int i = Hotkey::PLAY, j = 0; i <= Hotkey::SHOW_HIDE; ++i, ++j) + { + quint32 key = settings.value(QString("key_%1").arg(i), Hotkey::defaultKey(i)).toUInt(); + quint32 mod = settings.value(QString("modifiers_%1").arg(i), 0).toUInt(); + + if (key) + { + foreach(long mask_mod, ignModifiersList()) + { + Hotkey *hotkey = new Hotkey; + hotkey->action = i; + hotkey->key = key; + hotkey->code = XKeysymToKeycode(QX11Info::display(), hotkey->key); + XGrabKey(QX11Info::display(), hotkey->code, mod | mask_mod, rootWindow, False, + GrabModeAsync, GrabModeAsync); + hotkey->mod = mod | mask_mod; + m_grabbedKeys << hotkey; + } + } + } + settings.endGroup(); + XSync(QX11Info::display(), False); +// XSetErrorHandler(); +} + +HotkeyManager::~HotkeyManager() +{ + foreach(Hotkey *key, m_grabbedKeys) + XUngrabKey(QX11Info::display(), key->code, key->mod, QX11Info::appRootWindow()); + while (!m_grabbedKeys.isEmpty()) + delete m_grabbedKeys.takeFirst (); +} + +const QString HotkeyManager::getKeyString(quint32 key, quint32 modifiers) +{ + QString strModList[] = { "Control", "Shift", "Alt", "Mod2", "Mod3", "Super", "Mod5" }; + quint32 modList[] = { ControlMask, ShiftMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask }; + QString keyStr; + for (int j = 0; j < 7; j++) + { + if (modifiers & modList[j]) + keyStr.append(strModList[j] + "+"); + } + keyStr.append(XKeysymToString(key)); + return keyStr; +} + +bool HotkeyManager::eventFilter(QObject* o, QEvent* e) +{ + //receive events from active and root windows only + if (e->type() == QEvent::KeyPress && (o == qApp->desktop () || o == qApp->activeWindow ())) + { + QKeyEvent* k = static_cast(e); + quint32 key = k->nativeVirtualKey (); + quint32 mod = k->nativeModifiers (); + foreach(Hotkey *hotkey, m_grabbedKeys) + { + if (hotkey->key != key || hotkey->mod != mod) + continue; + qDebug("HotkeyManager: [%s] pressed", qPrintable(getKeyString(key, mod))); + + switch (hotkey->action) + { + case Hotkey::PLAY: + MediaPlayer::instance()->play(); + break; + case Hotkey::STOP: + MediaPlayer::instance()->stop(); + break; + case Hotkey::PAUSE: + SoundCore::instance()->pause(); + break; + case Hotkey::PLAY_PAUSE: + if (SoundCore::instance()->state() == Qmmp::Stopped) + MediaPlayer::instance()->play(); + else if (SoundCore::instance()->state() != Qmmp::FatalError) + SoundCore::instance()->pause(); + break; + case Hotkey::NEXT: + MediaPlayer::instance()->next(); + break; + case Hotkey::PREVIOUS: + MediaPlayer::instance()->previous(); + break; + case Hotkey::SHOW_HIDE: + toggleVisibility(); + } + qApp->processEvents(); + } + } + return QObject::eventFilter(o, e); +} +long HotkeyManager::m_alt_mask = 0; +long HotkeyManager::m_meta_mask = 0; +long HotkeyManager::m_super_mask = 0; +long HotkeyManager::m_hyper_mask = 0; +long HotkeyManager::m_numlock_mask = 0; +bool HotkeyManager::m_haveMods = FALSE; + +//copied from globalshortcutmanager_x11.cpp by Justin Karneges and Michail Pishchagin (Psi project) +void HotkeyManager::ensureModifiers() +{ + if (m_haveMods) + return; + + Display* appDpy = QX11Info::display(); + XModifierKeymap* map = XGetModifierMapping(appDpy); + if (map) + { + // XKeycodeToKeysym helper code adapeted from xmodmap + int min_keycode, max_keycode, keysyms_per_keycode = 1; + XDisplayKeycodes (appDpy, &min_keycode, &max_keycode); + XFree(XGetKeyboardMapping (appDpy, min_keycode, (max_keycode - min_keycode + 1), &keysyms_per_keycode)); + + int i, maskIndex = 0, mapIndex = 0; + for (maskIndex = 0; maskIndex < 8; maskIndex++) + { + for (i = 0; i < map->max_keypermod; i++) + { + if (map->modifiermap[mapIndex]) + { + KeySym sym; + int symIndex = 0; + do + { + sym = XKeycodeToKeysym(appDpy, map->modifiermap[mapIndex], symIndex); + symIndex++; + } + while ( !sym && symIndex < keysyms_per_keycode); + if (!m_alt_mask && (sym == XK_Alt_L || sym == XK_Alt_R)) + { + m_alt_mask = 1 << maskIndex; + } + if (!m_meta_mask && (sym == XK_Meta_L || sym == XK_Meta_R)) + { + m_meta_mask = 1 << maskIndex; + } + if (!m_super_mask && (sym == XK_Super_L || sym == XK_Super_R)) + { + m_super_mask = 1 << maskIndex; + } + if (!m_hyper_mask && (sym == XK_Hyper_L || sym == XK_Hyper_R)) + { + m_hyper_mask = 1 << maskIndex; + } + if (!m_numlock_mask && (sym == XK_Num_Lock)) + { + m_numlock_mask = 1 << maskIndex; + } + } + mapIndex++; + } + } + + XFreeModifiermap(map); + + // logic from qt source see gui/kernel/qkeymapper_x11.cpp + if (!m_meta_mask || m_meta_mask == m_alt_mask) + { + // no meta keys... s,meta,super, + m_meta_mask = m_super_mask; + if (!m_meta_mask || m_meta_mask == m_alt_mask) + { + // no super keys either? guess we'll use hyper then + m_meta_mask = m_hyper_mask; + } + } + } + else + { + // assume defaults + m_alt_mask = Mod1Mask; + m_meta_mask = Mod4Mask; + } + + m_haveMods = TRUE; +} + +QList HotkeyManager::ignModifiersList() +{ + ensureModifiers(); + QList ret; + if (m_numlock_mask) + { + ret << 0 << LockMask << m_numlock_mask << (LockMask | m_numlock_mask); + } + else + { + ret << 0 << LockMask; + } + return ret; +} diff --git a/src/plugins/General/hotkey/hotkeymanager.h b/src/plugins/General/hotkey/hotkeymanager.h new file mode 100644 index 000000000..0db01b79e --- /dev/null +++ b/src/plugins/General/hotkey/hotkeymanager.h @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef HOTKEYMANAGER_H +#define HOTKEYMANAGER_H + +#include +#include +#include +#include + +class QEvent; + +/** + @author Ilya Kotov +*/ + +class Hotkey +{ +public: + enum Action + { + PLAY = QTableWidgetItem::UserType, + STOP, + PAUSE, + PLAY_PAUSE, + NEXT, + PREVIOUS, + SHOW_HIDE + }; + + Hotkey() + { + action = PLAY; + key = 0; + mod = 0; + code = 0; + } + + quint32 mod; + quint32 key; + int action; + int code; + quint32 defaultKey(); + static quint32 defaultKey(int act); +}; + +class HotkeyManager : public General +{ + Q_OBJECT +public: + HotkeyManager(QObject *parent = 0); + + ~HotkeyManager(); + + static const QString getKeyString(quint32 key, quint32 modifiers); + static QList ignModifiersList(); + +protected: + virtual bool eventFilter(QObject* o, QEvent* e); + +private: + static void ensureModifiers(); + QList m_grabbedKeys; + static long m_alt_mask; + static long m_meta_mask; + static long m_super_mask; + static long m_hyper_mask; + static long m_numlock_mask; + static bool m_haveMods; +}; + +#endif diff --git a/src/plugins/General/hotkey/settingsdialog.cpp b/src/plugins/General/hotkey/settingsdialog.cpp new file mode 100644 index 000000000..2aca48de7 --- /dev/null +++ b/src/plugins/General/hotkey/settingsdialog.cpp @@ -0,0 +1,116 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include + +extern "C" +{ +#include +} + +#include +#include "hotkeydialog.h" +#include "settingsdialog.h" + +SettingsDialog::SettingsDialog(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + ui.tableWidget->verticalHeader()->setDefaultSectionSize(fontMetrics().height()); + ui.tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed); + ui.tableWidget->verticalHeader()->hide(); + ui.tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + ui.tableWidget->setRowCount (7); + ui.tableWidget->setItem(0,0, new QTableWidgetItem(tr("Play"))); + ui.tableWidget->setItem(1,0, new QTableWidgetItem(tr("Stop"))); + ui.tableWidget->setItem(2,0, new QTableWidgetItem(tr("Pause"))); + ui.tableWidget->setItem(3,0, new QTableWidgetItem(tr("Play/Pause"))); + ui.tableWidget->setItem(4,0, new QTableWidgetItem(tr("Next"))); + ui.tableWidget->setItem(5,0, new QTableWidgetItem(tr("Previous"))); + ui.tableWidget->setItem(6,0, new QTableWidgetItem(tr("Show/Hide"))); + + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("Hotkey"); + for (int i = Hotkey::PLAY, j = 0; i <= Hotkey::SHOW_HIDE; ++i, ++j) + { + Hotkey *hotkey = new Hotkey; + hotkey->action = i; + hotkey->key = settings.value(QString("key_%1").arg(i), hotkey->defaultKey()).toUInt(); + hotkey->mod = settings.value(QString("modifiers_%1").arg(i), 0).toUInt(); + ui.tableWidget->setItem(j,1, new QTableWidgetItem(HotkeyManager::getKeyString(hotkey->key, + hotkey->mod), i)); + m_hotkeys << hotkey; + } + settings.endGroup(); +} + + +SettingsDialog::~SettingsDialog() +{ + while (!m_hotkeys.isEmpty()) + delete m_hotkeys.takeFirst (); + +} + +void SettingsDialog::accept() +{ + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + settings.beginGroup("Hotkey"); + foreach(Hotkey *k, m_hotkeys) + { + settings.setValue(QString("key_%1").arg(k->action), k->key); + settings.setValue(QString("modifiers_%1").arg(k->action), k->mod); + } + settings.endGroup(); + QDialog::accept(); +} + +void SettingsDialog::on_tableWidget_itemDoubleClicked (QTableWidgetItem *item) +{ + Hotkey *k = 0; + foreach(k, m_hotkeys) + { + if (k->action == item->type()) + break; + } + if (!k) + return; + + HotkeyDialog *dialog = new HotkeyDialog(k->key, k->mod, this); + if (item->type() >= QTableWidgetItem::UserType && + dialog->exec() == QDialog::Accepted) + { + item->setText(HotkeyManager::getKeyString(dialog->nativeVirtualKey (), dialog->nativeModifiers ())); + k->key = dialog->nativeVirtualKey (); + k->mod = dialog->nativeModifiers (); + } + delete dialog; +} + +void SettingsDialog::on_resetButton_clicked () +{ + for (int i = 0; i < m_hotkeys.size(); ++i) + { + m_hotkeys[i]->key = m_hotkeys[i]->defaultKey(); + m_hotkeys[i]->mod = 0; + ui.tableWidget->item(i, 1)->setText(HotkeyManager::getKeyString(m_hotkeys[i]->key, m_hotkeys[i]->mod)); + } +} diff --git a/src/plugins/General/hotkey/settingsdialog.h b/src/plugins/General/hotkey/settingsdialog.h new file mode 100644 index 000000000..45cb2987f --- /dev/null +++ b/src/plugins/General/hotkey/settingsdialog.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include +#include "hotkeymanager.h" + +#include "ui_settingsdialog.h" + +/** + @author Ilya Kotov +*/ +class SettingsDialog : public QDialog +{ +Q_OBJECT +public: + SettingsDialog(QWidget *parent = 0); + + ~SettingsDialog(); + + +public slots: + virtual void accept(); + +private slots: + void on_tableWidget_itemDoubleClicked (QTableWidgetItem * item); + void on_resetButton_clicked(); + +private: + Ui::SettingsDialog ui; + QList m_hotkeys; +}; + +#endif diff --git a/src/plugins/General/hotkey/settingsdialog.ui b/src/plugins/General/hotkey/settingsdialog.ui new file mode 100644 index 000000000..fd4f1c633 --- /dev/null +++ b/src/plugins/General/hotkey/settingsdialog.ui @@ -0,0 +1,116 @@ + + + SettingsDialog + + + + 0 + 0 + 318 + 299 + + + + Global Hotkey Plugin Settings + + + + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::SingleSelection + + + true + + + true + + + 0 + + + 2 + + + + Action + + + + + Shortcut + + + + + + + + Reset + + + + + + + Qt::Horizontal + + + + 258 + 20 + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 334 + 227 + + + 207 + 236 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 382 + 229 + + + 107 + 216 + + + + + diff --git a/src/plugins/General/hotkey/translations/hotkey_plugin_cs.ts b/src/plugins/General/hotkey/translations/hotkey_plugin_cs.ts new file mode 100644 index 000000000..47e4b86d2 --- /dev/null +++ b/src/plugins/General/hotkey/translations/hotkey_plugin_cs.ts @@ -0,0 +1,108 @@ + + + + + HotkeyDialog + + + Modify Shortcut + + + + + Press the key combination you want to assign + + + + + Clear + + + + + HotkeyFactory + + + Global Hotkey Plugin + + + + + About Global Hotkey Plugin + + + + + Qmmp Global Hotkey Plugin + + + + + This plugin adds support for multimedia keys or global key combinations + + + + + Writen by: Ilya Kotov <forkotov02@hotmail.ru> + + + + + SettingsDialog + + + Play + + + + + Stop + + + + + Pause + + + + + Play/Pause + + + + + Next + + + + + Previous + + + + + Show/Hide + + + + + Global Hotkey Plugin Settings + + + + + Action + + + + + Shortcut + + + + + Reset + + + + diff --git a/src/plugins/General/hotkey/translations/hotkey_plugin_de.ts b/src/plugins/General/hotkey/translations/hotkey_plugin_de.ts new file mode 100644 index 000000000..47e4b86d2 --- /dev/null +++ b/src/plugins/General/hotkey/translations/hotkey_plugin_de.ts @@ -0,0 +1,108 @@ + + + + + HotkeyDialog + + + Modify Shortcut + + + + + Press the key combination you want to assign + + + + + Clear + + + + + HotkeyFactory + + + Global Hotkey Plugin + + + + + About Global Hotkey Plugin + + + + + Qmmp Global Hotkey Plugin + + + + + This plugin adds support for multimedia keys or global key combinations + + + + + Writen by: Ilya Kotov <forkotov02@hotmail.ru> + + + + + SettingsDialog + + + Play + + + + + Stop + + + + + Pause + + + + + Play/Pause + + + + + Next + + + + + Previous + + + + + Show/Hide + + + + + Global Hotkey Plugin Settings + + + + + Action + + + + + Shortcut + + + + + Reset + + + + diff --git a/src/plugins/General/hotkey/translations/hotkey_plugin_ru.ts b/src/plugins/General/hotkey/translations/hotkey_plugin_ru.ts new file mode 100644 index 000000000..dc62e6922 --- /dev/null +++ b/src/plugins/General/hotkey/translations/hotkey_plugin_ru.ts @@ -0,0 +1,108 @@ + + + + + HotkeyDialog + + + Modify Shortcut + Изменить сочетание клавиш + + + + Press the key combination you want to assign + Нажмите клавиши, сочетания которых вы хотите использовать + + + + Clear + Очистить + + + + HotkeyFactory + + + Global Hotkey Plugin + Модуль глоб. клавиш + + + + About Global Hotkey Plugin + О модуле глобальных клавиш + + + + Qmmp Global Hotkey Plugin + Модуль глобальных клавиш для Qmmp + + + + This plugin adds support for multimedia keys or global key combinations + Этот модуль добавляет поддержку медиа- или глобальных клавиш + + + + Writen by: Ilya Kotov <forkotov02@hotmail.ru> + Разработчик: Илья Котов <forkotov02@hotmail.ru> + + + + SettingsDialog + + + Play + Воспроизвести + + + + Stop + Остановить + + + + Pause + Приостановить + + + + Play/Pause + Воспроиз/приост + + + + Next + Следующий фрагмент + + + + Previous + Предыдущий фрагмент + + + + Show/Hide + Показать/Скрыть + + + + Global Hotkey Plugin Settings + Настройки модуля глобальных клавиш + + + + Action + Действие + + + + Shortcut + Горячая клавиша + + + + Reset + Сбросить + + + diff --git a/src/plugins/General/hotkey/translations/hotkey_plugin_uk_UA.ts b/src/plugins/General/hotkey/translations/hotkey_plugin_uk_UA.ts new file mode 100644 index 000000000..47e4b86d2 --- /dev/null +++ b/src/plugins/General/hotkey/translations/hotkey_plugin_uk_UA.ts @@ -0,0 +1,108 @@ + + + + + HotkeyDialog + + + Modify Shortcut + + + + + Press the key combination you want to assign + + + + + Clear + + + + + HotkeyFactory + + + Global Hotkey Plugin + + + + + About Global Hotkey Plugin + + + + + Qmmp Global Hotkey Plugin + + + + + This plugin adds support for multimedia keys or global key combinations + + + + + Writen by: Ilya Kotov <forkotov02@hotmail.ru> + + + + + SettingsDialog + + + Play + + + + + Stop + + + + + Pause + + + + + Play/Pause + + + + + Next + + + + + Previous + + + + + Show/Hide + + + + + Global Hotkey Plugin Settings + + + + + Action + + + + + Shortcut + + + + + Reset + + + + diff --git a/src/plugins/General/hotkey/translations/hotkey_plugin_zh_CN.ts b/src/plugins/General/hotkey/translations/hotkey_plugin_zh_CN.ts new file mode 100644 index 000000000..47e4b86d2 --- /dev/null +++ b/src/plugins/General/hotkey/translations/hotkey_plugin_zh_CN.ts @@ -0,0 +1,108 @@ + + + + + HotkeyDialog + + + Modify Shortcut + + + + + Press the key combination you want to assign + + + + + Clear + + + + + HotkeyFactory + + + Global Hotkey Plugin + + + + + About Global Hotkey Plugin + + + + + Qmmp Global Hotkey Plugin + + + + + This plugin adds support for multimedia keys or global key combinations + + + + + Writen by: Ilya Kotov <forkotov02@hotmail.ru> + + + + + SettingsDialog + + + Play + + + + + Stop + + + + + Pause + + + + + Play/Pause + + + + + Next + + + + + Previous + + + + + Show/Hide + + + + + Global Hotkey Plugin Settings + + + + + Action + + + + + Shortcut + + + + + Reset + + + + diff --git a/src/plugins/General/hotkey/translations/hotkey_plugin_zh_TW.ts b/src/plugins/General/hotkey/translations/hotkey_plugin_zh_TW.ts new file mode 100644 index 000000000..47e4b86d2 --- /dev/null +++ b/src/plugins/General/hotkey/translations/hotkey_plugin_zh_TW.ts @@ -0,0 +1,108 @@ + + + + + HotkeyDialog + + + Modify Shortcut + + + + + Press the key combination you want to assign + + + + + Clear + + + + + HotkeyFactory + + + Global Hotkey Plugin + + + + + About Global Hotkey Plugin + + + + + Qmmp Global Hotkey Plugin + + + + + This plugin adds support for multimedia keys or global key combinations + + + + + Writen by: Ilya Kotov <forkotov02@hotmail.ru> + + + + + SettingsDialog + + + Play + + + + + Stop + + + + + Pause + + + + + Play/Pause + + + + + Next + + + + + Previous + + + + + Show/Hide + + + + + Global Hotkey Plugin Settings + + + + + Action + + + + + Shortcut + + + + + Reset + + + + diff --git a/src/plugins/General/hotkey/translations/translations.qrc b/src/plugins/General/hotkey/translations/translations.qrc new file mode 100644 index 000000000..9258014ff --- /dev/null +++ b/src/plugins/General/hotkey/translations/translations.qrc @@ -0,0 +1,11 @@ + + + + hotkey_plugin_cs.qm + hotkey_plugin_de.qm + hotkey_plugin_zh_CN.qm + hotkey_plugin_zh_TW.qm + hotkey_plugin_ru.qm + hotkey_plugin_uk_UA.qm + + -- cgit v1.2.3-13-gbd6f