summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-19 09:00:55 (UTC)
committer zautrix <zautrix>2004-09-19 09:00:55 (UTC)
commit787181d34f0d195ad72c9cf6aedbc317b6dd713e (patch) (side-by-side diff)
treeac49d2b1d7887f96f3834458071b89e77b59218b
parentf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (diff)
downloadkdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.zip
kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.gz
kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.bz2
more AB sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp31
-rw-r--r--kabc/addressee.cpp19
-rw-r--r--kabc/addressee.h1
-rw-r--r--kabc/stdaddressbook.cpp7
-rw-r--r--kaddressbook/kabcore.cpp27
-rw-r--r--korganizer/calendarview.cpp2
6 files changed, 59 insertions, 28 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index ec9f893..46a9cf4 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -340,15 +340,20 @@ bool AddressBook::load()
error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) );
ok = false;
}
// mark all addressees as unchanged
Addressee::List::Iterator addrIt;
- for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt )
+ for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
(*addrIt).setChanged( false );
-
+ QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
+ if ( !id.isEmpty() ) {
+ //qDebug("setId aa %s ", id.latin1());
+ (*addrIt).setIDStr(id );
+ }
+ }
blockLSEchange = true;
return ok;
}
bool AddressBook::save( Ticket *ticket )
{
@@ -363,13 +368,18 @@ bool AddressBook::save( Ticket *ticket )
}
bool AddressBook::saveAB()
{
bool ok = true;
deleteRemovedAddressees();
-
+ Iterator ait;
+ for ( ait = begin(); ait != end(); ++ait ) {
+ if ( !(*ait).IDStr().isEmpty() ) {
+ (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
+ }
+ }
KRES::Manager<Resource>::ActiveIterator it;
KRES::Manager<Resource> *manager = d->mManager;
for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
if ( !(*it)->readOnly() && (*it)->isOpen() ) {
Ticket *ticket = requestSaveTicket( *it );
// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
@@ -447,14 +457,16 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
return 0;
}
void AddressBook::insertAddressee( const Addressee &a, bool setRev )
{
if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
+ //qDebug("block insert ");
return;
}
+ //qDebug("inserting.... %s ",a.uid().latin1() );
bool found = false;
Addressee::List::Iterator it;
for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
bool changed = false;
@@ -477,13 +489,13 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
}
(*it).setChanged( true );
}
found = true;
} else {
- if ( (*it).uid() == QString("last-syncAddressee-") ) {
+ if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
QString name = (*it).uid().mid( 19 );
Addressee b = a;
QString id = b.getID( name );
if ( ! id.isEmpty() ) {
QString des = (*it).note();
int startN;
@@ -513,13 +525,13 @@ void AddressBook::removeAddressee( const Addressee &a )
bool found = false;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
found = true;
it2 = it;
} else {
- if ( (*it).uid() == QString("last-syncAddressee-") ) {
+ if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
QString name = (*it).uid().mid( 19 );
Addressee b = a;
QString id = b.getID( name );
if ( ! id.isEmpty() ) {
QString des = (*it).note();
if( des.find( id ) < 0 ) {
@@ -542,18 +554,23 @@ void AddressBook::removeDeletedAddressees()
deleteRemovedAddressees();
Iterator it = begin();
Iterator it2 ;
QDateTime dt ( QDate( 2004,1,1) );
while ( it != end() ) {
(*it).setRevision( dt );
- if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
+ (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" );
+ (*it).setIDStr("");
+ if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) {
it2 = it;
+ //qDebug("removing %s ",(*it).uid().latin1() );
++it;
removeAddressee( it2 );
- } else
+ } else {
+ //qDebug("skipping %s ",(*it).uid().latin1() );
++it;
+ }
}
deleteRemovedAddressees();
}
void AddressBook::removeAddressee( const Iterator &it )
{
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 0f5d605..d6b70c4 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -76,13 +76,13 @@ struct Addressee::AddresseeData : public KShared
PhoneNumber::List phoneNumbers;
Address::List addresses;
Key::List keys;
QStringList emails;
QStringList categories;
QStringList custom;
-
+ int mTempSyncStat;
Resource *resource;
bool empty :1;
bool changed :1;
};
@@ -91,23 +91,22 @@ Addressee::Addressee()
mData = new AddresseeData;
mData->empty = true;
mData->changed = false;
mData->resource = 0;
mData->mExternalId = ":";
mData->revision = QDateTime ( QDate( 2004,1,1));
- mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
+ mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
}
Addressee::~Addressee()
{
}
Addressee::Addressee( const Addressee &a )
{
mData = a.mData;
- mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
}
Addressee &Addressee::operator=( const Addressee &a )
{
mData = a.mData;
return (*this);
@@ -265,43 +264,51 @@ void Addressee::computeCsum(const QString &dev)
++addressIter ) {
t = (*addressIter).asList();
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
}
- setCsum( dev, QString::number (getCsum4List(l)) );
+ uint cs = getCsum4List(l);
+ qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
+ setCsum( dev, QString::number (cs ));
}
void Addressee::removeID(const QString &prof)
{
detach();
mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof);
}
void Addressee::setID( const QString & prof , const QString & id )
{
detach();
+ qDebug("setID1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id );
+ qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
}
void Addressee::setTempSyncStat( int id )
{
- mTempSyncStat = id;
+ if ( mData->mTempSyncStat == id ) return;
+ detach();
+ mData->mTempSyncStat = id;
}
int Addressee::tempSyncStat() const
{
- return mTempSyncStat;
+ return mData->mTempSyncStat;
}
QString Addressee::getID( const QString & prof)
{
return KIdManager::getId ( mData->mExternalId, prof );
}
void Addressee::setCsum( const QString & prof , const QString & id )
{
detach();
+ qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() );
mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id );
+ qDebug("setcsum2 %s ",mData->mExternalId.latin1() );
}
QString Addressee::getCsum( const QString & prof)
{
return KIdManager::getCsum ( mData->mExternalId, prof );
}
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0805458..bfb0840 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -823,13 +823,12 @@ class Addressee
*/
bool changed() const;
private:
Addressee copy();
void detach();
- int mTempSyncStat;
struct AddresseeData;
mutable KSharedPtr<AddresseeData> mData;
};
QDataStream &operator<<( QDataStream &, const Addressee & );
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index ec47a4e..181a09e 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -162,13 +162,18 @@ bool StdAddressBook::save()
kdDebug(5700) << "StdAddressBook::save()" << endl;
bool ok = true;
AddressBook *ab = self();
ab->deleteRemovedAddressees();
-
+ Iterator ait;
+ for ( ait = ab->begin(); ait != ab->end(); ++ait ) {
+ if ( !(*ait).IDStr().isEmpty() ) {
+ (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
+ }
+ }
KRES::Manager<Resource>::ActiveIterator it;
KRES::Manager<Resource> *manager = ab->resourceManager();
for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
if ( !(*it)->readOnly() && (*it)->isOpen() ) {
Ticket *ticket = ab->requestSaveTicket( *it );
// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 8776b53..56f6af2 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2523,13 +2523,13 @@ KABC::Addressee KABCore::getLastSyncAddressee()
//qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
if (lse.isEmpty()) {
qDebug("Creating new last-syncAddressee ");
lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
QString sum = "";
- if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
sum = "E: ";
lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
lse.setRevision( mLastAddressbookSync );
lse.setCategories( i18n("SyncEvent") );
mAddressBook->insertAddressee( lse );
}
@@ -2549,21 +2549,23 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
// 2 take remote
// 3 cancel
QDateTime lastSync = mLastAddressbookSync;
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
bool remCh, locCh;
remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
- //if ( remCh )
- //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
+ if ( remCh )
+ qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
locCh = ( local->revision() > mLastAddressbookSync );
if ( !remCh && ! locCh ) {
- //qDebug("both not changed ");
+ qDebug("both not changed ");
lastSync = local->revision().addDays(1);
+ if ( mode <= SYNC_PREF_ASK )
+ return 0;
} else {
if ( locCh ) {
- //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
+ qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1());
lastSync = local->revision().addDays( -1 );
if ( !remCh )
remote->setRevision( lastSync.addDays( -1 ) );
} else {
//qDebug(" not loc changed ");
lastSync = local->revision().addDays( 1 );
@@ -2787,15 +2789,15 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
++changedLocal;
}
}
} else { // no conflict
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
QString des = addresseeLSync.note();
- QString pref = "a";
- if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
+ 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.setResource( 0 );
@@ -2817,45 +2819,41 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
}
}
}
++incCounter;
}
er.clear();
- QStringList el = remote->uidList();
+ QStringList el = local->uidList();
modulo = (el.count()/10)+1;
bar.setCaption (i18n("Add / remove addressees") );
bar.setTotalSteps ( el.count() ) ;
bar.show();
incCounter = 0;
while ( incCounter < el.count()) {
-
qApp->processEvents();
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
uid = el[ incCounter ];
bool skipIncidence = false;
if ( uid.left(19) == QString("last-syncAddressee-") )
skipIncidence = true;
- if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
- skipIncidence = true;
if ( !skipIncidence ) {
inL = local->findByUid( uid );
inR = remote->findByUid( uid );
if ( inR.isEmpty() ) {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
// pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
local->removeAddressee( inL );
++deletedAddresseeL;
} else {
if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) {
inL.removeID(mCurrentSyncDevice );
- ++addedAddresseeR;
- //qDebug("remote added Incidence %s ", inL.summary().latin1());
+ ++addedAddresseeR;
inL.setRevision( modifiedCalendar );
local->insertAddressee( inL, false );
inR = inL;
inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
inR.setResource( 0 );
remote->insertAddressee( inR, false );
@@ -2892,12 +2890,14 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
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"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
@@ -2934,12 +2934,13 @@ bool KABCore::syncAB(QString filename, int mode)
}
}
external = ! found;
}
if ( external ) {
+ qDebug("**********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 );
}
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 56b3fb0..0c75632 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -732,12 +732,14 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
//if ( remCh )
//qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
locCh = ( local->lastModified() > mLastCalendarSync );
if ( !remCh && ! locCh ) {
//qDebug("both not changed ");
lastSync = local->lastModified().addDays(1);
+ if ( mode <= SYNC_PREF_ASK )
+ return 0;
} else {
if ( locCh ) {
//qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1());
lastSync = local->lastModified().addDays( -1 );
if ( !remCh )
remote->setLastModified( lastSync.addDays( -1 ) );