author | zautrix <zautrix> | 2004-09-03 09:23:23 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-03 09:23:23 (UTC) |
commit | d171ed3b09665db0f511310d6c84a23d75135f50 (patch) (side-by-side diff) | |
tree | 557b3fd423a022559971ceafa61def5adbb7e828 | |
parent | f6b72fd55671131cd81a3357940c9337ea5d7494 (diff) | |
download | kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.zip kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.gz kdepimpi-d171ed3b09665db0f511310d6c84a23d75135f50.tar.bz2 |
Much better search possibility in kapi
-rw-r--r-- | kaddressbook/incsearchwidget.cpp | 7 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 40 | ||||
-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, 47 insertions, 14 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index 94c37e7..2ffa357 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp @@ -1,147 +1,150 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qlabel.h> #include <qlayout.h> #include <qtooltip.h> #include <qcombobox.h> #include <kdialog.h> #include <klineedit.h> #include <klocale.h> #include <kglobal.h> #include "incsearchwidget.h" IncSearchWidget::IncSearchWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) { #ifndef KAB_EMBEDDED //US setCaption( i18n( "Incremental Search" ) ); #endif //KAB_EMBEDDED QHBoxLayout *layout = new QHBoxLayout( this, 2, KDialog::spacingHint() ); #ifdef DESKTOP_VERSION 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 ) { mFieldCombo->clear(); mFieldCombo->insertItem( i18n( "All Fields" ) ); QFontMetrics fm ( mFieldCombo->font() ); int wid = fm.width(i18n( "All Fields" ) ); int max = wid; KABC::Field::List::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) { mFieldCombo->insertItem( (*it)->label() ); // wid = fm.width((*it)->label() ); //if ( wid > max ) // max = wid; } mFieldList = list; announceDoSearch(); announceFieldChanged(); mFieldCombo->setMaximumWidth( wid+60 ); } KABC::Field::List IncSearchWidget::fields() const { return mFieldList; } KABC::Field *IncSearchWidget::currentField()const { if ( mFieldCombo->currentItem() == -1 || mFieldCombo->currentItem() == 0 ) return 0; // for error or 'use all fields' else return mFieldList[ mFieldCombo->currentItem() - 1 ]; } void IncSearchWidget::setCurrentItem( int pos ) { mFieldCombo->setCurrentItem( pos ); announceFieldChanged(); } int IncSearchWidget::currentItem() const { return mFieldCombo->currentItem(); } #ifndef KAB_EMBEDDED #include "incsearchwidget.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index f0f08f4..4299ebd 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -740,219 +740,241 @@ void KABCore::cutContacts() //US if ( uidList.size() > 0 ) { if ( uidList.count() > 0 ) { PwCutCommand *command = new PwCutCommand( mAddressBook, uidList ); UndoStack::instance()->push( command ); RedoStack::instance()->clear(); setModified( true ); } } void KABCore::pasteContacts() { QClipboard *cb = QApplication::clipboard(); KABC::Addressee::List list = AddresseeUtil::clipboardToAddressees( cb->text() ); pasteContacts( list ); } void KABCore::pasteContacts( KABC::Addressee::List &list ) { KABC::Resource *resource = requestResource( this ); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) (*it).setResource( resource ); PwPasteCommand *command = new PwPasteCommand( this, list ); UndoStack::instance()->push( command ); RedoStack::instance()->clear(); setModified( true ); } void KABCore::setWhoAmI() { KABC::Addressee::List addrList = mViewManager->selectedAddressees(); if ( addrList.count() > 1 ) { KMessageBox::sorry( this, i18n( "Please select only one contact." ) ); return; } QString text( i18n( "<qt>Do you really want to use <b>%1</b> as your new personal contact?</qt>" ) ); if ( KMessageBox::questionYesNo( this, text.arg( addrList[ 0 ].assembledName() ) ) == KMessageBox::Yes ) static_cast<KABC::StdAddressBook*>( KABC::StdAddressBook::self() )->setWhoAmI( addrList[ 0 ] ); } void KABCore::setCategories() { KPIM::CategorySelectDialog dlg( KABPrefs::instance(), this, "", true ); if ( !dlg.exec() ) return; bool merge = false; QString msg = i18n( "Merge with existing categories?" ); if ( KMessageBox::questionYesNo( this, msg ) == KMessageBox::Yes ) merge = true; QStringList categories = dlg.selectedCategories(); QStringList uids = mViewManager->selectedUids(); QStringList::Iterator it; for ( it = uids.begin(); it != uids.end(); ++it ) { KABC::Addressee addr = mAddressBook->findByUid( *it ); if ( !addr.isEmpty() ) { if ( !merge ) addr.setCategories( categories ); else { 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(); - + 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() { 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(); mViewManager->refreshView(); mDetails->refreshView(); } bool KABCore::modified() const { return mModified; } void KABCore::contactModified( const KABC::Addressee &addr ) { Command *command = 0; QString uid; // check if it exists already KABC::Addressee origAddr = mAddressBook->findByUid( addr.uid() ); if ( origAddr.isEmpty() ) command = new PwNewCommand( mAddressBook, addr ); else { command = new PwEditCommand( mAddressBook, origAddr, addr ); uid = addr.uid(); } UndoStack::instance()->push( command ); RedoStack::instance()->clear(); setModified( true ); } void KABCore::newContact() { QPtrList<KABC::Resource> kabcResources = mAddressBook->resources(); QPtrList<KRES::Resource> kresResources; QPtrListIterator<KABC::Resource> it( kabcResources ); KABC::Resource *resource; while ( ( resource = it.current() ) != 0 ) { ++it; if ( !resource->readOnly() ) { KRES::Resource *res = static_cast<KRES::Resource*>( resource ); if ( res ) kresResources.append( res ); } } KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, this ); diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index 45c7b55..c93d51a 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -85,192 +85,199 @@ ViewManager::~ViewManager() unloadViews(); mViewFactoryDict.clear(); } void ViewManager::restoreSettings() { mViewNameList = KABPrefs::instance()->mViewNames; QString activeViewName = KABPrefs::instance()->mCurrentView; mActionSelectView->setItems( mViewNameList ); // Filter mFilterList = Filter::restore( mCore->config(), "Filter" ); mActionSelectFilter->setItems( filterNames() ); mActionSelectFilter->setCurrentItem( KABPrefs::instance()->mCurrentFilter ); // Tell the views to reread their config, since they may have // been modified by global settings QString _oldgroup = mCore->config()->group(); QDictIterator<KAddressBookView> it( mViewDict ); for ( it.toFirst(); it.current(); ++it ) { KConfigGroupSaver saver( mCore->config(), it.currentKey() ); it.current()->readConfig( mCore->config() ); } setActiveView( activeViewName ); mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); } void ViewManager::saveSettings() { QString _oldgroup = mCore->config()->group(); QDictIterator<KAddressBookView> it( mViewDict ); for ( it.toFirst(); it.current(); ++it ) { KConfigGroupSaver saver( mCore->config(), it.currentKey() ); #ifdef DESKTOP_VERSION (*it)->writeConfig( mCore->config() ); #else (*it).writeConfig( mCore->config() ); #endif } Filter::save( mCore->config(), "Filter", mFilterList ); KABPrefs::instance()->mCurrentFilter = mActionSelectFilter->currentItem(); // write the view name list KABPrefs::instance()->mViewNames = mViewNameList; KABPrefs::instance()->mCurrentView = mActiveView->caption(); } QStringList ViewManager::selectedUids() const { if ( mActiveView ) return mActiveView->selectedUids(); else return QStringList(); } QStringList ViewManager::selectedEmails() const { if ( mActiveView ) return mActiveView->selectedEmails(); else return QStringList(); } KABC::Addressee::List ViewManager::selectedAddressees() const { KABC::Addressee::List list; 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(); KConfigGroupSaver saver( config, name ); QString type = config->readEntry( "Type", "Table" ); kdDebug(5720) << "ViewManager::setActiveView: creating view - " << name << endl; ViewFactory *factory = mViewFactoryDict.find( type ); if ( factory ) view = factory->view( mCore->addressBook(), mViewWidgetStack ); if ( view ) { view->setCaption( name ); mViewDict.insert( name, view ); //US my version needs an int as second parameter to addWidget mViewWidgetStack->addWidget( view, -1 ); view->readConfig( config ); // The manager just relays the signals connect( view, SIGNAL( selected( const QString& ) ), SIGNAL( selected( const QString & ) ) ); connect( view, SIGNAL( executed( const QString& ) ), SIGNAL( executed( const QString& ) ) ); connect( view, SIGNAL( deleteRequest( ) ), SIGNAL( deleteRequest( ) ) ); connect( view, SIGNAL( modified() ), SIGNAL( modified() ) ); connect( view, SIGNAL( dropped( QDropEvent* ) ), SLOT( dropped( QDropEvent* ) ) ); connect( view, SIGNAL( startDrag() ), SLOT( startDrag() ) ); } } // If we found or created the view, raise it and refresh it if ( view ) { mActiveView = view; mViewWidgetStack->raiseWidget( view ); // Set the proper filter in the view. By setting the combo // box, the activated slot will be called, which will push // the filter to the view and refresh it. if ( view->defaultFilterType() == KAddressBookView::None ) { mActionSelectFilter->setCurrentItem( 0 ); setActiveFilter( 0 ); } else if ( view->defaultFilterType() == KAddressBookView::Active ) { setActiveFilter( mActionSelectFilter->currentItem() ); } else { uint pos = filterPosition( view->defaultFilterName() ); mActionSelectFilter->setCurrentItem( pos ); setActiveFilter( pos ); } //US qDebug("ViewManager::setActiveView 6" ); // Update the inc search widget to show the fields in the new active // view. mCore->setSearchFields( mActiveView->fields() ); //US performance optimization. setActiveFilter calls also mActiveView->refresh() //US mActiveView->refresh(); } else { qDebug("ViewManager::setActiveView: unable to find view" ); kdDebug(5720) << "ViewManager::setActiveView: unable to find view\n"; } } //US added another method with no parameter, since my moc compiler does not support default parameters. void ViewManager::refreshView() diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index a18e87d..97c2275 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h @@ -1,152 +1,153 @@ /* This file is part of KAddressBook. Copyright (c) 2002 Mike Pilone <mpilone@slac.com> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef VIEWMANAGER_H #define VIEWMANAGER_H #include <qwidget.h> #include <qstringlist.h> #include <kaddressbookview.h> #include <qdict.h> class KAction; 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 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. */ void dropped( QDropEvent* ); /** Called whenever the user attempts to start a drag in the view. This method will convert all the selected addressees into text (vcard) and create a drag object. */ void startDrag(); signals: /** Emitted whenever the user selects an entry in the view. */ void selected( const QString &uid ); void deleteRequest( ); /** Emitted whenever the user activates an entry in the view. */ void executed( const QString &uid ); /** Emitted whenever the address book is modified in some way. */ void modified(); /** Emitted whenever a url is dragged on a view. */ void urlDropped( const KURL& ); private slots: void setActiveView( const QString &name ); void setActiveFilter( int index ); void configureFilters(); private: void createViewFactories(); QStringList filterNames() const; int filterPosition( const QString &name ) const; QStringList viewNames() const; int viewPosition( const QString &name ) const; void initActions(); void initGUI(); KABCore *mCore; Filter mCurrentFilter; Filter::List mFilterList; QDict<KAddressBookView> mViewDict; QDict<ViewFactory> mViewFactoryDict; QStringList mViewNameList; QWidgetStack *mViewWidgetStack; KAddressBookView *mActiveView; KAction *mActionDeleteView; KSelectAction *mActionSelectFilter; KSelectAction *mActionSelectView; }; #endif 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 @@ -29,240 +29,240 @@ #include "contactlistview.h" #include "kabprefs.h" #include "undocmds.h" #include "viewmanager.h" #include <qlayout.h> #include "kaddressbooktableview.h" KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent, const char *name ) : KAddressBookView( ab, parent, name ) { mainLayout = new QVBoxLayout( viewWidget(), 2 ); // The list view will be created when the config is read. mListView = 0; } KAddressBookTableView::~KAddressBookTableView() { } void KAddressBookTableView::reconstructListView() { if (mListView) { disconnect(mListView, SIGNAL(selectionChanged()), this, SLOT(addresseeSelected())); disconnect(mListView, SIGNAL(executed(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); disconnect(mListView, SIGNAL(startAddresseeDrag()), this, SIGNAL(startDrag())); disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, SIGNAL(dropped(QDropEvent*))); delete mListView; } mListView = new ContactListView( this, addressBook(), viewWidget() ); // Add the columns KABC::Field::List fieldList = fields(); KABC::Field::List::ConstIterator it; int c = 0; for( it = fieldList.begin(); it != fieldList.end(); ++it ) { mListView->addColumn( (*it)->label() ); mListView->setColumnWidthMode(c++, QListView::Manual); //US // qDebug("KAddressBookTableView::reconstructListView: field %s", (*it)->label().latin1()); } connect(mListView, SIGNAL(selectionChanged()), this, SLOT(addresseeSelected())); connect(mListView, SIGNAL(startAddresseeDrag()), this, 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::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 ContactListViewItem *currentItem = dynamic_cast<ContactListViewItem*>( mListView->currentItem() ); #else //KAB_EMBEDDED ContactListViewItem *currentItem = (ContactListViewItem*)( mListView->currentItem() ); #endif //KAB_EMBEDDED if ( currentItem ) { #ifndef KAB_EMBEDDED ContactListViewItem *nextItem = dynamic_cast<ContactListViewItem*>( currentItem->itemBelow() ); #else //KAB_EMBEDDED ContactListViewItem *nextItem = (ContactListViewItem*)( currentItem->itemBelow() ); #endif //KAB_EMBEDDED if ( nextItem ) nextUID = nextItem->addressee().uid(); currentUID = currentItem->addressee().uid(); } mListView->clear(); currentItem = 0; KABC::Addressee::List addresseeList = addressees(); KABC::Addressee::List::Iterator it; for (it = addresseeList.begin(); it != addresseeList.end(); ++it ) { ContactListViewItem *item = new ContactListViewItem(*it, mListView, addressBook(), fields()); if ( (*it).uid() == currentUID ) currentItem = item; else if ( (*it).uid() == nextUID && !currentItem ) currentItem = item; } // Sometimes the background pixmap gets messed up when we add lots // of items. mListView->repaint(); if ( currentItem ) { mListView->setCurrentItem( currentItem ); mListView->ensureItemVisible( currentItem ); } } else { // Only need to update on entry. Iterate through and try to find it ContactListViewItem *ceItem; QListViewItemIterator it( mListView ); while ( it.current() ) { #ifndef KAB_EMBEDDED ceItem = dynamic_cast<ContactListViewItem*>( it.current() ); #else //KAB_EMBEDDED ceItem = (ContactListViewItem*)( it.current() ); #endif //KAB_EMBEDDED if ( ceItem && ceItem->addressee().uid() == uid ) { ceItem->refresh(); return; } ++it; } refresh( QString::null ); } } QStringList KAddressBookTableView::selectedUids() { QStringList uidList; QListViewItem *item; ContactListViewItem *ceItem; for(item = mListView->firstChild(); item; item = item->itemBelow()) { if (mListView->isSelected( item )) { #ifndef KAB_EMBEDDED ceItem = dynamic_cast<ContactListViewItem*>(item); #else //KAB_EMBEDDED |