From 480ffef4859d24cc0a936377f8983fd59312d4b6 Mon Sep 17 00:00:00 2001 From: zautrix Date: Thu, 09 Sep 2004 20:39:55 +0000 Subject: Added senseful searching in Kapi --- (limited to 'kaddressbook/views/kaddressbooktableview.cpp') diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index ab11e2a..12f7c27 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp @@ -112,6 +112,55 @@ void KAddressBookTableView::reconstructListView() mListView->show(); } +void KAddressBookTableView::doSearch( const QString& s, KABC::Field *field ) +{ + mListView->clear(); + if ( s.isEmpty() || s == "*" ) { + refresh(); + return; + } + QString pattern = s.lower()+"*"; + QRegExp re; + re.setWildcard(true); // most people understand these better. + re.setCaseSensitive(false); + re.setPattern( pattern ); + if (!re.isValid()) + return; + KABC::Addressee::List addresseeList = addressees(); + KABC::Addressee::List::Iterator it; + if ( field ) { + for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { +#if QT_VERSION >= 300 + if (re.search(field->value( *it ).lower()) != -1) +#else + if (re.match(field->value( *it ).lower()) != -1) +#endif + ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); + + } + } else { + KABC::Field::List fieldList = fields(); + KABC::Field::List::ConstIterator fieldIt; + for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { + for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) { +#if QT_VERSION >= 300 + if (re.search((*fieldIt)->value( *it ).lower()) != -1) +#else + if (re.match((*fieldIt)->value( *it ).lower()) != -1) +#endif + { + ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); + continue; + } + } + } + } + // Sometimes the background pixmap gets messed up when we add lots + // of items. + mListView->repaint(); + emit selected(QString::null); + +} void KAddressBookTableView::writeConfig(KConfig *config) { KAddressBookView::writeConfig(config); -- cgit v0.9.0.2