Skip to content
Open
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
25 changes: 17 additions & 8 deletions applets/dde-apps/appgroup.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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

Expand All @@ -15,11 +15,11 @@ Q_LOGGING_CATEGORY(appGroupLog, "org.deepin.dde.shell.dde-apps.appgroup")
namespace apps {
AppGroup::AppGroup(const QString &groupId, const QString &name, const QList<QStringList> &appIDs)
: AppItem(groupId, AppItemModel::FolderItemType)
, m_itemsPage(new ItemsPage(name, groupId == QStringLiteral("internal/folder/0") ? (4 * 8) : (3 * 4)))
, m_itemsPage(new ItemsPage(name, parseGroupId(groupId) == 0 ? (4 * 8) : (3 * 4)))
{
setItemsPerPage(m_itemsPage->maxItemCountPerPage());
setAppName(m_itemsPage->name());
// folder id is a part of its groupId: "internal/folder/{folderId}"
// folder id is a part of its groupId: "internal/folders/{folderId}"
setFolderId(parseGroupId(groupId));

for (const QStringList &items : appIDs) {
Expand Down Expand Up @@ -49,19 +49,28 @@ ItemsPage *AppGroup::itemsPage()

bool AppGroup::idIsFolder(const QString & id)
{
return id.startsWith(QStringLiteral("internal/folder/"));
return id.startsWith(QStringLiteral("internal/folders/")) && parseGroupId(id) >= 0;
}

QString AppGroup::groupIdFromNumber(int groupId)
{
return QStringLiteral("internal/folder/%1").arg(groupId);
return QStringLiteral("internal/folders/%1").arg(groupId);
}

int AppGroup::parseGroupId(const QString & id)
{
using namespace std::string_view_literals;
constexpr size_t len = "internal/folder/"sv.size();
return QStringView{id}.mid(len + 1).toInt();
// Accept legacy IDs while loading, always write the canonical plural form.
const QStringList prefixes{QStringLiteral("internal/folders/"), QStringLiteral("internal/folder/"), QStringLiteral("internal/group/")};
QString number = id;
for (const auto &prefix : prefixes) {
if (id.startsWith(prefix)) {
number = id.mid(prefix.size());
break;
}
}
bool ok = false;
const int result = number.toInt(&ok);
return ok && result >= 0 ? result : -1;
}

void AppGroup::setItemsPerPage(int number)
Expand Down
Loading
Loading