| 1 |
/* |
| 2 |
* Copyright 2015 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "qinputdeviceinfo_mock_p.h" |
| 18 |
|
| 19 |
#include <QTimer> |
| 20 |
#include <QDebug> |
| 21 |
|
| 22 |
QInputDeviceManagerPrivate::QInputDeviceManagerPrivate(QObject *parent) : |
| 23 |
QObject(parent), |
| 24 |
currentFilter(QInputDevice::Unknown) |
| 25 |
{ |
| 26 |
QTimer::singleShot(1, this, SIGNAL(ready())); |
| 27 |
} |
| 28 |
|
| 29 |
QInputDeviceManagerPrivate::~QInputDeviceManagerPrivate() |
| 30 |
{ |
| 31 |
} |
| 32 |
|
| 33 |
QInputDevice *QInputDeviceManagerPrivate::addMockDevice(const QString &devicePath, QInputDevice::InputType type) |
| 34 |
{ |
| 35 |
QInputDevice *inputDevice = new QInputDevice(this); |
| 36 |
inputDevice->setDevicePath(devicePath); |
| 37 |
inputDevice->setName("Mock Device " + devicePath); |
| 38 |
inputDevice->setType(type); |
| 39 |
deviceMap.insert(devicePath, inputDevice); |
| 40 |
Q_EMIT deviceAdded(devicePath); |
| 41 |
return inputDevice; |
| 42 |
} |
| 43 |
|
| 44 |
void QInputDeviceManagerPrivate::removeDevice(const QString &path) |
| 45 |
{ |
| 46 |
auto it = deviceMap.begin(); |
| 47 |
while (it != deviceMap.end()) { |
| 48 |
const QString devicePath = it.key(); |
| 49 |
if (devicePath.contains(path)) { |
| 50 |
it = deviceMap.erase(it); |
| 51 |
Q_EMIT deviceRemoved(devicePath); |
| 52 |
} else { |
| 53 |
++it; |
| 54 |
} |
| 55 |
} |
| 56 |
} |