cosmetix
[dyskinesia.git] / src / ghotkey / ghotkeyman.cpp
blob56230b03044cd78f488e19dbaf2c8c666ba90f04
1 /*
2 * ghotkeymanager.cpp - Class managing global shortcuts
3 * Copyright (C) 2006 Maciej Niedzielski
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "ghotkeyman.h"
22 #include <QCoreApplication>
24 #include "ghotkeytrigger.h"
27 GHotKeyMan *GHotKeyMan::mInstance = 0;
30 /**
31 * \brief Constructs new GHotKeyMan.
33 GHotKeyMan::GHotKeyMan () : QObject(QCoreApplication::instance()) {
37 GHotKeyMan::~GHotKeyMan () {
38 clear();
42 /**
43 * \brief Returns the instance of GHotKeyMan.
45 GHotKeyMan *GHotKeyMan::instance () {
46 if (!mInstance) mInstance = new GHotKeyMan();
47 return mInstance;
51 /**
52 * \brief Connects a key sequence with a slot.
53 * \param key, global shortcut to be connected
54 * \param receiver, object which should receive the notification
55 * \param slot, the SLOT() of the \a receiver which should be triggerd if the \a key is activated
57 void GHotKeyMan::connect (const QKeySequence &key, QObject *receiver, const char *slot) {
58 KeyTrigger *t = instance()->mTriggers[key];
59 if (!t) {
60 t = new KeyTrigger(key);
61 instance()->mTriggers.insert(key, t);
63 QObject::connect(t, SIGNAL(activated()), receiver, slot);
67 /**
68 * \brief Disonnects a key sequence from a slot.
69 * \param key, global shortcut to be disconnected
70 * \param receiver, object which \a slot is about to be disconnected
71 * \param slot, the SLOT() of the \a receiver which should no longer be triggerd if the \a key is activated
73 void GHotKeyMan::disconnect (const QKeySequence &key, QObject *receiver, const char *slot) {
74 KeyTrigger *t = instance()->mTriggers[key];
75 if (!t) return;
76 QObject::disconnect(t, SIGNAL(activated()), receiver, slot);
77 if (!t->isUsed()) delete instance()->mTriggers.take(key);
81 void GHotKeyMan::clear () {
82 foreach (KeyTrigger* t, instance()->mTriggers) delete t;
83 instance()->mTriggers.clear();