Commit a1d396ad authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Error checking in KCM, in case KDED is not running

Added a dbus interface isValid check to prevent a crash.

BUG: 323653
parent d3aba357
......@@ -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
......
......@@ -91,18 +91,25 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
//Store previous device config
pluginsConfigChanged();
if (!current.isValid()) {
kcmUi->deviceInfo->setVisible(false);
return;
}
currentIndex = sortProxyModel->mapToSource(current);
currentDevice = devicesModel->getDevice(currentIndex);
bool valid = currentIndex.isValid();
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());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment