summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-29 01:27:31 (UTC)
committer ulf69 <ulf69>2004-10-29 01:27:31 (UTC)
commitf8dd437160acec2959c462dd43d87f2a0920c0b9 (patch) (unidiff)
treeddd271930f54adc1b7220d534f682f616efeb20a
parent1b8d173d880e8f681bca88220bdd806a95d3c2a0 (diff)
downloadkdepimpi-f8dd437160acec2959c462dd43d87f2a0920c0b9.zip
kdepimpi-f8dd437160acec2959c462dd43d87f2a0920c0b9.tar.gz
kdepimpi-f8dd437160acec2959c462dd43d87f2a0920c0b9.tar.bz2
enabling/disabling syncing of launcher
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp10
-rw-r--r--pwmanager/pwmanager/pwmdoc.h20
2 files changed, 24 insertions, 6 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index fd17ce5..9043acc 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2975,96 +2975,98 @@ QString PwMDoc::getTitle()
2975 return title; 2975 return title;
2976} 2976}
2977 2977
2978bool PwMDoc::tryDelete() 2978bool PwMDoc::tryDelete()
2979{ 2979{
2980 2980
2981 if (deleted) 2981 if (deleted)
2982 return true; 2982 return true;
2983 int ret; 2983 int ret;
2984 if (isDirty()) { 2984 if (isDirty()) {
2985 ret = dirtyAskSave(getTitle()); 2985 ret = dirtyAskSave(getTitle());
2986 if (ret == 0) { // save to disk 2986 if (ret == 0) { // save to disk
2987 if (!saveDocUi(this)) 2987 if (!saveDocUi(this))
2988 goto out_ignore; 2988 goto out_ignore;
2989 } else if (ret == 1) { // don't save and delete 2989 } else if (ret == 1) { // don't save and delete
2990 goto out_accept; 2990 goto out_accept;
2991 } else { // cancel operation 2991 } else { // cancel operation
2992 goto out_ignore; 2992 goto out_ignore;
2993 } 2993 }
2994 } 2994 }
2995out_accept: 2995out_accept:
2996 deleted = true; 2996 deleted = true;
2997 delete this; 2997 delete this;
2998 return true; 2998 return true;
2999out_ignore: 2999out_ignore:
3000 return false; 3000 return false;
3001} 3001}
3002 3002
3003 3003
3004 3004
3005#ifdef PWM_EMBEDDED 3005#ifdef PWM_EMBEDDED
3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc
3007//US it could have been defined as static, but I did not want to. 3007//US it could have been defined as static, but I did not want to.
3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3009{ 3009{
3010 int addedPasswordsLocal = 0; 3010 int addedPasswordsLocal = 0;
3011 int addedPasswordsRemote = 0; 3011 int addedPasswordsRemote = 0;
3012 int deletedPasswordsRemote = 0; 3012 int deletedPasswordsRemote = 0;
3013 int deletedPasswordsLocal = 0; 3013 int deletedPasswordsLocal = 0;
3014 int changedLocal = 0; 3014 int changedLocal = 0;
3015 int changedRemote = 0; 3015 int changedRemote = 0;
3016 3016
3017 PwMSyncItem* syncItemLocal; 3017 PwMSyncItem* syncItemLocal;
3018 PwMSyncItem* syncItemRemote; 3018 PwMSyncItem* syncItemRemote;
3019 3019
3020 QString mCurrentSyncName = manager->getCurrentSyncName(); 3020 QString mCurrentSyncName = manager->getCurrentSyncName();
3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3022 3022
3023 bool mSyncLauncher = true;
3024
3023 bool fullDateRange = false; 3025 bool fullDateRange = false;
3024 int take; 3026 int take;
3025 // local->resetTempSyncStat(); 3027 // local->resetTempSyncStat();
3026 QDateTime mLastSync = QDateTime::currentDateTime(); 3028 QDateTime mLastSync = QDateTime::currentDateTime();
3027 QDateTime modifiedSync = mLastSync; 3029 QDateTime modifiedSync = mLastSync;
3028 3030
3029 unsigned int index; 3031 unsigned int index;
3030 //Step 1. Find syncinfo in Local file and create if not existent. 3032 //Step 1. Find syncinfo in Local file and create if not existent.
3031 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3033 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3032 if (found == false) 3034 if (found == false)
3033 { 3035 {
3034 PwMSyncItem newSyncItemLocal; 3036 PwMSyncItem newSyncItemLocal;
3035 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3037 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3036 newSyncItemLocal.lastSyncDate = mLastSync; 3038 newSyncItemLocal.lastSyncDate = mLastSync;
3037 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3039 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3038 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3040 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3039 if (found == false) { 3041 if (found == false) {
3040 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3042 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3041 return e_syncError; 3043 return e_syncError;
3042 } 3044 }
3043 } 3045 }
3044 3046
3045 syncItemLocal = syncLocal->getSyncDataEntry(index); 3047 syncItemLocal = syncLocal->getSyncDataEntry(index);
3046 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3048 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3047 3049
3048 //Step 2. Find syncinfo in remote file and create if not existent. 3050 //Step 2. Find syncinfo in remote file and create if not existent.
3049 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3051 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3050 if (found == false) 3052 if (found == false)
3051 { 3053 {
3052 qDebug("FULLDATE 1"); 3054 qDebug("FULLDATE 1");
3053 fullDateRange = true; 3055 fullDateRange = true;
3054 PwMSyncItem newSyncItemRemote; 3056 PwMSyncItem newSyncItemRemote;
3055 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3057 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3056 newSyncItemRemote.lastSyncDate = mLastSync; 3058 newSyncItemRemote.lastSyncDate = mLastSync;
3057 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3059 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3058 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3060 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3059 if (found == false) { 3061 if (found == false) {
3060 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3062 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3061 return e_syncError; 3063 return e_syncError;
3062 } 3064 }
3063 } 3065 }
3064 3066
3065 syncItemRemote = syncRemote->getSyncDataEntry(index); 3067 syncItemRemote = syncRemote->getSyncDataEntry(index);
3066 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3068 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3067 //and remove the found entry here. We will reenter it later again. 3069 //and remove the found entry here. We will reenter it later again.
3068 //US syncRemote->delSyncDataEntry(index, true); 3070 //US syncRemote->delSyncDataEntry(index, true);
3069 3071
3070 3072
@@ -3075,104 +3077,100 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
3075 3077
3076 if ( ! fullDateRange ) { 3078 if ( ! fullDateRange ) {
3077 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3079 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3078 3080
3079 fullDateRange = true; 3081 fullDateRange = true;
3080 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3082 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3081 } 3083 }
3082 } 3084 }
3083 // fullDateRange = true; // debug only! 3085 // fullDateRange = true; // debug only!
3084 if ( fullDateRange ) 3086 if ( fullDateRange )
3085 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3087 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3086 else 3088 else
3087 mLastSync = syncItemLocal->lastSyncDate; 3089 mLastSync = syncItemLocal->lastSyncDate;
3088 3090
3089 3091
3090 qDebug("*************************** "); 3092 qDebug("*************************** ");
3091 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3093 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3092 QStringList er = syncRemote->getIDEntryList(); 3094 QStringList er = syncRemote->getIDEntryList();
3093 PwMDataItem* inRemote ;//= er.first(); 3095 PwMDataItem* inRemote ;//= er.first();
3094 PwMDataItem* inLocal; 3096 PwMDataItem* inLocal;
3095 unsigned int catLocal, indexLocal; 3097 unsigned int catLocal, indexLocal;
3096 unsigned int catRemote, indexRemote; 3098 unsigned int catRemote, indexRemote;
3097 3099
3098 QString uid; 3100 QString uid;
3099 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3101 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3100 3102
3101 int modulo = (er.count()/10)+1; 3103 int modulo = (er.count()/10)+1;
3102 unsigned int incCounter = 0; 3104 unsigned int incCounter = 0;
3103 while ( incCounter < er.count()) { 3105 while ( incCounter < er.count()) {
3104 if (manager->isProgressBarCanceled()) 3106 if (manager->isProgressBarCanceled())
3105 return e_syncError; 3107 return e_syncError;
3106 if ( incCounter % modulo == 0 ) 3108 if ( incCounter % modulo == 0 )
3107 manager->showProgressBar(incCounter); 3109 manager->showProgressBar(incCounter);
3108 3110
3109 uid = er[ incCounter ]; 3111 uid = er[ incCounter ];
3110 qDebug("sync uid %s from remote file", uid.latin1()); 3112 qDebug("sync uid %s from remote file", uid.latin1());
3111 3113
3112 qApp->processEvents(); 3114 qApp->processEvents();
3113 3115
3114 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3116 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3115 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3117 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3116 PWM_ASSERT(inRemote); 3118 PWM_ASSERT(inRemote);
3117 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3119 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3118 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3120 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3119 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3121 qDebug("take %d %s ", take, inLocal->desc.c_str());
3120 if ( take == 3 ) 3122 if ( take == 3 )
3121 return e_syncError; 3123 return e_syncError;
3122 if ( take == 1 ) {// take local 3124 if ( take == 1 ) {// take local
3123 int oldlistpos = inRemote->listViewPos; 3125 inRemote->syncItem(*inLocal, mSyncLauncher);
3124 (*inRemote) = (*inLocal);
3125 inRemote->listViewPos = oldlistpos;
3126 ++changedRemote; 3126 ++changedRemote;
3127 } else { // take == 2 take remote 3127 } else { // take == 2 take remote
3128 int oldlistpos = inLocal->listViewPos; 3128 inLocal->syncItem(*inRemote, mSyncLauncher);
3129 (*inLocal) = (*inRemote);
3130 inLocal->listViewPos = oldlistpos;
3131 ++changedLocal; 3129 ++changedLocal;
3132 } 3130 }
3133 } 3131 }
3134 } else { // no conflict 3132 } else { // no conflict
3135 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3133 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3136 inRemote->meta.update = modifiedSync; 3134 inRemote->meta.update = modifiedSync;
3137 3135
3138 //first check if we have a matching category in the local file 3136 //first check if we have a matching category in the local file
3139 const string* remotecat = syncRemote->getCategory(catRemote); 3137 const string* remotecat = syncRemote->getCategory(catRemote);
3140 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3138 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3141 3139
3142 ++addedPasswordsLocal; 3140 ++addedPasswordsLocal;
3143 } else { 3141 } else {
3144 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3142 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3145 syncRemote->delEntry(catRemote, indexRemote, true); 3143 syncRemote->delEntry(catRemote, indexRemote, true);
3146 ++deletedPasswordsRemote; 3144 ++deletedPasswordsRemote;
3147 } 3145 }
3148 } 3146 }
3149 3147
3150 ++incCounter; 3148 ++incCounter;
3151 } 3149 }
3152 3150
3153 3151
3154 er.clear(); 3152 er.clear();
3155 QStringList el = syncLocal->getIDEntryList(); 3153 QStringList el = syncLocal->getIDEntryList();
3156 modulo = (el.count()/10)+1; 3154 modulo = (el.count()/10)+1;
3157 3155
3158 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3156 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3159 incCounter = 0; 3157 incCounter = 0;
3160 while ( incCounter < el.count()) { 3158 while ( incCounter < el.count()) {
3161 qApp->processEvents(); 3159 qApp->processEvents();
3162 if (manager->isProgressBarCanceled()) 3160 if (manager->isProgressBarCanceled())
3163 return e_syncError; 3161 return e_syncError;
3164 if ( incCounter % modulo == 0 ) 3162 if ( incCounter % modulo == 0 )
3165 manager->showProgressBar(incCounter); 3163 manager->showProgressBar(incCounter);
3166 uid = el[ incCounter ]; 3164 uid = el[ incCounter ];
3167 qDebug("sync uid %s from local file", uid.latin1()); 3165 qDebug("sync uid %s from local file", uid.latin1());
3168 3166
3169 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3167 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3170 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3168 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3171 PWM_ASSERT(inLocal); 3169 PWM_ASSERT(inLocal);
3172 3170
3173 if ( inRemote == 0 ) { 3171 if ( inRemote == 0 ) {
3174 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3172 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3175 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3173 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3176 syncLocal->delEntry(catLocal, indexLocal, true); 3174 syncLocal->delEntry(catLocal, indexLocal, true);
3177 ++deletedPasswordsLocal; 3175 ++deletedPasswordsLocal;
3178 } else { 3176 } else {
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index e419c24..09923ab 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -179,96 +179,116 @@ struct PwMDataItem
179 boollockStat; 179 boollockStat;
180 /** position of this item in main "list-view" 180 /** position of this item in main "list-view"
181 * If -1, the position is not yet specified and should be appended to the list 181 * If -1, the position is not yet specified and should be appended to the list
182 */ 182 */
183 intlistViewPos; 183 intlistViewPos;
184 /** does this entry contain binary data? */ 184 /** does this entry contain binary data? */
185 bool binary; 185 bool binary;
186 /** meta data for this data item. */ 186 /** meta data for this data item. */
187 PwMMetaData meta; 187 PwMMetaData meta;
188 /** data revision counter. This counter can be used 188 /** data revision counter. This counter can be used
189 * to easily, efficiently determine if this data item 189 * to easily, efficiently determine if this data item
190 * has changed since some time. 190 * has changed since some time.
191 * This counter is incremented on every update. 191 * This counter is incremented on every update.
192 */ 192 */
193 unsigned int rev; 193 unsigned int rev;
194 194
195 void clear(bool clearMeta = true) 195 void clear(bool clearMeta = true)
196 { 196 {
197 /* NOTE: Don't use .clear() here to be 197 /* NOTE: Don't use .clear() here to be
198 * backward compatible with gcc-2 (Debian Woody) 198 * backward compatible with gcc-2 (Debian Woody)
199 */ 199 */
200 desc = ""; 200 desc = "";
201 name = ""; 201 name = "";
202 pw = ""; 202 pw = "";
203 comment = ""; 203 comment = "";
204 url = ""; 204 url = "";
205 launcher = ""; 205 launcher = "";
206 lockStat = true; 206 lockStat = true;
207 listViewPos = -1; 207 listViewPos = -1;
208 binary = false; 208 binary = false;
209 if (clearMeta) 209 if (clearMeta)
210 meta.clear(); 210 meta.clear();
211 } 211 }
212 //US ENH: we need this operator to compare two items if we have no unique ids 212 //US ENH: we need this operator to compare two items if we have no unique ids
213 //available. Generaly this happens before the first sync 213 //available. Generaly this happens before the first sync
214 214
215 bool PwMDataItem::operator==( const PwMDataItem &a ) const 215 bool PwMDataItem::operator==( const PwMDataItem &a ) const
216 { 216 {
217 //qDebug("oper==%s", a.desc.c_str()); 217 //qDebug("oper==%s", a.desc.c_str());
218 if ( desc != a.desc ) return false; 218 if ( desc != a.desc ) return false;
219 if ( name != a.name ) return false; 219 if ( name != a.name ) return false;
220 if ( pw != a.pw ) return false; 220 if ( pw != a.pw ) return false;
221 if ( comment != a.comment ) return false; 221 if ( comment != a.comment ) return false;
222 if ( url != a.url ) return false; 222 if ( url != a.url ) return false;
223 if ( launcher != a.launcher ) return false; 223 if ( launcher != a.launcher ) return false;
224 //all other field will not be checked. 224 //all other field will not be checked.
225 return true; 225 return true;
226 } 226 }
227
228 //US ENH: this sync method actually copies all values from the parameter like the =operator
229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required.
230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true )
231 {
232 desc = a.desc;
233 name = a.name;
234 pw = a.pw;
235 comment = a.comment;
236 url = a.url;
237 if (syncLauncher == true)
238 launcher = a.launcher;
239 meta = a.meta;
240 binary = a.binary;
241 lockStat = a.lockStat;
242 rev = a.rev;
243
244 return true;
245 }
246
227}; 247};
228 248
229struct PwMCategoryItem 249struct PwMCategoryItem
230{ 250{
231 /** all PwMDataItems (all passwords) within this category */ 251 /** all PwMDataItems (all passwords) within this category */
232 vector<PwMDataItem>d; 252 vector<PwMDataItem>d;
233 /** category name/description */ 253 /** category name/description */
234 string name; 254 string name;
235 255
236 void clear() 256 void clear()
237 { 257 {
238 d.clear(); 258 d.clear();
239 name = ""; 259 name = "";
240 } 260 }
241}; 261};
242 262
243struct PwMSyncItem 263struct PwMSyncItem
244{ 264{
245 string syncName; 265 string syncName;
246 QDateTime lastSyncDate; 266 QDateTime lastSyncDate;
247 267
248 void clear() 268 void clear()
249 { 269 {
250 lastSyncDate = QDateTime(); 270 lastSyncDate = QDateTime();
251 syncName = ""; 271 syncName = "";
252 } 272 }
253}; 273};
254 274
255struct PwMItem 275struct PwMItem
256{ 276{
257 vector<PwMCategoryItem> dta; 277 vector<PwMCategoryItem> dta;
258 vector<PwMSyncItem> syncDta; 278 vector<PwMSyncItem> syncDta;
259 279
260 void clear() 280 void clear()
261 { 281 {
262 dta.clear(); 282 dta.clear();
263 syncDta.clear(); 283 syncDta.clear();
264 } 284 }
265}; 285};
266 286
267 287
268/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 288/** "Function Object" for sort()ing PwMDataItem::listViewPos */
269class dta_lvp_greater 289class dta_lvp_greater
270{ 290{
271public: 291public:
272 bool operator() (const pair<unsigned int, unsigned int> &d1, 292 bool operator() (const pair<unsigned int, unsigned int> &d1,
273 const pair<unsigned int, unsigned int> &d2) 293 const pair<unsigned int, unsigned int> &d2)
274 { 294 {