author | zautrix <zautrix> | 2005-03-25 00:08:08 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-25 00:08:08 (UTC) |
commit | 7c2e130ddd194f1c4b5365af6999a27c08232f4b (patch) (side-by-side diff) | |
tree | 75665681327ee49d7650f4d840b5c8c772180fb4 /kaddressbook | |
parent | 5cf054b82738d65f9b0a34ccb51c993ee4a0189f (diff) | |
download | kdepimpi-7c2e130ddd194f1c4b5365af6999a27c08232f4b.zip kdepimpi-7c2e130ddd194f1c4b5365af6999a27c08232f4b.tar.gz kdepimpi-7c2e130ddd194f1c4b5365af6999a27c08232f4b.tar.bz2 |
fixes
-rw-r--r-- | kaddressbook/filtereditdialog.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/kaddressbook/filtereditdialog.cpp b/kaddressbook/filtereditdialog.cpp index 1194406..ef9b979 100644 --- a/kaddressbook/filtereditdialog.cpp +++ b/kaddressbook/filtereditdialog.cpp @@ -1,315 +1,315 @@ /* 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$ */ #include <qbuttongroup.h> #include <qhbox.h> #include <qlabel.h> #include <qlayout.h> #include <qpushbutton.h> #include <qradiobutton.h> #include <qcheckbox.h> #include <qregexp.h> #include <qstring.h> #include <qtoolbutton.h> #include <qtooltip.h> #include <qwidget.h> #include <kapplication.h> #include <kbuttonbox.h> #include <kdebug.h> #include <kiconloader.h> #include <klineedit.h> #include <klistbox.h> #include <klistview.h> #include <klocale.h> #include <kglobal.h> #include "kabprefs.h" #include "filtereditdialog.h" FilterEditDialog::FilterEditDialog( QWidget *parent, const char *name ) : KDialogBase( Plain, i18n( "Edit Address Book Filter" ), Help | Ok | Cancel, Ok, parent, name, /*US false*/ true, true ) { initGUI(); QStringList cats = KABPrefs::instance()->mCustomCategories; QStringList::Iterator iter; for ( iter = cats.begin(); iter != cats.end(); ++iter ) mCategoriesView->insertItem( new QCheckListItem( mCategoriesView, (*iter), QCheckListItem::CheckBox ) ); filterNameTextChanged( mNameEdit->text() ); } FilterEditDialog::~FilterEditDialog() { } void FilterEditDialog::setFilter( const Filter &filter ) { mNameEdit->setText( filter.name() ); QStringList categories = filter.categories(); QListViewItem *item = mCategoriesView->firstChild(); while ( item != 0 ) { if ( categories.contains( item->text( 0 ) ) ) { QCheckListItem *checkItem = static_cast<QCheckListItem*>( item ); checkItem->setOn( true ); } item = item->nextSibling(); } if ( filter.matchRule() == Filter::Matching ) mMatchRuleGroup->setButton( 0 ); else mMatchRuleGroup->setButton( 1 ); int c = filter.criteria() ; mPublic->setChecked(c &Filter::ShowPublic); mPrivate->setChecked(c & Filter::ShowPrivate); mConfidential->setChecked(c & Filter::ShowConfidential); } Filter FilterEditDialog::filter() { Filter filter; filter.setName( mNameEdit->text() ); QStringList categories; QListViewItem *item = mCategoriesView->firstChild(); while ( item != 0 ) { QCheckListItem *checkItem = static_cast<QCheckListItem*>( item ); if ( checkItem->isOn() ) categories.append( item->text( 0 ) ); item = item->nextSibling(); } filter.setCategories( categories ); if ( mMatchRuleGroup->find( 0 )->isOn() ) filter.setMatchRule( Filter::Matching ); else filter.setMatchRule( Filter::NotMatching ); int c = 0; if (mPublic->isChecked()) c |= Filter::ShowPublic; if (mPrivate->isChecked()) c |= Filter::ShowPrivate; if (mConfidential->isChecked()) c |= Filter::ShowConfidential; filter.setCriteria( c ) ; return filter; } void FilterEditDialog::initGUI() { #ifndef KAB_EMBEDDED resize( 490, 300 ); #else //KAB_EMBEDDED resize( KMIN(KGlobal::getDesktopWidth()-10, 490), KMIN(KGlobal::getDesktopHeight()-50, 300)); #endif //KAB_EMBEDDED QWidget *page = plainPage(); QLabel *label; QGridLayout *topLayout = new QGridLayout( page, 3, 2, 0, spacingHint() ); label = new QLabel( i18n( "Name" ), page ); mNameEdit = new KLineEdit( page ); mNameEdit->setFocus(); topLayout->addWidget( label, 0, 0 ); topLayout->addWidget( mNameEdit, 0, 1 ); connect( mNameEdit, SIGNAL( textChanged( const QString& ) ), SLOT( filterNameTextChanged( const QString&) ) ); mCategoriesView = new KListView( page ); mCategoriesView->addColumn( i18n( "Categories" ) ); topLayout->addMultiCellWidget( mCategoriesView, 1, 1, 0, 1 ); mMatchRuleGroup = new QHButtonGroup( i18n( "Category rule" ), page ); mMatchRuleGroup->setExclusive( true ); QRadioButton *radio = new QRadioButton( i18n( "Include categories" ), mMatchRuleGroup ); - radio->setChecked( true ); //mMatchRuleGroup->insert( radio ); radio = new QRadioButton( i18n( "Exclude categories" ), mMatchRuleGroup ); + radio->setChecked( true ); //mMatchRuleGroup->insert( radio ); topLayout->addMultiCellWidget( mMatchRuleGroup, 2, 2, 0, 1 ); QHButtonGroup * mMatchPPCGroup = new QHButtonGroup(i18n( "Include contacts, that are:" ), page ); mPublic = new QCheckBox( i18n( "public" ), mMatchPPCGroup ); mPrivate = new QCheckBox( i18n( "private" ), mMatchPPCGroup ); mConfidential = new QCheckBox( i18n( "confidential" ), mMatchPPCGroup ); mPublic->setChecked( true ); mPrivate->setChecked( true ); mConfidential->setChecked( true ); topLayout->addMultiCellWidget( mMatchPPCGroup, 3, 3, 0, 1 ); } void FilterEditDialog::filterNameTextChanged( const QString &text ) { enableButtonOK( !text.isEmpty() ); } void FilterEditDialog::slotHelp() { #ifndef KAB_EMBEDDED kapp->invokeHelp( "using-filters" ); #endif //KAB_EMBEDDED } FilterDialog::FilterDialog( QWidget *parent, const char *name ) : KDialogBase( Plain, i18n( "Edit Address Book Filters" ), Ok | Cancel, Ok, parent, name, /*US false*/true, true ) { initGUI(); } FilterDialog::~FilterDialog() { } void FilterDialog::setFilters( const Filter::List &list ) { mFilterList.clear(); mInternalFilterList.clear(); Filter::List::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( (*it).isInternal() ) mInternalFilterList.append( *it ); else mFilterList.append( *it ); } refresh(); } Filter::List FilterDialog::filters() const { Filter::List list = mFilterList + mInternalFilterList; return list; } void FilterDialog::add() { #ifndef KAB_EMBEDDED FilterEditDialog dlg( this ); #else //KAB_EMBEDDED FilterEditDialog dlg( this->parentWidget() ); #endif //KAB_EMBEDDED if ( dlg.exec() ) mFilterList.append( dlg.filter() ); refresh(); mFilterListBox->setCurrentItem( mFilterListBox->count() - 1 ); } void FilterDialog::edit() { FilterEditDialog dlg( this ); uint pos = mFilterListBox->currentItem(); dlg.setFilter( mFilterList[ pos ] ); if ( dlg.exec() ) { mFilterList.remove( mFilterList.at( pos ) ); mFilterList.insert( mFilterList.at( pos ), dlg.filter() ); } refresh(); mFilterListBox->setCurrentItem( pos ); } void FilterDialog::remove() { mFilterList.remove( mFilterList.at( mFilterListBox->currentItem() ) ); selectionChanged( 0 ); refresh(); } void FilterDialog::refresh() { mFilterListBox->clear(); Filter::List::Iterator iter; for ( iter = mFilterList.begin(); iter != mFilterList.end(); ++iter ) mFilterListBox->insertItem( (*iter).name() ); } void FilterDialog::selectionChanged( QListBoxItem *item ) { bool state = ( item != 0 ); mEditButton->setEnabled( state ); mRemoveButton->setEnabled( state ); } void FilterDialog::initGUI() { #ifndef KAB_EMBEDDED resize( 330, 200 ); #else //KAB_EMBEDDED resize( KMIN(KGlobal::getDesktopWidth()-10, 330), KMIN(KGlobal::getDesktopHeight()-50, 200)); #endif //KAB_EMBEDDED QWidget *page = plainPage(); QGridLayout *topLayout = new QGridLayout( page, 1, 2, 0, spacingHint() ); mFilterListBox = new KListBox( page ); topLayout->addWidget( mFilterListBox, 0, 0 ); connect( mFilterListBox, SIGNAL( selectionChanged( QListBoxItem * ) ), SLOT( selectionChanged( QListBoxItem * ) ) ); connect( mFilterListBox, SIGNAL( doubleClicked ( QListBoxItem * ) ), SLOT( edit() ) ); KButtonBox *buttonBox = new KButtonBox( page, Vertical ); buttonBox->addButton( i18n( "&Add..." ), this, SLOT( add() ) ); mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( edit() ) ); mEditButton->setEnabled( false ); mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( remove() ) ); mRemoveButton->setEnabled( false ); buttonBox->layout(); topLayout->addWidget( buttonBox, 0, 1 ); } #ifndef KAB_EMBEDDED #include "filtereditdialog.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index e8f6132..59aa5a5 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2997,339 +2997,342 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo inL = inR; inL.setIDStr( idS ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); } inL.setResource( 0 ); local->insertAddressee( inL , false ); ++changedLocal; } } } } else { // no conflict ********** add or delete remote if ( filterIN.name().isEmpty() || filterIN.filterAddressee( inR ) ) { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { QString des = addresseeLSync.note(); if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); remote->insertAddressee( inR, false ); ++deletedAddresseeR; } else { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inL = inR; inL.setIDStr( ":" ); inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); inL.setResource( 0 ); local->insertAddressee( inL , false); ++addedAddressee; } } else { if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { inR.setRevision( modifiedCalendar ); remote->insertAddressee( inR, false ); inR.setResource( 0 ); local->insertAddressee( inR, false ); ++addedAddressee; } else { // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); remote->removeAddressee( inR ); ++deletedAddresseeR; } } } else { ++filteredIN; } } } ++incCounter; } er.clear(); QStringList el = local->uidList(); modulo = (el.count()/10)+1; syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); incCounter = 0; while ( incCounter < el.count()) { qApp->processEvents(); if (syncManager->isProgressBarCanceled()) return false; if ( incCounter % modulo == 0 ) syncManager->showProgressBar(incCounter); uid = el[ incCounter ]; bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; if ( !skipIncidence ) { inL = local->findByUid( uid ); if ( !inL.resource() || inL.resource()->includeInSync() ) { inR = remote->findByUid( uid ); if ( inR.isEmpty() ){ if ( filterOUT.name().isEmpty() || filterOUT.filterAddressee( inL ) ) { // no conflict ********** add or delete local if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { if ( ! syncManager->mWriteBackExistingOnly ) { inL.removeID(mCurrentSyncDevice ); ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } else { if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { //qDebug("data %s ", inL.revision().toString().latin1()); // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); local->removeAddressee( inL ); ++deletedAddresseeL; } else { if ( ! syncManager->mWriteBackExistingOnly ) { ++addedAddresseeR; inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; inR.setIDStr( ":" ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } } } } else { ++filteredOUT; } } } } ++incCounter; } el.clear(); syncManager->hideProgressBar(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); // get rid of micro seconds QTime t = mLastAddressbookSync.time(); mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); addresseeLSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRevision( mLastAddressbookSync ); addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); addresseeRSync.setNote( "" ) ; addresseeLSync.setNote( "" ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) remote->insertAddressee( addresseeRSync, false ); local->insertAddressee( addresseeLSync, false ); QString mes; mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR, filteredIN, filteredOUT ); qDebug( mes ); mes = i18n("Local addressbook changed!\n") +mes; if ( syncManager->mShowSyncSummary ) { if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, i18n("KA/Pi Synchronization"),i18n("Write back"))) { qDebug("KA: WB cancelled "); syncManager->mWriteBackFile = false; return syncOK; } } return syncOK; } //this is a overwritten callbackmethods from the syncinterface bool KABCore::sync(KSyncManager* manager, QString filename, int mode) { //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; if ( manager != syncManager ) qDebug("KABCore::sync:: ERROR! :: manager != syncManager "); QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("KA: Sync::AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); } else { external = !manager->mIsKapiFile; if ( external ) { qDebug("KA: Sync::Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); + syncManager->hideProgressBar(); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("KA: Sync::Saving remote AB "); if ( ! abLocal.saveAB()) qDebug("KA: sync::Error writing back AB to file "); if ( external ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); } } } setModified(); } abLocal.removeResources(); if ( syncOK ) mViewManager->refreshView(); return syncOK; } void KABCore::removeSyncInfo( QString syncProfile) { qDebug("KA: 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; message(i18n("Loading DTM address data..."), false); if ( abLocal.load() ) { qDebug("KA: AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; message(i18n("Sync preprocessing..."),false); abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); message(i18n("Synchronizing..."),false); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); + syncManager->hideProgressBar(); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( false ); message(i18n("Saving DTM address data..."),false); abLocal.saveAB(); message(i18n("Sync postprocessing..."),false); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); } } else message( i18n("Sync cancelled or failed.") ); setModified(); } abLocal.removeResources(); if ( syncOK ) { mViewManager->refreshView(); message(i18n("DTM syncing finished.")); } disableBR( false ); return syncOK; } void KABCore::message( QString m, bool startTimer) { topLevelWidget()->setCaption( m ); qApp->processEvents(); if ( startTimer ) mMessageTimer->start( 15000, true ); else mMessageTimer->stop(); } 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("KA: 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 ); + syncManager->hideProgressBar(); 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() { if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { syncManager->slotSyncMenu( 999 ); } mAddressBook->export2File( sentSyncFile() ); } QString KABCore::sentSyncFile() { #ifdef DESKTOP_VERSION return locateLocal( "tmp", "copysyncab.vcf" ); #else return QString( "/tmp/copysyncab.vcf" ); #endif } void KABCore::setCaptionBack() { mMessageTimer->stop(); topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); } |