summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp48
1 files changed, 40 insertions, 8 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
@@ -2893,10 +2893,13 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
2893 manager->showProgressBar(incCounter); 2893 manager->showProgressBar(incCounter);
2894 2894
2895 uid = er[ incCounter ]; 2895 uid = er[ incCounter ];
2896 qDebug("sync uid %s from remote file", uid.latin1());
2897
2896 qApp->processEvents(); 2898 qApp->processEvents();
2897 2899
2898 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 2900 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
2899 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 2901 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
2902 PWM_ASSERT(inRemote);
2900 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 2903 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
2901 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 2904 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
2902 //qDebug("take %d %s ", take, inL.summary().latin1()); 2905 //qDebug("take %d %s ", take, inL.summary().latin1());
@@ -3094,26 +3097,55 @@ bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3094{ 3097{
3095 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3098 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3096 3099
3097 // construct on the stack = automatic cleanup. 3100 //1) unlock local file first if necessary (ask for password)
3101 if (this->isDeepLocked()) {
3102 PwMerror ret = this->deepLock(false);
3103 if (ret != e_success)
3104 return false;
3105 }
3106
3107 //2) construct and open a new doc on the stack(automatic cleanup) for remote file.
3098 PwMDoc syncTarget(this, "synctarget"); 3108 PwMDoc syncTarget(this, "synctarget");
3109 PwMDoc* pSyncTarget = &syncTarget;
3110
3099 3111
3100 PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/); 3112 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3101 3113
3102 if (err != e_success) 3114 if (err == e_alreadyOpen) {
3115 PwMDocList::listItem li;
3116 if (getOpenDocList()->find(filename.latin1(), &li))
3117 pSyncTarget = li.doc;
3118 else {
3119 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3120 return false;
3121 }
3122 }
3123 else if (err != e_success) {
3124 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3103 return false; 3125 return false;
3104 3126 }
3127
3105 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3128 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3106 3129
3130
3131 //3) unlock remote file first if necessary (ask for password)
3132 if (pSyncTarget->isDeepLocked()) {
3133 PwMerror ret = pSyncTarget->deepLock(false);
3134 if (ret != e_success)
3135 return false;
3136 }
3137
3107 3138
3108 err = syncronize(manager, this, &syncTarget, mode ); 3139 err = syncronize(manager, this, pSyncTarget, mode );
3109 3140
3110 if (err == e_success) { 3141 if (err == e_success) {
3111 if ( PWMPrefs::instance()->mWriteBackFile ){ 3142 if ( PWMPrefs::instance()->mWriteBackFile ){
3112 qDebug("Saving remote PWManager file"); 3143 qDebug("Saving remote PWManager file");
3113 err = syncTarget.saveDoc(conf()->confGlobCompression()); 3144 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3114 if (err != e_success) 3145 if (err != e_success) {
3146 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3115 return false; 3147 return false;
3116 3148 }
3117 } 3149 }
3118 3150
3119 flagDirty(); 3151 flagDirty();