[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:44 UTC 2016


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

The following commit has been merged in the master branch:
commit f24e51f3cba2a8d40f130be491c37317b8b736af
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Sat Oct 8 11:58:04 2011 +0200

    Integrate global presence into kded-modue with autosaving last presence
    
    Reviewed-by: David Edmundson
    REVIEW: 102782
---
 CMakeLists.txt       |   2 +
 autoaway.cpp         |  47 ++++++++++----
 autoaway.h           |  16 ++---
 global-presence.cpp  | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++
 global-presence.h    |  99 ++++++++++++++++++++++++++++
 telepathy-module.cpp |  78 ++++++++++++++++++----
 telepathy-module.h   |  25 ++++---
 7 files changed, 404 insertions(+), 43 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 143afef..17fd7f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,8 @@ include_directories (${KDE4_INCLUDES}
 )
 
 set (telepathy_module_SRCS
+     telepathy-kded-module-plugin.cpp
+     global-presence.cpp
      telepathy-module.cpp
      autoaway.cpp
      telepathy-mpris.cpp
diff --git a/autoaway.cpp b/autoaway.cpp
index 812ba97..2c886d1 100644
--- a/autoaway.cpp
+++ b/autoaway.cpp
@@ -26,15 +26,18 @@
 #include <KIdleTime>
 #include <KConfig>
 #include <KConfigGroup>
+#include "global-presence.h"
 
-AutoAway::AutoAway(const Tp::AccountManagerPtr& am, QObject* parent)
-    : QObject(parent),
+// #define PLUGIN_PRIORITY 99
+
+AutoAway::AutoAway(QObject *parent)
+    : TelepathyKDEDModulePlugin(parent),
       m_awayTimeoutId(-1),
       m_extAwayTimeoutId(-1)
+//       m_idle(false)
 {
+    m_pluginPriority = 99;
     readConfig();
-    m_accountManager = am;
-    m_prevPresence = Tp::Presence::available();
 
     connect(KIdleTime::instance(), SIGNAL(timeoutReached(int)),
             this, SLOT(timeoutReached(int)));
@@ -49,21 +52,29 @@ AutoAway::~AutoAway()
 
 void AutoAway::timeoutReached(int id)
 {
+    if (!m_enabled) {
+        return;
+    }
     KIdleTime::instance()->catchNextResumeEvent();
     if (id == m_awayTimeoutId) {
-        if (!m_accountManager->onlineAccounts()->accounts().isEmpty()) {
-            if (m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() != Tp::Presence::away().type() ||
-                m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() != Tp::Presence::xa().type() ||
-                m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() != Tp::Presence::hidden().type()) {
+        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_prevPresence = m_accountManager->onlineAccounts()->accounts().first()->currentPresence();
-                Q_EMIT setPresence(Tp::Presence::away());
+//                 m_globalPresence->saveCurrentPresence(100);
+//                 m_idle = true;
+                m_requestedPresence = Tp::Presence::away();
+                Q_EMIT activate(true);
+//                 Q_EMIT requestPresenceChange(Tp::Presence::away());
 
             }
         } else if (id == m_extAwayTimeoutId) {
-            if (!m_accountManager->onlineAccounts()->accounts().isEmpty()) {
-                if (m_accountManager->onlineAccounts()->accounts().first()->currentPresence().type() == Tp::Presence::away().type()) {
-                    Q_EMIT setPresence(Tp::Presence::xa());
+            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);
                 }
             }
         }
@@ -73,7 +84,7 @@ void AutoAway::timeoutReached(int id)
 void AutoAway::backFromIdle()
 {
     kDebug();
-    Q_EMIT setPresence(m_prevPresence);
+    Q_EMIT activate(false);
 }
 
 void AutoAway::readConfig()
@@ -92,6 +103,9 @@ void AutoAway::readConfig()
     if (autoAwayEnabled) {
         int awayTime = kdedConfig.readEntry("awayAfter", 5);
         m_awayTimeoutId = KIdleTime::instance()->addIdleTimeout(awayTime * 60 * 1000);
+        m_enabled = true;
+    } else {
+        m_enabled = false;
     }
     if (autoAwayEnabled && autoXAEnabled) {
         int xaTime = kdedConfig.readEntry("xaAfter", 15);
@@ -103,3 +117,8 @@ void AutoAway::onSettingsChanged()
 {
     readConfig();
 }
+/*
+bool AutoAway::isIdle()
+{
+    return m_idle;
+}*/
diff --git a/autoaway.h b/autoaway.h
index a95f49a..1e83b8a 100644
--- a/autoaway.h
+++ b/autoaway.h
@@ -21,23 +21,22 @@
 #ifndef AUTOAWAY_H
 #define AUTOAWAY_H
 
-#include <QObject>
+#include "telepathy-kded-module-plugin.h"
 
 #include <TelepathyQt4/Presence>
 #include <TelepathyQt4/AccountManager>
 
-class AutoAway : public QObject
+class GlobalPresence;
+class AutoAway : public TelepathyKDEDModulePlugin
 {
     Q_OBJECT
 
 public:
-    AutoAway(const Tp::AccountManagerPtr& am, QObject* parent = 0);
+    AutoAway(QObject* parent = 0);
     ~AutoAway();
 
     void readConfig();
-
-Q_SIGNALS:
-    void setPresence(const Tp::Presence &presence);
+//     bool isIdle();
 
 public Q_SLOTS:
     void onSettingsChanged();
@@ -49,9 +48,10 @@ private Q_SLOTS:
 private:
     int m_awayTimeoutId;
     int m_extAwayTimeoutId;
+//     bool m_idle;
 
-    Tp::Presence m_prevPresence;
-    Tp::AccountManagerPtr m_accountManager;
+//     Tp::Presence m_prevPresence;
+//     Tp::AccountManagerPtr m_accountManager;
 };
 
 #endif // AUTOAWAY_H
diff --git a/global-presence.cpp b/global-presence.cpp
new file mode 100644
index 0000000..0ce00d0
--- /dev/null
+++ b/global-presence.cpp
@@ -0,0 +1,180 @@
+/*
+ *  Class handling global presence
+ *  Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ *  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
+ */
+
+#include "global-presence.h"
+
+#include <TelepathyQt4/AccountSet>
+#include <TelepathyQt4/Account>
+
+#include <KDebug>
+
+GlobalPresence* GlobalPresence::s_instance = 0;
+
+GlobalPresence::GlobalPresence(QObject *parent)
+    : QObject(parent),
+      m_requestedPresence(Tp::Presence::offline()),
+      m_currentPresence(Tp::Presence::offline()),
+      m_changingPresence(false)
+{
+    m_presenceSorting[Tp::ConnectionPresenceTypeAvailable] = 0;
+    m_presenceSorting[Tp::ConnectionPresenceTypeBusy] = 1;
+    m_presenceSorting[Tp::ConnectionPresenceTypeHidden] = 2;
+    m_presenceSorting[Tp::ConnectionPresenceTypeAway] = 3;
+    m_presenceSorting[Tp::ConnectionPresenceTypeExtendedAway] = 4;
+    //don't distinguish between the following three presences
+    m_presenceSorting[Tp::ConnectionPresenceTypeError] = 5;
+    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)
+{
+    if (! accountManager->isReady()) {
+        kFatal("GlobalPresence used with unready account manager");
+    }
+
+    m_enabledAccounts = accountManager->enabledAccounts();
+    m_onlineAccounts = accountManager->onlineAccounts();
+
+    Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+        onAccountAdded(account);
+    }
+
+    onCurrentPresenceChanged();
+    onRequestedPresenceChanged();
+    onChangingPresence();
+
+    connect(m_enabledAccounts.data(), SIGNAL(accountAdded(Tp::AccountPtr)), SLOT(onAccountAdded(Tp::AccountPtr)));
+}
+
+
+Tp::Presence GlobalPresence::currentPresence() const
+{
+    return m_currentPresence;
+}
+
+Tp::Presence GlobalPresence::requestedPresence() const
+{
+    return m_requestedPresence;
+}
+
+bool GlobalPresence::isChangingPresence() const
+{
+    return m_changingPresence;
+}
+
+
+void GlobalPresence::setPresence(const Tp::Presence &presence)
+{
+    Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+        account->setRequestedPresence(presence);
+    }
+}
+
+
+void GlobalPresence::onAccountAdded(const Tp::AccountPtr &account)
+{
+    connect(account.data(), SIGNAL(changingPresence(bool)), SLOT(onChangingPresence()));
+    connect(account.data(), SIGNAL(requestedPresenceChanged(Tp::Presence)), SLOT(onRequestedPresenceChanged()));
+    connect(account.data(), SIGNAL(currentPresenceChanged(Tp::Presence)), SLOT(onCurrentPresenceChanged()));
+}
+
+void GlobalPresence::onCurrentPresenceChanged()
+{
+    Tp::Presence highestCurrentPresence = Tp::Presence::offline();
+    Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+        if (m_presenceSorting[account->currentPresence().type()] < m_presenceSorting[highestCurrentPresence.type()]) {
+            highestCurrentPresence = account->currentPresence();
+        }
+    }
+
+    if (highestCurrentPresence.type() != m_currentPresence.type() ||
+            highestCurrentPresence.status() != m_requestedPresence.status()) {
+        m_currentPresence = highestCurrentPresence;
+        Q_EMIT currentPresenceChanged(m_currentPresence);
+    }
+}
+
+void GlobalPresence::onRequestedPresenceChanged()
+{
+    Tp::Presence highestRequestedPresence = Tp::Presence::offline();
+    Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+        if (m_presenceSorting[account->requestedPresence().type()] < m_presenceSorting[highestRequestedPresence.type()]) {
+            highestRequestedPresence = account->currentPresence();
+        }
+    }
+
+    if (highestRequestedPresence.type() != m_requestedPresence.type() &&
+            highestRequestedPresence.status() != m_requestedPresence.status()) {
+        m_requestedPresence = highestRequestedPresence;
+        Q_EMIT requestedPresenceChanged(m_requestedPresence);
+    }
+}
+
+void GlobalPresence::onChangingPresence()
+{
+    bool changingPresence = false;
+    Q_FOREACH(const Tp::AccountPtr &account, m_enabledAccounts->accounts()) {
+        if (account->isChangingPresence()) {
+            changingPresence = true;
+        }
+    }
+
+    if (changingPresence != m_changingPresence) {
+        m_changingPresence = changingPresence;
+        Q_EMIT (m_changingPresence);
+    }
+}
+
+bool GlobalPresence::hasEnabledAccounts() const
+{
+    if (m_enabledAccounts->accounts().isEmpty()) {
+        return false;
+    }
+
+    return true;
+}
+
+void GlobalPresence::saveCurrentPresence()
+{
+    m_savedPresence = m_currentPresence;
+}
+
+void GlobalPresence::restoreSavedPresence()
+{
+    setPresence(m_savedPresence);
+}
+
+Tp::AccountSetPtr GlobalPresence::onlineAccounts() const
+{
+    return m_onlineAccounts;
+}
diff --git a/global-presence.h b/global-presence.h
new file mode 100644
index 0000000..165c994
--- /dev/null
+++ b/global-presence.h
@@ -0,0 +1,99 @@
+/*
+ *  Class handling global presence
+ *  Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ *  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 GLOBALPRESENCE_H
+#define GLOBALPRESENCE_H
+
+#include <QObject>
+#include <TelepathyQt4/AccountManager>
+#include <TelepathyQt4/AccountSet>
+
+
+/** This class handles the presence between all enabled accounts
+ * It shows the highest current available presence, indicates if any accounts are changing, and what they are changing to.
+*/
+
+class GlobalPresence : public QObject
+{
+    Q_OBJECT
+public:
+    static GlobalPresence *Instance();
+
+    /** Set the account manager to use
+      * @param accountManager should be ready.
+      */
+    void setAccountManager(const Tp::AccountManagerPtr &accountManager);
+
+
+    /** The most online presence of any account*/
+    Tp::Presence currentPresence() const;
+
+    /** The most online presence requested for any account if any of the accounts are changing state.
+      otherwise returns current presence*/
+    Tp::Presence requestedPresence() const;
+
+    /** Returns true if any account is changing state (i.e connecting*/
+    bool isChangingPresence() const;
+
+    /** Returns true if there is any enabled account */
+    bool hasEnabledAccounts() const;
+
+    Tp::AccountSetPtr onlineAccounts() const;
+
+Q_SIGNALS:
+    void requestedPresenceChanged(const Tp::Presence &customPresence);
+    void currentPresenceChanged(const Tp::Presence &presence);
+    void changingPresence(bool isChanging);
+
+public Q_SLOTS:
+    /** Set all enabled accounts to the specified presence*/
+    void setPresence(const Tp::Presence &presence);
+
+    /**Saves the current presence to memory*/
+    void saveCurrentPresence();
+    /**Restores the saved presence from memory */
+    void restoreSavedPresence();
+
+private Q_SLOTS:
+    void onCurrentPresenceChanged();
+    void onRequestedPresenceChanged();
+    void onChangingPresence();
+
+    void onAccountAdded(const Tp::AccountPtr &account);
+
+private:
+    GlobalPresence(QObject *parent = 0);
+    static GlobalPresence *s_instance;
+
+    Tp::AccountSetPtr m_enabledAccounts;
+    Tp::AccountSetPtr m_onlineAccounts;
+
+    /**Saved presence for later restoration (for example after returning from auto-away) */
+    Tp::Presence m_savedPresence;
+    /** A cache of the last sent requested presence, to avoid resignalling*/
+    Tp::Presence m_requestedPresence;
+    /** A cache of the last sent presence*/
+    Tp::Presence m_currentPresence;
+    bool m_changingPresence;
+
+    /// Sets the sorting order of presences
+    QHash<uint, int> m_presenceSorting;
+};
+
+#endif // GLOBALPRESENCE_H
diff --git a/telepathy-module.cpp b/telepathy-module.cpp
index 174cecf..d7704ec 100644
--- a/telepathy-module.cpp
+++ b/telepathy-module.cpp
@@ -30,6 +30,10 @@
 #include "telepathy-mpris.h"
 #include "autoaway.h"
 #include "error-handler.h"
+#include "global-presence.h"
+#include "telepathy-kded-module-plugin.h"
+
+#include <KConfigGroup>
 
 K_PLUGIN_FACTORY(TelepathyModuleFactory, registerPlugin<TelepathyModule>(); )
 K_EXPORT_PLUGIN(TelepathyModuleFactory("telepathy_module"))
@@ -77,16 +81,19 @@ void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
         return;
     }
 
-    m_autoAway = new AutoAway(m_accountManager, this);
-    connect(m_autoAway, SIGNAL(setPresence(Tp::Presence)),
-            this, SLOT(setPresence(Tp::Presence)));
+    m_globalPresence = GlobalPresence::Instance();
+    m_globalPresence->setAccountManager(m_accountManager);
+
+    m_autoAway = new AutoAway(this);
+    connect(m_autoAway, SIGNAL(activate(bool)),
+            this, SLOT(onPluginActivated(bool)));
 
     connect(this, SIGNAL(settingsChanged()),
             m_autoAway, SLOT(onSettingsChanged()));
 
-    m_mpris = new TelepathyMPRIS(m_accountManager, this);
-    connect(m_mpris, SIGNAL(setPresence(Tp::Presence)),
-            this, SLOT(setPresence(Tp::Presence)));
+    m_mpris = new TelepathyMPRIS(this);
+    connect(m_mpris, SIGNAL(activate(bool)),
+            this, SLOT(onPluginActivated(bool)));
 
     connect(this, SIGNAL(settingsChanged()),
             m_mpris, SLOT(onSettingsChanged()));
@@ -94,14 +101,63 @@ void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
     m_errorHandler = new ErrorHandler(m_accountManager, this);
 }
 
-void TelepathyModule::setPresence(const Tp::Presence &presence)
+void TelepathyModule::onPresenceChanged(const Tp::Presence &presence)
+{
+    //only save if the presence is not auto-set
+    if (m_pluginStack.isEmpty()) {
+        KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+        KConfigGroup presenceConfig = config->group("LastPresence");
+
+        presenceConfig.writeEntry(QLatin1String("PresenceType"), (uint)m_globalPresence->currentPresence().type());
+        presenceConfig.writeEntry(QLatin1String("PresenceStatus"), m_globalPresence->currentPresence().status());
+        presenceConfig.writeEntry(QLatin1String("PresenceMessage"), m_globalPresence->currentPresence().statusMessage());
+
+        presenceConfig.sync();
+    }
+}
+
+void TelepathyModule::onPluginActivated(bool active)
 {
-    kDebug() << "Setting presence to" << presence.status() << presence.statusMessage();
-    Q_FOREACH (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
-        if (account->isEnabled() && account->isValid() && account->isOnline()) {
-            account->setRequestedPresence(presence);
+    TelepathyKDEDModulePlugin *plugin = qobject_cast<TelepathyKDEDModulePlugin*>(sender());
+    Q_ASSERT(plugin);
+
+    if (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.insert(i, plugin);
+            }
+        }
+
+        m_globalPresence->setPresence(m_pluginStack.top()->requestedPresence());
+    } else {
+        kDebug() << "Received deactivation request, current active plugins:" << m_pluginStack.size();
+        while (!m_pluginStack.isEmpty()) {
+            if (!m_pluginStack.top()->isActive()) {
+                m_pluginStack.pop();
+            } else {
+                break;
+            }
+        }
+
+        if (m_pluginStack.isEmpty()) {
+            m_globalPresence->restoreSavedPresence();
+        } else {
+            m_globalPresence->setPresence(m_pluginStack.top()->requestedPresence());
         }
     }
+
+    kDebug() << "Number of active plugins:" << m_pluginStack.size();
 }
 
 #include "telepathy-module.moc"
diff --git a/telepathy-module.h b/telepathy-module.h
index 815ee38..8d88a79 100644
--- a/telepathy-module.h
+++ b/telepathy-module.h
@@ -25,13 +25,16 @@
 
 #include <TelepathyQt4/AccountManager>
 
-class ErrorHandler;
-class TelepathyMPRIS;
-class AutoAway;
+class TelepathyKDEDModulePlugin;
 namespace Tp {
     class PendingOperation;
 }
 
+class GlobalPresence;
+class ErrorHandler;
+class TelepathyMPRIS;
+class AutoAway;
+
 class TelepathyModule : public KDEDModule
 {
     Q_OBJECT
@@ -43,17 +46,19 @@ public:
 Q_SIGNALS:
     void settingsChanged();
 
-public Q_SLOTS:
-    void setPresence(const Tp::Presence& presence);
-
 private Q_SLOTS:
     void onAccountManagerReady(Tp::PendingOperation*);
+    void onPresenceChanged(const Tp::Presence &presence);
+    void onPluginActivated(bool);
 
 private:
-    Tp::AccountManagerPtr m_accountManager;
-    AutoAway *m_autoAway;
-    TelepathyMPRIS *m_mpris;
-    ErrorHandler *m_errorHandler;
+    Tp::AccountManagerPtr    m_accountManager;
+    AutoAway                *m_autoAway;
+    TelepathyMPRIS          *m_mpris;
+    ErrorHandler            *m_errorHandler;
+    GlobalPresence          *m_globalPresence;
+
+    QStack<TelepathyKDEDModulePlugin*> m_pluginStack;
 };
 
 #endif // TELEPATHY_MODULE_H

-- 
ktp-kded-integration-module packaging



More information about the pkg-kde-commits mailing list