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
1 change: 1 addition & 0 deletions applets/dde-apps/amappitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ AMAppItem::AMAppItem(const QDBusObjectPath &path, const ObjectInterfaceMap &sour

auto categories = appInfo.value(u8"Categories").toStringList();
AppItem::setDDECategories(AppItemModel::DDECategories(CategoryUtils::parseBestMatchedCategory(categories)));
AppItem::setCategories(categories);

auto lastLaunchedTime = appInfo.value(u8"LastLaunchedTime").toULongLong();
AppItem::setLastLaunchedTime(lastLaunchedTime);
Expand Down
10 changes: 10 additions & 0 deletions applets/dde-apps/appitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@
return setData(categories, AppItemModel::DDECategoryRole);
}

QStringList AppItem::categories() const

Check warning on line 102 in applets/dde-apps/appitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'categories' is never used.
{
return data(AppItemModel::CategoriesRole).toStringList();
}

void AppItem::setCategories(const QStringList &categories)

Check warning on line 107 in applets/dde-apps/appitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setCategories' is never used.
{
return setData(categories, AppItemModel::CategoriesRole);
}

QString AppItem::actions() const
{
return data(AppItemModel::ActionsRole).toString();
Expand Down
3 changes: 3 additions & 0 deletions applets/dde-apps/appitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class AppItem : public QStandardItem
AppItemModel::DDECategories ddeCategories() const;
void setDDECategories(const AppItemModel::DDECategories &categories);

QStringList categories() const;
void setCategories(const QStringList &categories);

QString actions() const;
void setActions(const QString &actions);

Expand Down
1 change: 1 addition & 0 deletions applets/dde-apps/appitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ QHash<int, QByteArray> AppItemModel::roleNames() const
{AppItemModel::NoDisplayRole, QByteArrayLiteral("noDisplay")},
{AppItemModel::ActionsRole, QByteArrayLiteral("actions")},
{AppItemModel::DDECategoryRole, QByteArrayLiteral("ddeCategory")},
{AppItemModel::CategoriesRole, QByteArrayLiteral("categories")},
{AppItemModel::InstalledTimeRole, QByteArrayLiteral("installedTime")},
{AppItemModel::LastLaunchedTimeRole, QByteArrayLiteral("lastLaunchedTime")},
{AppItemModel::LaunchedTimesRole, QByteArrayLiteral("launchedTimes")},
Expand Down
1 change: 1 addition & 0 deletions applets/dde-apps/appitemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AppItemModel : public QStandardItemModel
NoDisplayRole,
ActionsRole,
DDECategoryRole,
CategoriesRole,
InstalledTimeRole,
LastLaunchedTimeRole,
LaunchedTimesRole,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
"permissions": "readwrite",
"visibility": "private"
},
"cgroupsBasedGroupingSkipCategories": {
"value": ["TerminalEmulator"],
"serial": 0,
"flags": [],
"name": "CGroups-Based Grouping Skipped Categories",
"name[zh_CN]": "基于 cgroups 的任务图标分组所应跳过的应用类别列表",
"description": "List of desktop file categories that cgroups-based grouping should skip checking",
"description[zh_CN]": "一个表示基于 CGroups 的应用分组所应当跳过的应用类别列表",
"permissions": "readwrite",
"visibility": "private"
},
"Docked_Items": {
"value": ["id: dde-file-manager,type: amAPP", "id: org.deepin.browser,type: amAPP", "id: deepin-app-store,type: amAPP", "id: org.deepin.dde.control-center, type: amAPP", "id: deepin-music,type: amAPP", "id: deepin-editor,type: amAPP", "id: deepin-mail,type: amAPP","id: deepin-terminal,type: amAPP","id: dde-calendar,type: amAPP", "id: deepin-calculator,type: amAPP"],
"serial": 0,
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static inline const QString TASKMANAGER_ALLOWFOCEQUIT_KEY = "Allow_Force_Quit";
static inline const QString TASKMANAGER_WINDOWSPLIT_KEY = "noTaskGrouping";
static inline const QString TASKMANAGER_CGROUPS_BASED_GROUPING_KEY = "cgroupsBasedGrouping";
static inline const QString TASKMANAGER_CGROUPS_BASED_GROUPING_SKIP_APPIDS = "cgroupsBasedGroupingSkipAppIds";
static inline const QString TASKMANAGER_CGROUPS_BASED_GROUPING_SKIP_CATEGORIES = "cgroupsBasedGroupingSkipCategories";
static inline const QString TASKMANAGER_DOCKEDITEMS_KEY = "Docked_Items";
constexpr auto TASKMANAGER_DOCKEDELEMENTS_KEY = "dockedElements";

Expand Down
40 changes: 38 additions & 2 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,44 @@ static QString getDesktopIdByPid(const QStringList &identifies)
qCDebug(taskManagerLog) << "appId is empty, AM failed to identify window with pid:" << windowPid;
return {};
}

return QString::fromUtf8(appId);
}

// 检查应用的 Categories 是否在跳过列表中
static bool shouldSkipCgroupsByCategories(const QString &desktopId, QAbstractItemModel *activeAppModel, const QHash<int, QByteArray> &roleNames)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

倒不如直接把 “尝试通过AM(Application Manager)匹配应用程序” 那块提出来。只提目前这一部分有点怪怪的。

{
auto skipCategories = Settings->cgroupsBasedGroupingSkipCategories();
if (skipCategories.isEmpty() || desktopId.isEmpty()) {
return false;
}

QStringList categories;

// 从 dde-apps 的 AppItem 读取 categories
if (activeAppModel) {
auto existingItem = activeAppModel->match(activeAppModel->index(0, 0), roleNames.key("desktopId"), desktopId, 1, Qt::MatchFixedString | Qt::MatchWrap).value(0);
if (existingItem.isValid()) {
categories = activeAppModel->data(existingItem, roleNames.key("categories")).toStringList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用再从 roleNames.key("categories") 获取 role 了吧?已经有 TaskManager::CategoriesRole 了。

}
}

if (categories.isEmpty()) {
return false;
}

// 检查是否有任何 category 在跳过列表中
for (const QString &category : categories) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是反了,不应该是迭代 skipCategories 然后判断 categories 是否包含 skipCategoriy 吗?

skipCategories 配置里预期不会有太多值,默认只有终端,也不期望用户自己随便加。

if (skipCategories.contains(category)) {
qCDebug(taskManagerLog) << "Skipping cgroups grouping for" << desktopId
<< "due to category:" << category;
return true;
}
}

return false;
}

class BoolFilterModel : public QSortFilterProxyModel, public AbstractTaskManagerInterface
{
Q_OBJECT
Expand Down Expand Up @@ -159,7 +193,9 @@ bool TaskManager::init()
// 尝试通过AM(Application Manager)匹配应用程序
if (Settings->cgroupsBasedGrouping()) {
auto desktopId = getDesktopIdByPid(identifies);
if (!desktopId.isEmpty() && !Settings->cgroupsBasedGroupingSkipIds().contains(desktopId)) {
if (!desktopId.isEmpty() &&
!Settings->cgroupsBasedGroupingSkipIds().contains(desktopId) &&
!shouldSkipCgroupsByCategories(desktopId, model, roleNames)) {
auto res = model->match(model->index(0, 0), roleNames.key(MODEL_DESKTOPID), desktopId, 1, Qt::MatchFixedString | Qt::MatchWrap).value(0);
if (res.isValid()) {
qCDebug(taskManagerLog) << "matched by AM desktop ID:" << desktopId << res;
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/taskmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage
NoDisplayRole,
ActionsRole,
DDECategoryRole,
CategoriesRole,
InstalledTimeRole,
LastLaunchedTimeRole,
LaunchedTimesRole,
Expand Down
6 changes: 6 additions & 0 deletions panels/dock/taskmanager/taskmanagersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
m_cgroupsBasedGrouping = m_taskManagerDconfig->value(TASKMANAGER_CGROUPS_BASED_GROUPING_KEY, true).toBool();
m_dockedElements = m_taskManagerDconfig->value(TASKMANAGER_DOCKEDELEMENTS_KEY, {}).toStringList();
m_cgroupsBasedGroupingSkipAppIds = m_taskManagerDconfig->value(TASKMANAGER_CGROUPS_BASED_GROUPING_SKIP_APPIDS, {"deepin-terminal"}).toStringList();
m_cgroupsBasedGroupingSkipCategories = m_taskManagerDconfig->value(TASKMANAGER_CGROUPS_BASED_GROUPING_SKIP_CATEGORIES, {"TerminalEmulator"}).toStringList();
migrateFromDockedItems();
}

Expand Down Expand Up @@ -89,7 +90,12 @@
return m_cgroupsBasedGroupingSkipAppIds;
}

QStringList TaskManagerSettings::cgroupsBasedGroupingSkipCategories() const

Check warning on line 93 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'cgroupsBasedGroupingSkipCategories' is never used.
{
return m_cgroupsBasedGroupingSkipCategories;
}

QStringList TaskManagerSettings::dockedElements() const

Check warning on line 98 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'dockedElements' is never used.
{
return m_dockedElements;
}
Expand Down
2 changes: 2 additions & 0 deletions panels/dock/taskmanager/taskmanagersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TaskManagerSettings : public QObject

bool cgroupsBasedGrouping() const;
QStringList cgroupsBasedGroupingSkipIds() const;
QStringList cgroupsBasedGroupingSkipCategories() const;

void setDockedElements(const QStringList &elements);
void toggleDockedElement(const QString &element);
Expand Down Expand Up @@ -58,5 +59,6 @@ class TaskManagerSettings : public QObject
bool m_cgroupsBasedGrouping;
QStringList m_dockedElements;
QStringList m_cgroupsBasedGroupingSkipAppIds;
QStringList m_cgroupsBasedGroupingSkipCategories;
};
}
Loading