Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
3 changes: 3 additions & 0 deletions src/models/appsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/models/itemarrangementproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions tests/searchfilterproxymodeltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QList<int>>();
Expand Down
Loading