author | ulf69 <ulf69> | 2004-10-08 00:24:58 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-10-08 00:24:58 (UTC) |
commit | 309df8e8df3a17602f948025b7951b21ec5c3fed (patch) (unidiff) | |
tree | f1b504be724510bd8d49b106cd1b98e09187c547 | |
parent | 91e43b55a0ddf6a6f39f4ed3ae828ddad6ec89a5 (diff) | |
download | kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.zip kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.tar.gz kdepimpi-309df8e8df3a17602f948025b7951b21ec5c3fed.tar.bz2 |
*** empty log message ***
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.cpp | 36 | ||||
-rw-r--r-- | pwmanager/pwmanager/pwmdoc.h | 38 | ||||
-rw-r--r-- | pwmanager/pwmanager/serializer.cpp | 2 |
3 files changed, 58 insertions, 18 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp index 76a45f4..ab3238a 100644 --- a/pwmanager/pwmanager/pwmdoc.cpp +++ b/pwmanager/pwmanager/pwmdoc.cpp | |||
@@ -2778,113 +2778,113 @@ bool PwMDoc::tryDelete() | |||
2778 | } | 2778 | } |
2779 | } | 2779 | } |
2780 | out_accept: | 2780 | out_accept: |
2781 | deleted = true; | 2781 | deleted = true; |
2782 | delete this; | 2782 | delete this; |
2783 | return true; | 2783 | return true; |
2784 | out_ignore: | 2784 | out_ignore: |
2785 | return false; | 2785 | return false; |
2786 | } | 2786 | } |
2787 | 2787 | ||
2788 | 2788 | ||
2789 | 2789 | ||
2790 | #ifdef PWM_EMBEDDED | 2790 | #ifdef PWM_EMBEDDED |
2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc | 2791 | //US ENH: this is the magic function that syncronizes the this doc with the remote doc |
2792 | //US it could have been defined as static, but I did not want to. | 2792 | //US it could have been defined as static, but I did not want to. |
2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) | 2793 | PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) |
2794 | { | 2794 | { |
2795 | int addedPasswordsLocal = 0; | 2795 | int addedPasswordsLocal = 0; |
2796 | int addedPasswordsRemote = 0; | 2796 | int addedPasswordsRemote = 0; |
2797 | int deletedPasswordsRemote = 0; | 2797 | int deletedPasswordsRemote = 0; |
2798 | int deletedPasswordsLocal = 0; | 2798 | int deletedPasswordsLocal = 0; |
2799 | int changedLocal = 0; | 2799 | int changedLocal = 0; |
2800 | int changedRemote = 0; | 2800 | int changedRemote = 0; |
2801 | 2801 | ||
2802 | PwMSyncItem* syncItemLocal; | 2802 | PwMSyncItem syncItemLocal; |
2803 | PwMSyncItem* syncItemRemote; | 2803 | PwMSyncItem syncItemRemote; |
2804 | 2804 | ||
2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); | 2805 | QString mCurrentSyncName = manager->getCurrentSyncName(); |
2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2806 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2807 | 2807 | ||
2808 | bool fullDateRange = false; | 2808 | bool fullDateRange = false; |
2809 | int take; | 2809 | int take; |
2810 | // local->resetTempSyncStat(); | 2810 | // local->resetTempSyncStat(); |
2811 | QDateTime mLastSync = QDateTime::currentDateTime(); | 2811 | QDateTime mLastSync = QDateTime::currentDateTime(); |
2812 | QDateTime modifiedSync = mLastSync; | 2812 | QDateTime modifiedSync = mLastSync; |
2813 | 2813 | ||
2814 | unsigned int index; | 2814 | unsigned int index; |
2815 | //Step 1. Find syncinfo in Local file and create if not existent. | 2815 | //Step 1. Find syncinfo in Local file and create if not existent. |
2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2816 | bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2817 | if (found == false) | 2817 | if (found == false) |
2818 | { | 2818 | { |
2819 | PwMSyncItem newSyncItemLocal; | 2819 | PwMSyncItem newSyncItemLocal; |
2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; | 2820 | newSyncItemLocal.syncName = mCurrentSyncDevice; |
2821 | newSyncItemLocal.lastSyncDate = mLastSync; | 2821 | newSyncItemLocal.lastSyncDate = mLastSync; |
2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); | 2822 | syncLocal->addSyncDataEntry(&newSyncItemLocal, true); |
2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); | 2823 | found = syncLocal->findSyncData(mCurrentSyncDevice, &index); |
2824 | if (found == false) { | 2824 | if (found == false) { |
2825 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); | 2825 | qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); |
2826 | return e_syncError; | 2826 | return e_syncError; |
2827 | } | 2827 | } |
2828 | } | 2828 | } |
2829 | 2829 | ||
2830 | syncItemLocal = syncLocal->getSyncDataEntry(index); | 2830 | syncItemLocal = syncLocal->getSyncDataEntry(index); |
2831 | qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); | 2831 | qDebug("Last Sync %s ", syncItemLocal.lastSyncDate.toString().latin1()); |
2832 | 2832 | ||
2833 | //Step 2. Find syncinfo in remote file and create if not existent. | 2833 | //Step 2. Find syncinfo in remote file and create if not existent. |
2834 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2834 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2835 | if (found == false) | 2835 | if (found == false) |
2836 | { | 2836 | { |
2837 | qDebug("FULLDATE 1"); | 2837 | qDebug("FULLDATE 1"); |
2838 | fullDateRange = true; | 2838 | fullDateRange = true; |
2839 | PwMSyncItem newSyncItemRemote; | 2839 | PwMSyncItem newSyncItemRemote; |
2840 | newSyncItemRemote.syncName = mCurrentSyncName; | 2840 | newSyncItemRemote.syncName = mCurrentSyncName; |
2841 | newSyncItemRemote.lastSyncDate = mLastSync; | 2841 | newSyncItemRemote.lastSyncDate = mLastSync; |
2842 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); | 2842 | syncRemote->addSyncDataEntry(&newSyncItemRemote, true); |
2843 | found = syncRemote->findSyncData(mCurrentSyncName, &index); | 2843 | found = syncRemote->findSyncData(mCurrentSyncName, &index); |
2844 | if (found == false) { | 2844 | if (found == false) { |
2845 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); | 2845 | qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); |
2846 | return e_syncError; | 2846 | return e_syncError; |
2847 | } | 2847 | } |
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()) |
@@ -2899,115 +2899,127 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s | |||
2899 | 2899 | ||
2900 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2900 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2901 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2901 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2902 | PWM_ASSERT(inRemote); | 2902 | PWM_ASSERT(inRemote); |
2903 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files | 2903 | if ( inLocal != 0 ) { // maybe conflict - same uid in both files |
2904 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { | 2904 | if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { |
2905 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2905 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2906 | if ( take == 3 ) | 2906 | if ( take == 3 ) |
2907 | return e_syncError; | 2907 | return e_syncError; |
2908 | if ( take == 1 ) {// take local | 2908 | if ( take == 1 ) {// take local |
2909 | //US syncRemote->removeAddressee( inRemote ); | 2909 | //US syncRemote->removeAddressee( inRemote ); |
2910 | (*inRemote) = (*inLocal); | 2910 | (*inRemote) = (*inLocal); |
2911 | //US syncRemote->insertAddressee( inRemote , false); | 2911 | //US syncRemote->insertAddressee( inRemote , false); |
2912 | ++changedRemote; | 2912 | ++changedRemote; |
2913 | } else { // take == 2 take remote | 2913 | } else { // take == 2 take remote |
2914 | //US syncLocal->removeAddressee( inLocal ); | 2914 | //US syncLocal->removeAddressee( inLocal ); |
2915 | (*inLocal) = (*inRemote); | 2915 | (*inLocal) = (*inRemote); |
2916 | //US syncLocal->insertAddressee( inLocal , false ); | 2916 | //US syncLocal->insertAddressee( inLocal , false ); |
2917 | ++changedLocal; | 2917 | ++changedLocal; |
2918 | } | 2918 | } |
2919 | } | 2919 | } |
2920 | } else { // no conflict | 2920 | } else { // no conflict |
2921 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { | 2921 | if ( inRemote->meta.update > mLastSync || mode == 5 ) { |
2922 | inRemote->meta.update = modifiedSync; | 2922 | inRemote->meta.update = modifiedSync; |
2923 | |||
2924 | //first check if we have a matching category in the local file | ||
2925 | const string* remotecat = syncRemote->getCategory(catRemote); | ||
2923 | //US syncRemote->insertAddressee( inRemote, false ); | 2926 | //US syncRemote->insertAddressee( inRemote, false ); |
2924 | //US syncLocal->insertAddressee( inRemote, false ); | 2927 | //US syncLocal->insertAddressee( inRemote, false ); |
2925 | syncLocal->addEntry("newcategory", inRemote, true, false); | 2928 | syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); |
2926 | 2929 | ||
2927 | ++addedPasswordsLocal; | 2930 | ++addedPasswordsLocal; |
2928 | } else { | 2931 | } else { |
2929 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2932 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2930 | syncRemote->delEntry(catRemote, indexRemote, true); | 2933 | syncRemote->delEntry(catRemote, indexRemote, true); |
2931 | //USsyncRemote->removeAddressee( inRemote ); | 2934 | //USsyncRemote->removeAddressee( inRemote ); |
2932 | ++deletedPasswordsRemote; | 2935 | ++deletedPasswordsRemote; |
2933 | } | 2936 | } |
2934 | } | 2937 | } |
2935 | 2938 | ||
2936 | ++incCounter; | 2939 | ++incCounter; |
2937 | } | 2940 | } |
2938 | 2941 | ||
2939 | 2942 | ||
2940 | er.clear(); | 2943 | er.clear(); |
2941 | QStringList el = syncLocal->getIDEntryList(); | 2944 | QStringList el = syncLocal->getIDEntryList(); |
2942 | modulo = (el.count()/10)+1; | 2945 | modulo = (el.count()/10)+1; |
2943 | 2946 | ||
2944 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2947 | manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2945 | incCounter = 0; | 2948 | incCounter = 0; |
2946 | while ( incCounter < el.count()) { | 2949 | while ( incCounter < el.count()) { |
2947 | qApp->processEvents(); | 2950 | qApp->processEvents(); |
2948 | if (manager->isProgressBarCanceled()) | 2951 | if (manager->isProgressBarCanceled()) |
2949 | return e_syncError; | 2952 | return e_syncError; |
2950 | if ( incCounter % modulo == 0 ) | 2953 | if ( incCounter % modulo == 0 ) |
2951 | manager->showProgressBar(incCounter); | 2954 | manager->showProgressBar(incCounter); |
2952 | uid = el[ incCounter ]; | 2955 | uid = el[ incCounter ]; |
2953 | 2956 | ||
2954 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); | 2957 | inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); |
2955 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); | 2958 | inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); |
2959 | PWM_ASSERT(inLocal); | ||
2960 | |||
2956 | if ( inRemote == 0 ) { | 2961 | if ( inRemote == 0 ) { |
2957 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { | 2962 | if ( inLocal->meta.update < mLastSync && mode != 4 ) { |
2958 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2963 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2959 | syncLocal->delEntry(catLocal, indexLocal, true); | 2964 | syncLocal->delEntry(catLocal, indexLocal, true); |
2960 | //USsyncLocal->removeAddressee( inLocal ); | 2965 | //USsyncLocal->removeAddressee( inLocal ); |
2961 | ++deletedPasswordsLocal; | 2966 | ++deletedPasswordsLocal; |
2962 | } else { | 2967 | } else { |
2963 | if ( ! manager->mWriteBackExistingOnly ) { | 2968 | if ( ! manager->mWriteBackExistingOnly ) { |
2964 | ++addedPasswordsRemote; | 2969 | ++addedPasswordsRemote; |
2965 | inLocal->meta.update = modifiedSync; | 2970 | inLocal->meta.update = modifiedSync; |
2971 | |||
2972 | //first check if we have a matching category in the remote file | ||
2973 | const string* localcat = syncLocal->getCategory(catLocal); | ||
2974 | |||
2966 | //USsyncLocal->insertAddressee( inLocal, false ); | 2975 | //USsyncLocal->insertAddressee( inLocal, false ); |
2967 | (*inRemote) = (*inLocal); | 2976 | PwMDataItem newEntry; |
2977 | newEntry = *inLocal; | ||
2978 | inRemote = &newEntry; | ||
2979 | |||
2968 | //USsyncRemote->insertAddressee( inRemote, false ); | 2980 | //USsyncRemote->insertAddressee( inRemote, false ); |
2969 | syncRemote->addEntry("newcategory", inRemote, true, false); | 2981 | syncRemote->addEntry(localcat->c_str(), inRemote, true, false); |
2970 | 2982 | ||
2971 | } | 2983 | } |
2972 | } | 2984 | } |
2973 | 2985 | ||
2974 | } | 2986 | } |
2975 | ++incCounter; | 2987 | ++incCounter; |
2976 | } | 2988 | } |
2977 | el.clear(); | 2989 | el.clear(); |
2978 | manager->hideProgressBar(); | 2990 | manager->hideProgressBar(); |
2979 | 2991 | ||
2980 | // Now write the info back into the sync data space of the files | 2992 | // Now write the info back into the sync data space of the files |
2981 | 2993 | ||
2982 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); | 2994 | mLastSync = QDateTime::currentDateTime().addSecs( 1 ); |
2983 | // get rid of micro seconds | 2995 | // get rid of micro seconds |
2984 | QTime t = mLastSync.time(); | 2996 | QTime t = mLastSync.time(); |
2985 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2997 | mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2986 | 2998 | ||
2987 | 2999 | ||
2988 | syncItemLocal->lastSyncDate = mLastSync; | 3000 | syncItemLocal.lastSyncDate = mLastSync; |
2989 | syncItemRemote->lastSyncDate = mLastSync; | 3001 | syncItemRemote.lastSyncDate = mLastSync; |
2990 | 3002 | ||
2991 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 3003 | // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2992 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 3004 | // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2993 | 3005 | ||
2994 | syncRemote->addSyncDataEntry( syncItemRemote, false ); | 3006 | syncRemote->addSyncDataEntry( syncItemRemote, false ); |
2995 | syncLocal->addSyncDataEntry( syncItemLocal, false ); | 3007 | syncLocal->addSyncDataEntry( syncItemLocal, false ); |
2996 | QString mes; | 3008 | QString mes; |
2997 | 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 ); | 3009 | 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 ); |
2998 | if ( manager->mShowSyncSummary ) { | 3010 | if ( manager->mShowSyncSummary ) { |
2999 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); | 3011 | KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); |
3000 | } | 3012 | } |
3001 | qDebug( mes ); | 3013 | qDebug( mes ); |
3002 | return e_success; | 3014 | return e_success; |
3003 | } | 3015 | } |
3004 | 3016 | ||
3005 | 3017 | ||
3006 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) | 3018 | int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) |
3007 | { | 3019 | { |
3008 | // 0 equal | 3020 | // 0 equal |
3009 | // 1 take local | 3021 | // 1 take local |
3010 | // 2 take remote | 3022 | // 2 take remote |
3011 | // 3 cancel | 3023 | // 3 cancel |
3012 | QDateTime localMod = local->meta.update; | 3024 | QDateTime localMod = local->meta.update; |
3013 | QDateTime remoteMod = remote->meta.update; | 3025 | QDateTime remoteMod = remote->meta.update; |
@@ -3261,40 +3273,40 @@ PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, u | |||
3261 | return &(*entrI); | 3273 | return &(*entrI); |
3262 | } | 3274 | } |
3263 | ++entrI; | 3275 | ++entrI; |
3264 | } | 3276 | } |
3265 | ++catcounter; | 3277 | ++catcounter; |
3266 | } | 3278 | } |
3267 | 3279 | ||
3268 | return 0; | 3280 | return 0; |
3269 | } | 3281 | } |
3270 | 3282 | ||
3271 | QStringList PwMDoc::getIDEntryList() | 3283 | QStringList PwMDoc::getIDEntryList() |
3272 | { | 3284 | { |
3273 | QStringList results; | 3285 | QStringList results; |
3274 | 3286 | ||
3275 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), | 3287 | vector<PwMCategoryItem>::iterator catcounter = dti.dta.begin(), |
3276 | catend = dti.dta.end(); | 3288 | catend = dti.dta.end(); |
3277 | 3289 | ||
3278 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; | 3290 | vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; |
3279 | 3291 | ||
3280 | while (catcounter != catend) { | 3292 | while (catcounter != catend) { |
3281 | entrBegin = catcounter->d.begin(); | 3293 | entrBegin = catcounter->d.begin(); |
3282 | entrEnd = catcounter->d.end(); | 3294 | entrEnd = catcounter->d.end(); |
3283 | entrI = entrBegin; | 3295 | entrI = entrBegin; |
3284 | while (entrI != entrEnd) { | 3296 | while (entrI != entrEnd) { |
3285 | results.append( (*entrI).meta.uniqueid ); | 3297 | results.append( (*entrI).meta.uniqueid.c_str() ); |
3286 | ++entrI; | 3298 | ++entrI; |
3287 | } | 3299 | } |
3288 | ++catcounter; | 3300 | ++catcounter; |
3289 | } | 3301 | } |
3290 | 3302 | ||
3291 | return results; | 3303 | return results; |
3292 | } | 3304 | } |
3293 | 3305 | ||
3294 | 3306 | ||
3295 | 3307 | ||
3296 | 3308 | ||
3297 | 3309 | ||
3298 | #ifndef PWM_EMBEDDED | 3310 | #ifndef PWM_EMBEDDED |
3299 | #include "pwmdoc.moc" | 3311 | #include "pwmdoc.moc" |
3300 | #endif | 3312 | #endif |
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h index 91277f6..ddab7f3 100644 --- a/pwmanager/pwmanager/pwmdoc.h +++ b/pwmanager/pwmanager/pwmdoc.h | |||
@@ -95,61 +95,72 @@ class PwMView; | |||
95 | class QFile; | 95 | class QFile; |
96 | 96 | ||
97 | /* meta data for a PwMDataItem */ | 97 | /* meta data for a PwMDataItem */ |
98 | struct PwMMetaData | 98 | struct PwMMetaData |
99 | { | 99 | { |
100 | PwMMetaData() | 100 | PwMMetaData() |
101 | : updateInt (0) | 101 | : updateInt (0) |
102 | { } | 102 | { } |
103 | /** creation date of the PwMDataItem to which | 103 | /** creation date of the PwMDataItem to which |
104 | * this meta data belongs. | 104 | * this meta data belongs. |
105 | */ | 105 | */ |
106 | QDateTimecreate; | 106 | QDateTimecreate; |
107 | /** becomes valid on this date */ | 107 | /** becomes valid on this date */ |
108 | QDateTimevalid; | 108 | QDateTimevalid; |
109 | /** expire date */ | 109 | /** expire date */ |
110 | QDateTimeexpire; | 110 | QDateTimeexpire; |
111 | /** update date (last updated at this date) */ | 111 | /** update date (last updated at this date) */ |
112 | QDateTimeupdate; | 112 | QDateTimeupdate; |
113 | /** update interval (in minutes). Time since the | 113 | /** update interval (in minutes). Time since the |
114 | * last update to remind the user to update the item. | 114 | * last update to remind the user to update the item. |
115 | * 0 disables. | 115 | * 0 disables. |
116 | */ | 116 | */ |
117 | unsigned long updateInt; | 117 | unsigned long updateInt; |
118 | 118 | ||
119 | //US ENH: enhancements of the filestructure | 119 | //US ENH: enhancements of the filestructure |
120 | /* each entry gets a unique id assigned */ | 120 | /* each entry gets a unique id assigned */ |
121 | QString uniqueid; | 121 | string uniqueid; |
122 | 122 | ||
123 | 123 | ||
124 | void clear() | 124 | void clear() |
125 | { | 125 | { |
126 | create = QDateTime(); | 126 | create = QDateTime(); |
127 | expire = QDateTime(); | 127 | expire = QDateTime(); |
128 | update = QDateTime(); | 128 | update = QDateTime(); |
129 | updateInt = 0; | 129 | updateInt = 0; |
130 | uniqueid = KApplication::randomString(8); | 130 | uniqueid = KApplication::randomString(8); |
131 | } | 131 | } |
132 | |||
133 | PwMMetaData& operator = (const PwMMetaData& x) | ||
134 | { | ||
135 | create = x.create; | ||
136 | expire = x.expire; | ||
137 | update = x.update; | ||
138 | updateInt = x.updateInt; | ||
139 | uniqueid = x.uniqueid; | ||
140 | return *this; | ||
141 | } | ||
142 | |||
132 | inline bool isValid() const | 143 | inline bool isValid() const |
133 | { | 144 | { |
134 | if (valid.isNull()) | 145 | if (valid.isNull()) |
135 | return true; | 146 | return true; |
136 | return (valid < QDateTime::currentDateTime()); | 147 | return (valid < QDateTime::currentDateTime()); |
137 | } | 148 | } |
138 | inline bool isExpired() const | 149 | inline bool isExpired() const |
139 | { | 150 | { |
140 | if (expire.isNull()) | 151 | if (expire.isNull()) |
141 | return false; | 152 | return false; |
142 | return (expire < QDateTime::currentDateTime()); | 153 | return (expire < QDateTime::currentDateTime()); |
143 | } | 154 | } |
144 | inline bool isUpdateIntOver() const | 155 | inline bool isUpdateIntOver() const |
145 | { | 156 | { |
146 | if (updateInt == 0 || | 157 | if (updateInt == 0 || |
147 | update.isNull()) | 158 | update.isNull()) |
148 | return false; | 159 | return false; |
149 | QDateTime d(update); | 160 | QDateTime d(update); |
150 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); | 161 | return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); |
151 | } | 162 | } |
152 | }; | 163 | }; |
153 | 164 | ||
154 | struct PwMDataItem | 165 | struct PwMDataItem |
155 | { | 166 | { |
@@ -185,48 +196,65 @@ struct PwMDataItem | |||
185 | /** data revision counter. This counter can be used | 196 | /** data revision counter. This counter can be used |
186 | * to easily, efficiently determine if this data item | 197 | * to easily, efficiently determine if this data item |
187 | * has changed since some time. | 198 | * has changed since some time. |
188 | * This counter is incremented on every update. | 199 | * This counter is incremented on every update. |
189 | */ | 200 | */ |
190 | unsigned int rev; | 201 | unsigned int rev; |
191 | 202 | ||
192 | void clear(bool clearMeta = true) | 203 | void clear(bool clearMeta = true) |
193 | { | 204 | { |
194 | /* NOTE: Don't use .clear() here to be | 205 | /* NOTE: Don't use .clear() here to be |
195 | * backward compatible with gcc-2 (Debian Woody) | 206 | * backward compatible with gcc-2 (Debian Woody) |
196 | */ | 207 | */ |
197 | desc = ""; | 208 | desc = ""; |
198 | name = ""; | 209 | name = ""; |
199 | pw = ""; | 210 | pw = ""; |
200 | comment = ""; | 211 | comment = ""; |
201 | url = ""; | 212 | url = ""; |
202 | launcher = ""; | 213 | launcher = ""; |
203 | lockStat = true; | 214 | lockStat = true; |
204 | listViewPos = -1; | 215 | listViewPos = -1; |
205 | binary = false; | 216 | binary = false; |
206 | if (clearMeta) | 217 | if (clearMeta) |
207 | meta.clear(); | 218 | meta.clear(); |
208 | } | 219 | } |
220 | |||
221 | PwMDataItem& operator = (const PwMDataItem& x) | ||
222 | { | ||
223 | qDebug("oper=%s", x.desc.c_str()); | ||
224 | desc = x.desc; | ||
225 | name = x.name; | ||
226 | pw = x.pw; | ||
227 | comment = x.comment; | ||
228 | url = x.url; | ||
229 | launcher = x.launcher; | ||
230 | lockStat = x.lockStat; | ||
231 | listViewPos = x.listViewPos; | ||
232 | binary = x.binary; | ||
233 | meta = x.meta; | ||
234 | rev = x.rev; | ||
235 | return *this; | ||
236 | } | ||
209 | 237 | ||
210 | }; | 238 | }; |
211 | 239 | ||
212 | struct PwMCategoryItem | 240 | struct PwMCategoryItem |
213 | { | 241 | { |
214 | /** all PwMDataItems (all passwords) within this category */ | 242 | /** all PwMDataItems (all passwords) within this category */ |
215 | vector<PwMDataItem>d; | 243 | vector<PwMDataItem>d; |
216 | /** category name/description */ | 244 | /** category name/description */ |
217 | string name; | 245 | string name; |
218 | 246 | ||
219 | void clear() | 247 | void clear() |
220 | { | 248 | { |
221 | d.clear(); | 249 | d.clear(); |
222 | name = ""; | 250 | name = ""; |
223 | } | 251 | } |
224 | }; | 252 | }; |
225 | 253 | ||
226 | struct PwMSyncItem | 254 | struct PwMSyncItem |
227 | { | 255 | { |
228 | string syncName; | 256 | string syncName; |
229 | QDateTime lastSyncDate; | 257 | QDateTime lastSyncDate; |
230 | 258 | ||
231 | void clear() | 259 | void clear() |
232 | { | 260 | { |
@@ -742,37 +770,37 @@ protected: | |||
742 | // 2 take remote | 770 | // 2 take remote |
743 | // 3 cancel | 771 | // 3 cancel |
744 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); | 772 | int takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ); |
745 | 773 | ||
746 | //the following methods are the overwritten callbackmethods from the syncinterface | 774 | //the following methods are the overwritten callbackmethods from the syncinterface |
747 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 775 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
748 | 776 | ||
749 | //called by the syncmanager to indicate that the work has to be marked as dirty. | 777 | //called by the syncmanager to indicate that the work has to be marked as dirty. |
750 | virtual void sync_setModified(); | 778 | virtual void sync_setModified(); |
751 | //called by the syncmanager to ask if the dirty flag is set. | 779 | //called by the syncmanager to ask if the dirty flag is set. |
752 | virtual bool sync_isModified(); | 780 | virtual bool sync_isModified(); |
753 | //called by the syncmanager to indicate that the work has to be saved. | 781 | //called by the syncmanager to indicate that the work has to be saved. |
754 | virtual void sync_save(); | 782 | virtual void sync_save(); |
755 | 783 | ||
756 | #endif | 784 | #endif |
757 | private: | 785 | private: |
758 | //US ENH: helpermethods to access the sync data for a certain syncname. | 786 | //US ENH: helpermethods to access the sync data for a certain syncname. |
759 | // It returns the syncdatas index | 787 | // It returns the syncdatas index |
760 | bool findSyncData(const QString &syncname, unsigned int *index); | 788 | bool findSyncData(const QString &syncname, unsigned int *index); |
761 | 789 | ||
762 | /** add new syncdataentry */ | 790 | /** add new syncdataentry */ |
763 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); | 791 | PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); |
764 | 792 | ||
765 | /** returns a pointer to the syncdata */ | 793 | /** returns a pointer to the syncdata */ |
766 | PwMSyncItem* getSyncDataEntry(unsigned int index) | 794 | PwMSyncItem getSyncDataEntry(unsigned int index) |
767 | { return &(dti.syncDta[index]); } | 795 | { return *(dti.syncDta[index]); } |
768 | 796 | ||
769 | /** delete entry */ | 797 | /** delete entry */ |
770 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); | 798 | bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); |
771 | 799 | ||
772 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); | 800 | PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); |
773 | 801 | ||
774 | QStringList getIDEntryList(); | 802 | QStringList getIDEntryList(); |
775 | 803 | ||
776 | }; | 804 | }; |
777 | 805 | ||
778 | #endif | 806 | #endif |
diff --git a/pwmanager/pwmanager/serializer.cpp b/pwmanager/pwmanager/serializer.cpp index f615082..74b3354 100644 --- a/pwmanager/pwmanager/serializer.cpp +++ b/pwmanager/pwmanager/serializer.cpp | |||
@@ -625,49 +625,49 @@ bool Serializer::writeMeta(QDomElement *e, | |||
625 | tag = domDoc->createElement(META_EXPIRE_DATE); | 625 | tag = domDoc->createElement(META_EXPIRE_DATE); |
626 | #ifndef PWM_EMBEDDED | 626 | #ifndef PWM_EMBEDDED |
627 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); | 627 | text = domDoc->createTextNode(dta.expire.toString(Qt::ISODate)); |
628 | #else | 628 | #else |
629 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); | 629 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.expire, KLocale::ISODate)); |
630 | #endif | 630 | #endif |
631 | tag.appendChild(text); | 631 | tag.appendChild(text); |
632 | e->appendChild(tag); | 632 | e->appendChild(tag); |
633 | 633 | ||
634 | tag = domDoc->createElement(META_UPDATE_DATE); | 634 | tag = domDoc->createElement(META_UPDATE_DATE); |
635 | #ifndef PWM_EMBEDDED | 635 | #ifndef PWM_EMBEDDED |
636 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); | 636 | text = domDoc->createTextNode(dta.update.toString(Qt::ISODate)); |
637 | #else | 637 | #else |
638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); | 638 | text = domDoc->createTextNode(KGlobal::locale()->formatDateTime(dta.update, KLocale::ISODate)); |
639 | #endif | 639 | #endif |
640 | tag.appendChild(text); | 640 | tag.appendChild(text); |
641 | e->appendChild(tag); | 641 | e->appendChild(tag); |
642 | 642 | ||
643 | tag = domDoc->createElement(META_UPDATE_INT); | 643 | tag = domDoc->createElement(META_UPDATE_INT); |
644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); | 644 | text = domDoc->createTextNode(tostr(dta.updateInt).c_str()); |
645 | tag.appendChild(text); | 645 | tag.appendChild(text); |
646 | e->appendChild(tag); | 646 | e->appendChild(tag); |
647 | 647 | ||
648 | tag = domDoc->createElement(META_UNIQUEID); | 648 | tag = domDoc->createElement(META_UNIQUEID); |
649 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid)); | 649 | text = domDoc->createTextNode(escapeEntryData(dta.uniqueid.c_str())); |
650 | tag.appendChild(text); | 650 | tag.appendChild(text); |
651 | e->appendChild(tag); | 651 | e->appendChild(tag); |
652 | 652 | ||
653 | #undef new_text | 653 | #undef new_text |
654 | return true; | 654 | return true; |
655 | } | 655 | } |
656 | 656 | ||
657 | QString Serializer::escapeEntryData(QString dta) | 657 | QString Serializer::escapeEntryData(QString dta) |
658 | { | 658 | { |
659 | #ifndef PWM_EMBEDDED | 659 | #ifndef PWM_EMBEDDED |
660 | dta.replace('\n', "$>--endl--<$"); | 660 | dta.replace('\n', "$>--endl--<$"); |
661 | dta.replace("]]>", "||>"); | 661 | dta.replace("]]>", "||>"); |
662 | #else | 662 | #else |
663 | dta.replace(QRegExp("\n"), "$>--endl--<$"); | 663 | dta.replace(QRegExp("\n"), "$>--endl--<$"); |
664 | dta.replace(QRegExp("]]>"), "||>"); | 664 | dta.replace(QRegExp("]]>"), "||>"); |
665 | #endif | 665 | #endif |
666 | return dta; | 666 | return dta; |
667 | } | 667 | } |
668 | 668 | ||
669 | QString Serializer::unescapeEntryData(QString dta) | 669 | QString Serializer::unescapeEntryData(QString dta) |
670 | { | 670 | { |
671 | #ifndef PWM_EMBEDDED | 671 | #ifndef PWM_EMBEDDED |
672 | dta.replace("$>--endl--<$", "\n"); | 672 | dta.replace("$>--endl--<$", "\n"); |
673 | dta.replace("||>", "]]>"); | 673 | dta.replace("||>", "]]>"); |