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 | |
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 @@ -828,122 +828,49 @@ void KABCore::setCategories() QStringList addrCategories = addr.categories(); QStringList::Iterator catIt; for ( catIt = categories.begin(); catIt != categories.end(); ++catIt ) { if ( !addrCategories.contains( *catIt ) ) addrCategories.append( *catIt ); } addr.setCategories( addrCategories ); } mAddressBook->insertAddressee( addr ); } } if ( uids.count() > 0 ) setModified( true ); } 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() { // qDebug("KABCore::setModifiedWOrefresh() "); mModified = true; mActionSave->setEnabled( mModified ); #ifdef DESKTOP_VERSION mDetails->refreshView(); #endif } void KABCore::setModified( bool modified ) { mModified = modified; mActionSave->setEnabled( mModified ); if ( modified ) mJumpButtonBar->recreateButtons(); diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h index 7457080..17106e8 100644 --- a/kaddressbook/kaddressbookview.h +++ b/kaddressbook/kaddressbookview.h @@ -43,48 +43,49 @@ namespace KABC { class AddressBook; } /** Base class for all views in kaddressbook. This class implements all the common methods needed to provide a view to the user. To implement a specific view (table, card, etc), just inherit from this class and implement all the pure virtuals. @author Mike Pilone <mpilone@slac.com> */ class KAddressBookView : public QWidget { Q_OBJECT public: enum DefaultFilterType { None = 0, Active = 1, Specific = 2 }; 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. If overloaded in the subclass, do not forget to call super class's method. @param config The KConfig object to read from. The group will already be set, so do not change the group. */ virtual void readConfig( KConfig *config ); /** Called whenever this view should write the config. The view should not write out information handled by the application, such as which fields are visible. The view should only write out information specific to itself (i.e.: All information in the ViewConfigWidget) If overloaded in the subclass, do not forget to call the super class's method. diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index c93d51a..c6baeac 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -525,49 +525,54 @@ void ViewManager::startDrag() QStringList::Iterator iter; for ( iter = uidList.begin(); iter != uidList.end(); ++iter ) addrList.append( mCore->addressBook()->findByUid( *iter ) ); KMultipleDrag *drag = new KMultipleDrag( this ); drag->addDragObject( new QTextDrag( AddresseeUtil::addresseesToClipboard(addrList), this ) ); KABC::Addressee::List::Iterator it; QStringList vcards; for ( it = addrList.begin(); it != addrList.end(); ++it ) { QString vcard = QString::null; KABC::VCardConverter converter; if ( converter.addresseeToVCard( *it, vcard ) ) vcards.append( vcard ); } drag->addDragObject( new KVCardDrag( vcards.join( "\r\n" ), this ) ); 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 ]; // Check if we have a view. Since the filter combo is created before // the view, this slot could be called before there is a valid view. if ( mActiveView ) { mActiveView->setFilter( currentFilter ); mActiveView->refresh(); emit selected( QString::null ); } } void ViewManager::configureFilters() { FilterDialog dlg( this ); dlg.setFilters( mFilterList ); diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index 97c2275..6def6b6 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h @@ -34,48 +34,49 @@ class KSelectAction; class KABCore; class QWidgetStack; class QDropEvent; namespace KABC { class AddressBook; } /** The view manager manages the views and everything related to them. The manager will load the views at startup and display a view when told to make one active. The view manager will also create and manage all dialogs directly related to views (ie: AddView, ConfigureView, DeleteView, etc). */ 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); public slots: //US void setSelected( const QString &uid = QString::null, bool selected = true ); void setSelected( const QString &uid, bool); //US added another method with no parameter, since my moc compiler does not support default parameters. void setSelected(); //US added another method with no parameter, since my moc compiler does not support default parameters. void refreshView(); void refreshView( const QString &uid); void editView(); void deleteView(); 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 @@ -94,48 +94,49 @@ class AddresseeCardViewItem : public CardViewItem setCaption( mAddressee.realName() ); } } private: KABC::Field::List mFields; bool mShowEmptyFields; KABC::AddressBook *mDocument; KABC::Addressee mAddressee; }; /////////////////////////////// // AddresseeCardView AddresseeCardView::AddresseeCardView(QWidget *parent, const char *name) : CardView(parent, 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 } void AddresseeCardView::dropEvent(QDropEvent *e) { emit addresseeDropped(e); } void AddresseeCardView::startDrag() { emit startAddresseeDrag(); } /////////////////////////////// // KAddressBookCardView @@ -219,49 +220,99 @@ void KAddressBookCardView::readConfig(KConfig *config) mCardView->setShowEmptyFields( mShowEmptyFields ); mCardView->setItemWidth( config->readNumEntry( "ItemWidth", 200 ) ); mCardView->setItemMargin( config->readNumEntry( "ItemMargin", 0 ) ); mCardView->setItemSpacing( config->readNumEntry( "ItemSpacing", 10 ) ); mCardView->setSeparatorWidth( config->readNumEntry( "SeparatorWidth", 2 ) ); disconnect(mCardView, SIGNAL(executed(CardViewItem *)), this, SLOT(addresseeExecuted(CardViewItem *))); if (KABPrefs::instance()->mHonorSingleClick) connect(mCardView, SIGNAL(executed(CardViewItem *)), this, SLOT(addresseeExecuted(CardViewItem *))); else connect(mCardView, SIGNAL(doubleClicked(CardViewItem *)), this, SLOT(addresseeExecuted(CardViewItem *))); } 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()) { if (item->isSelected()) { #ifndef KAB_EMBEDDED aItem = dynamic_cast<AddresseeCardViewItem*>(item); #else //KAB_EMBEDDED aItem = (AddresseeCardViewItem*)(item); #endif //KAB_EMBEDDED if (aItem) uidList << aItem->addressee().uid(); } } return uidList; } void KAddressBookCardView::refresh(QString uid) 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 @@ -33,49 +33,49 @@ #include "cardview.h" #include "kaddressbookview.h" #include "configurecardviewdialog.h" class QDragEnterEvent; class QDragEntryEvent; class QDropEvent; class KConfig; class AddresseeCardView; /** This view uses the CardView class to create a card view. At some point in the future I think this will be the default view of KAddressBook. */ 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); void setSelected(QString uid/*US = QString::null*/, bool selected/*US = true*/); //US added an additional method without parameter void setSelected(); protected slots: void addresseeExecuted(CardViewItem *item); void addresseeSelected(); private: AddresseeCardView *mCardView; bool mShowEmptyFields; }; class AddresseeCardView : public CardView { Q_OBJECT 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 @@ -75,48 +75,49 @@ AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) #endif //KAB_EMBEDDED { setSelectionMode( QIconView::Extended ); setResizeMode( QIconView::Adjust ); setWordWrapIconText( true ); setGridX( 100 ); setItemsMovable(false); setSorting(true, true); //US ??? setMode( KIconView::Select ); #ifndef KAB_EMBEDDED connect(this, SIGNAL(dropped(QDropEvent*, const QValueList<QIconDragItem>&)), 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() { emit startAddresseeDrag(); // We never want IconView to start the drag return 0; } //////////////////////////////// // AddresseeIconViewItem (internal class) #ifndef KAB_EMBEDDED class AddresseeIconViewItem : public KIconViewItem #else //KAB_EMBEDDED class AddresseeIconViewItem : public QIconViewItem #endif //KAB_EMBEDDED { public: #ifndef KAB_EMBEDDED AddresseeIconViewItem(const KABC::Field::List &fields, @@ -211,49 +212,95 @@ KAddressBookIconView::~KAddressBookIconView() void KAddressBookIconView::readConfig(KConfig *config) { KAddressBookView::readConfig(config); //US method executed is part of KIconView //US disconnect(mIconView, SIGNAL(executed(QIconViewItem *)), //US this, SLOT(addresseeExecuted(QIconViewItem *))); disconnect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), this, SLOT(addresseeExecuted(QIconViewItem *))); //US method executed is part of KIconView. Use selectionChanged instead /*US if (KABPrefs::instance()->mHonorSingleClick) connect(mIconView, SIGNAL(executed(QIconViewItem *)), this, SLOT(addresseeExecuted(QIconViewItem *))); 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()) { if (item->isSelected()) { #ifndef KAB_EMBEDDED aItem = dynamic_cast<AddresseeIconViewItem*>(item); #else //KAB_EMBEDDED aItem = (AddresseeIconViewItem*)(item); #endif //KAB_EMBEDDED if (aItem) uidList << aItem->addressee().uid(); } } return uidList; } void KAddressBookIconView::refresh(QString uid) 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 @@ -37,48 +37,49 @@ class QIconViewItem; class KConfig; class AddresseeIconView; class AddresseeIconViewItem; class QIconDragItem; class KAddressBookIconView; namespace KABC { class AddressBook; } /** This is an example kaddressbook view that is implemented using * KIconView. This view is not the most useful view, but it displays * how simple implementing a new view can be. */ class KAddressBookIconView : public KAddressBookView { Q_OBJECT 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); //MOC_SKIP_END #else //KAB_EMBEDDED //US my MOC do not like default parameters ??? void setSelected(QString uid, bool selected); #endif //KAB_EMBEDDED protected slots: void addresseeExecuted(QIconViewItem *item); void addresseeSelected(); private: AddresseeIconView *mIconView; QPtrList<AddresseeIconViewItem> mIconList; }; 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 @@ -91,48 +91,97 @@ void KAddressBookTableView::reconstructListView() SIGNAL(startDrag())); connect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, SIGNAL(dropped(QDropEvent*))); if (KABPrefs::instance()->mHonorSingleClick) connect(mListView, SIGNAL(executed(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); else connect(mListView, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); connect(mListView, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); connect(mListView, SIGNAL(signalDelete()), this, SLOT(addresseeDeleted())); //US performceimprovement. Refresh is done from the outside //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) { KAddressBookView::readConfig( config ); // The config could have changed the fields, so we need to reconstruct // the listview. reconstructListView(); // costum colors? if ( config->readBoolEntry( "EnableCustomColors", false ) ) { QPalette p( mListView->palette() ); QColor c = p.color(QPalette::Normal, QColorGroup::Base ); p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Text ); p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Button ); p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); 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 @@ -41,48 +41,49 @@ namespace KABC { class AddressBook; } * This class is the table view for kaddressbook. This view is a KListView * with multiple columns for the selected fields. * * @short Table View * @author Don Sanders <dsanders@kde.org> * @version 0.1 */ class KAddressBookTableView : public KAddressBookView { friend class ContactListView; Q_OBJECT public: KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); 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(); void addresseeDeleted(); /** Called whenever the user executes an addressee. In terms of the * list view, this is probably a double click */ void addresseeExecuted(QListViewItem*); private: QVBoxLayout *mainLayout; ContactListView *mListView; }; class TableViewFactory : public ViewFactory { public: |