summaryrefslogtreecommitdiffabout
path: root/kaddressbook/views
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
parent880518b6f1d4b06e3df45224c244d9c62f6fb7a9 (diff)
downloadkdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.zip
kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.gz
kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.bz2
Added senseful searching in Kapi
Diffstat (limited to 'kaddressbook/views') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/kaddressbookcardview.cpp53
-rw-r--r--kaddressbook/views/kaddressbookcardview.h2
-rw-r--r--kaddressbook/views/kaddressbookiconview.cpp47
-rw-r--r--kaddressbook/views/kaddressbookiconview.h1
-rw-r--r--kaddressbook/views/kaddressbooktableview.cpp49
-rw-r--r--kaddressbook/views/kaddressbooktableview.h1
6 files changed, 151 insertions, 2 deletions
diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp
index 239429f..49c0691 100644
--- a/kaddressbook/views/kaddressbookcardview.cpp
+++ b/kaddressbook/views/kaddressbookcardview.cpp
@@ -115,6 +115,7 @@ AddresseeCardView::~AddresseeCardView()
{
}
+
void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
{
#ifndef KAB_EMBEDDED
@@ -240,7 +241,57 @@ void KAddressBookCardView::writeConfig( KConfig *config )
config->writeEntry( "ItemWidth", mCardView->itemWidth() );
KAddressBookView::writeConfig( config );
}
-
+void KAddressBookCardView::doSearch( const QString& s,KABC::Field *field )
+{
+ mCardView->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;
+ mCardView->viewport()->setUpdatesEnabled( false );
+ 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
+ new AddresseeCardViewItem(fields(), mShowEmptyFields,
+ addressBook(), *it, mCardView);
+
+ }
+ } 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
+ {
+ new AddresseeCardViewItem(fields(), mShowEmptyFields,
+ addressBook(), *it, mCardView);
+ continue;
+ }
+ }
+ }
+ }
+ mCardView->viewport()->setUpdatesEnabled( true );
+ mCardView->viewport()->update();
+ // by default nothing is selected
+ emit selected(QString::null);
+}
QStringList KAddressBookCardView::selectedUids()
{
QStringList uidList;
diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h
index cd70371..b8efb01 100644
--- a/kaddressbook/views/kaddressbookcardview.h
+++ b/kaddressbook/views/kaddressbookcardview.h
@@ -54,7 +54,7 @@ class KAddressBookCardView : public KAddressBookView
KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent,
const char *name = 0 );
virtual ~KAddressBookCardView();
-
+ void doSearch( const QString& s,KABC::Field *field );
virtual QStringList selectedUids();
virtual QString type() const { return "Card"; }
diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp
index 50ff285..78d63b0 100644
--- a/kaddressbook/views/kaddressbookiconview.cpp
+++ b/kaddressbook/views/kaddressbookiconview.cpp
@@ -96,6 +96,7 @@ AddresseeIconView::~AddresseeIconView()
{
}
+
void AddresseeIconView::itemDropped(QDropEvent *e,
const QValueList<QIconDragItem> &)
{
@@ -232,7 +233,53 @@ void KAddressBookIconView::readConfig(KConfig *config)
this, SLOT(addresseeExecuted(QIconViewItem *)));
}
+void KAddressBookIconView::doSearch( const QString& s ,KABC::Field *field )
+{
+ mIconView->clear();
+ mIconList.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
+ mIconList.append(new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
+
+ }
+ } 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
+ {
+ mIconList.append( new AddresseeIconViewItem( fields(), addressBook(), *it, mIconView ));
+ continue;
+ }
+ }
+ }
+ }
+ mIconView->arrangeItemsInGrid( true );
+}
QStringList KAddressBookIconView::selectedUids()
{
QStringList uidList;
diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h
index 3afada3..963ee7c 100644
--- a/kaddressbook/views/kaddressbookiconview.h
+++ b/kaddressbook/views/kaddressbookiconview.h
@@ -58,6 +58,7 @@ class KAddressBookIconView : public KAddressBookView
virtual QStringList selectedUids();
virtual QString type() const { return "Icon"; }
+ void doSearch( const QString& s ,KABC::Field *field );
virtual void readConfig(KConfig *config);
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);
diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h
index bb991bc..ecfe7a1 100644
--- a/kaddressbook/views/kaddressbooktableview.h
+++ b/kaddressbook/views/kaddressbooktableview.h
@@ -62,6 +62,7 @@ friend class ContactListView;
virtual void readConfig(KConfig *config);
virtual void writeConfig(KConfig *config);
virtual QString type() const { return "Table"; }
+ void doSearch( const QString& s ,KABC::Field *field );
public slots:
virtual void reconstructListView();