summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Side-by-side diff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp75
-rw-r--r--kaddressbook/kaddressbookview.h1
-rw-r--r--kaddressbook/viewmanager.cpp5
-rw-r--r--kaddressbook/viewmanager.h1
-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
10 files changed, 159 insertions, 76 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 1a1bcff..2a2f904 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -848,82 +848,9 @@ void KABCore::setSearchFields( const KABC::Field::List &fields )
}
void KABCore::incrementalSearch( const QString& text )
{
- mViewManager->setSelected( QString::null, false );
-
- if ( !text.isEmpty() ) {
- KABC::Field *field = mIncSearchWidget->currentField();
- QString pattern = text.lower()+"*";
- QRegExp re;
- re.setWildcard(true); // most people understand these better.
- re.setCaseSensitive(false);
- re.setPattern( pattern );
- QStringList foundUids;
- if (!re.isValid())
- return;
-#if 1 //KDE_VERSION >= 319
- KABC::AddresseeList list( mAddressBook->allAddressees() );
- if ( field ) {
- list.sortByField( field );
- KABC::AddresseeList::Iterator it;
- for ( it = list.begin(); it != list.end(); ++it ) {
-
-#if QT_VERSION >= 300
- if (re.search(field->value( *it ).lower()) != -1)
-#else
- if (re.match(field->value( *it ).lower()) != -1)
-#endif
- {
- // if ( field->value( *it ).lower().startsWith( pattern ) ) {
- //mViewManager->setSelected( (*it).uid(), true );
- foundUids.append( (*it).uid() );
- //return;
- }
- }
- } else {
- KABC::AddresseeList::Iterator it;
- for ( it = list.begin(); it != list.end(); ++it ) {
- KABC::Field::List fieldList = mIncSearchWidget->fields();
- KABC::Field::List::ConstIterator fieldIt;
- 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
- {
- // if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
- //mViewManager->setSelected( (*it).uid(), true );
- foundUids.append( (*it).uid() );
- //return;
- }
- }
- }
- }
- if ( foundUids.count() > 0 )
- mViewManager->setListSelected( foundUids );
-#else
- KABC::AddressBook::Iterator it;
- for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
- if ( field ) {
- if ( field->value( *it ).lower().startsWith( pattern ) ) {
- mViewManager->setSelected( (*it).uid(), true );
- return;
- }
- } else {
- KABC::Field::List fieldList = mIncSearchWidget->fields();
- KABC::Field::List::ConstIterator fieldIt;
- for ( fieldIt = fieldList.begin(); fieldIt != fieldList.end(); ++fieldIt ) {
- if ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) {
- mViewManager->setSelected( (*it).uid(), true );
- return;
- }
- }
- }
- }
-#endif
- }
+ mViewManager->doSearch( text, mIncSearchWidget->currentField() );
}
void KABCore::setModified()
{
diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h
index 7457080..17106e8 100644
--- a/kaddressbook/kaddressbookview.h
+++ b/kaddressbook/kaddressbookview.h
@@ -63,8 +63,9 @@ class KAddressBookView : public QWidget
Must be overloaded in subclasses. Should return a list of
all the uids of selected contacts.
*/
virtual QStringList selectedUids() = 0;
+ virtual void doSearch( const QString& s ,KABC::Field *field ) = 0;
/**
Called whenever this view should read the config. This can be used
as a sign that the config has changed, therefore the view should
diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp
index c93d51a..c6baeac 100644
--- a/kaddressbook/viewmanager.cpp
+++ b/kaddressbook/viewmanager.cpp
@@ -545,9 +545,14 @@ void ViewManager::startDrag()
qDebug("ViewManager::startDrag() has to be changed!!" );
#endif //KAB_EMBEDDED
}
+void ViewManager::doSearch( const QString& s,KABC::Field *field )
+{
+ if ( mActiveView )
+ mActiveView->doSearch( s, field );
+}
void ViewManager::setActiveFilter( int index )
{
Filter currentFilter;
diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h
index 97c2275..6def6b6 100644
--- a/kaddressbook/viewmanager.h
+++ b/kaddressbook/viewmanager.h
@@ -54,8 +54,9 @@ class ViewManager : public QWidget
~ViewManager();
void restoreSettings();
void saveSettings();
+ void doSearch( const QString& s ,KABC::Field *field );
void unloadViews();
KSelectAction * getFilterAction() { return mActionSelectFilter; }
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
@@ -114,8 +114,9 @@ AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name)
AddresseeCardView::~AddresseeCardView()
{
}
+
void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e)
{
#ifndef KAB_EMBEDDED
if (QTextDrag::canDecode(e))
@@ -239,9 +240,59 @@ 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;
CardViewItem *item;
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
@@ -53,9 +53,9 @@ class KAddressBookCardView : public KAddressBookView
public:
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"; }
virtual void readConfig(KConfig *config);
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
@@ -95,8 +95,9 @@ AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name)
AddresseeIconView::~AddresseeIconView()
{
}
+
void AddresseeIconView::itemDropped(QDropEvent *e,
const QValueList<QIconDragItem> &)
{
emit addresseeDropped(e);
@@ -231,9 +232,55 @@ void KAddressBookIconView::readConfig(KConfig *config)
connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)),
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;
QIconViewItem *item;
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
@@ -57,8 +57,9 @@ class KAddressBookIconView : public KAddressBookView
virtual ~KAddressBookIconView();
virtual QStringList selectedUids();
virtual QString type() const { return "Icon"; }
+ void doSearch( const QString& s ,KABC::Field *field );
virtual void readConfig(KConfig *config);
public slots:
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
@@ -111,8 +111,57 @@ void KAddressBookTableView::reconstructListView()
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);
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
@@ -61,8 +61,9 @@ friend class ContactListView;
virtual void setSelected(QString uid = QString::null, bool selected = false);
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();