summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-06 06:18:43 (UTC)
committer ulf69 <ulf69>2004-10-06 06:18:43 (UTC)
commit8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8 (patch) (unidiff)
tree8d8ca7401ce699ee3aca98cace5561beb4104710
parent904cbf4f2a418d3cadc74a6168a4565ae6ebc3c5 (diff)
downloadkdepimpi-8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8.zip
kdepimpi-8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8.tar.gz
kdepimpi-8e5089d2f2011e38d811ae0fc6b6d4edaeaf89b8.tar.bz2
*** empty log message ***
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
@@ -2848,100 +2848,103 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
2848 } 2848 }
2849 2849
2850 syncItemRemote = syncRemote->getSyncDataEntry(index); 2850 syncItemRemote = syncRemote->getSyncDataEntry(index);
2851 //and remove the found entry here. We will reenter it later again. 2851 //and remove the found entry here. We will reenter it later again.
2852 syncRemote->delSyncDataEntry(index, true); 2852 syncRemote->delSyncDataEntry(index, true);
2853 2853
2854 2854
2855 if ( syncItemLocal->lastSyncDate == mLastSync ) { 2855 if ( syncItemLocal->lastSyncDate == mLastSync ) {
2856 qDebug("FULLDATE 2"); 2856 qDebug("FULLDATE 2");
2857 fullDateRange = true; 2857 fullDateRange = true;
2858 } 2858 }
2859 2859
2860 if ( ! fullDateRange ) { 2860 if ( ! fullDateRange ) {
2861 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 2861 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
2862 2862
2863 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2863 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2864 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2864 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2865 fullDateRange = true; 2865 fullDateRange = true;
2866 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 2866 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
2867 } 2867 }
2868 } 2868 }
2869 // fullDateRange = true; // debug only! 2869 // fullDateRange = true; // debug only!
2870 if ( fullDateRange ) 2870 if ( fullDateRange )
2871 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 2871 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
2872 else 2872 else
2873 mLastSync = syncItemLocal->lastSyncDate; 2873 mLastSync = syncItemLocal->lastSyncDate;
2874 2874
2875 2875
2876 qDebug("*************************** "); 2876 qDebug("*************************** ");
2877 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2877 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2878 QStringList er = syncRemote->getIDEntryList(); 2878 QStringList er = syncRemote->getIDEntryList();
2879 PwMDataItem* inRemote ;//= er.first(); 2879 PwMDataItem* inRemote ;//= er.first();
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 }
2916 } 2919 }
2917 } else { // no conflict 2920 } else { // no conflict
2918 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 2921 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
2919 inRemote->meta.update = modifiedSync; 2922 inRemote->meta.update = modifiedSync;
2920 //US syncRemote->insertAddressee( inRemote, false ); 2923 //US syncRemote->insertAddressee( inRemote, false );
2921 //US syncLocal->insertAddressee( inRemote, false ); 2924 //US syncLocal->insertAddressee( inRemote, false );
2922 syncLocal->addEntry("newcategory", inRemote, true, false); 2925 syncLocal->addEntry("newcategory", inRemote, true, false);
2923 2926
2924 ++addedPasswordsLocal; 2927 ++addedPasswordsLocal;
2925 } else { 2928 } else {
2926 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2929 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2927 syncRemote->delEntry(catRemote, indexRemote, true); 2930 syncRemote->delEntry(catRemote, indexRemote, true);
2928 //USsyncRemote->removeAddressee( inRemote ); 2931 //USsyncRemote->removeAddressee( inRemote );
2929 ++deletedPasswordsRemote; 2932 ++deletedPasswordsRemote;
2930 } 2933 }
2931 } 2934 }
2932 2935
2933 ++incCounter; 2936 ++incCounter;
2934 } 2937 }
2935 2938
2936 2939
2937 er.clear(); 2940 er.clear();
2938 QStringList el = syncLocal->getIDEntryList(); 2941 QStringList el = syncLocal->getIDEntryList();
2939 modulo = (el.count()/10)+1; 2942 modulo = (el.count()/10)+1;
2940 2943
2941 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2944 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2942 incCounter = 0; 2945 incCounter = 0;
2943 while ( incCounter < el.count()) { 2946 while ( incCounter < el.count()) {
2944 qApp->processEvents(); 2947 qApp->processEvents();
2945 if (manager->isProgressBarCanceled()) 2948 if (manager->isProgressBarCanceled())
2946 return e_syncError; 2949 return e_syncError;
2947 if ( incCounter % modulo == 0 ) 2950 if ( incCounter % modulo == 0 )
@@ -3049,116 +3052,145 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime
3049 if ( lastSync > remoteMod ) 3052 if ( lastSync > remoteMod )
3050 return 1; 3053 return 1;
3051 if ( lastSync > localMod ) 3054 if ( lastSync > localMod )
3052 return 2; 3055 return 2;
3053 return 2; 3056 return 2;
3054 break; 3057 break;
3055 case SYNC_PREF_NEWEST: 3058 case SYNC_PREF_NEWEST:
3056 if ( localMod > remoteMod ) 3059 if ( localMod > remoteMod )
3057 return 1; 3060 return 1;
3058 else 3061 else
3059 return 2; 3062 return 2;
3060 break; 3063 break;
3061 case SYNC_PREF_ASK: 3064 case SYNC_PREF_ASK:
3062 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3065 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3063 if ( lastSync > remoteMod ) 3066 if ( lastSync > remoteMod )
3064 return 1; 3067 return 1;
3065 if ( lastSync > localMod ) 3068 if ( lastSync > localMod )
3066 return 2; 3069 return 2;
3067 localIsNew = localMod >= remoteMod; 3070 localIsNew = localMod >= remoteMod;
3068 //qDebug("conflict! ************************************** "); 3071 //qDebug("conflict! ************************************** ");
3069 { 3072 {
3070 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3073 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3071 result = acd.executeD(localIsNew); 3074 result = acd.executeD(localIsNew);
3072 return result; 3075 return result;
3073 } 3076 }
3074 break; 3077 break;
3075 case SYNC_PREF_FORCE_LOCAL: 3078 case SYNC_PREF_FORCE_LOCAL:
3076 return 1; 3079 return 1;
3077 break; 3080 break;
3078 case SYNC_PREF_FORCE_REMOTE: 3081 case SYNC_PREF_FORCE_REMOTE:
3079 return 2; 3082 return 2;
3080 break; 3083 break;
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
3133//called by the syncmanager to ask if the dirty flag is set. 3165//called by the syncmanager to ask if the dirty flag is set.
3134bool PwMDoc::sync_isModified() 3166bool PwMDoc::sync_isModified()
3135{ 3167{
3136 return isDirty(); 3168 return isDirty();
3137} 3169}
3138 3170
3139//called by the syncmanager to indicate that the work has to be saved. 3171//called by the syncmanager to indicate that the work has to be saved.
3140void PwMDoc::sync_save() 3172void PwMDoc::sync_save()
3141{ 3173{
3142 saveDoc(conf()->confGlobCompression()); 3174 saveDoc(conf()->confGlobCompression());
3143} 3175}
3144#endif 3176#endif
3145 3177
3146 3178
3147bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3179bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3148{ 3180{
3149 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3181 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3150 end = dti.syncDta.end(); 3182 end = dti.syncDta.end();
3151 3183
3152 while (i != end) { 3184 while (i != end) {
3153 if ((*i).syncName == syncname.latin1()) { 3185 if ((*i).syncName == syncname.latin1()) {
3154 if (index) { 3186 if (index) {
3155 *index = i - dti.syncDta.begin(); 3187 *index = i - dti.syncDta.begin();
3156 } 3188 }
3157 return true; 3189 return true;
3158 } 3190 }
3159 ++i; 3191 ++i;
3160 } 3192 }
3161 return false; 3193 return false;
3162}; 3194};
3163 3195
3164/** add new syncdataentry */ 3196/** add new syncdataentry */