From 622fdcc46e177656d86d57c6f9f28e453f380744 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Thu, 15 Aug 2013 22:22:11 +0200 Subject: [PATCH] Fixed KCM crash on KDED restart + added a new datarole that could be useful to sort --- kcm/devicesmodel.cpp | 25 +++++++++++++++++++------ kcm/devicesmodel.h | 7 +++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/kcm/devicesmodel.cpp b/kcm/devicesmodel.cpp index d784256ab..599099358 100644 --- a/kcm/devicesmodel.cpp +++ b/kcm/devicesmodel.cpp @@ -85,7 +85,7 @@ void DevicesModel::refreshDeviceList() m_deviceList.append(new DeviceDbusInterface(id,this)); endInsertRows(); } - + Q_EMIT dataChanged(index(0),index(deviceIds.count())); } /* bool DevicesModel::insertRows(int row, int count, const QModelIndex &parent) @@ -129,23 +129,36 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const } - if (!index.isValid() || index.row() < 0 || index.row() >= m_deviceList.count()) { + if (!index.isValid() + || index.row() < 0 + || index.row() >= m_deviceList.count() + || !m_deviceList[index.row()]->isValid()) + { return QVariant(); } + DeviceDbusInterface* device = m_deviceList[index.row()]; + //FIXME: This function gets called lots of times per second, producing lots of dbus calls switch (role) { case IconModelRole: { - bool paired = m_deviceList[index.row()]->paired(); - bool reachable = m_deviceList[index.row()]->reachable(); + bool paired = device->paired(); + bool reachable = device->reachable(); QString icon = reachable? (paired? "user-online" : "user-busy") : "user-offline"; return KIcon(icon).pixmap(32, 32); } case IdModelRole: - return QString(m_deviceList[index.row()]->id()); + return QString(device->id()); case NameModelRole: - return QString(m_deviceList[index.row()]->name()); + return QString(device->name()); + case StatusModelRole: { + int status = StatusUnknown; + if (device->paired()) status |= StatusPaired; + if (device->reachable()) status |= StatusReachable; + return status; + } + default: return QVariant(); } diff --git a/kcm/devicesmodel.h b/kcm/devicesmodel.h index adba660a5..1b9100f69 100644 --- a/kcm/devicesmodel.h +++ b/kcm/devicesmodel.h @@ -39,6 +39,13 @@ public: NameModelRole = Qt::DisplayRole, IconModelRole = Qt::DecorationRole, IdModelRole = Qt::UserRole, + StatusModelRole //= Qt::UserRole+1 + }; + enum StatusFlags { + StatusUnknown = 0x00, + StatusPaired = 0x01, + StatusReachable = 0x10, + }; DevicesModel(QObject *parent = 0);