summaryrefslogtreecommitdiffabout
Side-by-side diff
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
@@ -436,201 +436,208 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
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 )
{
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 ) {
(*it).setRevision( QDateTime::currentDateTime() );
(*it).setChanged( true );
}
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;
for ( it = begin(); it != end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
removeAddressee( it );
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 );
}
}
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;
}
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 05225f9..650a638 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -197,137 +197,138 @@ class AddressBook : public QObject
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.
*/
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,137 +1,139 @@
/*
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>
//#include <qlabel.h>
#ifndef DESKTOP_VERSION
#include <qpe/ir.h>
#include <qpe/qpemenubar.h>
#include <qtopia/qcopenvelope_qws.h>
#else
#include <qmenubar.h>
#endif
#endif // KAB_EMBEDDED
#include "kcmconfigs/kcmkabconfig.h"
#include "kcmconfigs/kcmkdepimconfig.h"
#include "kpimglobalprefs.h"
#include "externalapphandler.h"
#include <kresources/selectdialog.h>
#include <kmessagebox.h>
#include <picture.h>
#include <resource.h>
//US#include <qsplitter.h>
#include <qmap.h>
#include <qdir.h>
#include <qfile.h>
#include <qvbox.h>
#include <qlayout.h>
#include <qclipboard.h>
#include <qtextstream.h>
#include <libkdepim/categoryselectdialog.h>
#include <kabc/vcardconverter.h>
#include "addresseeutil.h"
#include "undocmds.h"
#include "addresseeeditordialog.h"
#include "viewmanager.h"
#include "details/detailsviewcontainer.h"
#include "kabprefs.h"
#include "xxportmanager.h"
#include "incsearchwidget.h"
@@ -2504,387 +2506,363 @@ QString KABCore::getPassword( )
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
dia.hide();
qApp->processEvents();
return retfile;
}
#include <libkcal/syncdefines.h>
KABC::Addressee KABCore::getLastSyncAddressee()
{
Addressee lse;
//qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
if (lse.isEmpty()) {
lse.setUid( "last-syncEvent-"+mCurrentSyncDevice );
QString sum = "";
if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
sum = "E: ";
lse.setFamilyName(sum+mCurrentSyncDevice + i18n(" - sync event"));
lse.setRevision( mLastAddressbookSync );
lse.setCategories( i18n("SyncEvent") );
mAddressBook->insertAddressee( lse );
}
return lse;
}
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;
//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();
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
if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
getEventViewerDialog()->setSyncMode( true );
syncOK = synchronizeCalendar( mCalendar, calendar, mode );
getEventViewerDialog()->setSyncMode( false );
if ( syncOK ) {
if ( KOPrefs::instance()->mWriteBackFile )
{
storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
storage->save();
}
}
setModified();
}
#endif
}
void KABCore::confSync()
{
static KSyncPrefsDialog* sp = 0;
if ( ! sp ) {
sp = new KSyncPrefsDialog( this, "syncprefs", true );
}
sp->usrReadConfig();
#ifndef DESKTOP_VERSION
sp->showMaximized();
#else
sp->show();
#endif
sp->exec();
KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
fillSyncMenu();
}
void KABCore::syncSharp()
{
if ( mModified )
save();
qDebug("pending syncSharp() ");
//mView->syncSharp();
setModified();
}
void KABCore::syncPhone()
{
if ( mModified )