Commit eccc792efd59fc3f2717c99b1a7d37e36df80bc5
- Diff rendering mode:
- inline
- side by side
daemon/mousedevicesmonitor.cpp
(45 / 1)
|   | |||
| 30 | 30 | #include "mousedevicesmonitor.h" | |
| 31 | 31 | #include <KDebug> | |
| 32 | 32 | #include <QtDBus/QDBusInterface> | |
| 33 | #include <QtDBus/QDBusServiceWatcher> | ||
| 33 | 34 | #include <QtDBus/QDBusReply> | |
| 34 | 35 | #include <QtCore/QStringList> | |
| 36 | #include <QtCore/QPointer> | ||
| 35 | 37 | ||
| 36 | 38 | ||
| 37 | 39 | using namespace synaptiks; | |
| … | … | ||
| 61 | 61 | ||
| 62 | 62 | void _k_deviceAdded(const QString &udi); | |
| 63 | 63 | void _k_deviceRemoved(const QString &udi); | |
| 64 | void _k_halRegistered(); | ||
| 65 | void _k_halUnregistered(); | ||
| 64 | 66 | QStringList pluggedMouseDevices() const; | |
| 65 | 67 | bool queryCapability(const QString &udi, | |
| 66 | 68 | const QString &capability) const; | |
| 67 | 69 | QString getProperty(const QString &udi, | |
| 68 | 70 | const QString &property) const; | |
| 69 | 71 | ||
| 70 | QDBusInterface *hal_manager; | ||
| 72 | QPointer<QDBusInterface> hal_manager; | ||
| 73 | QDBusServiceWatcher *hal_watcher; | ||
| 71 | 74 | QSet<QString> mouseDevices; | |
| 72 | 75 | MouseDevicesMonitor *q_ptr; | |
| 73 | 76 | }; | |
| … | … | ||
| 86 | 86 | SLOT(_k_deviceAdded(const QString&))); | |
| 87 | 87 | q->connect(this->hal_manager, SIGNAL(DeviceRemoved(const QString&)), | |
| 88 | 88 | SLOT(_k_deviceRemoved(const QString&))); | |
| 89 | // watch the HAL service for (un-)registration to re-initialize the | ||
| 90 | // connection to this service if required (e.g. HAL was restarted due to | ||
| 91 | // an update or HAL crashed or whatever) | ||
| 92 | this->hal_watcher = new QDBusServiceWatcher(q); | ||
| 93 | this->hal_watcher->addWatchedService(HAL_SERVICE); | ||
| 94 | q->connect(this->hal_watcher, SIGNAL(serviceRegistered(const QString&)), | ||
| 95 | SLOT(_k_halRegistered())); | ||
| 96 | q->connect( | ||
| 97 | this->hal_watcher, SIGNAL(serviceUnregistered(const QString&)), | ||
| 98 | SLOT(_k_halUnregistered())); | ||
| 99 | this->hal_watcher->setConnection(this->hal_manager->connection()); | ||
| 89 | 100 | this->mouseDevices = QSet<QString>::fromList( | |
| 90 | 101 | this->pluggedMouseDevices()); | |
| 91 | 102 | } | |
| … | … | ||
| 117 | 117 | } | |
| 118 | 118 | } | |
| 119 | 119 | ||
| 120 | void MouseDevicesMonitorPrivate::_k_halRegistered() { | ||
| 121 | // HAL is available now, create the interface and "connect" all mouses | ||
| 122 | Q_Q(MouseDevicesMonitor); | ||
| 123 | this->hal_manager = new QDBusInterface( | ||
| 124 | HAL_SERVICE, HAL_MANAGER_PATH, HAL_MANAGER_IFACE, | ||
| 125 | this->hal_watcher->connection(), q); | ||
| 126 | this->mouseDevices = QSet<QString>::fromList( | ||
| 127 | this->pluggedMouseDevices()); | ||
| 128 | foreach (const QString &udi, this->mouseDevices) { | ||
| 129 | emit q->mousePlugged(udi); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | void MouseDevicesMonitorPrivate::_k_halUnregistered() { | ||
| 134 | // HAL is gone, so we consider all mouses being disconnected now, just | ||
| 135 | // to be on the safe side, because we can't montor mouse devices | ||
| 136 | // anymore. | ||
| 137 | Q_Q(MouseDevicesMonitor); | ||
| 138 | foreach (const QString &udi, this->mouseDevices) { | ||
| 139 | emit q->mouseUnplugged(udi); | ||
| 140 | } | ||
| 141 | this->mouseDevices.clear(); | ||
| 142 | // delete the now invalid interface | ||
| 143 | delete this->hal_manager; | ||
| 144 | } | ||
| 145 | |||
| 120 | 146 | QStringList MouseDevicesMonitorPrivate::pluggedMouseDevices() const { | |
| 121 | 147 | kDebug() << "enumerating plugged devices"; | |
| 148 | if (!this->hal_manager) | ||
| 149 | return QStringList(); | ||
| 122 | 150 | QDBusReply<QStringList> devices = this->hal_manager->call( | |
| 123 | 151 | "FindDeviceByCapability", "input.mouse"); | |
| 124 | 152 | if (!devices.isValid()) { |
daemon/mousedevicesmonitor.h
(2 / 0)
|   | |||
| 157 | 157 | ||
| 158 | 158 | Q_PRIVATE_SLOT(d_func(), void _k_deviceAdded(const QString&)) | |
| 159 | 159 | Q_PRIVATE_SLOT(d_func(), void _k_deviceRemoved(const QString&)) | |
| 160 | Q_PRIVATE_SLOT(d_func(), void _k_halRegistered()) | ||
| 161 | Q_PRIVATE_SLOT(d_func(), void _k_halUnregistered()) | ||
| 160 | 162 | ||
| 161 | 163 | MouseDevicesMonitorPrivate * const d_ptr; | |
| 162 | 164 | }; |

