[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:04:31 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=61620c4
The following commit has been merged in the master branch:
commit 61620c4d8ec28c26bbd4af0f16823691d49d5004
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
---
models/accounts-model-item.cpp | 27 ++++++++++++++++++++++++++-
models/accounts-model-item.h | 2 ++
models/accounts-model.cpp | 9 +++++++++
models/accounts-model.h | 3 +++
models/groups-model-item.cpp | 34 ++++++++++++++++++++++++++++++++--
models/groups-model-item.h | 2 +-
models/groups-model.cpp | 25 +++++++++++++++----------
7 files changed, 88 insertions(+), 14 deletions(-)
diff --git a/models/accounts-model-item.cpp b/models/accounts-model-item.cpp
index 6facdea..94ecfda 100644
--- a/models/accounts-model-item.cpp
+++ b/models/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/models/accounts-model-item.h b/models/accounts-model-item.h
index 54d8f87..e3748b7 100644
--- a/models/accounts-model-item.h
+++ b/models/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/models/accounts-model.cpp b/models/accounts-model.cpp
index 47fc697..e8867fc 100644
--- a/models/accounts-model.cpp
+++ b/models/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/models/accounts-model.h b/models/accounts-model.h
index 96e8994..7a9991e 100644
--- a/models/accounts-model.h
+++ b/models/accounts-model.h
@@ -86,6 +86,9 @@ public:
UpgradeCallCapabilityRole,
FileTransferCapabilityRole,
+ TotalUsersCountRole,
+ OnlineUsersCountRole,
+
CustomRole // a placemark for custom roles in inherited models
};
diff --git a/models/groups-model-item.cpp b/models/groups-model-item.cpp
index 6eec952..f01a7d6 100644
--- a/models/groups-model-item.cpp
+++ b/models/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/models/groups-model-item.h b/models/groups-model-item.h
index 63f3973..7fe99cc 100644
--- a/models/groups-model-item.h
+++ b/models/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/models/groups-model.cpp b/models/groups-model.cpp
index 46631e4..1ee874a 100644
--- a/models/groups-model.cpp
+++ b/models/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-common-internals packaging
More information about the pkg-kde-commits
mailing list