summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp10
-rw-r--r--pwmanager/pwmanager/pwmdoc.h20
2 files changed, 24 insertions, 6 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index fd17ce5..9043acc 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2831,492 +2831,490 @@ PwMerror PwMDoc::importFromGpasman(const QString *file)
2831 char *entry[4]; 2831 char *entry[4];
2832 PwMDataItem tmpData; 2832 PwMDataItem tmpData;
2833 ret = gp.load_init(file->latin1(), pw.latin1()); 2833 ret = gp.load_init(file->latin1(), pw.latin1());
2834 if (ret != 1) 2834 if (ret != 1)
2835 return e_accessFile; 2835 return e_accessFile;
2836 2836
2837 do { 2837 do {
2838 ret = gp.load_entry(entry); 2838 ret = gp.load_entry(entry);
2839 if(ret != 1) 2839 if(ret != 1)
2840 break; 2840 break;
2841 tmpData.desc = entry[0]; 2841 tmpData.desc = entry[0];
2842 tmpData.name = entry[1]; 2842 tmpData.name = entry[1];
2843 tmpData.pw = entry[2]; 2843 tmpData.pw = entry[2];
2844 tmpData.comment = entry[3]; 2844 tmpData.comment = entry[3];
2845 tmpData.lockStat = true; 2845 tmpData.lockStat = true;
2846 tmpData.listViewPos = -1; 2846 tmpData.listViewPos = -1;
2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true); 2847 ret2 = addEntry(DEFAULT_CATEGORY, &tmpData, true);
2848 for (i = 0; i < 4; ++i) 2848 for (i = 0; i < 4; ++i)
2849 free(entry[i]); 2849 free(entry[i]);
2850 if (ret2 == e_maxAllowedEntr) { 2850 if (ret2 == e_maxAllowedEntr) {
2851 gp.load_finalize(); 2851 gp.load_finalize();
2852 return e_maxAllowedEntr; 2852 return e_maxAllowedEntr;
2853 } 2853 }
2854 } while (1); 2854 } while (1);
2855 gp.load_finalize(); 2855 gp.load_finalize();
2856 if (isDocEmpty()) 2856 if (isDocEmpty())
2857 return e_wrongPw; // we assume this. 2857 return e_wrongPw; // we assume this.
2858 2858
2859 flagDirty(); 2859 flagDirty();
2860 return e_success; 2860 return e_success;
2861} 2861}
2862 2862
2863 2863
2864//US: we use the stl sort algorythm to sort all elements in the order 2864//US: we use the stl sort algorythm to sort all elements in the order
2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1 2865//of its listViewPos (in the order 1,2,3,5,...,x,-1, -1, -1
2866struct PwMDataItemListViewPosSort 2866struct PwMDataItemListViewPosSort
2867{ 2867{
2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd) 2868 bool operator()(PwMDataItem* rpStart, PwMDataItem* rpEnd)
2869 { 2869 {
2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()"); 2870 //qDebug("pwMDoc::PwMDataItemListViewPosSort()");
2871 if ((rpEnd)->listViewPos < 0) 2871 if ((rpEnd)->listViewPos < 0)
2872 return false; 2872 return false;
2873 else 2873 else
2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos; 2874 return (rpStart)->listViewPos < (rpEnd)->listViewPos;
2875 } 2875 }
2876}; 2876};
2877 2877
2878void PwMDoc::ensureLvp() 2878void PwMDoc::ensureLvp()
2879{ 2879{
2880 if (isDocEmpty()) 2880 if (isDocEmpty())
2881 return; 2881 return;
2882 2882
2883 //US ENH BUG: when using syncronizing, this way of sorting 2883 //US ENH BUG: when using syncronizing, this way of sorting
2884 //is not sufficient, because there might be empty spaces 2884 //is not sufficient, because there might be empty spaces
2885 // at the beginning. But the old algorythm only can add elements 2885 // at the beginning. But the old algorythm only can add elements
2886 //to the end.The result are crashes because of list overflows 2886 //to the end.The result are crashes because of list overflows
2887 //we need something to fill all gaps. 2887 //we need something to fill all gaps.
2888 vector<PwMDataItem*> sorted; 2888 vector<PwMDataItem*> sorted;
2889 vector< PwMDataItem*>::iterator sortedBegin, 2889 vector< PwMDataItem*>::iterator sortedBegin,
2890 sortedEnd, 2890 sortedEnd,
2891 sortedI; 2891 sortedI;
2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2892 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2893 catEnd = dti.dta.end(), 2893 catEnd = dti.dta.end(),
2894 catI = catBegin; 2894 catI = catBegin;
2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2895 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2896 int lvpTop, tmpLvp; 2896 int lvpTop, tmpLvp;
2897 2897
2898 //qDebug("collect:"); 2898 //qDebug("collect:");
2899 2899
2900 while (catI != catEnd) { 2900 while (catI != catEnd) {
2901 lvpTop = -1; 2901 lvpTop = -1;
2902 sorted.clear(); 2902 sorted.clear();
2903 2903
2904 entrBegin = catI->d.begin(); 2904 entrBegin = catI->d.begin();
2905 entrEnd = catI->d.end(); 2905 entrEnd = catI->d.end();
2906 entrI = entrBegin; 2906 entrI = entrBegin;
2907 2907
2908 //US: we use the stl sort algorythm to sort all elements in the order 2908 //US: we use the stl sort algorythm to sort all elements in the order
2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1 2909 //of its listViewPos (in the order 1,2,2,3,5,...,x,-1, -1, -1
2910 while (entrI != entrEnd) { 2910 while (entrI != entrEnd) {
2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2911 //qDebug("found: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2912 sorted.push_back((PwMDataItem*)&(*entrI)); 2912 sorted.push_back((PwMDataItem*)&(*entrI));
2913 ++entrI; 2913 ++entrI;
2914 } 2914 }
2915 2915
2916 sortedBegin = sorted.begin(); 2916 sortedBegin = sorted.begin();
2917 sortedEnd = sorted.end(); 2917 sortedEnd = sorted.end();
2918 2918
2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort()); 2919 sort(sortedBegin, sortedEnd, PwMDataItemListViewPosSort());
2920 2920
2921 // qDebug("resort:"); 2921 // qDebug("resort:");
2922 //now we have all sorted in a collection 2922 //now we have all sorted in a collection
2923 //Now start with the sorted and reset listviewpos. 2923 //Now start with the sorted and reset listviewpos.
2924 sortedBegin = sorted.begin(); 2924 sortedBegin = sorted.begin();
2925 sortedEnd = sorted.end(); 2925 sortedEnd = sorted.end();
2926 sortedI = sortedBegin; 2926 sortedI = sortedBegin;
2927 2927
2928 while (sortedI != sortedEnd) { 2928 while (sortedI != sortedEnd) {
2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1); 2929 // qDebug("reset defined: %s, from pos=%i to pos=%i", (*sortedI)->desc.c_str(), (*sortedI)->listViewPos, lvpTop+1);
2930 (*sortedI)->listViewPos = ++lvpTop; 2930 (*sortedI)->listViewPos = ++lvpTop;
2931 ++sortedI; 2931 ++sortedI;
2932 } 2932 }
2933 2933
2934 /*/debug 2934 /*/debug
2935 entrBegin = catI->d.begin(); 2935 entrBegin = catI->d.begin();
2936 entrEnd = catI->d.end(); 2936 entrEnd = catI->d.end();
2937 entrI = entrBegin; 2937 entrI = entrBegin;
2938 2938
2939 while (entrI != entrEnd) { 2939 while (entrI != entrEnd) {
2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos); 2940 qDebug("check: %s, pos=%i", (*entrI).desc.c_str(), (*entrI).listViewPos);
2941 ++entrI; 2941 ++entrI;
2942 } 2942 }
2943 */ 2943 */
2944 2944
2945 ++catI; 2945 ++catI;
2946 } 2946 }
2947} 2947}
2948 2948
2949QString PwMDoc::getTitle() 2949QString PwMDoc::getTitle()
2950{ 2950{
2951 /* NOTE: We have to ensure, that the returned title 2951 /* NOTE: We have to ensure, that the returned title
2952 * is unique and not reused somewhere else while 2952 * is unique and not reused somewhere else while
2953 * this document is valid (open). 2953 * this document is valid (open).
2954 */ 2954 */
2955 QString title(getFilename()); 2955 QString title(getFilename());
2956 2956
2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters 2957 //US ENH: The whole filename on PDAs is too long. So use only the last characters
2958 if (QApplication::desktop()->width() < 640) 2958 if (QApplication::desktop()->width() < 640)
2959 { 2959 {
2960 if (title.length() > 30) 2960 if (title.length() > 30)
2961 title = "..." + title.right(30); 2961 title = "..." + title.right(30);
2962 2962
2963 } 2963 }
2964 2964
2965 2965
2966 if (title.isEmpty()) { 2966 if (title.isEmpty()) {
2967 if (unnamedNum == 0) { 2967 if (unnamedNum == 0) {
2968 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2968 unnamedNum = PwMDocList::getNewUnnamedNumber();
2969 PWM_ASSERT(unnamedNum != 0); 2969 PWM_ASSERT(unnamedNum != 0);
2970 } 2970 }
2971 title = DEFAULT_TITLE; 2971 title = DEFAULT_TITLE;
2972 title += " "; 2972 title += " ";
2973 title += tostr(unnamedNum).c_str(); 2973 title += tostr(unnamedNum).c_str();
2974 } 2974 }
2975 return title; 2975 return title;
2976} 2976}
2977 2977
2978bool PwMDoc::tryDelete() 2978bool PwMDoc::tryDelete()
2979{ 2979{
2980 2980
2981 if (deleted) 2981 if (deleted)
2982 return true; 2982 return true;
2983 int ret; 2983 int ret;
2984 if (isDirty()) { 2984 if (isDirty()) {
2985 ret = dirtyAskSave(getTitle()); 2985 ret = dirtyAskSave(getTitle());
2986 if (ret == 0) { // save to disk 2986 if (ret == 0) { // save to disk
2987 if (!saveDocUi(this)) 2987 if (!saveDocUi(this))
2988 goto out_ignore; 2988 goto out_ignore;
2989 } else if (ret == 1) { // don't save and delete 2989 } else if (ret == 1) { // don't save and delete
2990 goto out_accept; 2990 goto out_accept;
2991 } else { // cancel operation 2991 } else { // cancel operation
2992 goto out_ignore; 2992 goto out_ignore;
2993 } 2993 }
2994 } 2994 }
2995out_accept: 2995out_accept:
2996 deleted = true; 2996 deleted = true;
2997 delete this; 2997 delete this;
2998 return true; 2998 return true;
2999out_ignore: 2999out_ignore:
3000 return false; 3000 return false;
3001} 3001}
3002 3002
3003 3003
3004 3004
3005#ifdef PWM_EMBEDDED 3005#ifdef PWM_EMBEDDED
3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc 3006//US ENH: this is the magic function that syncronizes the this doc with the remote doc
3007//US it could have been defined as static, but I did not want to. 3007//US it could have been defined as static, but I did not want to.
3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 3008PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode )
3009{ 3009{
3010 int addedPasswordsLocal = 0; 3010 int addedPasswordsLocal = 0;
3011 int addedPasswordsRemote = 0; 3011 int addedPasswordsRemote = 0;
3012 int deletedPasswordsRemote = 0; 3012 int deletedPasswordsRemote = 0;
3013 int deletedPasswordsLocal = 0; 3013 int deletedPasswordsLocal = 0;
3014 int changedLocal = 0; 3014 int changedLocal = 0;
3015 int changedRemote = 0; 3015 int changedRemote = 0;
3016 3016
3017 PwMSyncItem* syncItemLocal; 3017 PwMSyncItem* syncItemLocal;
3018 PwMSyncItem* syncItemRemote; 3018 PwMSyncItem* syncItemRemote;
3019 3019
3020 QString mCurrentSyncName = manager->getCurrentSyncName(); 3020 QString mCurrentSyncName = manager->getCurrentSyncName();
3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3021 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3022 3022
3023 bool mSyncLauncher = true;
3024
3023 bool fullDateRange = false; 3025 bool fullDateRange = false;
3024 int take; 3026 int take;
3025 // local->resetTempSyncStat(); 3027 // local->resetTempSyncStat();
3026 QDateTime mLastSync = QDateTime::currentDateTime(); 3028 QDateTime mLastSync = QDateTime::currentDateTime();
3027 QDateTime modifiedSync = mLastSync; 3029 QDateTime modifiedSync = mLastSync;
3028 3030
3029 unsigned int index; 3031 unsigned int index;
3030 //Step 1. Find syncinfo in Local file and create if not existent. 3032 //Step 1. Find syncinfo in Local file and create if not existent.
3031 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3033 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3032 if (found == false) 3034 if (found == false)
3033 { 3035 {
3034 PwMSyncItem newSyncItemLocal; 3036 PwMSyncItem newSyncItemLocal;
3035 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1(); 3037 newSyncItemLocal.syncName = mCurrentSyncDevice.latin1();
3036 newSyncItemLocal.lastSyncDate = mLastSync; 3038 newSyncItemLocal.lastSyncDate = mLastSync;
3037 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 3039 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
3038 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 3040 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
3039 if (found == false) { 3041 if (found == false) {
3040 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 3042 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
3041 return e_syncError; 3043 return e_syncError;
3042 } 3044 }
3043 } 3045 }
3044 3046
3045 syncItemLocal = syncLocal->getSyncDataEntry(index); 3047 syncItemLocal = syncLocal->getSyncDataEntry(index);
3046 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1()); 3048 qDebug("Last Sync Local %s ", syncItemLocal->lastSyncDate.toString().latin1());
3047 3049
3048 //Step 2. Find syncinfo in remote file and create if not existent. 3050 //Step 2. Find syncinfo in remote file and create if not existent.
3049 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3051 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3050 if (found == false) 3052 if (found == false)
3051 { 3053 {
3052 qDebug("FULLDATE 1"); 3054 qDebug("FULLDATE 1");
3053 fullDateRange = true; 3055 fullDateRange = true;
3054 PwMSyncItem newSyncItemRemote; 3056 PwMSyncItem newSyncItemRemote;
3055 newSyncItemRemote.syncName = mCurrentSyncName.latin1(); 3057 newSyncItemRemote.syncName = mCurrentSyncName.latin1();
3056 newSyncItemRemote.lastSyncDate = mLastSync; 3058 newSyncItemRemote.lastSyncDate = mLastSync;
3057 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 3059 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
3058 found = syncRemote->findSyncData(mCurrentSyncName, &index); 3060 found = syncRemote->findSyncData(mCurrentSyncName, &index);
3059 if (found == false) { 3061 if (found == false) {
3060 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 3062 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
3061 return e_syncError; 3063 return e_syncError;
3062 } 3064 }
3063 } 3065 }
3064 3066
3065 syncItemRemote = syncRemote->getSyncDataEntry(index); 3067 syncItemRemote = syncRemote->getSyncDataEntry(index);
3066 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1()); 3068 qDebug("Last Sync Remote %s ", syncItemRemote->lastSyncDate.toString().latin1());
3067 //and remove the found entry here. We will reenter it later again. 3069 //and remove the found entry here. We will reenter it later again.
3068 //US syncRemote->delSyncDataEntry(index, true); 3070 //US syncRemote->delSyncDataEntry(index, true);
3069 3071
3070 3072
3071 if ( syncItemLocal->lastSyncDate == mLastSync ) { 3073 if ( syncItemLocal->lastSyncDate == mLastSync ) {
3072 qDebug("FULLDATE 2"); 3074 qDebug("FULLDATE 2");
3073 fullDateRange = true; 3075 fullDateRange = true;
3074 } 3076 }
3075 3077
3076 if ( ! fullDateRange ) { 3078 if ( ! fullDateRange ) {
3077 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 3079 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
3078 3080
3079 fullDateRange = true; 3081 fullDateRange = true;
3080 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 3082 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
3081 } 3083 }
3082 } 3084 }
3083 // fullDateRange = true; // debug only! 3085 // fullDateRange = true; // debug only!
3084 if ( fullDateRange ) 3086 if ( fullDateRange )
3085 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 3087 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
3086 else 3088 else
3087 mLastSync = syncItemLocal->lastSyncDate; 3089 mLastSync = syncItemLocal->lastSyncDate;
3088 3090
3089 3091
3090 qDebug("*************************** "); 3092 qDebug("*************************** ");
3091 qDebug("mLastSync %s ",mLastSync.toString().latin1() ); 3093 qDebug("mLastSync %s ",mLastSync.toString().latin1() );
3092 QStringList er = syncRemote->getIDEntryList(); 3094 QStringList er = syncRemote->getIDEntryList();
3093 PwMDataItem* inRemote ;//= er.first(); 3095 PwMDataItem* inRemote ;//= er.first();
3094 PwMDataItem* inLocal; 3096 PwMDataItem* inLocal;
3095 unsigned int catLocal, indexLocal; 3097 unsigned int catLocal, indexLocal;
3096 unsigned int catRemote, indexRemote; 3098 unsigned int catRemote, indexRemote;
3097 3099
3098 QString uid; 3100 QString uid;
3099 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 3101 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
3100 3102
3101 int modulo = (er.count()/10)+1; 3103 int modulo = (er.count()/10)+1;
3102 unsigned int incCounter = 0; 3104 unsigned int incCounter = 0;
3103 while ( incCounter < er.count()) { 3105 while ( incCounter < er.count()) {
3104 if (manager->isProgressBarCanceled()) 3106 if (manager->isProgressBarCanceled())
3105 return e_syncError; 3107 return e_syncError;
3106 if ( incCounter % modulo == 0 ) 3108 if ( incCounter % modulo == 0 )
3107 manager->showProgressBar(incCounter); 3109 manager->showProgressBar(incCounter);
3108 3110
3109 uid = er[ incCounter ]; 3111 uid = er[ incCounter ];
3110 qDebug("sync uid %s from remote file", uid.latin1()); 3112 qDebug("sync uid %s from remote file", uid.latin1());
3111 3113
3112 qApp->processEvents(); 3114 qApp->processEvents();
3113 3115
3114 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3116 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3115 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3117 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3116 PWM_ASSERT(inRemote); 3118 PWM_ASSERT(inRemote);
3117 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 3119 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
3118 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 3120 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
3119 qDebug("take %d %s ", take, inLocal->desc.c_str()); 3121 qDebug("take %d %s ", take, inLocal->desc.c_str());
3120 if ( take == 3 ) 3122 if ( take == 3 )
3121 return e_syncError; 3123 return e_syncError;
3122 if ( take == 1 ) {// take local 3124 if ( take == 1 ) {// take local
3123 int oldlistpos = inRemote->listViewPos; 3125 inRemote->syncItem(*inLocal, mSyncLauncher);
3124 (*inRemote) = (*inLocal);
3125 inRemote->listViewPos = oldlistpos;
3126 ++changedRemote; 3126 ++changedRemote;
3127 } else { // take == 2 take remote 3127 } else { // take == 2 take remote
3128 int oldlistpos = inLocal->listViewPos; 3128 inLocal->syncItem(*inRemote, mSyncLauncher);
3129 (*inLocal) = (*inRemote);
3130 inLocal->listViewPos = oldlistpos;
3131 ++changedLocal; 3129 ++changedLocal;
3132 } 3130 }
3133 } 3131 }
3134 } else { // no conflict 3132 } else { // no conflict
3135 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 3133 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
3136 inRemote->meta.update = modifiedSync; 3134 inRemote->meta.update = modifiedSync;
3137 3135
3138 //first check if we have a matching category in the local file 3136 //first check if we have a matching category in the local file
3139 const string* remotecat = syncRemote->getCategory(catRemote); 3137 const string* remotecat = syncRemote->getCategory(catRemote);
3140 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 3138 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
3141 3139
3142 ++addedPasswordsLocal; 3140 ++addedPasswordsLocal;
3143 } else { 3141 } else {
3144 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 3142 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
3145 syncRemote->delEntry(catRemote, indexRemote, true); 3143 syncRemote->delEntry(catRemote, indexRemote, true);
3146 ++deletedPasswordsRemote; 3144 ++deletedPasswordsRemote;
3147 } 3145 }
3148 } 3146 }
3149 3147
3150 ++incCounter; 3148 ++incCounter;
3151 } 3149 }
3152 3150
3153 3151
3154 er.clear(); 3152 er.clear();
3155 QStringList el = syncLocal->getIDEntryList(); 3153 QStringList el = syncLocal->getIDEntryList();
3156 modulo = (el.count()/10)+1; 3154 modulo = (el.count()/10)+1;
3157 3155
3158 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3156 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3159 incCounter = 0; 3157 incCounter = 0;
3160 while ( incCounter < el.count()) { 3158 while ( incCounter < el.count()) {
3161 qApp->processEvents(); 3159 qApp->processEvents();
3162 if (manager->isProgressBarCanceled()) 3160 if (manager->isProgressBarCanceled())
3163 return e_syncError; 3161 return e_syncError;
3164 if ( incCounter % modulo == 0 ) 3162 if ( incCounter % modulo == 0 )
3165 manager->showProgressBar(incCounter); 3163 manager->showProgressBar(incCounter);
3166 uid = el[ incCounter ]; 3164 uid = el[ incCounter ];
3167 qDebug("sync uid %s from local file", uid.latin1()); 3165 qDebug("sync uid %s from local file", uid.latin1());
3168 3166
3169 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 3167 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
3170 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 3168 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
3171 PWM_ASSERT(inLocal); 3169 PWM_ASSERT(inLocal);
3172 3170
3173 if ( inRemote == 0 ) { 3171 if ( inRemote == 0 ) {
3174 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 3172 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
3175 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3173 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3176 syncLocal->delEntry(catLocal, indexLocal, true); 3174 syncLocal->delEntry(catLocal, indexLocal, true);
3177 ++deletedPasswordsLocal; 3175 ++deletedPasswordsLocal;
3178 } else { 3176 } else {
3179 if ( ! manager->mWriteBackExistingOnly ) { 3177 if ( ! manager->mWriteBackExistingOnly ) {
3180 ++addedPasswordsRemote; 3178 ++addedPasswordsRemote;
3181 inLocal->meta.update = modifiedSync; 3179 inLocal->meta.update = modifiedSync;
3182 3180
3183 //first check if we have a matching category in the remote file 3181 //first check if we have a matching category in the remote file
3184 const string* localcat = syncLocal->getCategory(catLocal); 3182 const string* localcat = syncLocal->getCategory(catLocal);
3185 3183
3186 PwMDataItem newEntry; 3184 PwMDataItem newEntry;
3187 newEntry = *inLocal; 3185 newEntry = *inLocal;
3188 inRemote = &newEntry; 3186 inRemote = &newEntry;
3189 3187
3190 //USsyncRemote->insertAddressee( inRemote, false ); 3188 //USsyncRemote->insertAddressee( inRemote, false );
3191 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 3189 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
3192 3190
3193 } 3191 }
3194 } 3192 }
3195 3193
3196 } 3194 }
3197 ++incCounter; 3195 ++incCounter;
3198 } 3196 }
3199 el.clear(); 3197 el.clear();
3200 manager->hideProgressBar(); 3198 manager->hideProgressBar();
3201 3199
3202 // Now write the info back into the sync data space of the files 3200 // Now write the info back into the sync data space of the files
3203 3201
3204 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 3202 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
3205 // get rid of micro seconds 3203 // get rid of micro seconds
3206 QTime t = mLastSync.time(); 3204 QTime t = mLastSync.time();
3207 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3205 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3208 3206
3209 3207
3210 syncItemLocal->lastSyncDate = mLastSync; 3208 syncItemLocal->lastSyncDate = mLastSync;
3211 syncItemRemote->lastSyncDate = mLastSync; 3209 syncItemRemote->lastSyncDate = mLastSync;
3212 3210
3213 QString mes; 3211 QString mes;
3214 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 ); 3212 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 );
3215 if ( manager->mShowSyncSummary ) { 3213 if ( manager->mShowSyncSummary ) {
3216 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3214 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3217 } 3215 }
3218 qDebug( mes ); 3216 qDebug( mes );
3219 return e_success; 3217 return e_success;
3220} 3218}
3221 3219
3222 3220
3223int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3221int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3224{ 3222{
3225 // 0 equal 3223 // 0 equal
3226 // 1 take local 3224 // 1 take local
3227 // 2 take remote 3225 // 2 take remote
3228 // 3 cancel 3226 // 3 cancel
3229 QDateTime localMod = local->meta.update; 3227 QDateTime localMod = local->meta.update;
3230 QDateTime remoteMod = remote->meta.update; 3228 QDateTime remoteMod = remote->meta.update;
3231 3229
3232 if ( localMod == remoteMod ) 3230 if ( localMod == remoteMod )
3233 return 0; 3231 return 0;
3234 3232
3235 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3233 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3236 3234
3237 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3235 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3238 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3236 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3239 //full = true; //debug only 3237 //full = true; //debug only
3240 if ( full ) { 3238 if ( full ) {
3241 bool equ = ( (*local) == (*remote) ); 3239 bool equ = ( (*local) == (*remote) );
3242 if ( equ ) { 3240 if ( equ ) {
3243 //qDebug("equal "); 3241 //qDebug("equal ");
3244 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3242 if ( mode < SYNC_PREF_FORCE_LOCAL )
3245 return 0; 3243 return 0;
3246 3244
3247 }//else //debug only 3245 }//else //debug only
3248 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str()); 3246 //qDebug("not equal %s %s ", local->desc.c_str(), remote->desc.c_str());
3249 } 3247 }
3250 3248
3251 int result; 3249 int result;
3252 bool localIsNew; 3250 bool localIsNew;
3253 //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() ); 3251 //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() );
3254 3252
3255 if ( full && mode < SYNC_PREF_NEWEST ) 3253 if ( full && mode < SYNC_PREF_NEWEST )
3256 mode = SYNC_PREF_ASK; 3254 mode = SYNC_PREF_ASK;
3257 3255
3258 switch( mode ) { 3256 switch( mode ) {
3259 case SYNC_PREF_LOCAL: 3257 case SYNC_PREF_LOCAL:
3260 if ( lastSync > remoteMod ) 3258 if ( lastSync > remoteMod )
3261 return 1; 3259 return 1;
3262 if ( lastSync > localMod ) 3260 if ( lastSync > localMod )
3263 return 2; 3261 return 2;
3264 return 1; 3262 return 1;
3265 break; 3263 break;
3266 case SYNC_PREF_REMOTE: 3264 case SYNC_PREF_REMOTE:
3267 if ( lastSync > remoteMod ) 3265 if ( lastSync > remoteMod )
3268 return 1; 3266 return 1;
3269 if ( lastSync > localMod ) 3267 if ( lastSync > localMod )
3270 return 2; 3268 return 2;
3271 return 2; 3269 return 2;
3272 break; 3270 break;
3273 case SYNC_PREF_NEWEST: 3271 case SYNC_PREF_NEWEST:
3274 if ( localMod > remoteMod ) 3272 if ( localMod > remoteMod )
3275 return 1; 3273 return 1;
3276 else 3274 else
3277 return 2; 3275 return 2;
3278 break; 3276 break;
3279 case SYNC_PREF_ASK: 3277 case SYNC_PREF_ASK:
3280 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3278 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3281 if ( lastSync > remoteMod ) 3279 if ( lastSync > remoteMod )
3282 return 1; 3280 return 1;
3283 if ( lastSync > localMod ) 3281 if ( lastSync > localMod )
3284 return 2; 3282 return 2;
3285 localIsNew = localMod >= remoteMod; 3283 localIsNew = localMod >= remoteMod;
3286 //qDebug("conflict! ************************************** "); 3284 //qDebug("conflict! ************************************** ");
3287 { 3285 {
3288 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3286 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3289 result = acd.executeD(localIsNew); 3287 result = acd.executeD(localIsNew);
3290 return result; 3288 return result;
3291 } 3289 }
3292 break; 3290 break;
3293 case SYNC_PREF_FORCE_LOCAL: 3291 case SYNC_PREF_FORCE_LOCAL:
3294 return 1; 3292 return 1;
3295 break; 3293 break;
3296 case SYNC_PREF_FORCE_REMOTE: 3294 case SYNC_PREF_FORCE_REMOTE:
3297 return 2; 3295 return 2;
3298 break; 3296 break;
3299 3297
3300 default: 3298 default:
3301 // SYNC_PREF_TAKE_BOTH not implemented 3299 // SYNC_PREF_TAKE_BOTH not implemented
3302 break; 3300 break;
3303 } 3301 }
3304 return 0; 3302 return 0;
3305} 3303}
3306 3304
3307void PwMDoc::removeSyncInfo( QString syncProfile) 3305void PwMDoc::removeSyncInfo( QString syncProfile)
3308{ 3306{
3309 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1()); 3307 qDebug("PwMDoc::not implemented: removeSyncInfo for profile %s ", syncProfile.latin1());
3310} 3308}
3311 3309
3312 3310
3313//this are the overwritten callbackmethods from the syncinterface 3311//this are the overwritten callbackmethods from the syncinterface
3314bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3312bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3315{ 3313{
3316 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3314 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3317 3315
3318 //1) unlock local file first if necessary (ask for password) 3316 //1) unlock local file first if necessary (ask for password)
3319 if (this->isDeepLocked()) { 3317 if (this->isDeepLocked()) {
3320 PwMerror ret = this->deepLock(false); 3318 PwMerror ret = this->deepLock(false);
3321 if (ret != e_success) 3319 if (ret != e_success)
3322 return false; 3320 return false;
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index e419c24..09923ab 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -35,384 +35,404 @@
35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01)) 35 #define PWM_CRYPT_BLOWFISH(static_cast<char>(0x01))
36 #define PWM_CRYPT_AES128(static_cast<char>(0x02)) 36 #define PWM_CRYPT_AES128(static_cast<char>(0x02))
37 #define PWM_CRYPT_AES192(static_cast<char>(0x03)) 37 #define PWM_CRYPT_AES192(static_cast<char>(0x03))
38 #define PWM_CRYPT_AES256(static_cast<char>(0x04)) 38 #define PWM_CRYPT_AES256(static_cast<char>(0x04))
39 #define PWM_CRYPT_3DES (static_cast<char>(0x05)) 39 #define PWM_CRYPT_3DES (static_cast<char>(0x05))
40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06)) 40 #define PWM_CRYPT_TWOFISH(static_cast<char>(0x06))
41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07)) 41 #define PWM_CRYPT_TWOFISH128(static_cast<char>(0x07))
42 42
43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00)) 43 #define PWM_COMPRESS_NONE(static_cast<char>(0x00))
44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01)) 44 #define PWM_COMPRESS_GZIP(static_cast<char>(0x01))
45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02)) 45 #define PWM_COMPRESS_BZIP2(static_cast<char>(0x02))
46 46
47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0))) 47 #define DEFAULT_MAX_ENTRIES(~(static_cast<unsigned int>(0)))
48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE" 48 #define FILE_ID_HEADER "PWM_PASSWORD_FILE"
49 49
50 50
51#include "pwmexception.h" 51#include "pwmexception.h"
52#include "pwmdocui.h" 52#include "pwmdocui.h"
53 53
54#include <qobject.h> 54#include <qobject.h>
55#include <qtimer.h> 55#include <qtimer.h>
56#include <qdatetime.h> 56#include <qdatetime.h>
57 57
58#include <kprocess.h> 58#include <kprocess.h>
59 59
60#ifndef PWM_EMBEDDED 60#ifndef PWM_EMBEDDED
61#include "configuration.h" 61#include "configuration.h"
62#else 62#else
63#include <kapplication.h> 63#include <kapplication.h>
64#include <ksyncmanager.h> 64#include <ksyncmanager.h>
65#endif 65#endif
66 66
67#include <string> 67#include <string>
68#include <vector> 68#include <vector>
69#include <utility> 69#include <utility>
70 70
71using std::vector; 71using std::vector;
72using std::string; 72using std::string;
73using std::pair; 73using std::pair;
74 74
75/* used in findEntry() function */ 75/* used in findEntry() function */
76 #define SEARCH_IN_DESC (1) 76 #define SEARCH_IN_DESC (1)
77 #define SEARCH_IN_NAME (1 << 1) 77 #define SEARCH_IN_NAME (1 << 1)
78 #define SEARCH_IN_PW (1 << 2) 78 #define SEARCH_IN_PW (1 << 2)
79 #define SEARCH_IN_COMMENT(1 << 3) 79 #define SEARCH_IN_COMMENT(1 << 3)
80 #define SEARCH_IN_URL (1 << 4) 80 #define SEARCH_IN_URL (1 << 4)
81 #define SEARCH_IN_LAUNCHER(1 << 5) 81 #define SEARCH_IN_LAUNCHER(1 << 5)
82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \ 82 #define SEARCH_IN_ALL (SEARCH_IN_DESC | SEARCH_IN_NAME| \
83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \ 83 SEARCH_IN_PW | SEARCH_IN_COMMENT| \
84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER) 84 SEARCH_IN_URL| SEARCH_IN_LAUNCHER)
85 85
86/** document deeplocked. Data is out for lunch to disk */ 86/** document deeplocked. Data is out for lunch to disk */
87 #define DOC_STAT_DEEPLOCKED (1) 87 #define DOC_STAT_DEEPLOCKED (1)
88/** encrypted document on disk is dirty. data has to go to disk. */ 88/** encrypted document on disk is dirty. data has to go to disk. */
89 #define DOC_STAT_DISK_DIRTY (1 << 1) 89 #define DOC_STAT_DISK_DIRTY (1 << 1)
90/** we are using a chipcard to encrypt the data */ 90/** we are using a chipcard to encrypt the data */
91 #define DOC_STAT_USE_CHIPCARD (1 << 2) 91 #define DOC_STAT_USE_CHIPCARD (1 << 2)
92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */ 92/** use "currentPw" to unlock. (This flag is set/unset by a timer) */
93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3) 93 #define DOC_STAT_UNLOCK_WITHOUT_PW(1 << 3)
94 94
95class PwMDoc; 95class PwMDoc;
96class PwMView; 96class PwMView;
97class QFile; 97class QFile;
98 98
99/* meta data for a PwMDataItem */ 99/* meta data for a PwMDataItem */
100struct PwMMetaData 100struct PwMMetaData
101{ 101{
102 PwMMetaData() 102 PwMMetaData()
103 : updateInt (0) 103 : updateInt (0)
104 { } 104 { }
105 /** creation date of the PwMDataItem to which 105 /** creation date of the PwMDataItem to which
106 * this meta data belongs. 106 * this meta data belongs.
107 */ 107 */
108 QDateTimecreate; 108 QDateTimecreate;
109 /** becomes valid on this date */ 109 /** becomes valid on this date */
110 QDateTimevalid; 110 QDateTimevalid;
111 /** expire date */ 111 /** expire date */
112 QDateTimeexpire; 112 QDateTimeexpire;
113 /** update date (last updated at this date) */ 113 /** update date (last updated at this date) */
114 QDateTimeupdate; 114 QDateTimeupdate;
115 /** update interval (in minutes). Time since the 115 /** update interval (in minutes). Time since the
116 * last update to remind the user to update the item. 116 * last update to remind the user to update the item.
117 * 0 disables. 117 * 0 disables.
118 */ 118 */
119 unsigned long updateInt; 119 unsigned long updateInt;
120 120
121 //US ENH: enhancements of the filestructure 121 //US ENH: enhancements of the filestructure
122 /* each entry gets a unique id assigned */ 122 /* each entry gets a unique id assigned */
123 string uniqueid; 123 string uniqueid;
124 124
125 125
126 void clear() 126 void clear()
127 { 127 {
128 create = QDateTime(); 128 create = QDateTime();
129 expire = QDateTime(); 129 expire = QDateTime();
130 update = QDateTime(); 130 update = QDateTime();
131 updateInt = 0; 131 updateInt = 0;
132 uniqueid = KApplication::randomString(8).latin1(); 132 uniqueid = KApplication::randomString(8).latin1();
133 } 133 }
134 134
135 inline bool isValid() const 135 inline bool isValid() const
136 { 136 {
137 if (valid.isNull()) 137 if (valid.isNull())
138 return true; 138 return true;
139 return (valid < QDateTime::currentDateTime()); 139 return (valid < QDateTime::currentDateTime());
140 } 140 }
141 inline bool isExpired() const 141 inline bool isExpired() const
142 { 142 {
143 if (expire.isNull()) 143 if (expire.isNull())
144 return false; 144 return false;
145 return (expire < QDateTime::currentDateTime()); 145 return (expire < QDateTime::currentDateTime());
146 } 146 }
147 inline bool isUpdateIntOver() const 147 inline bool isUpdateIntOver() const
148 { 148 {
149 if (updateInt == 0 || 149 if (updateInt == 0 ||
150 update.isNull()) 150 update.isNull())
151 return false; 151 return false;
152 QDateTime d(update); 152 QDateTime d(update);
153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime()); 153 return (d.addSecs(updateInt * 60) < QDateTime::currentDateTime());
154 } 154 }
155}; 155};
156 156
157struct PwMDataItem 157struct PwMDataItem
158{ 158{
159 PwMDataItem() 159 PwMDataItem()
160 : lockStat (true) 160 : lockStat (true)
161 , listViewPos (-1) 161 , listViewPos (-1)
162 , binary (false) 162 , binary (false)
163 , rev (0) 163 , rev (0)
164 { } 164 { }
165 165
166 /** password description */ 166 /** password description */
167 stringdesc; 167 stringdesc;
168 /** user-name */ 168 /** user-name */
169 stringname; 169 stringname;
170 /** the password itself */ 170 /** the password itself */
171 stringpw; 171 stringpw;
172 /** some comment */ 172 /** some comment */
173 stringcomment; 173 stringcomment;
174 /** an URL string */ 174 /** an URL string */
175 stringurl; 175 stringurl;
176 /** launcher. Can be executed as a system() command */ 176 /** launcher. Can be executed as a system() command */
177 stringlauncher; 177 stringlauncher;
178 /** locking status. If locked (true), pw is not emitted through getEntry() */ 178 /** locking status. If locked (true), pw is not emitted through getEntry() */
179 boollockStat; 179 boollockStat;
180 /** position of this item in main "list-view" 180 /** position of this item in main "list-view"
181 * If -1, the position is not yet specified and should be appended to the list 181 * If -1, the position is not yet specified and should be appended to the list
182 */ 182 */
183 intlistViewPos; 183 intlistViewPos;
184 /** does this entry contain binary data? */ 184 /** does this entry contain binary data? */
185 bool binary; 185 bool binary;
186 /** meta data for this data item. */ 186 /** meta data for this data item. */
187 PwMMetaData meta; 187 PwMMetaData meta;
188 /** data revision counter. This counter can be used 188 /** data revision counter. This counter can be used
189 * to easily, efficiently determine if this data item 189 * to easily, efficiently determine if this data item
190 * has changed since some time. 190 * has changed since some time.
191 * This counter is incremented on every update. 191 * This counter is incremented on every update.
192 */ 192 */
193 unsigned int rev; 193 unsigned int rev;
194 194
195 void clear(bool clearMeta = true) 195 void clear(bool clearMeta = true)
196 { 196 {
197 /* NOTE: Don't use .clear() here to be 197 /* NOTE: Don't use .clear() here to be
198 * backward compatible with gcc-2 (Debian Woody) 198 * backward compatible with gcc-2 (Debian Woody)
199 */ 199 */
200 desc = ""; 200 desc = "";
201 name = ""; 201 name = "";
202 pw = ""; 202 pw = "";
203 comment = ""; 203 comment = "";
204 url = ""; 204 url = "";
205 launcher = ""; 205 launcher = "";
206 lockStat = true; 206 lockStat = true;
207 listViewPos = -1; 207 listViewPos = -1;
208 binary = false; 208 binary = false;
209 if (clearMeta) 209 if (clearMeta)
210 meta.clear(); 210 meta.clear();
211 } 211 }
212 //US ENH: we need this operator to compare two items if we have no unique ids 212 //US ENH: we need this operator to compare two items if we have no unique ids
213 //available. Generaly this happens before the first sync 213 //available. Generaly this happens before the first sync
214 214
215 bool PwMDataItem::operator==( const PwMDataItem &a ) const 215 bool PwMDataItem::operator==( const PwMDataItem &a ) const
216 { 216 {
217 //qDebug("oper==%s", a.desc.c_str()); 217 //qDebug("oper==%s", a.desc.c_str());
218 if ( desc != a.desc ) return false; 218 if ( desc != a.desc ) return false;
219 if ( name != a.name ) return false; 219 if ( name != a.name ) return false;
220 if ( pw != a.pw ) return false; 220 if ( pw != a.pw ) return false;
221 if ( comment != a.comment ) return false; 221 if ( comment != a.comment ) return false;
222 if ( url != a.url ) return false; 222 if ( url != a.url ) return false;
223 if ( launcher != a.launcher ) return false; 223 if ( launcher != a.launcher ) return false;
224 //all other field will not be checked. 224 //all other field will not be checked.
225 return true; 225 return true;
226 } 226 }
227
228 //US ENH: this sync method actually copies all values from the parameter like the =operator
229 //does with two exceptions: listViewPos will not be changed, and the launcher only if required.
230 bool PwMDataItem::syncItem(const PwMDataItem &a, bool syncLauncher=true )
231 {
232 desc = a.desc;
233 name = a.name;
234 pw = a.pw;
235 comment = a.comment;
236 url = a.url;
237 if (syncLauncher == true)
238 launcher = a.launcher;
239 meta = a.meta;
240 binary = a.binary;
241 lockStat = a.lockStat;
242 rev = a.rev;
243
244 return true;
245 }
246
227}; 247};
228 248
229struct PwMCategoryItem 249struct PwMCategoryItem
230{ 250{
231 /** all PwMDataItems (all passwords) within this category */ 251 /** all PwMDataItems (all passwords) within this category */
232 vector<PwMDataItem>d; 252 vector<PwMDataItem>d;
233 /** category name/description */ 253 /** category name/description */
234 string name; 254 string name;
235 255
236 void clear() 256 void clear()
237 { 257 {
238 d.clear(); 258 d.clear();
239 name = ""; 259 name = "";
240 } 260 }
241}; 261};
242 262
243struct PwMSyncItem 263struct PwMSyncItem
244{ 264{
245 string syncName; 265 string syncName;
246 QDateTime lastSyncDate; 266 QDateTime lastSyncDate;
247 267
248 void clear() 268 void clear()
249 { 269 {
250 lastSyncDate = QDateTime(); 270 lastSyncDate = QDateTime();
251 syncName = ""; 271 syncName = "";
252 } 272 }
253}; 273};
254 274
255struct PwMItem 275struct PwMItem
256{ 276{
257 vector<PwMCategoryItem> dta; 277 vector<PwMCategoryItem> dta;
258 vector<PwMSyncItem> syncDta; 278 vector<PwMSyncItem> syncDta;
259 279
260 void clear() 280 void clear()
261 { 281 {
262 dta.clear(); 282 dta.clear();
263 syncDta.clear(); 283 syncDta.clear();
264 } 284 }
265}; 285};
266 286
267 287
268/** "Function Object" for sort()ing PwMDataItem::listViewPos */ 288/** "Function Object" for sort()ing PwMDataItem::listViewPos */
269class dta_lvp_greater 289class dta_lvp_greater
270{ 290{
271public: 291public:
272 bool operator() (const pair<unsigned int, unsigned int> &d1, 292 bool operator() (const pair<unsigned int, unsigned int> &d1,
273 const pair<unsigned int, unsigned int> &d2) 293 const pair<unsigned int, unsigned int> &d2)
274 { 294 {
275 return d1.second > d2.second; 295 return d1.second > d2.second;
276 } 296 }
277}; 297};
278 298
279/** list of PwMDoc documents and it's IDs */ 299/** list of PwMDoc documents and it's IDs */
280class PwMDocList 300class PwMDocList
281{ 301{
282public: 302public:
283 struct listItem 303 struct listItem
284 { 304 {
285 /** document filename (known as ID, here) */ 305 /** document filename (known as ID, here) */
286 string docId; 306 string docId;
287 /** pointer to the document class */ 307 /** pointer to the document class */
288 PwMDoc *doc; 308 PwMDoc *doc;
289 }; 309 };
290 310
291 PwMDocList() {} 311 PwMDocList() {}
292 312
293 /** add a new item to the list */ 313 /** add a new item to the list */
294 void add(PwMDoc *doc, const string &id); 314 void add(PwMDoc *doc, const string &id);
295 /** changes the contents of an existing item */ 315 /** changes the contents of an existing item */
296 void edit(PwMDoc *doc, const string &newId); 316 void edit(PwMDoc *doc, const string &newId);
297 /** remove the given item */ 317 /** remove the given item */
298 void del(PwMDoc *doc); 318 void del(PwMDoc *doc);
299 /** get the item at index */ 319 /** get the item at index */
300 listItem getAt(int index) 320 listItem getAt(int index)
301 { return docList[index]; } 321 { return docList[index]; }
302 /** find an entry with this id */ 322 /** find an entry with this id */
303 bool find(const string &id, listItem *ret = 0); 323 bool find(const string &id, listItem *ret = 0);
304 /** returns a copy of the list */ 324 /** returns a copy of the list */
305 const vector<listItem>* getList() const 325 const vector<listItem>* getList() const
306 { return &docList; } 326 { return &docList; }
307 327
308 328
309 /** returns a new unique number to extend the name of 329 /** returns a new unique number to extend the name of
310 * an unnamed document. 330 * an unnamed document.
311 */ 331 */
312 static unsigned int getNewUnnamedNumber() 332 static unsigned int getNewUnnamedNumber()
313 { return unnamedDocCnt++; } 333 { return unnamedDocCnt++; }
314 334
315protected: 335protected:
316 /* Hm, I think we shouldn't really use a "list" here, should we? 336 /* Hm, I think we shouldn't really use a "list" here, should we?
317 * So I decided to actually use a vector. 337 * So I decided to actually use a vector.
318 */ 338 */
319 vector<listItem> docList; 339 vector<listItem> docList;
320 /** This value is used to get a new number for yet unnamed 340 /** This value is used to get a new number for yet unnamed
321 * documents. It is incremented on every request. So it's 341 * documents. It is incremented on every request. So it's
322 * theoretically possible to overflow it, but... :) 342 * theoretically possible to overflow it, but... :)
323 */ 343 */
324 static unsigned int unnamedDocCnt; 344 static unsigned int unnamedDocCnt;
325}; 345};
326 346
327/** implements timers for the document */ 347/** implements timers for the document */
328class DocTimer : public QObject 348class DocTimer : public QObject
329{ 349{
330 Q_OBJECT 350 Q_OBJECT
331public: 351public:
332 enum TimerIDs 352 enum TimerIDs
333 { 353 {
334 id_mpwTimer, 354 id_mpwTimer,
335 id_autoLockTimer, 355 id_autoLockTimer,
336 id_metaCheckTimer 356 id_metaCheckTimer
337 }; 357 };
338 358
339public: 359public:
340 DocTimer(PwMDoc *_doc); 360 DocTimer(PwMDoc *_doc);
341 ~DocTimer(); 361 ~DocTimer();
342 362
343 /** start the timer */ 363 /** start the timer */
344 void start(TimerIDs timer); 364 void start(TimerIDs timer);
345 /** stop the timer */ 365 /** stop the timer */
346 void stop(TimerIDs timer); 366 void stop(TimerIDs timer);
347 /** get the lock for a timer. 367 /** get the lock for a timer.
348 * This lock is a recursive lock. When a lock is 368 * This lock is a recursive lock. When a lock is
349 * held, the timer will be stopped and timeout is 369 * held, the timer will be stopped and timeout is
350 * guaranteed to not happen 370 * guaranteed to not happen
351 */ 371 */
352 void getLock(TimerIDs timer); 372 void getLock(TimerIDs timer);
353 /** put a recursive timer lock */ 373 /** put a recursive timer lock */
354 void putLock(TimerIDs timer); 374 void putLock(TimerIDs timer);
355 375
356protected slots: 376protected slots:
357 /** timeout slot for the mpw timer */ 377 /** timeout slot for the mpw timer */
358 void mpwTimeout(); 378 void mpwTimeout();
359 /** timeout slot for the autoLock timer */ 379 /** timeout slot for the autoLock timer */
360 void autoLockTimeout(); 380 void autoLockTimeout();
361 /** timeout slot for the metaCheck timer */ 381 /** timeout slot for the metaCheck timer */
362 void metaCheckTimeout(); 382 void metaCheckTimeout();
363 383
364protected: 384protected:
365 /** pointer to the document associated with this timer. */ 385 /** pointer to the document associated with this timer. */
366 PwMDoc *doc; 386 PwMDoc *doc;
367 /** timer object for mpw timer */ 387 /** timer object for mpw timer */
368 QTimer *mpwTimer; 388 QTimer *mpwTimer;
369 /** timer object for the autoLock timer */ 389 /** timer object for the autoLock timer */
370 QTimer *autoLockTimer; 390 QTimer *autoLockTimer;
371 /** timer object for the metaCheck timer */ 391 /** timer object for the metaCheck timer */
372 QTimer *metaCheckTimer; 392 QTimer *metaCheckTimer;
373 /** lock counter for the mpw timer */ 393 /** lock counter for the mpw timer */
374 unsigned int mpwLock; 394 unsigned int mpwLock;
375 /** lock counter for the autoLock timer */ 395 /** lock counter for the autoLock timer */
376 unsigned int autoLockLock; 396 unsigned int autoLockLock;
377 /** lock counter for the metaCheck timer */ 397 /** lock counter for the metaCheck timer */
378 unsigned int metaCheckLock; 398 unsigned int metaCheckLock;
379}; 399};
380 400
381/** Document class for PwM */ 401/** Document class for PwM */
382//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required. 402//US ENH: derived from KSyncInterfaces, to get called by PwM when a sync is required.
383// But PwMDoc is handling the sync by itself. 403// But PwMDoc is handling the sync by itself.
384class PwMDoc : public PwMDocUi, public KSyncInterface 404class PwMDoc : public PwMDocUi, public KSyncInterface
385 405
386{ 406{
387 Q_OBJECT 407 Q_OBJECT
388 friend class DocTimer; 408 friend class DocTimer;
389 409
390public: 410public:
391 /** construtor */ 411 /** construtor */
392 PwMDoc(QObject* parent = 0, const char *name = 0); 412 PwMDoc(QObject* parent = 0, const char *name = 0);
393 /** destructor */ 413 /** destructor */
394 ~PwMDoc(); 414 ~PwMDoc();
395 415
396 /** returns a pointer to a list of all open documents */ 416 /** returns a pointer to a list of all open documents */
397 static PwMDocList* getOpenDocList() 417 static PwMDocList* getOpenDocList()
398 { return &openDocList; } 418 { return &openDocList; }
399 419
400 /** flag document dirty. dta changed */ 420 /** flag document dirty. dta changed */
401 void flagDirty() 421 void flagDirty()
402 { 422 {
403 setDocStatFlag(DOC_STAT_DISK_DIRTY); 423 setDocStatFlag(DOC_STAT_DISK_DIRTY);
404 emitDataChanged(this); 424 emitDataChanged(this);
405 } 425 }
406 /** modified? */ 426 /** modified? */
407 bool isDirty() 427 bool isDirty()
408 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); } 428 { return getDocStatFlag(DOC_STAT_DISK_DIRTY); }
409 /** save document to disk */ 429 /** save document to disk */
410 PwMerror saveDoc(char compress, const QString *file = 0); 430 PwMerror saveDoc(char compress, const QString *file = 0);
411 /** read document from file. 431 /** read document from file.
412 * "openLocked is must be set to either of these values: 432 * "openLocked is must be set to either of these values:
413 * 0 == open with all entries unlocked 433 * 0 == open with all entries unlocked
414 * 1 == open with all entries locked 434 * 1 == open with all entries locked
415 * 2 == open deep-locked 435 * 2 == open deep-locked
416 */ 436 */
417 PwMerror openDoc(const QString *file, int openLocked); 437 PwMerror openDoc(const QString *file, int openLocked);
418 /** export document to ascii-textfile */ 438 /** export document to ascii-textfile */