From 99dead6fe0e864ead73156859b38bfadad8012dc Mon Sep 17 00:00:00 2001 From: zhaoyingzhen Date: Tue, 17 Dec 2024 11:05:24 +0800 Subject: [PATCH] fix: Shutdown plugin miss menu function as title Log: as title Bug: BUG-294875 --- interfaces/constants.h | 1 + plugins/dde-dock/shutdown/shutdownplugin.cpp | 18 +++++++++--------- src/loader/pluginitem.cpp | 16 +++++++++++++++- src/loader/pluginitem.h | 3 ++- src/loader/widgetplugin.cpp | 2 +- src/protocol/plugin-manager-v1.xml | 4 +++- src/tray-wayland-integration/plugin.h | 2 +- src/tray-wayland-integration/pluginsurface.cpp | 4 ++-- 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/interfaces/constants.h b/interfaces/constants.h index afc9e9c6..8b60f3cc 100644 --- a/interfaces/constants.h +++ b/interfaces/constants.h @@ -253,6 +253,7 @@ const QString unDockMenuItemId = QStringLiteral("undock-item-id"); // 电源插件左键点击请求调出电源管理 const QString REQUEST_SHUTDOWN = QStringLiteral("requestShutdown"); +const QString SHUTDOWN_MENU_FLAG = QStringLiteral("Shutdown_"); } diff --git a/plugins/dde-dock/shutdown/shutdownplugin.cpp b/plugins/dde-dock/shutdown/shutdownplugin.cpp index d0ca9421..e9562c29 100644 --- a/plugins/dde-dock/shutdown/shutdownplugin.cpp +++ b/plugins/dde-dock/shutdown/shutdownplugin.cpp @@ -167,7 +167,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) QMap shutdown; if (contextMenu.contains(MENU_SHUTDOWN)) { - shutdown["itemId"] = "Shutdown"; + shutdown["itemId"] = SHUTDOWN_MENU_FLAG + "Shutdown"; shutdown["itemText"] = tr("Shut down"); shutdown["isActive"] = true; items.push_back(shutdown); @@ -175,7 +175,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) if (contextMenu.contains(MENU_UPDATE_SHUTDOWN)) { QMap map; - map["itemId"] = "UpdateAndShutdown"; + map["itemId"] = SHUTDOWN_MENU_FLAG + "UpdateAndShutdown"; map["itemText"] = tr("Update and Shut Down"); map["isActive"] = true; map["showReminder"] = true; @@ -184,7 +184,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) if (contextMenu.contains(MENU_REBOOT)) { QMap reboot; - reboot["itemId"] = "Restart"; + reboot["itemId"] = SHUTDOWN_MENU_FLAG + "Restart"; reboot["itemText"] = tr("Reboot"); reboot["isActive"] = true; items.push_back(reboot); @@ -192,7 +192,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) if (contextMenu.contains(MENU_UPDATE_REBOOT)) { QMap map; - map["itemId"] = "UpdateAndReboot"; + map["itemId"] = SHUTDOWN_MENU_FLAG + "UpdateAndReboot"; map["itemText"] = tr("Update and Reboot"); map["isActive"] = true; map["showReminder"] = true; @@ -209,7 +209,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) if (can_sleep) { QMap suspend; if (contextMenu.contains(MENU_SUSPEND)) { - suspend["itemId"] = "Suspend"; + suspend["itemId"] = SHUTDOWN_MENU_FLAG + "Suspend"; suspend["itemText"] = tr("Suspend"); suspend["isActive"] = true; items.push_back(suspend); @@ -222,7 +222,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) if (can_hibernate) { QMap hibernate; if (contextMenu.contains(MENU_HIBERNATE)) { - hibernate["itemId"] = "Hibernate"; + hibernate["itemId"] = SHUTDOWN_MENU_FLAG + "Hibernate"; hibernate["itemText"] = tr("Hibernate"); hibernate["isActive"] = true; items.push_back(hibernate); @@ -233,7 +233,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) QMap lock; if (contextMenu.contains(MENU_LOCK)) { - lock["itemId"] = "Lock"; + lock["itemId"] = SHUTDOWN_MENU_FLAG + "Lock"; lock["itemText"] = tr("Lock"); lock["isActive"] = true; items.push_back(lock); @@ -241,7 +241,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) if (contextMenu.contains(MENU_LOGOUT)) { QMap logout; - logout["itemId"] = "Logout"; + logout["itemId"] = SHUTDOWN_MENU_FLAG + "Logout"; logout["itemText"] = tr("Log out"); logout["isActive"] = true; items.push_back(logout); @@ -265,7 +265,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey) (DBusAccount().userList().count() > 1 || DSysInfo::uosType() == DSysInfo::UosType::UosServer))) && contextMenu.contains(MENU_SWITCH_USER)) { QMap switchUser; - switchUser["itemId"] = "SwitchUser"; + switchUser["itemId"] = SHUTDOWN_MENU_FLAG + "SwitchUser"; switchUser["itemText"] = tr("Switch user"); switchUser["isActive"] = true; items.push_back(switchUser); diff --git a/src/loader/pluginitem.cpp b/src/loader/pluginitem.cpp index 8e8565c0..267d9373 100644 --- a/src/loader/pluginitem.cpp +++ b/src/loader/pluginitem.cpp @@ -29,6 +29,11 @@ PluginItem::PluginItem(PluginsItemInterface *pluginItemInterface, const QString connect(m_menu, &QMenu::triggered, this, [this](QAction *action){ QString actionStr = action->data().toString(); + if (actionStr.startsWith(Dock::SHUTDOWN_MENU_FLAG)) { + handleShutDownMenu(actionStr); + return; + } + if (actionStr == Dock::dockMenuItemId || actionStr == Dock::unDockMenuItemId) { m_dbusProxy->setItemOnDock(DockQuickPlugins, m_itemKey, actionStr == Dock::dockMenuItemId); } else { @@ -239,6 +244,15 @@ void PluginItem::updatePopupSize(const QRect &rect) } } +void PluginItem::handleShutDownMenu(const QString &menuId) +{ + if (menuId.size() <= Dock::SHUTDOWN_MENU_FLAG.size()) + return; + + QString type = menuId.right(menuId.size() - Dock::SHUTDOWN_MENU_FLAG.size()); + Q_EMIT sigRequestShutdown(type); +} + void PluginItem::init() { winId(); @@ -331,7 +345,7 @@ bool PluginItem::executeCommand() qInfo() << "command: " << command; if (command == Dock::REQUEST_SHUTDOWN) { - emit sigRequestshutdown(); + emit sigRequestShutdown(QString()); return true; } diff --git a/src/loader/pluginitem.h b/src/loader/pluginitem.h index 7ec42f60..dc47f1c2 100644 --- a/src/loader/pluginitem.h +++ b/src/loader/pluginitem.h @@ -36,7 +36,7 @@ class PluginItem : public QWidget signals: void recvMouseEvent(int type); - void sigRequestshutdown(); + void sigRequestShutdown(const QString &type); protected: void mousePressEvent(QMouseEvent *e) override; @@ -62,6 +62,7 @@ class PluginItem : public QWidget private: void updatePopupSize(const QRect &rect); + void handleShutDownMenu(const QString &menuId); protected: QString m_itemKey; diff --git a/src/loader/widgetplugin.cpp b/src/loader/widgetplugin.cpp index 347fc8a2..cfc37ccf 100644 --- a/src/loader/widgetplugin.cpp +++ b/src/loader/widgetplugin.cpp @@ -335,7 +335,7 @@ void WidgetPlugin::initConnections(Plugin::EmbedPlugin *plugin, PluginItem *plug connect(plugin, &Plugin::EmbedPlugin::contentMarginChanged, pluginItem, &PluginItem::updatePluginContentMargin); connect(pluginItem, &PluginItem::recvMouseEvent, plugin, &Plugin::EmbedPlugin::pluginRecvMouseEvent); - connect(pluginItem, &PluginItem::sigRequestshutdown, plugin, &Plugin::EmbedPlugin::pluginRequestShutdown); + connect(pluginItem, &PluginItem::sigRequestShutdown, plugin, &Plugin::EmbedPlugin::pluginRequestShutdown); } int WidgetPlugin::getPluginFlags() diff --git a/src/protocol/plugin-manager-v1.xml b/src/protocol/plugin-manager-v1.xml index b70e10e5..5ddeb9ac 100644 --- a/src/protocol/plugin-manager-v1.xml +++ b/src/protocol/plugin-manager-v1.xml @@ -129,7 +129,9 @@ - + + + diff --git a/src/tray-wayland-integration/plugin.h b/src/tray-wayland-integration/plugin.h index e75bb69c..ecc21012 100644 --- a/src/tray-wayland-integration/plugin.h +++ b/src/tray-wayland-integration/plugin.h @@ -84,7 +84,7 @@ class EmbedPlugin : public QObject void requestMessage(const QString &msg); void pluginRecvMouseEvent(int type); void rawGlobalPosChanged(); - void pluginRequestShutdown(); + void pluginRequestShutdown(const QString &type); private: explicit EmbedPlugin(QWindow* window); diff --git a/src/tray-wayland-integration/pluginsurface.cpp b/src/tray-wayland-integration/pluginsurface.cpp index d2c6dd4d..581d2b39 100644 --- a/src/tray-wayland-integration/pluginsurface.cpp +++ b/src/tray-wayland-integration/pluginsurface.cpp @@ -42,8 +42,8 @@ PluginSurface::PluginSurface(PluginManagerIntegration *manager, QtWaylandClient: mouse_event(type); }); - connect(m_plugin, &EmbedPlugin::pluginRequestShutdown, this, [this] { - request_shutdown(); + connect(m_plugin, &EmbedPlugin::pluginRequestShutdown, this, [this](const QString &type){ + request_shutdown(type); }); }