127 lines
4.0 KiB
Diff
127 lines
4.0 KiB
Diff
|
From f3f824c85811596bc8886b86f31b5f37c2480736 Mon Sep 17 00:00:00 2001
|
||
|
From: Palo Kisa <palo.kisa@gmail.com>
|
||
|
Date: Wed, 28 Jun 2017 09:25:43 +0200
|
||
|
Subject: [PATCH] lxqtpower: Allow disabling of lxqt-session provider
|
||
|
|
||
|
To allow usage of LXQt::Power object inside of lxqt-session (handling
|
||
|
the called method of LXQtSessionProvider) we need to avoid recurently
|
||
|
calling lxqt-session itself.
|
||
|
---
|
||
|
lxqtpower/lxqtpower.cpp | 10 ++++++++--
|
||
|
lxqtpower/lxqtpower.h | 12 ++++++++++--
|
||
|
lxqtpower/lxqtpowerproviders.cpp | 36 +++++++++++++++++++++++++-----------
|
||
|
3 files changed, 43 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/lxqtpower/lxqtpower.cpp b/lxqtpower/lxqtpower.cpp
|
||
|
index 742793b..07cd19e 100644
|
||
|
--- a/lxqtpower/lxqtpower.cpp
|
||
|
+++ b/lxqtpower/lxqtpower.cpp
|
||
|
@@ -33,15 +33,21 @@
|
||
|
|
||
|
using namespace LXQt;
|
||
|
|
||
|
-Power::Power(QObject *parent) :
|
||
|
+Power::Power(bool useLxqtSessionProvider, QObject * parent /*= nullptr*/) :
|
||
|
QObject(parent)
|
||
|
{
|
||
|
mProviders.append(new CustomProvider(this));
|
||
|
+ if (useLxqtSessionProvider)
|
||
|
+ mProviders.append(new LXQtProvider(this));
|
||
|
mProviders.append(new SystemdProvider(this));
|
||
|
mProviders.append(new UPowerProvider(this));
|
||
|
mProviders.append(new ConsoleKitProvider(this));
|
||
|
mProviders.append(new LxSessionProvider(this));
|
||
|
- mProviders.append(new LXQtProvider(this));
|
||
|
+}
|
||
|
+
|
||
|
+Power::Power(QObject * parent /*= nullptr*/)
|
||
|
+ : Power(true, parent)
|
||
|
+{
|
||
|
}
|
||
|
|
||
|
|
||
|
diff --git a/lxqtpower/lxqtpower.h b/lxqtpower/lxqtpower.h
|
||
|
index f738b46..98b021e 100644
|
||
|
--- a/lxqtpower/lxqtpower.h
|
||
|
+++ b/lxqtpower/lxqtpower.h
|
||
|
@@ -56,8 +56,16 @@ class LXQT_API Power : public QObject
|
||
|
PowerSuspend /// Suspend the computer
|
||
|
};
|
||
|
|
||
|
- /// Constructs a Power with parent.
|
||
|
- explicit Power(QObject *parent = 0);
|
||
|
+ /*!
|
||
|
+ * Constructs the Power object.
|
||
|
+ * \param useLxqtSessionProvider indicates if the DBus methods
|
||
|
+ * provided by lxqt-session should be considered. This is useful to
|
||
|
+ * avoid recursion if the lxqt-session wants to provide some of the
|
||
|
+ * methods by itself with internal use of this object.
|
||
|
+ */
|
||
|
+ explicit Power(bool useLxqtSessionProvider, QObject *parent = nullptr);
|
||
|
+ /// Constructs a Power with using the lxqt-session provider.
|
||
|
+ explicit Power(QObject *parent = nullptr);
|
||
|
|
||
|
/// Destroys the object.
|
||
|
virtual ~Power();
|
||
|
diff --git a/lxqtpower/lxqtpowerproviders.cpp b/lxqtpower/lxqtpowerproviders.cpp
|
||
|
index 1304e05..3907cc7 100644
|
||
|
--- a/lxqtpower/lxqtpowerproviders.cpp
|
||
|
+++ b/lxqtpower/lxqtpowerproviders.cpp
|
||
|
@@ -500,31 +500,45 @@ LXQtProvider::~LXQtProvider()
|
||
|
|
||
|
bool LXQtProvider::canAction(Power::Action action) const
|
||
|
{
|
||
|
+ QString command;
|
||
|
switch (action)
|
||
|
{
|
||
|
case Power::PowerLogout:
|
||
|
- // there can be case when razo-session does not run
|
||
|
- return dbusCall(LXQT_SERVICE, LXQT_PATH, LXQT_SERVICE,
|
||
|
- QDBusConnection::sessionBus(), "canLogout",
|
||
|
- PowerProvider::DontCheckDBUS);
|
||
|
+ command = "canLogout";
|
||
|
+ break;
|
||
|
+ case Power::PowerReboot:
|
||
|
+ command = "canReboot";
|
||
|
+ break;
|
||
|
+ case Power::PowerShutdown:
|
||
|
+ command = "canPowerOff";
|
||
|
+ break;
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
+
|
||
|
+ // there can be case when lxqtsession-session does not run
|
||
|
+ return dbusCall(LXQT_SERVICE, LXQT_PATH, LXQT_SERVICE,
|
||
|
+ QDBusConnection::sessionBus(), command,
|
||
|
+ PowerProvider::DontCheckDBUS);
|
||
|
}
|
||
|
|
||
|
|
||
|
bool LXQtProvider::doAction(Power::Action action)
|
||
|
{
|
||
|
QString command;
|
||
|
-
|
||
|
switch (action)
|
||
|
{
|
||
|
- case Power::PowerLogout:
|
||
|
- command = "logout";
|
||
|
- break;
|
||
|
-
|
||
|
- default:
|
||
|
- return false;
|
||
|
+ case Power::PowerLogout:
|
||
|
+ command = "logout";
|
||
|
+ break;
|
||
|
+ case Power::PowerReboot:
|
||
|
+ command = "reboot";
|
||
|
+ break;
|
||
|
+ case Power::PowerShutdown:
|
||
|
+ command = "powerOff";
|
||
|
+ break;
|
||
|
+ default:
|
||
|
+ return false;
|
||
|
}
|
||
|
|
||
|
return dbusCall(LXQT_SERVICE,
|