summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views/kaddressbooktableview.cpp
authorzautrix <zautrix>2004-09-09 20:39:55 (UTC)
committer zautrix <zautrix>2004-09-09 20:39:55 (UTC)
commit480ffef4859d24cc0a936377f8983fd59312d4b6 (patch) (side-by-side diff)
tree9661e8b5e892ef653ffc2ed630dbe89acfeb4851 /kaddressbook/views/kaddressbooktableview.cpp
parent880518b6f1d4b06e3df45224c244d9c62f6fb7a9 (diff)
downloadkdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.zip
kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.gz
kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.bz2
Added senseful searching in Kapi
Diffstat (limited to 'kaddressbook/views/kaddressbooktableview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp49
1 files changed, 49 insertions, 0 deletions
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
@@ -109,12 +109,61 @@ void KAddressBookTableView::reconstructListView()
mListView->setSorting( 0, true );
mainLayout->addWidget( mListView );
mainLayout->activate();
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);
mListView->saveLayout(config, config->group());
}