summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Side-by-side diff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp133
1 files changed, 97 insertions, 36 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 16e1653..ec9f893 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -221,32 +221,33 @@ AddressBook::AddressBook()
}
AddressBook::AddressBook( const QString &config )
{
init(config, "contact");
}
AddressBook::AddressBook( const QString &config, const QString &family )
{
init(config, family);
}
// the default family is "contact"
void AddressBook::init(const QString &config, const QString &family )
{
+ blockLSEchange = false;
d = new AddressBookData;
QString fami = family;
qDebug("new ab ");
if (config != 0) {
qDebug("config != 0 ");
if ( family == "syncContact" ) {
qDebug("creating sync config ");
fami = "contact";
KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
con->setGroup( "General" );
con->writeEntry( "ResourceKeys", QString("sync") );
con->writeEntry( "Standard", QString("sync") );
con->setGroup( "Resource_sync" );
con->writeEntry( "FileFormat", QString("vcard") );
con->writeEntry( "FileName", config );
con->writeEntry( "ResourceIdentifier", QString("sync") );
@@ -332,32 +333,33 @@ 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 )
(*addrIt).setChanged( false );
+ 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()
{
@@ -434,122 +436,181 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
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 )
{
- Addressee::List::Iterator it;
- for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
- if ( a.uid() == (*it).uid() ) {
- if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) {
- return;
- }
- bool changed = false;
- Addressee addr = a;
- if ( addr != (*it) )
- changed = true;
-
- (*it) = a;
- if ( (*it).resource() == 0 )
- (*it).setResource( standardResource() );
-
- if ( changed ) {
- if ( setRev ) {
+ if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) {
+ return;
+ }
+ 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 );
- }
-
- return;
+ // 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-") ) {
+ 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 );
+ }
+ }
+ }
+ }
}
- }
- d->mAddressees.append( a );
- Addressee& addr = d->mAddressees.last();
- if ( addr.resource() == 0 )
- addr.setResource( standardResource() );
+ if ( found )
+ return;
+ d->mAddressees.append( a );
+ Addressee& addr = d->mAddressees.last();
+ if ( addr.resource() == 0 )
+ addr.setResource( standardResource() );
- addr.setChanged( true );
+ 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() ) {
- removeAddressee( it );
- return;
+ found = true;
+ it2 = it;
+ } else {
+ if ( (*it).uid() == 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 ) {
+ it2 = it;
+ ++it;
+ removeAddressee( it2 );
+ } else
+ ++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;
for ( it = begin(); it != end(); ++it ) {
if ( uid == (*it).uid() ) {
return *it;
}
}
return Addressee();
}
+#if 0
Addressee::List AddressBook::getExternLastSyncAddressees()
{
Addressee::List results;
Iterator it;
for ( it = begin(); it != end(); ++it ) {
if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) {
- if ( (*it).familyName().left(3) == "E: " )
+ if ( (*it).familyName().left(4) == "!E: " )
results.append( *it );
}
}
return results;
}
+#endif
void AddressBook::resetTempSyncStat()
{
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() );
}