summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-10-19 00:49:09 (UTC)
committer ulf69 <ulf69>2004-10-19 00:49:09 (UTC)
commitda724334d46c01ee9d4f04101dab5d048c35c833 (patch) (unidiff)
tree5169852bd5e26992c9d55558dc54cf1b5ee57ae8
parent9120b7e74bb928a7c148d27abb130990f8977a31 (diff)
downloadkdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.zip
kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.tar.gz
kdepimpi-da724334d46c01ee9d4f04101dab5d048c35c833.tar.bz2
final changes to have syncronisation in place
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp102
-rw-r--r--pwmanager/pwmanager/pwmdoc.h23
2 files changed, 60 insertions, 65 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 2a7b11d..e9906a4 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2757,157 +2757,178 @@ PwMerror PwMDoc::exportToGpasman(const QString *file)
2757 unlockAll_tempoary(true); 2757 unlockAll_tempoary(true);
2758 if (gp.save_finalize() == -1) 2758 if (gp.save_finalize() == -1)
2759 return e_writeFile; 2759 return e_writeFile;
2760 2760
2761 return e_success; 2761 return e_success;
2762} 2762}
2763 2763
2764PwMerror PwMDoc::importFromGpasman(const QString *file) 2764PwMerror PwMDoc::importFromGpasman(const QString *file)
2765{ 2765{
2766 PWM_ASSERT(file); 2766 PWM_ASSERT(file);
2767 QString pw = requestMpw(false); 2767 QString pw = requestMpw(false);
2768 if (pw == "") 2768 if (pw == "")
2769 return e_noPw; 2769 return e_noPw;
2770 GpasmanFile gp; 2770 GpasmanFile gp;
2771 int ret, i; 2771 int ret, i;
2772 PwMerror ret2; 2772 PwMerror ret2;
2773 char *entry[4]; 2773 char *entry[4];
2774 PwMDataItem tmpData; 2774 PwMDataItem tmpData;
2775 ret = gp.load_init(file->latin1(), pw.latin1()); 2775 ret = gp.load_init(file->latin1(), pw.latin1());
2776 if (ret != 1) 2776 if (ret != 1)
2777 return e_accessFile; 2777 return e_accessFile;
2778 2778
2779 do { 2779 do {
2780 ret = gp.load_entry(entry); 2780 ret = gp.load_entry(entry);
2781 if(ret != 1) 2781 if(ret != 1)
2782 break; 2782 break;
2783 tmpData.desc = entry[0]; 2783 tmpData.desc = entry[0];
2784 tmpData.name = entry[1]; 2784 tmpData.name = entry[1];
2785 tmpData.pw = entry[2]; 2785 tmpData.pw = entry[2];
2786 tmpData.comment = entry[3]; 2786 tmpData.comment = entry[3];
2787 tmpData.lockStat = true; 2787 tmpData.lockStat = true;
2788 tmpData.listViewPos = -1; 2788 tmpData.listViewPos = -1;
2789 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2789 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2790 for (i = 0; i < 4; ++i) 2790 for (i = 0; i < 4; ++i)
2791 free(entry[i]); 2791 free(entry[i]);
2792 if (ret2 == e_maxAllowedEntr) { 2792 if (ret2 == e_maxAllowedEntr) {
2793 gp.load_finalize(); 2793 gp.load_finalize();
2794 return e_maxAllowedEntr; 2794 return e_maxAllowedEntr;
2795 } 2795 }
2796 } while (1); 2796 } while (1);
2797 gp.load_finalize(); 2797 gp.load_finalize();
2798 if (isDocEmpty()) 2798 if (isDocEmpty())
2799 return e_wrongPw; // we assume this. 2799 return e_wrongPw; // we assume this.
2800 2800
2801 flagDirty(); 2801 flagDirty();
2802 return e_success; 2802 return e_success;
2803} 2803}
2804 2804
2805
2806//US: we use the stl sort algorythm to sort all elements in the order
2807//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2808struct PwMDataItemListViewPosSort
2809{
2810 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2811 {
2812 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2813 if ((rpEnd)->listViewPos < 0)
2814 return false;
2815 else
2816 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2817 }
2818};
2819
2805void PwMDoc::ensureLvp() 2820void PwMDoc::ensureLvp()
2806{ 2821{
2807 if (isDocEmpty()) 2822 if (isDocEmpty())
2808 return; 2823 return;
2809 2824
2810 //US ENH BUG: when using syncronizing, this way of sorting 2825 //US ENH BUG: when using syncronizing, this way of sorting
2811 //is not sufficient, because there might be empty spaces 2826 //is not sufficient, because there might be empty spaces
2812 // at the beginning. But this algorythm only can add elements 2827 // at the beginning. But the old algorythm only can add elements
2813 //to the end.The result are crashes because of listoverflows 2828 //to the end.The result are crashes because of list overflows
2814 //we need something to fill all gaps. 2829 //we need something to fill all gaps.
2815 vector< vector<PwMDataItem>::iterator > undefined; 2830 vector<PwMDataItem*> sorted;
2816 vector< vector<PwMDataItem>::iterator > sorted; 2831 vector< PwMDataItem*>::iterator sortedBegin,
2817 vector< vector<PwMDataItem>::iterator >::iterator undefBegin, 2832 sortedEnd,
2818 undefEnd, 2833 sortedI;
2819 undefI;
2820 vector< vector<PwMDataItem>::iterator >::iterator sortedBegin,
2821 sortedEnd,
2822 sortedI;
2823 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2834 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2824 catEnd = dti.dta.end(), 2835 catEnd = dti.dta.end(),
2825 catI = catBegin; 2836 catI = catBegin;
2826 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2837 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2827 int lvpTop, tmpLvp; 2838 int lvpTop, tmpLvp;
2828 2839
2840 //qDebug("collect:");
2841
2829 while (catI != catEnd) { 2842 while (catI != catEnd) {
2830 lvpTop = -1; 2843 lvpTop = -1;
2831 undefined.clear(); 2844 sorted.clear();
2832 2845
2833 entrBegin = catI->d.begin(); 2846 entrBegin = catI->d.begin();
2834 entrEnd = catI->d.end(); 2847 entrEnd = catI->d.end();
2835 entrI = entrBegin; 2848 entrI = entrBegin;
2836 2849
2850 //US: we use the stl sort algorythm to sort all elements in the order
2851 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2837 while (entrI != entrEnd) { 2852 while (entrI != entrEnd) {
2838 tmpLvp = entrI->listViewPos; 2853 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2839 if (tmpLvp == -1) 2854 sorted.push_back((PwMDataItem*)&(*entrI));
2840 undefined.push_back(entrI); 2855 ++entrI;
2841 else
2842 sorted[tmpLvp] = entrI;
2843 //US else if (tmpLvp > lvpTop)
2844 //US lvpTop = tmpLvp;
2845 ++entrI;
2846 } 2856 }
2847 2857
2848 //now we have all undefied in the collection. Now insert the existing 2858 sortedBegin = sorted.begin();
2859 sortedEnd = sorted.end();
2860
2861 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2862
2863 // qDebug("resort:");
2864 //now we have all sorted in a collection
2865 //Now start with the sorted and reset listviewpos.
2849 sortedBegin = sorted.begin(); 2866 sortedBegin = sorted.begin();
2850 sortedEnd = sorted.end(); 2867 sortedEnd = sorted.end();
2851 sortedI = sortedBegin; 2868 sortedI = sortedBegin;
2852 2869
2853 while (sortedI != sortedEnd) { 2870 while (sortedI != sortedEnd) {
2854 tmpLvp = (*sortedI)->listViewPos; 2871 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2855 undefined[tmpLvp] = *sortedI; 2872 (*sortedI)->listViewPos = ++lvpTop;
2856 ++sortedI; 2873 ++sortedI;
2857 } 2874 }
2858 2875
2859 undefBegin = undefined.begin(); 2876 /*/debug
2860 undefEnd = undefined.end(); 2877 entrBegin = catI->d.begin();
2861 undefI = undefBegin; 2878 entrEnd = catI->d.end();
2862 while (undefI != undefEnd) { 2879 entrI = entrBegin;
2863 (*undefI)->listViewPos = ++lvpTop; 2880
2864 ++undefI; 2881 while (entrI != entrEnd) {
2882 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2883 ++entrI;
2865 } 2884 }
2885 */
2886
2866 ++catI; 2887 ++catI;
2867 } 2888 }
2868} 2889}
2869 2890
2870QString PwMDoc::getTitle() 2891QString PwMDoc::getTitle()
2871{ 2892{
2872 /* NOTE: We have to ensure, that the returned title 2893 /* NOTE: We have to ensure, that the returned title
2873 * is unique and not reused somewhere else while 2894 * is unique and not reused somewhere else while
2874 * this document is valid (open). 2895 * this document is valid (open).
2875 */ 2896 */
2876 QString title(getFilename()); 2897 QString title(getFilename());
2877 2898
2878 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2899 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2879 if (QApplication::desktop()->width() < 640) 2900 if (QApplication::desktop()->width() < 640)
2880 { 2901 {
2881 if (title.length() > 30) 2902 if (title.length() > 30)
2882 title = "..." + title.right(30); 2903 title = "..." + title.right(30);
2883 2904
2884 } 2905 }
2885 2906
2886 2907
2887 if (title.isEmpty()) { 2908 if (title.isEmpty()) {
2888 if (unnamedNum == 0) { 2909 if (unnamedNum == 0) {
2889 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2910 unnamedNum = PwMDocList::getNewUnnamedNumber();
2890 PWM_ASSERT(unnamedNum != 0); 2911 PWM_ASSERT(unnamedNum != 0);
2891 } 2912 }
2892 title = DEFAULT_TITLE; 2913 title = DEFAULT_TITLE;
2893 title += " "; 2914 title += " ";
2894 title += tostr(unnamedNum).c_str(); 2915 title += tostr(unnamedNum).c_str();
2895 } 2916 }
2896 return title; 2917 return title;
2897} 2918}
2898 2919
2899bool PwMDoc::tryDelete() 2920bool PwMDoc::tryDelete()
2900{ 2921{
2901 if (deleted) 2922 if (deleted)
2902 return true; 2923 return true;
2903 int ret; 2924 int ret;
2904 if (isDirty()) { 2925 if (isDirty()) {
2905 ret = dirtyAskSave(getTitle()); 2926 ret = dirtyAskSave(getTitle());
2906 if (ret == 0) { // save to disk 2927 if (ret == 0) { // save to disk
2907 if (!saveDocUi(this)) 2928 if (!saveDocUi(this))
2908 goto out_ignore; 2929 goto out_ignore;
2909 } else if (ret == 1) { // don't save and delete 2930 } else if (ret == 1) { // don't save and delete
2910 goto out_accept; 2931 goto out_accept;
2911 } else { // cancel operation 2932 } else { // cancel operation
2912 goto out_ignore; 2933 goto out_ignore;
2913 } 2934 }
@@ -2951,280 +2972,273 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
2951 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2972 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2952 if (found == false) 2973 if (found == false)
2953 { 2974 {
2954 PwMSyncItem newSyncItemLocal; 2975 PwMSyncItem newSyncItemLocal;
2955 newSyncItemLocal.syncName = mCurrentSyncDevice; 2976 newSyncItemLocal.syncName = mCurrentSyncDevice;
2956 newSyncItemLocal.lastSyncDate = mLastSync; 2977 newSyncItemLocal.lastSyncDate = mLastSync;
2957 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 2978 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
2958 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2979 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2959 if (found == false) { 2980 if (found == false) {
2960 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 2981 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
2961 return e_syncError; 2982 return e_syncError;
2962 } 2983 }
2963 } 2984 }
2964 2985
2965 syncItemLocal = syncLocal->getSyncDataEntry(index); 2986 syncItemLocal = syncLocal->getSyncDataEntry(index);
2966 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 2987 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
2967 2988
2968 //Step 2. Find syncinfo in remote file and create if not existent. 2989 //Step 2. Find syncinfo in remote file and create if not existent.
2969 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2990 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2970 if (found == false) 2991 if (found == false)
2971 { 2992 {
2972 qDebug("FULLDATE 1"); 2993 qDebug("FULLDATE 1");
2973 fullDateRange = true; 2994 fullDateRange = true;
2974 PwMSyncItem newSyncItemRemote; 2995 PwMSyncItem newSyncItemRemote;
2975 newSyncItemRemote.syncName = mCurrentSyncName; 2996 newSyncItemRemote.syncName = mCurrentSyncName;
2976 newSyncItemRemote.lastSyncDate = mLastSync; 2997 newSyncItemRemote.lastSyncDate = mLastSync;
2977 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 2998 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
2978 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2999 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2979 if (found == false) { 3000 if (found == false) {
2980 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3001 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
2981 return e_syncError; 3002 return e_syncError;
2982 } 3003 }
2983 } 3004 }
2984 3005
2985 syncItemRemote = syncRemote->getSyncDataEntry(index); 3006 syncItemRemote = syncRemote->getSyncDataEntry(index);
2986 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3007 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
2987 //and remove the found entry here. We will reenter it later again. 3008 //and remove the found entry here. We will reenter it later again.
2988 //US syncRemote->delSyncDataEntry(index, true); 3009 //US syncRemote->delSyncDataEntry(index, true);
2989 3010
2990 3011
2991 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3012 if ( syncItemLocal->lastSyncDate == mLastSync ) {
2992 qDebug("FULLDATE 2"); 3013 qDebug("FULLDATE 2");
2993 fullDateRange = true; 3014 fullDateRange = true;
2994 } 3015 }
2995 3016
2996 if ( ! fullDateRange ) { 3017 if ( ! fullDateRange ) {
2997 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3018 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
2998 3019
2999 // qDebug("set fulldate to true %s %s" ,syncItemLocal->lastSyncDate.toString().latin1(), syncItemRemote->lastSyncDate.toString().latin1() );
3000 // qDebug("%d %d %d %d ", syncItemLocal->lastSyncDate.time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
3001 fullDateRange = true; 3020 fullDateRange = true;
3002 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3021 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3003 } 3022 }
3004 } 3023 }
3005 // fullDateRange = true; // debug only! 3024 // fullDateRange = true; // debug only!
3006 if ( fullDateRange ) 3025 if ( fullDateRange )
3007 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3026 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3008 else 3027 else
3009 mLastSync = syncItemLocal->lastSyncDate; 3028 mLastSync = syncItemLocal->lastSyncDate;
3010 3029
3011 3030
3012 qDebug("*************************** "); 3031 qDebug("*************************** ");
3013 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3032 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3014 QStringList er = syncRemote->getIDEntryList(); 3033 QStringList er = syncRemote->getIDEntryList();
3015 PwMDataItem* inRemote ;//= er.first(); 3034 PwMDataItem* inRemote ;//= er.first();
3016 PwMDataItem* inLocal; 3035 PwMDataItem* inLocal;
3017 unsigned int catLocal, indexLocal; 3036 unsigned int catLocal, indexLocal;
3018 unsigned int catRemote, indexRemote; 3037 unsigned int catRemote, indexRemote;
3019 3038
3020 QString uid; 3039 QString uid;
3021 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3040 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3022 3041
3023 int modulo = (er.count()/10)+1; 3042 int modulo = (er.count()/10)+1;
3024 unsigned int incCounter = 0; 3043 unsigned int incCounter = 0;
3025 while ( incCounter < er.count()) { 3044 while ( incCounter < er.count()) {
3026 if (manager->isProgressBarCanceled()) 3045 if (manager->isProgressBarCanceled())
3027 return e_syncError; 3046 return e_syncError;
3028 if ( incCounter % modulo == 0 ) 3047 if ( incCounter % modulo == 0 )
3029 manager->showProgressBar(incCounter); 3048 manager->showProgressBar(incCounter);
3030 3049
3031 uid = er[ incCounter ]; 3050 uid = er[ incCounter ];
3032 qDebug("sync uid %s from remote file", uid.latin1()); 3051 qDebug("sync uid %s from remote file", uid.latin1());
3033 3052
3034 qApp->processEvents(); 3053 qApp->processEvents();
3035 3054
3036 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3055 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3037 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3056 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3038 PWM_ASSERT(inRemote); 3057 PWM_ASSERT(inRemote);
3039 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3058 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3040 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3059 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3041 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3060 qDebug("take %d %s ", take, inLocal->desc.c_str());
3042 if ( take == 3 ) 3061 if ( take == 3 )
3043 return e_syncError; 3062 return e_syncError;
3044 if ( take == 1 ) {// take local 3063 if ( take == 1 ) {// take local
3045 //US syncRemote->removeAddressee( inRemote ); 3064 int oldlistpos = inRemote->listViewPos;
3046 (*inRemote) = (*inLocal); 3065 (*inRemote) = (*inLocal);
3047 //US syncRemote->insertAddressee( inRemote , false); 3066 inRemote->listViewPos = oldlistpos;
3048 ++changedRemote; 3067 ++changedRemote;
3049 } else { // take == 2 take remote 3068 } else { // take == 2 take remote
3050 //US syncLocal->removeAddressee( inLocal ); 3069 int oldlistpos = inLocal->listViewPos;
3051 (*inLocal) = (*inRemote); 3070 (*inLocal) = (*inRemote);
3052 //US syncLocal->insertAddressee( inLocal , false ); 3071 inLocal->listViewPos = oldlistpos;
3053 ++changedLocal; 3072 ++changedLocal;
3054 } 3073 }
3055 } 3074 }
3056 } else { // no conflict 3075 } else { // no conflict
3057 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3076 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3058 inRemote->meta.update = modifiedSync; 3077 inRemote->meta.update = modifiedSync;
3059 3078
3060 //first check if we have a matching category in the local file 3079 //first check if we have a matching category in the local file
3061 const string* remotecat = syncRemote->getCategory(catRemote); 3080 const string* remotecat = syncRemote->getCategory(catRemote);
3062 //US syncRemote->insertAddressee( inRemote, false ); 3081 //US syncRemote->insertAddressee( inRemote, false );
3063 //US syncLocal->insertAddressee( inRemote, false ); 3082 //US syncLocal->insertAddressee( inRemote, false );
3064 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3083 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3065 3084
3066 ++addedPasswordsLocal; 3085 ++addedPasswordsLocal;
3067 } else { 3086 } else {
3068 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3087 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3069 syncRemote->delEntry(catRemote, indexRemote, true); 3088 syncRemote->delEntry(catRemote, indexRemote, true);
3070 //USsyncRemote->removeAddressee( inRemote ); 3089 //USsyncRemote->removeAddressee( inRemote );
3071 ++deletedPasswordsRemote; 3090 ++deletedPasswordsRemote;
3072 } 3091 }
3073 } 3092 }
3074 3093
3075 ++incCounter; 3094 ++incCounter;
3076 } 3095 }
3077 3096
3078 3097
3079 er.clear(); 3098 er.clear();
3080 QStringList el = syncLocal->getIDEntryList(); 3099 QStringList el = syncLocal->getIDEntryList();
3081 modulo = (el.count()/10)+1; 3100 modulo = (el.count()/10)+1;
3082 3101
3083 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3102 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3084 incCounter = 0; 3103 incCounter = 0;
3085 while ( incCounter < el.count()) { 3104 while ( incCounter < el.count()) {
3086 qApp->processEvents(); 3105 qApp->processEvents();
3087 if (manager->isProgressBarCanceled()) 3106 if (manager->isProgressBarCanceled())
3088 return e_syncError; 3107 return e_syncError;
3089 if ( incCounter % modulo == 0 ) 3108 if ( incCounter % modulo == 0 )
3090 manager->showProgressBar(incCounter); 3109 manager->showProgressBar(incCounter);
3091 uid = el[ incCounter ]; 3110 uid = el[ incCounter ];
3092 qDebug("sync uid %s from local file", uid.latin1()); 3111 qDebug("sync uid %s from local file", uid.latin1());
3093 3112
3094 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3113 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3095 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3114 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3096 PWM_ASSERT(inLocal); 3115 PWM_ASSERT(inLocal);
3097 3116
3098 if ( inRemote == 0 ) { 3117 if ( inRemote == 0 ) {
3099 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3118 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3100 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3119 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3101 syncLocal->delEntry(catLocal, indexLocal, true); 3120 syncLocal->delEntry(catLocal, indexLocal, true);
3102 //USsyncLocal->removeAddressee( inLocal ); 3121 //USsyncLocal->removeAddressee( inLocal );
3103 ++deletedPasswordsLocal; 3122 ++deletedPasswordsLocal;
3104 } else { 3123 } else {
3105 if ( ! manager->mWriteBackExistingOnly ) { 3124 if ( ! manager->mWriteBackExistingOnly ) {
3106 ++addedPasswordsRemote; 3125 ++addedPasswordsRemote;
3107 inLocal->meta.update = modifiedSync; 3126 inLocal->meta.update = modifiedSync;
3108 3127
3109 //first check if we have a matching category in the remote file 3128 //first check if we have a matching category in the remote file
3110 const string* localcat = syncLocal->getCategory(catLocal); 3129 const string* localcat = syncLocal->getCategory(catLocal);
3111 3130
3112 //USsyncLocal->insertAddressee( inLocal, false ); 3131 //USsyncLocal->insertAddressee( inLocal, false );
3113 PwMDataItem newEntry; 3132 PwMDataItem newEntry;
3114 newEntry = *inLocal; 3133 newEntry = *inLocal;
3115 inRemote = &newEntry; 3134 inRemote = &newEntry;
3116 3135
3117 //USsyncRemote->insertAddressee( inRemote, false ); 3136 //USsyncRemote->insertAddressee( inRemote, false );
3118 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3137 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3119 3138
3120 } 3139 }
3121 } 3140 }
3122 3141
3123 } 3142 }
3124 ++incCounter; 3143 ++incCounter;
3125 } 3144 }
3126 el.clear(); 3145 el.clear();
3127 manager->hideProgressBar(); 3146 manager->hideProgressBar();
3128 3147
3129 // Now write the info back into the sync data space of the files 3148 // Now write the info back into the sync data space of the files
3130 3149
3131 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3150 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3132 // get rid of micro seconds 3151 // get rid of micro seconds
3133 QTime t = mLastSync.time(); 3152 QTime t = mLastSync.time();
3134 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3153 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3135 3154
3136 3155
3137 syncItemLocal->lastSyncDate = mLastSync; 3156 syncItemLocal->lastSyncDate = mLastSync;
3138 syncItemRemote->lastSyncDate = mLastSync; 3157 syncItemRemote->lastSyncDate = mLastSync;
3139 3158
3140 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
3141 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
3142
3143 //US syncRemote->addSyncDataEntry( syncItemRemote, false );
3144 //US syncLocal->addSyncDataEntry( syncItemLocal, false );
3145 QString mes; 3159 QString mes;
3146 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 ); 3160 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 );
3147 if ( manager->mShowSyncSummary ) { 3161 if ( manager->mShowSyncSummary ) {
3148 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3162 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3149 } 3163 }
3150 qDebug( mes ); 3164 qDebug( mes );
3151 return e_success; 3165 return e_success;
3152} 3166}
3153 3167
3154 3168
3155int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3169int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3156{ 3170{
3157 // 0 equal 3171 // 0 equal
3158 // 1 take local 3172 // 1 take local
3159 // 2 take remote 3173 // 2 take remote
3160 // 3 cancel 3174 // 3 cancel
3161 QDateTime localMod = local->meta.update; 3175 QDateTime localMod = local->meta.update;
3162 QDateTime remoteMod = remote->meta.update; 3176 QDateTime remoteMod = remote->meta.update;
3163 3177
3164 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3178 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3165 3179
3166 if ( localMod == remoteMod ) 3180 if ( localMod == remoteMod )
3167 return 0; 3181 return 0;
3168 3182
3169 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3183 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3170 3184
3171 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3185 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3172 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3186 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3173 full = true; //debug only 3187 //full = true; //debug only
3174 if ( full ) { 3188 if ( full ) {
3175 bool equ = ( (*local) == (*remote) ); 3189 bool equ = ( (*local) == (*remote) );
3176 if ( equ ) { 3190 if ( equ ) {
3177 qDebug("equal "); 3191 //qDebug("equal ");
3178 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3192 if ( mode < SYNC_PREF_FORCE_LOCAL )
3179 return 0; 3193 return 0;
3180 3194
3181 }else //debug only 3195 }//else //debug only
3182 qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3196 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3183 } 3197 }
3184 3198
3185 int result; 3199 int result;
3186 bool localIsNew; 3200 bool localIsNew;
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() ); 3201 //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() );
3188 3202
3189 if ( full && mode < SYNC_PREF_NEWEST ) 3203 if ( full && mode < SYNC_PREF_NEWEST )
3190 mode = SYNC_PREF_ASK; 3204 mode = SYNC_PREF_ASK;
3191 3205
3192 switch( mode ) { 3206 switch( mode ) {
3193 case SYNC_PREF_LOCAL: 3207 case SYNC_PREF_LOCAL:
3194 if ( lastSync > remoteMod ) 3208 if ( lastSync > remoteMod )
3195 return 1; 3209 return 1;
3196 if ( lastSync > localMod ) 3210 if ( lastSync > localMod )
3197 return 2; 3211 return 2;
3198 return 1; 3212 return 1;
3199 break; 3213 break;
3200 case SYNC_PREF_REMOTE: 3214 case SYNC_PREF_REMOTE:
3201 if ( lastSync > remoteMod ) 3215 if ( lastSync > remoteMod )
3202 return 1; 3216 return 1;
3203 if ( lastSync > localMod ) 3217 if ( lastSync > localMod )
3204 return 2; 3218 return 2;
3205 return 2; 3219 return 2;
3206 break; 3220 break;
3207 case SYNC_PREF_NEWEST: 3221 case SYNC_PREF_NEWEST:
3208 if ( localMod > remoteMod ) 3222 if ( localMod > remoteMod )
3209 return 1; 3223 return 1;
3210 else 3224 else
3211 return 2; 3225 return 2;
3212 break; 3226 break;
3213 case SYNC_PREF_ASK: 3227 case SYNC_PREF_ASK:
3214 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3228 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3215 if ( lastSync > remoteMod ) 3229 if ( lastSync > remoteMod )
3216 return 1; 3230 return 1;
3217 if ( lastSync > localMod ) 3231 if ( lastSync > localMod )
3218 return 2; 3232 return 2;
3219 localIsNew = localMod >= remoteMod; 3233 localIsNew = localMod >= remoteMod;
3220 //qDebug("conflict! ************************************** "); 3234 //qDebug("conflict! ************************************** ");
3221 { 3235 {
3222 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3236 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3223 result = acd.executeD(localIsNew); 3237 result = acd.executeD(localIsNew);
3224 return result; 3238 return result;
3225 } 3239 }
3226 break; 3240 break;
3227 case SYNC_PREF_FORCE_LOCAL: 3241 case SYNC_PREF_FORCE_LOCAL:
3228 return 1; 3242 return 1;
3229 break; 3243 break;
3230 case SYNC_PREF_FORCE_REMOTE: 3244 case SYNC_PREF_FORCE_REMOTE:
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index 6a1dd30..535fb92 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -164,128 +164,109 @@ struct PwMDataItem
164 /** password description */ 164 /** password description */
165 stringdesc; 165 stringdesc;
166 /** user-name */ 166 /** user-name */
167 stringname; 167 stringname;
168 /** the password itself */ 168 /** the password itself */
169 stringpw; 169 stringpw;
170 /** some comment */ 170 /** some comment */
171 stringcomment; 171 stringcomment;
172 /** an URL string */ 172 /** an URL string */
173 stringurl; 173 stringurl;
174 /** launcher. Can be executed as a system() command */ 174 /** launcher. Can be executed as a system() command */
175 stringlauncher; 175 stringlauncher;
176 /** locking status. If locked (true), pw is not emitted through getEntry() */ 176 /** locking status. If locked (true), pw is not emitted through getEntry() */
177 boollockStat; 177 boollockStat;
178 /** position of this item in main "list-view" 178 /** position of this item in main "list-view"
179 * If -1, the position is not yet specified and should be appended to the list 179 * If -1, the position is not yet specified and should be appended to the list
180 */ 180 */
181 intlistViewPos; 181 intlistViewPos;
182 /** does this entry contain binary data? */ 182 /** does this entry contain binary data? */
183 bool binary; 183 bool binary;
184 /** meta data for this data item. */ 184 /** meta data for this data item. */
185 PwMMetaData meta; 185 PwMMetaData meta;
186 /** data revision counter. This counter can be used 186 /** data revision counter. This counter can be used
187 * to easily, efficiently determine if this data item 187 * to easily, efficiently determine if this data item
188 * has changed since some time. 188 * has changed since some time.
189 * This counter is incremented on every update. 189 * This counter is incremented on every update.
190 */ 190 */
191 unsigned int rev; 191 unsigned int rev;
192 192
193 void clear(bool clearMeta = true) 193 void clear(bool clearMeta = true)
194 { 194 {
195 /* NOTE: Don't use .clear() here to be 195 /* NOTE: Don't use .clear() here to be
196 * backward compatible with gcc-2 (Debian Woody) 196 * backward compatible with gcc-2 (Debian Woody)
197 */ 197 */
198 desc = ""; 198 desc = "";
199 name = ""; 199 name = "";
200 pw = ""; 200 pw = "";
201 comment = ""; 201 comment = "";
202 url = ""; 202 url = "";
203 launcher = ""; 203 launcher = "";
204 lockStat = true; 204 lockStat = true;
205 listViewPos = -1; 205 listViewPos = -1;
206 binary = false; 206 binary = false;
207 if (clearMeta) 207 if (clearMeta)
208 meta.clear(); 208 meta.clear();
209 } 209 }
210 //US ENH: we need this operator to compare two items if we have no unique ids 210 //US ENH: we need this operator to compare two items if we have no unique ids
211 //available. Generaly this happens before the first sync 211 //available. Generaly this happens before the first sync
212
212 bool PwMDataItem::operator==( const PwMDataItem &a ) const 213 bool PwMDataItem::operator==( const PwMDataItem &a ) const
213 { 214 {
214 qDebug("oper==%s", a.desc.c_str()); 215 //qDebug("oper==%s", a.desc.c_str());
215 if ( desc != a.desc ) return false; 216 if ( desc != a.desc ) return false;
216 if ( name != a.name ) return false; 217 if ( name != a.name ) return false;
217 if ( pw != a.pw ) return false; 218 if ( pw != a.pw ) return false;
218 if ( comment != a.comment ) return false; 219 if ( comment != a.comment ) return false;
219 if ( url != a.url ) return false; 220 if ( url != a.url ) return false;
220 if ( launcher != a.launcher ) return false; 221 if ( launcher != a.launcher ) return false;
221 //all other field will not be checked. 222 //all other field will not be checked.
222 return true; 223 return true;
223 } 224 }
224
225 //US ENH:this operator is used to copy an elements data during syncronization
226 //Attention: listViewPos will not be copied. So the position will stay the same.
227 PwMDataItem& operator = (const PwMDataItem& x)
228 {
229 // qDebug("oper=%s", x.desc.c_str());
230 desc = x.desc;
231 name = x.name;
232 pw = x.pw;
233 comment = x.comment;
234 url = x.url;
235 launcher = x.launcher;
236 lockStat = x.lockStat;
237 //Do not copy listViewPos!!! listViewPos = x.listViewPos;
238 binary = x.binary;
239 meta = x.meta;
240 rev = x.rev;
241 return *this;
242 }
243
244}; 225};
245 226
246struct PwMCategoryItem 227struct PwMCategoryItem
247{ 228{
248 /** all PwMDataItems (all passwords) within this category */ 229 /** all PwMDataItems (all passwords) within this category */
249 vector<PwMDataItem>d; 230 vector<PwMDataItem>d;
250 /** category name/description */ 231 /** category name/description */
251 string name; 232 string name;
252 233
253 void clear() 234 void clear()
254 { 235 {
255 d.clear(); 236 d.clear();
256 name = ""; 237 name = "";
257 } 238 }
258}; 239};
259 240
260struct PwMSyncItem 241struct PwMSyncItem
261{ 242{
262 string syncName; 243 string syncName;
263 QDateTime lastSyncDate; 244 QDateTime lastSyncDate;
264 245
265 void clear() 246 void clear()
266 { 247 {
267 lastSyncDate = QDateTime(); 248 lastSyncDate = QDateTime();
268 syncName = ""; 249 syncName = "";
269 } 250 }
270}; 251};
271 252
272struct PwMItem 253struct PwMItem
273{ 254{
274 vector<PwMCategoryItem> dta; 255 vector<PwMCategoryItem> dta;
275 vector<PwMSyncItem> syncDta; 256 vector<PwMSyncItem> syncDta;
276 257
277 void clear() 258 void clear()
278 { 259 {
279 dta.clear(); 260 dta.clear();
280 syncDta.clear(); 261 syncDta.clear();
281 } 262 }
282}; 263};
283 264
284 265
285/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 266/** "Function Object" for sort()ing PwMDataItem::listViewPos */
286class dta_lvp_greater 267class dta_lvp_greater
287{ 268{
288public: 269public:
289 bool operator() (const pair<unsigned int, unsigned int> &d1, 270 bool operator() (const pair<unsigned int, unsigned int> &d1,
290 const pair<unsigned int, unsigned int> &d2) 271 const pair<unsigned int, unsigned int> &d2)
291 { 272 {