Diffstat (limited to 'pwmanager/pwmanager/pwmdoc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 0ac5517..2a7b11d 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -484,13 +484,14 @@ PwMerror PwMDoc::saveDoc(char compress, const QString *file) | |||
484 | printWarn(string("removing file ") | 484 | printWarn(string("removing file ") |
485 | + tmpFileMoved.latin1() | 485 | + tmpFileMoved.latin1() |
486 | + " failed!"); | 486 | + " failed!"); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | ret = e_success; | 489 | ret = e_success; |
490 | printDebug(string("writing file { compress: ") | 490 | printDebug(string("writing file { name: ") |
491 | + filename.latin1() + " compress: " | ||
491 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " | 492 | + tostr(static_cast<int>(compress)) + " cryptAlgo: " |
492 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " | 493 | + tostr(static_cast<int>(cryptAlgo)) + " hashAlgo: " |
493 | + tostr(static_cast<int>(hashAlgo)) | 494 | + tostr(static_cast<int>(hashAlgo)) |
494 | + " }"); | 495 | + " }"); |
495 | goto out; | 496 | goto out; |
496 | out_moveback: | 497 | out_moveback: |
@@ -602,13 +603,15 @@ out_success: | |||
602 | 603 | ||
603 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, | 604 | PwMerror PwMDoc::writeFileHeader(char keyHash, char dataHash, char crypt, char compress, |
604 | QString *pw, QFile *f) | 605 | QString *pw, QFile *f) |
605 | { | 606 | { |
606 | PWM_ASSERT(pw); | 607 | PWM_ASSERT(pw); |
607 | PWM_ASSERT(f); | 608 | PWM_ASSERT(f); |
608 | PWM_ASSERT(listView); | 609 | //US ENH: or maybe a bug: checking here for listView does not make sense because we do not check anywhere else |
610 | //Wenn I sync, I open a doc without a view => listView is 0 => Assertion | ||
611 | //USPWM_ASSERT(listView); | ||
609 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != | 612 | if (f->writeBlock(FILE_ID_HEADER, strlen(FILE_ID_HEADER)) != |
610 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { | 613 | static_cast<Q_LONG>(strlen(FILE_ID_HEADER))) { |
611 | return e_writeFile; | 614 | return e_writeFile; |
612 | } | 615 | } |
613 | if (f->putch(PWM_FILE_VER) == -1 || | 616 | if (f->putch(PWM_FILE_VER) == -1 || |
614 | f->putch(keyHash) == -1 || | 617 | f->putch(keyHash) == -1 || |
@@ -2801,16 +2804,25 @@ PwMerror PwMDoc::importFromGpasman(const QString *file) | |||
2801 | 2804 | ||
2802 | void PwMDoc::ensureLvp() | 2805 | void PwMDoc::ensureLvp() |
2803 | { | 2806 | { |
2804 | if (isDocEmpty()) | 2807 | if (isDocEmpty()) |
2805 | return; | 2808 | return; |
2806 | 2809 | ||
2810 | //US ENH BUG: when using syncronizing, this way of sorting | ||
2811 | //is not sufficient, because there might be empty spaces | ||
2812 | // at the beginning. But this algorythm only can add elements | ||
2813 | //to the end.The result are crashes because of listoverflows | ||
2814 | //we need something to fill all gaps. | ||
2807 | vector< vector<PwMDataItem>::iterator > undefined; | 2815 | vector< vector<PwMDataItem>::iterator > undefined; |
2816 | vector< vector<PwMDataItem>::iterator > sorted; | ||
2808 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, | 2817 | vector< vector<PwMDataItem>::iterator >::iterator undefBegin, |
2809 | undefEnd, | 2818 | undefEnd, |
2810 | undefI; | 2819 | undefI; |
2820 | vector< vector<PwMDataItem>::iterator >::iterator sortedBegin, | ||
2821 | sortedEnd, | ||
2822 | sortedI; | ||
2811 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), | 2823 | vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), |
2812 | catEnd = dti.dta.end(), | 2824 | catEnd = dti.dta.end(), |
2813 | catI = catBegin; | 2825 | catI = catBegin; |
2814 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 2826 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
2815 | int lvpTop, tmpLvp; | 2827 | int lvpTop, tmpLvp; |
2816 | 2828 | ||
@@ -2823,16 +2835,30 @@ void PwMDoc::ensureLvp() | |||
2823 | entrI = entrBegin; | 2835 | entrI = entrBegin; |
2824 | 2836 | ||
2825 | while (entrI != entrEnd) { | 2837 | while (entrI != entrEnd) { |
2826 | tmpLvp = entrI->listViewPos; | 2838 | tmpLvp = entrI->listViewPos; |
2827 | if (tmpLvp == -1) | 2839 | if (tmpLvp == -1) |
2828 | undefined.push_back(entrI); | 2840 | undefined.push_back(entrI); |
2829 | else if (tmpLvp > lvpTop) | 2841 | else |
2830 | lvpTop = tmpLvp; | 2842 | sorted[tmpLvp] = entrI; |
2843 | //US else if (tmpLvp > lvpTop) | ||
2844 | //US lvpTop = tmpLvp; | ||
2831 | ++entrI; | 2845 | ++entrI; |
2832 | } | 2846 | } |
2847 | |||
2848 | //now we have all undefied in the collection. Now insert the existing | ||
2849 | sortedBegin = sorted.begin(); | ||
2850 | sortedEnd = sorted.end(); | ||
2851 | sortedI = sortedBegin; | ||
2852 | |||
2853 | while (sortedI != sortedEnd) { | ||
2854 | tmpLvp = (*sortedI)->listViewPos; | ||
2855 | undefined[tmpLvp] = *sortedI; | ||
2856 | ++sortedI; | ||
2857 | } | ||
2858 | |||
2833 | undefBegin = undefined.begin(); | 2859 | undefBegin = undefined.begin(); |
2834 | undefEnd = undefined.end(); | 2860 | undefEnd = undefined.end(); |
2835 | undefI = undefBegin; | 2861 | undefI = undefBegin; |
2836 | while (undefI != undefEnd) { | 2862 | while (undefI != undefEnd) { |
2837 | (*undefI)->listViewPos = ++lvpTop; | 2863 | (*undefI)->listViewPos = ++lvpTop; |
2838 | ++undefI; | 2864 | ++undefI; |
@@ -2845,12 +2871,22 @@ QString PwMDoc::getTitle() | |||
2845 | { | 2871 | { |
2846 | /* NOTE: We have to ensure, that the returned title | 2872 | /* NOTE: We have to ensure, that the returned title |
2847 | * is unique and not reused somewhere else while | 2873 | * is unique and not reused somewhere else while |
2848 | * this document is valid (open). | 2874 | * this document is valid (open). |
2849 | */ | 2875 | */ |
2850 | QString title(getFilename()); | 2876 | QString title(getFilename()); |
2877 | |||
2878 | //US ENH: The whole filename on PDAs is too long. So use only the last characters | ||
2879 | if (QApplication::desktop()->width() < 640) | ||
2880 | { | ||
2881 | if (title.length() > 30) | ||
2882 | title = "..." + title.right(30); | ||
2883 | |||
2884 | } | ||
2885 | |||
2886 | |||
2851 | if (title.isEmpty()) { | 2887 | if (title.isEmpty()) { |
2852 | if (unnamedNum == 0) { | 2888 | if (unnamedNum == 0) { |
2853 | unnamedNum = PwMDocList::getNewUnnamedNumber(); | 2889 | unnamedNum = PwMDocList::getNewUnnamedNumber(); |
2854 | PWM_ASSERT(unnamedNum != 0); | 2890 | PWM_ASSERT(unnamedNum != 0); |
2855 | } | 2891 | } |
2856 | title = DEFAULT_TITLE; | 2892 | title = DEFAULT_TITLE; |
@@ -2924,13 +2960,13 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
2924 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 2960 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
2925 | return e_syncError; | 2961 | return e_syncError; |
2926 | } | 2962 | } |
2927 | } | 2963 | } |
2928 | 2964 | ||
2929 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 2965 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
2930 | qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 2966 | qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); |
2931 | 2967 | ||
2932 | //Step 2. Find syncinfo in remote file and create if not existent. | 2968 | //Step 2. Find syncinfo in remote file and create if not existent. |
2933 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2969 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2934 | if (found == false) | 2970 | if (found == false) |
2935 | { | 2971 | { |
2936 | qDebug("FULLDATE 1"); | 2972 | qDebug("FULLDATE 1"); |
@@ -2944,39 +2980,40 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
2944 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 2980 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
2945 | return e_syncError; | 2981 | return e_syncError; |
2946 | } | 2982 | } |
2947 | } | 2983 | } |
2948 | 2984 | ||
2949 | syncItemRemote = syncRemote->getSyncDataEntry(index); | 2985 | syncItemRemote = syncRemote->getSyncDataEntry(index); |
2986 | qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); | ||
2950 | //and remove the found entry here. We will reenter it later again. | 2987 | //and remove the found entry here. We will reenter it later again. |
2951 | //US syncRemote->delSyncDataEntry(index, true); | 2988 | //US syncRemote->delSyncDataEntry(index, true); |
2952 | 2989 | ||
2953 | 2990 | ||
2954 | if ( syncItemLocal->lastSyncDate == mLastSync ) { | 2991 | if ( syncItemLocal->lastSyncDate == mLastSync ) { |
2955 | qDebug("FULLDATE 2"); | 2992 | qDebug("FULLDATE 2"); |
2956 | fullDateRange = true; | 2993 | fullDateRange = true; |
2957 | } | 2994 | } |
2958 | 2995 | ||
2959 | if ( ! fullDateRange ) { | 2996 | if ( ! fullDateRange ) { |
2960 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { | 2997 | if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { |
2961 | 2998 | ||
2962 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2999 | // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() ); |
2963 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 3000 | // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2964 | fullDateRange = true; | 3001 | fullDateRange = true; |
2965 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); | 3002 | qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); |
2966 | } | 3003 | } |
2967 | } | 3004 | } |
2968 | // fullDateRange = true; // debug only! | 3005 | // fullDateRange = true; // debug only! |
2969 | if ( fullDateRange ) | 3006 | if ( fullDateRange ) |
2970 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); | 3007 | mLastSync = QDateTime::currentDateTime().addDays( -100*365); |
2971 | else | 3008 | else |
2972 | mLastSync = syncItemLocal->lastSyncDate; | 3009 | mLastSync = syncItemLocal->lastSyncDate; |
2973 | 3010 | ||
2974 | 3011 | ||
2975 | qDebug("*************************** "); | 3012 | qDebug("*************************** "); |
2976 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 3013 | qDebug("mLastSync %s ",mLastSync.toString().latin1() ); |
2977 | QStringList er = syncRemote->getIDEntryList(); | 3014 | QStringList er = syncRemote->getIDEntryList(); |
2978 | PwMDataItem* inRemote ;//= er.first(); | 3015 | PwMDataItem* inRemote ;//= er.first(); |
2979 | PwMDataItem* inLocal; | 3016 | PwMDataItem* inLocal; |
2980 | unsigned int catLocal, indexLocal; | 3017 | unsigned int catLocal, indexLocal; |
2981 | unsigned int catRemote, indexRemote; | 3018 | unsigned int catRemote, indexRemote; |
2982 | 3019 | ||
@@ -2998,13 +3035,13 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
2998 | 3035 | ||
2999 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3036 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3000 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3037 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3001 | PWM_ASSERT(inRemote); | 3038 | PWM_ASSERT(inRemote); |
3002 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 3039 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
3003 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 3040 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
3004 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 3041 | qDebug("take %d %s ", take, inLocal->desc.c_str()); |
3005 | if ( take == 3 ) | 3042 | if ( take == 3 ) |
3006 | return e_syncError; | 3043 | return e_syncError; |
3007 | if ( take == 1 ) {// take local | 3044 | if ( take == 1 ) {// take local |
3008 | //US syncRemote->removeAddressee( inRemote ); | 3045 | //US syncRemote->removeAddressee( inRemote ); |
3009 | (*inRemote) = (*inLocal); | 3046 | (*inRemote) = (*inLocal); |
3010 | //US syncRemote->insertAddressee( inRemote , false); | 3047 | //US syncRemote->insertAddressee( inRemote , false); |
@@ -3049,12 +3086,13 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
3049 | qApp->processEvents(); | 3086 | qApp->processEvents(); |
3050 | if (manager->isProgressBarCanceled()) | 3087 | if (manager->isProgressBarCanceled()) |
3051 | return e_syncError; | 3088 | return e_syncError; |
3052 | if ( incCounter % modulo == 0 ) | 3089 | if ( incCounter % modulo == 0 ) |
3053 | manager->showProgressBar(incCounter); | 3090 | manager->showProgressBar(incCounter); |
3054 | uid = el[ incCounter ]; | 3091 | uid = el[ incCounter ]; |
3092 | qDebug("sync uid %s from local file", uid.latin1()); | ||
3055 | 3093 | ||
3056 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 3094 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
3057 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 3095 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
3058 | PWM_ASSERT(inLocal); | 3096 | PWM_ASSERT(inLocal); |
3059 | 3097 | ||
3060 | if ( inRemote == 0 ) { | 3098 | if ( inRemote == 0 ) { |
@@ -3129,22 +3167,22 @@ int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime | |||
3129 | return 0; | 3167 | return 0; |
3130 | 3168 | ||
3131 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); | 3169 | qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); |
3132 | 3170 | ||
3133 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 3171 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
3134 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 3172 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
3135 | //full = true; //debug only | 3173 | full = true; //debug only |
3136 | if ( full ) { | 3174 | if ( full ) { |
3137 | bool equ = true;//US ( (*local) == (*remote) ); | 3175 | bool equ = ( (*local) == (*remote) ); |
3138 | if ( equ ) { | 3176 | if ( equ ) { |
3139 | //qDebug("equal "); | 3177 | qDebug("equal "); |
3140 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 3178 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
3141 | return 0; | 3179 | return 0; |
3142 | 3180 | ||
3143 | }//else //debug only | 3181 | }else //debug only |
3144 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 3182 | qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); |
3145 | } | 3183 | } |
3146 | 3184 | ||
3147 | int result; | 3185 | int result; |
3148 | bool localIsNew; | 3186 | bool localIsNew; |
3149 | //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() ); | 3187 | //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() ); |
3150 | 3188 | ||
@@ -3212,13 +3250,13 @@ bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | |||
3212 | if (this->isDeepLocked()) { | 3250 | if (this->isDeepLocked()) { |
3213 | PwMerror ret = this->deepLock(false); | 3251 | PwMerror ret = this->deepLock(false); |
3214 | if (ret != e_success) | 3252 | if (ret != e_success) |
3215 | return false; | 3253 | return false; |
3216 | } | 3254 | } |
3217 | 3255 | ||
3218 | //2) construct and open a new doc on the stack(automatic cleanup) for remote file. | 3256 | //2) construct and open a new doc on the stack(automatic cleanup of remote file). |
3219 | PwMDoc syncTarget(this, "synctarget"); | 3257 | PwMDoc syncTarget(this, "synctarget"); |
3220 | PwMDoc* pSyncTarget = &syncTarget; | 3258 | PwMDoc* pSyncTarget = &syncTarget; |
3221 | 3259 | ||
3222 | 3260 | ||
3223 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); | 3261 | PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/); |
3224 | 3262 | ||
@@ -3264,29 +3302,12 @@ bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) | |||
3264 | } | 3302 | } |
3265 | else { | 3303 | else { |
3266 | return false; | 3304 | return false; |
3267 | } | 3305 | } |
3268 | } | 3306 | } |
3269 | 3307 | ||
3270 | //called by the syncmanager to indicate that the work has to marked as dirty. | ||
3271 | void PwMDoc::sync_setModified() | ||
3272 | { | ||
3273 | flagDirty(); | ||
3274 | } | ||
3275 | |||
3276 | //called by the syncmanager to ask if the dirty flag is set. | ||
3277 | bool PwMDoc::sync_isModified() | ||
3278 | { | ||
3279 | return isDirty(); | ||
3280 | } | ||
3281 | |||
3282 | //called by the syncmanager to indicate that the work has to be saved. | ||
3283 | void PwMDoc::sync_save() | ||
3284 | { | ||
3285 | saveDoc(conf()->confGlobCompression()); | ||
3286 | } | ||
3287 | #endif | 3308 | #endif |
3288 | 3309 | ||
3289 | 3310 | ||
3290 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) | 3311 | bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) |
3291 | { | 3312 | { |
3292 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), | 3313 | vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), |