feat: 规范代码中直接调用系统命令的部分

代码中减少直接使用QProcess调用命令的方式,这种DBus的使用DDBusSender就好了

Log:
Change-Id: I7113fcd61fc5bf06e5a7b3bb073fd1a2d2c154ea
This commit is contained in:
Fanpengcheng 2020-12-10 17:10:59 +08:00
parent 01529fea58
commit eb24a50f32
3 changed files with 41 additions and 13 deletions

View File

@ -23,6 +23,7 @@
#include "../widgets/tipswidget.h"
#include <DWindowManagerHelper>
#include <DDBusSender>
#include <QIcon>
@ -140,7 +141,13 @@ void MultitaskingPlugin::invokedMenuItem(const QString &itemKey, const QString &
Q_UNUSED(checked)
if (menuId == "multitasking") {
QProcess::startDetached("dbus-send --session --dest=com.deepin.wm --print-reply /com/deepin/wm com.deepin.wm.PerformAction int32:1");
DDBusSender()
.service("com.deepin.wm")
.interface("com.deepin.wm")
.path("/com/deepin/wm")
.method(QString("PerformAction"))
.arg(1)
.call();
} else if (menuId == "remove") {
pluginStateSwitched();
}

View File

@ -27,6 +27,8 @@
#include <QIcon>
#include <QGSettings>
#include <DDBusSender>
#define PLUGIN_STATE_KEY "enable"
#define DELAYTIME (20 * 1000)
@ -143,8 +145,15 @@ void PowerPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId,
Q_UNUSED(itemKey)
Q_UNUSED(checked)
if (menuId == "power")
QProcess::startDetached("dbus-send --print-reply --dest=com.deepin.dde.ControlCenter /com/deepin/dde/ControlCenter com.deepin.dde.ControlCenter.ShowModule \"string:power\"");
if (menuId == "power") {
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter")
.method(QString("ShowModule"))
.arg(QString("power"))
.call();
}
}
void PowerPlugin::refreshIcon(const QString &itemKey)

View File

@ -25,6 +25,7 @@
#include "../widgets/tipswidget.h"
#include <DSysInfo>
#include <DDBusSender>
#include <QIcon>
#include <QSettings>
@ -200,8 +201,15 @@ void ShutdownPlugin::invokedMenuItem(const QString &itemKey, const QString &menu
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 200);
if (menuId == "power")
QProcess::startDetached("dbus-send --print-reply --dest=com.deepin.dde.ControlCenter /com/deepin/dde/ControlCenter com.deepin.dde.ControlCenter.ShowModule \"string:power\"");
if (menuId == "power") {
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter")
.method(QString("ShowModule"))
.arg(QString("power"))
.call();
}
else if (menuId == "Lock") {
if (QFile::exists(ICBC_CONF_FILE)) {
QDBusMessage send = QDBusMessage::createMethodCall("com.deepin.dde.lockFront", "/com/deepin/dde/lockFront", "com.deepin.dde.lockFront", "SwitchTTYAndShow");
@ -212,17 +220,21 @@ void ShutdownPlugin::invokedMenuItem(const QString &itemKey, const QString &menu
#endif
} else {
QProcess::startDetached("dbus-send", QStringList() << "--print-reply"
<< "--dest=com.deepin.dde.lockFront"
<< "/com/deepin/dde/lockFront"
<< QString("com.deepin.dde.lockFront.Show"));
DDBusSender()
.service("com.deepin.dde.lockFront")
.interface("com.deepin.dde.lockFront")
.path("/com/deepin/dde/lockFront")
.method(QString("Show"))
.call();
}
}
else
QProcess::startDetached("dbus-send", QStringList() << "--print-reply"
<< "--dest=com.deepin.dde.shutdownFront"
<< "/com/deepin/dde/shutdownFront"
<< QString("com.deepin.dde.shutdownFront.%1").arg(menuId));
DDBusSender()
.service("com.deepin.dde.shutdownFront")
.interface("com.deepin.dde.shutdownFront")
.path("/com/deepin/dde/shutdownFront")
.method(QString(menuId))
.call();
}
void ShutdownPlugin::displayModeChanged(const Dock::DisplayMode displayMode)