[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:06:03 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=6dd9dd8
The following commit has been merged in the master branch:
commit 6dd9dd8764ab83e2f485734d07c5f54638508847
Author: Dan Vrátil <dvratil at redhat.com>
Date: Thu Jan 3 16:08:24 2013 +0100
Update group members counters when contact presence changes
---
KTp/Models/contacts-filter-model.cpp | 157 ++++++++++++++++++++---------------
KTp/Models/contacts-filter-model.h | 5 +-
2 files changed, 91 insertions(+), 71 deletions(-)
diff --git a/KTp/Models/contacts-filter-model.cpp b/KTp/Models/contacts-filter-model.cpp
index 87d9f71..b7b16b9 100644
--- a/KTp/Models/contacts-filter-model.cpp
+++ b/KTp/Models/contacts-filter-model.cpp
@@ -69,7 +69,10 @@ public:
bool filterAcceptsAccount(const QModelIndex &index) const;
bool filterAcceptsContact(const QModelIndex &index) const;
- bool filterAcceptsGroup(const QModelIndex &index) const;
+ bool filterAcceptsGroup(const QModelIndex &index);
+
+ void countContacts(const QModelIndex &sourceParent);
+ void sourceModelChanged(const QModelIndex &sourceIndex);
QHash<QString, int> m_onlineContactsCounts;
QHash<QString, int> m_totalContactsCounts;
@@ -352,14 +355,14 @@ bool ContactsFilterModel::Private::filterAcceptsContact(const QModelIndex &index
return true;
}
-bool ContactsFilterModel::Private::filterAcceptsGroup(const QModelIndex &index) const
+bool ContactsFilterModel::Private::filterAcceptsGroup(const QModelIndex &index)
{
QString groupName = index.data(ContactsModel::IdRole).toString();
if (presenceTypeFilterFlags != DoNotFilterByPresence) {
// If there is no cached value, create one
if (!m_onlineContactsCounts.contains(groupName)) {
- q->countContacts(index);
+ countContacts(index);
}
// Don't accept groups with no online contacts
@@ -370,7 +373,7 @@ bool ContactsFilterModel::Private::filterAcceptsGroup(const QModelIndex &index)
else {
// If there is no cached value, create one
if (!m_totalContactsCounts.contains(groupName)) {
- q->countContacts(index);
+ countContacts(index);
}
// Don't accept groups with no total contacts
@@ -381,6 +384,75 @@ bool ContactsFilterModel::Private::filterAcceptsGroup(const QModelIndex &index)
return true;
}
+void ContactsFilterModel::Private::countContacts(const QModelIndex &sourceParent)
+{
+ QString key;
+
+ ContactsModel::RowType rowType = static_cast<ContactsModel::RowType>(sourceParent.data(ContactsModel::TypeRole).toInt());
+ if (rowType == ContactsModel::GroupRowType) {
+ key = sourceParent.data(Qt::DisplayRole).toString();
+ } else if (rowType == ContactsModel::AccountRowType) {
+ Tp::AccountPtr account = sourceParent.data(ContactsModel::AccountRole).value<Tp::AccountPtr>();
+ if (account.isNull()) {
+ return;
+ }
+ key = account->uniqueIdentifier();
+ } else {
+ return;
+ }
+
+ // Count the online contacts
+ int tmpCounter = 0;
+
+ for (int i = 0; i < q->sourceModel()->rowCount(sourceParent); ++i) {
+ QModelIndex child = q->sourceModel()->index(i, 0, sourceParent);
+
+ // We want all online contacts that are accepted by the filter
+ if (q->filterAcceptsRow(child.row(), sourceParent)
+ && child.data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
+ && child.data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
+ tmpCounter++;
+ }
+ }
+
+ m_onlineContactsCounts.insert(key, tmpCounter);
+
+ // Now count the total contacts accepted by the filter (but ignore presence filter).
+ // Save the presenceTypeFilterFlags to reapply them later, because we need to disable
+ // presence filtering to get the right numbers
+ PresenceTypeFilterFlags saved = q->presenceTypeFilterFlags();
+ presenceTypeFilterFlags = ContactsFilterModel::DoNotFilterByPresence;
+
+ tmpCounter = 0;
+ for (int i = 0; i < q->sourceModel()->rowCount(sourceParent); ++i) {
+ QModelIndex child = q->sourceModel()->index(i, 0, sourceParent);
+ if (q->filterAcceptsRow(child.row(), sourceParent)) {
+ tmpCounter++;
+ }
+ }
+
+ // Restore the saved presenceTypeFilterFlags
+ presenceTypeFilterFlags = saved;
+
+ m_totalContactsCounts.insert(key, tmpCounter);
+}
+
+void ContactsFilterModel::Private::sourceModelChanged(const QModelIndex &sourceIndex)
+{
+ const QModelIndex groupSourceIndex;
+ if (sourceIndex.data(ContactsModel::TypeRole).toUInt() == ContactsModel::ContactRowType) {
+ groupSourceIndex = sourceIndex.parent();
+ } else {
+ groupSourceIndex = sourceIndex;
+ }
+
+ countContacts(groupSourceIndex);
+
+ const QModelIndex mappedIndex = q->mapFromSource(sourceIndex);
+ Q_EMIT q->dataChanged(mappedIndex, mappedIndex);
+}
+
+
ContactsFilterModel::ContactsFilterModel(QObject *parent)
: QSortFilterProxyModel(parent),
d(new Private(this))
@@ -410,7 +482,7 @@ QVariant ContactsFilterModel::data(const QModelIndex &index, int role) const
const QString groupName = sourceIndex.data(Qt::DisplayRole).toString();
// If there is no cached value, create one
if (!d->m_onlineContactsCounts.contains(groupName)) {
- countContacts(sourceIndex);
+ d->countContacts(sourceIndex);
}
return d->m_onlineContactsCounts.value(groupName);
} else if (rowType == ContactsModel::AccountRowType) {
@@ -420,7 +492,7 @@ QVariant ContactsFilterModel::data(const QModelIndex &index, int role) const
}
// If there is no cached value, create one
if (!d->m_onlineContactsCounts.contains(account->uniqueIdentifier())) {
- countContacts(sourceIndex);
+ d->countContacts(sourceIndex);
}
return d->m_onlineContactsCounts.value(account->uniqueIdentifier());
}
@@ -429,7 +501,7 @@ QVariant ContactsFilterModel::data(const QModelIndex &index, int role) const
const QString groupName = sourceIndex.data(Qt::DisplayRole).toString();
// If there is no cached value, create one
if (!d->m_totalContactsCounts.contains(groupName)) {
- countContacts(sourceIndex);
+ d->countContacts(sourceIndex);
}
return d->m_totalContactsCounts.value(groupName);
} else if (rowType == ContactsModel::AccountRowType) {
@@ -439,7 +511,7 @@ QVariant ContactsFilterModel::data(const QModelIndex &index, int role) const
}
// If there is no cached value, create one
if (!d->m_totalContactsCounts.contains(account->uniqueIdentifier())) {
- countContacts(sourceIndex);
+ d->countContacts(sourceIndex);
}
return d->m_totalContactsCounts.value(account->uniqueIdentifier());
}
@@ -453,13 +525,13 @@ void ContactsFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
{
// Disconnect the previous source model
disconnect(this->sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
disconnect(this->sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
disconnect(this->sourceModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
disconnect(this->sourceModel(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
// Clear all cached values as they aren't valid anymore because the source model changed.
d->m_onlineContactsCounts.clear();
@@ -468,13 +540,13 @@ void ContactsFilterModel::setSourceModel(QAbstractItemModel *sourceModel)
// Connect the new source model
connect(this->sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
connect(this->sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
connect(this->sourceModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
connect(this->sourceModel(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
- this, SLOT(countContacts(QModelIndex)));
+ this, SLOT(sourceModelChanged(QModelIndex)));
}
void ContactsFilterModel::invalidateFilter()
@@ -816,59 +888,6 @@ void ContactsFilterModel::setIdFilterMatchFlags(Qt::MatchFlags idFilterMatchFlag
}
}
-void ContactsFilterModel::countContacts(const QModelIndex &sourceParent) const
-{
- QString key;
-
- ContactsModel::RowType rowType = static_cast<ContactsModel::RowType>(sourceParent.data(ContactsModel::TypeRole).toInt());
- if (rowType == ContactsModel::GroupRowType) {
- key = sourceParent.data(Qt::DisplayRole).toString();
- } else if (rowType == ContactsModel::AccountRowType) {
- Tp::AccountPtr account = sourceParent.data(ContactsModel::AccountRole).value<Tp::AccountPtr>();
- if (account.isNull()) {
- return;
- }
- key = account->uniqueIdentifier();
- } else {
- return;
- }
-
- // Count the online contacts
- int tmpCounter = 0;
-
- for (int i = 0; i < sourceModel()->rowCount(sourceParent); ++i) {
- QModelIndex child = sourceModel()->index(i, 0, sourceParent);
-
- // We want all online contacts that are accepted by the filter
- if (filterAcceptsRow(child.row(), sourceParent)
- && child.data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeOffline
- && child.data(ContactsModel::PresenceTypeRole).toUInt() != Tp::ConnectionPresenceTypeUnknown) {
- tmpCounter++;
- }
- }
-
- d->m_onlineContactsCounts.insert(key, tmpCounter);
-
- // Now count the total contacts accepted by the filter (but ignore presence filter).
- // Save the presenceTypeFilterFlags to reapply them later, because we need to disable
- // presence filtering to get the right numbers
- PresenceTypeFilterFlags saved = presenceTypeFilterFlags();
- d->presenceTypeFilterFlags = ContactsFilterModel::DoNotFilterByPresence;
-
- tmpCounter = 0;
- for (int i = 0; i < sourceModel()->rowCount(sourceParent); ++i) {
- QModelIndex child = sourceModel()->index(i, 0, sourceParent);
- if (filterAcceptsRow(child.row(), sourceParent)) {
- tmpCounter++;
- }
- }
-
- // Restore the saved presenceTypeFilterFlags
- d->presenceTypeFilterFlags = saved;
-
- d->m_totalContactsCounts.insert(key, tmpCounter);
-}
-
bool ContactsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
diff --git a/KTp/Models/contacts-filter-model.h b/KTp/Models/contacts-filter-model.h
index 4a29e74..bddebb0 100644
--- a/KTp/Models/contacts-filter-model.h
+++ b/KTp/Models/contacts-filter-model.h
@@ -277,8 +277,6 @@ public:
Q_SLOT void setIdFilterMatchFlags(Qt::MatchFlags idFilterMatchFlags);
Q_SIGNAL void idFilterMatchFlagsChanged(Qt::MatchFlags idFilterMatchFlags);
- Q_SLOT void countContacts(const QModelIndex &index) const;
-
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
bool lessThan (const QModelIndex &left, const QModelIndex &right) const;
@@ -289,6 +287,9 @@ protected:
private:
class Private;
Private * const d;
+
+ Q_PRIVATE_SLOT(d, void sourceModelChanged(const QModelIndex &index))
+ Q_PRIVATE_SLOT(d, void countContacts(const QModelIndex &index))
};
#endif // ACCOUNTFILTERMODEL_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list