2
#include <QCoreApplication>
4
#include "psioptions.h"
5
#include "shortcutmanager.h"
6
#include "globalshortcutmanager.h"
10
* \brief The Construtor of the Shortcutmanager
12
ShortcutManager::ShortcutManager() : QObject(QCoreApplication::instance())
14
// Make sure that there is at least one shortcut for sending messages
15
if (shortcuts("chat.send").isEmpty()) {
16
qWarning("Restoring chat.send shortcut");
18
vl << qVariantFromValue(QKeySequence(Qt::Key_Enter)) << qVariantFromValue(QKeySequence(Qt::Key_Return));
19
PsiOptions::instance()->setOption("options.shortcuts.chat.send",vl);
24
* "The one and only instance" of the ShortcutManager
26
ShortcutManager* ShortcutManager::instance_ = NULL;
29
* \brief The Instantiator of the Shortcutmanager
31
ShortcutManager* ShortcutManager::instance()
34
instance_ = new ShortcutManager();
39
* \brief get the QKeySequence associated with the keyname "name"
40
* \param the shortcut name e.g. "misc.sendmessage" which is in the options xml then
41
* mirrored as options.shortcuts.misc.sendmessage
42
* \return QKeySequence, the Keysequence associated with the keyname, or
43
* the first key sequence if there are multiple
45
QKeySequence ShortcutManager::shortcut(const QString& name)
47
QVariant variant = PsiOptions::instance()->getOption(QString("options.shortcuts.%1").arg(name));
48
QString type = variant.typeName();
49
if (type == "QVariantList")
50
variant = variant.toList().first();
51
//qDebug() << "shortcut: " << name << variant.value<QKeySequence>().toString();
52
return variant.value<QKeySequence>();
56
* \brief get the QVariantList associated with the keyname "name"
57
* \param the shortcut name e.g. "misc.sendmessage" which is in the options xml then
58
* mirrored as options.shortcuts.misc.sendmessage
59
* \return List of sequences
61
QList<QKeySequence> ShortcutManager::shortcuts(const QString& name)
63
QList<QKeySequence> list;
64
QVariant variant = PsiOptions::instance()->getOption(QString("options.shortcuts.%1").arg(name));
65
QString type = variant.typeName();
66
if (type == "QVariantList") {
67
foreach(QVariant variant, variant.toList()) {
68
list += variant.value<QKeySequence>();
72
QKeySequence k = variant.value<QKeySequence>();
81
* \brief this function connects the Key or Keys associated with the keyname "path" with the slot "slot"
82
* of the Widget "parent"
83
* \param path, the shortcut name e.g. "misc.sendmessage" which is in the options xml then
84
* mirrored as options.shortcuts.misc.sendmessage
85
* \param parent, the widget to which the new QAction should be connected to
86
* \param slot, the SLOT() of the parent which should be triggerd if the KeySequence is activated
88
void ShortcutManager::connect(const QString& path, QObject* parent, const char* slot)
90
if (parent == NULL || slot == NULL)
93
if (!path.startsWith("global.")) {
94
foreach(QKeySequence sequence, ShortcutManager::instance()->shortcuts(path)) {
95
if (!sequence.isEmpty()) {
96
QAction* act = new QAction(parent);
97
act->setShortcut(sequence);
98
if (parent->isWidgetType())
99
((QWidget*) parent)->addAction(act);
100
parent->connect(act, SIGNAL(activated()), slot);
105
foreach(QKeySequence sequence, ShortcutManager::instance()->shortcuts(path)) {
106
if (!sequence.isEmpty()) {
107
GlobalShortcutManager::instance()->connect(sequence, parent, slot);