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


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

The following commit has been merged in the master branch:
commit f3c94b92261020fa7aa7ee984dcc3507d42272e4
Author: Rohan Garg <rohangarg at kubuntu.org>
Date:   Sat Sep 29 02:05:47 2012 +0530

    Use the new GlobalContactManager class
    
    Instead of duplicating code, use the new GlobalContactManager class in
    order to get the list of all contacts.
    
    In addition to the above, notifications are only shown if their new
    priority is higher than that of the previous one, for eg : only
    notifies the user when a contact goes from Away to Online and not the
    other way around
    
    Misc: Add var names to header and fix coding style a bit
    
    REVIEW: 106355
---
 contactnotify.cpp | 110 +++++++++++++++++++++++++++---------------------------
 contactnotify.h   |  24 ++++++------
 2 files changed, 68 insertions(+), 66 deletions(-)

diff --git a/contactnotify.cpp b/contactnotify.cpp
index 403b915..65bdaac 100644
--- a/contactnotify.cpp
+++ b/contactnotify.cpp
@@ -28,87 +28,87 @@
 #include <KAboutData>
 
 #include <KTp/presence.h>
+#include <KTp/global-contact-manager.h>
 
-ContactNotify::ContactNotify(const Tp::AccountManagerPtr accountMgr, QObject *parent) :
+using namespace KTp;
+
+ContactNotify::ContactNotify(const Tp::AccountManagerPtr &accountMgr, QObject *parent) :
     QObject(parent)
 {
+    Q_ASSERT(accountMgr);
     m_accountManager = accountMgr;
     if (!m_accountManager) {
         return;
     }
 
-    QList<Tp::AccountPtr> accounts = m_accountManager->allAccounts();
-    Q_FOREACH(const Tp::AccountPtr &account, accounts) {
-        // Accounts that are already online should be handled immediately
-        if (account.data()->isOnline()) {
-            kDebug() << "Account" << account.data()->normalizedName() << "is already Online";
-            accountIsOnline(account.data());
-        } else {
-            // Handle accounts coming online
-            connect(account.data(), SIGNAL(onlinenessChanged(bool)),
-                    SLOT(accountCameOnline(bool)));
-        }
-    }
-}
+    GlobalContactManager *contactManager = new GlobalContactManager(m_accountManager, this);
 
-void ContactNotify::accountCameOnline(bool online)
-{
-    if (online) {
-        const Tp::Account *account = (Tp::Account *)QObject::sender();
-        if (account) {
-            kDebug() << "Account" << account->normalizedName() << "came Online";
-            accountIsOnline(account);
-        }
-    }
-}
+    Tp::Presence currentPresence;
 
-void ContactNotify::accountIsOnline(const Tp::Account *account)
-{
-    Q_ASSERT(account);
-    m_connection = account->connection();
-    if (m_connection.data()) {
-        connect(m_connection.data(), SIGNAL(statusChanged(Tp::ConnectionStatus)),
-                SLOT(onStatusChanged(Tp::ConnectionStatus)));
-    }
-}
+    Q_FOREACH(const AccountContact &contact, contactManager->allKnownContacts()) {
+        connect(contact.contact().data(), SIGNAL(presenceChanged(Tp::Presence)),
+                SLOT(contactPresenceChanged(Tp::Presence)));
 
-void ContactNotify::onStatusChanged(const Tp::ConnectionStatus status)
-{
-    if (status == Tp::ConnectionStatusConnected) {
-        Tp::ContactManagerPtr contactManager = m_connection.data()->contactManager();
-        Tp::Contacts contacts = contactManager.data()->allKnownContacts();
-        // This is going to be *slow* when the user has alot of contacts
-        // Optimize it later on
-        Q_FOREACH (const Tp::ContactPtr &contact, contacts) {
-            connect(contact.data(), SIGNAL(presenceChanged(Tp::Presence)),
-                    SLOT(contactPresenceChanged(Tp::Presence)));
-        }
+        currentPresence = contact.contact()->presence();
+        m_presenceHash[contact.contact()->id()] = Presence::sortPriority(currentPresence.type());
     }
+
+    connect(contactManager, SIGNAL(allKnownContactsChanged(AccountContactList,AccountContactList)),
+            SLOT(onContactsChanged(AccountContactList,AccountContactList)));
 }
 
-void ContactNotify::contactPresenceChanged(const Tp::Presence presence)
+
+void ContactNotify::contactPresenceChanged(const Tp::Presence &presence)
 {
     KTp::Presence ktpPresence(presence);
-    Tp::Contact *contact = (Tp::Contact *)QObject::sender();
-    sendNotification(i18nc("%1 is the contact name, %2 is the presence message",
-                           "%1 is now %2",
-                           contact->alias(),
-                           ktpPresence.displayString()),
-                     ktpPresence.icon(),
-                     contact);
+    Tp::ContactPtr contact(qobject_cast<Tp::Contact*>(QObject::sender()));
+    int priority = m_presenceHash[contact->id()];
+
+    // Don't show presence messages when moving from a higher priority to a lower
+    // priority, for eg : When a contact changes from Online -> Away, don't send
+    // a notification, but do send a notification when a contact changes from
+    // Away -> Online
+    if (KTp::Presence::sortPriority(presence.type()) < priority) {
+        sendNotification(i18nc("%1 is the contact name, %2 is the presence name",
+                               "%1 is now %2",
+                               contact->alias(),
+                               ktpPresence.displayString()),
+                         ktpPresence.icon(),
+                         contact);
+    }
+
+    m_presenceHash.insert(contact->id(), Presence::sortPriority(presence.type()));
 }
 
-void ContactNotify::sendNotification(QString text, KIcon icon, const Tp::Contact *contact)
+void ContactNotify::sendNotification(const QString &text, const KIcon &icon, const Tp::ContactPtr &contact)
 {
     //The pointer is automatically deleted when the event is closed
     KNotification *notification;
     notification = new KNotification(QLatin1String("contactInfo"), KNotification::CloseOnTimeout);
 
-    KAboutData aboutData("ktelepathy",0,KLocalizedString(),0);
+    KAboutData aboutData("ktelepathy", 0, KLocalizedString(), 0);
     notification->setComponentData(KComponentData(aboutData));
 
     notification->setPixmap(icon.pixmap(48));
     notification->setText(text);
-    notification->addContext(QLatin1String("contact"), contact->id());
+    notification->addContext(QLatin1String("contact"), contact.data()->id());
     notification->sendEvent();
 }
+
+void ContactNotify::onContactsChanged(const AccountContactList &contactsAdded, const AccountContactList &contactsRemoved)
+{
+    Tp::Presence currentPresence;
+
+    Q_FOREACH(const AccountContact &contact, contactsAdded) {
+        connect(contact.contact().data(), SIGNAL(presenceChanged(Tp::Presence)),
+                SLOT(contactPresenceChanged(Tp::Presence)));
+
+        currentPresence = contact.contact().data()->presence();
+        m_presenceHash[contact.contact()->id()] = Presence::sortPriority(currentPresence.type());
+
+    }
+
+    Q_FOREACH(const AccountContact &contact, contactsRemoved) {
+        m_presenceHash.remove(contact.contact()->id());
+    }
+ }
diff --git a/contactnotify.h b/contactnotify.h
index 53093f4..462b3f3 100644
--- a/contactnotify.h
+++ b/contactnotify.h
@@ -19,27 +19,29 @@
 #ifndef CONTACTNOTIFY_H
 #define CONTACTNOTIFY_H
 
-class KIcon;
-
 #include <TelepathyQt/Types>
 #include <TelepathyQt/Connection>
 
+#include <KTp/global-contact-manager.h>
+
+class KIcon;
+
+using namespace KTp;
+
 class ContactNotify : public QObject
 {
     Q_OBJECT
 public:
-    ContactNotify(Tp::AccountManagerPtr accountMgr, QObject *parent = 0);
+    ContactNotify(const Tp::AccountManagerPtr &accountMgr, QObject *parent = 0);
+
+private Q_SLOTS:
+    void onContactsChanged(const AccountContactList &contactsAdded, const AccountContactList &contactsRemoved);
+    void contactPresenceChanged(const Tp::Presence &presence);
 
 private:
     Tp::AccountManagerPtr m_accountManager;
-    Tp::ConnectionPtr m_connection;
-    void sendNotification(QString, KIcon, const Tp::Contact*);
-
-private Q_SLOTS:
-    void accountCameOnline(bool);
-    void accountIsOnline(const Tp::Account *);
-    void contactPresenceChanged(const Tp::Presence);
-    void onStatusChanged(const Tp::ConnectionStatus);
+    void sendNotification(const QString &text, const KIcon &icon, const Tp::ContactPtr &contact);
+    QHash<QString, int> m_presenceHash;
 };
 
 #endif // CONTACTNOTIFY_H

-- 
ktp-kded-integration-module packaging



More information about the pkg-kde-commits mailing list