summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp22
-rw-r--r--pwmanager/pwmanager/pwmdoc.h4
2 files changed, 13 insertions, 13 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index ab3238a..3f2f042 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2706,398 +2706,398 @@ void PwMDoc::ensureLvp()
2706 return; 2706 return;
2707 2707
2708 vector< vector<PwMDataItem>::iterator > undefined; 2708 vector< vector<PwMDataItem>::iterator > undefined;
2709 vector< vector<PwMDataItem>::iterator >::iterator undefBegin, 2709 vector< vector<PwMDataItem>::iterator >::iterator undefBegin,
2710 undefEnd, 2710 undefEnd,
2711 undefI; 2711 undefI;
2712 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(), 2712 vector<PwMCategoryItem>::iterator catBegin = dti.dta.begin(),
2713 catEnd = dti.dta.end(), 2713 catEnd = dti.dta.end(),
2714 catI = catBegin; 2714 catI = catBegin;
2715 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI; 2715 vector<PwMDataItem>::iterator entrBegin, entrEnd, entrI;
2716 int lvpTop, tmpLvp; 2716 int lvpTop, tmpLvp;
2717 2717
2718 while (catI != catEnd) { 2718 while (catI != catEnd) {
2719 lvpTop = -1; 2719 lvpTop = -1;
2720 undefined.clear(); 2720 undefined.clear();
2721 2721
2722 entrBegin = catI->d.begin(); 2722 entrBegin = catI->d.begin();
2723 entrEnd = catI->d.end(); 2723 entrEnd = catI->d.end();
2724 entrI = entrBegin; 2724 entrI = entrBegin;
2725 2725
2726 while (entrI != entrEnd) { 2726 while (entrI != entrEnd) {
2727 tmpLvp = entrI->listViewPos; 2727 tmpLvp = entrI->listViewPos;
2728 if (tmpLvp == -1) 2728 if (tmpLvp == -1)
2729 undefined.push_back(entrI); 2729 undefined.push_back(entrI);
2730 else if (tmpLvp > lvpTop) 2730 else if (tmpLvp > lvpTop)
2731 lvpTop = tmpLvp; 2731 lvpTop = tmpLvp;
2732 ++entrI; 2732 ++entrI;
2733 } 2733 }
2734 undefBegin = undefined.begin(); 2734 undefBegin = undefined.begin();
2735 undefEnd = undefined.end(); 2735 undefEnd = undefined.end();
2736 undefI = undefBegin; 2736 undefI = undefBegin;
2737 while (undefI != undefEnd) { 2737 while (undefI != undefEnd) {
2738 (*undefI)->listViewPos = ++lvpTop; 2738 (*undefI)->listViewPos = ++lvpTop;
2739 ++undefI; 2739 ++undefI;
2740 } 2740 }
2741 ++catI; 2741 ++catI;
2742 } 2742 }
2743} 2743}
2744 2744
2745QString PwMDoc::getTitle() 2745QString PwMDoc::getTitle()
2746{ 2746{
2747 /* NOTE: We have to ensure, that the returned title 2747 /* NOTE: We have to ensure, that the returned title
2748 * is unique and not reused somewhere else while 2748 * is unique and not reused somewhere else while
2749 * this document is valid (open). 2749 * this document is valid (open).
2750 */ 2750 */
2751 QString title(getFilename()); 2751 QString title(getFilename());
2752 if (title.isEmpty()) { 2752 if (title.isEmpty()) {
2753 if (unnamedNum == 0) { 2753 if (unnamedNum == 0) {
2754 unnamedNum = PwMDocList::getNewUnnamedNumber(); 2754 unnamedNum = PwMDocList::getNewUnnamedNumber();
2755 PWM_ASSERT(unnamedNum != 0); 2755 PWM_ASSERT(unnamedNum != 0);
2756 } 2756 }
2757 title = DEFAULT_TITLE; 2757 title = DEFAULT_TITLE;
2758 title += " "; 2758 title += " ";
2759 title += tostr(unnamedNum).c_str(); 2759 title += tostr(unnamedNum).c_str();
2760 } 2760 }
2761 return title; 2761 return title;
2762} 2762}
2763 2763
2764bool PwMDoc::tryDelete() 2764bool PwMDoc::tryDelete()
2765{ 2765{
2766 if (deleted) 2766 if (deleted)
2767 return true; 2767 return true;
2768 int ret; 2768 int ret;
2769 if (isDirty()) { 2769 if (isDirty()) {
2770 ret = dirtyAskSave(getTitle()); 2770 ret = dirtyAskSave(getTitle());
2771 if (ret == 0) { // save to disk 2771 if (ret == 0) { // save to disk
2772 if (!saveDocUi(this)) 2772 if (!saveDocUi(this))
2773 goto out_ignore; 2773 goto out_ignore;
2774 } else if (ret == 1) { // don't save and delete 2774 } else if (ret == 1) { // don't save and delete
2775 goto out_accept; 2775 goto out_accept;
2776 } else { // cancel operation 2776 } else { // cancel operation
2777 goto out_ignore; 2777 goto out_ignore;
2778 } 2778 }
2779 } 2779 }
2780out_accept: 2780out_accept:
2781 deleted = true; 2781 deleted = true;
2782 delete this; 2782 delete this;
2783 return true; 2783 return true;
2784out_ignore: 2784out_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.
2793PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* syncRemote, int mode ) 2793PwMerror 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 //US 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())
2891 return e_syncError; 2891 return e_syncError;
2892 if ( incCounter % modulo == 0 ) 2892 if ( incCounter % modulo == 0 )
2893 manager->showProgressBar(incCounter); 2893 manager->showProgressBar(incCounter);
2894 2894
2895 uid = er[ incCounter ]; 2895 uid = er[ incCounter ];
2896 qDebug("sync uid %s from remote file", uid.latin1()); 2896 qDebug("sync uid %s from remote file", uid.latin1());
2897 2897
2898 qApp->processEvents(); 2898 qApp->processEvents();
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 2923
2924 //first check if we have a matching category in the local file 2924 //first check if we have a matching category in the local file
2925 const string* remotecat = syncRemote->getCategory(catRemote); 2925 const string* remotecat = syncRemote->getCategory(catRemote);
2926 //US syncRemote->insertAddressee( inRemote, false ); 2926 //US syncRemote->insertAddressee( inRemote, false );
2927 //US syncLocal->insertAddressee( inRemote, false ); 2927 //US syncLocal->insertAddressee( inRemote, false );
2928 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false); 2928 syncLocal->addEntry(remotecat->c_str(), inRemote, true, false);
2929 2929
2930 ++addedPasswordsLocal; 2930 ++addedPasswordsLocal;
2931 } else { 2931 } else {
2932 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2932 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2933 syncRemote->delEntry(catRemote, indexRemote, true); 2933 syncRemote->delEntry(catRemote, indexRemote, true);
2934 //USsyncRemote->removeAddressee( inRemote ); 2934 //USsyncRemote->removeAddressee( inRemote );
2935 ++deletedPasswordsRemote; 2935 ++deletedPasswordsRemote;
2936 } 2936 }
2937 } 2937 }
2938 2938
2939 ++incCounter; 2939 ++incCounter;
2940 } 2940 }
2941 2941
2942 2942
2943 er.clear(); 2943 er.clear();
2944 QStringList el = syncLocal->getIDEntryList(); 2944 QStringList el = syncLocal->getIDEntryList();
2945 modulo = (el.count()/10)+1; 2945 modulo = (el.count()/10)+1;
2946 2946
2947 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2947 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2948 incCounter = 0; 2948 incCounter = 0;
2949 while ( incCounter < el.count()) { 2949 while ( incCounter < el.count()) {
2950 qApp->processEvents(); 2950 qApp->processEvents();
2951 if (manager->isProgressBarCanceled()) 2951 if (manager->isProgressBarCanceled())
2952 return e_syncError; 2952 return e_syncError;
2953 if ( incCounter % modulo == 0 ) 2953 if ( incCounter % modulo == 0 )
2954 manager->showProgressBar(incCounter); 2954 manager->showProgressBar(incCounter);
2955 uid = el[ incCounter ]; 2955 uid = el[ incCounter ];
2956 2956
2957 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 2957 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
2958 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 2958 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
2959 PWM_ASSERT(inLocal); 2959 PWM_ASSERT(inLocal);
2960 2960
2961 if ( inRemote == 0 ) { 2961 if ( inRemote == 0 ) {
2962 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 2962 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
2963 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2963 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2964 syncLocal->delEntry(catLocal, indexLocal, true); 2964 syncLocal->delEntry(catLocal, indexLocal, true);
2965 //USsyncLocal->removeAddressee( inLocal ); 2965 //USsyncLocal->removeAddressee( inLocal );
2966 ++deletedPasswordsLocal; 2966 ++deletedPasswordsLocal;
2967 } else { 2967 } else {
2968 if ( ! manager->mWriteBackExistingOnly ) { 2968 if ( ! manager->mWriteBackExistingOnly ) {
2969 ++addedPasswordsRemote; 2969 ++addedPasswordsRemote;
2970 inLocal->meta.update = modifiedSync; 2970 inLocal->meta.update = modifiedSync;
2971 2971
2972 //first check if we have a matching category in the remote file 2972 //first check if we have a matching category in the remote file
2973 const string* localcat = syncLocal->getCategory(catLocal); 2973 const string* localcat = syncLocal->getCategory(catLocal);
2974 2974
2975 //USsyncLocal->insertAddressee( inLocal, false ); 2975 //USsyncLocal->insertAddressee( inLocal, false );
2976 PwMDataItem newEntry; 2976 PwMDataItem newEntry;
2977 newEntry = *inLocal; 2977 newEntry = *inLocal;
2978 inRemote = &newEntry; 2978 inRemote = &newEntry;
2979 2979
2980 //USsyncRemote->insertAddressee( inRemote, false ); 2980 //USsyncRemote->insertAddressee( inRemote, false );
2981 syncRemote->addEntry(localcat->c_str(), inRemote, true, false); 2981 syncRemote->addEntry(localcat->c_str(), inRemote, true, false);
2982 2982
2983 } 2983 }
2984 } 2984 }
2985 2985
2986 } 2986 }
2987 ++incCounter; 2987 ++incCounter;
2988 } 2988 }
2989 el.clear(); 2989 el.clear();
2990 manager->hideProgressBar(); 2990 manager->hideProgressBar();
2991 2991
2992 // 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
2993 2993
2994 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 2994 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
2995 // get rid of micro seconds 2995 // get rid of micro seconds
2996 QTime t = mLastSync.time(); 2996 QTime t = mLastSync.time();
2997 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2997 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2998 2998
2999 2999
3000 syncItemLocal.lastSyncDate = mLastSync; 3000 syncItemLocal->lastSyncDate = mLastSync;
3001 syncItemRemote.lastSyncDate = mLastSync; 3001 syncItemRemote->lastSyncDate = mLastSync;
3002 3002
3003 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 3003 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
3004 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 3004 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
3005 3005
3006 syncRemote->addSyncDataEntry( syncItemRemote, false ); 3006 //US syncRemote->addSyncDataEntry( syncItemRemote, false );
3007 syncLocal->addSyncDataEntry( syncItemLocal, false ); 3007 //US syncLocal->addSyncDataEntry( syncItemLocal, false );
3008 QString mes; 3008 QString mes;
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 ); 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 );
3010 if ( manager->mShowSyncSummary ) { 3010 if ( manager->mShowSyncSummary ) {
3011 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") ); 3011 KMessageBox::information(0, mes, i18n("PWM/Pi Synchronization") );
3012 } 3012 }
3013 qDebug( mes ); 3013 qDebug( mes );
3014 return e_success; 3014 return e_success;
3015} 3015}
3016 3016
3017 3017
3018int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3018int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3019{ 3019{
3020 // 0 equal 3020 // 0 equal
3021 // 1 take local 3021 // 1 take local
3022 // 2 take remote 3022 // 2 take remote
3023 // 3 cancel 3023 // 3 cancel
3024 QDateTime localMod = local->meta.update; 3024 QDateTime localMod = local->meta.update;
3025 QDateTime remoteMod = remote->meta.update; 3025 QDateTime remoteMod = remote->meta.update;
3026 3026
3027 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3027 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3028 3028
3029 if ( localMod == remoteMod ) 3029 if ( localMod == remoteMod )
3030 return 0; 3030 return 0;
3031 3031
3032 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3032 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3033 3033
3034 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3034 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3035 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3035 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3036 //full = true; //debug only 3036 //full = true; //debug only
3037 if ( full ) { 3037 if ( full ) {
3038 bool equ = true;//US ( (*local) == (*remote) ); 3038 bool equ = true;//US ( (*local) == (*remote) );
3039 if ( equ ) { 3039 if ( equ ) {
3040 //qDebug("equal "); 3040 //qDebug("equal ");
3041 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3041 if ( mode < SYNC_PREF_FORCE_LOCAL )
3042 return 0; 3042 return 0;
3043 3043
3044 }//else //debug only 3044 }//else //debug only
3045 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 3045 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
3046 } 3046 }
3047 3047
3048 int result; 3048 int result;
3049 bool localIsNew; 3049 bool localIsNew;
3050 //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() ); 3050 //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() );
3051 3051
3052 if ( full && mode < SYNC_PREF_NEWEST ) 3052 if ( full && mode < SYNC_PREF_NEWEST )
3053 mode = SYNC_PREF_ASK; 3053 mode = SYNC_PREF_ASK;
3054 3054
3055 switch( mode ) { 3055 switch( mode ) {
3056 case SYNC_PREF_LOCAL: 3056 case SYNC_PREF_LOCAL:
3057 if ( lastSync > remoteMod ) 3057 if ( lastSync > remoteMod )
3058 return 1; 3058 return 1;
3059 if ( lastSync > localMod ) 3059 if ( lastSync > localMod )
3060 return 2; 3060 return 2;
3061 return 1; 3061 return 1;
3062 break; 3062 break;
3063 case SYNC_PREF_REMOTE: 3063 case SYNC_PREF_REMOTE:
3064 if ( lastSync > remoteMod ) 3064 if ( lastSync > remoteMod )
3065 return 1; 3065 return 1;
3066 if ( lastSync > localMod ) 3066 if ( lastSync > localMod )
3067 return 2; 3067 return 2;
3068 return 2; 3068 return 2;
3069 break; 3069 break;
3070 case SYNC_PREF_NEWEST: 3070 case SYNC_PREF_NEWEST:
3071 if ( localMod > remoteMod ) 3071 if ( localMod > remoteMod )
3072 return 1; 3072 return 1;
3073 else 3073 else
3074 return 2; 3074 return 2;
3075 break; 3075 break;
3076 case SYNC_PREF_ASK: 3076 case SYNC_PREF_ASK:
3077 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3077 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3078 if ( lastSync > remoteMod ) 3078 if ( lastSync > remoteMod )
3079 return 1; 3079 return 1;
3080 if ( lastSync > localMod ) 3080 if ( lastSync > localMod )
3081 return 2; 3081 return 2;
3082 localIsNew = localMod >= remoteMod; 3082 localIsNew = localMod >= remoteMod;
3083 //qDebug("conflict! ************************************** "); 3083 //qDebug("conflict! ************************************** ");
3084 { 3084 {
3085 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3085 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3086 result = acd.executeD(localIsNew); 3086 result = acd.executeD(localIsNew);
3087 return result; 3087 return result;
3088 } 3088 }
3089 break; 3089 break;
3090 case SYNC_PREF_FORCE_LOCAL: 3090 case SYNC_PREF_FORCE_LOCAL:
3091 return 1; 3091 return 1;
3092 break; 3092 break;
3093 case SYNC_PREF_FORCE_REMOTE: 3093 case SYNC_PREF_FORCE_REMOTE:
3094 return 2; 3094 return 2;
3095 break; 3095 break;
3096 3096
3097 default: 3097 default:
3098 // SYNC_PREF_TAKE_BOTH not implemented 3098 // SYNC_PREF_TAKE_BOTH not implemented
3099 break; 3099 break;
3100 } 3100 }
3101 return 0; 3101 return 0;
3102} 3102}
3103 3103
diff --git a/pwmanager/pwmanager/pwmdoc.h b/pwmanager/pwmanager/pwmdoc.h
index ddab7f3..2e9547e 100644
--- a/pwmanager/pwmanager/pwmdoc.h
+++ b/pwmanager/pwmanager/pwmdoc.h
@@ -698,109 +698,109 @@ protected:
698 unsigned int dataChangedLock; 698 unsigned int dataChangedLock;
699 699
700 /** list of all open documents */ 700 /** list of all open documents */
701 static PwMDocList openDocList; 701 static PwMDocList openDocList;
702 702
703protected: 703protected:
704 /** serialize "dta" and return it in "d". */ 704 /** serialize "dta" and return it in "d". */
705 bool serializeDta(string *d); 705 bool serializeDta(string *d);
706 /** de-serialize "d" and overwrite "dta" */ 706 /** de-serialize "d" and overwrite "dta" */
707 bool deSerializeDta(const string *d, bool entriesLocked); 707 bool deSerializeDta(const string *d, bool entriesLocked);
708 /** write header to file */ 708 /** write header to file */
709 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress, 709 PwMerror writeFileHeader(char keyHash, char dataHash, char crypt, char compress,
710 QString *pw, QFile *f); 710 QString *pw, QFile *f);
711 /** write data-hash to file */ 711 /** write data-hash to file */
712 PwMerror writeDataHash(char dataHash, string *d, QFile *f); 712 PwMerror writeDataHash(char dataHash, string *d, QFile *f);
713 /** check header. Read header info and verify key-hash and filever. 713 /** check header. Read header info and verify key-hash and filever.
714 * returns length of header in "headerLength" */ 714 * returns length of header in "headerLength" */
715 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress, 715 PwMerror checkHeader(char *cryptAlgo, QString *pw, char *compress,
716 unsigned int *headerLength, char *dataHashType, 716 unsigned int *headerLength, char *dataHashType,
717 string *dataHash, QFile *f); 717 string *dataHash, QFile *f);
718 /** check the data-hash */ 718 /** check the data-hash */
719 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream); 719 PwMerror checkDataHash(char dataHashType, const string *dataHash, const string *dataStream);
720 /** encrypt data "d" and write to "filename" */ 720 /** encrypt data "d" and write to "filename" */
721 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo); 721 PwMerror encrypt(string *d, const QString *pw, QFile *f, char algo);
722 /** read data from file beginning at "pos", decrypt and return it */ 722 /** read data from file beginning at "pos", decrypt and return it */
723 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f); 723 PwMerror decrypt(string *d, unsigned int pos, const QString *pw, char algo, QFile *f);
724 /** compress the data */ 724 /** compress the data */
725 bool compressDta(string *d, char algo); 725 bool compressDta(string *d, char algo);
726 /** uncompress the data */ 726 /** uncompress the data */
727 bool decompressDta(string *d, char algo); 727 bool decompressDta(string *d, char algo);
728 /** internal import function for a text-file generated by PwM. 728 /** internal import function for a text-file generated by PwM.
729 * If this is not a valid PwM-exported file, it returns e_fileFormat */ 729 * If this is not a valid PwM-exported file, it returns e_fileFormat */
730 PwMerror importText_PwM(const QString *file); 730 PwMerror importText_PwM(const QString *file);
731 /** PwM-text-import helper function to extract the name/pw/comment out 731 /** PwM-text-import helper function to extract the name/pw/comment out
732 * of one entry-line */ 732 * of one entry-line */
733 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out); 733 bool textExtractEntry_PwM(const char *in, ssize_t in_size, string *out);
734 /** compare two strings */ 734 /** compare two strings */
735 bool compareString(const string &s1, const string &s2, bool caseSensitive, 735 bool compareString(const string &s1, const string &s2, bool caseSensitive,
736 bool exactWordMatch); 736 bool exactWordMatch);
737 /** clears all document-data */ 737 /** clears all document-data */
738 void clearDoc(); 738 void clearDoc();
739 /** delete all empty categories */ 739 /** delete all empty categories */
740 void delAllEmptyCat(bool dontFlagDirty); 740 void delAllEmptyCat(bool dontFlagDirty);
741 /** set a document status flag */ 741 /** set a document status flag */
742 void setDocStatFlag(unsigned int statFlag) 742 void setDocStatFlag(unsigned int statFlag)
743 { curDocStat |= statFlag; } 743 { curDocStat |= statFlag; }
744 /** unset a document status flag */ 744 /** unset a document status flag */
745 void unsetDocStatFlag(unsigned int statFlag) 745 void unsetDocStatFlag(unsigned int statFlag)
746 { curDocStat &= ~statFlag; } 746 { curDocStat &= ~statFlag; }
747 /** get a document status flag */ 747 /** get a document status flag */
748 bool getDocStatFlag(unsigned int statFlag) const 748 bool getDocStatFlag(unsigned int statFlag) const
749 { return (curDocStat & statFlag); } 749 { return (curDocStat & statFlag); }
750 /** set the "currentPassword" */ 750 /** set the "currentPassword" */
751 void setCurrentPw(const QString &pw) 751 void setCurrentPw(const QString &pw)
752 { 752 {
753 currentPw = pw; 753 currentPw = pw;
754 setDocStatFlag(DOC_STAT_DISK_DIRTY); 754 setDocStatFlag(DOC_STAT_DISK_DIRTY);
755 } 755 }
756 /** make a backup-copy of the given file */ 756 /** make a backup-copy of the given file */
757 bool backupFile(const QString &filePath); 757 bool backupFile(const QString &filePath);
758 /** copy a file from src to dst */ 758 /** copy a file from src to dst */
759 bool copyFile(const QString &src, const QString &dst); 759 bool copyFile(const QString &src, const QString &dst);
760 760
761 761
762 public: 762 public:
763#ifdef PWM_EMBEDDED 763#ifdef PWM_EMBEDDED
764 //US ENH: this is the magic function that syncronizes the local doc with the remote doc. 764 //US ENH: this is the magic function that syncronizes the local doc with the remote doc.
765 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode ); 765 PwMerror syncronize(KSyncManager* manager, PwMDoc* syncLocal, PwMDoc* syncRemote, int mode );
766 766
767 //takePwMDataItem returns the following values 767 //takePwMDataItem returns the following values
768 // 0 equal 768 // 0 equal
769 // 1 take local 769 // 1 take local
770 // 2 take remote 770 // 2 take remote
771 // 3 cancel 771 // 3 cancel
772 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 );
773 773
774 //the following methods are the overwritten callbackmethods from the syncinterface 774 //the following methods are the overwritten callbackmethods from the syncinterface
775 virtual bool sync(KSyncManager* manager, QString filename, int mode); 775 virtual bool sync(KSyncManager* manager, QString filename, int mode);
776 776
777 //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.
778 virtual void sync_setModified(); 778 virtual void sync_setModified();
779 //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.
780 virtual bool sync_isModified(); 780 virtual bool sync_isModified();
781 //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.
782 virtual void sync_save(); 782 virtual void sync_save();
783 783
784#endif 784#endif
785 private: 785 private:
786 //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.
787 // It returns the syncdatas index 787 // It returns the syncdatas index
788 bool findSyncData(const QString &syncname, unsigned int *index); 788 bool findSyncData(const QString &syncname, unsigned int *index);
789 789
790 /** add new syncdataentry */ 790 /** add new syncdataentry */
791 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false); 791 PwMerror addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty = false);
792 792
793 /** returns a pointer to the syncdata */ 793 /** returns a pointer to the syncdata */
794 PwMSyncItem getSyncDataEntry(unsigned int index) 794 PwMSyncItem* getSyncDataEntry(unsigned int index)
795 { return *(dti.syncDta[index]); } 795 { return &(dti.syncDta[index]); }
796 796
797 /** delete entry */ 797 /** delete entry */
798 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false); 798 bool delSyncDataEntry(unsigned int index, bool dontFlagDirty = false);
799 799
800 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index); 800 PwMDataItem* findEntryByID(const QString &uid, unsigned int *category, unsigned int *index);
801 801
802 QStringList getIDEntryList(); 802 QStringList getIDEntryList();
803 803
804}; 804};
805 805
806#endif 806#endif