[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:32 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=ab27e83
The following commit has been merged in the master branch:
commit ab27e8387f5ab1df502ec93d4f344c3b98bcd76a
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Sat Jun 18 02:03:23 2011 +0100
Renamed AccountFilterModel to AccountsFilterModel, to match accountS model
REVIEW: 101665
Reviewed-by: Francesco Nwokeka
---
models/accounts-filter-model.cpp | 178 +++++++++++++++++++++++++++++++++++++++
models/accounts-filter-model.h | 86 +++++++++++++++++++
2 files changed, 264 insertions(+)
diff --git a/models/accounts-filter-model.cpp b/models/accounts-filter-model.cpp
new file mode 100644
index 0000000..24580d4
--- /dev/null
+++ b/models/accounts-filter-model.cpp
@@ -0,0 +1,178 @@
+/*
+ * Provide some filters on the account model
+ *
+ * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
+ * Copyright (C) 2011 Martin Klapetek <martin dot klapetek at gmail dot com>
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "accounts-filter-model.h"
+
+#include "accounts-model.h"
+#include "groups-model.h"
+#include "groups-model-item.h"
+#include "contact-model-item.h"
+#include "accounts-model-item.h"
+
+
+#include <KDebug>
+
+AccountsFilterModel::AccountsFilterModel(QObject *parent)
+ : QSortFilterProxyModel(parent),
+ m_showOfflineUsers(false),
+ m_filterByName(false)
+{
+
+}
+
+void AccountsFilterModel::showOfflineUsers(bool showOfflineUsers)
+{
+ m_showOfflineUsers = showOfflineUsers;
+ invalidateFilter();
+}
+
+bool AccountsFilterModel::showOfflineUsers() const
+{
+ return m_showOfflineUsers;
+}
+
+bool AccountsFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+{
+ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+
+ int type = index.data(AccountsModel::ItemRole).userType();
+ if (type == qMetaTypeId<ContactModelItem*>()) {
+ return filterAcceptsContact(index);
+ }
+ else if (type == qMetaTypeId<AccountsModelItem*>()) {
+ return filterAcceptsAccount(index);
+ }
+ else if (type == qMetaTypeId<GroupsModelItem*>()) {
+ return filterAcceptsGroup(index);
+ }
+ else {
+ kDebug() << "Unknown type found in Account Filter";
+ return true;
+ }
+}
+
+bool AccountsFilterModel::filterAcceptsAccount(const QModelIndex &index) const
+{
+ bool rowAccepted = true;
+ //hide disabled accounts
+ if (!index.data(AccountsModel::EnabledRole).toBool()) {
+ rowAccepted = false;
+ }
+ //hide
+ if (index.data(AccountsModel::ConnectionStatusRole).toUInt()
+ != Tp::ConnectionStatusConnected) {
+ rowAccepted = false;
+ }
+ return rowAccepted;
+}
+
+bool AccountsFilterModel::filterAcceptsContact(const QModelIndex &index) const
+{
+ bool rowAccepted = true;
+ if (m_filterByName &&
+ !index.data(AccountsModel::AliasRole).toString().contains(m_filterString, Qt::CaseInsensitive)) {
+ rowAccepted = false;
+ }
+
+ //filter offline users out
+ if (!m_showOfflineUsers &&
+ ((index.data(AccountsModel::PresenceTypeRole).toUInt()
+ == Tp::ConnectionPresenceTypeOffline) ||
+ (index.data(AccountsModel::PresenceTypeRole).toUInt()
+ == Tp::ConnectionPresenceTypeUnknown))) {
+ rowAccepted = false;
+ }
+ return rowAccepted;
+}
+
+bool AccountsFilterModel::filterAcceptsGroup(const QModelIndex &index) const
+{
+ bool acceptRow = true;
+ if (!m_showOfflineUsers) {
+ if (index.data(AccountsModel::OnlineUsersCountRole).toInt() == 0) {
+ acceptRow = false;
+ }
+ }
+ return acceptRow;
+}
+
+void AccountsFilterModel::setFilterString(const QString &str)
+{
+ m_filterString = str;
+ m_filterByName = true;
+ invalidateFilter();
+}
+
+void AccountsFilterModel::clearFilterString()
+{
+ m_filterString.clear();
+ m_filterByName = false;
+ invalidateFilter();
+}
+
+bool AccountsFilterModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
+{
+ uint leftPresence;
+ uint rightPresence;
+
+ QString leftDisplayedName = sourceModel()->data(left).toString();
+ QString rightDisplayedName = sourceModel()->data(right).toString();
+
+ if (sortRole() == AccountsModel::PresenceTypeRole) {
+ leftPresence = sourceModel()->data(left, AccountsModel::PresenceTypeRole).toUInt();
+ rightPresence = sourceModel()->data(right, AccountsModel::PresenceTypeRole).toUInt();
+
+ if (leftPresence == rightPresence) {
+ return QString::localeAwareCompare(leftDisplayedName, rightDisplayedName) < 0;
+ } else {
+ if (leftPresence == Tp::ConnectionPresenceTypeAvailable) {
+ return true;
+ }
+ if (leftPresence == Tp::ConnectionPresenceTypeUnset ||
+ leftPresence == Tp::ConnectionPresenceTypeOffline ||
+ leftPresence == Tp::ConnectionPresenceTypeUnknown ||
+ leftPresence == Tp::ConnectionPresenceTypeError) {
+ return false;
+ }
+
+ return leftPresence < rightPresence;
+ }
+ } else {
+ return QString::localeAwareCompare(leftDisplayedName, rightDisplayedName) < 0;
+ }
+}
+
+void AccountsFilterModel::setSortByPresence(bool enabled)
+{
+ if (enabled) {
+ setSortRole(AccountsModel::PresenceTypeRole);
+ } else {
+ setSortRole(Qt::DisplayRole);
+ }
+}
+
+bool AccountsFilterModel::isSortedByPresence() const
+{
+ return sortRole() == AccountsModel::PresenceTypeRole;
+}
+
+
+#include "accounts-filter-model.moc"
diff --git a/models/accounts-filter-model.h b/models/accounts-filter-model.h
new file mode 100644
index 0000000..4340ad4
--- /dev/null
+++ b/models/accounts-filter-model.h
@@ -0,0 +1,86 @@
+/*
+ * Provide some filters on the account model
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef ACCOUNTSFILTERMODEL_H
+#define ACCOUNTSFILTERMODEL_H
+
+#include <QSortFilterProxyModel>
+
+class AccountsModelItem;
+class ContactModelItem;
+
+/**
+ * rief Class used to sort and filter the contacts.
+ *
+ * Filters:
+ * Hide offline contacts
+ * Hide contacts not matching a string in the search bar
+ * Sort contacts:
+ * By name
+ * By presence
+ */
+class AccountsFilterModel : public QSortFilterProxyModel
+{
+ Q_OBJECT
+
+public:
+ AccountsFilterModel(QObject *parent = 0);
+
+ bool showOfflineUsers() const;
+
+ /**
+ * rief Flag to sort the contactlist by presence.
+ *
+ * If set to false, the contact list is only sorted by name.
+ */
+ bool isSortedByPresence() const;
+
+public slots:
+ void showOfflineUsers(bool showOfflineUsers);
+ void setFilterString(const QString &str);
+ void clearFilterString();
+ /**
+ * rief Lets the proxy know whether the model should get sorted by presence or not.
+ *
+ * \param enabled if true, the model will get sorted by presence, otherwise just by name.
+ */
+ void setSortByPresence(bool enabled);
+
+protected:
+ bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+ bool lessThan ( const QModelIndex &left, const QModelIndex &right ) const;
+
+private:
+
+ bool filterAcceptsAccount(const QModelIndex &index) const;
+ bool filterAcceptsContact(const QModelIndex &index) const;
+ bool filterAcceptsGroup(const QModelIndex &index) const;
+
+ /// Shows offline users
+ bool m_showOfflineUsers;
+
+ /// Used when searching for contact
+ bool m_filterByName;
+
+ /// Holds the string which is searched in the model
+ QString m_filterString;
+};
+
+#endif // ACCOUNTFILTERMODEL_H
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list