summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 4e8a603..6c1a9c0 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2848,100 +2848,103 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
}
syncItemRemote = syncRemote->getSyncDataEntry(index);
//and remove the found entry here. We will reenter it later again.
syncRemote->delSyncDataEntry(index, true);
if ( syncItemLocal->lastSyncDate == mLastSync ) {
qDebug("FULLDATE 2");
fullDateRange = true;
}
if ( ! fullDateRange ) {
if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
// 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", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
}
}
// fullDateRange = true; // debug only!
if ( fullDateRange )
mLastSync = QDateTime::currentDateTime().addDays( -100*365);
else
mLastSync = syncItemLocal->lastSyncDate;
qDebug("*************************** ");
// qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
QStringList er = syncRemote->getIDEntryList();
PwMDataItem* inRemote ;//= er.first();
PwMDataItem* inLocal;
unsigned int catLocal, indexLocal;
unsigned int catRemote, indexRemote;
QString uid;
manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
int modulo = (er.count()/10)+1;
unsigned int incCounter = 0;
while ( incCounter < er.count()) {
if (manager->isProgressBarCanceled())
return e_syncError;
if ( incCounter % modulo == 0 )
manager->showProgressBar(incCounter);
uid = er[ incCounter ];
+ qDebug("sync uid %s from remote file", uid.latin1());
+
qApp->processEvents();
inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
+ PWM_ASSERT(inRemote);
if ( inLocal != 0 ) { // maybe conflict - same uid in both files
if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
//qDebug("take %d %s ", take, inL.summary().latin1());
if ( take == 3 )
return e_syncError;
if ( take == 1 ) {// take local
//US syncRemote->removeAddressee( inRemote );
(*inRemote) = (*inLocal);
//US syncRemote->insertAddressee( inRemote , false);
++changedRemote;
} else { // take == 2 take remote
//US syncLocal->removeAddressee( inLocal );
(*inLocal) = (*inRemote);
//US syncLocal->insertAddressee( inLocal , false );
++changedLocal;
}
}
} else { // no conflict
if ( inRemote->meta.update > mLastSync || mode == 5 ) {
inRemote->meta.update = modifiedSync;
//US syncRemote->insertAddressee( inRemote, false );
//US syncLocal->insertAddressee( inRemote, false );
syncLocal->addEntry("newcategory", inRemote, true, false);
++addedPasswordsLocal;
} else {
// pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
syncRemote->delEntry(catRemote, indexRemote, true);
//USsyncRemote->removeAddressee( inRemote );
++deletedPasswordsRemote;
}
}
++incCounter;
}
er.clear();
QStringList el = syncLocal->getIDEntryList();
modulo = (el.count()/10)+1;
manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
incCounter = 0;
while ( incCounter < el.count()) {
qApp->processEvents();
if (manager->isProgressBarCanceled())
return e_syncError;
if ( incCounter % modulo == 0 )
@@ -3049,116 +3052,145 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
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! ************************************** ");
{
PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*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;
}
//this are the overwritten callbackmethods from the syncinterface
bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
{
QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
- // construct on the stack = automatic cleanup.
+ //1) unlock local file first if necessary (ask for password)
+ if (this->isDeepLocked()) {
+ PwMerror ret = this->deepLock(false);
+ if (ret != e_success)
+ return false;
+ }
+
+ //2) construct and open a new doc on the stack(automatic cleanup) for remote file.
PwMDoc syncTarget(this, "synctarget");
+ PwMDoc* pSyncTarget = &syncTarget;
- PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/);
- if (err != e_success)
+ PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
+
+ if (err == e_alreadyOpen) {
+ PwMDocList::listItem li;
+ if (getOpenDocList()->find(filename.latin1(), &li))
+ pSyncTarget = li.doc;
+ else {
+ qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
+ return false;
+ }
+ }
+ else if (err != e_success) {
+ qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
return false;
+ }
qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
- err = syncronize(manager, this, &syncTarget, mode );
+ //3) unlock remote file first if necessary (ask for password)
+ if (pSyncTarget->isDeepLocked()) {
+ PwMerror ret = pSyncTarget->deepLock(false);
+ if (ret != e_success)
+ return false;
+ }
+
+
+ err = syncronize(manager, this, pSyncTarget, mode );
if (err == e_success) {
if ( PWMPrefs::instance()->mWriteBackFile ) {
qDebug("Saving remote PWManager file");
- err = syncTarget.saveDoc(conf()->confGlobCompression());
- if (err != e_success)
+ err = pSyncTarget->saveDoc(conf()->confGlobCompression());
+ if (err != e_success) {
+ qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
return false;
-
+ }
}
flagDirty();
return true;
}
else {
return false;
}
}
//called by the syncmanager to indicate that the work has to marked as dirty.
void PwMDoc::sync_setModified()
{
flagDirty();
}
//called by the syncmanager to ask if the dirty flag is set.
bool PwMDoc::sync_isModified()
{
return isDirty();
}
//called by the syncmanager to indicate that the work has to be saved.
void PwMDoc::sync_save()
{
saveDoc(conf()->confGlobCompression());
}
#endif
bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
{
vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
end = dti.syncDta.end();
while (i != end) {
if ((*i).syncName == syncname.latin1()) {
if (index) {
*index = i - dti.syncDta.begin();
}
return true;
}
++i;
}
return false;
};
/** add new syncdataentry */