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


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

The following commit has been merged in the master branch:
commit b8a2e12b77aad62cd98d30e79543b55ce2226d5e
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Thu Mar 10 20:30:22 2011 +0100

    Add user filtering by search string
---
 CMakeLists.txt         |  1 +
 accountfiltermodel.cpp | 41 +++++++++++++++++----
 accountfiltermodel.h   | 11 +++++-
 filterbar.cpp          | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++
 filterbar.h            | 70 ++++++++++++++++++++++++++++++++++++
 main-widget.cpp        | 47 ++++++++++++++++--------
 main-widget.h          |  4 ++-
 main-widget.ui         | 26 ++++++++++++++
 8 files changed, 272 insertions(+), 24 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index dbeafa6..344812e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,7 @@ set (contactlist_SRCS
      contact-model-item.cpp
      tree-node.cpp
      accounts-model-item.cpp
+     filterbar.cpp
      main.cpp
      main-widget.cpp
 )
diff --git a/accountfiltermodel.cpp b/accountfiltermodel.cpp
index 4334c49..9429c0e 100644
--- a/accountfiltermodel.cpp
+++ b/accountfiltermodel.cpp
@@ -2,6 +2,7 @@
  * 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
@@ -23,7 +24,8 @@
 
 AccountFilterModel::AccountFilterModel(QObject *parent)
     : QSortFilterProxyModel(parent),
-      m_filterOfflineUsers(false)
+      m_filterOfflineUsers(false),
+      m_filterByName(false)
 {
 
 }
@@ -41,17 +43,42 @@ bool AccountFilterModel::filterOfflineUsers() const
 
 bool AccountFilterModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
 {
+    bool rowAccepted = true;
     //if we're looking at filtering an account or not
-    if (source_parent != QModelIndex()) {
-        if (m_filterOfflineUsers &&
+    if(source_parent != QModelIndex()) {
+        
+        //filter by name in the contact list
+        if(m_filterByName && 
+            !source_parent.child(source_row, 0).data(AccountsModel::AliasRole).toString()
+                .contains(m_filterString, Qt::CaseInsensitive)) {
+            
+            rowAccepted = false;
+        }
+        
+        //filter offline users out
+        if( m_filterOfflineUsers &&
             (source_parent.child(source_row, 0).data(AccountsModel::PresenceTypeRole).toUInt()
-                == Tp::ConnectionPresenceTypeOffline) ||
+            == Tp::ConnectionPresenceTypeOffline) ||
             (source_parent.child(source_row, 0).data(AccountsModel::PresenceTypeRole).toUInt()
-                == Tp::ConnectionPresenceTypeUnknown)) {
+            == Tp::ConnectionPresenceTypeUnknown)) {
             
-                return false;
+                rowAccepted = false;
         }
     }
 
-    return true;
+    return rowAccepted;
+}
+
+void AccountFilterModel::setFilterString (const QString& str)
+{
+    m_filterString = str;
+    m_filterByName = true;
+    invalidateFilter();
+}
+
+void AccountFilterModel::clearFilterString()
+{
+    m_filterString.clear();
+    m_filterByName = false;
+    invalidateFilter();
 }
diff --git a/accountfiltermodel.h b/accountfiltermodel.h
index 8810b02..a360710 100644
--- a/accountfiltermodel.h
+++ b/accountfiltermodel.h
@@ -34,12 +34,21 @@ public:
     
 public slots:
     void filterOfflineUsers(bool filterOfflineUsers);
-
+    void setFilterString(const QString &str);
+    void clearFilterString();
+    
 protected:
     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
 
 private:
+    /// Filters out offline users
     bool m_filterOfflineUsers;
+    
+    /// Used when searching for contact
+    bool m_filterByName;
+    
+    /// Holds the string which is searched in the model
+    QString m_filterString;
 };
 
 #endif // ACCOUNTFILTERMODEL_H
diff --git a/filterbar.cpp b/filterbar.cpp
new file mode 100644
index 0000000..3f4b7c2
--- /dev/null
+++ b/filterbar.cpp
@@ -0,0 +1,96 @@
+/***************************************************************************
+ *   Copyright (C) 2006-2010 by Peter Penz <peter.penz19 at gmail.com>        *
+ *   Copyright (C) 2006 by Gregor Kališnik <gregor at podnapisi.net>          *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+#include "filterbar.h"
+
+#include <QBoxLayout>
+#include <QKeyEvent>
+#include <QLabel>
+#include <QToolButton>
+
+#include <KIcon>
+#include <KLocale>
+#include <KLineEdit>
+#include <KIconLoader>
+
+FilterBar::FilterBar(QWidget* parent) :
+    QWidget(parent)
+{
+    // Create close button
+    QToolButton *closeButton = new QToolButton(this);
+    closeButton->setAutoRaise(true);
+    closeButton->setIcon(KIcon("dialog-close"));
+    closeButton->setToolTip(i18nc("@info:tooltip", "Hide Filter Bar"));
+    connect(closeButton, SIGNAL(clicked()), this, SIGNAL(closeRequest()));
+
+    // Create label
+    QLabel* filterLabel = new QLabel(i18nc("@label:textbox", "Filter:"), this);
+
+    // Create filter editor
+    m_filterInput = new KLineEdit(this);
+    m_filterInput->setLayoutDirection(Qt::LeftToRight);
+    m_filterInput->setClearButtonShown(true);
+    connect(m_filterInput, SIGNAL(textChanged(const QString&)),
+            this, SIGNAL(filterChanged(const QString&)));
+    setFocusProxy(m_filterInput);
+
+    // Apply layout
+    QHBoxLayout* hLayout = new QHBoxLayout(this);
+    hLayout->setMargin(0);
+    hLayout->addWidget(closeButton);
+    hLayout->addWidget(filterLabel);
+    hLayout->addWidget(m_filterInput);
+
+    filterLabel->setBuddy(m_filterInput);
+}
+
+FilterBar::~FilterBar()
+{
+}
+
+void FilterBar::selectAll()
+{
+    m_filterInput->selectAll();
+}
+
+void FilterBar::clear()
+{
+    m_filterInput->clear();
+}
+
+void FilterBar::showEvent(QShowEvent* event)
+{
+    if (!event->spontaneous()) {
+        m_filterInput->setFocus();
+    }
+}
+
+void FilterBar::keyReleaseEvent(QKeyEvent* event)
+{
+    QWidget::keyReleaseEvent(event);
+    if (event->key() == Qt::Key_Escape) {
+        if (m_filterInput->text().isEmpty()) {
+            emit closeRequest();
+        } else {
+            m_filterInput->clear();
+        }
+    }
+}
+
+#include "filterbar.moc"
diff --git a/filterbar.h b/filterbar.h
new file mode 100644
index 0000000..9546c63
--- /dev/null
+++ b/filterbar.h
@@ -0,0 +1,70 @@
+/***************************************************************************
+ *   Copyright (C) 2006-2010 by Peter Penz <peter.penz19 at gmail.com>        *
+ *   Copyright (C) 2006 by Gregor Kališnik <gregor at podnapisi.net>          *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program 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 General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef FILTERBAR_H
+#define FILTERBAR_H
+
+#include <QWidget>
+
+class KLineEdit;
+
+/**
+ * @brief Provides an input field for filtering the currently shown items.
+ *
+ * @author Gregor Kališnik <gregor at podnapisi.net>
+ */
+class FilterBar : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit FilterBar(QWidget* parent = 0);
+    virtual ~FilterBar();
+
+    /**
+     * Selects the whole text of the filter bar.
+     */
+    void selectAll();
+
+public slots:
+    /** Clears the input field. */
+    void clear();
+
+signals:
+    /**
+     * Signal that reports the name filter has been
+     * changed to  nameFilter.
+     */
+    void filterChanged(const QString& nameFilter);
+
+    /**
+     * Emitted as soon as the filterbar should get closed.
+     */
+    void closeRequest();
+
+protected:
+    virtual void showEvent(QShowEvent* event);
+    virtual void keyReleaseEvent(QKeyEvent* event);
+
+private:
+    KLineEdit* m_filterInput;
+};
+
+#endif
diff --git a/main-widget.cpp b/main-widget.cpp
index aeab343..ee25f1c 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -55,7 +55,9 @@ MainWidget::MainWidget(QWidget *parent)
     Tp::registerTypes();
 
     setupUi(this);
+    m_filterBar->hide();
     setWindowIcon(KIcon("telepathy"));
+    
     m_actionAdd_contact->setIcon(KIcon("list-add-user"));
     m_actionAdd_contact->setText(QString());
     m_actionAdd_contact->setToolTip(i18n("Add new contacts.."));
@@ -69,6 +71,10 @@ MainWidget::MainWidget(QWidget *parent)
     m_actionHide_offline->setText(QString());
     m_actionHide_offline->setToolTip(i18n("Show/Hide offline users"));
     
+    m_actionSearch_contact->setIcon(KIcon("edit-find-user"));
+    m_actionSearch_contact->setText(QString());
+    m_actionSearch_contact->setToolTip(i18n("Find contact"));
+    
     // Start setting up the Telepathy AccountManager.
     Tp::AccountFactoryPtr  accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
                                                                        Tp::Features() << Tp::Account::FeatureCore
@@ -98,12 +104,6 @@ MainWidget::MainWidget(QWidget *parent)
     connect(m_accountManager.data(), SIGNAL(newAccount(Tp::AccountPtr)),
             this, SLOT(onNewAccountAdded(Tp::AccountPtr)));
     
-    // Initialize Telepathy
-    //TelepathyBridge::instance()->init();
-    //connect(TelepathyBridge::instance(),
-    //        SIGNAL(ready(bool)),
-    //        SLOT(onHandlerReady(bool)));
-    
     m_delegate = new ContactDelegate(this);
     
     m_contactsListView->header()->hide();
@@ -117,7 +117,6 @@ MainWidget::MainWidget(QWidget *parent)
     
     addOverlayButtons();
     
-    
     connect(m_contactsListView, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(onCustomContextMenuRequested(QPoint)));
     
@@ -132,6 +131,9 @@ MainWidget::MainWidget(QWidget *parent)
     
     connect(m_actionGroup_contacts, SIGNAL(triggered(bool)),
             this, SLOT(onGroupContacts(bool)));
+    
+    connect(m_actionSearch_contact, SIGNAL(triggered(bool)),
+            this, SLOT(toggleSearchWidget(bool)));
 }
 
 MainWidget::~MainWidget()
@@ -151,6 +153,7 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
     m_modelFilter->setSourceModel(m_model);
     m_modelFilter->setDynamicSortFilter(true);
     m_modelFilter->filterOfflineUsers(true);
+    m_modelFilter->clearFilterString();
     m_modelFilter->setSortRole(Qt::DisplayRole);
     m_contactsListView->setModel(m_modelFilter);
     m_contactsListView->setSortingEnabled(true);
@@ -158,6 +161,18 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
 
     connect(m_actionHide_offline, SIGNAL(toggled(bool)),
             m_modelFilter, SLOT(filterOfflineUsers(bool)));
+
+    connect(m_filterBar, SIGNAL(filterChanged(QString)),
+            m_modelFilter, SLOT(setFilterString(QString)));
+    
+    connect(m_filterBar, SIGNAL(closeRequest()),
+            m_modelFilter, SLOT(clearFilterString()));
+    
+    connect(m_filterBar, SIGNAL(closeRequest()),
+            m_filterBar, SLOT(hide()));
+    
+    connect(m_filterBar, SIGNAL(closeRequest()),
+            m_actionSearch_contact, SLOT(toggle()));
     
     m_accountButtonsLayout->insertStretch(-1);
     
@@ -169,14 +184,6 @@ void MainWidget::onAccountManagerReady(Tp::PendingOperation* op)
     m_contactsListView->expandAll();
 }
 
-void MainWidget::systemMessageTest()
-{
-    if(sender()->objectName() == "infoBt")
-        showMessageToUser("Info message...", MainWidget::SystemMessageInfo);
-    else showMessageToUser("Error message...", MainWidget::SystemMessageError);
-    
-}
-
 void MainWidget::onAccountReady(Tp::PendingOperation* op)
 {
     if (op->isError()) {
@@ -402,6 +409,16 @@ void MainWidget::addOverlayButtons()
                 this, SLOT(startTextChannel(QModelIndex)));
 }
 
+void MainWidget::toggleSearchWidget(bool show)
+{
+    if(show) {
+        m_filterBar->show();
+    }
+    else {
+        m_filterBar->hide();
+    }
+}
+
 void MainWidget::onCustomContextMenuRequested(const QPoint& point)
 {
     Q_UNUSED(point);
diff --git a/main-widget.h b/main-widget.h
index d248c6e..ffaba43 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -35,6 +35,7 @@ class KSelectAction;
 class AccountsModel;
 class AccountFilterModel;
 class ContactDelegate;
+class FilterBar;
 
 class MainWidget : public QWidget, Ui::MainWidget
 {
@@ -70,11 +71,11 @@ public Q_SLOTS:
     void onAccountReady(Tp::PendingOperation *op);
     void onAccountConnectionStatusChanged(Tp::ConnectionStatus status);
     void showMessageToUser(const QString &text, const SystemMessageType type);
-    void systemMessageTest();
     void addOverlayButtons();
     void onNewAccountAdded(const Tp::AccountPtr &account);
     void onAccountStateChanged(bool enabled); 
     void onAccountRemoved();
+    void toggleSearchWidget(bool show);
     //    void startAudioChannel();
     //    void startVideoChannel();
     
@@ -87,6 +88,7 @@ private:
     KMenu*                  m_accountMenu;
     KSelectAction*          m_setStatusAction;
     ContactDelegate*        m_delegate;
+//     FilterBar*              m_filterBar;
 };
 
 
diff --git a/main-widget.ui b/main-widget.ui
index bfcb0ad..9fcad66 100644
--- a/main-widget.ui
+++ b/main-widget.ui
@@ -25,12 +25,16 @@
      <addaction name="m_actionAdd_contact"/>
      <addaction name="m_actionGroup_contacts"/>
      <addaction name="m_actionHide_offline"/>
+     <addaction name="m_actionSearch_contact"/>
     </widget>
    </item>
    <item>
     <widget class="QTreeView" name="m_contactsListView"/>
    </item>
    <item>
+    <widget class="FilterBar" name="m_filterBar" native="true"/>
+   </item>
+   <item>
     <layout class="QHBoxLayout" name="m_accountButtonsLayout"/>
    </item>
   </layout>
@@ -61,7 +65,29 @@
     <string>Hide offline</string>
    </property>
   </action>
+  <action name="m_actionSearch_contact">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="checked">
+    <bool>false</bool>
+   </property>
+   <property name="text">
+    <string>Search contacts</string>
+   </property>
+   <property name="shortcut">
+    <string>Ctrl+I</string>
+   </property>
+  </action>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>FilterBar</class>
+   <extends>QWidget</extends>
+   <header>filterbar.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list