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


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

The following commit has been merged in the master branch:
commit 232797df2ab9862c5834e049ba612c6550b07c16
Author: Rémy Greinhofer <remy.greinhofer at gmail.com>
Date:   Fri Apr 22 15:34:09 2011 +0200

    Filter by status in the proxy model
    
    The contacts in the list are now sorted by default by name, and can be
    as well sorted by status.
    
    BUG: 246223
    REVIEW: 101108
    Reviewed by: David Edmundson
---
 account-filter-model.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++--
 account-filter-model.h   | 25 ++++++++++++++++++++++++
 main-widget.cpp          | 29 ++++++++++++++++++++-------
 main-widget.h            |  2 +-
 4 files changed, 97 insertions(+), 10 deletions(-)

diff --git a/account-filter-model.cpp b/account-filter-model.cpp
index 7182362..8ca6561 100644
--- a/account-filter-model.cpp
+++ b/account-filter-model.cpp
@@ -21,6 +21,7 @@
 
 #include "account-filter-model.h"
 #include "accounts-model.h"
+
 #include <KDebug>
 
 AccountFilterModel::AccountFilterModel(QObject *parent)
@@ -78,7 +79,7 @@ bool AccountFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sou
     return rowAccepted;
 }
 
-void AccountFilterModel::setFilterString(const QString& str)
+void AccountFilterModel::setFilterString(const QString &str)
 {
     m_filterString = str;
     m_filterByName = true;
@@ -90,4 +91,50 @@ void AccountFilterModel::clearFilterString()
     m_filterString.clear();
     m_filterByName = false;
     invalidateFilter();
-}
\ No newline at end of file
+}
+
+bool AccountFilterModel::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 AccountFilterModel::setSortByPresence(bool enabled)
+{
+    if (enabled) {
+        setSortRole(AccountsModel::PresenceTypeRole);
+    } else {
+        setSortRole(Qt::DisplayRole);
+    }
+}
+
+bool AccountFilterModel::isSortedByPresence() const
+{
+    return sortRole() == AccountsModel::PresenceTypeRole;
+}
diff --git a/account-filter-model.h b/account-filter-model.h
index d33231d..6591355 100644
--- a/account-filter-model.h
+++ b/account-filter-model.h
@@ -23,6 +23,16 @@
 
 #include <QSortFilterProxyModel>
 
+/**
+  * 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 AccountFilterModel : public QSortFilterProxyModel
 {
     Q_OBJECT
@@ -31,13 +41,28 @@ public:
     AccountFilterModel(QObject *parent = 0);
     bool filterOfflineUsers() 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 filterOfflineUsers(bool filterOfflineUsers);
     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 source_row, const QModelIndex &source_parent) const;
+    bool lessThan ( const QModelIndex &left, const QModelIndex &right ) const;
 
 private:
     /// Filters out offline users
diff --git a/main-widget.cpp b/main-widget.cpp
index 498d01c..88895e5 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -128,6 +128,13 @@ MainWidget::MainWidget(QWidget *parent)
 
     m_toolBar->addAction(m_hideOfflineAction);
 
+    m_sortByPresenceAction = new KAction(KIcon("view-sort-ascending"), QString(), this);
+    m_sortByPresenceAction->setCheckable(true);
+    m_sortByPresenceAction->setChecked(false);
+    m_sortByPresenceAction->setToolTip(i18n("Sort by presence"));
+
+    m_toolBar->addAction(m_sortByPresenceAction);
+
     m_searchContactAction = new KAction(KIcon("edit-find-user"), QString(), this );
     m_searchContactAction->setShortcut(KStandardShortcut::find());
     m_searchContactAction->setCheckable(true);
@@ -233,9 +240,11 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
     m_modelFilter = new AccountFilterModel(this);
     m_modelFilter->setSourceModel(m_model);
     m_modelFilter->setDynamicSortFilter(true);
-    m_modelFilter->filterOfflineUsers(true);
+    m_modelFilter->filterOfflineUsers(m_hideOfflineAction->isChecked());
     m_modelFilter->clearFilterString();
+    m_modelFilter->setFilterCaseSensitivity(Qt::CaseInsensitive);
     m_modelFilter->setSortRole(Qt::DisplayRole);
+    m_modelFilter->setSortByPresence(m_sortByPresenceAction->isChecked());
     m_contactsListView->setModel(m_modelFilter);
     m_contactsListView->setSortingEnabled(true);
     m_contactsListView->sortByColumn(0, Qt::AscendingOrder);
@@ -255,6 +264,9 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
     connect(m_filterBar, SIGNAL(closeRequest()),
             m_searchContactAction, SLOT(toggle()));
 
+    connect(m_sortByPresenceAction, SIGNAL(toggled(bool)),
+            m_modelFilter, SLOT(setSortByPresence(bool)));
+
     connect(m_modelFilter, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
         m_delegate, SLOT(contactRemoved(QModelIndex,int,int)));
 
@@ -351,12 +363,15 @@ void MainWidget::onContactManagerStateChanged(Tp::ContactListState state)
     if (state == Tp::ContactListStateSuccess) {
         Tp::ContactManagerPtr contactManager(qobject_cast< Tp::ContactManager* >(sender()));
 
-        QFutureWatcher< Tp::ContactPtr > watcher;
-        connect(&watcher, SIGNAL(finished()), this, SLOT(onAccountsPresenceStatusFiltered()));
-        watcher.setFuture(QtConcurrent::filtered(contactManager->allKnownContacts(),
-                                                 kde_tp_filter_contacts_by_publication_status));
+        if (contactManager) {
 
-        kDebug() << "Watcher is on";
+            QFutureWatcher< Tp::ContactPtr > watcher;
+            connect(&watcher, SIGNAL(finished()), this, SLOT(onAccountsPresenceStatusFiltered()));
+            watcher.setFuture(QtConcurrent::filtered(contactManager->allKnownContacts(),
+                                                    kde_tp_filter_contacts_by_publication_status));
+
+            kDebug() << "Watcher is on";
+        }
     }
 }
 
@@ -528,7 +543,7 @@ void MainWidget::toggleSearchWidget(bool show)
 void MainWidget::onAddContactRequest() {
     QWeakPointer<AddContactDialog> dialog = new AddContactDialog(m_model, this);
     if (dialog.data()->exec() == QDialog::Accepted) {
-	Tp::AccountPtr account = dialog.data()->account();
+    Tp::AccountPtr account = dialog.data()->account();
         QStringList identifiers = QStringList() << dialog.data()->screenName();
         Tp::PendingContacts* pendingContacts = account->connection()->contactManager()->contactsForIdentifiers(identifiers);
         connect(pendingContacts, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onAddContactRequestFoundContacts(Tp::PendingOperation*)));
diff --git a/main-widget.h b/main-widget.h
index a63045f..68bc7b5 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -85,7 +85,6 @@ public Q_SLOTS:
     void loadAvatarFromFile();
     //    void startAudioChannel();
     //    void startVideoChannel();
-
     void onCustomContextMenuRequested(const QPoint &point);
 
 private Q_SLOTS:
@@ -114,6 +113,7 @@ private:
     KAction                *m_groupContactsAction;
     KAction                *m_hideOfflineAction;
     KAction                *m_searchContactAction;
+    KAction                *m_sortByPresenceAction;
 };
 
 

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list