Fixed KCM crash on KDED restart

+ added a new datarole that could be useful to sort
This commit is contained in:
Albert Vaca 2013-08-15 22:22:11 +02:00
parent 4aac44801f
commit 622fdcc46e
2 changed files with 26 additions and 6 deletions

View file

@ -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();
}

View file

@ -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);