File PowerManagementConnector.diff of Package powerdevil
--- daemon/CMakeLists.txt 2008/11/11 10:25:42 1.1
+++ daemon/CMakeLists.txt 2008/11/11 10:42:00
@@ -11,6 +11,7 @@
TimerBasedPoller.cpp
PollSystemLoader.cpp
SuspensionLockHandler.cpp
+ PowerManagementConnector.cpp
)
kde4_add_kcfg_files(kded_powerdevil_SRCS ../PowerDevilSettings.kcfgc)
@@ -24,6 +25,9 @@
qt4_add_dbus_interface(kded_powerdevil_SRCS ${ksmserver_xml} ksmserver_interface )
qt4_add_dbus_adaptor( kded_powerdevil_SRCS org.kde.PowerDevil.xml PowerDevilDaemon.h PowerDevilDaemon )
+qt4_add_dbus_adaptor( kded_powerdevil_SRCS ${DBUS_INTERFACES_INSTALL_DIR}/org.kde.Solid.PowerManagement.xml PowerManagementConnector.h PowerManagementConnector )
+qt4_add_dbus_adaptor( kded_powerdevil_SRCS ${DBUS_INTERFACES_INSTALL_DIR}/org.kde.Solid.PowerManagement.Inhibit.xml PowerManagementConnector.h PowerManagementConnector powermanagementinhibitadaptor PowerManagementInhibitAdaptor )
+
kde4_add_plugin( kded_powerdevil
${kded_powerdevil_SRCS}
)
--- daemon/PowerDevilDaemon.cpp 2008/11/11 10:26:55 1.1
+++ daemon/PowerDevilDaemon.cpp 2008/11/11 10:28:13
@@ -41,6 +41,7 @@
#include "PowerDevilSettings.h"
#include "powerdeviladaptor.h"
+#include "PowerManagementConnector.h"
#include "PollSystemLoader.h"
#include "SuspensionLockHandler.h"
@@ -173,6 +174,7 @@
//DBus
new PowerDevilAdaptor(this);
+ new PowerManagementConnector(this);
// This gets registered to avoid double copies.
QDBusConnection::sessionBus().registerService("org.kde.powerdevilsystem");
--- daemon/PowerManagementConnector.h 2008/11/11 10:28:50 1.1
+++ daemon/PowerManagementConnector.h 2008/11/11 10:29:15
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Kevin Ottens <ervin@kde.org> *
+ * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ ***************************************************************************/
+
+#ifndef POWERMANAGEMENTCONNECTOR_H
+#define POWERMANAGEMENTCONNECTOR_H
+
+#include <QtCore/QObject>
+#include <QtCore/QMap>
+#include <QtCore/QMultiMap>
+
+#include <QtDBus/QDBusMessage>
+
+#include "PowerDevilDaemon.h"
+
+class PowerManagementConnector : public QObject
+{
+ Q_OBJECT
+
+public:
+ PowerManagementConnector(PowerDevilDaemon *parent);
+
+ bool CanHibernate();
+ bool CanSuspend();
+
+ bool GetPowerSaveStatus();
+
+ void Suspend();
+ void Hibernate();
+
+ bool HasInhibit();
+
+ int Inhibit(const QString &application, const QString &reason);
+ void UnInhibit(int cookie);
+ void ForceUnInhibitAll();
+
+signals:
+ void CanSuspendChanged(bool canSuspend);
+ void CanHibernateChanged(bool canHibernate);
+ void PowerSaveStatusChanged(bool savePower);
+
+ void HasInhibitChanged(bool hasInhibit);
+
+private slots:
+ void _k_stateChanged(int battery, bool plugged);
+
+private:
+ PowerDevilDaemon *m_daemon;
+
+
+};
+
+#endif /*POWERMANAGEMENTCONNECTOR_H*/
--- daemon/PowerManagementConnector.cpp 2008/11/11 10:28:53 1.1
+++ daemon/PowerManagementConnector.cpp 2008/11/11 10:29:11
@@ -0,0 +1,107 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Kevin Ottens <ervin@kde.org> *
+ * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
+ **************************************************************************/
+
+#include "PowerManagementConnector.h"
+
+#include "SuspensionLockHandler.h"
+
+#include <solid/control/powermanager.h>
+
+#include "powermanagementadaptor.h"
+#include "powermanagementinhibitadaptor.h"
+
+PowerManagementConnector::PowerManagementConnector(PowerDevilDaemon *parent)
+ : QObject(parent), m_daemon(parent)
+{
+ new PowerManagementAdaptor(this);
+ new PowerManagementInhibitAdaptor(this);
+
+ QDBusConnection c = QDBusConnection::sessionBus();
+
+ c.registerService("org.kde.Solid.PowerManagement");
+ c.registerObject("/org/kde/Solid/PowerManagement", this);
+
+ c.registerService("org.kde.Solid.PowerManagement.Inhibit");
+ c.registerObject("/org/kde/Solid/PowerManagement/Inhibit", this);
+
+ connect(m_daemon, SIGNAL(stateChanged(int, bool)),
+ this, SLOT(_k_stateChanged(int, bool)));
+ connect(m_daemon->lockHandler(), SIGNAL(inhibitChanged(bool)),
+ this, SIGNAL(HasInhibitChanged(bool)));
+}
+
+bool PowerManagementConnector::CanHibernate()
+{
+ Solid::Control::PowerManager::SuspendMethods methods
+ = Solid::Control::PowerManager::supportedSuspendMethods();
+
+ return methods & Solid::Control::PowerManager::ToDisk;
+}
+
+bool PowerManagementConnector::CanSuspend()
+{
+ Solid::Control::PowerManager::SuspendMethods methods
+ = Solid::Control::PowerManager::supportedSuspendMethods();
+
+ return methods & Solid::Control::PowerManager::ToRam;
+}
+
+bool PowerManagementConnector::GetPowerSaveStatus()
+{
+ return Solid::Control::PowerManager::acAdapterState() == Solid::Control::PowerManager::Unplugged;
+}
+
+void PowerManagementConnector::Suspend()
+{
+ m_daemon->suspend(PowerDevilDaemon::S2Ram);
+}
+
+void PowerManagementConnector::Hibernate()
+{
+ m_daemon->suspend(PowerDevilDaemon::S2Disk);
+}
+
+bool PowerManagementConnector::HasInhibit()
+{
+ return m_daemon->lockHandler()->hasInhibit();
+}
+
+int PowerManagementConnector::Inhibit(const QString &application, const QString &reason)
+{
+ return m_daemon->lockHandler()->inhibit(application, reason);
+}
+
+void PowerManagementConnector::UnInhibit(int cookie)
+{
+ m_daemon->lockHandler()->releaseInhibiton(cookie);
+}
+
+void PowerManagementConnector::ForceUnInhibitAll()
+{
+ m_daemon->lockHandler()->releaseAllInhibitions();
+}
+
+void PowerManagementConnector::_k_stateChanged(int battery, bool plugged)
+{
+ Q_UNUSED(battery)
+ emit PowerSaveStatusChanged(!plugged);
+}
+
+#include "PowerManagementConnector.moc"