Commit 487367f7 authored by Dan Pascu's avatar Dan Pascu

Added search capabilities to the contact list

parent 26f8e83a
......@@ -20,7 +20,7 @@ import sys
_qt_application = QApplication(sys.argv)
from blink import ui
from blink.contacts import ContactDelegate, ContactModel
from blink.contacts import ContactDelegate, ContactModel, ContactSearchModel
from blink.resources import Resources
......@@ -38,6 +38,11 @@ class Blink(object):
self.main_window.contact_list.setItemDelegate(ContactDelegate(self.main_window.contact_list))
self.contact_model.test()
self.contact_search_model = ContactSearchModel(self.contact_model, self.main_window)
self.main_window.search_list.setModel(self.contact_search_model)
self.main_window.search_list.setItemDelegate(ContactDelegate(self.main_window.search_list))
self.main_window.search_box.textChanged.connect(self.contact_search_model.setFilterFixedString)
self.main_window.main_view.setCurrentWidget(self.main_window.contacts_panel)
self.main_window.contacts_view.setCurrentWidget(self.main_window.contact_list_panel)
self.main_window.search_view.setCurrentWidget(self.main_window.search_list_panel)
......@@ -85,7 +90,7 @@ class Blink(object):
def text_changed(self, text):
active_widget = self.main_window.contact_list_panel if text.isEmpty() else self.main_window.search_panel
self.main_window.contacts_view.setCurrentWidget(active_widget)
active_widget = self.main_window.search_list_panel if len(text)<3 else self.main_window.not_found_panel
active_widget = self.main_window.search_list_panel if self.contact_search_model.rowCount() else self.main_window.not_found_panel
self.main_window.search_view.setCurrentWidget(active_widget)
def test_add_contact(self):
......
......@@ -2,7 +2,7 @@
#
from PyQt4.QtCore import Qt, QAbstractListModel, QModelIndex, QSize
from PyQt4.QtGui import QColor, QPainter, QPalette, QPixmap, QStyle, QStyledItemDelegate
from PyQt4.QtGui import QColor, QPainter, QPalette, QPixmap, QStyle, QSortFilterProxyModel, QStyledItemDelegate
from application.python.util import Null
from functools import partial
......@@ -251,3 +251,27 @@ class ContactModel(QAbstractListModel):
self.addGroup(test_group)
class ContactSearchModel(QSortFilterProxyModel):
def __init__(self, model, parent=None):
super(ContactSearchModel, self).__init__(parent)
self.setSourceModel(model)
self.setDynamicSortFilter(True)
def data(self, index, role=Qt.DisplayRole):
data = super(ContactSearchModel, self).data(index, role)
return data.toPyObject() if role==Qt.DisplayRole else data
def filterAcceptsRow(self, source_row, source_parent):
source_model = self.sourceModel()
source_index = source_model.index(source_row, 0, source_parent)
item = source_model.data(source_index, Qt.DisplayRole)
if type(item) is ContactGroup:
return False
search_string = unicode(self.filterRegExp().pattern())
return search_string in item.name.lower() or search_string in item.uri.lower()
def lessThan(self, left, right):
print "lessThan", left, right, left.model().data(left, Qt.DisplayRole)
return super(ContactSearchModel, self).lessThan(left, right)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment