Error checking in KCM, in case KDED is not running
Added a dbus interface isValid check to prevent a crash. BUG: 323653
This commit is contained in:
parent
d3aba3572b
commit
a1d396ad20
2 changed files with 22 additions and 7 deletions
|
@ -95,7 +95,6 @@ void DevicesModel::refreshDeviceList()
|
|||
|
||||
QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
|
||||
if (!m_dbusInterface->isValid()) {
|
||||
switch (role) {
|
||||
case IconModelRole:
|
||||
|
@ -117,7 +116,7 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
DeviceDbusInterface* device = m_deviceList[index.row()];
|
||||
|
||||
//FIXME: This function gets called lots of times per second, producing lots of dbus calls
|
||||
//FIXME: This function gets called lots of times, producing lots of dbus calls. Add a cache.
|
||||
switch (role) {
|
||||
case IconModelRole: {
|
||||
bool paired = device->paired();
|
||||
|
@ -144,7 +143,16 @@ QVariant DevicesModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
DeviceDbusInterface* DevicesModel::getDevice(const QModelIndex& index)
|
||||
{
|
||||
return m_deviceList[index.row()];
|
||||
if (!index.isValid()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int row = index.row();
|
||||
if (row < 0 || row >= m_deviceList.size()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_deviceList[row];
|
||||
}
|
||||
|
||||
int DevicesModel::rowCount(const QModelIndex &parent) const
|
||||
|
|
15
kcm/kcm.cpp
15
kcm/kcm.cpp
|
@ -91,18 +91,25 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
|
|||
//Store previous device config
|
||||
pluginsConfigChanged();
|
||||
|
||||
currentIndex = sortProxyModel->mapToSource(current);
|
||||
if (!current.isValid()) {
|
||||
kcmUi->deviceInfo->setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
bool valid = currentIndex.isValid();
|
||||
currentIndex = sortProxyModel->mapToSource(current);
|
||||
currentDevice = devicesModel->getDevice(currentIndex);
|
||||
|
||||
bool valid = (currentDevice != NULL && currentDevice->isValid());
|
||||
kcmUi->deviceInfo->setVisible(valid);
|
||||
if (!valid) return;
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
//FIXME: KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time
|
||||
delete kcmUi->pluginSelector;
|
||||
kcmUi->pluginSelector = new KPluginSelector(this);
|
||||
kcmUi->verticalLayout_2->addWidget(kcmUi->pluginSelector);
|
||||
|
||||
currentDevice = devicesModel->getDevice(currentIndex);
|
||||
kcmUi->deviceName->setText(currentDevice->name());
|
||||
kcmUi->trust_checkbox->setChecked(currentDevice->paired());
|
||||
|
||||
|
|
Loading…
Reference in a new issue