kitchensync
standardsync.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "standardsync.h"
00025
00026 #include "syncer.h"
00027 #include "syncee.h"
00028
00029 #include <kdebug.h>
00030
00031 using namespace KSync;
00032
00033
00034
00035
00036
00037
00038 void StandardSync::syncToTarget( Syncee* syncee,
00039 Syncee* target,
00040 bool override)
00041 {
00042 return syncMeta( syncee, target, override );
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 void StandardSync::syncMeta( Syncee* syncee,
00059 Syncee* target,
00060 bool over )
00061 {
00062 kdDebug(5250) << "SYNC: SyncMeta " << endl;
00063 QPtrList<SyncEntry> entries = syncee->added();
00064 SyncEntry* entry;
00065 SyncEntry* targetEntry;
00066
00067
00068 for ( entry = entries.first(); entry; entry = entries.next() ) {
00069 targetEntry = target->findEntry( entry->id() );
00070 kdDebug(5250) << "SYNC: About to add " << entry->name() << endl;
00071 if(!targetEntry ){
00072 kdDebug(5250) << "SYNC: Not added before " << endl;
00073 addEntry( syncee, target, entry );
00074 }else {
00075 kdDebug(5250) << "SYNC: Added before " << endl;
00076 }
00077 }
00078
00079 syncSyncEntryListToSyncee( syncee->modified(), syncee, target, over );
00080 syncSyncEntryListToSyncee( syncee->removed(), syncee, target,over );
00081
00082 }
00083
00084
00085
00086
00087 void StandardSync::addEntry( Syncee* in, Syncee* out, SyncEntry* add )
00088 {
00089 if ( add->id().startsWith("Konnector-") ) {
00090 QString oldId = add->id();
00091 add->setId( in->generateNewId() );
00092 in->insertId( add->type(), oldId, add->id() );
00093 out->insertId( add->type(), oldId, add->id() );
00094 }
00095 out->addEntry( add->clone() );
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 void StandardSync::syncSyncEntryListToSyncee(QPtrList<SyncEntry> entries, Syncee* syncee,
00108 Syncee* target,
00109 bool over )
00110 {
00111 kdDebug(5250) << "For All" << endl;
00112 SyncEntry* entry;
00113 SyncEntry* other;
00114 SyncEntry* result;
00115
00116 for ( entry = entries.first(); entry; entry = entries.next() ) {
00117 result = 0;
00118 other = target->findEntry( entry->id() );
00119 if (other ) {
00120 kdDebug(5250) << "Entry 1 " << entry->name() << endl;
00121 kdDebug(5250) << "Entry 2 " << other->name() << endl;
00122
00123
00124 if(entry->wasModified() && other->state()== SyncEntry::Undefined ) {
00125 kdDebug(5250) << "Modified and unchanged " << endl;
00126 entry->mergeWith( other );
00127 target->replaceEntry( other, entry->clone() );
00128 }
00129
00130 else if ( entry->wasRemoved() &&
00131 other->wasRemoved() ) {
00132 kdDebug(5250) << "Removed and removed too " << endl;
00133
00134 informBothDeleted( entry, other );
00135 target->replaceEntry( other, entry->clone() );
00136
00137 } else if ( entry->wasRemoved() &&
00138 other->state() == SyncEntry::Undefined ) {
00139
00140 if (confirmDelete(entry, other) )
00141 target->replaceEntry( other, entry->clone() );
00142
00143
00144
00145
00146
00147 else {
00148 entry = other->clone();
00149 entry->setState( SyncEntry::Undefined );
00150 }
00151 }
00152
00153 else if ( entry->wasRemoved() &&
00154 other->wasModified() ) {
00155 kdDebug(5250) << "Entry wasRemoved and other wasModified override is "
00156 << over << endl;
00157 result = 0;
00158 if (!over)
00159 result = deconflict(entry,other);
00160
00161
00162
00163
00164
00165 if (!over && !result ) {
00166 kdDebug(5250) << "SYNC: no decision" << endl;
00167 entry->setDontSync( true );
00168 other->setDontSync( true );
00169 }else if (result == entry || over) {
00170
00171 target->replaceEntry(other,entry->clone() );
00172 }
00173
00174 } else if ( entry->wasModified() && other->wasModified() ) {
00175 kdDebug(5250) << "Both where modified and override is" << over<< endl;
00176 kdDebug(5250) << "Entry1 timestamp " << entry->timestamp() << endl;
00177 kdDebug(5250) << "Entry2 timestamp " << other->timestamp() << endl;
00178 kdDebug(5250) << "Equals " << entry->equals( other ) << endl;
00179
00180 result = 0l;
00181 if (!over )
00182 result = deconflict(entry,other);
00183
00184 if (!over && !result ) {
00185 kdDebug(5250) << "SYNC: no decision" << endl;
00186 entry->setDontSync( true );
00187 other->setDontSync( true );
00188 }else if (result == entry || over) {
00189 entry->mergeWith( other );
00190 target->replaceEntry(other,entry->clone() );
00191 }
00192 }
00193 } else {
00194 kdDebug(5250) << "added " << endl;
00195 addEntry(syncee, target, entry);
00196 }
00197
00198 }
00199 }
00200
|