author | zautrix <zautrix> | 2004-10-10 23:26:49 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-10 23:26:49 (UTC) |
commit | ea40295e233db219dc2431960e18fb4398ddb75c (patch) (side-by-side diff) | |
tree | 1d654ae51d7f65f4375787105951a8f4f9fc359e /kaddressbook | |
parent | 640874bb21ea348edb33a54690ad225e0efdd1e4 (diff) | |
download | kdepimpi-ea40295e233db219dc2431960e18fb4398ddb75c.zip kdepimpi-ea40295e233db219dc2431960e18fb4398ddb75c.tar.gz kdepimpi-ea40295e233db219dc2431960e18fb4398ddb75c.tar.bz2 |
added better searching in kapi
-rw-r--r-- | kaddressbook/incsearchwidget.cpp | 6 | ||||
-rw-r--r-- | kaddressbook/incsearchwidget.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 3 | ||||
-rw-r--r-- | kaddressbook/kaddressbookview.h | 2 | ||||
-rw-r--r-- | kaddressbook/viewmanager.cpp | 11 | ||||
-rw-r--r-- | kaddressbook/viewmanager.h | 2 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 18 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.h | 2 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.cpp | 17 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookiconview.h | 2 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 16 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.h | 2 |
12 files changed, 79 insertions, 4 deletions
diff --git a/kaddressbook/incsearchwidget.cpp b/kaddressbook/incsearchwidget.cpp index 3533427..78eaf65 100644 --- a/kaddressbook/incsearchwidget.cpp +++ b/kaddressbook/incsearchwidget.cpp @@ -1,161 +1,167 @@ /* 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 <kglobal.h> #include "kabprefs.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 // for performance reasons, we do a search on the pda only after return is pressed connect( mSearchText, SIGNAL( textChanged( const QString& ) ), SLOT( announceDoSearch2() ) ); connect( mFieldCombo, SIGNAL( activated( const QString& ) ), SLOT( announceDoSearch2() ) ); connect( mSearchText, SIGNAL( returnPressed() ), SLOT( announceDoSearch() ) ); connect( mFieldCombo, SIGNAL( activated( const QString& ) ), SLOT( announceFieldChanged() ) ); + + + connect( mSearchText, SIGNAL( scrollUP() ), this, SIGNAL( scrollUP() )); + connect( mSearchText, SIGNAL( scrollDOWN() ), this, SIGNAL( scrollDOWN() )); + + setFocusProxy( mSearchText ); } IncSearchWidget::~IncSearchWidget() { } void IncSearchWidget::announceDoSearch2() { if ( KABPrefs::instance()->mSearchWithReturn ) return; emit doSearch( mSearchText->text() ); //qDebug("emit dosreach "); } void IncSearchWidget::announceDoSearch() { emit doSearch( mSearchText->text() ); // qDebug("emit dosreach "); } 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/incsearchwidget.h b/kaddressbook/incsearchwidget.h index 5c95438..1546a51 100644 --- a/kaddressbook/incsearchwidget.h +++ b/kaddressbook/incsearchwidget.h @@ -1,74 +1,76 @@ /* 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. */ #ifndef INCSEARCHWIDGET_H #define INCSEARCHWIDGET_H #include <qwidget.h> #include <kabc/field.h> class QComboBox; class KLineEdit; class IncSearchWidget : public QWidget { Q_OBJECT public: IncSearchWidget( QWidget *parent, const char *name = 0 ); ~IncSearchWidget(); void setFields( const KABC::Field::List &list ); KABC::Field::List fields() const; KABC::Field *currentField() const; void setCurrentItem( int pos ); int currentItem() const; signals: + void scrollUP(); + void scrollDOWN(); /** This signal is emmited whenever the text in the input widget is changed. You can get the sorting field by @ref currentField. */ void doSearch( const QString& text ); /** This signal is emmited whenever the search field changes. */ void fieldChanged(); private slots: void announceDoSearch(); void announceDoSearch2(); void announceFieldChanged(); private: QComboBox* mFieldCombo; KLineEdit* mSearchText; KABC::Field::List mFieldList; }; #endif diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index cd261f6..f2d4cd6 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -1292,769 +1292,770 @@ void KABCore::setDetailsVisible( bool visible ) mViewManager->hide(); mDetails->show(); } else { mViewManager->show(); mDetails->hide(); } setJumpButtonBarVisible( !visible ); } } void KABCore::extensionChanged( int id ) { //change the details view only for non desktop systems #ifndef DESKTOP_VERSION if (id == 0) { //the user disabled the extension. if (mMultipleViewsAtOnce) { // enable detailsview again setDetailsVisible( true ); mActionDetails->setChecked( true ); } else { //go back to the listview setDetailsVisible( false ); mActionDetails->setChecked( false ); mActionDetails->setEnabled(true); } } else { //the user enabled the extension. setDetailsVisible( false ); mActionDetails->setChecked( false ); if (!mMultipleViewsAtOnce) { mActionDetails->setEnabled(false); } mExtensionManager->setSelectionChanged(); } #endif// DESKTOP_VERSION } void KABCore::extensionModified( const KABC::Addressee::List &list ) { if ( list.count() != 0 ) { KABC::Addressee::List::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) mAddressBook->insertAddressee( *it ); if ( list.count() > 1 ) setModified(); else setModifiedWOrefresh(); } if ( list.count() == 0 ) mViewManager->refreshView(); else mViewManager->refreshView( list[ 0 ].uid() ); } QString KABCore::getNameByPhone( const QString &phone ) { #ifndef KAB_EMBEDDED QRegExp r( "[/*/-/ ]" ); QString localPhone( phone ); bool found = false; QString ownerName = ""; KABC::AddressBook::Iterator iter; KABC::PhoneNumber::List::Iterator phoneIter; KABC::PhoneNumber::List phoneList; for ( iter = mAddressBook->begin(); !found && ( iter != mAddressBook->end() ); ++iter ) { phoneList = (*iter).phoneNumbers(); for ( phoneIter = phoneList.begin(); !found && ( phoneIter != phoneList.end() ); ++phoneIter) { // Get rid of separator chars so just the numbers are compared. if ( (*phoneIter).number().replace( r, "" ) == localPhone.replace( r, "" ) ) { ownerName = (*iter).formattedName(); found = true; } } } return ownerName; #else //KAB_EMBEDDED qDebug("KABCore::getNameByPhone finsih method"); return ""; #endif //KAB_EMBEDDED } void KABCore::openConfigDialog() { KCMultiDialog* ConfigureDialog = new KCMultiDialog( "PIM", this ,"kabconfigdialog", true ); KCMKabConfig* kabcfg = new KCMKabConfig( ConfigureDialog->getNewVBoxPage(i18n( "Addressbook")) , "KCMKabConfig" ); ConfigureDialog->addModule(kabcfg ); KCMKdePimConfig* kdelibcfg = new KCMKdePimConfig( ConfigureDialog->getNewVBoxPage(i18n( "Global")) , "KCMKdeLibConfig" ); ConfigureDialog->addModule(kdelibcfg ); connect( ConfigureDialog, SIGNAL( applyClicked() ), this, SLOT( configurationChanged() ) ); connect( ConfigureDialog, SIGNAL( okClicked() ), this, SLOT( configurationChanged() ) ); saveSettings(); #ifndef DESKTOP_VERSION ConfigureDialog->showMaximized(); #endif if ( ConfigureDialog->exec() ) KMessageBox::information( this, i18n("Some changes are only\neffective after a restart!\n") ); delete ConfigureDialog; } void KABCore::openLDAPDialog() { #ifndef KAB_EMBEDDED if ( !mLdapSearchDialog ) { mLdapSearchDialog = new LDAPSearchDialog( mAddressBook, this ); connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), mViewManager, SLOT( refreshView() ) ); connect( mLdapSearchDialog, SIGNAL( addresseesAdded() ), this, SLOT( setModified() ) ); } else mLdapSearchDialog->restoreSettings(); if ( mLdapSearchDialog->isOK() ) mLdapSearchDialog->exec(); #else //KAB_EMBEDDED qDebug("KABCore::openLDAPDialog() finsih method"); #endif //KAB_EMBEDDED } void KABCore::print() { #ifndef KAB_EMBEDDED KPrinter printer; if ( !printer.setup( this ) ) return; KABPrinting::PrintingWizard wizard( &printer, mAddressBook, mViewManager->selectedUids(), this ); wizard.exec(); #else //KAB_EMBEDDED qDebug("KABCore::print() finsih method"); #endif //KAB_EMBEDDED } void KABCore::addGUIClient( KXMLGUIClient *client ) { if ( mGUIClient ) mGUIClient->insertChildClient( client ); else KMessageBox::error( this, "no KXMLGUICLient"); } void KABCore::configurationChanged() { mExtensionManager->reconfigure(); } void KABCore::addressBookChanged() { /*US QDictIterator<AddresseeEditorDialog> it( mEditorDict ); while ( it.current() ) { if ( it.current()->dirty() ) { QString text = i18n( "Data has been changed externally. Unsaved " "changes will be lost." ); KMessageBox::information( this, text ); } it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); ++it; } */ if (mEditorDialog) { if (mEditorDialog->dirty()) { QString text = i18n( "Data has been changed externally. Unsaved " "changes will be lost." ); KMessageBox::information( this, text ); } QString currentuid = mEditorDialog->addressee().uid(); mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); } mViewManager->refreshView(); // mDetails->refreshView(); } AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, const char *name ) { if ( mEditorDialog == 0 ) { mEditorDialog = new AddresseeEditorDialog( this, parent, name ? name : "editorDialog" ); connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), SLOT( contactModified( const KABC::Addressee& ) ) ); //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), // SLOT( slotEditorDestroyed( const QString& ) ) ; } return mEditorDialog; } void KABCore::slotEditorDestroyed( const QString &uid ) { //mEditorDict.remove( uid ); } void KABCore::initGUI() { #ifndef KAB_EMBEDDED QHBoxLayout *topLayout = new QHBoxLayout( this ); topLayout->setSpacing( KDialogBase::spacingHint() ); mExtensionBarSplitter = new QSplitter( this ); mExtensionBarSplitter->setOrientation( Qt::Vertical ); mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); QVBox *viewSpace = new QVBox( mDetailsSplitter ); mIncSearchWidget = new IncSearchWidget( viewSpace ); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( mDetailsSplitter ); mJumpButtonBar = new JumpButtonBar( this, this ); mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); topLayout->addWidget( mExtensionBarSplitter ); topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); topLayout->addWidget( mJumpButtonBar ); topLayout->setStretchFactor( mJumpButtonBar, 1 ); mXXPortManager = new XXPortManager( this, this ); #else //KAB_EMBEDDED //US initialize viewMenu before settingup viewmanager. // Viewmanager needs this menu to plugin submenues. viewMenu = new QPopupMenu( this ); settingsMenu = new QPopupMenu( this ); //filterMenu = new QPopupMenu( this ); ImportMenu = new QPopupMenu( this ); ExportMenu = new QPopupMenu( this ); syncMenu = new QPopupMenu( this ); changeMenu= new QPopupMenu( this ); //US since we have no splitter for the embedded system, setup // a layout with two frames. One left and one right. QBoxLayout *topLayout; // = new QHBoxLayout( this ); // QBoxLayout *topLayout = (QBoxLayout*)layout(); // QWidget *mainBox = new QWidget( this ); // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); #ifdef DESKTOP_VERSION topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); topLayout->addWidget(mMiniSplitter ); mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); mViewManager = new ViewManager( this, mExtensionBarSplitter ); mDetails = new ViewContainer( mMiniSplitter ); mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); #else if ( QApplication::desktop()->width() > 480 ) { topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); } else { topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); } topLayout->addWidget(mMiniSplitter ); mViewManager = new ViewManager( this, mMiniSplitter ); mDetails = new ViewContainer( mMiniSplitter ); mExtensionManager = new ExtensionManager( this, mMiniSplitter ); #endif //eh->hide(); // topLayout->addWidget(mExtensionManager ); /*US #ifndef KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( mDetailsSplitter ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( mDetailsSplitter ); topLayout->addWidget( mDetailsSplitter ); topLayout->setStretchFactor( mDetailsSplitter, 100 ); #else //KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); // mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( this ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( this ); topLayout->addWidget( viewSpace ); // topLayout->setStretchFactor( mDetailsSplitter, 100 ); topLayout->addWidget( mDetails ); #endif //KAB_NOSPLITTER */ syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); syncManager->setBlockSave(false); connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); syncManager->setDefaultFileName( sentSyncFile()); //connect(syncManager , SIGNAL( ), this, SLOT( ) ); #endif //KAB_EMBEDDED initActions(); #ifdef KAB_EMBEDDED addActionsManually(); //US make sure the export and import menues are initialized before creating the xxPortManager. mXXPortManager = new XXPortManager( this, this ); // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); // mActionQuit->plug ( mMainWindow->toolBar()); //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); // mIncSearchWidget->hide(); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); - + connect( mIncSearchWidget, SIGNAL( scrollUP() ),mViewManager, SLOT( scrollUP() ) ); + connect( mIncSearchWidget, SIGNAL( scrollDOWN() ),mViewManager, SLOT( scrollDOWN() ) ); mJumpButtonBar = new JumpButtonBar( this, this ); topLayout->addWidget( mJumpButtonBar ); //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); // mMainWindow->getIconToolBar()->raise(); #endif //KAB_EMBEDDED } void KABCore::initActions() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifndef KAB_EMBEDDED connect( QApplication::clipboard(), SIGNAL( dataChanged() ), SLOT( clipboardDataChanged() ) ); #endif //KAB_EMBEDDED // file menu if ( mIsPart ) { mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, SLOT( sendMail() ), actionCollection(), "kaddressbook_mail" ); mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, SLOT( print() ), actionCollection(), "kaddressbook_print" ); } else { mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); } mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, SLOT( save() ), actionCollection(), "file_sync" ); mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, SLOT( newContact() ), actionCollection(), "file_new_contact" ); mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, this, SLOT( mailVCard() ), actionCollection(), "file_mail_vcard"); mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, SLOT( export2phone() ), actionCollection(), "kaddressbook_ex2phone" ); mActionBeamVCard = 0; mActionBeam = 0; #ifndef DESKTOP_VERSION if ( Ir::supported() ) { mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, SLOT( beamVCard() ), actionCollection(), "kaddressbook_beam_vcard" ); mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, SLOT( beamMySelf() ), actionCollection(), "kaddressbook_beam_myself" ); } #endif mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, this, SLOT( editContact2() ), actionCollection(), "file_properties" ); #ifdef KAB_EMBEDDED // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, mMainWindow, SLOT( exit() ), actionCollection(), "quit" ); #endif //KAB_EMBEDDED // edit menu if ( mIsPart ) { mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, SLOT( copyContacts() ), actionCollection(), "kaddressbook_copy" ); mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, SLOT( cutContacts() ), actionCollection(), "kaddressbook_cut" ); mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, SLOT( pasteContacts() ), actionCollection(), "kaddressbook_paste" ); mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, SLOT( selectAllContacts() ), actionCollection(), "kaddressbook_select_all" ); mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, SLOT( undo() ), actionCollection(), "kaddressbook_undo" ); mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, this, SLOT( redo() ), actionCollection(), "kaddressbook_redo" ); } else { mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); } mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", Key_Delete, this, SLOT( deleteContacts() ), actionCollection(), "edit_delete" ); mActionUndo->setEnabled( false ); mActionRedo->setEnabled( false ); // settings menu #ifdef KAB_EMBEDDED //US special menuentry to configure the addressbook resources. On KDE // you do that through the control center !!! mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, SLOT( configureResources() ), actionCollection(), "kaddressbook_configure_resources" ); #endif //KAB_EMBEDDED if ( mIsPart ) { mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, SLOT( openConfigDialog() ), actionCollection(), "kaddressbook_configure" ); mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, this, SLOT( configureKeyBindings() ), actionCollection(), "kaddressbook_configure_shortcuts" ); #ifdef KAB_EMBEDDED mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); mActionConfigureToolbars->setEnabled( false ); #endif //KAB_EMBEDDED } else { mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); } mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, actionCollection(), "options_show_jump_bar" ); connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, actionCollection(), "options_show_details" ); connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); // misc // only enable LDAP lookup if we can handle the protocol #ifndef KAB_EMBEDDED if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, this, SLOT( openLDAPDialog() ), actionCollection(), "ldap_lookup" ); } #else //KAB_EMBEDDED //qDebug("KABCore::initActions() LDAP has to be implemented"); #endif //KAB_EMBEDDED mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, SLOT( setWhoAmI() ), actionCollection(), "set_personal" ); mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, SLOT( setCategories() ), actionCollection(), "edit_set_categories" ); mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, SLOT( removeVoice() ), actionCollection(), "remove_voice" ); mActionImportOL = new KAction( i18n( "Import from Outlook..." ), 0, this, SLOT( importFromOL() ), actionCollection(), "import_OL" ); #ifdef KAB_EMBEDDED mActionLicence = new KAction( i18n( "Licence" ), 0, this, SLOT( showLicence() ), actionCollection(), "licence_about_data" ); mActionFaq = new KAction( i18n( "Faq" ), 0, this, SLOT( faq() ), actionCollection(), "faq_about_data" ); mActionAboutKAddressbook = new KAction( i18n( "&About KAddressBook" ), "kaddressbook2", 0, this, SLOT( createAboutData() ), actionCollection(), "kaddressbook_about_data" ); #endif //KAB_EMBEDDED clipboardDataChanged(); connect( UndoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); connect( RedoStack::instance(), SIGNAL( changed() ), SLOT( updateActionMenu() ) ); } //US we need this function, to plug all actions into the correct menues. // KDE uses a XML format to plug the actions, but we work her without this overhead. void KABCore::addActionsManually() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifdef KAB_EMBEDDED QPopupMenu *fileMenu = new QPopupMenu( this ); QPopupMenu *editMenu = new QPopupMenu( this ); QPopupMenu *helpMenu = new QPopupMenu( this ); KToolBar* tb = mMainWindow->toolBar(); #ifdef DESKTOP_VERSION QMenuBar* mb = mMainWindow->menuBar(); //US setup menubar. //Disable the following block if you do not want to have a menubar. mb->insertItem( "&File", fileMenu ); mb->insertItem( "&Edit", editMenu ); mb->insertItem( "&View", viewMenu ); mb->insertItem( "&Settings", settingsMenu ); mb->insertItem( i18n("Synchronize"), syncMenu ); mb->insertItem( "&Change selected", changeMenu ); mb->insertItem( "&Help", helpMenu ); mIncSearchWidget = new IncSearchWidget( tb ); // tb->insertWidget(-1, 0, mIncSearchWidget); #else //US setup toolbar QPEMenuBar *menuBarTB = new QPEMenuBar( tb ); QPopupMenu *popupBarTB = new QPopupMenu( this ); menuBarTB->insertItem( "ME", popupBarTB); tb->insertWidget(-1, 0, menuBarTB); mIncSearchWidget = new IncSearchWidget( tb ); tb->enableMoving(false); popupBarTB->insertItem( "&File", fileMenu ); popupBarTB->insertItem( "&Edit", editMenu ); popupBarTB->insertItem( "&View", viewMenu ); popupBarTB->insertItem( "&Settings", settingsMenu ); popupBarTB->insertItem( i18n("Synchronize"), syncMenu ); mViewManager->getFilterAction()->plug ( popupBarTB); popupBarTB->insertItem( "&Change selected", changeMenu ); popupBarTB->insertItem( "&Help", helpMenu ); if (QApplication::desktop()->width() > 320 ) { // mViewManager->getFilterAction()->plug ( tb); } #endif // mActionQuit->plug ( mMainWindow->toolBar()); //US Now connect the actions with the menue entries. mActionPrint->plug( fileMenu ); mActionMail->plug( fileMenu ); fileMenu->insertSeparator(); mActionNewContact->plug( fileMenu ); mActionNewContact->plug( tb ); mActionEditAddressee->plug( fileMenu ); if ((KGlobal::getDesktopSize() > KGlobal::Small ) || (!KABPrefs::instance()->mMultipleViewsAtOnce )) mActionEditAddressee->plug( tb ); fileMenu->insertSeparator(); mActionSave->plug( fileMenu ); fileMenu->insertItem( "&Import", ImportMenu ); fileMenu->insertItem( "&Export", ExportMenu ); fileMenu->insertSeparator(); mActionMailVCard->plug( fileMenu ); #ifndef DESKTOP_VERSION if ( Ir::supported() ) mActionBeamVCard->plug( fileMenu ); if ( Ir::supported() ) mActionBeam->plug(fileMenu ); #endif fileMenu->insertSeparator(); mActionQuit->plug( fileMenu ); #ifdef _WIN32_ mActionImportOL->plug( ImportMenu ); #endif // edit menu mActionUndo->plug( editMenu ); mActionRedo->plug( editMenu ); editMenu->insertSeparator(); mActionCut->plug( editMenu ); mActionCopy->plug( editMenu ); mActionPaste->plug( editMenu ); mActionDelete->plug( editMenu ); editMenu->insertSeparator(); mActionSelectAll->plug( editMenu ); mActionRemoveVoice->plug( changeMenu ); // settings menu //US special menuentry to configure the addressbook resources. On KDE // you do that through the control center !!! mActionConfigResources->plug( settingsMenu ); settingsMenu->insertSeparator(); mActionConfigKAddressbook->plug( settingsMenu ); if ( mIsPart ) { mActionConfigShortcuts->plug( settingsMenu ); mActionConfigureToolbars->plug( settingsMenu ); } else { mActionKeyBindings->plug( settingsMenu ); } settingsMenu->insertSeparator(); mActionJumpBar->plug( settingsMenu ); mActionDetails->plug( settingsMenu ); if (!KABPrefs::instance()->mMultipleViewsAtOnce || KGlobal::getDesktopSize() == KGlobal::Desktop ) mActionDetails->plug( tb ); settingsMenu->insertSeparator(); mActionWhoAmI->plug( settingsMenu ); mActionCategories->plug( settingsMenu ); mActionLicence->plug( helpMenu ); mActionFaq->plug( helpMenu ); mActionAboutKAddressbook->plug( helpMenu ); if (KGlobal::getDesktopSize() > KGlobal::Small ) { mActionSave->plug( tb ); mViewManager->getFilterAction()->plug ( tb); if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { mActionUndo->plug( tb ); mActionDelete->plug( tb ); mActionRedo->plug( tb ); } } //mActionQuit->plug ( tb ); // tb->insertWidget(-1, 0, mIncSearchWidget, 6); //US link the searchwidget first to this. // The real linkage to the toolbar happens later. //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); //US tb->insertItem( mIncSearchWidget ); /*US mIncSearchWidget = new IncSearchWidget( tb ); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mJumpButtonBar = new JumpButtonBar( this, this ); //US topLayout->addWidget( mJumpButtonBar ); this->layout()->add( mJumpButtonBar ); */ #endif //KAB_EMBEDDED mActionExport2phone->plug( ExportMenu ); connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); syncManager->fillSyncMenu(); } void KABCore::showLicence() { KApplication::showLicence(); } void KABCore::removeVoice() { if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) return; KABC::Addressee::List list = mViewManager->selectedAddressees(); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( (*it).removeVoice() ) contactModified((*it) ); } } void KABCore::clipboardDataChanged() { if ( mReadWrite ) mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); } void KABCore::updateActionMenu() { UndoStack *undo = UndoStack::instance(); RedoStack *redo = RedoStack::instance(); diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h index 17106e8..c134e96 100644 --- a/kaddressbook/kaddressbookview.h +++ b/kaddressbook/kaddressbookview.h @@ -1,296 +1,298 @@ /* 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 KADDRESSBOOKVIEW_H #define KADDRESSBOOKVIEW_H #ifndef KAB_EMBEDDED #include <klibloader.h> #endif //KAB_EMBEDDED class KConfig; class QDropEvent; #include <qstringlist.h> #include <kabc/field.h> #include <qwidget.h> #include "viewconfigurewidget.h" #include "filter.h" 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; + virtual void scrollUP() = 0; + virtual void scrollDOWN() = 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. @param config The KConfig object to read from. The group will already be set, so do not change the group. */ virtual void writeConfig( KConfig *config ); /** Returns a QString with all the selected email addresses concatenated together with a ',' seperator. */ virtual QString selectedEmails(); /** Return the type of the view: Icon, Table, etc. Please make sure that this is the same value that ViewWrapper::type() will return for your view. */ virtual QString type() const = 0; /** Returns a list of the fields that should be displayed. The list is composed of the fields proper names (ie: Home Address), so the view may need to translate them in order to get the value from the addressee. This list is generated from the config file, so it is advisable to call this method whenever a readConfig() is called in order to get the newest list of fields. */ KABC::Field::List fields() const; /** Sets the active filter. This filter will be used for filtering the list of addressees to display. The view will <b>not</b> automatically refresh itself, so in most cases you will want to call KAddressBookView::refresh() after this method. */ void setFilter( const Filter& ); /** @return The default filter type selection. If the selection is SpecificFilter, the name of the filter can be retrieved with defaultFilterName() */ DefaultFilterType defaultFilterType() const; /** @return The name of the default filter. This string is only valid if defaultFilterType() is returning SpecificFilter. */ const QString &defaultFilterName() const; /** @return The address book. */ KABC::AddressBook *addressBook() const; public slots: /** Must be overloaded in subclasses to refresh the view. Refreshing includes updating the view to ensure that only items in the document are visible. If <i>uid</i> is valid, only the addressee with uid needs to be refreshed. This is an optimization only. */ virtual void refresh( QString uid = QString::null ) = 0; /** This method must be overloaded in subclasses. Select (highlight) the addressee matching <i>uid</i>. If uid is equal to QString::null, then all addressees should be selected. */ #ifndef KAB_EMBEDDED //MOC_SKIP_BEGIN virtual void setSelected( QString uid = QString::null, bool selected = true ) = 0; //MOC_SKIP_END #else //KAB_EMBEDDED //US my moc can not handle the default parameters. Is this a problem ??? virtual void setSelected( QString uid, bool selected) = 0; #endif //KAB_EMBEDDED signals: /** This signal should be emitted by a subclass whenever an addressee is modified. */ void modified(); /** This signal should be emitted by a subclass whenever an addressee is selected. Selected means that the addressee was given the focus. Some widgets may call this 'highlighted'. The view is responsible for emitting this signal multiple times if multiple items are selected, with the last item selected being the last emit. @param uid The uid of the selected addressee. @see KListView */ void selected( const QString &uid ); void deleteRequest(); /** This signal should be emitted by a subclass whenever an addressee is executed. This is defined by the KDE system wide config, but it either means single or doubleclicked. @param ui The uid of the selected addressee @see KListView */ void executed( const QString &uid ); /** This signal is emitted whenever a user attempts to start a drag in the view. The slot connected to this signal would usually want to create a QDragObject. */ void startDrag(); /** This signal is emitted whenever the user drops something on the view. The individual view should handle checking if the item is droppable (ie: if it is a vcard). */ void dropped( QDropEvent* ); protected: /** Returns a list of the addressees that should be displayed. This method should always be used by the subclass to get a list of addressees. This method internally takes many factors into account, including the current filter. */ KABC::Addressee::List addressees(); /** This method returns the widget that should be used as the parent for all view components. By using this widget as the parent and not 'this', the view subclass has the option of placing other widgets around the view (ie: search fields, etc). Do not delete this widget! */ QWidget *viewWidget(); private: void initGUI(); DefaultFilterType mDefaultFilterType; Filter mFilter; QString mDefaultFilterName; KABC::AddressBook *mAddressBook; KABC::Field::List mFieldList; QWidget *mViewWidget; }; #ifndef KAB_EMBEDDED //MOC_SKIP_BEGIN class ViewFactory : public KLibFactory //MOC_SKIP_END #else //KAB_EMBEDDED class ViewFactory #endif //KAB_EMBEDDED { public: virtual KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ) = 0; /** @return The type of the view. This is normally a small one word string (ie: Table, Icon, Tree, etc). */ virtual QString type() const = 0; /** @return The description of the view. This should be a 3 to 4 line string (don't actually use return characters in the string) describing the features offered by the view. */ virtual QString description() const = 0; /** Creates a config dialog for the view type. The default implementation will return a ViewConfigDialog. This default dialog will allow the user to set the visible fields only. If you need more config options (as most views will), this method can be overloaded to return your sublcass of ViewConfigDialog. If this method is over loaded the base classes method should <B>not</B> be called. */ virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); protected: virtual QObject* createObject( QObject*, const char*, const char*, const QStringList & ) { return 0; } }; #endif diff --git a/kaddressbook/viewmanager.cpp b/kaddressbook/viewmanager.cpp index c6baeac..f4fb08b 100644 --- a/kaddressbook/viewmanager.cpp +++ b/kaddressbook/viewmanager.cpp @@ -1,472 +1,481 @@ /* 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. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KAB_EMBEDDED #include <libkdepim/kvcarddrag.h> #include <kabc/vcardconverter.h> #include <kconfig.h> #include <kdeversion.h> #include <kiconloader.h> #include <klocale.h> #include <kmessagebox.h> #include <kmultipledrag.h> #include <ktrader.h> #include <kurldrag.h> #include "addresseeutil.h" #else //KAB_EMBEDDED #include "views/kaddressbookiconview.h" #include "views/kaddressbooktableview.h" #include "views/kaddressbookcardview.h" #include "kaddressbookview.h" #include <qaction.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <kconfigbase.h> #endif //KAB_EMBEDDED #include <kdebug.h> #include <kactionclasses.h> #include <qlayout.h> #include <qwidgetstack.h> #include <kabc/addressbook.h> #include "filtereditdialog.h" #include "addviewdialog.h" #include "kabcore.h" #include "kabprefs.h" #include "viewmanager.h" ViewManager::ViewManager( KABCore *core, QWidget *parent, const char *name ) : QWidget( parent, name ), mCore( core ), mActiveView( 0 ) { initGUI(); initActions(); mViewDict.setAutoDelete( true ); createViewFactories(); } ViewManager::~ViewManager() { unloadViews(); mViewFactoryDict.clear(); } - +void ViewManager::scrollUP() +{ + if ( mActiveView ) + mActiveView->scrollUP(); +} +void ViewManager::scrollDOWN() +{ + if ( mActiveView ) + mActiveView->scrollDOWN(); +} 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() { refreshView( QString::null ); } void ViewManager::refreshView( const QString &uid ) { if ( mActiveView ) mActiveView->refresh( uid ); } void ViewManager::editView() { if ( !mActiveView ) return; ViewFactory *factory = mViewFactoryDict.find( mActiveView->type() ); ViewConfigureWidget *wdg = 0; ViewConfigureDialog* dlg = 0; if ( factory ) { // Save the filters so the dialog has the latest set Filter::save( mCore->config(), "Filter", mFilterList ); dlg = new ViewConfigureDialog( 0, mActiveView->caption(), this, "conf_dlg" ); wdg = factory->configureWidget( mCore->addressBook(), dlg,"conf_wid" ); } else { qDebug("ViewManager::editView()::cannot find viewfactory "); return; } if ( wdg ) { dlg->setWidget( wdg ); #ifndef DESKTOP_VERSION //dlg.setMaximumSize( 640, 480 ); //dlg->setGeometry( 40,40, 400, 300); dlg->showMaximized(); #endif KConfigGroupSaver saver( mCore->config(), mActiveView->caption() ); dlg->restoreSettings( mCore->config() ); if ( dlg->exec() ) { dlg->saveSettings( mCore->config() ); mActiveView->readConfig( mCore->config() ); // 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 ( mActiveView->defaultFilterType() == KAddressBookView::None ) { mActionSelectFilter->setCurrentItem( 0 ); setActiveFilter( 0 ); } else if ( mActiveView->defaultFilterType() == KAddressBookView::Active ) { setActiveFilter( mActionSelectFilter->currentItem() ); } else { uint pos = filterPosition( mActiveView->defaultFilterName() ); mActionSelectFilter->setCurrentItem( pos ); setActiveFilter( pos ); } mCore->setSearchFields( mActiveView->fields() ); //US performance optimization. setActiveFilter calls also mActiveView->refresh() //US mActiveView->refresh(); //US this is a bugfix, that we get notified if we change a views configuration emit modified(); } } delete dlg; } void ViewManager::deleteView() { QString text = i18n( "<qt>Are you sure that you want to delete the view <b>%1</b>?</qt>" ) .arg( mActiveView->caption() ); QString caption = i18n( "Confirm Delete" ); if (QMessageBox::information( this, caption, text, i18n("Yes!"), i18n("No"), 0, 0 ) == 0) { mViewNameList.remove( mActiveView->caption() ); // remove the view from the config file KConfig *config = mCore->config(); config->deleteGroup( mActiveView->caption() ); mViewDict.remove( mActiveView->caption() ); mActiveView = 0; // we are in an invalid state now, but that should be fixed after // we emit the signal mActionSelectView->setItems( mViewNameList ); if ( mViewNameList.count() > 0 ) { mActionSelectView->setCurrentItem( 0 ); setActiveView( mViewNameList[ 0 ] ); } mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); } } void ViewManager::addView() { AddViewDialog dialog( &mViewFactoryDict, this ); if ( dialog.exec() ) { QString newName = dialog.viewName(); QString type = dialog.viewType(); // Check for name conflicts bool firstConflict = true; int numTries = 1; while ( mViewNameList.contains( newName ) > 0 ) { if ( !firstConflict ) { newName = newName.left( newName.length() - 4 ); firstConflict = false; } newName = QString( "%1 <%2>" ).arg( newName ).arg( numTries ); numTries++; } // Add the new one to the list mViewNameList.append( newName ); // write the view to the config file, KConfig *config = mCore->config(); config->deleteGroup( newName ); KConfigGroupSaver saver( config, newName ); config->writeEntry( "Type", type ); // try to set the active view mActionSelectView->setItems( mViewNameList ); mActionSelectView->setCurrentItem( mViewNameList.findIndex( newName ) ); setActiveView( newName ); editView(); mActionDeleteView->setEnabled( mViewNameList.count() > 1 ); } } void ViewManager::createViewFactories() { #ifndef KAB_EMBEDDED KTrader::OfferList plugins = KTrader::self()->query( "KAddressBook/View" ); KTrader::OfferList::ConstIterator it; for ( it = plugins.begin(); it != plugins.end(); ++it ) { if ( !(*it)->hasServiceType( "KAddressBook/View" ) ) continue; KLibFactory *factory = KLibLoader::self()->factory( (*it)->library().latin1() ); if ( !factory ) { kdDebug(5720) << "ViewManager::createViewFactories(): Factory creation failed" << endl; continue; } ViewFactory *viewFactory = static_cast<ViewFactory*>( factory ); if ( !viewFactory ) { kdDebug(5720) << "ViewManager::createViewFactories(): Cast failed" << endl; continue; } mViewFactoryDict.insert( viewFactory->type(), viewFactory ); } #else //KAB_EMBEDDED ViewFactory* viewFactory = new IconViewFactory(); mViewFactoryDict.insert( viewFactory->type(), viewFactory ); // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); viewFactory = new TableViewFactory(); mViewFactoryDict.insert( viewFactory->type(), viewFactory ); // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); viewFactory = new CardViewFactory(); mViewFactoryDict.insert( viewFactory->type(), viewFactory ); // qDebug("ViewManager::createViewFactories() Loading factory: %s", viewFactory->type().latin1()); #endif //KAB_EMBEDDED } diff --git a/kaddressbook/viewmanager.h b/kaddressbook/viewmanager.h index 6def6b6..585f4e9 100644 --- a/kaddressbook/viewmanager.h +++ b/kaddressbook/viewmanager.h @@ -1,154 +1,156 @@ /* 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 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: + void scrollUP(); + void scrollDOWN(); //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/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index 4babf67..a7bf6c9 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp @@ -1,448 +1,464 @@ /* 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. */ #include <qdragobject.h> #include <qevent.h> #include <qiconview.h> #include <qlayout.h> #include <qstringlist.h> #include <qregexp.h> +#include <qapplication.h> #include <kabc/addressbook.h> #include <kabc/addressee.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> #include "kabprefs.h" #include "viewmanager.h" #include "kaddressbookcardview.h" #ifndef KAB_EMBEDDED extern "C" { void *init_libkaddrbk_cardview() { return ( new CardViewFactory ); } } #endif //KAB_EMBEDDED //////////////////////////////// // AddresseeCardViewItem (internal class) class AddresseeCardViewItem : public CardViewItem { public: AddresseeCardViewItem(const KABC::Field::List &fields, bool showEmptyFields, KABC::AddressBook *doc, const KABC::Addressee &a, CardView *parent) : CardViewItem(parent, a.formattedName()), mFields( fields ), mShowEmptyFields(showEmptyFields), mDocument(doc), mAddressee(a) { if ( mFields.isEmpty() ) { mFields = KABC::Field::defaultFields(); } refresh(); } const KABC::Addressee &addressee() const { return mAddressee; } void refresh() { // Update our addressee, since it may have changed elsewhere mAddressee = mDocument->findByUid(mAddressee.uid()); if (!mAddressee.isEmpty()) { clearFields(); // Try all the selected fields until we find one with text. // This will limit the number of unlabeled icons in the view KABC::Field::List::Iterator iter; for (iter = mFields.begin(); iter != mFields.end(); ++iter) { // insert empty fields or not? not doing so saves a bit of memory and CPU // (during geometry calculations), but prevents having equally // wide label columns in all cards, unless CardViewItem/CardView search // globally for the widest label. (anders) //if (mShowEmptyFields || !(*iter)->value( mAddressee ).isEmpty()) insertField((*iter)->label(), (*iter)->value( mAddressee )); } // We might want to make this the first field. hmm... -mpilone 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 KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, QWidget *parent, const char *name ) : KAddressBookView( ab, parent, name ) { mShowEmptyFields = false; // Init the GUI QVBoxLayout *layout = new QVBoxLayout(viewWidget()); mCardView = new AddresseeCardView(viewWidget(), "mCardView"); mCardView->setSelectionMode(CardView::Extended); layout->addWidget(mCardView); // Connect up the signals connect(mCardView, SIGNAL(executed(CardViewItem *)), this, SLOT(addresseeExecuted(CardViewItem *))); connect(mCardView, SIGNAL(selectionChanged()), this, SLOT(addresseeSelected())); connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), this, SIGNAL(dropped(QDropEvent*))); connect(mCardView, SIGNAL(startAddresseeDrag()), this, SIGNAL(startDrag())); } KAddressBookCardView::~KAddressBookCardView() { } +void KAddressBookCardView::scrollUP() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mCardView, ev ); + +} +void KAddressBookCardView::scrollDOWN() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mCardView, ev ); +} void KAddressBookCardView::readConfig(KConfig *config) { KAddressBookView::readConfig(config); // costum colors? if ( config->readBoolEntry( "EnableCustomColors", false ) ) { QPalette p( mCardView->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 ) ); mCardView->viewport()->setPalette( p ); } else { // needed if turned off during a session. mCardView->viewport()->setPalette( mCardView->palette() ); } //custom fonts? QFont f( font() ); if ( config->readBoolEntry( "EnableCustomFonts", false ) ) { mCardView->setFont( config->readFontEntry( "TextFont", &f) ); f.setBold( true ); mCardView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); } else { mCardView->setFont( f ); f.setBold( true ); mCardView->setHeaderFont( f ); } mCardView->setDrawCardBorder(config->readBoolEntry("DrawBorder", true)); mCardView->setDrawColSeparators(config->readBoolEntry("DrawSeparators", true)); mCardView->setDrawFieldLabels(config->readBoolEntry("DrawFieldLabels",false)); mShowEmptyFields = config->readBoolEntry("ShowEmptyFields", false); 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 + if ( mCardView->firstItem() ) { + mCardView->setCurrentItem ( mCardView->firstItem() ); + mCardView->setSelected ( mCardView->firstItem() , true ); + } + else 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) { CardViewItem *item; AddresseeCardViewItem *aItem; if (uid.isNull()) { // Rebuild the view mCardView->viewport()->setUpdatesEnabled( false ); mCardView->clear(); KABC::Addressee::List addresseeList = addressees(); KABC::Addressee::List::Iterator iter; for (iter = addresseeList.begin(); iter != addresseeList.end(); ++iter) { if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) continue; aItem = new AddresseeCardViewItem(fields(), mShowEmptyFields, addressBook(), *iter, mCardView); } mCardView->viewport()->setUpdatesEnabled( true ); mCardView->viewport()->update(); // by default nothing is selected emit selected(QString::null); } else { // Try to find the one to refresh bool found = false; for (item = mCardView->firstItem(); item && !found; item = item->nextItem()) { #ifndef KAB_EMBEDDED aItem = dynamic_cast<AddresseeCardViewItem*>(item); #else //KAB_EMBEDDED aItem = (AddresseeCardViewItem*)(item); #endif //KAB_EMBEDDED if ((aItem) && (aItem->addressee().uid() == uid)) { aItem->refresh(); found = true; } } } } void KAddressBookCardView::setSelected(QString uid, bool selected) { CardViewItem *item; AddresseeCardViewItem *aItem; if (uid.isNull()) { mCardView->selectAll(selected); } else { bool found = false; for (item = mCardView->firstItem(); item && !found; item = item->nextItem()) { #ifndef KAB_EMBEDDED aItem = dynamic_cast<AddresseeCardViewItem*>(item); #else //KAB_EMBEDDED aItem = (AddresseeCardViewItem*)(item); #endif //KAB_EMBEDDED if ((aItem) && (aItem->addressee().uid() == uid)) { mCardView->setSelected(aItem, selected); mCardView->ensureItemVisible(item); found = true; } } } } //US added an additional method without parameter void KAddressBookCardView::setSelected() { setSelected(QString::null, true); } void KAddressBookCardView::addresseeExecuted(CardViewItem *item) { #ifndef KAB_EMBEDDED AddresseeCardViewItem *aItem = dynamic_cast<AddresseeCardViewItem*>(item); #else //KAB_EMBEDDED AddresseeCardViewItem *aItem = (AddresseeCardViewItem*)(item); #endif //KAB_EMBEDDED if (aItem) { //kdDebug()<<"... even has a valid item:)"<<endl; emit executed(aItem->addressee().uid()); } } void KAddressBookCardView::addresseeSelected() { CardViewItem *item; AddresseeCardViewItem *aItem; bool found = false; for (item = mCardView->firstItem(); item && !found; 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 ) { emit selected(aItem->addressee().uid()); found = true; } } } if (!found) emit selected(QString::null); } #ifndef KAB_EMBEDDED #include "kaddressbookcardview.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/views/kaddressbookcardview.h b/kaddressbook/views/kaddressbookcardview.h index b8efb01..45a9781 100644 --- a/kaddressbook/views/kaddressbookcardview.h +++ b/kaddressbook/views/kaddressbookcardview.h @@ -1,117 +1,119 @@ #ifndef KADDRESSBOOKCARDVIEW_H #define KADDRESSBOOKCARDVIEW_H /* 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. */ #include <qstring.h> #ifndef KAB_EMBEDDED #include <kiconview.h> #else //KAB_EMBEDDED #include <klocale.h> #endif //KAB_EMBEDDED #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 *); + virtual void scrollUP(); + virtual void scrollDOWN(); 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 public: AddresseeCardView(QWidget *parent, const char *name = 0); ~AddresseeCardView(); signals: void startAddresseeDrag(); void addresseeDropped(QDropEvent *); protected: virtual void dragEnterEvent(QDragEnterEvent *); virtual void dropEvent(QDropEvent *); virtual void startDrag(); }; class CardViewFactory : public ViewFactory { public: KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new KAddressBookCardView( ab, parent, name ); } QString type() const { return "Card"; } QString description() const { return i18n( "Rolodex style cards represent contacts." ); } ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ) { return new ConfigureCardViewWidget( ab, parent, name ); } }; #endif diff --git a/kaddressbook/views/kaddressbookiconview.cpp b/kaddressbook/views/kaddressbookiconview.cpp index fdc0db9..f4c68b8 100644 --- a/kaddressbook/views/kaddressbookiconview.cpp +++ b/kaddressbook/views/kaddressbookiconview.cpp @@ -1,429 +1,446 @@ /* 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 KAB_EMBEDDED #include <qiconview.h> #include <qstringlist.h> #include <kabc/addressee.h> #include <kconfig.h> #include <kdebug.h> #include <kglobal.h> #include <kiconloader.h> #include <klocale.h> #else //KAB_EMBEDDED #endif //KAB_EMBEDDED #include <kabc/addressbook.h> #include "kabprefs.h" #include "viewmanager.h" #include "kaddressbookiconview.h" #include <qlayout.h> #include <qregexp.h> +#include <qapplication.h> #include <kglobal.h> /*US transfered to the headerfile class IconViewFactory : public ViewFactory { public: KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new KAddressBookIconView( ab, parent, name ); } QString type() const { return "Icon"; } QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } }; */ extern "C" { void *init_libkaddrbk_iconview() { return ( new IconViewFactory ); } } //////////////////////////////// // AddresseeIconView (internal class) #ifndef KAB_EMBEDDED AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) : KIconView(parent, name) #else //KAB_EMBEDDED AddresseeIconView::AddresseeIconView(QWidget *parent, const char *name) : QIconView(parent, 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, KABC::AddressBook *doc, const KABC::Addressee &a, QIconView *parent) : KIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) #else //KAB_EMBEDDED AddresseeIconViewItem(const KABC::Field::List &fields, KABC::AddressBook *doc, const KABC::Addressee &a, QIconView *parent) : QIconViewItem(parent), mFields( fields ), mDocument(doc), mAddressee(a) #endif //KAB_EMBEDDED { if ( mFields.isEmpty() ) { mFields = KABC::Field::defaultFields(); } refresh(); } const KABC::Addressee &addressee() const { return mAddressee; } void refresh() { // Update our addressee, since it may have changed elsewhere mAddressee = mDocument->findByUid(mAddressee.uid()); if (!mAddressee.isEmpty()) setText( mAddressee.givenName() + " " + mAddressee.familyName() ); QPixmap icon; QPixmap defaultIcon( KGlobal::iconLoader()->loadIcon( "vcard", KIcon::Desktop, 128 ) ); KABC::Picture pic = mAddressee.photo(); if ( pic.data().isNull() ) pic = mAddressee.logo(); if ( pic.isIntern() && !pic.data().isNull() ) { QImage img = pic.data(); #ifndef KAB_EMBEDDED if ( img.width() > img.height() ) icon = img.scaleWidth( 32 ); else icon = img.scaleHeight( 32 ); #else //KAB_EMBEDDED qDebug("AddresseeIconViewItem::refresh - scale here dependend of the displaysize and the right factor"); icon.convertFromImage(img.smoothScale(32, 32)); #endif //KAB_EMBEDDED } else icon = defaultIcon; setPixmap( icon ); } private: KABC::Field::List mFields; KABC::AddressBook *mDocument; KABC::Addressee mAddressee; }; /////////////////////////////// // KAddressBookView KAddressBookIconView::KAddressBookIconView( KABC::AddressBook *ab, QWidget *parent, const char *name) : KAddressBookView( ab, parent, name ) { // Init the GUI QVBoxLayout *layout = new QVBoxLayout(viewWidget()); mIconView = new AddresseeIconView(viewWidget(), "mIconView"); layout->addWidget(mIconView); // Connect up the signals //US method executed is part of KIconView //US connect(mIconView, SIGNAL(executed(QIconViewItem *)), //US this, SLOT(addresseeExecuted(QIconViewItem *))); connect(mIconView, SIGNAL(selectionChanged(QIconViewItem *)), this, SLOT(addresseeExecuted(QIconViewItem *))); connect(mIconView, SIGNAL(selectionChanged()), this, SLOT(addresseeSelected())); connect(mIconView, SIGNAL(addresseeDropped(QDropEvent*)), this, SIGNAL(dropped(QDropEvent*))); connect(mIconView, SIGNAL(startAddresseeDrag()), this, SIGNAL(startDrag())); } KAddressBookIconView::~KAddressBookIconView() { } +void KAddressBookIconView::scrollUP() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mIconView, ev ); +} +void KAddressBookIconView::scrollDOWN() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mIconView, ev ); +} 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 ); + if ( mIconView->firstItem() ) { + mIconView->setCurrentItem ( mIconView->firstItem() ); + mIconView->setSelected ( mIconView->firstItem() , true ); + } + else + emit selected(QString::null); } 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) { QIconViewItem *item; AddresseeIconViewItem *aItem; if ( uid.isNull() ) { // Rebuild the view mIconView->clear(); mIconList.clear(); KABC::Addressee::List addresseeList = addressees(); KABC::Addressee::List::Iterator iter; for ( iter = addresseeList.begin(); iter != addresseeList.end(); ++iter ) { if ( (*iter).uid().left(2) == "la" && (*iter).uid().left(19) == QString("last-syncAddressee-") ) continue; aItem = new AddresseeIconViewItem( fields(), addressBook(), *iter, mIconView ); } mIconView->arrangeItemsInGrid( true ); for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { #ifndef KAB_EMBEDDED AddresseeIconViewItem* aivi = dynamic_cast<AddresseeIconViewItem*>( item ); #else //KAB_EMBEDDED AddresseeIconViewItem* aivi = (AddresseeIconViewItem*)( item ); #endif //KAB_EMBEDDED mIconList.append( aivi ); } } else { // Try to find the one to refresh for ( item = mIconView->firstItem(); item; item = item->nextItem() ) { #ifndef KAB_EMBEDDED aItem = dynamic_cast<AddresseeIconViewItem*>(item); #else //KAB_EMBEDDED aItem = (AddresseeIconViewItem*)(item); #endif //KAB_EMBEDDED if ((aItem) && (aItem->addressee().uid() == uid)) { aItem->refresh(); mIconView->arrangeItemsInGrid( true ); return; } } refresh( QString::null ); } } void KAddressBookIconView::setSelected(QString uid, bool selected) { QIconViewItem *item; AddresseeIconViewItem *aItem; if (uid.isNull()) { mIconView->selectAll(selected); } else { bool found = false; for (item = mIconView->firstItem(); item && !found; item = item->nextItem()) { #ifndef KAB_EMBEDDED aItem = dynamic_cast<AddresseeIconViewItem*>(item); #else //KAB_EMBEDDED aItem = (AddresseeIconViewItem*)(item); #endif //KAB_EMBEDDED if ((aItem) && (aItem->addressee().uid() == uid)) { mIconView->setSelected(aItem, selected); mIconView->ensureItemVisible( aItem ); found = true; } } } } void KAddressBookIconView::addresseeExecuted(QIconViewItem *item) { #ifndef KAB_EMBEDDED AddresseeIconViewItem *aItem = dynamic_cast<AddresseeIconViewItem*>(item); #else //KAB_EMBEDDED AddresseeIconViewItem *aItem = (AddresseeIconViewItem*)(item); #endif //KAB_EMBEDDED if (aItem) { emit executed(aItem->addressee().uid()); } } void KAddressBookIconView::addresseeSelected() { QIconViewItem *item; AddresseeIconViewItem *aItem; bool found = false; for (item = mIconView->firstItem(); item && !found; 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) { emit selected(aItem->addressee().uid()); found = true; } } } if (!found) emit selected(QString::null); } #ifndef KAB_EMBEDDED #include "kaddressbookiconview.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/views/kaddressbookiconview.h b/kaddressbook/views/kaddressbookiconview.h index 963ee7c..acfcd71 100644 --- a/kaddressbook/views/kaddressbookiconview.h +++ b/kaddressbook/views/kaddressbookiconview.h @@ -1,131 +1,133 @@ /* 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 KADDRESSBOOKICONVIEW_H #define KADDRESSBOOKICONVIEW_H #include <qstring.h> #ifndef KAB_EMBEDDED #include <kiconview.h> #else //KAB_EMBEDDED #include <qiconview.h> #include <qptrlist.h> #include <klocale.h> #endif //KAB_EMBEDDED #include "kaddressbookview.h" 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); + virtual void scrollUP(); + virtual void scrollDOWN(); 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; }; #ifndef KAB_EMBEDDED //MOC_SKIP_BEGIN class AddresseeIconView : public KIconView //MOC_SKIP_END #else //KAB_EMBEDDED class AddresseeIconView : public QIconView #endif //KAB_EMBEDDED { Q_OBJECT public: AddresseeIconView(QWidget *parent, const char *name); ~AddresseeIconView(); signals: void addresseeDropped(QDropEvent *); void startAddresseeDrag(); protected: virtual QDragObject *dragObject(); protected slots: void itemDropped(QDropEvent *, const QValueList<QIconDragItem> &); }; class IconViewFactory : public ViewFactory { public: KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new KAddressBookIconView( ab, parent, name ); } QString type() const { return "Icon"; } QString description() const { return i18n( "Icons represent contacts. Very simple view." ); } }; /* extern "C" { void *init_libkaddrbk_iconview() { return ( new IconViewFactory ); } } */ #endif diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index fbfddba..2412170 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp @@ -1,445 +1,459 @@ // $Id$ #include <qvbox.h> #include <qlistbox.h> #include <qwidget.h> #include <qfile.h> #include <qimage.h> #include <qcombobox.h> #include <qapplication.h> #include <qdragobject.h> #include <qevent.h> #include <qurl.h> #include <qpixmap.h> #include <kabc/addressbook.h> #include <kapplication.h> #include <kconfig.h> #include <kcolorbutton.h> #include <kdebug.h> #include <kglobal.h> #include <kiconloader.h> #include <klineedit.h> #include <klocale.h> #include <kmessagebox.h> #include <kurl.h> #include <kurlrequester.h> //US#include "configuretableviewdialog.h" #include "contactlistview.h" #include "kabprefs.h" #include "undocmds.h" #include "viewmanager.h" #include <qlayout.h> #include <qheader.h> #include <qregexp.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::scrollUP() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mListView, ev ); +} +void KAddressBookTableView::scrollDOWN() +{ + QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mListView, ev ); +} 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::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()); break; } } } } // Sometimes the background pixmap gets messed up when we add lots // of items. mListView->repaint(); + if ( mListView->firstChild() ) { + mListView->setCurrentItem ( mListView->firstChild() ); + mListView->setSelected ( mListView->firstChild(), true ); + } + else 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 ) ); 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 ) ); #ifndef KAB_EMBEDDED c = KGlobalSettings::alternateBackgroundColor(); #else //KAB_EMBEDDED c = QColor(240, 240, 240); #endif //KAB_EMBEDDED c = config->readColorEntry ("AlternatingBackgroundColor", &c); mListView->setAlternateColor(c); //US mListView->viewport()->setPalette( p ); mListView->setPalette( p ); } else { // needed if turned off during a session. //US mListView->viewport()->setPalette( mListView->palette() ); mListView->setPalette( mListView->palette() ); } //custom fonts? QFont f( font() ); if ( config->readBoolEntry( "EnableCustomFonts", false ) ) { mListView->setFont( config->readFontEntry( "TextFont", &f) ); f.setBold( true ); //US mListView->setHeaderFont( config->readFontEntry( "HeaderFont", &f ) ); mListView->header()->setFont( config->readFontEntry( "HeaderFont", &f ) ); } else { mListView->setFont( f ); f.setBold( true ); //US mListView->setHeaderFont( f ); mListView->header()->setFont( f ); } // 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 ) { if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) continue; 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 ceItem = (ContactListViewItem*)(item); #endif //KAB_EMBEDDED if (ceItem != 0L) uidList << ceItem->addressee().uid(); } } if ( uidList.count() == 0 ) if ( mListView->currentItem() ) { ceItem = (ContactListViewItem*)(mListView->currentItem()) ; uidList << ceItem->addressee().uid(); } return uidList; } void KAddressBookTableView::setSelected(QString uid, bool selected) { QListViewItem *item; ContactListViewItem *ceItem; if (uid.isNull()) { mListView->selectAll(selected); } else { for(item = mListView->firstChild(); item; item = item->itemBelow()) { #ifndef KAB_EMBEDDED ceItem = dynamic_cast<ContactListViewItem*>(item); #else //KAB_EMBEDDED ceItem = (ContactListViewItem*)(item); #endif //KAB_EMBEDDED if ((ceItem != 0L) && (ceItem->addressee().uid() == uid)) { mListView->setSelected(item, selected); if (selected) mListView->ensureItemVisible(item); } } } } void KAddressBookTableView::addresseeSelected() { // We need to try to find the first selected item. This might not be the // last selected item, but when QListView is in multiselection mode, // there is no way to figure out which one was // selected last. QListViewItem *item; bool found =false; for (item = mListView->firstChild(); item && !found; item = item->nextSibling()) { if (item->isSelected()) { found = true; #ifndef KAB_EMBEDDED ContactListViewItem *ceItem = dynamic_cast<ContactListViewItem*>(item); #else //KAB_EMBEDDED ContactListViewItem *ceItem = (ContactListViewItem*)(item); #endif //KAB_EMBEDDED if ( ceItem ) emit selected(ceItem->addressee().uid()); } } if (!found) emit selected(QString::null); } void KAddressBookTableView::addresseeExecuted(QListViewItem *item) { if (item) { #ifndef KAB_EMBEDDED ContactListViewItem *ceItem = dynamic_cast<ContactListViewItem*>(item); #else //KAB_EMBEDDED ContactListViewItem *ceItem = (ContactListViewItem*)(item); #endif //KAB_EMBEDDED if (ceItem) { emit executed(ceItem->addressee().uid()); } } else { emit executed(QString::null); } } void KAddressBookTableView::addresseeDeleted() { emit deleteRequest(); } #ifndef KAB_EMBEDDED #include "kaddressbooktableview.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/views/kaddressbooktableview.h b/kaddressbook/views/kaddressbooktableview.h index ecfe7a1..865f8d5 100644 --- a/kaddressbook/views/kaddressbooktableview.h +++ b/kaddressbook/views/kaddressbooktableview.h @@ -1,115 +1,117 @@ #ifndef KADDRESSBOOKTABLEVIEW_H #define KADDRESSBOOKTABLEVIEW_H #ifndef KAB_EMBEDDED #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <qwidget.h> #include <qlistview.h> #include <qstring.h> #include <qdialog.h> #include <qtabdialog.h> #include <qstringlist.h> #include <qvaluelist.h> #include "undo.h" #else //KAB_EMBEDDED #include "views/configuretableviewdialog.h" #endif //KAB_EMBEDDED #include "klocale.h" #include "kaddressbookview.h" class QListViewItem; class QListBox; class QVBoxLayout; class KConfig; class ContactListViewItem; class ContactListView; 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 ); + virtual void scrollUP(); + virtual void scrollDOWN(); 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: KAddressBookView *view( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new KAddressBookTableView( ab, parent, name ); } QString type() const { return "Table"; } QString description() const { return i18n( "A listing of contacts in a table. Each cell of " "the table holds a field of the contact." ); } ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ) { return new ConfigureTableViewWidget( ab, parent, name ); } }; /*US extern "C" { void *init_libkaddrbk_tableview() { return ( new TableViewFactory ); } } */ #endif |