diff --git a/src/models/appsmodel.cpp b/src/models/appsmodel.cpp index f2086062..b172abe8 100644 --- a/src/models/appsmodel.cpp +++ b/src/models/appsmodel.cpp @@ -113,12 +113,17 @@ void AppsModel::setSourceModel(QAbstractItemModel *model) rebuildRows(); } -QModelIndex AppsModel::indexFromDesktopId(const QString &desktopId) const +QModelIndex AppsModel::indexFromAppId(const QString &appId) const { if (rowCount() == 0) return {}; + return match(index(0, 0), DesktopIdRole, appId, 1, Qt::MatchExactly).value(0); +} + +QModelIndex AppsModel::indexFromDesktopId(const QString &desktopId) const +{ for (int i = 0; i < rowCount(); ++i) { - if (AppsModel::normalizedDesktopId(desktopId) == AppsModel::normalizedDesktopId(data(index(i, 0), DesktopIdRole).toString())) + if (desktopId == normalizedDesktopId(data(index(i, 0), DesktopIdRole).toString())) return index(i, 0); } return {}; diff --git a/src/models/appsmodel.h b/src/models/appsmodel.h index aa44e377..2a85053f 100644 --- a/src/models/appsmodel.h +++ b/src/models/appsmodel.h @@ -59,10 +59,13 @@ class AppsModel : public QAbstractListModel } void setSourceModel(QAbstractItemModel *sourceModel); + // Raw app IDs come from dde-shell; desktop file IDs include one extra .desktop suffix. + QModelIndex indexFromAppId(const QString &appId) const; QModelIndex indexFromDesktopId(const QString &desktopId) const; bool ready() const; QVariantMap ddeCategories() const; + // Convert a raw app ID to a desktop file ID, even when the app ID ends in .desktop. static QString normalizedDesktopId(const QString &sourceId); int rowCount(const QModelIndex &parent = QModelIndex()) const override; diff --git a/src/models/itemarrangementproxymodel.cpp b/src/models/itemarrangementproxymodel.cpp index f56807af..74345eee 100644 --- a/src/models/itemarrangementproxymodel.cpp +++ b/src/models/itemarrangementproxymodel.cpp @@ -163,7 +163,7 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const ItemsPage * dstFolder = createFolder(dstFolderId); qCDebug(logModels) << "Appending items to new folder page:" << dropId << dragId; dstFolder->appendPage({normDropId, normDragId}); - const QModelIndex dropItem = AppsModel::instance().indexFromDesktopId(dropId); + const QModelIndex dropItem = AppsModel::instance().indexFromAppId(dropId); if (dropItem.isValid()) { const int dropCategory = dropItem.data(AppsModel::DDECategoryRole).toInt(); QString folderName = "internal/category/" + QString::number(dropCategory); diff --git a/tests/searchfilterproxymodeltest.cpp b/tests/searchfilterproxymodeltest.cpp index 06fa5695..20c3f30c 100644 --- a/tests/searchfilterproxymodeltest.cpp +++ b/tests/searchfilterproxymodeltest.cpp @@ -382,16 +382,18 @@ void TestSearchFilterProxyModel::testSharedModelAdapter() QCOMPARE(appsModel.indexFromDesktopId("org.test.hidden.desktop").data(AppsModel::DesktopIdRole).toString(), QStringLiteral("org.test.hidden")); - auto suffixedItem = createTestAppItem("org.test.suffixed", "Suffixed", "Suffixed"); + auto suffixedItem = createTestAppItem("org.test.suffixed.desktop", "Suffixed", "Suffixed"); m_sourceModel.appendRow(suffixedItem); QCOMPARE(rowsInsertedSpy.count(), 2); - const QModelIndex suffixedIndex = appsModel.indexFromDesktopId("org.test.suffixed"); + const QModelIndex suffixedIndex = appsModel.indexFromAppId("org.test.suffixed.desktop"); QCOMPARE(suffixedIndex.data(AppsModel::DesktopIdRole).toString(), - QStringLiteral("org.test.suffixed")); + QStringLiteral("org.test.suffixed.desktop")); + QCOMPARE(AppsModel::normalizedDesktopId("org.test.suffixed.desktop"), + QStringLiteral("org.test.suffixed.desktop.desktop")); QSignalSpy dataChangedSpy(&appsModel, &QAbstractItemModel::dataChanged); suffixedItem->setData(QStringLiteral("Renamed"), SourceNameRole); - QCOMPARE(appsModel.indexFromDesktopId("org.test.suffixed").data(Qt::DisplayRole).toString(), + QCOMPARE(appsModel.indexFromDesktopId("org.test.suffixed.desktop.desktop").data(Qt::DisplayRole).toString(), QStringLiteral("Renamed")); QVERIFY(!dataChangedSpy.isEmpty()); const auto changedRoles = dataChangedSpy.constLast().at(2).value>();