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
@@ -2880,36 +2880,39 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
2880 PwMDataItem* inLocal; 2880 PwMDataItem* inLocal;
2881 unsigned int catLocal, indexLocal; 2881 unsigned int catLocal, indexLocal;
2882 unsigned int catRemote, indexRemote; 2882 unsigned int catRemote, indexRemote;
2883 2883
2884 QString uid; 2884 QString uid;
2885 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2885 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2886 2886
2887 int modulo = (er.count()/10)+1; 2887 int modulo = (er.count()/10)+1;
2888 unsigned int incCounter = 0; 2888 unsigned int incCounter = 0;
2889 while ( incCounter < er.count()) { 2889 while ( incCounter < er.count()) {
2890 if (manager->isProgressBarCanceled()) 2890 if (manager->isProgressBarCanceled())
2891 return e_syncError; 2891 return e_syncError;
2892 if ( incCounter % modulo == 0 ) 2892 if ( incCounter % modulo == 0 )
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());
2903 if ( take == 3 ) 2906 if ( take == 3 )
2904 return e_syncError; 2907 return e_syncError;
2905 if ( take == 1 ) {// take local 2908 if ( take == 1 ) {// take local
2906 //US syncRemote->removeAddressee( inRemote ); 2909 //US syncRemote->removeAddressee( inRemote );
2907 (*inRemote) = (*inLocal); 2910 (*inRemote) = (*inLocal);
2908 //US syncRemote->insertAddressee( inRemote , false); 2911 //US syncRemote->insertAddressee( inRemote , false);
2909 ++changedRemote; 2912 ++changedRemote;
2910 } else { // take == 2 take remote 2913 } else { // take == 2 take remote
2911 //US syncLocal->removeAddressee( inLocal ); 2914 //US syncLocal->removeAddressee( inLocal );
2912 (*inLocal) = (*inRemote); 2915 (*inLocal) = (*inRemote);
2913 //US syncLocal->insertAddressee( inLocal , false ); 2916 //US syncLocal->insertAddressee( inLocal , false );
2914 ++changedLocal; 2917 ++changedLocal;
2915 } 2918 }
@@ -3081,52 +3084,81 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
3081 3084
3082 default: 3085 default:
3083 // SYNC_PREF_TAKE_BOTH not implemented 3086 // SYNC_PREF_TAKE_BOTH not implemented
3084 break; 3087 break;
3085 } 3088 }
3086 return 0; 3089 return 0;
3087} 3090}
3088 3091
3089 3092
3090 3093
3091 3094
3092//this are the overwritten callbackmethods from the syncinterface 3095//this are the overwritten callbackmethods from the syncinterface
3093bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3096bool 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();
3120 return true; 3152 return true;
3121 } 3153 }
3122 else { 3154 else {
3123 return false; 3155 return false;
3124 } 3156 }
3125} 3157}
3126 3158
3127//called by the syncmanager to indicate that the work has to marked as dirty. 3159//called by the syncmanager to indicate that the work has to marked as dirty.
3128void PwMDoc::sync_setModified() 3160void PwMDoc::sync_setModified()
3129{ 3161{
3130 flagDirty(); 3162 flagDirty();
3131} 3163}
3132 3164