Skip to content

Commit

Permalink
fix: Shutdown plugin miss menu function
Browse files Browse the repository at this point in the history
as title

Log: as title
Bug: BUG-294875
  • Loading branch information
yixinshark committed Dec 17, 2024
1 parent fdcef9e commit bbcd974
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions interfaces/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const QString unDockMenuItemId = QStringLiteral("undock-item-id");

// 电源插件左键点击请求调出电源管理
const QString REQUEST_SHUTDOWN = QStringLiteral("requestShutdown");
const QString SHUTDOWN_MENU_FLAG = QStringLiteral("Shutdown_");

}

Expand Down
18 changes: 9 additions & 9 deletions plugins/dde-dock/shutdown/shutdownplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,15 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)

QMap<QString, QVariant> 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);
}

if (contextMenu.contains(MENU_UPDATE_SHUTDOWN)) {
QMap<QString, QVariant> map;
map["itemId"] = "UpdateAndShutdown";
map["itemId"] = SHUTDOWN_MENU_FLAG + "UpdateAndShutdown";
map["itemText"] = tr("Update and Shut Down");
map["isActive"] = true;
map["showReminder"] = true;
Expand All @@ -184,15 +184,15 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)

if (contextMenu.contains(MENU_REBOOT)) {
QMap<QString, QVariant> reboot;
reboot["itemId"] = "Restart";
reboot["itemId"] = SHUTDOWN_MENU_FLAG + "Restart";
reboot["itemText"] = tr("Reboot");
reboot["isActive"] = true;
items.push_back(reboot);
}

if (contextMenu.contains(MENU_UPDATE_REBOOT)) {
QMap<QString, QVariant> map;
map["itemId"] = "UpdateAndReboot";
map["itemId"] = SHUTDOWN_MENU_FLAG + "UpdateAndReboot";
map["itemText"] = tr("Update and Reboot");
map["isActive"] = true;
map["showReminder"] = true;
Expand All @@ -209,7 +209,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
if (can_sleep) {
QMap<QString, QVariant> 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);
Expand All @@ -222,7 +222,7 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
if (can_hibernate) {
QMap<QString, QVariant> 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);
Expand All @@ -233,15 +233,15 @@ const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)

QMap<QString, QVariant> 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);
}

if (contextMenu.contains(MENU_LOGOUT)) {
QMap<QString, QVariant> logout;
logout["itemId"] = "Logout";
logout["itemId"] = SHUTDOWN_MENU_FLAG + "Logout";
logout["itemText"] = tr("Log out");
logout["isActive"] = true;
items.push_back(logout);
Expand All @@ -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<QString, QVariant> switchUser;
switchUser["itemId"] = "SwitchUser";
switchUser["itemId"] = SHUTDOWN_MENU_FLAG + "SwitchUser";
switchUser["itemText"] = tr("Switch user");
switchUser["isActive"] = true;
items.push_back(switchUser);
Expand Down
16 changes: 15 additions & 1 deletion src/loader/pluginitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -331,7 +345,7 @@ bool PluginItem::executeCommand()
qInfo() << "command: " << command;

if (command == Dock::REQUEST_SHUTDOWN) {
emit sigRequestshutdown();
emit sigRequestShutdown(QString());
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/loader/pluginitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,6 +62,7 @@ class PluginItem : public QWidget

private:
void updatePopupSize(const QRect &rect);
void handleShutDownMenu(const QString &menuId);

protected:
QString m_itemKey;
Expand Down
2 changes: 1 addition & 1 deletion src/loader/widgetplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion src/protocol/plugin-manager-v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
<request name="dcc_icon" >
<arg name="type" type="string"/>
</request>
<request name="request_shutdown"/>
<request name="request_shutdown">
<arg name="type" type="string"/>
</request>
<request name="source_size" >
<arg name="width" type="int"/>
<arg name="height" type="int"/>
Expand Down
2 changes: 1 addition & 1 deletion src/tray-wayland-integration/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/tray-wayland-integration/pluginsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down

0 comments on commit bbcd974

Please sign in to comment.