summaryrefslogtreecommitdiffabout
path: root/kabc
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 /kabc
parentf370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (diff)
downloadkdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.zip
kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.gz
kdepimpi-787181d34f0d195ad72c9cf6aedbc317b6dd713e.tar.bz2
more AB sync
Diffstat (limited to 'kabc') (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
4 files changed, 43 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index ec9f893..46a9cf4 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -322,72 +322,82 @@ void AddressBook::init(const QString &config, const QString &family )
AddressBook::~AddressBook()
{
delete d->mConfig; d->mConfig = 0;
delete d->mManager; d->mManager = 0;
//US delete d->mErrorHandler; d->mErrorHandler = 0;
delete d; d = 0;
}
bool AddressBook::load()
{
clear();
KRES::Manager<Resource>::ActiveIterator it;
bool ok = true;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
if ( !(*it)->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 )
{
kdDebug(5700) << "AddressBook::save()"<< endl;
if ( ticket->resource() ) {
deleteRemovedAddressees();
return ticket->resource()->save( ticket );
}
return false;
}
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() );
if ( !ticket ) {
error( i18n( "Unable to save to resource '%1'. It is locked." )
.arg( (*it)->resourceName() ) );
return false;
}
//if ( !save( ticket ) )
if ( ticket->resource() ) {
if ( ! ticket->resource()->save( ticket ) )
ok = false;
} else
ok = false;
}
}
return ok;
}
@@ -429,149 +439,156 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl;
if ( !resource )
{
qDebug("AddressBook::requestSaveTicket no resource" );
resource = standardResource();
}
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
if ( (*it) == resource ) {
if ( (*it)->readOnly() || !(*it)->isOpen() )
return 0;
else
return (*it)->requestSaveTicket();
}
}
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;
Addressee addr = a;
if ( addr != (*it) )
changed = true;
(*it) = a;
if ( (*it).resource() == 0 )
(*it).setResource( standardResource() );
if ( changed ) {
if ( setRev ) {
// get rid of micro seconds
QDateTime dt = QDateTime::currentDateTime();
QTime t = dt.time();
dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
(*it).setRevision( dt );
}
(*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;
if( (startN = des.find( id ) ) >= 0 ) {
int endN = des.find( ",", startN+1 );
des = des.left( startN ) + des.mid( endN+1 );
(*it).setNote( des );
}
}
}
}
}
if ( found )
return;
d->mAddressees.append( a );
Addressee& addr = d->mAddressees.last();
if ( addr.resource() == 0 )
addr.setResource( standardResource() );
addr.setChanged( true );
}
void AddressBook::removeAddressee( const Addressee &a )
{
Iterator it;
Iterator it2;
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 ) {
des += id + ",";
(*it).setNote( des );
}
}
}
}
}
if ( found )
removeAddressee( it2 );
}
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 )
{
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;
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 0f5d605..d6b70c4 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -58,74 +58,73 @@ struct Addressee::AddresseeData : public KShared
QDateTime birthday;
QString mailer;
TimeZone timeZone;
Geo geo;
QString title;
QString role;
QString organization;
QString note;
QString productId;
QDateTime revision;
QString sortString;
KURL url;
Secrecy secrecy;
Picture logo;
Picture photo;
Sound sound;
Agent agent;
QString mExternalId;
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;
};
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);
}
Addressee Addressee::copy()
{
Addressee a;
*(a.mData) = *mData;
return a;
}
void Addressee::detach()
{
if ( mData.count() == 1 ) return;
*this = copy();
}
bool Addressee::operator==( const Addressee &a ) const
{
if ( uid() != a.uid() ) return false;
@@ -247,79 +246,87 @@ void Addressee::computeCsum(const QString &dev)
t.sort();
uint iii;
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->emails;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->categories;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
t = mData->custom;
t.sort();
for ( iii = 0; iii < t.count(); ++iii)
l.append( t[iii] );
KABC::Address::List::Iterator addressIter;
for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end();
++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 );
}
void Addressee::setIDStr( const QString & s )
{
detach();
mData->mExternalId = s;
}
QString Addressee::IDStr() const
{
return mData->mExternalId;
}
void Addressee::setUid( const QString &id )
{
if ( id == mData->uid ) return;
detach();
mData->empty = false;
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0805458..bfb0840 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -805,36 +805,35 @@ class Addressee
/**
Return pointer to resource.
*/
Resource *resource() const;
/**
Return resourcelabel.
*/
//US
static QString resourceLabel();
/**
Mark addressee as changed.
*/
void setChanged( bool value );
/**
Return whether the addressee is changed.
*/
bool changed() const;
private:
Addressee copy();
void detach();
- int mTempSyncStat;
struct AddresseeData;
mutable KSharedPtr<AddresseeData> mData;
};
QDataStream &operator<<( QDataStream &, const Addressee & );
QDataStream &operator>>( QDataStream &, Addressee & );
}
#endif
diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp
index ec47a4e..181a09e 100644
--- a/kabc/stdaddressbook.cpp
+++ b/kabc/stdaddressbook.cpp
@@ -144,49 +144,54 @@ void StdAddressBook::init( bool )
if ( !res ) {
res = manager->createResource( "file" );
if ( res )
{
addResource( res );
}
else
qDebug(" No resource available!!!");
}
setStandardResource( res );
manager->writeConfig();
load();
}
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() );
if ( !ticket ) {
ab->error( i18n( "Unable to save to resource '%1'. It is locked." )
.arg( (*it)->resourceName() ) );
return false;
}
if ( !ab->save( ticket ) )
ok = false;
}
}
return ok;
}
void StdAddressBook::close()
{
//US destructObject is not defined on my system???. Is setObject(0) the same ???
//US addressBookDeleter.destructObject();