author | zautrix <zautrix> | 2004-09-09 20:39:55 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-09 20:39:55 (UTC) |
commit | 480ffef4859d24cc0a936377f8983fd59312d4b6 (patch) (side-by-side diff) | |
tree | 9661e8b5e892ef653ffc2ed630dbe89acfeb4851 /kaddressbook | |
parent | 880518b6f1d4b06e3df45224c244d9c62f6fb7a9 (diff) | |
download | kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.zip kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.gz kdepimpi-480ffef4859d24cc0a936377f8983fd59312d4b6.tar.bz2 |
Added senseful searching in Kapi
-rw-r--r-- | kaddressbook/kabcore.cpp | 75 | ||||
-rw-r--r-- | kaddressbook/kaddressbookview.h | 1 | ||||
-rw-r--r-- | kaddressbook/viewmanager.cpp | 5 | ||||
-rw-r--r-- | kaddressbook/viewmanager.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 51 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.h | 2 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.cpp | 47 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 49 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.h | 1 |
10 files changed, 158 insertions, 75 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 1a1bcff..2a2f904 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -844,90 +844,17 @@ void KABCore::setCategories() void KABCore::setSearchFields( const KABC::Field::List &fields ) { mIncSearchWidget->setFields( 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() { setModified( true ); } void KABCore::setModifiedWOrefresh() diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h index 7457080..17106e8 100644 --- a/kaddressbook/kaddressbookview.h +++ b/kaddressbook/kaddressbookview.h @@ -59,16 +59,17 @@ class KAddressBookView : public QWidget KAddressBookView( KABC::AddressBook *ab, QWidget *parent, const char *name ); virtual ~KAddressBookView(); /** 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 assume the worst and rebuild itself if necessary. For example, in a table view this method may be called when the user adds or removes columns from the view. diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index c93d51a..c6baeac 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -541,17 +541,22 @@ void ViewManager::startDrag() drag->setPixmap( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop ) ); drag->dragCopy(); #else //KAB_EMBEDDED 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; if ( ( index - 1 ) < 0 ) currentFilter = Filter(); else currentFilter = mFilterList[ index - 1 ]; diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index 97c2275..6def6b6 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h @@ -50,16 +50,17 @@ class ViewManager : public QWidget { Q_OBJECT public: ViewManager( KABCore *core, QWidget *parent, const char *name = 0 ); ~ViewManager(); void restoreSettings(); void saveSettings(); + void doSearch( const QString& s ,KABC::Field *field ); void unloadViews(); KSelectAction * getFilterAction() { return mActionSelectFilter; } QStringList selectedUids() const; QStringList selectedEmails() const; KABC::Addressee::List selectedAddressees() const; void setListSelected(QStringList); 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 @@ -110,16 +110,17 @@ AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) { setAcceptDrops(true); } AddresseeCardView::~AddresseeCardView() { } + void AddresseeCardView::dragEnterEvent(QDragEnterEvent *e) { #ifndef KAB_EMBEDDED if (QTextDrag::canDecode(e)) e->accept(); #else //KAB_EMBEDDED qDebug("AddresseeCardView::dragEnterEvent drag&drop is not implemented"); #endif //KAB_EMBEDDED @@ -235,17 +236,67 @@ void KAddressBookCardView::readConfig(KConfig *config) } 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; AddresseeCardViewItem *aItem; for (item = mCardView->firstItem(); item; item = item->nextItem()) { 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 @@ -49,17 +49,17 @@ class AddresseeCardView; class KAddressBookCardView : public KAddressBookView { Q_OBJECT 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); virtual void writeConfig(KConfig *); public slots: void refresh(QString uid = QString::null); 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 @@ -91,16 +91,17 @@ AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) this, SLOT(itemDropped(QDropEvent*, const QValueList<QIconDragItem>&))); #endif //KAB_EMBEDDED } AddresseeIconView::~AddresseeIconView() { } + void AddresseeIconView::itemDropped(QDropEvent *e, const QValueList<QIconDragItem> &) { emit addresseeDropped(e); } QDragObject *AddresseeIconView::dragObject() { @@ -227,17 +228,63 @@ void KAddressBookIconView::readConfig(KConfig *config) else connect(mIconView, SIGNAL(doubleClicked(QIconViewItem *)), this, SLOT(addresseeExecuted(QIconViewItem *))); */ 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; AddresseeIconViewItem *aItem; for (item = mIconView->firstItem(); item; item = item->nextItem()) { 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 @@ -53,16 +53,17 @@ class KAddressBookIconView : public KAddressBookView public: KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 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: void refresh(QString uid = QString::null); #ifndef KAB_EMBEDDED //MOC_SKIP_BEGIN void setSelected(QString uid = QString::null, bool selected = true); 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 @@ -107,16 +107,65 @@ void KAddressBookTableView::reconstructListView() //US refresh(); 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()); } void KAddressBookTableView::readConfig(KConfig *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 @@ -57,16 +57,17 @@ friend class ContactListView; virtual ~KAddressBookTableView(); virtual void refresh(QString uid = QString::null); virtual QStringList selectedUids(); 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(); protected slots: /** Called whenever the user selects an addressee in the list view. */ void addresseeSelected(); |