summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp22
-rw-r--r--pwmanager/pwmanager/pwmdoc.h4
2 files changed, 25 insertions, 1 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index ddbf4f2..17cb74a 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -3120,385 +3120,405 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
3120 3120
3121 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3121 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3122 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3122 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3123 PWM_ASSERT(inRemote); 3123 PWM_ASSERT(inRemote);
3124 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3124 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3125 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3125 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3126 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3126 qDebug("take %d %s ", take, inLocal->desc.c_str());
3127 if ( take == 3 ) 3127 if ( take == 3 )
3128 return e_syncError; 3128 return e_syncError;
3129 if ( take == 1 ) {// take local 3129 if ( take == 1 ) {// take local
3130 inRemote->syncItem(*inLocal, mSyncLauncher); 3130 inRemote->syncItem(*inLocal, mSyncLauncher);
3131 ++changedRemote; 3131 ++changedRemote;
3132 } else { // take == 2 take remote 3132 } else { // take == 2 take remote
3133 inLocal->syncItem(*inRemote, mSyncLauncher); 3133 inLocal->syncItem(*inRemote, mSyncLauncher);
3134 ++changedLocal; 3134 ++changedLocal;
3135 } 3135 }
3136 } 3136 }
3137 } else { // no conflict 3137 } else { // no conflict
3138 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3138 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3139 inRemote->meta.update = modifiedSync; 3139 inRemote->meta.update = modifiedSync;
3140 3140
3141 //first check if we have a matching category in the local file 3141 //first check if we have a matching category in the local file
3142 const string* remotecat = syncRemote->getCategory(catRemote); 3142 const string* remotecat = syncRemote->getCategory(catRemote);
3143 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3143 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3144 3144
3145 ++addedPasswordsLocal; 3145 ++addedPasswordsLocal;
3146 } else { 3146 } else {
3147 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3147 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3148 syncRemote->delEntry(catRemote, indexRemote, true); 3148 syncRemote->delEntry(catRemote, indexRemote, true);
3149 ++deletedPasswordsRemote; 3149 ++deletedPasswordsRemote;
3150 } 3150 }
3151 } 3151 }
3152 3152
3153 ++incCounter; 3153 ++incCounter;
3154 } 3154 }
3155 3155
3156 3156
3157 er.clear(); 3157 er.clear();
3158 QStringList el = syncLocal->getIDEntryList(); 3158 QStringList el = syncLocal->getIDEntryList();
3159 modulo = (el.count()/10)+1; 3159 modulo = (el.count()/10)+1;
3160 3160
3161 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3161 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3162 incCounter = 0; 3162 incCounter = 0;
3163 while ( incCounter < el.count()) { 3163 while ( incCounter < el.count()) {
3164 qApp->processEvents(); 3164 qApp->processEvents();
3165 if (manager->isProgressBarCanceled()) 3165 if (manager->isProgressBarCanceled())
3166 return e_syncError; 3166 return e_syncError;
3167 if ( incCounter % modulo == 0 ) 3167 if ( incCounter % modulo == 0 )
3168 manager->showProgressBar(incCounter); 3168 manager->showProgressBar(incCounter);
3169 uid = el[ incCounter ]; 3169 uid = el[ incCounter ];
3170 qDebug("sync uid %s from local file", uid.latin1()); 3170 qDebug("sync uid %s from local file", uid.latin1());
3171 3171
3172 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3172 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3173 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3173 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3174 PWM_ASSERT(inLocal); 3174 PWM_ASSERT(inLocal);
3175 3175
3176 if ( inRemote == 0 ) { 3176 if ( inRemote == 0 ) {
3177 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3177 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3178 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3178 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3179 syncLocal->delEntry(catLocal, indexLocal, true); 3179 syncLocal->delEntry(catLocal, indexLocal, true);
3180 ++deletedPasswordsLocal; 3180 ++deletedPasswordsLocal;
3181 } else { 3181 } else {
3182 if ( ! manager->mWriteBackExistingOnly ) { 3182 if ( ! manager->mWriteBackExistingOnly ) {
3183 ++addedPasswordsRemote; 3183 ++addedPasswordsRemote;
3184 inLocal->meta.update = modifiedSync; 3184 inLocal->meta.update = modifiedSync;
3185 3185
3186 //first check if we have a matching category in the remote file 3186 //first check if we have a matching category in the remote file
3187 const string* localcat = syncLocal->getCategory(catLocal); 3187 const string* localcat = syncLocal->getCategory(catLocal);
3188 3188
3189 PwMDataItem newEntry; 3189 PwMDataItem newEntry;
3190 newEntry = *inLocal; 3190 newEntry = *inLocal;
3191 inRemote = &newEntry; 3191 inRemote = &newEntry;
3192 3192
3193 //USsyncRemote->insertAddressee( inRemote, false ); 3193 //USsyncRemote->insertAddressee( inRemote, false );
3194 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3194 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3195 3195
3196 } 3196 }
3197 } 3197 }
3198 3198
3199 } 3199 }
3200 ++incCounter; 3200 ++incCounter;
3201 } 3201 }
3202 el.clear(); 3202 el.clear();
3203 manager->hideProgressBar(); 3203 manager->hideProgressBar();
3204 3204
3205 // Now write the info back into the sync data space of the files 3205 // Now write the info back into the sync data space of the files
3206 3206
3207 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3207 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3208 // get rid of micro seconds 3208 // get rid of micro seconds
3209 QTime t = mLastSync.time(); 3209 QTime t = mLastSync.time();
3210 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3210 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3211 3211
3212 3212
3213 syncItemLocal->lastSyncDate = mLastSync; 3213 syncItemLocal->lastSyncDate = mLastSync;
3214 syncItemRemote->lastSyncDate = mLastSync; 3214 syncItemRemote->lastSyncDate = mLastSync;
3215 3215
3216 QString mes; 3216 QString mes;
3217 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote ); 3217 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
3218 if ( manager->mShowSyncSummary ) { 3218 if ( manager->mShowSyncSummary ) {
3219 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3219 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3220 } 3220 }
3221 qDebug( mes ); 3221 qDebug( mes );
3222 return e_success; 3222 return e_success;
3223} 3223}
3224 3224
3225 3225
3226int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3226int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3227{ 3227{
3228 // 0 equal 3228 // 0 equal
3229 // 1 take local 3229 // 1 take local
3230 // 2 take remote 3230 // 2 take remote
3231 // 3 cancel 3231 // 3 cancel
3232 QDateTime localMod = local->meta.update; 3232 QDateTime localMod = local->meta.update;
3233 QDateTime remoteMod = remote->meta.update; 3233 QDateTime remoteMod = remote->meta.update;
3234 3234
3235 if ( localMod == remoteMod ) 3235 if ( localMod == remoteMod )
3236 return 0; 3236 return 0;
3237 3237
3238 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3238 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3239 3239
3240 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3240 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3241 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3241 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3242 //full = true; //debug only 3242 //full = true; //debug only
3243 if ( full ) { 3243 if ( full ) {
3244 bool equ = ( (*local) == (*remote) ); 3244 bool equ = ( (*local) == (*remote) );
3245 if ( equ ) { 3245 if ( equ ) {
3246 //qDebug("equal "); 3246 //qDebug("equal ");
3247 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3247 if ( mode < SYNC_PREF_FORCE_LOCAL )
3248 return 0; 3248 return 0;
3249 3249
3250 }//else //debug only 3250 }//else //debug only
3251 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3251 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3252 } 3252 }
3253 3253
3254 int result; 3254 int result;
3255 bool localIsNew; 3255 bool localIsNew;
3256 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); 3256 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() );
3257 3257
3258 if ( full && mode < SYNC_PREF_NEWEST ) 3258 if ( full && mode < SYNC_PREF_NEWEST )
3259 mode = SYNC_PREF_ASK; 3259 mode = SYNC_PREF_ASK;
3260 3260
3261 switch( mode ) { 3261 switch( mode ) {
3262 case SYNC_PREF_LOCAL: 3262 case SYNC_PREF_LOCAL:
3263 if ( lastSync > remoteMod ) 3263 if ( lastSync > remoteMod )
3264 return 1; 3264 return 1;
3265 if ( lastSync > localMod ) 3265 if ( lastSync > localMod )
3266 return 2; 3266 return 2;
3267 return 1; 3267 return 1;
3268 break; 3268 break;
3269 case SYNC_PREF_REMOTE: 3269 case SYNC_PREF_REMOTE:
3270 if ( lastSync > remoteMod ) 3270 if ( lastSync > remoteMod )
3271 return 1; 3271 return 1;
3272 if ( lastSync > localMod ) 3272 if ( lastSync > localMod )
3273 return 2; 3273 return 2;
3274 return 2; 3274 return 2;
3275 break; 3275 break;
3276 case SYNC_PREF_NEWEST: 3276 case SYNC_PREF_NEWEST:
3277 if ( localMod > remoteMod ) 3277 if ( localMod > remoteMod )
3278 return 1; 3278 return 1;
3279 else 3279 else
3280 return 2; 3280 return 2;
3281 break; 3281 break;
3282 case SYNC_PREF_ASK: 3282 case SYNC_PREF_ASK:
3283 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3283 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3284 if ( lastSync > remoteMod ) 3284 if ( lastSync > remoteMod )
3285 return 1; 3285 return 1;
3286 if ( lastSync > localMod ) 3286 if ( lastSync > localMod )
3287 return 2; 3287 return 2;
3288 localIsNew = localMod >= remoteMod; 3288 localIsNew = localMod >= remoteMod;
3289 //qDebug("conflict! ************************************** "); 3289 //qDebug("conflict! ************************************** ");
3290 { 3290 {
3291 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3291 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3292 result = acd.executeD(localIsNew); 3292 result = acd.executeD(localIsNew);
3293 return result; 3293 return result;
3294 } 3294 }
3295 break; 3295 break;
3296 case SYNC_PREF_FORCE_LOCAL: 3296 case SYNC_PREF_FORCE_LOCAL:
3297 return 1; 3297 return 1;
3298 break; 3298 break;
3299 case SYNC_PREF_FORCE_REMOTE: 3299 case SYNC_PREF_FORCE_REMOTE:
3300 return 2; 3300 return 2;
3301 break; 3301 break;
3302 3302
3303 default: 3303 default:
3304 // SYNC_PREF_TAKE_BOTH not implemented 3304 // SYNC_PREF_TAKE_BOTH not implemented
3305 break; 3305 break;
3306 } 3306 }
3307 return 0; 3307 return 0;
3308} 3308}
3309 3309
3310void PwMDoc::removeSyncInfo( QString syncProfile) 3310void PwMDoc::removeSyncInfo( QString syncProfile)
3311{ 3311{
3312 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); 3312 bool res, found;
3313 unsigned int count, i;
3314 if ( syncProfile.isEmpty() ) {
3315 count = numSyncDataEntries();
3316 for (i = count; count > 0; count-- ) {
3317 res = delSyncDataEntry(i-1, false);
3318 if (res == false) {
3319 qDebug("PwMDoc::removeSyncInfo: could not remove syncprofile");
3320 }
3321 }
3322 } else {
3323 found = findSyncData(syncProfile, &count);
3324 if (found == true)
3325 {
3326 res = delSyncDataEntry(count, false);
3327 if (res == false) {
3328 qDebug("PwMDoc::removeSyncInfo: could not remove %s", syncProfile.latin1());
3329
3330 }
3331 }
3332 }
3313} 3333}
3314 3334
3315 3335
3316//this are the overwritten callbackmethods from the syncinterface 3336//this are the overwritten callbackmethods from the syncinterface
3317bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3337bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3318{ 3338{
3319 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3339 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3320 3340
3321 //1) unlock local file first if necessary (ask for password) 3341 //1) unlock local file first if necessary (ask for password)
3322 if (this->isDeepLocked()) { 3342 if (this->isDeepLocked()) {
3323 PwMerror ret = this->deepLock(false); 3343 PwMerror ret = this->deepLock(false);
3324 if (ret != e_success) 3344 if (ret != e_success)
3325 return false; 3345 return false;
3326 } 3346 }
3327 3347
3328 //2) construct and open a new doc on the stack(automatic cleanup of remote file). 3348 //2) construct and open a new doc on the stack(automatic cleanup of remote file).
3329 PwMDoc syncTarget(this, "synctarget"); 3349 PwMDoc syncTarget(this, "synctarget");
3330 PwMDoc* pSyncTarget = &syncTarget; 3350 PwMDoc* pSyncTarget = &syncTarget;
3331 3351
3332 3352
3333 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); 3353 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3334 3354
3335 if (err == e_alreadyOpen) { 3355 if (err == e_alreadyOpen) {
3336 PwMDocList::listItem li; 3356 PwMDocList::listItem li;
3337 if (getOpenDocList()->find(filename.latin1(), &li)) 3357 if (getOpenDocList()->find(filename.latin1(), &li))
3338 pSyncTarget = li.doc; 3358 pSyncTarget = li.doc;
3339 else { 3359 else {
3340 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3360 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3341 return false; 3361 return false;
3342 } 3362 }
3343 } 3363 }
3344 else if (err != e_success) { 3364 else if (err != e_success) {
3345 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1()); 3365 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3346 return false; 3366 return false;
3347 } 3367 }
3348 3368
3349 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3369 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3350 3370
3351 3371
3352 //3) unlock remote file first if necessary (ask for password) 3372 //3) unlock remote file first if necessary (ask for password)
3353 if (pSyncTarget->isDeepLocked()) { 3373 if (pSyncTarget->isDeepLocked()) {
3354 PwMerror ret = pSyncTarget->deepLock(false); 3374 PwMerror ret = pSyncTarget->deepLock(false);
3355 if (ret != e_success) 3375 if (ret != e_success)
3356 return false; 3376 return false;
3357 } 3377 }
3358 3378
3359 3379
3360 err = syncronize(manager, this, pSyncTarget, mode ); 3380 err = syncronize(manager, this, pSyncTarget, mode );
3361 3381
3362 if (err == e_success) { 3382 if (err == e_success) {
3363 if ( manager->mWriteBackFile ){ 3383 if ( manager->mWriteBackFile ){
3364 qDebug("Saving remote PWManager file"); 3384 qDebug("Saving remote PWManager file");
3365 err = pSyncTarget->saveDoc(conf()->confGlobCompression()); 3385 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3366 if (err != e_success) { 3386 if (err != e_success) {
3367 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1()); 3387 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3368 return false; 3388 return false;
3369 } 3389 }
3370 } 3390 }
3371 3391
3372 flagDirty(); 3392 flagDirty();
3373 return true; 3393 return true;
3374 } 3394 }
3375 else { 3395 else {
3376 return false; 3396 return false;
3377 } 3397 }
3378} 3398}
3379 3399
3380#endif 3400#endif
3381 3401
3382 3402
3383bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3403bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3384{ 3404{
3385 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3405 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3386 end = dti.syncDta.end(); 3406 end = dti.syncDta.end();
3387 3407
3388 while (i != end) { 3408 while (i != end) {
3389 if ((*i).syncName == syncname.latin1()) { 3409 if ((*i).syncName == syncname.latin1()) {
3390 if (index) { 3410 if (index) {
3391 *index = i - dti.syncDta.begin(); 3411 *index = i - dti.syncDta.begin();
3392 } 3412 }
3393 return true; 3413 return true;
3394 } 3414 }
3395 ++i; 3415 ++i;
3396 } 3416 }
3397 return false; 3417 return false;
3398}; 3418};
3399 3419
3400/** add new syncdataentry */ 3420/** add new syncdataentry */
3401PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3421PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3402{ 3422{
3403 PWM_ASSERT(d); 3423 PWM_ASSERT(d);
3404 3424
3405 if (isDeepLocked()) { 3425 if (isDeepLocked()) {
3406 PwMerror ret; 3426 PwMerror ret;
3407 ret = deepLock(false); 3427 ret = deepLock(false);
3408 if (ret != e_success) 3428 if (ret != e_success)
3409 return e_lock; 3429 return e_lock;
3410 } 3430 }
3411 unsigned int index; 3431 unsigned int index;
3412 3432
3413 const QString tmp = d->syncName.c_str(); 3433 const QString tmp = d->syncName.c_str();
3414 bool exists = findSyncData(d->syncName.c_str(), &index); 3434 bool exists = findSyncData(d->syncName.c_str(), &index);
3415 3435
3416 if (exists == true) { 3436 if (exists == true) {
3417 // DOH! We found this entry. 3437 // DOH! We found this entry.
3418 return e_entryExists; 3438 return e_entryExists;
3419 } 3439 }
3420 3440
3421 dti.syncDta.push_back(*d); 3441 dti.syncDta.push_back(*d);
3422 3442
3423 if (!dontFlagDirty) 3443 if (!dontFlagDirty)
3424 flagDirty(); 3444 flagDirty();
3425 return e_success; 3445 return e_success;
3426} 3446}
3427 3447
3428 3448
3429 3449
3430/** delete syncdata entry */ 3450/** delete syncdata entry */
3431bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3451bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3432{ 3452{
3433 if (isDeepLocked()) 3453 if (isDeepLocked())
3434 return false; 3454 return false;
3435 if (index > dti.syncDta.size() - 1) 3455 if (index > dti.syncDta.size() - 1)
3436 return false; 3456 return false;
3437 3457
3438 // delete entry 3458 // delete entry
3439 dti.syncDta.erase(dti.syncDta.begin() + index); 3459 dti.syncDta.erase(dti.syncDta.begin() + index);
3440 3460
3441 if (!dontFlagDirty) 3461 if (!dontFlagDirty)
3442 flagDirty(); 3462 flagDirty();
3443 return true; 3463 return true;
3444} 3464}
3445 3465
3446 3466
3447PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3467PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3448{ 3468{
3449 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3469 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3450 catend = dti.dta.end(); 3470 catend = dti.dta.end();
3451 3471
3452 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3472 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3453 3473
3454 while (catcounter != catend) { 3474 while (catcounter != catend) {
3455 entrBegin = catcounter->d.begin(); 3475 entrBegin = catcounter->d.begin();
3456 entrEnd = catcounter->d.end(); 3476 entrEnd = catcounter->d.end();
3457 entrI = entrBegin; 3477 entrI = entrBegin;
3458 while (entrI != entrEnd) { 3478 while (entrI != entrEnd) {
3459 if ((*entrI).meta.uniqueid == uid.latin1()) { 3479 if ((*entrI).meta.uniqueid == uid.latin1()) {
3460 if (category) 3480 if (category)
3461 *category = catcounter - dti.dta.begin(); 3481 *category = catcounter - dti.dta.begin();
3462 if (index) 3482 if (index)
3463 *index = entrI - entrBegin; 3483 *index = entrI - entrBegin;
3464 3484
3465 return &(*entrI); 3485 return &(*entrI);
3466 } 3486 }
3467 ++entrI; 3487 ++entrI;
3468 } 3488 }
3469 ++catcounter; 3489 ++catcounter;
3470 } 3490 }
3471 3491
3472 return 0; 3492 return 0;
3473} 3493}
3474 3494
3475QStringList PwMDoc::getIDEntryList() 3495QStringList PwMDoc::getIDEntryList()
3476{ 3496{
3477 QStringList results; 3497 QStringList results;
3478 3498
3479 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), 3499 vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(),
3480 catend = dti.dta.end(); 3500 catend = dti.dta.end();
3481 3501
3482 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 3502 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
3483 3503
3484 while (catcounter != catend) { 3504 while (catcounter != catend) {
3485 entrBegin = catcounter->d.begin(); 3505 entrBegin = catcounter->d.begin();
3486 entrEnd = catcounter->d.end(); 3506 entrEnd = catcounter->d.end();
3487 entrI = entrBegin; 3507 entrI = entrBegin;
3488 while (entrI != entrEnd) { 3508 while (entrI != entrEnd) {
3489 results.append( (*entrI).meta.uniqueid.c_str() ); 3509 results.append( (*entrI).meta.uniqueid.c_str() );
3490 ++entrI; 3510 ++entrI;
3491 } 3511 }
3492 ++catcounter; 3512 ++catcounter;
3493 } 3513 }
3494 3514
3495 return results; 3515 return results;
3496} 3516}
3497 3517
3498 3518
3499 3519
3500 3520
3501 3521
3502#ifndef PWM_EMBEDDED 3522#ifndef PWM_EMBEDDED
3503#include "pwmdoc.moc" 3523#include "pwmdoc.moc"
3504#endif 3524#endif
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index ef81dfc..138dd3d 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -625,199 +625,203 @@ public:
625 { listView = _listView; } 625 { listView = _listView; }
626 /** returns the list-view-pointer */ 626 /** returns the list-view-pointer */
627 PwMView * getListViewPointer() 627 PwMView * getListViewPointer()
628 { return listView; } 628 { return listView; }
629 /** try to delete the doc. The user may be asked to save 629 /** try to delete the doc. The user may be asked to save
630 * the data. The user may cancel the whole operation. 630 * the data. The user may cancel the whole operation.
631 * false is returned, then. 631 * false is returned, then.
632 */ 632 */
633 bool tryDelete(); 633 bool tryDelete();
634 /** is the doc deleted? (with tryDelete() ) */ 634 /** is the doc deleted? (with tryDelete() ) */
635 bool isDeleted() 635 bool isDeleted()
636 { return deleted; } 636 { return deleted; }
637 /** returns the document timer object */ 637 /** returns the document timer object */
638 DocTimer * timer() 638 DocTimer * timer()
639 { return _timer; } 639 { return _timer; }
640 /** get a lock on the dataChanged signal. 640 /** get a lock on the dataChanged signal.
641 * If someone is holding a lock, the signal is not emitted. 641 * If someone is holding a lock, the signal is not emitted.
642 */ 642 */
643 void getDataChangedLock() 643 void getDataChangedLock()
644 { ++dataChangedLock; } 644 { ++dataChangedLock; }
645 /** put the dataChanged lock */ 645 /** put the dataChanged lock */
646 void putDataChangedLock() 646 void putDataChangedLock()
647 { --dataChangedLock; } 647 { --dataChangedLock; }
648 /** returns the revision count of the item at cat/index */ 648 /** returns the revision count of the item at cat/index */
649 unsigned int getEntryRevCnt(unsigned int category, unsigned int index) 649 unsigned int getEntryRevCnt(unsigned int category, unsigned int index)
650 { return dti.dta[category].d[index].rev; } 650 { return dti.dta[category].d[index].rev; }
651 /** returns a const pointer to the entries meta */ 651 /** returns a const pointer to the entries meta */
652 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index) 652 const PwMMetaData * getEntryMeta(unsigned int category, unsigned int index)
653 { return &(dti.dta[category].d[index].meta); } 653 { return &(dti.dta[category].d[index].meta); }
654 /** is the entry at "category" "index" a binary entry? */ 654 /** is the entry at "category" "index" a binary entry? */
655 bool isBinEntry(unsigned int category, unsigned int index) 655 bool isBinEntry(unsigned int category, unsigned int index)
656 { return dti.dta[category].d[index].binary; } 656 { return dti.dta[category].d[index].binary; }
657 657
658public slots: 658public slots:
659 /** wrapper for PwMTray */ 659 /** wrapper for PwMTray */
660 void _deepUnlock(); 660 void _deepUnlock();
661 661
662signals: 662signals:
663 /** the data of the document has changed and must be updated 663 /** the data of the document has changed and must be updated
664 * in all views. 664 * in all views.
665 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal! 665 * NOTE: use emitDataChanged(PwMDoc *document) to emit this signal!
666 */ 666 */
667 void dataChanged(PwMDoc *document); 667 void dataChanged(PwMDoc *document);
668 /** the document class is going to close. This signal may be 668 /** the document class is going to close. This signal may be
669 * used to nofify all views, that the user closed the document, 669 * used to nofify all views, that the user closed the document,
670 * so the views can go down, too. 670 * so the views can go down, too.
671 */ 671 */
672 void docClosed(PwMDoc *document); 672 void docClosed(PwMDoc *document);
673 /** somebody just opened the document */ 673 /** somebody just opened the document */
674 void docOpened(PwMDoc *document); 674 void docOpened(PwMDoc *document);
675 /** this document object just got created */ 675 /** this document object just got created */
676 void docCreated(PwMDoc *document); 676 void docCreated(PwMDoc *document);
677 677
678public: 678public:
679 /** emit the dataChanged signal after checking for a lock */ 679 /** emit the dataChanged signal after checking for a lock */
680 void emitDataChanged(PwMDoc *document) 680 void emitDataChanged(PwMDoc *document)
681 { 681 {
682 if (!dataChangedLock) 682 if (!dataChangedLock)
683 emit dataChanged(document); 683 emit dataChanged(document);
684 } 684 }
685 685
686protected: 686protected:
687 /** current file for this doc */ 687 /** current file for this doc */
688 QString filename; 688 QString filename;
689//US ENH: we need a place where we keep the syncentries. So I invented 689//US ENH: we need a place where we keep the syncentries. So I invented
690// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem 690// struct PwMItem, that has a vector of PwMCategoryItem and vector of PwMSyncItem
691 /** holds all data */ 691 /** holds all data */
692 PwMItem dti; 692 PwMItem dti;
693 /** maximum number of entries */ 693 /** maximum number of entries */
694 unsigned int maxEntries; 694 unsigned int maxEntries;
695 /** currently used password to encrypt data */ 695 /** currently used password to encrypt data */
696 QString currentPw; 696 QString currentPw;
697 /** current global document status flags */ 697 /** current global document status flags */
698 unsigned int curDocStat; 698 unsigned int curDocStat;
699 /** browser process for goToURL() */ 699 /** browser process for goToURL() */
700 KProcess browserProc; 700 KProcess browserProc;
701 /** pointer to the list-view, using this document. 701 /** pointer to the list-view, using this document.
702 * As there can only be one list-view per doc, we 702 * As there can only be one list-view per doc, we
703 * don't need a list here. 703 * don't need a list here.
704 */ 704 */
705 PwMView *listView; 705 PwMView *listView;
706 /** unnamedNum is used to store the "unnamed counter" 706 /** unnamedNum is used to store the "unnamed counter"
707 * for this document, while it's unnamed. If it's 0, 707 * for this document, while it's unnamed. If it's 0,
708 * we have to get a new unique one. 708 * we have to get a new unique one.
709 */ 709 */
710 unsigned int unnamedNum; 710 unsigned int unnamedNum;
711 /** is this doc going to be deleted (executing in destructor context) */ 711 /** is this doc going to be deleted (executing in destructor context) */
712 bool deleted; 712 bool deleted;
713 /** document timer */ 713 /** document timer */
714 DocTimer *_timer; 714 DocTimer *_timer;
715 /** lock counter for the "dataChanged" signal */ 715 /** lock counter for the "dataChanged" signal */
716 unsigned int dataChangedLock; 716 unsigned int dataChangedLock;
717 717
718 /** list of all open documents */ 718 /** list of all open documents */
719 static PwMDocList openDocList; 719 static PwMDocList openDocList;
720 720
721protected: 721protected:
722 /** serialize "dta" and return it in "d". */ 722 /** serialize "dta" and return it in "d". */
723 bool serializeDta(string *d); 723 bool serializeDta(string *d);
724 /** de-serialize "d" and overwrite "dta" */ 724 /** de-serialize "d" and overwrite "dta" */
725 bool deSerializeDta(const string *d, bool entriesLocked); 725 bool deSerializeDta(const string *d, bool entriesLocked);
726 /** write header to file */ 726 /** write header to file */
727 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 727 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
728 QString *pw, QFile *f); 728 QString *pw, QFile *f);
729 /** write data-hash to file */ 729 /** write data-hash to file */
730 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 730 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
731 /** check header. Read header info and verify key-hash and filever. 731 /** check header. Read header info and verify key-hash and filever.
732 * returns length of header in "headerLength" */ 732 * returns length of header in "headerLength" */
733 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 733 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
734 unsigned int *headerLength, char *dataHashType, 734 unsigned int *headerLength, char *dataHashType,
735 string *dataHash, QFile *f); 735 string *dataHash, QFile *f);
736 /** check the data-hash */ 736 /** check the data-hash */
737 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 737 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
738 /** encrypt data "d" and write to "filename" */ 738 /** encrypt data "d" and write to "filename" */
739 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); 739 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
740 /** read data from file beginning at "pos", decrypt and return it */ 740 /** read data from file beginning at "pos", decrypt and return it */
741 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); 741 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
742 /** compress the data */ 742 /** compress the data */
743 bool compressDta(string *d, char algo); 743 bool compressDta(string *d, char algo);
744 /** uncompress the data */ 744 /** uncompress the data */
745 bool decompressDta(string *d, char algo); 745 bool decompressDta(string *d, char algo);
746 /** internal import function for a text-file generated by PwM. 746 /** internal import function for a text-file generated by PwM.
747 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 747 * If this is not a valid PwM-exported file, it returns e_fileFormat */
748 PwMerror importText_PwM(const QString *file); 748 PwMerror importText_PwM(const QString *file);
749 /** PwM-text-import helper function to extract the name/pw/comment out 749 /** PwM-text-import helper function to extract the name/pw/comment out
750 * of one entry-line */ 750 * of one entry-line */
751 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 751 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
752 /** compare two strings */ 752 /** compare two strings */
753 bool compareString(const string &s1, const string &s2, bool caseSensitive, 753 bool compareString(const string &s1, const string &s2, bool caseSensitive,
754 bool exactWordMatch); 754 bool exactWordMatch);
755 /** clears all document-data */ 755 /** clears all document-data */
756 void clearDoc(); 756 void clearDoc();
757 /** delete all empty categories */ 757 /** delete all empty categories */
758 void delAllEmptyCat(bool dontFlagDirty); 758 void delAllEmptyCat(bool dontFlagDirty);
759 /** set a document status flag */ 759 /** set a document status flag */
760 void setDocStatFlag(unsigned int statFlag) 760 void setDocStatFlag(unsigned int statFlag)
761 { curDocStat |= statFlag; } 761 { curDocStat |= statFlag; }
762 /** unset a document status flag */ 762 /** unset a document status flag */
763 void unsetDocStatFlag(unsigned int statFlag) 763 void unsetDocStatFlag(unsigned int statFlag)
764 { curDocStat &= ~statFlag; } 764 { curDocStat &= ~statFlag; }
765 /** get a document status flag */ 765 /** get a document status flag */
766 bool getDocStatFlag(unsigned int statFlag) const 766 bool getDocStatFlag(unsigned int statFlag) const
767 { return (curDocStat & statFlag); } 767 { return (curDocStat & statFlag); }
768 /** set the "currentPassword" */ 768 /** set the "currentPassword" */
769 void setCurrentPw(const QString &pw) 769 void setCurrentPw(const QString &pw)
770 { 770 {
771 currentPw = pw; 771 currentPw = pw;
772 setDocStatFlag(DOC_STAT_DISK_DIRTY); 772 setDocStatFlag(DOC_STAT_DISK_DIRTY);
773 } 773 }
774 /** make a backup-copy of the given file */ 774 /** make a backup-copy of the given file */
775 bool backupFile(const QString &filePath); 775 bool backupFile(const QString &filePath);
776 /** copy a file from src to dst */ 776 /** copy a file from src to dst */
777 bool copyFile(const QString &src, const QString &dst); 777 bool copyFile(const QString &src, const QString &dst);
778 778
779 779
780 public: 780 public:
781#ifdef PWM_EMBEDDED 781#ifdef PWM_EMBEDDED
782 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 782 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
783 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 783 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
784 784
785 //takePwMDataItem returns the following values 785 //takePwMDataItem returns the following values
786 // 0 equal 786 // 0 equal
787 // 1 take local 787 // 1 take local
788 // 2 take remote 788 // 2 take remote
789 // 3 cancel 789 // 3 cancel
790 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); 790 int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full );
791 791
792 //the following methods are the overwritten callbackmethods from the syncinterface 792 //the following methods are the overwritten callbackmethods from the syncinterface
793 virtual bool sync(KSyncManager* manager, QString filename, int mode); 793 virtual bool sync(KSyncManager* manager, QString filename, int mode);
794 virtual void removeSyncInfo( QString syncProfile); 794 virtual void removeSyncInfo( QString syncProfile);
795 795
796#endif 796#endif
797 //US ENH: helpermethods to return a whole category entry 797 //US ENH: helpermethods to return a whole category entry
798 /** returns a pointer to the categoryitem */ 798 /** returns a pointer to the categoryitem */
799 PwMCategoryItem* getCategoryEntry(unsigned int index) 799 PwMCategoryItem* getCategoryEntry(unsigned int index)
800 { return &(dti.dta[index]); } 800 { return &(dti.dta[index]); }
801 801
802 private: 802 private:
803 //US ENH: helpermethods to access the sync data for a certain syncname. 803 //US ENH: helpermethods to access the sync data for a certain syncname.
804 // It returns the syncdatas index 804 // It returns the syncdatas index
805 bool findSyncData(const QString &syncname, unsigned int *index); 805 bool findSyncData(const QString &syncname, unsigned int *index);
806 806
807 /** add new syncdataentry */ 807 /** add new syncdataentry */
808 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 808 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
809 809
810 /** returns a pointer to the syncdata */ 810 /** returns a pointer to the syncdata */
811 PwMSyncItem* getSyncDataEntry(unsigned int index) 811 PwMSyncItem* getSyncDataEntry(unsigned int index)
812 { return &(dti.syncDta[index]); } 812 { return &(dti.syncDta[index]); }
813 813
814 /** delete entry */ 814 /** delete entry */
815 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 815 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
816 816
817 /** returns number of categories */
818 unsigned int numSyncDataEntries()
819 { return dti.syncDta.size(); }
820
817 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 821 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
818 822
819 QStringList getIDEntryList(); 823 QStringList getIDEntryList();
820 824
821}; 825};
822 826
823#endif 827#endif