From 9227e946f64416294a8c0321b80e2e9d453dd6df Mon Sep 17 00:00:00 2001 From: BLumia Date: Wed, 23 Sep 2026 12:54:52 +0800 Subject: [PATCH] fix: fix apps with .desktop suffix cannot launch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Stop stripping .desktop suffix in applicationObjectPath() 2. Return raw desktop ID from AppsModel::data(DesktopIdRole) 3. Add static normalizedDesktopId() for consistent ID normalization 4. Update all proxy models and desktop integration to use normalized IDs 5. Update test assertions to expect raw desktop IDs Log: Fixed launcher unable to start apps with .desktop suffix in app ID Influence: 1. Test launching apps with .desktop suffix in app ID (e.g. org.telegram.desktop) 2. Test launching apps without .desktop suffix in app ID 3. Test app search, sort, and favorite functions still work correctly 4. Test app uninstall and dock operations fix: 修复应用名含 .desktop 后缀的应用无法启动的问题 1. 停止在 applicationObjectPath() 中去除 .desktop 后缀 2. AppsModel::data(DesktopIdRole) 返回原始桌面 ID 3. 新增静态 normalizedDesktopId() 方法统一归一化处理 4. 更新所有代理模型和桌面集成模块使用归一化 ID 5. 更新测试断言以匹配原始桌面 ID Log: 修复启动器无法启动应用名含 .desktop 后缀的应用程序 Influence: 1. 测试应用名含 .desktop 后缀的应用启动(如 org.telegram.desktop) 2. 测试应用名不含 .desktop 后缀的应用启动 3. 测试应用搜索、排序和收藏功能是否正常 4. 测试应用卸载和驻留栏操作 PMS: BUG-378253 --- desktopintegration.cpp | 23 +++++++-------- src/ddeintegration/appmgr.cpp | 2 -- src/models/appsmodel.cpp | 24 ++++++++-------- src/models/appsmodel.h | 3 +- src/models/favoritedproxymodel.cpp | 18 ++++++------ src/models/frequentlyusedproxymodel.cpp | 7 +++-- src/models/itemarrangementproxymodel.cpp | 36 +++++++++++++----------- tests/searchfilterproxymodeltest.cpp | 28 +++++++++--------- 8 files changed, 74 insertions(+), 67 deletions(-) diff --git a/desktopintegration.cpp b/desktopintegration.cpp index 58512494..6b17943f 100644 --- a/desktopintegration.cpp +++ b/desktopintegration.cpp @@ -4,6 +4,7 @@ #include "desktopintegration.h" #include "appmgr.h" +#include "appsmodel.h" #include #include @@ -42,7 +43,7 @@ bool DesktopIntegration::isTreeLand() void DesktopIntegration::openSystemSettings() { qCInfo(logDesktopIntegration) << "Opening system settings"; - launchByDesktopId("org.deepin.dde.control-center.desktop"); + launchByDesktopId("org.deepin.dde.control-center"); } void DesktopIntegration::launchByDesktopId(const QString &desktopId) @@ -52,7 +53,7 @@ void DesktopIntegration::launchByDesktopId(const QString &desktopId) connect(activation, &ds::XdgActivation::tokenReady, &instance(), [desktopId, activation](const QString &token) { if (!AppMgr::launchApp(desktopId, token)) { qCDebug(logDesktopIntegration) << "AppMgr launch failed, trying AppInfo launch"; - AppInfo::launchByDesktopId(desktopId); + AppInfo::launchByDesktopId(AppsModel::normalizedDesktopId(desktopId)); } activation->deleteLater(); }); @@ -89,11 +90,11 @@ void DesktopIntegration::showUrl(const QString &url) bool DesktopIntegration::appIsCompulsoryForDesktop(const QString &desktopId) { - if (m_compulsoryAppIdList.contains(desktopId)) return true; + if (m_compulsoryAppIdList.contains(AppsModel::normalizedDesktopId(desktopId))) return true; const QString currentDE(DesktopIntegration::currentDE()); - const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, desktopId); + const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, AppsModel::normalizedDesktopId(desktopId)); for (const AppStream::Component & component : components) { return component.compulsoryForDesktops().contains(currentDE); } @@ -103,7 +104,7 @@ bool DesktopIntegration::appIsCompulsoryForDesktop(const QString &desktopId) bool DesktopIntegration::appIsDummyPackage(const QString &desktopId) { - const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, desktopId); + const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, AppsModel::normalizedDesktopId(desktopId)); for (const AppStream::Component & component : components) { return component.customValue("DDE::is_dummy_package") == "true"; } @@ -135,7 +136,7 @@ QString DesktopIntegration::backgroundUrl() const bool DesktopIntegration::isDockedApp(const QString &desktopId) const { // This is something we shouldn't do but anyway... - const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId); + const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId)); // Seems QML's list type doesn't have a contains() method... return m_dockIntegration->isDocked(fullPath); } @@ -143,14 +144,14 @@ bool DesktopIntegration::isDockedApp(const QString &desktopId) const void DesktopIntegration::sendToDock(const QString &desktopId) { qCInfo(logDesktopIntegration) << "Sending app to dock:" << desktopId; - const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId); + const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId)); return m_dockIntegration->sendToDock(fullPath); } void DesktopIntegration::removeFromDock(const QString &desktopId) { qCInfo(logDesktopIntegration) << "Removing app from dock:" << desktopId; - const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId); + const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId)); return m_dockIntegration->removeFromDock(fullPath); } @@ -165,7 +166,7 @@ inline QString desktopItemFilePath(const QString &desktopId) bool DesktopIntegration::isOnDesktop(const QString &desktopId) const { - QString desktopItemPath = desktopItemFilePath(desktopId); + QString desktopItemPath = desktopItemFilePath(AppsModel::normalizedDesktopId(desktopId)); if (desktopItemPath.isEmpty()) return false; return QFileInfo::exists(desktopItemPath); } @@ -196,7 +197,7 @@ void DesktopIntegration::setAutoStart(const QString &desktopId, bool on) bool DesktopIntegration::shouldSkipConfirmUninstallDialog(const QString &desktopId) const { bool result = false; - const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId); + const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId)); if (fullPath.isEmpty()) return result; DDesktopEntry entry(fullPath); @@ -210,7 +211,7 @@ bool DesktopIntegration::shouldSkipConfirmUninstallDialog(const QString &desktop void DesktopIntegration::uninstallApp(const QString &desktopId) { qCInfo(logDesktopIntegration) << "Uninstalling app:" << desktopId; - const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId); + const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId)); m_appWizIntegration->legacyRequestUninstall(fullPath); } diff --git a/src/ddeintegration/appmgr.cpp b/src/ddeintegration/appmgr.cpp index c2e70654..d076217b 100644 --- a/src/ddeintegration/appmgr.cpp +++ b/src/ddeintegration/appmgr.cpp @@ -41,8 +41,6 @@ const QStringList &disabledScaleEnvironments() QString applicationObjectPath(QString desktopId) { - if (desktopId.endsWith(QLatin1String(".desktop"))) - desktopId.chop(8); if (desktopId.isEmpty() || desktopId.startsWith(QLatin1String("internal/"))) return {}; return ApplicationObjectPathPrefix + DUtil::escapeToObjectPath(desktopId); diff --git a/src/models/appsmodel.cpp b/src/models/appsmodel.cpp index cebe3b34..23ecef10 100644 --- a/src/models/appsmodel.cpp +++ b/src/models/appsmodel.cpp @@ -63,7 +63,7 @@ AppsModel::AppsModel(QObject *parent) for (int sourceRow = 0; sourceRow < m_sourceModel->rowCount(); ++sourceRow) { const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0); - if (normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()) != desktopId) + if (AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()) != desktopId) continue; if (!acceptsSourceIndex(sourceIndex)) return; @@ -117,9 +117,11 @@ QModelIndex AppsModel::indexFromDesktopId(const QString &desktopId) const { if (rowCount() == 0) return {}; - const auto matches = match(index(0, 0), AppsModel::DesktopIdRole, - normalizedDesktopId(desktopId), 1, Qt::MatchExactly); - return matches.value(0); + for (int i = 0; i < rowCount(); ++i) { + if (AppsModel::normalizedDesktopId(desktopId) == AppsModel::normalizedDesktopId(data(index(i, 0), DesktopIdRole).toString())) + return index(i, 0); + } + return {}; } bool AppsModel::ready() const @@ -169,7 +171,7 @@ QVariant AppsModel::data(const QModelIndex &index, int role) const case AppsModel::NameRole: return sourceData(sourceIndex, NameRoleName); case AppsModel::DesktopIdRole: - return normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); + return sourceData(sourceIndex, DesktopIdRoleName).toString(); case AppsModel::CategoriesRole: return sourceData(sourceIndex, CategoriesRoleName); case AppsModel::DDECategoryRole: @@ -238,7 +240,7 @@ bool AppsModel::acceptsSourceIndex(const QModelIndex &sourceIndex) const if (!sourceIndex.isValid()) return false; - const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); + const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); if (desktopId.isEmpty() || m_excludedAppIdList.contains(desktopId)) return false; @@ -289,7 +291,7 @@ QList AppsModel::mappedRoles(const QList &sourceRoles) const return uniqueRoles; } -QString AppsModel::normalizedDesktopId(const QString &sourceId) const +QString AppsModel::normalizedDesktopId(const QString &sourceId) { if (sourceId.isEmpty() || sourceId.endsWith(QLatin1String(".desktop")) || sourceId.startsWith(QLatin1String("internal/"))) return sourceId; @@ -333,7 +335,7 @@ void AppsModel::beginRemoveSourceRows(const QModelIndex &parent, int first, int for (int sourceRow = first; sourceRow <= last; ++sourceRow) { const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0); AppMgr::instance()->cancelPendingAppItem( - normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString())); + AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString())); } const int adapterFirst = adapterRowForSourceRow(first); @@ -376,7 +378,7 @@ void AppsModel::updateSourceRows(const QModelIndex &topLeft, const QModelIndex & const int currentRow = m_rows.indexOf(persistentSourceIndex); const bool accepted = acceptsSourceIndex(sourceIndex); - const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); + const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); const bool pending = AppMgr::instance()->isPendingAppItem(desktopId); if ((mayChangeMembership || pending) && accepted && currentRow < 0) { if (shouldDelaySourceIndex(sourceIndex)) @@ -405,7 +407,7 @@ void AppsModel::rebuildRows() if (m_sourceModel) { for (int row = 0; row < m_sourceModel->rowCount(); ++row) { const QModelIndex sourceIndex = m_sourceModel->index(row, 0); - const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); + const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); if (acceptsSourceIndex(sourceIndex) && !AppMgr::instance()->isPendingAppItem(desktopId)) m_rows.append(sourceIndex); } @@ -415,7 +417,7 @@ void AppsModel::rebuildRows() bool AppsModel::shouldDelaySourceIndex(const QModelIndex &sourceIndex) const { - const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); + const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()); const QString iconName = sourceData(sourceIndex, IconNameRoleName).toString(); return AppMgr::instance()->waitForIcon(desktopId, iconName); } diff --git a/src/models/appsmodel.h b/src/models/appsmodel.h index 5ca0a80d..aa44e377 100644 --- a/src/models/appsmodel.h +++ b/src/models/appsmodel.h @@ -63,6 +63,8 @@ class AppsModel : public QAbstractListModel bool ready() const; QVariantMap ddeCategories() const; + static QString normalizedDesktopId(const QString &sourceId); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; QHash roleNames() const override; @@ -81,7 +83,6 @@ public Q_SLOTS: int sourceRole(const QByteArray &name) const; QVariant sourceData(const QModelIndex &sourceIndex, const QByteArray &roleName) const; QList mappedRoles(const QList &sourceRoles) const; - QString normalizedDesktopId(const QString &sourceId) const; int adapterRowForSourceRow(int sourceRow) const; void insertSourceRows(const QModelIndex &parent, int first, int last); void beginRemoveSourceRows(const QModelIndex &parent, int first, int last); diff --git a/src/models/favoritedproxymodel.cpp b/src/models/favoritedproxymodel.cpp index ff0ac8a1..18bac984 100644 --- a/src/models/favoritedproxymodel.cpp +++ b/src/models/favoritedproxymodel.cpp @@ -26,15 +26,15 @@ FavoritedProxyModel::FavoritedProxyModel(QObject *parent) bool FavoritedProxyModel::exists(const QString &desktopId) { - qCDebug(logModels) << desktopId << m_favoritedAppIds.contains(desktopId); - return m_favoritedAppIds.contains(desktopId); + qCDebug(logModels) << desktopId << m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(desktopId)); + return m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(desktopId)); } void FavoritedProxyModel::addFavorite(const QString &desktopId) { - if (m_favoritedAppIds.contains(desktopId)) return; + if (m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(desktopId))) return; - m_favoritedAppIds.append(desktopId); + m_favoritedAppIds.append(AppsModel::normalizedDesktopId(desktopId)); qCInfo(logModels) << "Favorite added:" << desktopId; save(); @@ -43,7 +43,7 @@ void FavoritedProxyModel::addFavorite(const QString &desktopId) void FavoritedProxyModel::removeFavorite(const QString &desktopId) { - m_favoritedAppIds.removeOne(desktopId); + m_favoritedAppIds.removeOne(AppsModel::normalizedDesktopId(desktopId)); qCInfo(logModels) << "Favorite removed:" << desktopId; save(); @@ -52,7 +52,7 @@ void FavoritedProxyModel::removeFavorite(const QString &desktopId) void FavoritedProxyModel::pinToTop(const QString &desktopId) { - int idx = m_favoritedAppIds.indexOf(desktopId); + int idx = m_favoritedAppIds.indexOf(AppsModel::normalizedDesktopId(desktopId)); if (idx != -1) { m_favoritedAppIds.move(idx, 0); @@ -67,13 +67,13 @@ bool FavoritedProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou { QModelIndex modelIndex = this->sourceModel()->index(sourceRow, 0, sourceParent); - return m_favoritedAppIds.contains(modelIndex.data(AppsModel::DesktopIdRole).toString()); + return m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(modelIndex.data(AppsModel::DesktopIdRole).toString())); } bool FavoritedProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { - const int leftIndex = m_favoritedAppIds.indexOf(source_left.data(AppsModel::DesktopIdRole).toString()); - const int rightIndex = m_favoritedAppIds.indexOf(source_right.data(AppsModel::DesktopIdRole).toString()); + const int leftIndex = m_favoritedAppIds.indexOf(AppsModel::normalizedDesktopId(source_left.data(AppsModel::DesktopIdRole).toString())); + const int rightIndex = m_favoritedAppIds.indexOf(AppsModel::normalizedDesktopId(source_right.data(AppsModel::DesktopIdRole).toString())); return leftIndex < rightIndex; } diff --git a/src/models/frequentlyusedproxymodel.cpp b/src/models/frequentlyusedproxymodel.cpp index 43833570..4ec5e3c2 100644 --- a/src/models/frequentlyusedproxymodel.cpp +++ b/src/models/frequentlyusedproxymodel.cpp @@ -1,8 +1,9 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later #include "frequentlyusedproxymodel.h" +#include "appsmodel.h" #include #include @@ -125,8 +126,8 @@ bool FrequentlyUsedProxyModel::inRecentlyInstalledModel(const QModelIndex &index bool FrequentlyUsedProxyModel::lessThenByFrequentlyUsed(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const { - const auto leftId = sourceLeft.data(m_desktopIdRole).toString(); - const auto rightId = sourceRight.data(m_desktopIdRole).toString(); + const auto leftId = AppsModel::normalizedDesktopId(sourceLeft.data(m_desktopIdRole).toString()); + const auto rightId = AppsModel::normalizedDesktopId(sourceRight.data(m_desktopIdRole).toString()); const auto leftInFrequentlyUsed = m_frequentlyUsedAppIdList.indexOf(leftId); const auto rightInFrequentlyUsed = m_frequentlyUsedAppIdList.indexOf(rightId); return leftInFrequentlyUsed < rightInFrequentlyUsed; diff --git a/src/models/itemarrangementproxymodel.cpp b/src/models/itemarrangementproxymodel.cpp index e90424bc..f56807af 100644 --- a/src/models/itemarrangementproxymodel.cpp +++ b/src/models/itemarrangementproxymodel.cpp @@ -49,7 +49,7 @@ void ItemArrangementProxyModel::updateFolderName(int folderId, const QString &na void ItemArrangementProxyModel::bringToFront(const QString & id) { - std::tuple origPos = findItem(id); + std::tuple origPos = findItem(AppsModel::normalizedDesktopId(id)); // can only bring top-level item to front if (std::get<0>(origPos) != 0) return; @@ -77,8 +77,11 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const return; } - std::tuple dragOrigPos = findItem(dragId); - std::tuple dropOrigPos = findItem(dropId); + const QString normDragId = AppsModel::normalizedDesktopId(dragId); + const QString normDropId = AppsModel::normalizedDesktopId(dropId); + + std::tuple dragOrigPos = findItem(normDragId); + std::tuple dropOrigPos = findItem(normDropId); qCDebug(logModels) << "Drop position:" << std::get<0>(dropOrigPos) << std::get<1>(dropOrigPos) << std::get<2>(dropOrigPos); Q_ASSERT(std::get<0>(dragOrigPos) != -1); @@ -105,12 +108,12 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const ItemsPage * srcFolder = folderById(std::get<0>(dragOrigPos)); ItemsPage * dstFolder = folderById(std::get<0>(dropOrigPos)); qCDebug(logModels) << "Removing item from source folder"; - srcFolder->removeItem(dragId); + srcFolder->removeItem(normDragId); if (srcFolder->pageCount() == 0 && srcFolder != dstFolder) { qCDebug(logModels) << "Source folder is empty and different from destination, removing it"; removeFolder(QString::number(std::get<0>(dragOrigPos))); } - dstFolder->insertItem(dragId, std::get<1>(dropOrigPos), std::get<2>(dropOrigPos)); + dstFolder->insertItem(normDragId, std::get<1>(dropOrigPos), std::get<2>(dropOrigPos)); } } else { if (dragId.startsWith("internal/folders/") && dropId != "internal/folders/0") return; // cannot drag folder onto something @@ -143,23 +146,23 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const } // hold the empty page avoid access out of page range ! - srcFolder->removeItem(dragId, false); + srcFolder->removeItem(normDragId, false); if (srcFolder->itemCount() == 0 && srcFolder != dstFolder) { qCDebug(logModels) << "Source folder is empty and different, removing folder"; removeFolder(QString::number(srcFolderId)); } - dstFolder->insertItemToPage(dragId, pageHint); + dstFolder->insertItemToPage(normDragId, pageHint); // clear empty page qCDebug(logModels) << "Clearing empty pages from source folder"; srcFolder->removeEmptyPages(); } else { - srcFolder->removeItem(dragId); // make a new folder, move two items into the folder + srcFolder->removeItem(normDragId); QString dstFolderId = findAvailableFolderId(); ItemsPage * dstFolder = createFolder(dstFolderId); qCDebug(logModels) << "Appending items to new folder page:" << dropId << dragId; - dstFolder->appendPage({dropId, dragId}); + dstFolder->appendPage({normDropId, normDragId}); const QModelIndex dropItem = AppsModel::instance().indexFromDesktopId(dropId); if (dropItem.isValid()) { const int dropCategory = dropItem.data(AppsModel::DDECategoryRole).toInt(); @@ -172,7 +175,7 @@ void ItemArrangementProxyModel::commitDndOperation(const QString &dragId, const removeFolder(QString::number(srcFolderId)); } m_topLevel->insertItem(dstFolderId, std::get<1>(dropOrigPos), std::get<2>(dropOrigPos)); - m_topLevel->removeItem(dropId); + m_topLevel->removeItem(normDropId); } } @@ -222,7 +225,7 @@ QVariant ItemArrangementProxyModel::data(const QModelIndex &index, int role) con qCWarning(logModels) << "Invalid or internal ID:" << id << "index:" << index << "row:" << index.row() << "role:" << role; } int folder, page, idx; - std::tie(folder, page, idx) = findItem(id); + std::tie(folder, page, idx) = findItem(AppsModel::normalizedDesktopId(id)); switch (role) { case PageRole: @@ -398,12 +401,13 @@ void ItemArrangementProxyModel::onSourceModelChanged() int appsCount = AppsModel::instance().rowCount(); for (int i = 0; i < appsCount; i++) { QString desktopId(AppsModel::instance().data(AppsModel::instance().index(i, 0), AppsModel::DesktopIdRole).toString()); - appDesktopIdSet.insert(desktopId); + QString normalizedId = AppsModel::normalizedDesktopId(desktopId); + appDesktopIdSet.insert(normalizedId); int folder; - std::tie(folder, std::ignore, std::ignore) = findItem(desktopId); + std::tie(folder, std::ignore, std::ignore) = findItem(normalizedId); // add all existing ones if they are not already in if (folder == -1) { - findItem(desktopId); + findItem(normalizedId); // Find first available page with space int targetPage = -1; int targetIndex = -1; @@ -421,11 +425,11 @@ void ItemArrangementProxyModel::onSourceModelChanged() if (targetPage != -1) { // Add to first available page with space qCDebug(logModels) << "Adding item to existing page" << targetPage << "at index" << targetIndex; - m_topLevel->insertItem(desktopId, targetPage, targetIndex); + m_topLevel->insertItem(normalizedId, targetPage, targetIndex); } else { // All pages are full, append to new page qCDebug(logModels) << "All pages full, appending item to new page"; - m_topLevel->appendItem(desktopId); + m_topLevel->appendItem(normalizedId); } } } diff --git a/tests/searchfilterproxymodeltest.cpp b/tests/searchfilterproxymodeltest.cpp index 185c7aaa..16552c84 100644 --- a/tests/searchfilterproxymodeltest.cpp +++ b/tests/searchfilterproxymodeltest.cpp @@ -173,21 +173,21 @@ void TestSearchFilterProxyModel::testBasicSearch() model.setFilterRegularExpression(QRegularExpression("Calculator")); qCDebug(logTest) << "Calculator search returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.calculator.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.calculator"); // 测试基本搜索 - 部分匹配 qCDebug(logTest) << "Testing partial match search for 'Text'"; model.setFilterRegularExpression(QRegularExpression("Text")); qCDebug(logTest) << "Text search returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.editor.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.editor"); // 测试基本搜索 - 不区分大小写 qCDebug(logTest) << "Testing case-insensitive search for 'calculator'"; model.setFilterRegularExpression(QRegularExpression("calculator")); qCDebug(logTest) << "Case-insensitive search returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.calculator.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.calculator"); // 测试基本搜索 - 多个结果 qCDebug(logTest) << "Testing multi-result search for 'e'"; @@ -207,14 +207,14 @@ void TestSearchFilterProxyModel::testChineseSearch() model.setFilterRegularExpression(QRegularExpression("音乐")); qCDebug(logTest) << "Chinese search for '音乐' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.music.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.music"); // 测试中文部分匹配 qCDebug(logTest) << "Testing Chinese partial match for '阅读'"; model.setFilterRegularExpression(QRegularExpression("阅读")); qCDebug(logTest) << "Chinese search for '阅读' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.reader.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.reader"); qCInfo(logTest) << "Chinese search tests completed successfully"; } @@ -228,26 +228,26 @@ void TestSearchFilterProxyModel::testPinyinSearch() model.setFilterRegularExpression(QRegularExpression("yinyue")); qCDebug(logTest) << "Pinyin search for 'yinyue' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.music.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.music"); // 测试拼音部分匹配 qCDebug(logTest) << "Testing Pinyin partial match for 'yuedu'"; model.setFilterRegularExpression(QRegularExpression("yuedu")); qCDebug(logTest) << "Pinyin search for 'yuedu' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.reader.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.reader"); // 测试拼音首字母匹配 qCDebug(logTest) << "Testing Pinyin initials match for 'rl'"; model.setFilterRegularExpression(QRegularExpression("rl")); qCDebug(logTest) << "Pinyin initials search for 'rl' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.calendar.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.calendar"); qCDebug(logTest) << "Testing Pinyin initials match for 'aqzx'"; model.setFilterRegularExpression(QRegularExpression("aqzx")); qCDebug(logTest) << "Pinyin initials search for 'aqzx' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.defender.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.defender"); qCInfo(logTest) << "Pinyin search tests completed successfully"; } @@ -261,14 +261,14 @@ void TestSearchFilterProxyModel::testJianpinSearch() model.setFilterRegularExpression(QRegularExpression("yy")); qCDebug(logTest) << "Jianpin search for 'yy' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.music.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.music"); // 测试简拼部分匹配 qCDebug(logTest) << "Testing Jianpin partial match for 'yd' (阅读)"; model.setFilterRegularExpression(QRegularExpression("yd")); qCDebug(logTest) << "Jianpin search for 'yd' returned" << model.rowCount() << "items"; QCOMPARE(model.rowCount(), 1); - QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.reader.desktop"); + QCOMPARE(model.data(model.index(0, 0), AppsModel::DesktopIdRole).toString(), "org.deepin.reader"); qCInfo(logTest) << "Jianpin search tests completed successfully"; } @@ -297,10 +297,10 @@ void TestSearchFilterProxyModel::testSorting() QString desktopId = model.data(model.index(i, 0), AppsModel::DesktopIdRole).toString(); qCDebug(logTest) << "Result" << i << ":" << desktopId; - if (desktopId == "org.deepin.browser.desktop") { + if (desktopId == "org.deepin.browser") { qCDebug(logTest) << "Found browser at position" << i; foundBrowser = true; - } else if (desktopId == "org.deepin.editor.desktop") { + } else if (desktopId == "org.deepin.editor") { qCDebug(logTest) << "Found editor at position" << i; foundEditor = true; } @@ -380,7 +380,7 @@ void TestSearchFilterProxyModel::testSharedModelAdapter() QCOMPARE(appsModel.rowCount(), initialRowCount + 1); QCOMPARE(rowsInsertedSpy.count(), 1); QCOMPARE(appsModel.indexFromDesktopId("org.test.hidden.desktop").data(AppsModel::DesktopIdRole).toString(), - QStringLiteral("org.test.hidden.desktop")); + QStringLiteral("org.test.hidden")); auto suffixedItem = createTestAppItem("org.test.suffixed.desktop", "Suffixed", "Suffixed"); m_sourceModel.appendRow(suffixedItem);