From 2ca41b41224b01fd0453388178b3a0360a6df225 Mon Sep 17 00:00:00 2001 From: Wu JiangYu Date: Fri, 23 Oct 2026 14:48:54 +0800 Subject: [PATCH] fix: handle raw app IDs ending in .desktop correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Add indexFromAppId() to match raw app IDs directly via DesktopIdRole 2. Fix indexFromDesktopId() to compare the given ID against the normalized desktop ID instead of normalizing both sides, which double- appended .desktop to IDs already ending in .desktop 3. Use indexFromAppId() in ItemArrangementProxyModel when handling dnd drop IDs from dde-shell 4. Document the distinction between raw app IDs and desktop file IDs 5. Update tests to cover IDs that already include a .desktop suffix The previous normalization applied to both sides of the comparison caused IDs ending in .desktop to resolve incorrectly. Raw app IDs from dde-shell differ from desktop file IDs, so a dedicated lookup is needed. Influence: 1. Test drag-and-drop of apps whose IDs end in .desktop into folders 2. Verify folder categorization works for such apps 3. Test indexFromAppId with raw IDs and indexFromDesktopId with desktop file IDs 4. Verify normalizedDesktopId returns the expected .desktop.desktop result for suffixed IDs 5. Test lookup for IDs without .desktop suffix still works 6. Run search filter proxy model tests to confirm no regressions fix: 正确处理以 .desktop 结尾的原始应用 ID 1. 新增 indexFromAppId(),通过 DesktopIdRole 直接匹配原始应用 ID 2. 修复 indexFromDesktopId(),将给定 ID 与归一化后的桌面文件 ID 比较,而 不是对双方都归一化,避免对已带 .desktop 后缀的 ID 重复追加后缀 3. 在 ItemArrangementProxyModel 处理来自 dde-shell 的拖放 ID 时改 用 indexFromAppId() 4. 补充原始应用 ID 与桌面文件 ID 区别的注释 5. 更新测试,覆盖已带 .desktop 后缀的 ID 场景 此前的归一化对比较双方都执行,导致以 .desktop 结尾的 ID 解析错误。来自 dde-shell 的原始应用 ID 与桌面文件 ID 不同,因此需要专门的查找方法。 Influence: 1. 测试将以 .desktop 结尾 ID 的应用拖放至文件夹 2. 验证此类应用的文件夹分类功能 3. 测试 indexFromAppId 处理原始 ID、indexFromDesktopId 处理桌面文件 ID 4. 验证 normalizedDesktopId 对带后缀 ID 返回预期的 .desktop.desktop 结果 5. 测试不带 .desktop 后缀的 ID 查找仍正常 6. 运行搜索过滤代理模型测试,确认无回归 PMS: BUG-396959 --- src/models/appsmodel.cpp | 9 +++++++-- src/models/appsmodel.h | 3 +++ src/models/itemarrangementproxymodel.cpp | 2 +- tests/searchfilterproxymodeltest.cpp | 10 ++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) 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>();