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
2 changes: 1 addition & 1 deletion qml/FullscreenFrame.qml
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ InputEventItem {
folderGridViewPopup.startPointX = itemPos.x + width / 2
folderGridViewPopup.startPointY = itemPos.y + height / 2
folderGridViewPopup.open()
folderGridViewPopup.folderName = model.display.startsWith("internal/category/") ? getCategoryName(model.display.substring(18)) : model.display
folderGridViewPopup.folderName = model.display
console.log("open folder id:" + idNum)
}
onMenuTriggered: {
Expand Down
2 changes: 1 addition & 1 deletion qml/IconItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Control {
// So we give the max sourceSize and use scale to solve it.
property int maxIconSize: 128
property int maxIconSizeInFolder: 64
readonly property string text: display.startsWith("internal/category/") ? getCategoryName(display.substring(18)) : display
readonly property string text: display

property string iconSource
property bool dndEnabled: false
Expand Down
29 changes: 1 addition & 28 deletions qml/Main.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -16,33 +16,6 @@ import org.deepin.launchpad.models 1.0
import org.deepin.launchpad.windowed 1.0

QtObject {
function getCategoryName(section) {
switch (Number(section)) {
case AppItem.Internet:
return qsTr("Internet");
case AppItem.Chat:
return qsTr("Chat");
case AppItem.Music:
return qsTr("Music");
case AppItem.Video:
return qsTr("Video");
case AppItem.Graphics:
return qsTr("Graphics");
case AppItem.Game:
return qsTr("Games");
case AppItem.Office:
return qsTr("Office");
case AppItem.Reading:
return qsTr("Reading");
case AppItem.Development:
return qsTr("Development");
case AppItem.System:
return qsTr("System");
default:
return qsTr("Others");
}
}

function launchApp(desktopId) {
if (DebugHelper.avoidLaunchApp) {
DTK.sendSystemMessage("dde-launchpad (debug)",
Expand Down
4 changes: 2 additions & 2 deletions qml/windowed/AppListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ FocusScope {
if (CategorizedSortProxyModel.categoryType === CategorizedSortProxyModel.Alphabetary) {
return section.toUpperCase();
} else {
return getCategoryName(section)
return ItemArrangementProxyModel.categoryDisplayName(section)
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ FocusScope {
model: ddeCategoryMenu.existingSections
delegate: MenuItem {
id: menuItem
text: getCategoryName(modelData)
text: ItemArrangementProxyModel.categoryDisplayName(modelData)
textColor: DStyle.Style.menu.itemText
font: DTK.fontManager.t6
onTriggered: {
Expand Down
4 changes: 2 additions & 2 deletions qml/windowed/FreeSortListView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Item {
console.log("freesort view folder clicked:", desktopId);
let idStr = model.desktopId
let strFolderId = Number(idStr.replace("internal/folders/", ""))
let strFolderName = model.display.startsWith("internal/category/") ? getCategoryName(model.display.substring(18)) : model.display
let strFolderName = model.display
let offset = height / 2
folderClicked(strFolderId, strFolderName, mapToItem(listView, offset, offset))
} else {
Expand Down Expand Up @@ -260,7 +260,7 @@ Item {

ItemDelegate {
id: itemDelegate
text: model.display.startsWith("internal/category/") ? getCategoryName(model.display.substring(18)) : model.display
text: model.display
checkable: false
icon.name: itemType === ItemArrangementProxyModel.FolderItemType ? "folder" : iconName
DciIcon.mode: DTK.NormalState
Expand Down
2 changes: 1 addition & 1 deletion qml/windowed/IconItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Control {
id: root
opacity: Drag.active ? 0 : 1

property string text: display.startsWith("internal/category/") ? getCategoryName(display.substring(18)) : display
property string text: display

property string iconSource
property bool dndEnabled: false
Expand Down
3 changes: 3 additions & 0 deletions shell-launcher-applet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ PACKAGE org.deepin.ds.dock.launcherapplet
QML_FILES
${QML_FILES_NEED_TRANSLATION}
${CMAKE_CURRENT_LIST_DIR}/package/launcheritem.qml
SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/launcheritem.cpp
${PROJECT_SOURCE_DIR}/src/models/itemarrangementproxymodel.cpp
)
59 changes: 58 additions & 1 deletion shell-launcher-applet/launcheritem.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "launcheritem.h"
#include "pluginfactory.h"

Check warning on line 6 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "pluginfactory.h" not found.
#include "../launchercontroller.h"
#include <blurhashimageprovider.h>

Check warning on line 8 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <blurhashimageprovider.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <appitem.h>

Check warning on line 9 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <appitem.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <appsmodel.h>

Check warning on line 10 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <appsmodel.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <itemarrangementproxymodel.h>

Check warning on line 11 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <itemarrangementproxymodel.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DDBusSender>

Check warning on line 13 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDBusSender> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 14 in shell-launcher-applet/launcheritem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <applet.h>
#include <qmlengine.h>
Expand All @@ -16,6 +19,18 @@
DS_USE_NAMESPACE
namespace {
Q_LOGGING_CATEGORY(logApplet, "org.deepin.dde.launchpad.applet")

constexpr QLatin1StringView groupIdPrefix("internal/folders/");

int folderIdFromGroupId(const QString &groupId)
{
if (!groupId.startsWith(groupIdPrefix))
return -1;

bool ok = false;
const int folderId = QStringView(groupId).sliced(groupIdPrefix.size()).toInt(&ok);
return ok && folderId > 0 ? folderId : -1;
}
}

namespace dock {
Expand All @@ -42,6 +57,48 @@
return true;
}

QAbstractItemModel *LauncherItem::itemArrangementModel() const
{
return &ItemArrangementProxyModel::instance();
}

QString LauncherItem::groupDisplayName(const QString &groupId) const
{
if (folderIdFromGroupId(groupId) < 0)
return {};

auto &model = ItemArrangementProxyModel::instance();
const auto matches = model.match(model.index(0, 0), AppItem::DesktopIdRole,
groupId, 1, Qt::MatchExactly);
if (matches.isEmpty())
return {};

return matches.constFirst().data(Qt::DisplayRole).toString();
}

QVariantList LauncherItem::groupItemDetails(const QString &groupId) const
{
const int folderId = folderIdFromGroupId(groupId);
if (folderId < 0)
return {};

const auto desktopIds = ItemArrangementProxyModel::instance().folderItems(folderId);
QVariantList details;
details.reserve(desktopIds.size());
for (const auto &desktopId : desktopIds) {
const auto item = AppsModel::instance().itemFromDesktopId(desktopId);
if (!item)
continue;

details.append(QVariantMap{
{QStringLiteral("desktopId"), desktopId},
{QStringLiteral("name"), item->name()},
{QStringLiteral("iconName"), item->iconName()},
});
}
return details;
}

D_APPLET_CLASS(LauncherItem)
}

Expand Down
10 changes: 9 additions & 1 deletion shell-launcher-applet/launcheritem.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include "applet.h"

Check warning on line 7 in shell-launcher-applet/launcheritem.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "applet.h" not found.
#include "dsglobal.h"

Check warning on line 8 in shell-launcher-applet/launcheritem.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsglobal.h" not found.

#include <QAbstractItemModel>

Check warning on line 10 in shell-launcher-applet/launcheritem.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QAbstractItemModel> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QVariant>

namespace dock {

class LauncherItem : public DS_NAMESPACE::DApplet
{
Q_OBJECT
Q_PROPERTY(QString iconName MEMBER m_iconName NOTIFY iconNameChanged FINAL)
Q_PROPERTY(QAbstractItemModel *itemArrangementModel READ itemArrangementModel CONSTANT FINAL)
public:
explicit LauncherItem(QObject *parent = nullptr);
virtual bool init() override;

QAbstractItemModel *itemArrangementModel() const;
Q_INVOKABLE QString groupDisplayName(const QString &groupId) const;
Q_INVOKABLE QVariantList groupItemDetails(const QString &groupId) const;

Q_SIGNALS:
void iconNameChanged();

Expand Down
27 changes: 0 additions & 27 deletions shell-launcher-applet/package/launcheritem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,6 @@ AppletItem {
}
}

function getCategoryName(section) {
switch (Number(section)) {
case AppItem.Internet:
return qsTr("Internet");
case AppItem.Chat:
return qsTr("Chat");
case AppItem.Music:
return qsTr("Music");
case AppItem.Video:
return qsTr("Video");
case AppItem.Graphics:
return qsTr("Graphics");
case AppItem.Game:
return qsTr("Games");
case AppItem.Office:
return qsTr("Office");
case AppItem.Reading:
return qsTr("Reading");
case AppItem.Development:
return qsTr("Development");
case AppItem.System:
return qsTr("System");
default:
return qsTr("Others");
}
}

function launchApp(desktopId) {
DesktopIntegration.launchByDesktopId(desktopId);
LauncherController.visible = false;
Expand Down
53 changes: 51 additions & 2 deletions src/models/itemarrangementproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "appsmodel.h"
#include "categoryutils.h"

#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QSettings>
Expand All @@ -15,11 +16,53 @@

Q_DECLARE_LOGGING_CATEGORY(logModels)

namespace {
constexpr QLatin1StringView categoryNamePrefix("internal/category/");
}

ItemArrangementProxyModel::~ItemArrangementProxyModel()
{
qCDebug(logModels) << "Destroying ItemArrangementProxyModel";
}

QString ItemArrangementProxyModel::categoryDisplayName(int category) const
{
switch (category) {
case AppItem::Internet:
return QCoreApplication::translate("launcheritem", "Internet");
case AppItem::Chat:
return QCoreApplication::translate("launcheritem", "Chat");
case AppItem::Music:
return QCoreApplication::translate("launcheritem", "Music");
case AppItem::Video:
return QCoreApplication::translate("launcheritem", "Video");
case AppItem::Graphics:
return QCoreApplication::translate("launcheritem", "Graphics");
case AppItem::Game:
return QCoreApplication::translate("launcheritem", "Games");
case AppItem::Office:
return QCoreApplication::translate("launcheritem", "Office");
case AppItem::Reading:
return QCoreApplication::translate("launcheritem", "Reading");
case AppItem::Development:
return QCoreApplication::translate("launcheritem", "Development");
case AppItem::System:
return QCoreApplication::translate("launcheritem", "System");
default:
return QCoreApplication::translate("launcheritem", "Others");
}
}

QString ItemArrangementProxyModel::localizedFolderName(const QString &folderName) const
{
if (!folderName.startsWith(categoryNamePrefix))
return folderName;

bool ok = false;
const int category = QStringView(folderName).sliced(categoryNamePrefix.size()).toInt(&ok);
return categoryDisplayName(ok ? category : AppItem::Others);
}

int ItemArrangementProxyModel::pageCount(int folderId) const
{
if (folderId == 0) return m_topLevel->pageCount();
Expand Down Expand Up @@ -248,7 +291,7 @@ QVariant ItemArrangementProxyModel::data(const QModelIndex &index, int role) con

switch (role) {
case Qt::DisplayRole:
return m_folders.value(id)->name();
return localizedFolderName(m_folders.value(id)->name());
case AppItem::DesktopIdRole:
return id;
case AppItem::IsAutoStartRole:
Expand Down Expand Up @@ -502,13 +545,19 @@ void ItemArrangementProxyModel::removeFolder(const QString &idNumber)
}

// get folder by id. 0 is top level, >=1 is folder
ItemsPage *ItemArrangementProxyModel::folderById(int id)
ItemsPage *ItemArrangementProxyModel::folderById(int id) const
{
if (id == 0) return m_topLevel;
const QString folderId("internal/folders/" + QString::number(id));
return m_folders.value(folderId);
}

QStringList ItemArrangementProxyModel::folderItems(int folderId) const
{
const auto page = folderById(folderId);
return page ? page->allArrangedItems() : QStringList{};
}

QStringList ItemArrangementProxyModel::allArrangedItems() const
{
return m_topLevel->allArrangedItems();
Expand Down
5 changes: 4 additions & 1 deletion src/models/itemarrangementproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel
Q_INVOKABLE void commitDndOperation(const QString & dragId, const QString & dropId, const DndOperation op, int pageHint = -1);
Q_INVOKABLE int creatEmptyPage(int folderId = 0) const;
Q_INVOKABLE void removeEmptyPage() const;
Q_INVOKABLE QString categoryDisplayName(int category) const;

ItemsPage *itemsPage() { return m_topLevel; }
QStringList folderItems(int folderId) const;

// QAbstractItemModel interface
public:
Expand All @@ -85,7 +87,8 @@ class ItemArrangementProxyModel : public QConcatenateTablesProxyModel
QString findAvailableFolderId();
ItemsPage * createFolder(const QString & id);
void removeFolder(const QString & idNumber);
ItemsPage * folderById(int id);
QString localizedFolderName(const QString &folderName) const;
ItemsPage * folderById(int id) const;
QStringList allArrangedItems() const;

// <folder-id, items-arrangement-data> folder-id: internal/folder/<id number>
Expand Down
Loading