summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-18 14:22:10 (UTC)
committer zautrix <zautrix>2004-09-18 14:22:10 (UTC)
commitca8fcf3fd4dc068747d8f31e2189145b22853d55 (patch) (side-by-side diff)
tree29417ffd55d1c4186922a64ed0cdf1c6a1cc69a3
parentbb16660f29fc709791aa0ee4cb63a40710a994a8 (diff)
downloadkdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.zip
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.gz
kdepimpi-ca8fcf3fd4dc068747d8f31e2189145b22853d55.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp15
-rw-r--r--kabc/addressbook.h3
-rw-r--r--kaddressbook/kabcore.cpp206
3 files changed, 105 insertions, 119 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 9332e21..6e8d027 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -484,105 +484,112 @@ void AddressBook::removeAddressee( const Addressee &a )
return;
}
}
}
void AddressBook::removeAddressee( const Iterator &it )
{
d->mRemovedAddressees.append( (*it) );
d->mAddressees.remove( it.d->mIt );
}
AddressBook::Iterator AddressBook::find( const Addressee &a )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
return it;
}
}
return end();
}
Addressee AddressBook::findByUid( const QString &uid )
{
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).uid() ) {
return *it;
}
}
return Addressee();
}
Addressee::List AddressBook::getExternLastSyncAddressees()
{
Addressee::List results;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( (*it).uid().left( 20 ) == "last-syncAddressee-" ) {
if ( (*it).familyName().left(3) == "E: " )
results.append( *it );
}
}
return results;
}
void AddressBook::resetTempSyncStat()
{
-
-
- Iterator it;
+ Iterator it;
for ( it = begin(); it != end(); ++it ) {
(*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL );
}
}
-
+
+QStringList AddressBook:: uidList()
+{
+ QStringList results;
+ Iterator it;
+ for ( it = begin(); it != end(); ++it ) {
+ results.append( (*it).uid() );
+ }
+ return results;
+}
Addressee::List AddressBook::allAddressees()
{
return d->mAddressees;
}
Addressee::List AddressBook::findByName( const QString &name )
{
Addressee::List results;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( name == (*it).realName() ) {
results.append( *it );
}
}
return results;
}
Addressee::List AddressBook::findByEmail( const QString &email )
{
Addressee::List results;
QStringList mailList;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
mailList = (*it).emails();
for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
if ( email == (*ite) ) {
results.append( *it );
}
}
}
return results;
}
Addressee::List AddressBook::findByCategory( const QString &category )
{
Addressee::List results;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( (*it).hasCategory( category) ) {
results.append( *it );
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 05225f9..650a638 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -245,89 +245,90 @@ class AddressBook : public QObject
/**
Add custom field to address book.
@param label User visible label of the field.
@param category Ored list of field categories.
@param key Identifier used as key for reading and writing the field.
@param app String used as application key for reading and writing
the field.
*/
bool addCustomField( const QString &label, int category = Field::All,
const QString &key = QString::null,
const QString &app = QString::null );
/**
Add address book resource.
*/
bool addResource( Resource * );
/**
Remove address book resource.
*/
bool removeResource( Resource * );
/**
Return pointer list of all resources.
*/
QPtrList<Resource> resources();
/**
Set the @p ErrorHandler, that is used by @ref error() to
provide gui-independend error messages.
*/
void setErrorHandler( ErrorHandler * );
/**
Shows gui independend error messages.
*/
void error( const QString& );
/**
Query all resources to clean up their lock files
*/
void cleanUp();
// sync stuff
Addressee::List getExternLastSyncAddressees();
- void resetTempSyncStat();
+ void resetTempSyncStat();
+ QStringList uidList();
signals:
/**
Emitted, when the address book has changed on disk.
*/
void addressBookChanged( AddressBook * );
/**
Emitted, when the address book has been locked for writing.
*/
void addressBookLocked( AddressBook * );
/**
Emitted, when the address book has been unlocked.
*/
void addressBookUnlocked( AddressBook * );
protected:
void deleteRemovedAddressees();
void setStandardResource( Resource * );
Resource *standardResource();
KRES::Manager<Resource> *resourceManager();
void init(const QString &config, const QString &family);
private:
//US QPtrList<Resource> mDummy; // Remove in KDE 4
struct AddressBookData;
AddressBookData *d;
};
QDataStream &operator<<( QDataStream &, const AddressBook & );
QDataStream &operator>>( QDataStream &, AddressBook & );
}
#endif
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 53c63ff..f497541 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1,89 +1,91 @@
/*
This file is part of KAddressbook.
Copyright (c) 2003 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.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include "kabcore.h"
#include <stdaddressbook.h>
#include <klocale.h>
#include <kfiledialog.h>
+#include <qprogressbar.h>
#ifndef KAB_EMBEDDED
#include <qclipboard.h>
#include <qdir.h>
#include <qfile.h>
#include <qapplicaton.h>
+#include <qprogressbar.h>
#include <qlayout.h>
#include <qregexp.h>
#include <qvbox.h>
#include <kabc/addresseelist.h>
#include <kabc/errorhandler.h>
#include <kabc/resource.h>
#include <kabc/vcardconverter.h>
#include <kapplication.h>
#include <kactionclasses.h>
#include <kcmultidialog.h>
#include <kdebug.h>
#include <kdeversion.h>
#include <kkeydialog.h>
#include <kmessagebox.h>
#include <kprinter.h>
#include <kprotocolinfo.h>
#include <kresources/selectdialog.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <kxmlguiclient.h>
#include <kaboutdata.h>
#include <libkdepim/categoryselectdialog.h>
#include "addresseeutil.h"
#include "addresseeeditordialog.h"
#include "extensionmanager.h"
#include "kstdaction.h"
#include "kaddressbookservice.h"
#include "ldapsearchdialog.h"
#include "printing/printingwizard.h"
#else // KAB_EMBEDDED
#include <kapplication.h>
#include "KDGanttMinimizeSplitter.h"
#include "kaddressbookmain.h"
#include "kactioncollection.h"
#include "addresseedialog.h"
//US
#include <addresseeview.h>
#include <qapp.h>
#include <qmenubar.h>
//#include <qtoolbar.h>
#include <qmessagebox.h>
#include <kdebug.h>
#include <kiconloader.h> // needed for SmallIcon
#include <kresources/kcmkresources.h>
#include <ktoolbar.h>
@@ -2552,291 +2554,267 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
bool fullDateRange = false;
local->resetTempSyncStat();
mLastAddressbookSync = QDateTime::currentDateTime();
QDateTime modifiedCalendar = mLastAddressbookSync;;
addresseeLSync = getLastSyncAddressee();
addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
if ( !addresseeR.isEmpty() ) {
addresseeRSync = addresseeR;
remote->removeAddressee(addresseeR );
} else {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
addresseeRSync = addresseeLSync ;
} else {
fullDateRange = true;
Addressee newAdd;
addresseeRSync = newAdd;
addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
addresseeRSync.setRevision( mLastAddressbookSync );
addresseeRSync.setCategories( i18n("SyncAddressee") );
}
}
if ( addresseeLSync.revision() == mLastAddressbookSync )
fullDateRange = true;
if ( ! fullDateRange ) {
if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
// qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
//qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
fullDateRange = true;
}
}
if ( fullDateRange )
mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
else
mLastAddressbookSync = addresseeLSync.revision();
// for resyncing if own file has changed
// PENDING fixme later when implemented
#if 0
if ( mCurrentSyncDevice == "deleteaftersync" ) {
mLastAddressbookSync = loadedFileVersion;
qDebug("setting mLastAddressbookSync ");
}
#endif
- #if 0
//qDebug("*************************** ");
qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
- QPtrList<Incidence> er = remote->rawIncidences();
- Incidence* inR = er.first();
- Incidence* inL;
+ QStringList er = remote->uidList();
+ Addressee inR ;//= er.first();
+ Addressee inL;
QProgressBar bar( er.count(),0 );
bar.setCaption (i18n("Syncing - close to abort!") );
int w = 300;
if ( QApplication::desktop()->width() < 320 )
w = 220;
int h = bar.sizeHint().height() ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
bar.show();
int modulo = (er.count()/10)+1;
int incCounter = 0;
- while ( inR ) {
+ while ( incCounter < er.count()) {
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
- ++incCounter;
- uid = inR->uid();
+ uid = er[ incCounter ];
bool skipIncidence = false;
- if ( uid.left(15) == QString("last-syncAddressee-") )
+ if ( uid.left(20) == QString("last-syncAddressee-") )
skipIncidence = true;
QString idS;
- qApp->processAddressees();
+ qApp->processEvents();
if ( !skipIncidence ) {
- inL = local->incidence( uid );
- if ( inL ) { // maybe conflict - same uid in both calendars
- int maxrev = inL->revision();
- if ( maxrev < inR->revision() )
- maxrev = inR->revision();
- if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) {
- //qDebug("take %d %s ", take, inL->summary().latin1());
+ inL = local->findByUid( uid );
+ inR = remote->findByUid( uid );
+ //inL.setResource( 0 );
+ //inR.setResource( 0 );
+ if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
+ // pending if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) {
+ if ( true ) {
+ //qDebug("take %d %s ", take, inL.summary().latin1());
if ( take == 3 )
return false;
if ( take == 1 ) {// take local
- if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
- inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
+ inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
+ local->insertAddressee( inL );
+ }
else
- idS = inR->IDStr();
- remote->deleteIncidence( inR );
- if ( inL->revision() < maxrev )
- inL->setRevision( maxrev );
- inR = inL->clone();
- inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ idS = inR.IDStr();
+ remote->removeAddressee( inR );
+ inR = inL;
+ inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
- inR->setIDStr( idS );
- remote->addIncidence( inR );
+ inR.setIDStr( idS );
+ inR.setResource( 0 );
+ remote->insertAddressee( inR );
++changedRemote;
} else {
- if ( inR->revision() < maxrev )
- inR->setRevision( maxrev );
- idS = inL->IDStr();
- local->deleteIncidence( inL );
- inL = inR->clone();
- inL->setIDStr( idS );
- local->addIncidence( inL );
+ idS = inL.IDStr();
+ local->removeAddressee( inL );
+ inL = inR;
+ inL.setIDStr( idS );
+ inL.setResource( 0 );
+ local->insertAddressee( inL );
++changedLocal;
}
}
} else { // no conflict
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
- QString des = addresseeLSync->description();
- QString pref = "e";
- if ( inR->type() == "Todo" )
- pref = "t";
- if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
- inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
- //remote->deleteIncidence( inR );
+ QString des = addresseeLSync.note();
+ QString pref = "a";
+ if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
+ inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
++deletedAddresseeR;
} else {
- inR->setLastModified( modifiedCalendar );
- inL = inR->clone();
- local->addIncidence( inL );
+ inR.setRevision( modifiedCalendar );
+ remote->insertAddressee( inR );
+ inL = inR;
+ inL.setResource( 0 );
+ local->insertAddressee( inL );
++addedAddressee;
}
} else {
- if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) {
- inR->setLastModified( modifiedCalendar );
- local->addIncidence( inR->clone() );
+ if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
+ inR.setRevision( modifiedCalendar );
+ remote->insertAddressee( inR );
+ inR.setResource( 0 );
+ local->insertAddressee( inR );
++addedAddressee;
} else {
- checkExternSyncAddressee(addresseeRSyncSharp, inR);
- remote->deleteIncidence( inR );
+ // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
+ remote->removeAddressee( inR );
++deletedAddresseeR;
}
}
}
}
- inR = er.next();
+ ++incCounter;
}
- QPtrList<Incidence> el = local->rawIncidences();
- inL = el.first();
+ er.clear();
+ QStringList el = remote->uidList();
modulo = (el.count()/10)+1;
bar.setCaption (i18n("Add / remove addressees") );
bar.setTotalSteps ( el.count() ) ;
bar.show();
incCounter = 0;
-
- while ( inL ) {
+ while ( incCounter < el.count()) {
- qApp->processAddressees();
+ qApp->processEvents();
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
- ++incCounter;
- uid = inL->uid();
+ uid = el[ incCounter ];
bool skipIncidence = false;
- if ( uid.left(15) == QString("last-syncAddressee-") )
+ if ( uid.left(20) == QString("last-syncAddressee-") )
skipIncidence = true;
- if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
skipIncidence = true;
if ( !skipIncidence ) {
- inR = remote->incidence( uid );
- if ( ! inR ) {
+ inL = local->findByUid( uid );
+ inR = remote->findByUid( uid );
+ if ( inR.isEmpty() ) {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
- if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
- checkExternSyncAddressee(addresseeLSyncSharp, inL);
- local->deleteIncidence( inL );
+ if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
+ // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ local->removeAddressee( inL );
++deletedAddresseeL;
} else {
- if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
- inL->removeID(mCurrentSyncDevice );
+ if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
+ inL.removeID(mCurrentSyncDevice );
++addedAddresseeR;
- //qDebug("remote added Incidence %s ", inL->summary().latin1());
- inL->setLastModified( modifiedCalendar );
- inR = inL->clone();
- inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
- remote->addIncidence( inR );
+ //qDebug("remote added Incidence %s ", inL.summary().latin1());
+ inL.setRevision( modifiedCalendar );
+ local->insertAddressee( inL );
+ inR = inL;
+ inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ inR.setResource( 0 );
+ remote->insertAddressee( inR );
}
}
} else {
- if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) {
- checkExternSyncAddressee(addresseeLSyncSharp, inL);
- local->deleteIncidence( inL );
+ if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
+ // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
+ local->removeAddressee( inL );
++deletedAddresseeL;
} else {
- if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
+ if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
++addedAddresseeR;
- inL->setLastModified( modifiedCalendar );
- remote->addIncidence( inL->clone() );
+ inL.setRevision( modifiedCalendar );
+ local->insertAddressee( inL );
+ inR = inL;
+ inR.setResource( 0 );
+ remote->insertAddressee( inR );
}
}
}
}
}
- inL = el.next();
+ ++incCounter;
}
+ el.clear();
int delFut = 0;
- if ( KOPrefs::instance()->mWriteBackInFuture ) {
- er = remote->rawIncidences();
- inR = er.first();
- QDateTime dt;
- QDateTime cur = QDateTime::currentDateTime();
- QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
- while ( inR ) {
- if ( inR->type() == "Todo" ) {
- Todo * t = (Todo*)inR;
- if ( t->hasDueDate() )
- dt = t->dtDue();
- else
- dt = cur.addSecs( 62 );
- }
- else if (inR->type() == "Addressee" ) {
- bool ok;
- dt = inR->getNextOccurence( cur, &ok );
- if ( !ok )
- dt = cur.addSecs( -62 );
- }
- else
- dt = inR->dtStart();
- if ( dt < cur || dt > end ) {
- remote->deleteIncidence( inR );
- ++delFut;
- }
- inR = er.next();
- }
- }
+
+ #if 0
+
bar.hide();
mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
- addresseeLSync->setReadOnly( false );
- addresseeLSync->setDtStart( mLastAddressbookSync );
- addresseeRSync->setDtStart( mLastAddressbookSync );
- addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) );
- addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) );
- addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
- addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
- addresseeLSync->setReadOnly( true );
+ addresseeLSync.setRevision( mLastAddressbookSync );
+ addresseeRSync.setRevision( mLastAddressbookSync );
+ addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
+ addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName );
+ addresseeLSync.setReadOnly( true );
if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
remote->addAddressee( addresseeRSync );
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"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
QString delmess;
if ( delFut ) {
delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
mes += delmess;
}
if ( KOPrefs::instance()->mShowSyncSummary ) {
KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
}
qDebug( mes );
mCalendar->checkAlarmForIncidence( 0, true );
return syncOK;
#endif
return false;
}
bool KABCore::syncAB(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;
AddressBook abLocal(filename,"syncContact");
bool syncOK = false;
if ( abLocal.load() ) {
qDebug("AB loaded %s mode %d",filename.latin1(), mode );
AddressBook::Iterator it;
QStringList vcards;
for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
qDebug("Name %s ", (*it).familyName().latin1());
}
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
if ( syncOK ) {
if ( KABPrefs::instance()->mWriteBackFile )
{
qDebug("saving remote AB ");
abLocal.saveAB();
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
#if 0