[SCM] ktp-kded-integration-module packaging branch, master, updated. debian/15.12.1-2-382-gbd961c2

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:12:45 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-kded-module.git;a=commitdiff;h=4e41d79

The following commit has been merged in the master branch:
commit 4e41d798546cff4163fde3e62e09a7d639b88029
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Mon Oct 10 16:22:51 2011 +0200

    New stacking system for plugins, code refactor, global presence integration, last used presence saving (system-wide), improvements in mpris-players detection and auto-away system
    
    Reviewed-by: David Edmundson
    REVIEW: 102804
    FEATURE: 269605
---
 autoaway.cpp                                   |  47 +++----
 autoaway.h                                     |   8 +-
 global-presence.cpp                            |  14 --
 global-presence.h                              |   5 +-
 autoaway.h => telepathy-kded-module-plugin.cpp |  53 ++++----
 telepathy-kded-module-plugin.h                 |  62 +++++++++
 telepathy-module.cpp                           |  41 +++---
 telepathy-module.h                             |   4 +-
 telepathy-mpris.cpp                            | 175 +++++++++++++++----------
 telepathy-mpris.h                              |  13 +-
 10 files changed, 239 insertions(+), 183 deletions(-)

diff --git a/autoaway.cpp b/autoaway.cpp
index 2c886d1..c52798e 100644
--- a/autoaway.cpp
+++ b/autoaway.cpp
@@ -28,15 +28,12 @@
 #include <KConfigGroup>
 #include "global-presence.h"
 
-// #define PLUGIN_PRIORITY 99
-
-AutoAway::AutoAway(QObject *parent)
-    : TelepathyKDEDModulePlugin(parent),
+AutoAway::AutoAway(GlobalPresence* globalPresence, QObject* parent)
+    : TelepathyKDEDModulePlugin(globalPresence, parent),
       m_awayTimeoutId(-1),
       m_extAwayTimeoutId(-1)
-//       m_idle(false)
 {
-    m_pluginPriority = 99;
+    setPluginPriority(99);
     readConfig();
 
     connect(KIdleTime::instance(), SIGNAL(timeoutReached(int)),
@@ -52,30 +49,21 @@ AutoAway::~AutoAway()
 
 void AutoAway::timeoutReached(int id)
 {
-    if (!m_enabled) {
+    if (!isEnabled()) {
         return;
     }
     KIdleTime::instance()->catchNextResumeEvent();
     if (id == m_awayTimeoutId) {
-        if (!m_globalPresence->onlineAccounts()->accounts().isEmpty()) {
-            if (m_globalPresence->currentPresence().type() != Tp::Presence::away().type() ||
-                m_globalPresence->currentPresence().type() != Tp::Presence::xa().type() ||
-                m_globalPresence->currentPresence().type() != Tp::Presence::hidden().type()) {
-
-//                 m_globalPresence->saveCurrentPresence(100);
-//                 m_idle = true;
-                m_requestedPresence = Tp::Presence::away();
-                Q_EMIT activate(true);
-//                 Q_EMIT requestPresenceChange(Tp::Presence::away());
+        if (m_globalPresence->currentPresence().type() != Tp::Presence::away().type() ||
+            m_globalPresence->currentPresence().type() != Tp::Presence::xa().type() ||
+            m_globalPresence->currentPresence().type() != Tp::Presence::hidden().type()) {
 
-            }
+            setRequestedPresence(Tp::Presence::away());
+            setActive(true);
         } else if (id == m_extAwayTimeoutId) {
-            if (!m_globalPresence->onlineAccounts()->accounts().isEmpty()) {
-                if (m_globalPresence->currentPresence().type() == Tp::Presence::away().type()) {
-//                     Q_EMIT requestPresenceChange(Tp::Presence::xa());
-                        m_requestedPresence = Tp::Presence::xa();
-                        Q_EMIT activate(true);
-                }
+            if (m_globalPresence->currentPresence().type() == Tp::Presence::away().type()) {
+                setRequestedPresence(Tp::Presence::xa());
+                setActive(true);
             }
         }
     }
@@ -84,7 +72,7 @@ void AutoAway::timeoutReached(int id)
 void AutoAway::backFromIdle()
 {
     kDebug();
-    Q_EMIT activate(false);
+    setActive(false);
 }
 
 void AutoAway::readConfig()
@@ -103,9 +91,9 @@ void AutoAway::readConfig()
     if (autoAwayEnabled) {
         int awayTime = kdedConfig.readEntry("awayAfter", 5);
         m_awayTimeoutId = KIdleTime::instance()->addIdleTimeout(awayTime * 60 * 1000);
-        m_enabled = true;
+        setEnabled(true);
     } else {
-        m_enabled = false;
+        setEnabled(false);
     }
     if (autoAwayEnabled && autoXAEnabled) {
         int xaTime = kdedConfig.readEntry("xaAfter", 15);
@@ -117,8 +105,3 @@ void AutoAway::onSettingsChanged()
 {
     readConfig();
 }
-/*
-bool AutoAway::isIdle()
-{
-    return m_idle;
-}*/
diff --git a/autoaway.h b/autoaway.h
index 1e83b8a..9b55937 100644
--- a/autoaway.h
+++ b/autoaway.h
@@ -27,16 +27,16 @@
 #include <TelepathyQt4/AccountManager>
 
 class GlobalPresence;
+
 class AutoAway : public TelepathyKDEDModulePlugin
 {
     Q_OBJECT
 
 public:
-    AutoAway(QObject* parent = 0);
+    AutoAway(GlobalPresence *globalPresence, QObject* parent = 0);
     ~AutoAway();
 
     void readConfig();
-//     bool isIdle();
 
 public Q_SLOTS:
     void onSettingsChanged();
@@ -48,10 +48,6 @@ private Q_SLOTS:
 private:
     int m_awayTimeoutId;
     int m_extAwayTimeoutId;
-//     bool m_idle;
-
-//     Tp::Presence m_prevPresence;
-//     Tp::AccountManagerPtr m_accountManager;
 };
 
 #endif // AUTOAWAY_H
diff --git a/global-presence.cpp b/global-presence.cpp
index 0ce00d0..b7ee786 100644
--- a/global-presence.cpp
+++ b/global-presence.cpp
@@ -24,8 +24,6 @@
 
 #include <KDebug>
 
-GlobalPresence* GlobalPresence::s_instance = 0;
-
 GlobalPresence::GlobalPresence(QObject *parent)
     : QObject(parent),
       m_requestedPresence(Tp::Presence::offline()),
@@ -42,18 +40,6 @@ GlobalPresence::GlobalPresence(QObject *parent)
     m_presenceSorting[Tp::ConnectionPresenceTypeUnknown] = 5;
     m_presenceSorting[Tp::ConnectionPresenceTypeUnset] = 5;
     m_presenceSorting[Tp::ConnectionPresenceTypeOffline] = 6;
-
-    //set the correct current presence
-    onCurrentPresenceChanged();
-}
-
-GlobalPresence* GlobalPresence::Instance()
-{
-    if (!s_instance) {
-        s_instance = new GlobalPresence();
-    }
-
-    return s_instance;
 }
 
 void GlobalPresence::setAccountManager(const Tp::AccountManagerPtr &accountManager)
diff --git a/global-presence.h b/global-presence.h
index 165c994..420f0e2 100644
--- a/global-presence.h
+++ b/global-presence.h
@@ -33,7 +33,7 @@ class GlobalPresence : public QObject
 {
     Q_OBJECT
 public:
-    static GlobalPresence *Instance();
+    GlobalPresence(QObject *parent = 0);
 
     /** Set the account manager to use
       * @param accountManager should be ready.
@@ -78,9 +78,6 @@ private Q_SLOTS:
     void onAccountAdded(const Tp::AccountPtr &account);
 
 private:
-    GlobalPresence(QObject *parent = 0);
-    static GlobalPresence *s_instance;
-
     Tp::AccountSetPtr m_enabledAccounts;
     Tp::AccountSetPtr m_onlineAccounts;
 
diff --git a/autoaway.h b/telepathy-kded-module-plugin.cpp
similarity index 57%
copy from autoaway.h
copy to telepathy-kded-module-plugin.cpp
index 1e83b8a..2370a2c 100644
--- a/autoaway.h
+++ b/telepathy-kded-module-plugin.cpp
@@ -1,5 +1,5 @@
 /*
-    Auto away-presence setter-class
+    Parent class for Telepathy KDED Plugins
     Copyright (C) 2011  Martin Klapetek <martin.klapetek at gmail.com>
 
     This library is free software; you can redistribute it and/or
@@ -18,40 +18,33 @@
 */
 
 
-#ifndef AUTOAWAY_H
-#define AUTOAWAY_H
-
 #include "telepathy-kded-module-plugin.h"
 
-#include <TelepathyQt4/Presence>
-#include <TelepathyQt4/AccountManager>
+#include "global-presence.h"
 
-class GlobalPresence;
-class AutoAway : public TelepathyKDEDModulePlugin
+TelepathyKDEDModulePlugin::TelepathyKDEDModulePlugin(GlobalPresence* globalPresence, QObject* parent)
+    : QObject(parent),
+      m_enabled(false),
+      m_pluginPriority(50)
 {
-    Q_OBJECT
-
-public:
-    AutoAway(QObject* parent = 0);
-    ~AutoAway();
-
-    void readConfig();
-//     bool isIdle();
-
-public Q_SLOTS:
-    void onSettingsChanged();
+    m_globalPresence = globalPresence;
+}
 
-private Q_SLOTS:
-    void timeoutReached(int);
-    void backFromIdle();
+TelepathyKDEDModulePlugin::~TelepathyKDEDModulePlugin()
+{
+}
 
-private:
-    int m_awayTimeoutId;
-    int m_extAwayTimeoutId;
-//     bool m_idle;
+void TelepathyKDEDModulePlugin::setEnabled(bool enabled)
+{
+    m_enabled = enabled;
 
-//     Tp::Presence m_prevPresence;
-//     Tp::AccountManagerPtr m_accountManager;
-};
+    if(!enabled) {
+        setActive(false);
+    }
+}
 
-#endif // AUTOAWAY_H
+void TelepathyKDEDModulePlugin::setActive(bool active)
+{
+    m_active = active;
+    Q_EMIT activate(active);
+}
diff --git a/telepathy-kded-module-plugin.h b/telepathy-kded-module-plugin.h
new file mode 100644
index 0000000..6fb78b8
--- /dev/null
+++ b/telepathy-kded-module-plugin.h
@@ -0,0 +1,62 @@
+/*
+    Parent class for Telepathy KDED Plugins
+    Copyright (C) 2011  Martin Klapetek <martin.klapetek at gmail.com>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+
+#ifndef TELEPATHY_KDED_MODULE_PLUGIN_H
+#define TELEPATHY_KDED_MODULE_PLUGIN_H
+
+#include <QObject>
+#include <TelepathyQt4/Presence>
+#include <TelepathyQt4/AccountManager>
+
+class GlobalPresence;
+class TelepathyKDEDModulePlugin : public QObject
+{
+    Q_OBJECT
+
+public:
+    TelepathyKDEDModulePlugin(GlobalPresence *globalPresence, QObject *parent = 0);
+    virtual ~TelepathyKDEDModulePlugin();
+
+    bool isActive() const { return m_active; };
+    bool isEnabled() const { return m_enabled; };
+    int pluginPriority() const { return m_pluginPriority; };
+
+    Tp::Presence requestedPresence() const { return m_requestedPresence; };
+
+Q_SIGNALS:
+    void requestPresenceChange(const Tp::Presence &presence);
+    void activate(bool);
+
+protected:
+    void setActive(bool active);
+    void setEnabled(bool enabled);
+    void setPluginPriority(int priority) { m_pluginPriority = priority; };
+    void setRequestedPresence(const Tp::Presence &presence) { m_requestedPresence = presence; };
+
+    GlobalPresence *m_globalPresence;
+
+private:
+    Tp::Presence m_requestedPresence;
+    bool m_enabled;
+    bool m_active;
+    int m_pluginPriority;
+};
+
+#endif // TELEPATHY_KDED_MODULE_PLUGIN_H
diff --git a/telepathy-module.cpp b/telepathy-module.cpp
index d7704ec..92dc11d 100644
--- a/telepathy-module.cpp
+++ b/telepathy-module.cpp
@@ -81,17 +81,17 @@ void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
         return;
     }
 
-    m_globalPresence = GlobalPresence::Instance();
+    m_globalPresence = new GlobalPresence(this);
     m_globalPresence->setAccountManager(m_accountManager);
 
-    m_autoAway = new AutoAway(this);
+    m_autoAway = new AutoAway(m_globalPresence, this);
     connect(m_autoAway, SIGNAL(activate(bool)),
             this, SLOT(onPluginActivated(bool)));
 
     connect(this, SIGNAL(settingsChanged()),
             m_autoAway, SLOT(onSettingsChanged()));
 
-    m_mpris = new TelepathyMPRIS(this);
+    m_mpris = new TelepathyMPRIS(m_globalPresence, this);
     connect(m_mpris, SIGNAL(activate(bool)),
             this, SLOT(onPluginActivated(bool)));
 
@@ -125,35 +125,36 @@ void TelepathyModule::onPluginActivated(bool active)
         kDebug() << "Received activation request, current active plugins:" << m_pluginStack.size();
         if (m_pluginStack.isEmpty()) {
             m_globalPresence->saveCurrentPresence();
-            m_pluginStack.push(plugin);
-        }
-        if (m_pluginStack.top() != plugin) {
-            if (plugin->pluginPriority() >= m_pluginStack.top()->pluginPriority()) {
-                m_pluginStack.push(plugin);
-            } else {
-                int i = 0;
-                while (m_pluginStack.at(i++)->pluginPriority() <= plugin->pluginPriority()) {
+            m_pluginStack.append(plugin);
+        } else if (!m_pluginStack.contains(plugin)) {
+            int i;
+            for (i = 0; i < m_pluginStack.size(); i++) {
+                if (plugin->pluginPriority() >= m_pluginStack.at(i)->pluginPriority()) {
+                    break;
                 }
-
-                m_pluginStack.insert(i, plugin);
             }
+            m_pluginStack.insert(i, plugin);
         }
 
-        m_globalPresence->setPresence(m_pluginStack.top()->requestedPresence());
+        if (!m_globalPresence->onlineAccounts()->accounts().isEmpty()) {
+            m_globalPresence->setPresence(m_pluginStack.first()->requestedPresence());
+        }
     } else {
         kDebug() << "Received deactivation request, current active plugins:" << m_pluginStack.size();
         while (!m_pluginStack.isEmpty()) {
-            if (!m_pluginStack.top()->isActive()) {
-                m_pluginStack.pop();
+            if (!m_pluginStack.first()->isActive()) {
+                m_pluginStack.removeFirst();
             } else {
                 break;
             }
         }
 
-        if (m_pluginStack.isEmpty()) {
-            m_globalPresence->restoreSavedPresence();
-        } else {
-            m_globalPresence->setPresence(m_pluginStack.top()->requestedPresence());
+        if (!m_globalPresence->onlineAccounts()->accounts().isEmpty()) {
+            if (m_pluginStack.isEmpty()) {
+                m_globalPresence->restoreSavedPresence();
+            } else {
+                m_globalPresence->setPresence(m_pluginStack.first()->requestedPresence());
+            }
         }
     }
 
diff --git a/telepathy-module.h b/telepathy-module.h
index 8d88a79..3ab89bc 100644
--- a/telepathy-module.h
+++ b/telepathy-module.h
@@ -25,11 +25,11 @@
 
 #include <TelepathyQt4/AccountManager>
 
-class TelepathyKDEDModulePlugin;
 namespace Tp {
     class PendingOperation;
 }
 
+class TelepathyKDEDModulePlugin;
 class GlobalPresence;
 class ErrorHandler;
 class TelepathyMPRIS;
@@ -58,7 +58,7 @@ private:
     ErrorHandler            *m_errorHandler;
     GlobalPresence          *m_globalPresence;
 
-    QStack<TelepathyKDEDModulePlugin*> m_pluginStack;
+    QList<TelepathyKDEDModulePlugin*> m_pluginStack;
 };
 
 #endif // TELEPATHY_MODULE_H
diff --git a/telepathy-mpris.cpp b/telepathy-mpris.cpp
index b4920d8..879ec62 100644
--- a/telepathy-mpris.cpp
+++ b/telepathy-mpris.cpp
@@ -25,63 +25,25 @@
 #include <QVariant>
 #include <KDebug>
 #include <TelepathyQt4/AccountSet>
+#include <KSharedConfig>
+#include <KConfigGroup>
+#include "global-presence.h"
 
-TelepathyMPRIS::TelepathyMPRIS(const Tp::AccountManagerPtr am, QObject* parent) : QObject(parent)
+TelepathyMPRIS::TelepathyMPRIS(GlobalPresence* globalPresence, QObject* parent)
+    : TelepathyKDEDModulePlugin(globalPresence, parent)
 {
-    m_accountManager = am;
+    setPluginPriority(50);
 
-    if (am->onlineAccounts()->accounts().isEmpty()) {
-        return;
-    }
-
-    m_originalPresence = am->onlineAccounts()->accounts().first()->currentPresence().statusMessage();
-
-    QDBusConnectionInterface *i = QDBusConnection::sessionBus().interface();
-    QStringList mprisServices = i->registeredServiceNames().value().filter(QLatin1String("org.mpris.MediaPlayer2"));
-
-    QString artist;
-    QString title;
-    QString album;
-
-    Q_FOREACH (const QString &service, mprisServices) {
-        QDBusInterface mprisInterface(service, QLatin1String("/org/mpris/MediaPlayer2"), QLatin1String("org.mpris.MediaPlayer2.Player"));
-        if (mprisInterface.property("PlaybackStatus") == QLatin1String("Playing")) {
-            QMap<QString, QVariant> metadata = mprisInterface.property("Metadata").toMap();
-            artist = metadata.value(QLatin1String("xesam:artist")).toString();
-            title = metadata.value(QLatin1String("xesam:title")).toString();
-            album = metadata.value(QLatin1String("xesam:album")).toString();
-
-            QDBusConnection::sessionBus().connect(
-                service,
-                QLatin1String("/org/mpris/MediaPlayer2"),
-                QLatin1String("org.freedesktop.DBus.Properties"),
-                QLatin1String("PropertiesChanged"),
-                this,
-                SLOT(onPlayerSignalReceived(const QString& ,
-                                            const QVariantMap& ,
-                                            const QStringList& )) );
+    //read settings and detect players if plugin is enabled
+    onSettingsChanged();
 
-            break;
-        }
-    }
-
-    if (!am->onlineAccounts()->accounts().isEmpty()) {
-        Tp::Presence currentPresence = am->onlineAccounts()->accounts().first()->currentPresence();
-
-        Tp::SimplePresence presence;
-        presence.type = currentPresence.type();
-        presence.status = currentPresence.status();
-        presence.statusMessage = QString(QLatin1String("Now listening to %1 by %2 from album %3")).arg(title, artist, album);
-
-        kDebug() << "Setting presence message to" << presence.statusMessage;
-
-        Q_EMIT setPresence(presence);
-    }
+    //watch for new mpris-enabled players
+    connect(QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
+            this, SLOT(serviceOwnerChanged(QString,QString,QString)));
 }
 
 TelepathyMPRIS::~TelepathyMPRIS()
 {
-
 }
 
 void TelepathyMPRIS::onPlayerSignalReceived(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
@@ -89,47 +51,122 @@ void TelepathyMPRIS::onPlayerSignalReceived(const QString &interface, const QVar
     Q_UNUSED(interface)
     Q_UNUSED(invalidatedProperties)
 
-    if (m_accountManager->onlineAccounts()->accounts().isEmpty()) {
+    //if the plugin is disabled, no point in parsing the received signal
+    if (!isEnabled()) {
         return;
     }
-    //FIXME We can do less lame parsing
+
+    QString artist;
+    QString title;
+    QString album;
+
+    //FIXME We can do less lame parsing...maybe.
     Q_FOREACH (const QVariant &property, changedProperties.values()) {
         if (property.canConvert<QDBusArgument>()) {
-            QString artist;
-            QString title;
-            QString album;
-
             QDBusArgument g = property.value<QDBusArgument>();
             QMap<QString, QVariant> k = qdbus_cast<QMap<QString, QVariant> >(g);
             title = k.value(QLatin1String("xesam:title")).toString();
             artist = k.value(QLatin1String("xesam:artist")).toString();
             album = k.value(QLatin1String("xesam:album")).toString();
 
-            Tp::Presence currentPresence = m_accountManager->onlineAccounts()->accounts().first()->currentPresence();
-
-            Tp::SimplePresence presence;
-            presence.type = currentPresence.type();
-            presence.status = currentPresence.status();
-            presence.statusMessage = QString(QLatin1String("Now listening to %1 by %2 from album %3")).arg(title, artist, album);
-
-            Q_EMIT setPresence(presence);
+            //we got what we need, bail out
+            break;
         }
 
         if (property.canConvert<QString>()) {
-            if (property.toString() == QLatin1String("Paused")) {
-                Tp::Presence currentPresence = m_accountManager->onlineAccounts()->accounts().first()->currentPresence();
+            if (property.toString() == QLatin1String("Paused") || property.toString() == QLatin1String("Stopped")) {
+                setActive(false);
+                return;
+            }
+
+            if (property.toString() == QLatin1String("Playing")) {
+                QStringList mprisServices = QDBusConnection::sessionBus().interface()->registeredServiceNames().value().filter(QLatin1String("org.mpris.MediaPlayer2"));
+
+                Q_FOREACH (const QString &service, mprisServices) {
+                    QDBusInterface mprisInterface(service, QLatin1String("/org/mpris/MediaPlayer2"), QLatin1String("org.mpris.MediaPlayer2.Player"));
+                    if (mprisInterface.property("PlaybackStatus") == QLatin1String("Playing")) {
+                        QMap<QString, QVariant> metadata = mprisInterface.property("Metadata").toMap();
+                        artist = metadata.value(QLatin1String("xesam:artist")).toString();
+                        title = metadata.value(QLatin1String("xesam:title")).toString();
+                        album = metadata.value(QLatin1String("xesam:album")).toString();
+
+                        break;
+                    }
 
-                Tp::SimplePresence presence;
-                presence.type = currentPresence.type();
-                presence.status = currentPresence.status();
-                presence.statusMessage = m_originalPresence;
+                }
             }
         }
     }
 
+    Tp::Presence currentPresence = m_globalPresence->currentPresence();
+
+    Tp::SimplePresence presence;
+    presence.type = currentPresence.type();
+    presence.status = currentPresence.status();
+    presence.statusMessage = QString(QLatin1String("Now listening to %1 by %2 from album %3")).arg(title, artist, album);
+
+    setRequestedPresence(Tp::Presence(presence));
+    setActive(true);
+}
+
+void TelepathyMPRIS::detectPlayers()
+{
+    QDBusConnectionInterface *i = QDBusConnection::sessionBus().interface();
+    QStringList mprisServices = i->registeredServiceNames().value().filter(QLatin1String("org.mpris.MediaPlayer2"));
+    QStringList players;
+
+    Q_FOREACH (const QString &service, mprisServices) {
+        kDebug() << "Found mpris service:" << service;
+        QDBusInterface mprisInterface(service, QLatin1String("/org/mpris/MediaPlayer2"), QLatin1String("org.mpris.MediaPlayer2.Player"));
+        if (mprisInterface.property("PlaybackStatus") == QLatin1String("Playing")) {
+            QVariantMap m;
+            m.insert(QLatin1String("PlaybackStatus"), QVariant(QLatin1String("Playing")));
+            onPlayerSignalReceived(QString(), m, QStringList());
+        }
+
+        //check if we are already watching this service
+        if (!m_knownPlayers.contains(service)) {
+            QDBusConnection::sessionBus().connect(
+                service,
+                QLatin1String("/org/mpris/MediaPlayer2"),
+                                                QLatin1String("org.freedesktop.DBus.Properties"),
+                                                QLatin1String("PropertiesChanged"),
+                                                this,
+                                                SLOT(onPlayerSignalReceived(const QString&, const QVariantMap&, const QStringList& )) );
+
+        }
+
+        players.append(service);
+    }
+
+    //this gets rid of removed services and stores only those currently present
+    m_knownPlayers = players;
 }
 
 void TelepathyMPRIS::onSettingsChanged()
 {
+    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+    KConfigGroup kdedConfig = config->group("KDED");
+
+    bool pluginEnabled = kdedConfig.readEntry("nowPlayingEnabled", true);
 
+    //if the plugin was enabled and is now disabled
+    if (isEnabled() && !pluginEnabled) {
+        setEnabled(false);
+        return;
+    }
+
+    //if the plugin was disabled and is now enabled
+    if (!isEnabled() && pluginEnabled) {
+        setEnabled(true);
+        detectPlayers();
+    }
+}
+
+void TelepathyMPRIS::serviceOwnerChanged(const QString& a, const QString& b, const QString& c)
+{
+    if (a.contains(QLatin1String("org.mpris.MediaPlayer2"))) {
+        kDebug() << "Found new mpris interface, running detection...";
+        detectPlayers();
+    }
 }
diff --git a/telepathy-mpris.h b/telepathy-mpris.h
index 5dd596f..8504a8b 100644
--- a/telepathy-mpris.h
+++ b/telepathy-mpris.h
@@ -21,28 +21,29 @@
 #ifndef TELEPATHY_MPRIS_H
 #define TELEPATHY_MPRIS_H
 
-#include <QObject>
+#include "telepathy-kded-module-plugin.h"
 #include <TelepathyQt4/Presence>
 #include <TelepathyQt4/AccountManager>
 
-class TelepathyMPRIS : public QObject
+class TelepathyMPRIS : public TelepathyKDEDModulePlugin
 {
     Q_OBJECT
 
 public:
-    TelepathyMPRIS(const Tp::AccountManagerPtr am, QObject *parent = 0);
+    TelepathyMPRIS(GlobalPresence *globalPresence, QObject *parent = 0);
     virtual ~TelepathyMPRIS();
 
 public Q_SLOTS:
     void onPlayerSignalReceived(const QString &interface, const QVariantMap &changedProperties, const QStringList &invalidatedProperties);
     void onSettingsChanged();
+    void detectPlayers();
+    void serviceOwnerChanged(const QString &a, const QString &b, const QString &c);
 
 Q_SIGNALS:
-    void setPresence(const Tp::Presence &presence);
+    void togglePlaybackActive(bool);
 
 private:
-    Tp::AccountManagerPtr m_accountManager;
-    QString m_originalPresence;
+    QStringList m_knownPlayers;
 };
 
 #endif // TELEPATHY_MPRIS_H

-- 
ktp-kded-integration-module packaging



More information about the pkg-kde-commits mailing list