@@ -0,0 +1,140 @@
1+/****************************************************************************
3+** Copyright (C) 2015 Jolla.
4+** Contact: http://www.qt-project.org/legal
6+** This file is part of the QtSystems module of the Qt Toolkit.
8+** $QT_BEGIN_LICENSE:LGPL$
9+** Commercial License Usage
10+** Licensees holding valid commercial Qt licenses may use this file in
11+** accordance with the commercial license agreement provided with the
12+** Software or, alternatively, in accordance with the terms contained in
13+** a written agreement between you and Digia. For licensing terms and
14+** conditions see http://qt.digia.com/licensing. For further information
15+** use the contact form at http://qt.digia.com/contact-us.
17+** GNU Lesser General Public License Usage
18+** Alternatively, this file may be used under the terms of the GNU Lesser
19+** General Public License version 2.1 as published by the Free Software
20+** Foundation and appearing in the file LICENSE.LGPL included in the
21+** packaging of this file. Please review the following information to
22+** ensure the GNU Lesser General Public License version 2.1 requirements
23+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25+** In addition, as a special exception, Digia gives you certain additional
26+** rights. These rights are described in the Digia Qt LGPL Exception
27+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29+** GNU General Public License Usage
30+** Alternatively, this file may be used under the terms of the GNU
31+** General Public License version 3.0 as published by the Free Software
32+** Foundation and appearing in the file LICENSE.GPL included in the
33+** packaging of this file. Please review the following information to
34+** ensure the GNU General Public License version 3.0 requirements will be
35+** met: http://www.gnu.org/copyleft/gpl.html.
40+****************************************************************************/
41+#include "mockqdeclarativeinputdeviceinfo_p.h"
43+QDeclarativeInputDeviceInfo::QDeclarativeInputDeviceInfo(QObject *parent) :
44+ QAbstractListModel(parent),
45+ deviceInfo(new QInputDeviceInfo)
49+QDeclarativeInputDeviceInfo::~QDeclarativeInputDeviceInfo()
54+QVariant QDeclarativeInputDeviceInfo::data(const QModelIndex &index, int role) const
58+ return QVariant::fromValue(static_cast<QObject *>(inputDevices.value(index.row())));
64+int QDeclarativeInputDeviceInfo::rowCount(const QModelIndex &parent) const
68+ return inputDevices.count();
71+int QDeclarativeInputDeviceInfo::indexOf(const QString &devicePath) const
74+ Q_FOREACH (QInputDevice *device, inputDevices) {
76+ if (device->devicePath() == devicePath) return idx;
82+QInputDevice *QDeclarativeInputDeviceInfo::get(int index) const
84+ if (index < 0 || index > inputDevices.count())
86+ return inputDevices.value(index);
89+void QDeclarativeInputDeviceInfo::updateDeviceList()
91+ QVector <QInputDevice *> newDevices = deviceInfo->deviceList();
93+ int numNew = newDevices.count();
95+ for (int i = 0; i < numNew; i++) {
96+ int j = inputDevices.indexOf(newDevices.value(i));
98+ // not found -> remove from list
99+ beginInsertRows(QModelIndex(), i, i);
100+ inputDevices.insert(i, newDevices.value(i));
102+ } else if (i != j) {
103+ // changed its position -> move it
104+ QInputDevice* device = inputDevices.value(j);
105+ beginMoveRows(QModelIndex(), j, j, QModelIndex(), i);
106+ inputDevices.remove(j);
107+ inputDevices.insert(i, device);
110+ QModelIndex changedIndex(this->index(j, 0, QModelIndex()));
111+ Q_EMIT dataChanged(changedIndex, changedIndex);
115+ int numOld = inputDevices.count();
116+ if (numOld > numNew) {
117+ beginRemoveRows(QModelIndex(), numNew, numOld - 1);
118+ inputDevices.remove(numNew, numOld - numNew);
123+void QDeclarativeInputDeviceInfo::addedDevice(const QString &devicePath)
126+ Q_EMIT newDevice(devicePath);
129+void QDeclarativeInputDeviceInfo::removedDevice(const QString &devicePath)
132+ Q_EMIT deviceRemoved(devicePath);
135+QHash<int, QByteArray> QDeclarativeInputDeviceInfo::roleNames() const
137+ QHash<int, QByteArray> roles;
138+ roles.insert(ServiceRole, "service");