6702190811
When using 'Send a file/URL' in the indicator with multiple devices, the device the user selects for file sharing is not automatically selected in the URL handler dialog that follows. This happens because `model.rowForDevice(deviceId)` is called without waiting for the model to be populated, always returning -1. Resolving this exposed another bug, where the selected device was still not the one picked. This happens because `proxyModel` is used to fill the `QComboBox` but `model` is used to find the correct index. Since `DevicesPluginFilterProxyModel` sorts and filters the data from `model` the indices do not match. This commit addresses these issues by deferring the device selection until data is available and implementing `rowForDevice` for filtered/sorted data in `DevicesPluginFilterProxyModel`.
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
/**
|
|
* SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
*/
|
|
|
|
#include "devicespluginfilterproxymodel.h"
|
|
|
|
bool DevicesPluginFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
|
{
|
|
const QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
|
|
auto device = qobject_cast<DeviceDbusInterface *>(idx.data(DevicesModel::DeviceRole).value<QObject *>());
|
|
return device->hasPlugin(m_pluginFilter);
|
|
}
|
|
|
|
void DevicesPluginFilterProxyModel::setPluginFilter(const QString plugin)
|
|
{
|
|
m_pluginFilter = plugin;
|
|
}
|
|
|
|
QString DevicesPluginFilterProxyModel::pluginFilter() const
|
|
{
|
|
return m_pluginFilter;
|
|
}
|
|
|
|
int DevicesPluginFilterProxyModel::rowForDevice(const QString &id) const
|
|
{
|
|
for (int i = 0, c = rowCount(); i < c; ++i) {
|
|
if (data(index(i, 0), DevicesModel::IdModelRole).value<QString>() == id) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
#include "moc_devicespluginfilterproxymodel.cpp"
|