summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-29 14:01:58 (UTC)
committer zautrix <zautrix>2004-10-29 14:01:58 (UTC)
commit102cc4a711e303372efea9797623ee2d9f27f63c (patch) (side-by-side diff)
tree32e56b436e52b5b1bab701839a24fc175288d57c
parent8c55eb6afe84ef69bb284d384a0c9f1ef1484ad8 (diff)
downloadkdepimpi-102cc4a711e303372efea9797623ee2d9f27f63c.zip
kdepimpi-102cc4a711e303372efea9797623ee2d9f27f63c.tar.gz
kdepimpi-102cc4a711e303372efea9797623ee2d9f27f63c.tar.bz2
removed debug output
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp11
-rw-r--r--kabc/addressbook.h1
-rw-r--r--kabc/addressee.cpp2
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp137
-rw-r--r--kabc/tmpaddressbook.cpp9
-rw-r--r--kaddressbook/kabcore.cpp31
6 files changed, 39 insertions, 152 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 4c4ae09..8487ff3 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -1067,182 +1067,193 @@ Addressee::List AddressBook::findByCategory( const QString &category )
}
return results;
}
void AddressBook::dump() const
{
kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl;
ConstIterator it;
for( it = begin(); it != end(); ++it ) {
(*it).dump();
}
kdDebug(5700) << "AddressBook::dump() --- end ---" << endl;
}
QString AddressBook::identifier()
{
QStringList identifier;
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
if ( !(*it)->identifier().isEmpty() )
identifier.append( (*it)->identifier() );
}
return identifier.join( ":" );
}
Field::List AddressBook::fields( int category )
{
if ( d->mAllFields.isEmpty() ) {
d->mAllFields = Field::allFields();
}
if ( category == Field::All ) return d->mAllFields;
Field::List result;
Field::List::ConstIterator it;
for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) {
if ( (*it)->category() & category ) result.append( *it );
}
return result;
}
bool AddressBook::addCustomField( const QString &label, int category,
const QString &key, const QString &app )
{
if ( d->mAllFields.isEmpty() ) {
d->mAllFields = Field::allFields();
}
//US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app;
QString a = app.isNull() ? KGlobal::getAppName() : app;
QString k = key.isNull() ? label : key;
Field *field = Field::createCustomField( label, category, k, a );
if ( !field ) return false;
d->mAllFields.append( field );
return true;
}
QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
{
if (!ab.d) return s;
return s << ab.d->mAddressees;
}
QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
{
if (!ab.d) return s;
s >> ab.d->mAddressees;
return s;
}
bool AddressBook::addResource( Resource *resource )
{
if ( !resource->open() ) {
kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
return false;
}
resource->setAddressBook( this );
d->mManager->add( resource );
return true;
}
+void AddressBook::removeResources()
+{
+ //remove all possible resources. This should cleanup the configfile.
+ QPtrList<KABC::Resource> mResources = resources();
+
+ QPtrListIterator<KABC::Resource> it(mResources);
+ for ( ; it.current(); ++it ) {
+ KABC::Resource *res = it.current();
+ removeResource(res);
+ }
+}
bool AddressBook::removeResource( Resource *resource )
{
resource->close();
if ( resource == standardResource() )
d->mManager->setStandardResource( 0 );
resource->setAddressBook( 0 );
d->mManager->remove( resource );
return true;
}
QPtrList<Resource> AddressBook::resources()
{
QPtrList<Resource> list;
// qDebug("AddressBook::resources() 1");
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
list.append( *it );
return list;
}
/*US
void AddressBook::setErrorHandler( ErrorHandler *handler )
{
delete d->mErrorHandler;
d->mErrorHandler = handler;
}
*/
void AddressBook::error( const QString& msg )
{
/*US
if ( !d->mErrorHandler ) // create default error handler
d->mErrorHandler = new ConsoleErrorHandler;
if ( d->mErrorHandler )
d->mErrorHandler->error( msg );
else
kdError(5700) << "no error handler defined" << endl;
*/
kdDebug(5700) << "msg" << endl;
qDebug(msg);
}
void AddressBook::deleteRemovedAddressees()
{
Addressee::List::Iterator it;
for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) {
Resource *resource = (*it).resource();
if ( resource && !resource->readOnly() && resource->isOpen() )
resource->removeAddressee( *it );
}
d->mRemovedAddressees.clear();
}
void AddressBook::setStandardResource( Resource *resource )
{
// qDebug("AddressBook::setStandardResource 1");
d->mManager->setStandardResource( resource );
}
Resource *AddressBook::standardResource()
{
return d->mManager->standardResource();
}
KRES::Manager<Resource> *AddressBook::resourceManager()
{
return d->mManager;
}
void AddressBook::cleanUp()
{
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
if ( !(*it)->readOnly() && (*it)->isOpen() )
(*it)->cleanUp();
}
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 75f8b51..2351add 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -181,169 +181,170 @@ class AddressBook : public QObject
Insert an Addressee object into address book. If an object with the same
unique id already exists in the address book it it replaced by the new
one. If not the new object is appended to the address book.
*/
void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
/**
Removes entry from the address book.
*/
void removeAddressee( const Addressee & );
/**
This is like @ref removeAddressee() just above, with the difference that
the first element is a iterator, returned by @ref begin().
*/
void removeAddressee( const Iterator & );
/**
Find the specified entry in address book. Returns end(), if the entry
couldn't be found.
*/
Iterator find( const Addressee & );
/**
Find the entry specified by an unique id. Returns an empty Addressee
object, if the address book does not contain an entry with this id.
*/
Addressee findByUid( const QString & );
/**
Returns a list of all addressees in the address book. This list can
be sorted with @ref KABC::AddresseeList for example.
*/
Addressee::List allAddressees();
/**
Find all entries with the specified name in the address book. Returns
an empty list, if no entries could be found.
*/
Addressee::List findByName( const QString & );
/**
Find all entries with the specified email address in the address book.
Returns an empty list, if no entries could be found.
*/
Addressee::List findByEmail( const QString & );
/**
Find all entries wich have the specified category in the address book.
Returns an empty list, if no entries could be found.
*/
Addressee::List findByCategory( const QString & );
/**
Return a string identifying this addressbook.
*/
virtual QString identifier();
/**
Used for debug output.
*/
void dump() const;
void emitAddressBookLocked() { emit addressBookLocked( this ); }
void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); }
void emitAddressBookChanged() { emit addressBookChanged( this ); }
/**
Return list of all Fields known to the address book which are associated
with the given field category.
*/
Field::List fields( int category = Field::All );
/**
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.
*/
+ void removeResources();
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();
QStringList uidList();
void removeSyncAddressees( bool removeDeleted = false );
void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset );
Addressee findByExternUid( const QString& uid , const QString& profile );
bool containsExternalUid( const QString& uid );
void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset );
void postExternSync( AddressBook* aBook, const QString& csd , bool setID );
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;
bool blockLSEchange;
};
QDataStream &operator<<( QDataStream &, const AddressBook & );
QDataStream &operator>>( QDataStream &, AddressBook & );
}
#endif
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3d4992c..028d3bb 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -179,193 +179,193 @@ bool Addressee::isEmpty() const
return mData->empty;
}
ulong Addressee::getCsum4List( const QStringList & attList)
{
int max = attList.count();
ulong cSum = 0;
int j,k,i;
int add;
for ( i = 0; i < max ; ++i ) {
QString s = attList[i];
if ( ! s.isEmpty() ){
j = s.length();
for ( k = 0; k < j; ++k ) {
int mul = k +1;
add = s[k].unicode ();
if ( k < 16 )
mul = mul * mul;
int ii = i+1;
add = add * mul *ii*ii*ii;
cSum += add;
}
}
}
//QString dump = attList.join(",");
//qDebug("csum: %d %s", cSum,dump.latin1());
return cSum;
}
void Addressee::computeCsum(const QString &dev)
{
QStringList l;
//if ( !mData->name.isEmpty() ) l.append(mData->name);
//if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName );
if ( !mData->familyName.isEmpty() ) l.append( mData->familyName );
if ( !mData->givenName.isEmpty() ) l.append(mData->givenName );
if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName );
if ( !mData->prefix.isEmpty() ) l.append( mData->prefix );
if ( !mData->suffix.isEmpty() ) l.append( mData->suffix );
if ( !mData->nickName.isEmpty() ) l.append( mData->nickName );
if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() );
if ( !mData->mailer.isEmpty() ) l.append( mData->mailer );
if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() );
if ( mData->geo.isValid() ) l.append( mData->geo.asString() );
if ( !mData->title .isEmpty() ) l.append( mData->title );
if ( !mData->role.isEmpty() ) l.append( mData->role );
if ( !mData->organization.isEmpty() ) l.append( mData->organization );
if ( !mData->note.isEmpty() ) l.append( mData->note );
if ( !mData->productId.isEmpty() ) l.append(mData->productId );
if ( !mData->sortString.isEmpty() ) l.append( mData->sortString );
if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString());
// if ( !mData->logo.isEmpty() ) l.append( );
//if ( !mData->photo.isEmpty() ) l.append( );
//if ( !mData->sound.isEmpty() ) l.append( );
//if ( !mData->agent.isEmpty() ) l.append( );
if ( mData->url.isValid() )
if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() );
KABC::PhoneNumber::List phoneNumbers;
KABC::PhoneNumber::List::Iterator phoneIter;
QStringList t;
for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end();
++phoneIter )
t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) );
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)
if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) {
int find = t[iii].find (':')+1;
//qDebug("lennnn %d %d ", find, t[iii].length());
if ( find < t[iii].length())
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] );
}
uint cs = getCsum4List(l);
-#if 1
+#if 0
for ( iii = 0; iii < l.count(); ++iii)
qDebug("%d***%s***",iii,l[iii].latin1());
qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() );
#endif
setCsum( dev, QString::number (cs ));
}
void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false)
{
detach();
if ( mData->name.isEmpty() ) mData->name = ad.mData->name;
if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName;
if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName;
if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ;
if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName;
if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix;
if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix;
if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName;
if ( !mData->birthday.isValid() )
if ( ad.mData->birthday.isValid())
mData->birthday = ad.mData->birthday;
if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer;
if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone;
if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo;
if ( mData->title .isEmpty() ) mData->title = ad.mData->title ;
if ( mData->role.isEmpty() ) mData->role = ad.mData->role ;
if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ;
if ( mData->note.isEmpty() ) mData->note = ad.mData->note ;
if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId;
if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString;
if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy;
if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ;
QStringList t;
QStringList tAD;
uint iii;
// ********** phone numbers
PhoneNumber::List phoneAD = ad.phoneNumbers();
PhoneNumber::List::Iterator phoneItAD;
for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) {
bool found = false;
PhoneNumber::List::Iterator it;
for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
if ( ( *phoneItAD ).contains( (*it) ) ) {
found = true;
(*it).setType( ( *phoneItAD ).type() );
(*it).setNumber( ( *phoneItAD ).number() );
break;
}
}
if ( isSubSet && ! found )
mData->phoneNumbers.append( *phoneItAD );
}
if ( isSubSet ) {
// ************* emails;
t = mData->emails;
tAD = ad.mData->emails;
for ( iii = 0; iii < tAD.count(); ++iii)
if ( !t.contains(tAD[iii] ) )
mData->emails.append( tAD[iii] );
}
// ************* categories;
t = mData->categories;
tAD = ad.mData->categories;
for ( iii = 0; iii < tAD.count(); ++iii)
if ( !t.contains(tAD[iii] ) )
mData->categories.append( tAD[iii] );
QStringList::ConstIterator it;
for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) {
QString qualifiedName = (*it).left( (*it).find( ":" ));
bool found = false;
QStringList::ConstIterator itL;
for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) {
if ( (*itL).startsWith( qualifiedName ) ) {
found = true;
break;
}
}
if ( ! found ) {
mData->custom.append( *it );
}
}
if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo;
if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo;
if ( !mData->sound.isIntern() ) {
if ( mData->sound.url().isEmpty() ) {
mData->sound = ad.mData->sound;
}
}
if ( !mData->agent.isIntern() ) {
if ( mData->agent.url().isEmpty() ) {
mData->agent = ad.mData->agent;
}
}
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index ba17c50..48b7d91 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -1,406 +1,285 @@
/*
This file is part of libkabc.
Copyright (c) 2004 Ulf Schenk
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
//US #include <qtimer.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
//US #include <ksavefile.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include <sl/slzdb.h>
#include <libkdepim/ksyncprofile.h>
#include "resourcesharpdtmconfig.h"
#include "resourcesharpdtm.h"
#include "stdaddressbook.h"
#include "sharpdtmconverter.h"
//#define ALLOW_LOCKING
using namespace KABC;
extern "C"
{
void *init_microkabc_sharpdtm()
{
return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
}
}
ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
: Resource( config ), mConverter (0)
{
// we can not choose the filename. Therefore use the default to display
-
+ mAccess = 0;
QString fileName = SlZDataBase::addressbookFileName();
init( fileName );
}
ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
: Resource( 0 )
{
+ mAccess = 0;
init( fileName );
}
void ResourceSharpDTM::init( const QString &fileName )
{
-
- connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
- connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
- connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
-
setFileName( fileName );
}
ResourceSharpDTM::~ResourceSharpDTM()
{
if (mConverter != 0)
delete mConverter;
if(mAccess != 0)
delete mAccess;
}
void ResourceSharpDTM::writeConfig( KConfig *config )
{
Resource::writeConfig( config );
}
Ticket *ResourceSharpDTM::requestSaveTicket()
{
-
qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
if ( !addressBook() ) return 0;
-
-#ifdef ALLOW_LOCKING
- if ( !lock( fileName() ) ) {
- qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
- return 0;
- }
-#endif
return createTicket( this );
}
bool ResourceSharpDTM::doOpen()
{
- qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1());
+ qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1());
+ if ( ! mAccess ) {
// the last parameter in the SlZDataBase constructor means "readonly"
mAccess = new SlZDataBase(fileName(),
SlZDataBase::addressbookItems(),
NULL, false);
-
+ }
if ( !mAccess ) {
qDebug("Unable to load file() %s", fileName().latin1());
return false;
}
-
- if (mConverter == 0)
- {
+ if (mConverter == 0) {
mConverter = new SharpDTMConverter();
bool res = mConverter->init();
if ( !res )
{
QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
-
qDebug(msg);
delete mAccess;
mAccess = 0;
return false;
}
}
-
return true;
}
void ResourceSharpDTM::doClose()
{
- qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1());
-
- if(mAccess)
- {
- delete mAccess;
- mAccess = 0;
- }
- // it seems so, that deletion of access deletes backend as well
- //delete backend;
-
return;
}
bool ResourceSharpDTM::load()
{
- qDebug("ResourceSharpDTM::load: %s", fileName().latin1());
-
+ qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1());
bool res = false;
-
CardId id;
-
for (bool res=mAccess->first(); res == true; res=mAccess->next())
{
id = mAccess->cardId();
-
KABC::Addressee addressee;
-
res = mConverter->sharpToAddressee( id, mAccess, addressee );
-
if ( !addressee.isEmpty() && res )
{
addressee.setResource( this );
addressBook()->insertAddressee( addressee );
}
}
-
return true;
}
bool ResourceSharpDTM::save( Ticket *ticket )
{
qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
-
- mDirWatch.stopScan();
-
KABC::AddressBook::Iterator it;
bool res;
KABC::Addressee::List changedAddressees;
typedef QMap<int,QString> AddresseeMap;
AddresseeMap map;
CardId id ;
-
for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
QString uid = (*it).originalExternalUID();
bool res;
if ( uid.isEmpty() )
id = 0;
else
id = uid.toUInt();
KABC::Addressee addressee = (*it);
if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) {
res = mAccess->startEditCard(id);
if (res == true)
{
res = mConverter->addresseeToSharp( (*it), mAccess, id );
if (res == true)
{
- res = mAccess->finishEditCard(&id);
- //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
- //(*it).setExternalUID( QString::number( id ) );
- //(*it).setOriginalExternalUID( QString::number( id ) );
+ res = mAccess->finishEditCard(&id);;
map.insert(id,(*it).uid());
if (res == false)
qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
}
else
{
qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
mAccess->cancelEditCard();
}
}
} else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
res = mAccess->deleteCard(&id);
if ( !res )
qDebug("delete error ");
} else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
//changed
res = mAccess->startEditCard(id);
if (res == true)
{
res = mConverter->addresseeToSharp( (*it), mAccess, id );
if (res == true)
{
res = mAccess->finishEditCard(&id);
- //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM );
map.insert(id,(*it).uid());
if (res == false)
qDebug("Unable to append Contact: %s", addressee.formattedName().latin1());
-
}
else
{
qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1());
mAccess->cancelEditCard();
}
}
}
}
}
AddresseeMap::Iterator itam;
for ( res=mAccess->first(); res == true; res=mAccess->next())
{
id = mAccess->cardId();
int idint = id;
itam = map.find( idint );
if ( itam != map.end() ) {
KABC::Addressee addressee;
res = mConverter->sharpToAddressee( id, mAccess, addressee );
if ( !addressee.isEmpty() && res )
{
addressee.setResource( this );
addressee.setUid( itam.data() );
addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
addressBook()->insertAddressee( addressee , false );
}
}
}
-
- //US mAccess->save();
-
- mDirWatch.startScan();
delete ticket;
- unlock( fileName() );
return true;
}
bool ResourceSharpDTM::lock( const QString &lockfileName )
{
-#ifdef ALLOW_LOCKING
- qDebug("ResourceSharpDTM::lock: %s", fileName().latin1());
-
- kdDebug(5700) << "ResourceSharpDTM::lock()" << endl;
-
- QString fn = lockfileName;
-
- KURL url(fn);
- QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
-
- kdDebug(5700) << "-- lock name: " << lockName << endl;
-
- if (QFile::exists( lockName ))
- {
- qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName());
- return false;
- }
-
-
- QString lockUniqueName;
- lockUniqueName = fn + KApplication::randomString( 8 );
-
- url = lockUniqueName;
-//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
- mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
- kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
-
- // Create unique file
- QFile file( mLockUniqueName );
- file.open( IO_WriteOnly );
- file.close();
-
- // Create lock file
- int result = 0;
-#ifndef _WIN32_
- result = ::link( QFile::encodeName( mLockUniqueName ),
- QFile::encodeName( lockName ) );
-#endif
- if ( result == 0 ) {
- addressBook()->emitAddressBookLocked();
- return true;
- }
-
- // TODO: check stat
-
- return false;
-#else
- return true;
-#endif
}
void ResourceSharpDTM::unlock( const QString &fileName )
{
-#ifdef ALLOW_LOCKING
- qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1());
-
- QString fn = fileName;
- KURL url(fn);
- QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
- QFile::remove( lockName );
- QFile::remove( mLockUniqueName );
- addressBook()->emitAddressBookUnlocked();
-#endif
}
void ResourceSharpDTM::setFileName( const QString &newFileName )
{
- mDirWatch.stopScan();
- mDirWatch.removeFile( fileName() );
-
Resource::setFileName( newFileName );
-
- mDirWatch.addFile( fileName() );
- mDirWatch.startScan();
-
}
void ResourceSharpDTM::fileChanged()
{
- // There is a small theoretical chance that KDirWatch calls us before
- // we are fully constructed
- if (!addressBook())
- return;
- QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
- if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
- load();
- addressBook()->emitAddressBookChanged();
- }
}
void ResourceSharpDTM::removeAddressee( const Addressee &addr )
{
}
void ResourceSharpDTM::cleanUp()
{
unlock( fileName() );
}
diff --git a/kabc/tmpaddressbook.cpp b/kabc/tmpaddressbook.cpp
index 6e24302..cfa57e3 100644
--- a/kabc/tmpaddressbook.cpp
+++ b/kabc/tmpaddressbook.cpp
@@ -1,56 +1,49 @@
/*
This file is part of libkabc.
Copyright (c) 2004 Ulf Schenk
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <qptrlist.h>
#include "tmpaddressbook.h"
using namespace KABC;
#include "resource.h"
TmpAddressBook::TmpAddressBook()
: AddressBook(0, "tmpcontact")
{
}
TmpAddressBook::TmpAddressBook( const QString &config )
: AddressBook( config, "tmpcontact" )
{
}
TmpAddressBook::~TmpAddressBook()
{
- //remove all possible resources. This should cleanup the configfile.
- QPtrList<KABC::Resource> mResources = resources();
-
- QPtrListIterator<KABC::Resource> it(mResources);
- for ( ; it.current(); ++it ) {
- KABC::Resource *res = it.current();
- removeResource(res);
- }
+ removeResources();
}
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 6e482b5..e6bdde9 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2149,527 +2149,527 @@ void KABCore::configureKeyBindings()
}
#ifdef KAB_EMBEDDED
void KABCore::configureResources()
{
KRES::KCMKResources dlg( this, "" , 0 );
if ( !dlg.exec() )
return;
KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") );
}
#endif //KAB_EMBEDDED
/* this method will be called through the QCop interface from Ko/Pi to select addresses
* for the attendees list of an event.
*/
void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid)
{
QStringList nameList;
QStringList emailList;
QStringList uidList;
KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this);
uint i=0;
for (i=0; i < list.count(); i++)
{
nameList.append(list[i].realName());
emailList.append(list[i].preferredEmail());
uidList.append(list[i].uid());
}
bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList);
}
/* this method will be called through the QCop interface from Ko/Pi to select birthdays
* to put them into the calendar.
*/
void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid)
{
// qDebug("KABCore::requestForBirthdayList");
QStringList birthdayList;
QStringList anniversaryList;
QStringList realNameList;
QStringList preferredEmailList;
QStringList assembledNameList;
QStringList uidList;
KABC::AddressBook::Iterator it;
int count = 0;
for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
++count;
}
QProgressBar bar(count,0 );
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();
bar.setCaption (i18n("Collecting birthdays - close to abort!") );
qApp->processEvents();
QDate bday;
QString anni;
QString formattedbday;
for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it )
{
if ( ! bar.isVisible() )
return;
bar.setProgress( count++ );
qApp->processEvents();
bday = (*it).birthday().date();
anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" );
if ( bday.isValid() || !anni.isEmpty())
{
if (bday.isValid())
formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate);
else
formattedbday = "NOTVALID";
if (anni.isEmpty())
anni = "INVALID";
birthdayList.append(formattedbday);
anniversaryList.append(anni); //should be ISODate
realNameList.append((*it).realName());
preferredEmailList.append((*it).preferredEmail());
assembledNameList.append((*it).assembledName());
uidList.append((*it).uid());
- qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
+ //qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() );
}
}
bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList);
}
/* this method will be called through the QCop interface from other apps to show details of a contact.
*/
void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid)
{
- qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
+ //qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1());
QString foundUid = QString::null;
if ( ! uid.isEmpty() ) {
Addressee adrr = mAddressBook->findByUid( uid );
if ( !adrr.isEmpty() ) {
foundUid = uid;
}
if ( email == "sendbacklist" ) {
//qDebug("ssssssssssssssssssssssend ");
QStringList nameList;
QStringList emailList;
QStringList uidList;
nameList.append(adrr.realName());
emailList = adrr.emails();
uidList.append( adrr.preferredEmail());
bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList);
return;
}
}
if ( email == "sendbacklist" )
return;
if (foundUid.isEmpty())
{
//find the uid of the person first
Addressee::List namelist;
Addressee::List emaillist;
if (!name.isEmpty())
namelist = mAddressBook->findByName( name );
if (!email.isEmpty())
emaillist = mAddressBook->findByEmail( email );
- qDebug("count %d %d ", namelist.count(),emaillist.count() );
+ //qDebug("count %d %d ", namelist.count(),emaillist.count() );
//check if we have a match in Namelist and Emaillist
if ((namelist.count() == 0) && (emaillist.count() > 0)) {
foundUid = emaillist[0].uid();
}
else if ((namelist.count() > 0) && (emaillist.count() == 0))
foundUid = namelist[0].uid();
else
{
for (int i = 0; i < namelist.count(); i++)
{
for (int j = 0; j < emaillist.count(); j++)
{
if (namelist[i] == emaillist[j])
{
foundUid = namelist[i].uid();
}
}
}
}
}
else
{
foundUid = uid;
}
if (!foundUid.isEmpty())
{
// raise Ka/Pi if it is in the background
#ifndef DESKTOP_VERSION
#ifndef KORG_NODCOP
//QCopEnvelope e("QPE/Application/kapi", "raise()");
#endif
#endif
mMainWindow->showMaximized();
mMainWindow-> raise();
mViewManager->setSelected( "", false);
mViewManager->refreshView( "" );
mViewManager->setSelected( foundUid, true );
mViewManager->refreshView( foundUid );
if ( !mMultipleViewsAtOnce )
{
setDetailsVisible( true );
mActionDetails->setChecked(true);
}
}
}
void KABCore::whatsnew()
{
KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
}
void KABCore::synchowto()
{
KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
}
void KABCore::kdesynchowto()
{
KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" );
}
void KABCore::multisynchowto()
{
KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" );
}
void KABCore::faq()
{
KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
}
#include <libkcal/syncdefines.h>
KABC::Addressee KABCore::getLastSyncAddressee()
{
Addressee lse;
QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
//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 ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
sum = "E: ";
lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
lse.setRevision( mLastAddressbookSync );
lse.setCategories( i18n("SyncEvent") );
mAddressBook->insertAddressee( lse );
}
return lse;
}
int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
{
//void setZaurusId(int id);
// int zaurusId() const;
// void setZaurusUid(int id);
// int zaurusUid() const;
// void setZaurusStat(int id);
// int zaurusStat() const;
// 0 equal
// 1 take local
// 2 take remote
// 3 cancel
QDateTime lastSync = mLastAddressbookSync;
QDateTime localMod = local->revision();
QDateTime remoteMod = remote->revision();
QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
bool remCh, locCh;
remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
- qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
+ //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
locCh = ( localMod > mLastAddressbookSync );
if ( !remCh && ! locCh ) {
- qDebug("both not changed ");
+ //qDebug("both not changed ");
lastSync = localMod.addDays(1);
if ( mode <= SYNC_PREF_ASK )
return 0;
} else {
if ( locCh ) {
- qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
+ //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
lastSync = localMod.addDays( -1 );
if ( !remCh )
remoteMod =( lastSync.addDays( -1 ) );
} else {
- qDebug(" not loc changed ");
+ //qDebug(" not loc changed ");
lastSync = localMod.addDays( 1 );
if ( remCh ) {
- qDebug("rem changed ");
+ //qDebug("rem changed ");
remoteMod =( lastSync.addDays( 1 ) );
}
}
}
full = true;
if ( mode < SYNC_PREF_ASK )
mode = SYNC_PREF_ASK;
} else {
if ( localMod == remoteMod )
return 0;
}
- qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
- qDebug("lastsync %s ", lastSync.toString().latin1() );
+ //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
+ //qDebug("lastsync %s ", lastSync.toString().latin1() );
//full = true; //debug only
if ( full ) {
bool equ = ( (*local) == (*remote) );
if ( equ ) {
- qDebug("equal ");
+ //qDebug("equal ");
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
}
if ( mode < SYNC_PREF_FORCE_LOCAL )
return 0;
}//else //debug only
//qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
}
int result;
bool localIsNew;
//qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
if ( full && mode < SYNC_PREF_NEWEST )
mode = SYNC_PREF_ASK;
switch( mode ) {
case SYNC_PREF_LOCAL:
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
return 1;
break;
case SYNC_PREF_REMOTE:
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
return 2;
break;
case SYNC_PREF_NEWEST:
if ( localMod > remoteMod )
return 1;
else
return 2;
break;
case SYNC_PREF_ASK:
//qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
localIsNew = localMod >= remoteMod;
//qDebug("conflict! ************************************** ");
{
KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this );
result = acd.executeD(localIsNew);
return result;
}
break;
case SYNC_PREF_FORCE_LOCAL:
return 1;
break;
case SYNC_PREF_FORCE_REMOTE:
return 2;
break;
default:
// SYNC_PREF_TAKE_BOTH not implemented
break;
}
return 0;
}
bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
{
bool syncOK = true;
int addedAddressee = 0;
int addedAddresseeR = 0;
int deletedAddresseeR = 0;
int deletedAddresseeL = 0;
int changedLocal = 0;
int changedRemote = 0;
QString mCurrentSyncName = syncManager->getCurrentSyncName();
QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
//QPtrList<Addressee> el = local->rawAddressees();
Addressee addresseeR;
QString uid;
int take;
Addressee addresseeL;
Addressee addresseeRSync;
Addressee addresseeLSync;
// KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
//KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
bool fullDateRange = false;
local->resetTempSyncStat();
mLastAddressbookSync = QDateTime::currentDateTime();
if ( syncManager->syncWithDesktop() ) {
// remote->removeSyncInfo( QString());//remove all info
if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
} else {
qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
}
}
QDateTime modifiedCalendar = mLastAddressbookSync;
addresseeLSync = getLastSyncAddressee();
qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
if ( !addresseeR.isEmpty() ) {
addresseeRSync = addresseeR;
remote->removeAddressee(addresseeR );
} else {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
addresseeRSync = addresseeLSync ;
} else {
- qDebug("FULLDATE 1");
+ //qDebug("FULLDATE 1");
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 ) {
- qDebug("FULLDATE 2");
+ // qDebug("FULLDATE 2");
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;
- qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
+ //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
}
}
// fullDateRange = true; // debug only!
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
//qDebug("*************************** ");
// qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
QStringList er = remote->uidList();
Addressee inR ;//= er.first();
Addressee inL;
syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
int modulo = (er.count()/10)+1;
int incCounter = 0;
while ( incCounter < er.count()) {
if (syncManager->isProgressBarCanceled())
return false;
if ( incCounter % modulo == 0 )
syncManager->showProgressBar(incCounter);
uid = er[ incCounter ];
bool skipIncidence = false;
if ( uid.left(19) == QString("last-syncAddressee-") )
skipIncidence = true;
QString idS,OidS;
qApp->processEvents();
if ( !skipIncidence ) {
inL = local->findByUid( uid );
inR = remote->findByUid( uid );
//inL.setResource( 0 );
//inR.setResource( 0 );
if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
if ( !inL.resource() || inL.resource()->includeInSync() ) {
if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
//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) );
inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
local->insertAddressee( inL, false );
idS = inR.externalUID();
OidS = inR.originalExternalUID();
}
else
idS = inR.IDStr();
remote->removeAddressee( inR );
inR = inL;
inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
inR.setOriginalExternalUID( OidS );
inR.setExternalUID( idS );
if ( syncManager->syncWithDesktop() ) {
inR.setIDStr("changed" );
}
//inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
} else {
inR.setIDStr( idS );
}
inR.setResource( 0 );
remote->insertAddressee( inR , false);
++changedRemote;
} else { // take == 2 take remote **********************
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
if ( inR.revision().date().year() < 2004 )
inR.setRevision( modifiedCalendar );
}
idS = inL.IDStr();
local->removeAddressee( inL );
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 ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
@@ -2763,210 +2763,213 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
}
}
}
}
}
++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"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
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("cancelled ");
return false;
}
}
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;
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal(filename,"syncContact");
bool syncOK = false;
if ( abLocal.load() ) {
qDebug("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("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 );
if ( syncOK ) {
if ( syncManager->mWriteBackFile )
{
if ( external )
abLocal.removeSyncAddressees( !isXML);
qDebug("Saving remote AB ");
if ( ! abLocal.saveAB())
qDebug("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("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 );
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
AddressBook abLocal( resource,"syncContact");
bool syncOK = false;
if ( abLocal.load() ) {
qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
mGlobalSyncMode = SYNC_MODE_EXTERNAL;
abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {
abLocal.removeSyncAddressees( false );
abLocal.saveAB();
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
}
} else
message( i18n("Sync cancelled or failed.") );
setModified();
}
+ abLocal.removeResources();
if ( syncOK )
mViewManager->refreshView();
disableBR( false );
return syncOK;
}
void KABCore::message( QString m )
{
topLevelWidget()->setCaption( m );
mMessageTimer->start( 15000, true );
}
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("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 );
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") );
}