author | zautrix <zautrix> | 2005-01-17 18:22:47 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-17 18:22:47 (UTC) |
commit | 32479683283fc9f20d369ac9671ba0f8a33d3381 (patch) (side-by-side diff) | |
tree | 0d764657db915bd2d2bf2fb751800eb14515626b | |
parent | 11e05160cda1571a208edbabc71f6d94e394d829 (diff) | |
download | kdepimpi-32479683283fc9f20d369ac9671ba0f8a33d3381.zip kdepimpi-32479683283fc9f20d369ac9671ba0f8a33d3381.tar.gz kdepimpi-32479683283fc9f20d369ac9671ba0f8a33d3381.tar.bz2 |
fast set formatted name
-rw-r--r-- | kaddressbook/imagewidget.cpp | 25 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 52 | ||||
-rw-r--r-- | kaddressbook/xxportselectdialog.cpp | 48 | ||||
-rw-r--r-- | kaddressbook/xxportselectdialog.h | 1 |
4 files changed, 87 insertions, 39 deletions
diff --git a/kaddressbook/imagewidget.cpp b/kaddressbook/imagewidget.cpp index 9ee4eac..1e9743c 100644 --- a/kaddressbook/imagewidget.cpp +++ b/kaddressbook/imagewidget.cpp @@ -8,156 +8,155 @@ (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 <kabc/picture.h> #ifndef KAB_EMBEDDED #include <kaccelmanager.h> #include <kio/netaccess.h> #include <kimageio.h> #endif //KAB_EMBEDDED #include <kdebug.h> #include <kdialog.h> #include <kiconloader.h> #include <klocale.h> #include <kurlrequester.h> #include <kurl.h> #include <qcheckbox.h> #include <qgroupbox.h> #include <qlabel.h> #include <qlayout.h> #include <qpixmap.h> #include <qpushbutton.h> #include <qapplication.h> #include "imagewidget.h" ImageWidget::ImageWidget( QWidget *parent, const char *name ) : QWidget( parent, name ) { QGridLayout *topLayout = new QGridLayout( this, 2, 1, KDialog::marginHint(), KDialog::spacingHint() ); QGroupBox *photoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Photo" ), this ); - QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 4, 2, + QGridLayout *boxLayout = new QGridLayout( photoBox->layout(), 3, 2, KDialog::spacingHint() ); boxLayout->setRowStretch( 2, 1 ); mPhotoLabel = new QLabel( photoBox ); int fac = 9; if ( QApplication::desktop()->width() > 320 ) fac = 6; mPhotoLabel->setFixedSize( 50*9/fac, 70*9/fac ); mPhotoLabel->setScaledContents( true ); mPhotoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); boxLayout->addMultiCellWidget( mPhotoLabel, 0, 3, 0, 0 ); mPhotoUrl = new KURLRequester( photoBox ); #ifndef KAB_EMBEDDED mPhotoUrl->setFilter( KImageIO::pattern() ); #else //KAB_EMBEDDED //US qDebug("ImageWidget::ImageWidget KImageIO not defined. Does this harm ???"); #endif //KAB_EMBEDDED boxLayout->addWidget( mPhotoUrl, 0, 1 ); - - mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), photoBox ); + QHBox *hb1 = new QHBox ( photoBox ); + mUsePhotoUrl = new QCheckBox( i18n( "Store as URL" ), hb1 ); mUsePhotoUrl->setEnabled( false ); - boxLayout->addWidget( mUsePhotoUrl, 1, 1 ); + boxLayout->addWidget( hb1, 1, 1 ); - QPushButton * pb = new QPushButton( i18n( "Remove" ), photoBox ); + QPushButton * pb = new QPushButton( i18n( "Remove" ), hb1 ); connect( pb, SIGNAL( clicked() ),this, SLOT( removePhoto() ) ); - boxLayout->addWidget( pb, 2, 1 ); - boxLayout->addWidget( new QLabel( photoBox ), 3, 1 ); + boxLayout->addWidget( new QLabel( photoBox ), 2, 1 ); topLayout->addWidget( photoBox, 0, 0 ); QGroupBox *logoBox = new QGroupBox( 0, Qt::Vertical, i18n( "Logo" ), this ); - boxLayout = new QGridLayout( logoBox->layout(), 4, 2, KDialog::spacingHint() ); + boxLayout = new QGridLayout( logoBox->layout(), 3, 2, KDialog::spacingHint() ); boxLayout->setRowStretch( 2, 1 ); mLogoLabel = new QLabel( logoBox ); mLogoLabel->setFixedSize( 50*9/fac, 70*9/fac ); mLogoLabel->setScaledContents( true ); mLogoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); boxLayout->addMultiCellWidget( mLogoLabel, 0, 3, 0, 0 ); mLogoUrl = new KURLRequester( logoBox ); #ifndef KAB_EMBEDDED mLogoUrl->setFilter( KImageIO::pattern() ); #else //KAB_EMBEDDED //US qDebug("ImageWidget::ImageWidget KImageIO not defined 2"); #endif //KAB_EMBEDDED boxLayout->addWidget( mLogoUrl, 0, 1 ); - mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), logoBox ); + QHBox *hb2 = new QHBox ( logoBox ); + mUseLogoUrl = new QCheckBox( i18n( "Store as URL" ), hb2 ); mUseLogoUrl->setEnabled( false ); - boxLayout->addWidget( mUseLogoUrl, 1, 1 ); + boxLayout->addWidget( hb2, 1, 1 ); - pb = new QPushButton( i18n( "Remove" ), logoBox ); + pb = new QPushButton( i18n( "Remove" ), hb2 ); connect( pb, SIGNAL( clicked() ),this, SLOT( removeLogo() ) ); - boxLayout->addWidget( pb, 2, 1 ); - boxLayout->addWidget( new QLabel( logoBox ), 3, 1 ); + boxLayout->addWidget( new QLabel( logoBox ), 2, 1 ); topLayout->addWidget( logoBox, 1, 0 ); connect( mPhotoUrl, SIGNAL( textChanged( const QString& ) ), SIGNAL( changed() ) ); connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), SLOT( loadPhoto() ) ); connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), SIGNAL( changed() ) ); connect( mPhotoUrl, SIGNAL( urlSelected( const QString& ) ), SLOT( updateGUI() ) ); connect( mUsePhotoUrl, SIGNAL( toggled( bool ) ), SIGNAL( changed() ) ); connect( mLogoUrl, SIGNAL( textChanged( const QString& ) ), SIGNAL( changed() ) ); connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), SLOT( loadLogo() ) ); connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), SIGNAL( changed() ) ); connect( mLogoUrl, SIGNAL( urlSelected( const QString& ) ), SLOT( updateGUI() ) ); connect( mUseLogoUrl, SIGNAL( toggled( bool ) ), SIGNAL( changed() ) ); #ifndef KAB_EMBEDDED KAcceleratorManager::manage( this ); #endif //KAB_EMBEDDED } ImageWidget::~ImageWidget() { } void ImageWidget::setPhoto( const KABC::Picture &photo ) { bool blocked = signalsBlocked(); blockSignals( true ); if ( photo.isIntern() ) { //US //US mPhotoLabel->setPixmap( photo.data() ); if (photo.data().isNull() != true) { QPixmap pm; pm.convertFromImage(photo.data()); mPhotoLabel->setPixmap( pm ); diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 9526f23..d393660 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -180,97 +180,98 @@ class KABCatPrefs : public QDialog QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("New categories not in list:"), this ); lay->addWidget( format ); format->setExclusive ( true ) ; addCatBut = new QRadioButton(i18n("Add to category list"), format ); new QRadioButton(i18n("Remove from addressees"), format ); addCatBut->setChecked( true ); QPushButton * ok = new QPushButton( i18n("OK"), this ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); resize( 200, 200 ); } bool addCat() { return addCatBut->isChecked(); } private: QRadioButton* addCatBut; }; class KABFormatPrefs : public QDialog { public: KABFormatPrefs( QWidget *parent=0, const char *name=0 ) : QDialog( parent, name, true ) { setCaption( i18n("Set formatted name") ); QVBoxLayout* lay = new QVBoxLayout( this ); lay->setSpacing( 3 ); lay->setMargin( 3 ); QLabel * lab = new QLabel( i18n("You can set the formatted name\nfor a list of contacts in one go."), this ); lay->addWidget( lab ); QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Set formatted name to:"), this ); lay->addWidget( format ); format->setExclusive ( true ) ; simple = new QRadioButton(i18n("Simple: James Bond"), format ); full = new QRadioButton(i18n("Full: Mr. James 007 Bond I"), format ); reverse = new QRadioButton(i18n("Reverse: Bond, James"), format ); company = new QRadioButton(i18n("Organization: MI6"), format ); simple->setChecked( true ); setCompany = new QCheckBox(i18n("Set formatted name to\norganization, if name empty"), this); lay->addWidget( setCompany ); QPushButton * ok = new QPushButton( i18n("Select contact list"), this ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); - resize( 200, 200 ); + //resize( 200, 200 ); + } public: QRadioButton* simple, *full, *reverse, *company; QCheckBox* setCompany; }; class KAex2phonePrefs : public QDialog { public: KAex2phonePrefs( QWidget *parent=0, const char *name=0 ) : QDialog( parent, name, true ) { setCaption( i18n("Export to phone options") ); QVBoxLayout* lay = new QVBoxLayout( this ); lay->setSpacing( 3 ); lay->setMargin( 3 ); QLabel *lab; lay->addWidget(lab = new QLabel( i18n("Please read Help-Sync Howto\nto know what settings to use."), this ) ); lab->setAlignment (AlignHCenter ); QHBox* temphb; temphb = new QHBox( this ); new QLabel( i18n("I/O device: "), temphb ); mPhoneDevice = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); new QLabel( i18n("Connection: "), temphb ); mPhoneConnection = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); new QLabel( i18n("Model(opt.): "), temphb ); mPhoneModel = new QLineEdit( temphb); lay->addWidget( temphb ); // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); // lay->addWidget( mWriteToSim ); lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); lab->setAlignment (AlignHCenter); QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); resize( 220, 240 ); } @@ -1328,97 +1329,98 @@ void KABCore::editContact( const QString &uid ) if ( mExtensionManager->isQuickEditVisible() ) return; // First, locate the contact entry QString localUID = uid; if ( localUID.isNull() ) { QStringList uidList = mViewManager->selectedUids(); if ( uidList.count() > 0 ) localUID = *( uidList.at( 0 ) ); } KABC::Addressee addr = mAddressBook->findByUid( localUID ); if ( !addr.isEmpty() ) { mEditorDialog->setAddressee( addr ); KApplication::execDialog ( mEditorDialog ); } } /** Shows or edits the detail view for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void KABCore::executeContact( const QString &uid /*US = QString::null*/ ) { if ( mMultipleViewsAtOnce ) { editContact( uid ); } else { setDetailsVisible( true ); mActionDetails->setChecked(true); } } void KABCore::save() { if (syncManager->blockSave()) return; if ( !mModified ) return; syncManager->setBlockSave(true); QString text = i18n( "There was an error while attempting to save\n the " "address book. Please check that some \nother application is " "not using it. " ); - message(i18n("Saving addressbook ... ")); + message(i18n("Saving ... please wait! ")); + qApp->processEvents(); #ifndef KAB_EMBEDDED KABC::StdAddressBook *b = dynamic_cast<KABC::StdAddressBook*>( mAddressBook ); if ( !b || !b->save() ) { KMessageBox::error( this, text, i18n( "Unable to Save" ) ); } #else //KAB_EMBEDDED KABC::StdAddressBook *b = (KABC::StdAddressBook*)( mAddressBook ); if ( !b || !b->save() ) { QMessageBox::critical( this, i18n( "Unable to Save" ), text, i18n("Ok")); } #endif //KAB_EMBEDDED message(i18n("Addressbook saved!")); setModified( false ); syncManager->setBlockSave(false); } void KABCore::undo() { UndoStack::instance()->undo(); // Refresh the view mViewManager->refreshView(); } void KABCore::redo() { RedoStack::instance()->redo(); // Refresh the view mViewManager->refreshView(); } void KABCore::setJumpButtonBarVisible( bool visible ) { if (mMultipleViewsAtOnce) { if ( visible ) mJumpButtonBar->show(); else mJumpButtonBar->hide(); } else { // show the jumpbar only if "the details are hidden" == "viewmanager are shown" if (mViewManager->isVisible()) { @@ -2318,121 +2320,127 @@ void KABCore::manageCategories( ) QStringList catList = KABPrefs::instance()->mCustomCategories; QStringList catIncList; QStringList newCatList; KABC::AddressBook::Iterator it; for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { QStringList catIncList = (*it).categories(); int i; if ( catIncList.count() ) { newCatList.clear(); for( i = 0; i< catIncList.count(); ++i ) { if ( catList.contains (catIncList[i])) { newCatList.append( catIncList[i] ); } } newCatList.sort(); (*it).setCategories( newCatList ); mAddressBook->insertAddressee( (*it) ); } } setModified( true ); mViewManager->refreshView(); message( i18n("Removing categories done!")); } delete cp; } 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; XXPortSelectDialog dlg( this, false, this ); if ( dlg.exec() ) list = dlg.contacts(); else return; KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( (*it).removeVoice() ) addrModified((*it), false ); } } void KABCore::setFormattedName() { KABFormatPrefs setpref; if ( !setpref.exec() ) { return; } - KABC::Addressee::List list; XXPortSelectDialog dlg( this, false, this ); - if ( dlg.exec() ) - list = dlg.contacts(); - else + if ( !dlg.exec() ) return; - KABC::Addressee::List::Iterator it; - for ( it = list.begin(); it != list.end(); ++it ) { - QString fName; - if ( setpref.simple->isChecked() ) - fName = NameEditDialog::formattedName( (*it), NameEditDialog::SimpleName ); - else if ( setpref.full->isChecked() ) - fName = NameEditDialog::formattedName( (*it), NameEditDialog::FullName ); - else if ( setpref.reverse->isChecked() ) - fName = NameEditDialog::formattedName( (*it), NameEditDialog::ReverseName ); - else - fName = (*it).organization(); - if ( setpref.setCompany->isChecked() ) - if ( fName.isEmpty() || fName =="," ) + mAddressBook->setUntagged(); + dlg.tagSelected(); + int count = 0; + KABC::AddressBook::Iterator it; + for ( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { + if ( (*it).tagged() ) { + message(i18n("Changing contact #%1").arg( ++count ) ); + qApp->processEvents(); + QString fName; + if ( setpref.simple->isChecked() ) + fName = NameEditDialog::formattedName( (*it), NameEditDialog::SimpleName ); + else if ( setpref.full->isChecked() ) + fName = NameEditDialog::formattedName( (*it), NameEditDialog::FullName ); + else if ( setpref.reverse->isChecked() ) + fName = NameEditDialog::formattedName( (*it), NameEditDialog::ReverseName ); + else fName = (*it).organization(); - (*it).setFormattedName( fName ); - addrModified((*it),false ); + if ( setpref.setCompany->isChecked() ) + if ( fName.isEmpty() || fName =="," ) + fName = (*it).organization(); + (*it).setFormattedName( fName ); + } } + message(i18n("Refreshing view...") ); + mViewManager->refreshView( "" ); Addressee add; mDetails->setAddressee( add ); + message(i18n("Setting formatted name completed!") ); } void KABCore::clipboardDataChanged() { if ( mReadWrite ) mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); } void KABCore::updateActionMenu() { UndoStack *undo = UndoStack::instance(); RedoStack *redo = RedoStack::instance(); if ( undo->isEmpty() ) mActionUndo->setText( i18n( "Undo" ) ); else mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); mActionUndo->setEnabled( !undo->isEmpty() ); if ( !redo->top() ) mActionRedo->setText( i18n( "Redo" ) ); else mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); mActionRedo->setEnabled( !redo->isEmpty() ); } void KABCore::configureKeyBindings() { #ifndef KAB_EMBEDDED KKeyDialog::configure( actionCollection(), true ); #else //KAB_EMBEDDED qDebug("KABCore::configureKeyBindings() not implemented"); #endif //KAB_EMBEDDED } #ifdef KAB_EMBEDDED void KABCore::configureResources() { KRES::KCMKResources dlg( this, "" , 0 ); if ( !dlg.exec() ) return; KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); } @@ -3161,97 +3169,97 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode) return syncOK; } void KABCore::removeSyncInfo( QString syncProfile) { qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); mAddressBook->removeSyncInfo( syncProfile ); setModified(); } //this is a overwritten callbackmethods from the syncinterface bool KABCore::syncExternal(KSyncManager* manager, QString resource) { if ( resource == "phone" ) return syncPhone(); disableBR( true ); if ( manager != syncManager ) qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal( resource,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( false ); abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); } } else message( i18n("Sync cancelled or failed.") ); setModified(); } abLocal.removeResources(); if ( syncOK ) mViewManager->refreshView(); disableBR( false ); return syncOK; } void KABCore::message( QString m ) { topLevelWidget()->setCaption( m ); - mMessageTimer->start( 15000, true ); + mMessageTimer->start( 20000, true ); } bool KABCore::syncPhone() { QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); QString fileName = getPhoneFile(); if ( !PhoneAccess::readFromPhone( fileName) ) { message(i18n("Phone access failed!")); return false; } AddressBook abLocal( fileName,"syncContact"); bool syncOK = false; { abLocal.importFromFile( fileName ); qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preparePhoneSync( mCurrentSyncDevice, true ); abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( true ); abLocal.saveABphone( fileName ); abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); } } setModified(); } abLocal.removeResources(); if ( syncOK ) mViewManager->refreshView(); return syncOK; } void KABCore::getFile( bool success ) { if ( ! success ) { message( i18n("Error receiving file. Nothing changed!") ); return; } int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); if ( count ) setModified( true ); message( i18n("Pi-Sync successful!") ); mViewManager->refreshView(); } void KABCore::syncFileRequest() { diff --git a/kaddressbook/xxportselectdialog.cpp b/kaddressbook/xxportselectdialog.cpp index 6282453..e7bc8c0 100644 --- a/kaddressbook/xxportselectdialog.cpp +++ b/kaddressbook/xxportselectdialog.cpp @@ -9,158 +9,198 @@ (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$ */ #include <kabc/addressbook.h> #include <kapplication.h> #include <kcombobox.h> #include <klocale.h> #include <kglobal.h> #include <qapplication.h> #include <qbuttongroup.h> #include <qcombobox.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qlistview.h> #include <qpushbutton.h> #include <qradiobutton.h> #include <qstringlist.h> #include <qwhatsthis.h> #include "kabcore.h" #include "kabprefs.h" #include "xxportselectdialog.h" XXPortSelectDialog::XXPortSelectDialog( KABCore *core, bool sort, QWidget* parent, const char* name ) - : KDialogBase( Plain, i18n( "Choose which contacts to select" ), Help | Ok | Cancel, + : KDialogBase( Plain, i18n( "Choose contact selection" ), Help | Ok | Cancel, Ok, parent, name, true, true ), mCore( core ), mUseSorting( sort ) { initGUI(); connect( mFiltersCombo, SIGNAL( activated( int ) ), SLOT( filterChanged( int ) ) ); connect( mCategoriesView, SIGNAL( clicked( QListViewItem* ) ), SLOT( categoryClicked( QListViewItem* ) ) ); // setup filters #ifndef KAB_EMBEDDED mFilters = Filter::restore( kapp->config(), "Filter" ); Filter::List::iterator filterIt; #else //KAB_EMBEDDED mFilters = Filter::restore( KGlobal::config(), "Filter" ); Filter::List::Iterator filterIt; #endif //KAB_EMBEDDED QStringList filters; for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt ) filters.append( (*filterIt).name() ); mFiltersCombo->insertStringList( filters ); mUseFilters->setEnabled( filters.count() > 0 ); // setup categories QStringList categories = KABPrefs::instance()->mCustomCategories; QStringList::Iterator it; for ( it = categories.begin(); it != categories.end(); ++it ) new QCheckListItem( mCategoriesView, *it, QCheckListItem::CheckBox ); mUseCategories->setEnabled( categories.count() > 0 ); int count = mCore->selectedUIDs().count(); mUseSelection->setEnabled( count != 0 ); mUseSelection->setChecked( count > 1 ); mSortTypeCombo->insertItem( i18n( "Ascending" ) ); mSortTypeCombo->insertItem( i18n( "Descending" ) ); mFields = mCore->addressBook()->fields( KABC::Field::All ); KABC::Field::List::Iterator fieldIt; for ( fieldIt = mFields.begin(); fieldIt != mFields.end(); ++fieldIt ) mFieldCombo->insertItem( (*fieldIt)->label() ); } QStringList XXPortSelectDialog::uids() { QStringList uidlist; KABC::AddresseeList list = contacts(); KABC::Addressee::List::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) uidlist.append((*it).uid()); return uidlist; } +void XXPortSelectDialog::tagSelected() +{ + if ( mUseSelection->isChecked() ) { + + QStringList selection = mCore->selectedUIDs(); + KABC::AddressBook::Iterator it; + for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) { + if ( selection.findIndex((*it).uid()) >= 0 ) + (*it).setTagged( true ); + } + } else if ( mUseFilters->isChecked() ) { + // find contacts that can pass selected filter + Filter::List::Iterator filterIt; + for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt ) + if ( (*filterIt).name() == mFiltersCombo->currentText() ) + break; + KABC::AddressBook::Iterator it; + for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) { + if ( (*filterIt).filterAddressee( *it ) ) + (*it).setTagged( true ); + } + } else if ( mUseCategories->isChecked() ) { + QStringList categorieList = categories(); + KABC::AddressBook::Iterator it; + for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) { + QStringList tmp( (*it).categories() ); + QStringList::Iterator tmpIt; + for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt ) + if ( categorieList.contains( *tmpIt ) ) { + (*it).setTagged( true ); + break; + } + } + } else { + // create a string list of all entries: + KABC::AddressBook::Iterator it; + for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) + (*it).setTagged( true ); + } +} KABC::AddresseeList XXPortSelectDialog::contacts() { - QStringList selection = mCore->selectedUIDs(); KABC::AddresseeList list; if ( mUseSelection->isChecked() ) { QStringList::Iterator it; + QStringList selection = mCore->selectedUIDs(); for ( it = selection.begin(); it != selection.end(); ++it ) { KABC::Addressee addr = mCore->addressBook()->findByUid( *it ); if ( !addr.isEmpty() ) list.append( addr ); } } else if ( mUseFilters->isChecked() ) { // find contacts that can pass selected filter Filter::List::Iterator filterIt; for ( filterIt = mFilters.begin(); filterIt != mFilters.end(); ++filterIt ) if ( (*filterIt).name() == mFiltersCombo->currentText() ) break; KABC::AddressBook::Iterator it; for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) { if ( (*filterIt).filterAddressee( *it ) ) list.append( *it ); } } else if ( mUseCategories->isChecked() ) { QStringList categorieList = categories(); KABC::AddressBook::Iterator it; for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) { QStringList tmp( (*it).categories() ); QStringList::Iterator tmpIt; for ( tmpIt = tmp.begin(); tmpIt != tmp.end(); ++tmpIt ) if ( categorieList.contains( *tmpIt ) ) { list.append( *it ); break; } } } else { // create a string list of all entries: KABC::AddressBook::Iterator it; for ( it = mCore->addressBook()->begin(); it != mCore->addressBook()->end(); ++it ) list.append( *it ); } if ( mUseSorting ) { list.setReverseSorting( mSortTypeCombo->currentItem() == 1 ); uint pos = mFieldCombo->currentItem(); if ( pos < mFields.count() ) list.sortByField( mFields[ pos ] ); } return list; } QStringList XXPortSelectDialog::categories() const { @@ -201,94 +241,94 @@ void XXPortSelectDialog::slotHelp() void XXPortSelectDialog::initGUI() { QFrame *page = plainPage(); QVBoxLayout *topLayout = new QVBoxLayout( page, KDialog::marginHint(), KDialog::spacingHint() ); QLabel *label = new QLabel( i18n( "Which contacts do you want to select?" ), page ); topLayout->addWidget( label ); mButtonGroup = new QButtonGroup( i18n( "Contact Selection" ), page ); mButtonGroup->setColumnLayout( 0, Qt::Vertical ); mButtonGroup->layout()->setSpacing( KDialog::spacingHint() ); mButtonGroup->layout()->setMargin( KDialog::marginHint() ); QGridLayout *groupLayout = new QGridLayout( mButtonGroup->layout() ); groupLayout->setAlignment( Qt::AlignTop ); mUseWholeBook = new QRadioButton( i18n( "&All" ), mButtonGroup ); mUseWholeBook->setChecked( true ); QWhatsThis::add( mUseWholeBook, i18n( "Select the entire address book" ) ); groupLayout->addWidget( mUseWholeBook, 0, 0 ); mUseSelection = new QRadioButton( i18n( "&Selected" ), mButtonGroup ); QWhatsThis::add( mUseSelection, i18n( "Only contacts selected in KAddressBook.\n" "This option is disabled if no contacts are selected." ) ); groupLayout->addWidget( mUseSelection, 1, 0 ); mUseFilters = new QRadioButton( i18n( "By matching &filter" ), mButtonGroup ); QWhatsThis::add( mUseFilters, i18n( "Only contacts matching the selected filter.\n" "This option is disabled if you haven't defined any filters" ) ); groupLayout->addWidget( mUseFilters, 2, 0 ); mUseCategories = new QRadioButton( i18n( "By Cate&gories" ), mButtonGroup ); QWhatsThis::add( mUseCategories, i18n( "Only contacts who are members of a category that is checked on the list to the left.\n" "This option is disabled if you have no categories." ) ); groupLayout->addWidget( mUseCategories, 3, 0 ); mFiltersCombo = new QComboBox( false, mButtonGroup ); QWhatsThis::add( mFiltersCombo, i18n( "Select a filter to decide which contacts to select." ) ); groupLayout->addWidget( mFiltersCombo, 2, 1 ); mCategoriesView = new QListView( mButtonGroup ); mCategoriesView->addColumn( "" ); mCategoriesView->header()->hide(); QWhatsThis::add( mCategoriesView, i18n( "Check the categories whose members you want to select." ) ); groupLayout->addWidget( mCategoriesView, 3, 1 ); - // if (QApplication::desktop()->height() == 480 ) - // mCategoriesView->setMaximumHeight( 240 ); + if (QApplication::desktop()->height() == 480 ) + mCategoriesView->setMaximumHeight( 240 ); topLayout->addWidget( mButtonGroup ); QButtonGroup *sortingGroup = new QButtonGroup( i18n( "Sorting" ), page ); sortingGroup->setColumnLayout( 0, Qt::Vertical ); QGridLayout *sortLayout = new QGridLayout( sortingGroup->layout(), 2, 2, KDialog::spacingHint() ); sortLayout->setAlignment( Qt::AlignTop ); label = new QLabel( i18n( "Criterion:" ), sortingGroup ); sortLayout->addWidget( label, 0, 0 ); #ifndef KAB_EMBEDDED mFieldCombo = new KComboBox( false, sortingGroup ); #else //KAB_EMBEDDED //US Combobox is not editable anyway mFieldCombo = new KComboBox( sortingGroup ); #endif //KAB_EMBEDDED sortLayout->addWidget( mFieldCombo, 0, 1 ); label = new QLabel( i18n( "Order:" ), sortingGroup ); sortLayout->addWidget( label, 1, 0 ); #ifndef KAB_EMBEDDED mSortTypeCombo = new KComboBox( false, sortingGroup ); #else //KAB_EMBEDDED //US Combobox is not editable anyway mSortTypeCombo = new KComboBox( sortingGroup ); #endif //KAB_EMBEDDED sortLayout->addWidget( mSortTypeCombo, 1, 1 ); topLayout->addWidget( sortingGroup ); if ( !mUseSorting ) sortingGroup->hide(); #ifndef DESKTOP_VERSION hideButtons(); #endif } #ifndef KAB_EMBEDDED #include "xxportselectdialog.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/xxportselectdialog.h b/kaddressbook/xxportselectdialog.h index 3bb696f..28b1fef 100644 --- a/kaddressbook/xxportselectdialog.h +++ b/kaddressbook/xxportselectdialog.h @@ -3,80 +3,81 @@ Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk> 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 XXPORTSELECTDIALOG_H #define XXPORTSELECTDIALOG_H #include <kabc/addresseelist.h> #include <kabc/field.h> #include <kdialogbase.h> #include "filter.h" class QButtonGroup; class QComboBox; class QListView; class QListViewItem; class QRadioButton; class KABCore; class KComboBox; class XXPortSelectDialog : public KDialogBase { Q_OBJECT public: XXPortSelectDialog( KABCore *core, bool sort, QWidget* parent, const char* name = 0 ); KABC::AddresseeList contacts(); + void tagSelected(); QStringList uids(); private slots: void filterChanged( int ); void categoryClicked( QListViewItem * i ); protected slots: void slotHelp(); private: void initGUI(); QStringList categories() const; QButtonGroup* mButtonGroup; QRadioButton* mUseCategories; QRadioButton* mUseFilters; QRadioButton* mUseWholeBook; QRadioButton* mUseSelection; QComboBox* mFiltersCombo; QListView* mCategoriesView; KComboBox *mFieldCombo; KComboBox *mSortTypeCombo; KABCore *mCore; KABC::AddresseeList mAddresseeList; Filter::List mFilters; KABC::Field::List mFields; bool mUseSorting; }; #endif |