[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:06:37 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=690bb27

The following commit has been merged in the master branch:
commit 690bb273aca43e936f1db7ca4aa1b26a4b3364e6
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Thu Jun 9 13:02:33 2011 +0200

    Add group counts (model and delegate) and enable filter to filter out empty groups.
    
    Reviewed-by: David Edmundson
    REVIEW: 101559
---
 abstract-contact-delegate.cpp |  6 +++---
 account-filter-model.cpp      | 13 ++++++++++---
 accounts-model-item.cpp       | 27 ++++++++++++++++++++++++++-
 accounts-model-item.h         |  2 ++
 accounts-model.cpp            |  9 +++++++++
 accounts-model.h              |  3 +++
 groups-model-item.cpp         | 34 ++++++++++++++++++++++++++++++++--
 groups-model-item.h           |  2 +-
 groups-model.cpp              | 25 +++++++++++++++----------
 9 files changed, 101 insertions(+), 20 deletions(-)

diff --git a/abstract-contact-delegate.cpp b/abstract-contact-delegate.cpp
index db2f3de..fd9d7f5 100644
--- a/abstract-contact-delegate.cpp
+++ b/abstract-contact-delegate.cpp
@@ -77,8 +77,8 @@ void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewIte
 
     QFont groupFont = KGlobalSettings::smallestReadableFont();
 
-    QString counts;// = QString(" (%1/%2)").arg(index.data(AccountsModel::).toString(),
-    //               index.data(ModelRoles::AccountAllContactsCountRole).toString());
+    QString counts = QString(" (%1/%2)").arg(index.data(AccountsModel::OnlineUsersCountRole).toString(),
+                   index.data(AccountsModel::TotalUsersCountRole).toString());
 
     if (index.data(AccountsModel::ItemRole).userType() == qMetaTypeId<AccountsModelItem*>()) {
         painter->drawPixmap(accountGroupRect, KIcon(index.data(AccountsModel::IconRole).toString())
@@ -101,7 +101,7 @@ void AbstractContactDelegate::paint(QPainter* painter, const QStyleOptionViewIte
     painter->setRenderHint(QPainter::Antialiasing, false);
 
     QFontMetrics fm = painter->fontMetrics();
-    int groupNameWidth = fm.width(index.data(GroupsModel::GroupNameRole).toString());
+    int groupNameWidth = fm.width(index.data(GroupsModel::GroupNameRole).toString().append(counts));
 
     painter->drawLine(expandSignRect.right() + SPACING * 2,
                       groupRect.y() + groupRect.height() / 2,
diff --git a/account-filter-model.cpp b/account-filter-model.cpp
index 2542ae6..d30b208 100644
--- a/account-filter-model.cpp
+++ b/account-filter-model.cpp
@@ -23,8 +23,6 @@
 #include "accounts-model.h"
 #include "groups-model.h"
 
-#include <KDebug>
-
 AccountFilterModel::AccountFilterModel(QObject *parent)
     : QSortFilterProxyModel(parent),
       m_filterOfflineUsers(false),
@@ -70,7 +68,16 @@ bool AccountFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sou
         QModelIndex index = sourceModel()->index(source_row, 0);
         if (index.isValid()) {
             if (m_groupsActive) {
-                rowAccepted = true;
+                if (m_filterOfflineUsers) {
+                    if (index.data(AccountsModel::OnlineUsersCountRole).toInt() > 0) {
+                        return true;
+                    } else {
+                        return false;
+                    }
+                } else {
+                    //if the offline users are shown, display all the groups
+                    return true;
+                }
             } else {
                 if (!index.data(AccountsModel::EnabledRole).toBool()) {
                     rowAccepted = false;
diff --git a/accounts-model-item.cpp b/accounts-model-item.cpp
index 6facdea..94ecfda 100644
--- a/accounts-model-item.cpp
+++ b/accounts-model-item.cpp
@@ -31,7 +31,8 @@
 struct AccountsModelItem::Private
 {
     Private(const Tp::AccountPtr &account)
-        : mAccount(account)
+        : mAccount(account),
+          mOnlineCount(0)
     {
     }
 
@@ -39,6 +40,7 @@ struct AccountsModelItem::Private
     void setStatusMessage(const QString &value);
 
     Tp::AccountPtr mAccount;
+    int mOnlineCount;
 };
 
 void AccountsModelItem::Private::setStatus(const QString &value)
@@ -179,6 +181,10 @@ QVariant AccountsModelItem::data(int role) const
         return mPriv->mAccount->connectionStatus();
     case AccountsModel::ConnectionStatusReasonRole:
         return mPriv->mAccount->connectionStatusReason();
+    case AccountsModel::TotalUsersCountRole:
+        return size();
+    case AccountsModel::OnlineUsersCountRole:
+        return mPriv->mOnlineCount;
     default:
         return QVariant();
     }
@@ -277,6 +283,8 @@ void AccountsModelItem::onContactsChanged(const Tp::Contacts &addedContacts,
         }
     }
     emit childrenAdded(this, newNodes);
+
+    countOnlineContacts();
 }
 
 void AccountsModelItem::onStatusChanged(Tp::ConnectionStatus status)
@@ -383,6 +391,23 @@ void AccountsModelItem::addKnownContacts()
     if (newNodes.count() > 0) {
         emit childrenAdded(this, newNodes);
     }
+
+    countOnlineContacts();
+}
+
+void AccountsModelItem::countOnlineContacts()
+{
+    int tmpCounter = 0;
+    for (int i = 0; i < size(); ++i) {
+        ContactModelItem* contactNode = qobject_cast<ContactModelItem*>(childAt(i));
+        Q_ASSERT(contactNode);
+        if (contactNode->data(AccountsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
+            && contactNode->data(AccountsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
+            tmpCounter++;
+        }
+    }
+
+    mPriv->mOnlineCount = tmpCounter;
 }
 
 #include "accounts-model-item.moc"
diff --git a/accounts-model-item.h b/accounts-model-item.h
index 54d8f87..e3748b7 100644
--- a/accounts-model-item.h
+++ b/accounts-model-item.h
@@ -53,6 +53,8 @@ public:
 
     void clearContacts();
 
+    void countOnlineContacts();
+
 Q_SIGNALS:
     void connectionStatusChanged(const QString &accountId, int status);
 
diff --git a/accounts-model.cpp b/accounts-model.cpp
index 47fc697..e8867fc 100644
--- a/accounts-model.cpp
+++ b/accounts-model.cpp
@@ -134,6 +134,15 @@ void AccountsModel::onNewAccount(const Tp::AccountPtr &account)
 
 void AccountsModel::onItemChanged(TreeNode *node)
 {
+    if (node->parent()) {
+        //if it is a group item
+        if (node->parent() == mPriv->mTree) {
+            qobject_cast<AccountsModelItem*>(node)->countOnlineContacts();
+        } else {
+            qobject_cast<AccountsModelItem*>(node->parent())->countOnlineContacts();
+            emit dataChanged(index(node->parent()), index(node->parent()));
+        }
+    }
     QModelIndex accountIndex = index(node);
     emit dataChanged(accountIndex, accountIndex);
 }
diff --git a/accounts-model.h b/accounts-model.h
index 96e8994..7a9991e 100644
--- a/accounts-model.h
+++ b/accounts-model.h
@@ -86,6 +86,9 @@ public:
         UpgradeCallCapabilityRole,
         FileTransferCapabilityRole,
 
+        TotalUsersCountRole,
+        OnlineUsersCountRole,
+
         CustomRole // a placemark for custom roles in inherited models
     };
 
diff --git a/groups-model-item.cpp b/groups-model-item.cpp
index 6eec952..f01a7d6 100644
--- a/groups-model-item.cpp
+++ b/groups-model-item.cpp
@@ -32,7 +32,8 @@
 struct GroupsModelItem::Private
 {
     Private(const QString &groupName)
-        : mGroupName(groupName)
+        : mGroupName(groupName),
+          mOnlineUsersCount(0)
     {
     }
 
@@ -40,6 +41,7 @@ struct GroupsModelItem::Private
     QString groupName();
 
     QString mGroupName;
+    int mOnlineUsersCount;
 };
 
 void GroupsModelItem::Private::setGroupName(const QString& value)
@@ -69,6 +71,10 @@ QVariant GroupsModelItem::data(int role) const
         return QVariant::fromValue((GroupsModelItem*)this);
     case GroupsModel::GroupNameRole:
         return mPriv->mGroupName;
+    case AccountsModel::TotalUsersCountRole:
+        return size();
+    case AccountsModel::OnlineUsersCountRole:
+        return mPriv->mOnlineUsersCount;
     default:
         return QVariant();
     }
@@ -98,19 +104,43 @@ QString GroupsModelItem::groupName()
 void GroupsModelItem::addProxyContact(ProxyTreeNode *proxyNode)
 {
     emit childrenAdded(this, QList<TreeNode*>() << proxyNode);
+
+    //the group counters needs to be updated
+    emit changed(this);
 }
 
 void GroupsModelItem::removeProxyContact(ProxyTreeNode *proxyNode)
 {
     emit childrenRemoved(this, indexOf(proxyNode), indexOf(proxyNode));
+
+    //the group counters needs to be updated
+    emit changed(this);
 }
 
 void GroupsModelItem::removeContact(ContactModelItem* contact)
 {
-    for (int i = 0; i < children().size(); i++) {
+    for (int i = 0; i < size(); i++) {
         ProxyTreeNode* proxyNode = qobject_cast<ProxyTreeNode*>(childAt(i));
         if (proxyNode->data(AccountsModel::ItemRole).value<ContactModelItem*>() == contact) {
             proxyNode->remove();
         }
     }
+
+    //the group counters needs to be updated
+    emit changed(this);
+}
+
+void GroupsModelItem::countOnlineContacts()
+{
+    int tmpCounter = 0;
+    for (int i = 0; i < size(); ++i) {
+        ProxyTreeNode* proxyNode = qobject_cast<ProxyTreeNode*>(childAt(i));
+        Q_ASSERT(proxyNode);
+        if (proxyNode->data(AccountsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
+            && proxyNode->data(AccountsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
+            tmpCounter++;
+        }
+    }
+
+    mPriv->mOnlineUsersCount = tmpCounter;
 }
diff --git a/groups-model-item.h b/groups-model-item.h
index 63f3973..7fe99cc 100644
--- a/groups-model-item.h
+++ b/groups-model-item.h
@@ -53,7 +53,7 @@ public:
     void removeProxyContact(ProxyTreeNode* proxyNode);
     void removeContact(ContactModelItem* contact);
 
-//     void clearContacts();
+    void countOnlineContacts();
 
 private Q_SLOTS:
 
diff --git a/groups-model.cpp b/groups-model.cpp
index 46631e4..1ee874a 100644
--- a/groups-model.cpp
+++ b/groups-model.cpp
@@ -154,6 +154,19 @@ QModelIndex GroupsModel::parent(const QModelIndex &index) const
 
 void GroupsModel::onItemChanged(TreeNode* node)
 {
+    if (node->parent()) {
+        //if it is a group item
+        if (node->parent() == mPriv->mTree) {
+            GroupsModelItem *groupItem = qobject_cast<GroupsModelItem*>(node);
+            Q_ASSERT(groupItem);
+            groupItem->countOnlineContacts();
+        } else {
+            GroupsModelItem *groupItem = qobject_cast<GroupsModelItem*>(node->parent());
+            Q_ASSERT(groupItem);
+            groupItem->countOnlineContacts();
+            emit dataChanged(index(node->parent()), index(node->parent()));
+        }
+    }
     emit dataChanged(index(node), index(node));
 }
 
@@ -178,6 +191,8 @@ void GroupsModel::onItemsRemoved(TreeNode *parent, int first, int last)
         parent->childAt(i)->remove();
     }
     endRemoveRows();
+
+    onItemChanged(parent);
 }
 
 
@@ -242,10 +257,7 @@ void GroupsModel::onContactRemovedFromGroup(const QString& group)
 
 void GroupsModel::removeContactFromGroup(ProxyTreeNode* proxyNode, const QString& group)
 {
-    kDebug() << "Removing contact from" << group;
-
     QStringList contactGroups = proxyNode->data(AccountsModel::ItemRole).value<ContactModelItem*>()->contact()->groups();
-    kDebug() << "Left groups are:" << contactGroups;
 
     contactGroups.removeOne(group);
 
@@ -278,8 +290,6 @@ void GroupsModel::addContactToGroups(ContactModelItem* contactItem, const QStrin
 
 void GroupsModel::addContactToGroups(ContactModelItem* contactItem, QStringList groups)
 {
-    kDebug() << "Contact groups:" << groups;
-
     //check if the contact is in Ungrouped group, if it is, it needs to be removed from there
     bool checkUngrouped = false;
     //if the contact has no groups, create an 'Ungrouped' group for it
@@ -295,15 +305,11 @@ void GroupsModel::addContactToGroups(ContactModelItem* contactItem, QStringList
         bool groupExists = false;
         GroupsModelItem *groupItem;
 
-        kDebug() << "Adding" << contactItem->contact()->alias() << "to" << group;
-
         //check if the group already exists first
         for (int i = 0; i < mPriv->mTree->children().size(); i++) {
-//         foreach (GroupsModelItem *savedGroupItem, mPriv->mTree->children()) {
             GroupsModelItem *savedGroupItem = qobject_cast<GroupsModelItem*>(mPriv->mTree->childAt(i));
             if (savedGroupItem->groupName() == group) {
                 groupExists = true;
-                kDebug() << "Existing group found for" << group;
                 groupItem = savedGroupItem;
 
                 if (!checkUngrouped) {
@@ -326,7 +332,6 @@ void GroupsModel::addContactToGroups(ContactModelItem* contactItem, QStringList
         }
 
         if (!groupExists) {
-            kDebug() << "Creating new group for" << group;
             groupItem = new GroupsModelItem(group);
             onItemsAdded(mPriv->mTree, QList<TreeNode *>() << groupItem);
         }

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list