[kde-workspace] update the systemd PowerDevil Policy Agent patch to match the upstream

Lukas Tinkl ltinkl at fedoraproject.org
Fri Sep 21 16:02:19 UTC 2012


commit e6e513c4a887c068aa98ed55b3754fdcd0458af0
Author: Lukas Tinkl <lukas at kde.org>
Date:   Fri Sep 21 18:02:19 2012 +0200

    update the systemd PowerDevil Policy Agent patch to match the upstream
    
      version (part of KDE 4.9.2)
    - update clock applets on system date/time changes

 kde-workspace-4.9.2-kcmclock.patch   |  180 +++++++++++++++
 kde-workspace.spec                   |   17 +-
 powerdevil-systemd-policyagent.patch |  407 +++++++++++++++++++---------------
 3 files changed, 423 insertions(+), 181 deletions(-)
---
diff --git a/kde-workspace-4.9.2-kcmclock.patch b/kde-workspace-4.9.2-kcmclock.patch
new file mode 100644
index 0000000..3b1bece
--- /dev/null
+++ b/kde-workspace-4.9.2-kcmclock.patch
@@ -0,0 +1,180 @@
+commit 40e9065ebc3b0f0549943b05778bc008e51012ea
+Author: Lukas Tinkl <lukas at kde.org>
+Date:   Fri Sep 21 14:50:56 2012 +0200
+
+    propagate changes from the Date/Time control module (kcmclock)
+    
+    by sending a DBUS signal "clockUpdated" which interested parties
+    can react to.
+    
+    Fix the "time" dataengine to react to that signal.
+    
+    Also tweak the analog/digital clocks so that they react
+    on updated data (I made sure no unnecessary repaints are made).
+    
+    Fix the analog clock to update every minute at most (60000 milliseconds,
+    not 6000 ;)
+
+diff --git a/kcontrol/dateandtime/dtime.cpp b/kcontrol/dateandtime/dtime.cpp
+index 7d8aa40..11c7a46 100644
+--- a/kcontrol/dateandtime/dtime.cpp
++++ b/kcontrol/dateandtime/dtime.cpp
+@@ -122,14 +122,9 @@ Dtime::Dtime(QWidget * parent)
+ 
+ void Dtime::currentZone()
+ {
+-    QByteArray result(100, '\0');
+-
+-    time_t now = ::time(0);
+-    tzset();
+-    strftime(result.data(), result.size(), "%Z", localtime(&now));
+     m_local->setText(i18n("Current local time zone: %1 (%2)",
+                           KTimeZoneWidget::displayName(KSystemTimeZones::local()),
+-                          QLatin1String(result)));
++                          QString::fromUtf8(KSystemTimeZones::local().abbreviations().first())));
+ }
+ 
+ void Dtime::serverTimeCheck() {
+diff --git a/kcontrol/dateandtime/main.cpp b/kcontrol/dateandtime/main.cpp
+index 62fedc4..2fa0f3e 100644
+--- a/kcontrol/dateandtime/main.cpp
++++ b/kcontrol/dateandtime/main.cpp
+@@ -100,6 +100,10 @@ void KclockModule::save()
+         dtime->processHelperErrors(reply.errorCode());
+     }
+   }
++  else {
++      QDBusMessage msg = QDBusMessage::createSignal("/org/kde/kcmshell_clock", "org.kde.kcmshell_clock", "clockUpdated");
++      QDBusConnection::sessionBus().send(msg);
++  }
+ 
+   // NOTE: super nasty hack #1
+   // Try to work around time mismatch between KSystemTimeZones' update of local
+@@ -108,19 +112,9 @@ void KclockModule::save()
+   // local timezone was found.
+   QTimer::singleShot(5000, this, SLOT(load()));
+ 
+-  // setDisable(false) happens in load(), since QTimer::singleShot is non-blocking
++  // setDisabled(false) happens in load(), since QTimer::singleShot is non-blocking
+ }
+ 
+-void KclockModule::slotDateTimeHelperFinished(int exitCode)
+-{
+-    dtime->processHelperErrors( exitCode );
+-#if 0
+-  // Tell the clock applet about the change so that it can update its timezone
+-  QDBusInterface clock("org.kde.kicker", "/Applets/Clock", "org.kde.kicker.ClockApplet");
+-  clock.call("reconfigure");
+-#endif
+-
+-}
+ void KclockModule::load()
+ {
+   dtime->load();
+diff --git a/kcontrol/dateandtime/main.h b/kcontrol/dateandtime/main.h
+index 11a4190..c1e5234 100644
+--- a/kcontrol/dateandtime/main.h
++++ b/kcontrol/dateandtime/main.h
+@@ -34,11 +34,9 @@ class KclockModule : public KCModule
+ 
+ public:
+   KclockModule(QWidget *parent, const QVariantList &);
+-  
++
+   void	save();
+   void	load();
+-private Q_SLOTS:
+-  void slotDateTimeHelperFinished(int exitCode);
+ 
+ private:
+   QTabWidget   *tab;
+diff --git a/plasma/generic/applets/analog-clock/clock.cpp b/plasma/generic/applets/analog-clock/clock.cpp
+index 799bb83..8cb5b6a 100644
+--- a/plasma/generic/applets/analog-clock/clock.cpp
++++ b/plasma/generic/applets/analog-clock/clock.cpp
+@@ -94,7 +94,7 @@ void Clock::connectToEngine()
+     if (m_showSecondHand) {
+         timeEngine->connectSource(currentTimezone(), this, 500);
+     } else {
+-        timeEngine->connectSource(currentTimezone(), this, 6000, Plasma::AlignToMinute);
++        timeEngine->connectSource(currentTimezone(), this, 60000, Plasma::AlignToMinute);
+     }
+ }
+ 
+@@ -152,16 +152,7 @@ void Clock::dataUpdated(const QString& source, const Plasma::DataEngine::Data &d
+ {
+     Q_UNUSED(source);
+     m_time = data["Time"].toTime();
+-
+-    if (m_time.minute() == lastTimeSeen().minute() &&
+-        (!m_showSecondHand || m_time.second() == lastTimeSeen().second())) {
+-        // avoid unnecessary repaints
+-        return;
+-    }
+-
+-    if (m_time.minute() != lastTimeSeen().minute() && m_repaintCache == RepaintNone) {
+-        m_repaintCache = RepaintHands;
+-    }
++    m_repaintCache = RepaintHands;
+ 
+     if (Plasma::ToolTipManager::self()->isVisible(this)) {
+         updateTipContent();
+@@ -224,7 +215,7 @@ void Clock::changeEngineTimezone(const QString &oldTimezone, const QString &newT
+     if (m_showSecondHand) {
+         timeEngine->connectSource(newTimezone, this, 500);
+     } else {
+-        timeEngine->connectSource(newTimezone, this, 6000, Plasma::AlignToMinute);
++        timeEngine->connectSource(newTimezone, this, 60000, Plasma::AlignToMinute);
+     }
+ 
+     if (m_showingTimezone != (m_showTimezoneString || shouldDisplayTimezone())) {
+diff --git a/plasma/generic/applets/digital-clock/clock.cpp b/plasma/generic/applets/digital-clock/clock.cpp
+index 1331776..708cb1e 100644
+--- a/plasma/generic/applets/digital-clock/clock.cpp
++++ b/plasma/generic/applets/digital-clock/clock.cpp
+@@ -246,18 +246,13 @@ void Clock::dataUpdated(const QString &source, const Plasma::DataEngine::Data &d
+     m_time = data["Time"].toTime();
+     m_date = data["Date"].toDate();
+ 
+-    // avoid unnecessary repaints
+-    if ((m_showSeconds && m_time.second() != lastTimeSeen().second()) ||
+-        m_time.minute() != lastTimeSeen().minute()) {
+-
+-        if (Plasma::ToolTipManager::self()->isVisible(this)) {
+-            updateTipContent();
+-        }
+-
+-        updateClockApplet(data);
+-        generatePixmap();
+-        update();
++    if (Plasma::ToolTipManager::self()->isVisible(this)) {
++        updateTipContent();
+     }
++
++    updateClockApplet(data);
++    generatePixmap();
++    update();
+ }
+ 
+ void Clock::createClockConfigurationInterface(KConfigDialog *parent)
+@@ -309,7 +304,7 @@ void Clock::createClockConfigurationInterface(KConfigDialog *parent)
+             parent, SLOT(settingsModified()));
+     connect(ui.useCustomShadowColor, SIGNAL(stateChanged(int)),
+             parent, SLOT(settingsModified()));
+-    connect(ui.plainClockShadowColor, SIGNAL(changed(QColor)), 
++    connect(ui.plainClockShadowColor, SIGNAL(changed(QColor)),
+             parent, SLOT(settingsModified()));
+     connect(ui.showTimeZone, SIGNAL(stateChanged(int)),
+             parent, SLOT(settingsModified()));
+diff --git a/plasma/generic/dataengines/time/timeengine.cpp b/plasma/generic/dataengines/time/timeengine.cpp
+index c05c923..2f69e8f 100644
+--- a/plasma/generic/dataengines/time/timeengine.cpp
++++ b/plasma/generic/dataengines/time/timeengine.cpp
+@@ -57,6 +57,7 @@ void TimeEngine::init()
+     QDBusConnection dbus = QDBusConnection::sessionBus();
+     dbus.connect(QString(), QString(), "org.kde.KTimeZoned", "configChanged", this, SLOT(tzConfigChanged()));
+     dbus.connect("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", "resumingFromSuspend", this, SLOT(clockSkewed()));
++    dbus.connect(QString(), "/org/kde/kcmshell_clock", "org.kde.kcmshell_clock", "clockUpdated", this, SLOT(clockSkewed()));
+ }
+ 
+ void TimeEngine::clockSkewed()
diff --git a/kde-workspace.spec b/kde-workspace.spec
index 0ea7d18..4eb3ec2 100644
--- a/kde-workspace.spec
+++ b/kde-workspace.spec
@@ -11,7 +11,7 @@
 Summary: KDE Workspace
 Name:    kde-workspace
 Version: 4.9.1
-Release: 5%{?dist}
+Release: 6%{?dist}
 
 License: GPLv2
 URL:     https://projects.kde.org/projects/kde/kde-workspace
@@ -122,12 +122,15 @@ Patch101: kde-workspace-4.9.2-devicenotifier-freespace.patch
 ## plasma active patches
 # adapted version of wac-html-widgets.patch
 Patch153: kde-workspace-4.7.80-wac-html-widgets.patch
+Patch154: kde-workspace-4.9.2-kcmclock.patch
+Patch155: powerdevil-systemd-policyagent.patch
+
 
 ## Fedora specific patches
 ## HAL-ectomy
 Patch200: kde-workspace-4.7.80-no_HAL.patch
 Patch210: kdebase-workspace-4.5.90-no_HAL2.patch
-Patch220: powerdevil-systemd-policyagent.patch
+
 
 # rhel patches
 Patch300: kde-workspace-4.8.3-webkit.patch
@@ -454,7 +457,9 @@ Requires: akonadi
 %patch59 -p1 -b fontconfigdir
 
 # upstream patches
-%patch100 -p1  -b .kwin_regression
+%patch100 -p1 -b .kwin_regression
+%patch154 -p1 -b .kcmclock
+%patch155 -p1 -b .powerdevil-systemd
 
 # plasma-active
 %patch153 -p1 -b .wac-html-widgets
@@ -462,7 +467,6 @@ Requires: akonadi
 # Fedora patches
 %patch200 -p1 -b .no_HAL
 %patch210 -p1 -b .no_HAL2
-%patch220 -p1 -b .powerdevil-systemd
 
 # rhel patches
 %if 0%{?rhel}
@@ -1007,6 +1011,11 @@ fi
 
 
 %changelog
+* Fri Sep 21 2012 Lukáš Tinkl <ltinkl at redhat.com> 4.9.1-6
+- update the systemd PowerDevil Policy Agent patch to match the upstream
+  version (part of KDE 4.9.2)
+- update clock applets on system date/time changes
+
 * Tue Sep 18 2012 Lukáš Tinkl <ltinkl at redhat.com> 4.9.1-5
 - fix device notifier Free Space meter
 
diff --git a/powerdevil-systemd-policyagent.patch b/powerdevil-systemd-policyagent.patch
index e41ac41..097d0f2 100644
--- a/powerdevil-systemd-policyagent.patch
+++ b/powerdevil-systemd-policyagent.patch
@@ -1,21 +1,19 @@
-diff --git a/powerdevil/daemon/CMakeLists.txt b/powerdevil/daemon/CMakeLists.txt
-index 35a4fd4..033a0d5 100644
---- a/powerdevil/daemon/CMakeLists.txt
-+++ b/powerdevil/daemon/CMakeLists.txt
-@@ -8,6 +8,11 @@ set(POWERDEVIL_CORE_VERSION_MINOR 1)
- set(POWERDEVIL_CORE_VERSION_MICRO 0)
- set(POWERDEVIL_CORE_VERSION_STRING ${POWERDEVIL_CORE_VERSION_MAJOR}.${POWERDEVIL_CORE_VERSION_MINOR}.${POWERDEVIL_CORE_VERSION_MICRO})
- 
-+option(POWERDEVIL_USE_SYSTEMD "Use systemd instead of ConsoleKit in PowerDevil" OFF)
-+if (POWERDEVIL_USE_SYSTEMD)
-+    add_definitions(-DPOWERDEVIL_USE_SYSTEMD=1)
-+endif ()
-+
- # Add bundled actions
- set(powerdevil_bundled_actions_SRCS
-     actions/bundled/suspendsession.cpp
+commit b58f080d393214f3ba01bab017f62f568b0390d4
+Author: Lukas Tinkl <lukas at kde.org>
+Date:   Fri Sep 21 14:58:32 2012 +0200
+
+    implement systemd support for PowerDevil Policy Agent
+    
+    This enables PowerDevil to react on active session changes
+    (correct locking, screen brightness) on systems w/o ConsoleKit,
+    like Fedora 18
+    
+    Fixes e.g. https://bugzilla.redhat.com/show_bug.cgi?id=849334
+    
+    REVIEW: 106506
+
 diff --git a/powerdevil/daemon/powerdevilpolicyagent.cpp b/powerdevil/daemon/powerdevilpolicyagent.cpp
-index 5ba595b..d2dbd73 100644
+index 5ba595b..d971721 100644
 --- a/powerdevil/daemon/powerdevilpolicyagent.cpp
 +++ b/powerdevil/daemon/powerdevilpolicyagent.cpp
 @@ -1,5 +1,6 @@
@@ -25,26 +23,23 @@ index 5ba595b..d2dbd73 100644
   *                                                                         *
   *   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  *
-@@ -20,6 +21,14 @@
+@@ -20,6 +21,12 @@
  
  #include "powerdevilpolicyagent.h"
  
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +#include <QtCore/QCoreApplication>
 +#include <QtDBus/QDBusObjectPath>
 +#include <QtDBus/QDBusArgument>
 +#include <QtCore/QMetaType>
 +#include <QtDBus/QDBusMetaType>
-+#endif
 +
  #include <QtDBus/QDBusConnection>
  #include <QtDBus/QDBusInterface>
  #include <QtDBus/QDBusPendingReply>
-@@ -29,13 +38,41 @@
+@@ -29,13 +36,39 @@
  #include <KGlobal>
  #include <KDebug>
  
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +struct NamedDBusObjectPath
 +{
 +    QString name;
@@ -68,7 +63,6 @@ index 5ba595b..d2dbd73 100644
 +    argument.endStructure();
 +    return argument;
 +}
-+#endif
 +
 +Q_DECLARE_METATYPE(NamedDBusObjectPath)
 +
@@ -83,31 +77,23 @@ index 5ba595b..d2dbd73 100644
      ~PolicyAgentHelper() {
          delete q;
      }
-@@ -55,11 +92,19 @@ PolicyAgent *PolicyAgent::instance()
+@@ -55,10 +88,12 @@ PolicyAgent *PolicyAgent::instance()
  
  PolicyAgent::PolicyAgent(QObject* parent)
      : QObject(parent)
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +    , m_sdAvailable(false)
-+#else
      , m_ckAvailable(false)
-+#endif
      , m_sessionIsBeingInterrupted(false)
      , m_lastCookie(0)
      , m_busWatcher(new QDBusServiceWatcher(this))
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +    , m_sdWatcher(new QDBusServiceWatcher(this))
-+#else
      , m_ckWatcher(new QDBusServiceWatcher(this))
-+#endif
  {
      Q_ASSERT(!s_globalPolicyAgent->q);
-     s_globalPolicyAgent->q = this;
-@@ -72,6 +117,22 @@ PolicyAgent::~PolicyAgent()
+@@ -72,19 +107,34 @@ PolicyAgent::~PolicyAgent()
  
  void PolicyAgent::init()
  {
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +    // Watch over the systemd service
 +    m_sdWatcher.data()->setConnection(QDBusConnection::systemBus());
 +    m_sdWatcher.data()->setWatchMode(QDBusServiceWatcher::WatchForUnregistration |
@@ -115,154 +101,238 @@ index 5ba595b..d2dbd73 100644
 +    m_sdWatcher.data()->addWatchedService(SYSTEMD_LOGIN1_SERVICE);
 +
 +    connect(m_sdWatcher.data(), SIGNAL(serviceRegistered(QString)),
-+            this, SLOT(onConsoleKitRegistered(QString)));
++            this, SLOT(onSessionHandlerRegistered(QString)));
 +    connect(m_sdWatcher.data(), SIGNAL(serviceUnregistered(QString)),
-+            this, SLOT(onConsoleKitUnregistered(QString)));
++            this, SLOT(onSessionHandlerUnregistered(QString)));
 +    // If it's up and running already, let's cache it
 +    if (QDBusConnection::systemBus().interface()->isServiceRegistered(SYSTEMD_LOGIN1_SERVICE)) {
-+        onConsoleKitRegistered(SYSTEMD_LOGIN1_SERVICE);
++        onSessionHandlerRegistered(SYSTEMD_LOGIN1_SERVICE);
 +    }
-+#else
++
      // Watch over the ConsoleKit service
      m_ckWatcher.data()->setConnection(QDBusConnection::sessionBus());
      m_ckWatcher.data()->setWatchMode(QDBusServiceWatcher::WatchForUnregistration |
-@@ -86,6 +147,7 @@ void PolicyAgent::init()
-     if (QDBusConnection::systemBus().interface()->isServiceRegistered("org.freedesktop.ConsoleKit")) {
-         onConsoleKitRegistered("org.freedesktop.ConsoleKit");
+                                      QDBusServiceWatcher::WatchForRegistration);
+-    m_ckWatcher.data()->addWatchedService("org.freedesktop.ConsoleKit");
++    m_ckWatcher.data()->addWatchedService(CONSOLEKIT_SERVICE);
+ 
+     connect(m_ckWatcher.data(), SIGNAL(serviceRegistered(QString)),
+-            this, SLOT(onConsoleKitRegistered(QString)));
++            this, SLOT(onSessionHandlerRegistered(QString)));
+     connect(m_ckWatcher.data(), SIGNAL(serviceUnregistered(QString)),
+-            this, SLOT(onConsoleKitUnregistered(QString)));
++            this, SLOT(onSessionHandlerUnregistered(QString)));
+     // If it's up and running already, let's cache it
+-    if (QDBusConnection::systemBus().interface()->isServiceRegistered("org.freedesktop.ConsoleKit")) {
+-        onConsoleKitRegistered("org.freedesktop.ConsoleKit");
++    if (QDBusConnection::systemBus().interface()->isServiceRegistered(CONSOLEKIT_SERVICE)) {
++        onSessionHandlerRegistered(CONSOLEKIT_SERVICE);
      }
-+#endif
  
      // Now set up our service watcher
-     m_busWatcher.data()->setConnection(QDBusConnection::sessionBus());
-@@ -95,8 +157,83 @@ void PolicyAgent::init()
+@@ -95,75 +145,176 @@ void PolicyAgent::init()
              this, SLOT(onServiceUnregistered(QString)));
  }
  
 -void PowerDevil::PolicyAgent::onConsoleKitRegistered(const QString& )
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +QString PolicyAgent::getNamedPathProperty(const QString &path, const QString &iface, const QString &prop) const
  {
+-    m_ckAvailable = true;
 +    QDBusMessage message = QDBusMessage::createMethodCall(SYSTEMD_LOGIN1_SERVICE, path,
 +                                                          QLatin1String("org.freedesktop.DBus.Properties"), QLatin1String("Get"));
 +    message << iface << prop;
 +    QDBusMessage reply = QDBusConnection::systemBus().call(message);
 +
-+    NamedDBusObjectPath namedPath;
-+    reply.arguments().at(0).value<QDBusVariant>().variant().value<QDBusArgument>() >> namedPath;
-+    return namedPath.path.path();
++    QVariantList args = reply.arguments();
++    if (!args.isEmpty()) {
++        NamedDBusObjectPath namedPath;
++        args.at(0).value<QDBusVariant>().variant().value<QDBusArgument>() >> namedPath;
++        return namedPath.path.path();
++    }
+ 
+-    // Otherwise, let's ask ConsoleKit
+-    QDBusInterface ckiface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager",
+-                           "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus());
++    return QString();
 +}
-+#endif
-+
-+void PolicyAgent::onConsoleKitRegistered(const QString& )
+ 
+-    QDBusPendingReply<QDBusObjectPath> sessionPath = ckiface.asyncCall("GetCurrentSession");
++void PolicyAgent::onSessionHandlerRegistered(const QString & serviceName)
 +{
-+#ifdef POWERDEVIL_USE_SYSTEMD
-+    m_sdAvailable = true;
++    if (serviceName == SYSTEMD_LOGIN1_SERVICE) {
++        m_sdAvailable = true;
+ 
+-    sessionPath.waitForFinished();
++        qRegisterMetaType<NamedDBusObjectPath>();
++        qDBusRegisterMetaType<NamedDBusObjectPath>();
+ 
+-    if (!sessionPath.isValid() || sessionPath.value().path().isEmpty()) {
+-        kDebug() << "The session is not registered with ck";
+-        m_ckAvailable = false;
+-        return;
+-    }
++        // get the current session
++        QDBusInterface managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, QDBusConnection::systemBus());
++        QDBusPendingReply<QDBusObjectPath> session = managerIface.asyncCall(QLatin1String("GetSessionByPID"), (quint32) QCoreApplication::applicationPid());
++        session.waitForFinished();
+ 
+-    m_ckSessionInterface = new QDBusInterface("org.freedesktop.ConsoleKit", sessionPath.value().path(),
+-                                              "org.freedesktop.ConsoleKit.Session", QDBusConnection::systemBus());
++        if (!session.isValid()) {
++            kDebug() << "The session is not registered with systemd";
++            m_sdAvailable = false;
++            return;
++        }
+ 
+-    if (!m_ckSessionInterface.data()->isValid()) {
+-        // As above
+-        kDebug() << "Can't contact iface";
+-        m_ckAvailable = false;
+-        return;
+-    }
++        QString sessionPath = session.value().path();
++        kDebug() << "Session path:" << sessionPath;
 +
-+    qRegisterMetaType<NamedDBusObjectPath>();
-+    qDBusRegisterMetaType<NamedDBusObjectPath>();
++        m_sdSessionInterface = new QDBusInterface(SYSTEMD_LOGIN1_SERVICE, sessionPath,
++                                                  SYSTEMD_LOGIN1_SESSION_IFACE, QDBusConnection::systemBus(), this);
++        if (!m_sdSessionInterface.data()->isValid()) {
++            // As above
++            kDebug() << "Can't contact session iface";
++            m_sdAvailable = false;
++            delete m_sdSessionInterface.data();
++            return;
++        }
+ 
+-    // Now let's obtain the seat
+-    QDBusPendingReply< QDBusObjectPath > seatPath = m_ckSessionInterface.data()->asyncCall("GetSeatId");
+-    seatPath.waitForFinished();
+ 
+-    if (!sessionPath.isValid() || sessionPath.value().path().isEmpty()) {
+-        kDebug() << "Unable to associate ck session with a seat";
+-        m_ckAvailable = false;
+-        return;
+-    }
++        // now let's obtain the seat
++        QString seatPath = getNamedPathProperty(sessionPath, SYSTEMD_LOGIN1_SESSION_IFACE, "Seat");
+ 
+-    if (!QDBusConnection::systemBus().connect("org.freedesktop.ConsoleKit", seatPath.value().path(),
+-                                              "org.freedesktop.ConsoleKit.Seat", "ActiveSessionChanged",
+-                                              this, SLOT(onConsoleKitActiveSessionChanged(QString)))) {
+-        kDebug() << "Unable to connect to ActiveSessionChanged";
+-        m_ckAvailable = false;
+-        return;
+-    }
++        if (seatPath.isEmpty() || seatPath == "/") {
++            kDebug() << "Unable to associate systemd session with a seat" << seatPath;
++            m_sdAvailable = false;
++            return;
++        }
+ 
+-    // Force triggering of active session changed
+-    QDBusMessage call = QDBusMessage::createMethodCall("org.freedesktop.ConsoleKit", seatPath.value().path(),
+-                                                       "org.freedesktop.ConsoleKit.Seat", "GetActiveSession");
+-    QDBusPendingReply< QDBusObjectPath > activeSession = QDBusConnection::systemBus().asyncCall(call);
+-    activeSession.waitForFinished();
++        // get the current seat
++        m_sdSeatInterface = new QDBusInterface(SYSTEMD_LOGIN1_SERVICE, seatPath,
++                                               SYSTEMD_LOGIN1_SEAT_IFACE, QDBusConnection::systemBus(), this);
+ 
+-    onConsoleKitActiveSessionChanged(activeSession.value().path());
++        if (!m_sdSeatInterface.data()->isValid()) {
++            // As above
++            kDebug() << "Can't contact seat iface";
++            m_sdAvailable = false;
++            delete m_sdSeatInterface.data();
++            return;
++        }
+ 
+-    kDebug() << "ConsoleKit support initialized";
++        // finally get the active session path and watch for its changes
++        m_activeSessionPath = getNamedPathProperty(seatPath, SYSTEMD_LOGIN1_SEAT_IFACE, "ActiveSession");
 +
-+    // get the current session
-+    QDBusInterface managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, QDBusConnection::systemBus());
-+    QDBusPendingReply<QDBusObjectPath> session = managerIface.asyncCall(QLatin1String("GetSessionByPID"), (quint32) QCoreApplication::applicationPid());
-+    session.waitForFinished();
++        kDebug() << "ACTIVE SESSION PATH:" << m_activeSessionPath;
++        QDBusConnection::systemBus().connect(SYSTEMD_LOGIN1_SERVICE, seatPath, "org.freedesktop.DBus.Properties", "PropertiesChanged", this,
++                                             SLOT(onActiveSessionChanged(QString,QVariantMap,QStringList)));
 +
-+    if (!session.isValid()) {
-+        kDebug() << "The session is not registered with systemd";
-+        m_sdAvailable = false;
-+        return;
-+    }
++        onActiveSessionChanged(m_activeSessionPath);
 +
-+    QString sessionPath = session.value().path();
-+    kDebug() << "Session path:" << sessionPath;
++        kDebug() << "systemd support initialized";
++    } else if (serviceName == CONSOLEKIT_SERVICE) {
++        m_ckAvailable = true;
 +
-+    m_sdSessionInterface = new QDBusInterface(SYSTEMD_LOGIN1_SERVICE, sessionPath,
-+                                              SYSTEMD_LOGIN1_SESSION_IFACE, QDBusConnection::systemBus());
-+    if (!m_sdSessionInterface.data()->isValid()) {
-+        // As above
-+        kDebug() << "Can't contact session iface";
-+        m_sdAvailable = false;
-+        return;
-+    }
++        // Otherwise, let's ask ConsoleKit
++        QDBusInterface ckiface(CONSOLEKIT_SERVICE, "/org/freedesktop/ConsoleKit/Manager",
++                               "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus());
 +
++        QDBusPendingReply<QDBusObjectPath> sessionPath = ckiface.asyncCall("GetCurrentSession");
 +
-+    // now let's obtain the seat
-+    QString seatPath = getNamedPathProperty(sessionPath, SYSTEMD_LOGIN1_SESSION_IFACE, "Seat");
++        sessionPath.waitForFinished();
 +
-+    if (seatPath.isEmpty() || seatPath == "/") {
-+        kDebug() << "Unable to associate systemd session with a seat" << seatPath;
-+        m_sdAvailable = false;
-+        return;
-+    }
++        if (!sessionPath.isValid() || sessionPath.value().path().isEmpty()) {
++            kDebug() << "The session is not registered with ck";
++            m_ckAvailable = false;
++            return;
++        }
 +
-+    // get the current seat
-+    m_sdSeatInterface = new QDBusInterface(SYSTEMD_LOGIN1_SERVICE, seatPath,
-+                                           SYSTEMD_LOGIN1_SEAT_IFACE, QDBusConnection::systemBus());
++        m_ckSessionInterface = new QDBusInterface(CONSOLEKIT_SERVICE, sessionPath.value().path(),
++                                                  "org.freedesktop.ConsoleKit.Session", QDBusConnection::systemBus());
 +
-+    if (!m_sdSeatInterface.data()->isValid()) {
-+        // As above
-+        kDebug() << "Can't contact seat iface";
-+        m_sdAvailable = false;
-+        return;
-+    }
++        if (!m_ckSessionInterface.data()->isValid()) {
++            // As above
++            kDebug() << "Can't contact iface";
++            m_ckAvailable = false;
++            return;
++        }
 +
-+    // finally get the active session path and watch for its changes
-+    m_activeSessionPath = getNamedPathProperty(seatPath, SYSTEMD_LOGIN1_SEAT_IFACE, "ActiveSession");
++        // Now let's obtain the seat
++        QDBusPendingReply< QDBusObjectPath > seatPath = m_ckSessionInterface.data()->asyncCall("GetSeatId");
++        seatPath.waitForFinished();
 +
-+    kDebug() << "ACTIVE SESSION PATH:" << m_activeSessionPath;
-+    QDBusConnection::systemBus().connect(SYSTEMD_LOGIN1_SERVICE, seatPath, "org.freedesktop.DBus.Properties", "PropertiesChanged", this,
-+                                         SLOT(slotActiveSessionChanged(QString,QVariantMap,QStringList)));
++        if (!seatPath.isValid() || seatPath.value().path().isEmpty()) {
++            kDebug() << "Unable to associate ck session with a seat";
++            m_ckAvailable = false;
++            return;
++        }
 +
-+    onActiveSessionChanged(m_activeSessionPath);
++        if (!QDBusConnection::systemBus().connect(CONSOLEKIT_SERVICE, seatPath.value().path(),
++                                                  "org.freedesktop.ConsoleKit.Seat", "ActiveSessionChanged",
++                                                  this, SLOT(onActiveSessionChanged(QString)))) {
++            kDebug() << "Unable to connect to ActiveSessionChanged";
++            m_ckAvailable = false;
++            return;
++        }
 +
-+    kDebug() << "systemd support initialized";
-+#else // POWERDEVIL_USE_SYSTEMD
-     m_ckAvailable = true;
- 
-     // Otherwise, let's ask ConsoleKit
-@@ -127,7 +264,7 @@ void PowerDevil::PolicyAgent::onConsoleKitRegistered(const QString& )
-     QDBusPendingReply< QDBusObjectPath > seatPath = m_ckSessionInterface.data()->asyncCall("GetSeatId");
-     seatPath.waitForFinished();
- 
--    if (!sessionPath.isValid() || sessionPath.value().path().isEmpty()) {
-+    if (!seatPath.isValid() || seatPath.value().path().isEmpty()) {
-         kDebug() << "Unable to associate ck session with a seat";
-         m_ckAvailable = false;
-         return;
-@@ -135,7 +272,7 @@ void PowerDevil::PolicyAgent::onConsoleKitRegistered(const QString& )
- 
-     if (!QDBusConnection::systemBus().connect("org.freedesktop.ConsoleKit", seatPath.value().path(),
-                                               "org.freedesktop.ConsoleKit.Seat", "ActiveSessionChanged",
--                                              this, SLOT(onConsoleKitActiveSessionChanged(QString)))) {
-+                                              this, SLOT(onActiveSessionChanged(QString)))) {
-         kDebug() << "Unable to connect to ActiveSessionChanged";
-         m_ckAvailable = false;
-         return;
-@@ -147,23 +284,46 @@ void PowerDevil::PolicyAgent::onConsoleKitRegistered(const QString& )
-     QDBusPendingReply< QDBusObjectPath > activeSession = QDBusConnection::systemBus().asyncCall(call);
-     activeSession.waitForFinished();
- 
--    onConsoleKitActiveSessionChanged(activeSession.value().path());
-+    onActiveSessionChanged(activeSession.value().path());
- 
-     kDebug() << "ConsoleKit support initialized";
-+#endif // POWERDEVIL_USE_SYSTEMD
++        // Force triggering of active session changed
++        QDBusMessage call = QDBusMessage::createMethodCall(CONSOLEKIT_SERVICE, seatPath.value().path(),
++                                                           "org.freedesktop.ConsoleKit.Seat", "GetActiveSession");
++        QDBusPendingReply< QDBusObjectPath > activeSession = QDBusConnection::systemBus().asyncCall(call);
++        activeSession.waitForFinished();
++
++        onActiveSessionChanged(activeSession.value().path());
++
++        kDebug() << "ConsoleKit support initialized";
++    }
++    else
++        kdWarning() << "Unhandled service registered:" << serviceName;
  }
  
 -void PowerDevil::PolicyAgent::onConsoleKitUnregistered(const QString& )
-+void PolicyAgent::onConsoleKitUnregistered(const QString& )
++void PolicyAgent::onSessionHandlerUnregistered(const QString & serviceName)
  {
-+#ifdef POWERDEVIL_USE_SYSTEMD
-+    m_sdAvailable = false;
-+    m_sdSessionInterface.data()->deleteLater();
-+#else
-     m_ckAvailable = false;
-     m_ckSessionInterface.data()->deleteLater();
-+#endif
+-    m_ckAvailable = false;
+-    m_ckSessionInterface.data()->deleteLater();
++    if (serviceName == SYSTEMD_LOGIN1_SERVICE) {
++        m_sdAvailable = false;
++        delete m_sdSessionInterface.data();
++    }
++    else if (serviceName == CONSOLEKIT_SERVICE) {
++        m_ckAvailable = false;
++        delete m_ckSessionInterface.data();
++    }
  }
  
 -void PolicyAgent::onConsoleKitActiveSessionChanged(const QString& activeSession)
-+#ifdef POWERDEVIL_USE_SYSTEMD
-+void PolicyAgent::slotActiveSessionChanged(const QString & ifaceName, const QVariantMap & changedProps, const QStringList & invalidatedProps)
++void PolicyAgent::onActiveSessionChanged(const QString & ifaceName, const QVariantMap & changedProps, const QStringList & invalidatedProps)
  {
 -    if (activeSession.isEmpty()) {
 +    const QString key = QLatin1String("ActiveSession");
@@ -273,26 +343,22 @@ index 5ba595b..d2dbd73 100644
 +        onActiveSessionChanged(m_activeSessionPath);
 +    }
 +}
-+#endif
 +
 +void PolicyAgent::onActiveSessionChanged(const QString& activeSession)
 +{
 +    if (activeSession.isEmpty() || activeSession == "/") {
          kDebug() << "Switched to inactive session - leaving unchanged";
          return;
-+#ifdef POWERDEVIL_USE_SYSTEMD
-+    } else if (activeSession == m_sdSessionInterface.data()->path()) {
-+#else
-     } else if (activeSession == m_ckSessionInterface.data()->path()) {
-+#endif
+-    } else if (activeSession == m_ckSessionInterface.data()->path()) {
++    } else if ((!m_sdSessionInterface.isNull() && activeSession == m_sdSessionInterface.data()->path()) ||
++               (!m_ckSessionInterface.isNull() && activeSession == m_ckSessionInterface.data()->path())) {
          kDebug() << "Current session is now active";
          m_wasLastActiveSession = true;
      } else {
-@@ -201,6 +361,18 @@ PolicyAgent::RequiredPolicies PolicyAgent::unavailablePolicies()
+@@ -201,6 +352,17 @@ PolicyAgent::RequiredPolicies PolicyAgent::unavailablePolicies()
  
  PolicyAgent::RequiredPolicies PolicyAgent::requirePolicyCheck(PolicyAgent::RequiredPolicies policies)
  {
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +    if (!m_sdAvailable) {
 +        // No way to determine if we are on the current session, simply suppose we are
 +        kDebug() << "Can't contact systemd";
@@ -303,20 +369,12 @@ index 5ba595b..d2dbd73 100644
 +            return policies;
 +        }
 +    }
-+#else
++
      if (!m_ckAvailable) {
          // No way to determine if we are on the current session, simply suppose we are
          kDebug() << "Can't contact ck";
-@@ -212,6 +384,7 @@ PolicyAgent::RequiredPolicies PolicyAgent::requirePolicyCheck(PolicyAgent::Requi
-             return policies;
-         }
-     }
-+#endif
- 
-     // Ok, let's go then
-     RequiredPolicies retpolicies = None;
 diff --git a/powerdevil/daemon/powerdevilpolicyagent.h b/powerdevil/daemon/powerdevilpolicyagent.h
-index f637f1e..80dcba4 100644
+index f637f1e..6001846 100644
 --- a/powerdevil/daemon/powerdevilpolicyagent.h
 +++ b/powerdevil/daemon/powerdevilpolicyagent.h
 @@ -1,5 +1,6 @@
@@ -326,7 +384,7 @@ index f637f1e..80dcba4 100644
   *                                                                         *
   *   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  *
-@@ -32,6 +33,13 @@
+@@ -32,6 +33,15 @@
  class QDBusServiceWatcher;
  class QDBusInterface;
  
@@ -336,11 +394,13 @@ index f637f1e..80dcba4 100644
 +#define SYSTEMD_LOGIN1_SESSION_IFACE "org.freedesktop.login1.Session"
 +#define SYSTEMD_LOGIN1_SEAT_IFACE "org.freedesktop.login1.Seat"
 +
++#define CONSOLEKIT_SERVICE "org.freedesktop.ConsoleKit"
++
 +
  namespace PowerDevil
  {
  
-@@ -69,7 +77,6 @@ public Q_SLOTS:
+@@ -69,15 +79,15 @@ public Q_SLOTS:
      void ReleaseInhibition(uint cookie);
  
      void releaseAllInhibitions();
@@ -348,46 +408,39 @@ index f637f1e..80dcba4 100644
  Q_SIGNALS:
      void unavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies newpolicies);
  
-@@ -77,7 +84,11 @@ private Q_SLOTS:
-     void onServiceUnregistered(const QString &serviceName);
-     void onConsoleKitRegistered(const QString&);
-     void onConsoleKitUnregistered(const QString&);
+ private Q_SLOTS:
+-    void onServiceUnregistered(const QString &serviceName);
+-    void onConsoleKitRegistered(const QString&);
+-    void onConsoleKitUnregistered(const QString&);
 -    void onConsoleKitActiveSessionChanged(const QString &activeSession);
-+#ifdef POWERDEVIL_USE_SYSTEMD
-+    void slotActiveSessionChanged(const QString & ifaceName, const QVariantMap & changedProps, const QStringList & invalidatedProps);
-+#endif
++    void onServiceUnregistered(const QString & serviceName);
++    void onSessionHandlerRegistered(const QString & serviceName);
++    void onSessionHandlerUnregistered(const QString & serviceName);
++    void onActiveSessionChanged(const QString & ifaceName, const QVariantMap & changedProps, const QStringList & invalidatedProps);
 +    void onActiveSessionChanged(const QString &activeSession);
-+
  
  private:
      explicit PolicyAgent(QObject* parent = 0);
-@@ -92,9 +103,17 @@ private:
+@@ -92,6 +102,14 @@ private:
      uint addInhibitionWithExplicitDBusService(uint types, const QString &appName,
                                                const QString &reason, const QString &service);
  
-+#ifdef POWERDEVIL_USE_SYSTEMD
++    // systemd support
 +    QString getNamedPathProperty(const QString & path, const QString & iface, const QString & prop) const;
 +    bool m_sdAvailable;
 +    QString m_activeSessionPath;
 +    QWeakPointer< QDBusInterface > m_sdSessionInterface;
 +    QWeakPointer< QDBusInterface > m_sdSeatInterface;
-+#else
++
++    // ConsoleKit support
      bool m_ckAvailable;
      QWeakPointer< QDBusInterface > m_ckSessionInterface;
      QWeakPointer< QDBusInterface > m_ckSeatInterface;
-+#endif
-     bool m_sessionIsBeingInterrupted;
- 
-     QHash< uint, QPair< QString, QString > > m_cookieToAppName;
-@@ -104,7 +123,11 @@ private:
+@@ -104,6 +122,7 @@ private:
      uint m_lastCookie;
  
      QWeakPointer< QDBusServiceWatcher > m_busWatcher;
-+#ifdef POWERDEVIL_USE_SYSTEMD
 +    QWeakPointer< QDBusServiceWatcher > m_sdWatcher;
-+#else
      QWeakPointer< QDBusServiceWatcher > m_ckWatcher;
-+#endif
  
      bool m_wasLastActiveSession;
- 


More information about the scm-commits mailing list