-rw-r--r-- | kaddressbook/incsearchwidget.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 42 | ||||
-rw-r--r-- | kaddressbook/viewmanager.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/viewmanager.h | 1 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 6 |
5 files changed, 48 insertions, 15 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index 94c37e7..2ffa357 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp @@ -46,54 +46,57 @@ IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) QLabel *label = new QLabel( i18n( "Search:" ), this ); label->setAlignment( QLabel::AlignVCenter | QLabel::AlignRight ); layout->addWidget( label ); #endif //KAB_EMBEDDED mSearchText = new KLineEdit( this ); layout->addWidget( mSearchText ); // #ifdef KAB_EMBEDDED // if (KGlobal::getOrientation() == KGlobal::Portrait) // mSearchText->setMaximumWidth(30); // #endif //KAB_EMBEDDED mFieldCombo = new QComboBox( false, this ); layout->addWidget( mFieldCombo ); mFieldCombo->setMaximumHeight( 34 ); QToolTip::add( mFieldCombo, i18n( "Select Incremental Search Field" ) ); // #ifndef KAB_EMBEDDED // resize( QSize(420, 50).expandedTo( sizeHint() ) ); // #else //KAB_EMBEDDED // resize( QSize(30, 10).expandedTo( sizeHint() ) ); // #endif //KAB_EMBEDDED +#ifdef DESKTOP_VERSION + // for performance reasons, we do a search on the pda only after return is pressed connect( mSearchText, SIGNAL( textChanged( const QString& ) ), SLOT( announceDoSearch() ) ); - connect( mSearchText, SIGNAL( returnPressed() ), - SLOT( announceDoSearch() ) ); connect( mFieldCombo, SIGNAL( activated( const QString& ) ), SLOT( announceDoSearch() ) ); +#endif + connect( mSearchText, SIGNAL( returnPressed() ), + SLOT( announceDoSearch() ) ); connect( mFieldCombo, SIGNAL( activated( const QString& ) ), SLOT( announceFieldChanged() ) ); setFocusProxy( mSearchText ); } IncSearchWidget::~IncSearchWidget() { } void IncSearchWidget::announceDoSearch() { emit doSearch( mSearchText->text() ); } void IncSearchWidget::announceFieldChanged() { emit fieldChanged(); } void IncSearchWidget::setFields( const KABC::Field::List &list ) { diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index f0f08f4..4299ebd 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -812,75 +812,97 @@ void KABCore::setCategories() 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(); - + 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 ( field->value( *it ).lower().startsWith( pattern ) ) { - mViewManager->setSelected( (*it).uid(), true ); - return; - } + +#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 ( (*fieldIt)->value( *it ).lower().startsWith( pattern ) ) { - mViewManager->setSelected( (*it).uid(), true ); - return; +#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 } } void KABCore::setModified() diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index 45c7b55..c93d51a 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -157,48 +157,55 @@ KABC::Addressee::List ViewManager::selectedAddressees() const if ( mActiveView ) { QStringList uids = mActiveView->selectedUids(); QStringList::Iterator it; for ( it = uids.begin(); it != uids.end(); ++it ) { KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); if ( !addr.isEmpty() ) list.append( addr ); } } return list; } //US added another method with no parameter, since my moc compiler does not support default parameters. void ViewManager::setSelected() { setSelected( QString::null, true ); } void ViewManager::setSelected( const QString &uid, bool selected ) { if ( mActiveView ) mActiveView->setSelected( uid, selected ); } +void ViewManager::setListSelected(QStringList list) +{ + int i, count = list.count(); + for ( i = 0; i < count;++i ) + setSelected( list[i], true ); + +} void ViewManager::unloadViews() { mViewDict.clear(); mActiveView = 0; } void ViewManager::setActiveView( const QString &name ) { KAddressBookView *view = 0; // Check that this isn't the same as the current active view if ( mActiveView && ( mActiveView->caption() == name ) ) return; // At this point we know the view that should be active is not // currently active. We will try to find the new on in the list. If // we can't find it, it means it hasn't been instantiated, so we will // create it on demand. view = mViewDict.find( name ); // Check if we found the view. If we didn't, then we need to create it if ( view == 0 ) { KConfig *config = mCore->config(); diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index a18e87d..97c2275 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h @@ -41,48 +41,49 @@ 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 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(); void addView(); protected slots: /** Called whenever the user drops something in the active view. This method will try to decode what was dropped, and if it was a valid addressee, add it to the addressbook. */ diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index 66a3f0b..0847b64 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp @@ -101,96 +101,96 @@ void KAddressBookTableView::reconstructListView() 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::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 ) ); c = p.color(QPalette::Normal, QColorGroup::ButtonText ); p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Highlight ); p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Base ); p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "AlternatingBackgroundColor", &c ) ); mListView->viewport()->setPalette( p ); } else { // needed if turned off during a session. mListView->viewport()->setPalette( mListView->palette() ); } //custom fonts? QFont f( font() ); if ( config->readBoolEntry( "EnableCustomFonts", false ) ) { // mListView->setFont( config->readFontEntry( "TextFont", &f) ); f.setBold( true ); // mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); } else { // mListView->setFont( f ); f.setBold( true ); // mListView->setHeaderFont( f ); } - // The config could have changed the fields, so we need to reconstruct - // the listview. - reconstructListView(); // Set the list view options mListView->setAlternateBackgroundEnabled(config->readBoolEntry("ABackground", true)); mListView->setSingleLineEnabled(config->readBoolEntry("SingleLine", false)); mListView->setToolTipsEnabled(config->readBoolEntry("ToolTips", true)); if (config->readBoolEntry("Background", false)) mListView->setBackgroundPixmap(config->readEntry("BackgroundName")); // Restore the layout of the listview mListView->restoreLayout(config, config->group()); } void KAddressBookTableView::refresh(QString uid) { // For now just repopulate. In reality this method should // check the value of uid, and if valid iterate through // the listview to find the entry, then tell it to refresh. if (uid.isNull()) { // Clear the list view QString currentUID, nextUID; #ifndef KAB_EMBEDDED |