3
* Copyright 2013 Canonical Ltd.
4
* Author: Manuel de la Pena <manuel.delapena@canonical.com>
6
* This program is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 3, as published
8
* by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranties of
12
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
* PURPOSE. See the GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
* In addition, as a special exception, the copyright holders give
19
* permission to link the code of portions of this program with the
20
* OpenSSL library under certain conditions as described in each
21
* individual source file, and distribute linked combinations
23
* You must obey the GNU General Public License in all respects
24
* for all of the code used other than OpenSSL. If you modify
25
* file(s) with this exception, you may extend this exception to your
26
* version of the file(s), but you are not obligated to do so. If you
27
* do not wish to do so, delete this exception statement from your
28
* version. If you delete this exception statement from all source
29
* files in the program, then also delete it here.
33
#include "signal_mapper.h"
38
DBusSignalMapper::_init DBusSignalMapper::_initializer;
40
class DBusSignalMapperPrivate
42
Q_DECLARE_PUBLIC(DBusSignalMapper)
44
DBusSignalMapperPrivate(DBusSignalMapper* parent) :
47
void _q_senderDestroyed() {
48
Q_Q(DBusSignalMapper);
49
q->removeMappings(q->sender());
51
QHash<QObject*, int> intHash;
52
QHash<QObject*, QString> stringHash;
53
QHash<QObject*, QWidget*> widgetHash;
54
QHash<QObject*, QObject*> objectHash;
57
DBusSignalMapper* q_ptr;
60
DBusSignalMapper::DBusSignalMapper(QObject *parent) :
62
d_ptr(new DBusSignalMapperPrivate(this))
66
DBusSignalMapper::~DBusSignalMapper()
70
void DBusSignalMapper::setMapping(QObject* sender, int id)
72
Q_D(DBusSignalMapper);
73
d->intHash.insert(sender, id);
74
connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
77
void DBusSignalMapper::setMapping(QObject* sender, const QString &text)
79
Q_D(DBusSignalMapper);
80
d->stringHash.insert(sender, text);
81
connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
84
void DBusSignalMapper::setMapping(QObject* sender, QWidget *widget)
86
Q_D(DBusSignalMapper);
87
d->widgetHash.insert(sender, widget);
88
connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
91
void DBusSignalMapper::setMapping(QObject* sender, QObject *object)
93
Q_D(DBusSignalMapper);
94
d->objectHash.insert(sender, object);
95
connect(sender, SIGNAL(destroyed()), this, SLOT(_q_senderDestroyed()));
98
QObject* DBusSignalMapper::mapping(int id) const
100
Q_D(const DBusSignalMapper);
101
return d->intHash.key(id);
104
QObject* DBusSignalMapper::mapping(const QString& id) const
106
Q_D(const DBusSignalMapper);
107
return d->stringHash.key(id);
110
QObject* DBusSignalMapper::mapping(QWidget* widget) const
112
Q_D(const DBusSignalMapper);
113
return d->widgetHash.key(widget);
116
QObject* DBusSignalMapper::mapping(QObject* object) const
118
Q_D(const DBusSignalMapper);
119
return d->objectHash.key(object);
122
void DBusSignalMapper::removeMappings(QObject* sender)
124
Q_D(DBusSignalMapper);
126
d->intHash.remove(sender);
127
d->stringHash.remove(sender);
128
d->widgetHash.remove(sender);
129
d->objectHash.remove(sender);
132
void DBusSignalMapper::map(QDBusPendingCallWatcher* watcher)
134
map(watcher, sender());
137
void DBusSignalMapper::map(QDBusPendingCallWatcher* watcher, QObject* sender)
139
Q_D(DBusSignalMapper);
140
if (d->intHash.contains(sender))
141
emit mapped(watcher, d->intHash.value(sender));
142
if (d->stringHash.contains(sender))
143
emit mapped(watcher, d->stringHash.value(sender));
144
if (d->widgetHash.contains(sender))
145
emit mapped(watcher, d->widgetHash.value(sender));
146
if (d->objectHash.contains(sender))
147
emit mapped(watcher, d->objectHash.value(sender));
150
QList<QObject*> DBusSignalMapper::intMaps()
152
Q_D(DBusSignalMapper);
153
return d->intHash.keys();
156
QList<QObject*> DBusSignalMapper::stringMaps()
158
Q_D(DBusSignalMapper);
159
return d->stringHash.keys();
162
QList<QObject*> DBusSignalMapper::widgetMaps()
164
Q_D(DBusSignalMapper);
165
return d->widgetHash.keys();
168
QList<QObject*> DBusSignalMapper::objectMaps()
170
Q_D(DBusSignalMapper);
171
return d->objectHash.keys();
177
#include "moc_signal_mapper.cpp"