summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/pwmanager/pwmdoc.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/pwmanager/pwmanager/pwmdoc.cpp b/pwmanager/pwmanager/pwmdoc.cpp
index 4e8a603..6c1a9c0 100644
--- a/pwmanager/pwmanager/pwmdoc.cpp
+++ b/pwmanager/pwmanager/pwmdoc.cpp
@@ -2800,196 +2800,199 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
2800 int changedRemote = 0; 2800 int changedRemote = 0;
2801 2801
2802 PwMSyncItem* syncItemLocal; 2802 PwMSyncItem* syncItemLocal;
2803 PwMSyncItem* syncItemRemote; 2803 PwMSyncItem* syncItemRemote;
2804 2804
2805 QString mCurrentSyncName = manager->getCurrentSyncName(); 2805 QString mCurrentSyncName = manager->getCurrentSyncName();
2806 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2806 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2807 2807
2808 bool fullDateRange = false; 2808 bool fullDateRange = false;
2809 int take; 2809 int take;
2810 // local->resetTempSyncStat(); 2810 // local->resetTempSyncStat();
2811 QDateTime mLastSync = QDateTime::currentDateTime(); 2811 QDateTime mLastSync = QDateTime::currentDateTime();
2812 QDateTime modifiedSync = mLastSync; 2812 QDateTime modifiedSync = mLastSync;
2813 2813
2814 unsigned int index; 2814 unsigned int index;
2815 //Step 1. Find syncinfo in Local file and create if not existent. 2815 //Step 1. Find syncinfo in Local file and create if not existent.
2816 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2816 bool found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2817 if (found == false) 2817 if (found == false)
2818 { 2818 {
2819 PwMSyncItem newSyncItemLocal; 2819 PwMSyncItem newSyncItemLocal;
2820 newSyncItemLocal.syncName = mCurrentSyncDevice; 2820 newSyncItemLocal.syncName = mCurrentSyncDevice;
2821 newSyncItemLocal.lastSyncDate = mLastSync; 2821 newSyncItemLocal.lastSyncDate = mLastSync;
2822 syncLocal->addSyncDataEntry(&newSyncItemLocal, true); 2822 syncLocal->addSyncDataEntry(&newSyncItemLocal, true);
2823 found = syncLocal->findSyncData(mCurrentSyncDevice, &index); 2823 found = syncLocal->findSyncData(mCurrentSyncDevice, &index);
2824 if (found == false) { 2824 if (found == false) {
2825 qDebug("PwMDoc::syncronize : newly created local sync data could not be found"); 2825 qDebug("PwMDoc::syncronize : newly created local sync data could not be found");
2826 return e_syncError; 2826 return e_syncError;
2827 } 2827 }
2828 } 2828 }
2829 2829
2830 syncItemLocal = syncLocal->getSyncDataEntry(index); 2830 syncItemLocal = syncLocal->getSyncDataEntry(index);
2831 qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1()); 2831 qDebug("Last Sync %s ", syncItemLocal->lastSyncDate.toString().latin1());
2832 2832
2833 //Step 2. Find syncinfo in remote file and create if not existent. 2833 //Step 2. Find syncinfo in remote file and create if not existent.
2834 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2834 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2835 if (found == false) 2835 if (found == false)
2836 { 2836 {
2837 qDebug("FULLDATE 1"); 2837 qDebug("FULLDATE 1");
2838 fullDateRange = true; 2838 fullDateRange = true;
2839 PwMSyncItem newSyncItemRemote; 2839 PwMSyncItem newSyncItemRemote;
2840 newSyncItemRemote.syncName = mCurrentSyncName; 2840 newSyncItemRemote.syncName = mCurrentSyncName;
2841 newSyncItemRemote.lastSyncDate = mLastSync; 2841 newSyncItemRemote.lastSyncDate = mLastSync;
2842 syncRemote->addSyncDataEntry(&newSyncItemRemote, true); 2842 syncRemote->addSyncDataEntry(&newSyncItemRemote, true);
2843 found = syncRemote->findSyncData(mCurrentSyncName, &index); 2843 found = syncRemote->findSyncData(mCurrentSyncName, &index);
2844 if (found == false) { 2844 if (found == false) {
2845 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found"); 2845 qDebug("PwMDoc::syncronize : newly created remote sync data could not be found");
2846 return e_syncError; 2846 return e_syncError;
2847 } 2847 }
2848 } 2848 }
2849 2849
2850 syncItemRemote = syncRemote->getSyncDataEntry(index); 2850 syncItemRemote = syncRemote->getSyncDataEntry(index);
2851 //and remove the found entry here. We will reenter it later again. 2851 //and remove the found entry here. We will reenter it later again.
2852 syncRemote->delSyncDataEntry(index, true); 2852 syncRemote->delSyncDataEntry(index, true);
2853 2853
2854 2854
2855 if ( syncItemLocal->lastSyncDate == mLastSync ) { 2855 if ( syncItemLocal->lastSyncDate == mLastSync ) {
2856 qDebug("FULLDATE 2"); 2856 qDebug("FULLDATE 2");
2857 fullDateRange = true; 2857 fullDateRange = true;
2858 } 2858 }
2859 2859
2860 if ( ! fullDateRange ) { 2860 if ( ! fullDateRange ) {
2861 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) { 2861 if ( syncItemLocal->lastSyncDate != syncItemRemote->lastSyncDate ) {
2862 2862
2863 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2863 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2864 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2864 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2865 fullDateRange = true; 2865 fullDateRange = true;
2866 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() ); 2866 qDebug("FULLDATE 3 %s %s", syncItemLocal->lastSyncDate.toString().latin1() , syncItemRemote->lastSyncDate.toString().latin1() );
2867 } 2867 }
2868 } 2868 }
2869 // fullDateRange = true; // debug only! 2869 // fullDateRange = true; // debug only!
2870 if ( fullDateRange ) 2870 if ( fullDateRange )
2871 mLastSync = QDateTime::currentDateTime().addDays( -100*365); 2871 mLastSync = QDateTime::currentDateTime().addDays( -100*365);
2872 else 2872 else
2873 mLastSync = syncItemLocal->lastSyncDate; 2873 mLastSync = syncItemLocal->lastSyncDate;
2874 2874
2875 2875
2876 qDebug("*************************** "); 2876 qDebug("*************************** ");
2877 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2877 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2878 QStringList er = syncRemote->getIDEntryList(); 2878 QStringList er = syncRemote->getIDEntryList();
2879 PwMDataItem* inRemote ;//= er.first(); 2879 PwMDataItem* inRemote ;//= er.first();
2880 PwMDataItem* inLocal; 2880 PwMDataItem* inLocal;
2881 unsigned int catLocal, indexLocal; 2881 unsigned int catLocal, indexLocal;
2882 unsigned int catRemote, indexRemote; 2882 unsigned int catRemote, indexRemote;
2883 2883
2884 QString uid; 2884 QString uid;
2885 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2885 manager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2886 2886
2887 int modulo = (er.count()/10)+1; 2887 int modulo = (er.count()/10)+1;
2888 unsigned int incCounter = 0; 2888 unsigned int incCounter = 0;
2889 while ( incCounter < er.count()) { 2889 while ( incCounter < er.count()) {
2890 if (manager->isProgressBarCanceled()) 2890 if (manager->isProgressBarCanceled())
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());
2897
2896 qApp->processEvents(); 2898 qApp->processEvents();
2897 2899
2898 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 2900 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
2899 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 2901 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
2902 PWM_ASSERT(inRemote);
2900 if ( inLocal != 0 ) { // maybe conflict - same uid in both files 2903 if ( inLocal != 0 ) { // maybe conflict - same uid in both files
2901 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) { 2904 if ( (take = takePwMDataItem( inLocal, inRemote, mLastSync, mode, fullDateRange) ) ) {
2902 //qDebug("take %d %s ", take, inL.summary().latin1()); 2905 //qDebug("take %d %s ", take, inL.summary().latin1());
2903 if ( take == 3 ) 2906 if ( take == 3 )
2904 return e_syncError; 2907 return e_syncError;
2905 if ( take == 1 ) {// take local 2908 if ( take == 1 ) {// take local
2906 //US syncRemote->removeAddressee( inRemote ); 2909 //US syncRemote->removeAddressee( inRemote );
2907 (*inRemote) = (*inLocal); 2910 (*inRemote) = (*inLocal);
2908 //US syncRemote->insertAddressee( inRemote , false); 2911 //US syncRemote->insertAddressee( inRemote , false);
2909 ++changedRemote; 2912 ++changedRemote;
2910 } else { // take == 2 take remote 2913 } else { // take == 2 take remote
2911 //US syncLocal->removeAddressee( inLocal ); 2914 //US syncLocal->removeAddressee( inLocal );
2912 (*inLocal) = (*inRemote); 2915 (*inLocal) = (*inRemote);
2913 //US syncLocal->insertAddressee( inLocal , false ); 2916 //US syncLocal->insertAddressee( inLocal , false );
2914 ++changedLocal; 2917 ++changedLocal;
2915 } 2918 }
2916 } 2919 }
2917 } else { // no conflict 2920 } else { // no conflict
2918 if ( inRemote->meta.update > mLastSync || mode == 5 ) { 2921 if ( inRemote->meta.update > mLastSync || mode == 5 ) {
2919 inRemote->meta.update = modifiedSync; 2922 inRemote->meta.update = modifiedSync;
2920 //US syncRemote->insertAddressee( inRemote, false ); 2923 //US syncRemote->insertAddressee( inRemote, false );
2921 //US syncLocal->insertAddressee( inRemote, false ); 2924 //US syncLocal->insertAddressee( inRemote, false );
2922 syncLocal->addEntry("newcategory", inRemote, true, false); 2925 syncLocal->addEntry("newcategory", inRemote, true, false);
2923 2926
2924 ++addedPasswordsLocal; 2927 ++addedPasswordsLocal;
2925 } else { 2928 } else {
2926 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2929 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2927 syncRemote->delEntry(catRemote, indexRemote, true); 2930 syncRemote->delEntry(catRemote, indexRemote, true);
2928 //USsyncRemote->removeAddressee( inRemote ); 2931 //USsyncRemote->removeAddressee( inRemote );
2929 ++deletedPasswordsRemote; 2932 ++deletedPasswordsRemote;
2930 } 2933 }
2931 } 2934 }
2932 2935
2933 ++incCounter; 2936 ++incCounter;
2934 } 2937 }
2935 2938
2936 2939
2937 er.clear(); 2940 er.clear();
2938 QStringList el = syncLocal->getIDEntryList(); 2941 QStringList el = syncLocal->getIDEntryList();
2939 modulo = (el.count()/10)+1; 2942 modulo = (el.count()/10)+1;
2940 2943
2941 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2944 manager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2942 incCounter = 0; 2945 incCounter = 0;
2943 while ( incCounter < el.count()) { 2946 while ( incCounter < el.count()) {
2944 qApp->processEvents(); 2947 qApp->processEvents();
2945 if (manager->isProgressBarCanceled()) 2948 if (manager->isProgressBarCanceled())
2946 return e_syncError; 2949 return e_syncError;
2947 if ( incCounter % modulo == 0 ) 2950 if ( incCounter % modulo == 0 )
2948 manager->showProgressBar(incCounter); 2951 manager->showProgressBar(incCounter);
2949 uid = el[ incCounter ]; 2952 uid = el[ incCounter ];
2950 2953
2951 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal ); 2954 inLocal = syncLocal->findEntryByID( uid, &catLocal, &indexLocal );
2952 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote ); 2955 inRemote = syncRemote->findEntryByID( uid, &catRemote, &indexRemote );
2953 if ( inRemote == 0 ) { 2956 if ( inRemote == 0 ) {
2954 if ( inLocal->meta.update < mLastSync && mode != 4 ) { 2957 if ( inLocal->meta.update < mLastSync && mode != 4 ) {
2955 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2958 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2956 syncLocal->delEntry(catLocal, indexLocal, true); 2959 syncLocal->delEntry(catLocal, indexLocal, true);
2957 //USsyncLocal->removeAddressee( inLocal ); 2960 //USsyncLocal->removeAddressee( inLocal );
2958 ++deletedPasswordsLocal; 2961 ++deletedPasswordsLocal;
2959 } else { 2962 } else {
2960 if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) { 2963 if ( ! PWMPrefs::instance()->mWriteBackExistingOnly ) {
2961 ++addedPasswordsRemote; 2964 ++addedPasswordsRemote;
2962 inLocal->meta.update = modifiedSync; 2965 inLocal->meta.update = modifiedSync;
2963 //USsyncLocal->insertAddressee( inLocal, false ); 2966 //USsyncLocal->insertAddressee( inLocal, false );
2964 (*inRemote) = (*inLocal); 2967 (*inRemote) = (*inLocal);
2965 //USsyncRemote->insertAddressee( inRemote, false ); 2968 //USsyncRemote->insertAddressee( inRemote, false );
2966 syncRemote->addEntry("newcategory", inRemote, true, false); 2969 syncRemote->addEntry("newcategory", inRemote, true, false);
2967 2970
2968 } 2971 }
2969 } 2972 }
2970 2973
2971 } 2974 }
2972 ++incCounter; 2975 ++incCounter;
2973 } 2976 }
2974 el.clear(); 2977 el.clear();
2975 manager->hideProgressBar(); 2978 manager->hideProgressBar();
2976 2979
2977 // Now write the info back into the sync data space of the files 2980 // Now write the info back into the sync data space of the files
2978 2981
2979 mLastSync = QDateTime::currentDateTime().addSecs( 1 ); 2982 mLastSync = QDateTime::currentDateTime().addSecs( 1 );
2980 // get rid of micro seconds 2983 // get rid of micro seconds
2981 QTime t = mLastSync.time(); 2984 QTime t = mLastSync.time();
2982 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2985 mLastSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2983 2986
2984 2987
2985 syncItemLocal->lastSyncDate = mLastSync; 2988 syncItemLocal->lastSyncDate = mLastSync;
2986 syncItemRemote->lastSyncDate = mLastSync; 2989 syncItemRemote->lastSyncDate = mLastSync;
2987 2990
2988 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2991 // addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2989 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2992 // addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2990 2993
2991 syncRemote->addSyncDataEntry( syncItemRemote, false ); 2994 syncRemote->addSyncDataEntry( syncItemRemote, false );
2992 syncLocal->addSyncDataEntry( syncItemLocal, false ); 2995 syncLocal->addSyncDataEntry( syncItemLocal, false );
2993 QString mes; 2996 QString mes;
2994 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 ); 2997 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedPasswordsLocal, addedPasswordsRemote, changedLocal, changedRemote, deletedPasswordsLocal, deletedPasswordsRemote );
2995 if ( PWMPrefs::instance()->mShowSyncSummary ) { 2998 if ( PWMPrefs::instance()->mShowSyncSummary ) {
@@ -3001,212 +3004,241 @@ PwMerror PwMDoc::syncronize(KSyncManager* manager, PwMDoc* syncLocal , PwMDoc* s
3001 3004
3002 3005
3003int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full ) 3006int PwMDoc::takePwMDataItem( PwMDataItem* local, PwMDataItem* remote, QDateTime lastSync, int mode , bool full )
3004{ 3007{
3005 // 0 equal 3008 // 0 equal
3006 // 1 take local 3009 // 1 take local
3007 // 2 take remote 3010 // 2 take remote
3008 // 3 cancel 3011 // 3 cancel
3009 QDateTime localMod = local->meta.update; 3012 QDateTime localMod = local->meta.update;
3010 QDateTime remoteMod = remote->meta.update; 3013 QDateTime remoteMod = remote->meta.update;
3011 3014
3012 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3015 //US QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3013 3016
3014 if ( localMod == remoteMod ) 3017 if ( localMod == remoteMod )
3015 return 0; 3018 return 0;
3016 3019
3017 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() ); 3020 qDebug(" %d %d conflict on %s %s ", mode, full, local->desc.c_str(), remote->desc.c_str() );
3018 3021
3019 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); 3022 //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod);
3020 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); 3023 //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
3021 //full = true; //debug only 3024 //full = true; //debug only
3022 if ( full ) { 3025 if ( full ) {
3023 bool equ = true;//US ( (*local) == (*remote) ); 3026 bool equ = true;//US ( (*local) == (*remote) );
3024 if ( equ ) { 3027 if ( equ ) {
3025 //qDebug("equal "); 3028 //qDebug("equal ");
3026 if ( mode < SYNC_PREF_FORCE_LOCAL ) 3029 if ( mode < SYNC_PREF_FORCE_LOCAL )
3027 return 0; 3030 return 0;
3028 3031
3029 }//else //debug only 3032 }//else //debug only
3030 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 3033 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
3031 } 3034 }
3032 3035
3033 int result; 3036 int result;
3034 bool localIsNew; 3037 bool localIsNew;
3035 //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() ); 3038 //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() );
3036 3039
3037 if ( full && mode < SYNC_PREF_NEWEST ) 3040 if ( full && mode < SYNC_PREF_NEWEST )
3038 mode = SYNC_PREF_ASK; 3041 mode = SYNC_PREF_ASK;
3039 3042
3040 switch( mode ) { 3043 switch( mode ) {
3041 case SYNC_PREF_LOCAL: 3044 case SYNC_PREF_LOCAL:
3042 if ( lastSync > remoteMod ) 3045 if ( lastSync > remoteMod )
3043 return 1; 3046 return 1;
3044 if ( lastSync > localMod ) 3047 if ( lastSync > localMod )
3045 return 2; 3048 return 2;
3046 return 1; 3049 return 1;
3047 break; 3050 break;
3048 case SYNC_PREF_REMOTE: 3051 case SYNC_PREF_REMOTE:
3049 if ( lastSync > remoteMod ) 3052 if ( lastSync > remoteMod )
3050 return 1; 3053 return 1;
3051 if ( lastSync > localMod ) 3054 if ( lastSync > localMod )
3052 return 2; 3055 return 2;
3053 return 2; 3056 return 2;
3054 break; 3057 break;
3055 case SYNC_PREF_NEWEST: 3058 case SYNC_PREF_NEWEST:
3056 if ( localMod > remoteMod ) 3059 if ( localMod > remoteMod )
3057 return 1; 3060 return 1;
3058 else 3061 else
3059 return 2; 3062 return 2;
3060 break; 3063 break;
3061 case SYNC_PREF_ASK: 3064 case SYNC_PREF_ASK:
3062 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 3065 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
3063 if ( lastSync > remoteMod ) 3066 if ( lastSync > remoteMod )
3064 return 1; 3067 return 1;
3065 if ( lastSync > localMod ) 3068 if ( lastSync > localMod )
3066 return 2; 3069 return 2;
3067 localIsNew = localMod >= remoteMod; 3070 localIsNew = localMod >= remoteMod;
3068 //qDebug("conflict! ************************************** "); 3071 //qDebug("conflict! ************************************** ");
3069 { 3072 {
3070 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ ); 3073 PwMDataItemChooser acd ( *local,*remote, localIsNew , 0/*this*/ );
3071 result = acd.executeD(localIsNew); 3074 result = acd.executeD(localIsNew);
3072 return result; 3075 return result;
3073 } 3076 }
3074 break; 3077 break;
3075 case SYNC_PREF_FORCE_LOCAL: 3078 case SYNC_PREF_FORCE_LOCAL:
3076 return 1; 3079 return 1;
3077 break; 3080 break;
3078 case SYNC_PREF_FORCE_REMOTE: 3081 case SYNC_PREF_FORCE_REMOTE:
3079 return 2; 3082 return 2;
3080 break; 3083 break;
3081 3084
3082 default: 3085 default:
3083 // SYNC_PREF_TAKE_BOTH not implemented 3086 // SYNC_PREF_TAKE_BOTH not implemented
3084 break; 3087 break;
3085 } 3088 }
3086 return 0; 3089 return 0;
3087} 3090}
3088 3091
3089 3092
3090 3093
3091 3094
3092//this are the overwritten callbackmethods from the syncinterface 3095//this are the overwritten callbackmethods from the syncinterface
3093bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode) 3096bool PwMDoc::sync(KSyncManager* manager, QString filename, int mode)
3094{ 3097{
3095 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3098 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3096 3099
3097 // construct on the stack = automatic cleanup. 3100 //1) unlock local file first if necessary (ask for password)
3101 if (this->isDeepLocked()) {
3102 PwMerror ret = this->deepLock(false);
3103 if (ret != e_success)
3104 return false;
3105 }
3106
3107 //2) construct and open a new doc on the stack(automatic cleanup) for remote file.
3098 PwMDoc syncTarget(this, "synctarget"); 3108 PwMDoc syncTarget(this, "synctarget");
3109 PwMDoc* pSyncTarget = &syncTarget;
3110
3099 3111
3100 PwMerror err = syncTarget.openDoc(&filename, 2 /*== deeplocked*/); 3112 PwMerror err = pSyncTarget->openDoc(&filename, 1 /*== open with all entries locked*/);
3101 3113
3102 if (err != e_success) 3114 if (err == e_alreadyOpen) {
3115 PwMDocList::listItem li;
3116 if (getOpenDocList()->find(filename.latin1(), &li))
3117 pSyncTarget = li.doc;
3118 else {
3119 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3120 return false;
3121 }
3122 }
3123 else if (err != e_success) {
3124 qDebug("PwmDoc::sync: sync failed. Error %i while opening file %s",err, filename.latin1());
3103 return false; 3125 return false;
3104 3126 }
3127
3105 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode ); 3128 qDebug("PWM file loaded %s,sync mode %d",filename.latin1(), mode );
3106 3129
3130
3131 //3) unlock remote file first if necessary (ask for password)
3132 if (pSyncTarget->isDeepLocked()) {
3133 PwMerror ret = pSyncTarget->deepLock(false);
3134 if (ret != e_success)
3135 return false;
3136 }
3137
3107 3138
3108 err = syncronize(manager, this, &syncTarget, mode ); 3139 err = syncronize(manager, this, pSyncTarget, mode );
3109 3140
3110 if (err == e_success) { 3141 if (err == e_success) {
3111 if ( PWMPrefs::instance()->mWriteBackFile ){ 3142 if ( PWMPrefs::instance()->mWriteBackFile ){
3112 qDebug("Saving remote PWManager file"); 3143 qDebug("Saving remote PWManager file");
3113 err = syncTarget.saveDoc(conf()->confGlobCompression()); 3144 err = pSyncTarget->saveDoc(conf()->confGlobCompression());
3114 if (err != e_success) 3145 if (err != e_success) {
3146 qDebug("PwmDoc::sync: Sync failed. Error %i while storing file %s",err, filename.latin1());
3115 return false; 3147 return false;
3116 3148 }
3117 } 3149 }
3118 3150
3119 flagDirty(); 3151 flagDirty();
3120 return true; 3152 return true;
3121 } 3153 }
3122 else { 3154 else {
3123 return false; 3155 return false;
3124 } 3156 }
3125} 3157}
3126 3158
3127//called by the syncmanager to indicate that the work has to marked as dirty. 3159//called by the syncmanager to indicate that the work has to marked as dirty.
3128void PwMDoc::sync_setModified() 3160void PwMDoc::sync_setModified()
3129{ 3161{
3130 flagDirty(); 3162 flagDirty();
3131} 3163}
3132 3164
3133//called by the syncmanager to ask if the dirty flag is set. 3165//called by the syncmanager to ask if the dirty flag is set.
3134bool PwMDoc::sync_isModified() 3166bool PwMDoc::sync_isModified()
3135{ 3167{
3136 return isDirty(); 3168 return isDirty();
3137} 3169}
3138 3170
3139//called by the syncmanager to indicate that the work has to be saved. 3171//called by the syncmanager to indicate that the work has to be saved.
3140void PwMDoc::sync_save() 3172void PwMDoc::sync_save()
3141{ 3173{
3142 saveDoc(conf()->confGlobCompression()); 3174 saveDoc(conf()->confGlobCompression());
3143} 3175}
3144#endif 3176#endif
3145 3177
3146 3178
3147bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index) 3179bool PwMDoc::findSyncData(const QString &syncname, unsigned int *index)
3148{ 3180{
3149 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(), 3181 vector<PwMSyncItem>::iterator i = dti.syncDta.begin(),
3150 end = dti.syncDta.end(); 3182 end = dti.syncDta.end();
3151 3183
3152 while (i != end) { 3184 while (i != end) {
3153 if ((*i).syncName == syncname.latin1()) { 3185 if ((*i).syncName == syncname.latin1()) {
3154 if (index) { 3186 if (index) {
3155 *index = i - dti.syncDta.begin(); 3187 *index = i - dti.syncDta.begin();
3156 } 3188 }
3157 return true; 3189 return true;
3158 } 3190 }
3159 ++i; 3191 ++i;
3160 } 3192 }
3161 return false; 3193 return false;
3162}; 3194};
3163 3195
3164/** add new syncdataentry */ 3196/** add new syncdataentry */
3165PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty) 3197PwMerror PwMDoc::addSyncDataEntry(PwMSyncItem *d, bool dontFlagDirty)
3166{ 3198{
3167 PWM_ASSERT(d); 3199 PWM_ASSERT(d);
3168 3200
3169 if (isDeepLocked()) { 3201 if (isDeepLocked()) {
3170 PwMerror ret; 3202 PwMerror ret;
3171 ret = deepLock(false); 3203 ret = deepLock(false);
3172 if (ret != e_success) 3204 if (ret != e_success)
3173 return e_lock; 3205 return e_lock;
3174 } 3206 }
3175 unsigned int index; 3207 unsigned int index;
3176 3208
3177 const QString tmp = d->syncName.c_str(); 3209 const QString tmp = d->syncName.c_str();
3178 bool exists = findSyncData(d->syncName.c_str(), &index); 3210 bool exists = findSyncData(d->syncName.c_str(), &index);
3179 3211
3180 if (exists == true) { 3212 if (exists == true) {
3181 // DOH! We found this entry. 3213 // DOH! We found this entry.
3182 return e_entryExists; 3214 return e_entryExists;
3183 } 3215 }
3184 3216
3185 dti.syncDta.push_back(*d); 3217 dti.syncDta.push_back(*d);
3186 3218
3187 if (!dontFlagDirty) 3219 if (!dontFlagDirty)
3188 flagDirty(); 3220 flagDirty();
3189 return e_success; 3221 return e_success;
3190} 3222}
3191 3223
3192 3224
3193 3225
3194/** delete syncdata entry */ 3226/** delete syncdata entry */
3195bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty) 3227bool PwMDoc::delSyncDataEntry(unsigned int index, bool dontFlagDirty)
3196{ 3228{
3197 if (isDeepLocked()) 3229 if (isDeepLocked())
3198 return false; 3230 return false;
3199 if (index > dti.syncDta.size() - 1) 3231 if (index > dti.syncDta.size() - 1)
3200 return false; 3232 return false;
3201 3233
3202 // delete entry 3234 // delete entry
3203 dti.syncDta.erase(dti.syncDta.begin() + index); 3235 dti.syncDta.erase(dti.syncDta.begin() + index);
3204 3236
3205 if (!dontFlagDirty) 3237 if (!dontFlagDirty)
3206 flagDirty(); 3238 flagDirty();
3207 return true; 3239 return true;
3208} 3240}
3209 3241
3210 3242
3211PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index) 3243PwMDataItem* PwMDoc::findEntryByID(const QString &uid, unsigned int *category, unsigned int *index)
3212{ 3244{