mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
feat: 电源按钮右键菜单配置
新增电源插件右键菜单支持配置的功能 Log: 新增电源插件右键菜单支持配置的功能 Task: https://pms.uniontech.com/task-view-114011.html Influence: 任务栏电源按钮右键菜单 Change-Id: I97f050a10360b1893d17b2a12e3157286edf3fd6
This commit is contained in:
parent
c483cb8331
commit
44ab6359d5
17
configs/org.deepin.dde.dock.plugin.power.json
Normal file
17
configs/org.deepin.dde.dock.plugin.power.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"magic":"dsg.config.meta",
|
||||||
|
"version":"1.0",
|
||||||
|
"contents":{
|
||||||
|
"contextMenu":{
|
||||||
|
"value": ["Shutdown", "Reboot", "Suspend", "Hibernate", "Lock", "Logout", "SwitchUser", "PowerSettings"],
|
||||||
|
"serial": 0,
|
||||||
|
"flags": [],
|
||||||
|
"name": "ContextMenu",
|
||||||
|
"name[zh_CN]": "电源按钮右键菜单",
|
||||||
|
"description[zh_CN]": "电源界面的右键菜单内容,如需不显示某个选项,移除即可;默认值:\"Shutdown\", \"Reboot\", \"Suspend\", \"Hibernate\", \"Lock\", \"Logout\", \"SwitchUser\", \"PowerSettings\";",
|
||||||
|
"description":"",
|
||||||
|
"permissions":"readwrite",
|
||||||
|
"visibility":"private"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,3 +33,5 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins/system-trays)
|
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins/system-trays)
|
||||||
|
|
||||||
|
dconfig_meta_files(APPID org.deepin.dde.dock FILES ../../configs/org.deepin.dde.dock.plugin.power.json)
|
||||||
|
@ -37,6 +37,15 @@
|
|||||||
#define GSETTING_SHOW_SHUTDOWN "showShutdown"
|
#define GSETTING_SHOW_SHUTDOWN "showShutdown"
|
||||||
#define GSETTING_SHOW_LOCK "showLock"
|
#define GSETTING_SHOW_LOCK "showLock"
|
||||||
|
|
||||||
|
const QString MENU_SHUTDONW = "Shutdown";
|
||||||
|
const QString MENU_REBOOT = "Reboot";
|
||||||
|
const QString MENU_SUSPEND = "Suspend";
|
||||||
|
const QString MENU_HIBERNATE = "Hibernate";
|
||||||
|
const QString MENU_LOCK = "Lock";
|
||||||
|
const QString MENU_LOGOUT = "Logout";
|
||||||
|
const QString MENU_SWITCH_USER = "SwitchUser";
|
||||||
|
const QString MENU_POWER_SETTINGS = "PowerSettings";
|
||||||
|
|
||||||
DCORE_USE_NAMESPACE
|
DCORE_USE_NAMESPACE
|
||||||
using namespace Dock;
|
using namespace Dock;
|
||||||
|
|
||||||
@ -48,6 +57,7 @@ ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
|||||||
, m_powerManagerInter(new DBusPowerManager("com.deepin.daemon.PowerManager", "/com/deepin/daemon/PowerManager", QDBusConnection::systemBus(), this))
|
, m_powerManagerInter(new DBusPowerManager("com.deepin.daemon.PowerManager", "/com/deepin/daemon/PowerManager", QDBusConnection::systemBus(), this))
|
||||||
, m_gsettings(Utils::ModuleSettingsPtr("shutdown", QByteArray(), this))
|
, m_gsettings(Utils::ModuleSettingsPtr("shutdown", QByteArray(), this))
|
||||||
, m_sessionShellGsettings(Utils::SettingsPtr("com.deepin.dde.session-shell", "/com/deepin/dde/session-shell/", this))
|
, m_sessionShellGsettings(Utils::SettingsPtr("com.deepin.dde.session-shell", "/com/deepin/dde/session-shell/", this))
|
||||||
|
, m_dconfig(DConfig::create("org.deepin.dde.dock", "org.deepin.dde.dock.plugin.power", QString(), this))
|
||||||
{
|
{
|
||||||
m_tipsLabel->setVisible(false);
|
m_tipsLabel->setVisible(false);
|
||||||
m_tipsLabel->setAccessibleName("shutdown");
|
m_tipsLabel->setAccessibleName("shutdown");
|
||||||
@ -119,22 +129,40 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(itemKey);
|
Q_UNUSED(itemKey);
|
||||||
|
|
||||||
|
QStringList contextMenu = {
|
||||||
|
MENU_SHUTDONW,
|
||||||
|
MENU_REBOOT,
|
||||||
|
MENU_SUSPEND,
|
||||||
|
MENU_HIBERNATE,
|
||||||
|
MENU_LOCK,
|
||||||
|
MENU_LOGOUT,
|
||||||
|
MENU_SWITCH_USER,
|
||||||
|
MENU_POWER_SETTINGS
|
||||||
|
};
|
||||||
|
|
||||||
|
if (m_dconfig.data()->isValid()) {
|
||||||
|
contextMenu = m_dconfig.data()->value("contextMenu", contextMenu).toStringList();
|
||||||
|
}
|
||||||
|
|
||||||
QList<QVariant> items;
|
QList<QVariant> items;
|
||||||
items.reserve(6);
|
items.reserve(6);
|
||||||
|
|
||||||
QMap<QString, QVariant> shutdown;
|
QMap<QString, QVariant> shutdown;
|
||||||
if (!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_SHUTDOWN) && m_gsettings->get(GSETTING_SHOW_SHUTDOWN).toBool())) {
|
if ((!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_SHUTDOWN) && m_gsettings->get(GSETTING_SHOW_SHUTDOWN).toBool())) && contextMenu.contains(MENU_SHUTDONW)) {
|
||||||
shutdown["itemId"] = "Shutdown";
|
shutdown["itemId"] = "Shutdown";
|
||||||
shutdown["itemText"] = tr("Shut down");
|
shutdown["itemText"] = tr("Shut down");
|
||||||
shutdown["isActive"] = true;
|
shutdown["isActive"] = true;
|
||||||
items.push_back(shutdown);
|
items.push_back(shutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QVariant> reboot;
|
if (contextMenu.contains(MENU_REBOOT)) {
|
||||||
reboot["itemId"] = "Restart";
|
QMap<QString, QVariant> reboot;
|
||||||
reboot["itemText"] = tr("Reboot");
|
reboot["itemId"] = "Restart";
|
||||||
reboot["isActive"] = true;
|
reboot["itemText"] = tr("Reboot");
|
||||||
items.push_back(reboot);
|
reboot["isActive"] = true;
|
||||||
|
items.push_back(reboot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef DISABLE_POWER_OPTIONS
|
#ifndef DISABLE_POWER_OPTIONS
|
||||||
|
|
||||||
@ -145,7 +173,9 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
|||||||
;
|
;
|
||||||
if (can_sleep) {
|
if (can_sleep) {
|
||||||
QMap<QString, QVariant> suspend;
|
QMap<QString, QVariant> suspend;
|
||||||
if (!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_SUSPEND) && m_gsettings->get(GSETTING_SHOW_SUSPEND).toBool())) {
|
if ((!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_SUSPEND)
|
||||||
|
&& m_gsettings->get(GSETTING_SHOW_SUSPEND).toBool()))
|
||||||
|
&& contextMenu.contains(MENU_SUSPEND)) {
|
||||||
suspend["itemId"] = "Suspend";
|
suspend["itemId"] = "Suspend";
|
||||||
suspend["itemText"] = tr("Suspend");
|
suspend["itemText"] = tr("Suspend");
|
||||||
suspend["isActive"] = true;
|
suspend["isActive"] = true;
|
||||||
@ -153,12 +183,13 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool can_hibernate = enviromentVar.contains("POWER_CAN_HIBERNATE") ? QVariant(enviromentVar.value("POWER_CAN_HIBERNATE")).toBool()
|
bool can_hibernate = enviromentVar.contains("POWER_CAN_HIBERNATE") ?
|
||||||
: checkSwap() && m_powerManagerInter->CanHibernate();
|
QVariant(enviromentVar.value("POWER_CAN_HIBERNATE")).toBool() : checkSwap() && m_powerManagerInter->CanHibernate();
|
||||||
|
|
||||||
if (can_hibernate) {
|
if (can_hibernate) {
|
||||||
QMap<QString, QVariant> hibernate;
|
QMap<QString, QVariant> hibernate;
|
||||||
if (!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_HIBERNATE) && m_gsettings->get(GSETTING_SHOW_HIBERNATE).toBool())) {
|
if ((!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_HIBERNATE) && m_gsettings->get(GSETTING_SHOW_HIBERNATE).toBool()))
|
||||||
|
&& contextMenu.contains(MENU_HIBERNATE)) {
|
||||||
hibernate["itemId"] = "Hibernate";
|
hibernate["itemId"] = "Hibernate";
|
||||||
hibernate["itemText"] = tr("Hibernate");
|
hibernate["itemText"] = tr("Hibernate");
|
||||||
hibernate["isActive"] = true;
|
hibernate["isActive"] = true;
|
||||||
@ -169,18 +200,21 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QMap<QString, QVariant> lock;
|
QMap<QString, QVariant> lock;
|
||||||
if (!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_LOCK) && m_gsettings->get(GSETTING_SHOW_LOCK).toBool())) {
|
if ((!m_gsettings || (m_gsettings->keys().contains(GSETTING_SHOW_LOCK) && m_gsettings->get(GSETTING_SHOW_LOCK).toBool()))
|
||||||
|
&& contextMenu.contains(MENU_LOCK)) {
|
||||||
lock["itemId"] = "Lock";
|
lock["itemId"] = "Lock";
|
||||||
lock["itemText"] = tr("Lock");
|
lock["itemText"] = tr("Lock");
|
||||||
lock["isActive"] = true;
|
lock["isActive"] = true;
|
||||||
items.push_back(lock);
|
items.push_back(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QVariant> logout;
|
if (contextMenu.contains(MENU_LOGOUT)) {
|
||||||
logout["itemId"] = "Logout";
|
QMap<QString, QVariant> logout;
|
||||||
logout["itemText"] = tr("Log out");
|
logout["itemId"] = "Logout";
|
||||||
logout["isActive"] = true;
|
logout["itemText"] = tr("Log out");
|
||||||
items.push_back(logout);
|
logout["isActive"] = true;
|
||||||
|
items.push_back(logout);
|
||||||
|
}
|
||||||
|
|
||||||
if (!QFile::exists(ICBC_CONF_FILE)) {
|
if (!QFile::exists(ICBC_CONF_FILE)) {
|
||||||
// 读取com.deepin.dde.session-shell切换用户配置项
|
// 读取com.deepin.dde.session-shell切换用户配置项
|
||||||
@ -195,9 +229,10 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 和登录锁屏界面的逻辑保持一致
|
// 和登录锁屏界面的逻辑保持一致
|
||||||
if (AlwaysShow == switchUserConfig ||
|
if ((AlwaysShow == switchUserConfig ||
|
||||||
(OnDemand == switchUserConfig &&
|
(OnDemand == switchUserConfig &&
|
||||||
(DBusAccount().userList().count() > 1 || DSysInfo::uosType() == DSysInfo::UosType::UosServer))) {
|
(DBusAccount().userList().count() > 1 || DSysInfo::uosType() == DSysInfo::UosType::UosServer)))
|
||||||
|
&& contextMenu.contains(MENU_SWITCH_USER)) {
|
||||||
QMap<QString, QVariant> switchUser;
|
QMap<QString, QVariant> switchUser;
|
||||||
switchUser["itemId"] = "SwitchUser";
|
switchUser["itemId"] = "SwitchUser";
|
||||||
switchUser["itemText"] = tr("Switch account");
|
switchUser["itemText"] = tr("Switch account");
|
||||||
@ -206,11 +241,13 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_POWER_OPTIONS
|
#ifndef DISABLE_POWER_OPTIONS
|
||||||
QMap<QString, QVariant> power;
|
if (contextMenu.contains(MENU_POWER_SETTINGS)) {
|
||||||
power["itemId"] = "power";
|
QMap<QString, QVariant> power;
|
||||||
power["itemText"] = tr("Power settings");
|
power["itemId"] = "power";
|
||||||
power["isActive"] = true;
|
power["itemText"] = tr("Power settings");
|
||||||
items.push_back(power);
|
power["isActive"] = true;
|
||||||
|
items.push_back(power);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,11 @@
|
|||||||
#include "shutdownwidget.h"
|
#include "shutdownwidget.h"
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
|
#include <DConfig>
|
||||||
|
|
||||||
|
DCORE_USE_NAMESPACE
|
||||||
|
|
||||||
class DBusPowerManager;
|
class DBusPowerManager;
|
||||||
|
|
||||||
@ -116,6 +121,7 @@ private:
|
|||||||
DBusPowerManager* m_powerManagerInter;
|
DBusPowerManager* m_powerManagerInter;
|
||||||
const QGSettings *m_gsettings;
|
const QGSettings *m_gsettings;
|
||||||
const QGSettings *m_sessionShellGsettings;
|
const QGSettings *m_sessionShellGsettings;
|
||||||
|
QSharedPointer<DConfig> m_dconfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHUTDOWNPLUGIN_H
|
#endif // SHUTDOWNPLUGIN_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user