kitchensync
syncer.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <kdebug.h>
00024
00025 #include "standardsync.h"
00026 #include "syncui.h"
00027 #include "syncee.h"
00028
00029 #include "syncer.h"
00030
00031 using namespace KSync;
00032
00033 Syncer::Syncer( SyncUi *ui, SyncAlgorithm *algorithm )
00034 : mOwnUi( false ), mOwnAlgorithm( false )
00035 {
00036 if ( !ui ) {
00037 mUi = new SyncUi();
00038 mOwnUi = true;
00039 } else mUi = ui;
00040
00041 if ( !algorithm ) {
00042 mAlgorithm = new StandardSync( mUi );
00043 mOwnAlgorithm = true;
00044 } else mAlgorithm = algorithm;
00045 }
00046
00047 Syncer::~Syncer()
00048 {
00049 if ( mOwnUi ) delete mUi;
00050 if ( mOwnAlgorithm ) delete mAlgorithm;
00051 }
00052
00053 void Syncer::addSyncee( Syncee *syncee )
00054 {
00055 mSyncees.append( syncee );
00056 }
00057
00058 void Syncer::clear()
00059 {
00060 mSyncees.clear();
00061 }
00062
00063 void Syncer::sync()
00064 {
00065 Syncee *target = mSyncees.last();
00066
00067 if ( !target ) {
00068 kdWarning() << "Syncer::sync(): No Syncees set." << endl;
00069 return;
00070 }
00071
00072 Syncee *syncee = mSyncees.first();
00073 while ( syncee != target ) {
00074 syncToTarget( syncee, target );
00075 syncee = mSyncees.next();
00076 }
00077
00078 syncee = mSyncees.first();
00079 while ( syncee != target ) {
00080 syncToTarget( target, syncee, true );
00081
00082 syncee = mSyncees.next();
00083 }
00084 }
00085
00086 void Syncer::syncAllToTarget( Syncee *target, bool writeback )
00087 {
00088 Syncee *syncee = mSyncees.first();
00089 while ( syncee ) {
00090 syncToTarget(syncee,target);
00091 syncee = mSyncees.next();
00092 }
00093
00094
00095 if ( writeback ) {
00096 for ( Syncee *syncee = mSyncees.first(); syncee;
00097 syncee = mSyncees.next() ) {
00098 syncToTarget( target, syncee, true );
00099 }
00100 }
00101 }
00102
00103 void Syncer::syncToTarget( Syncee *source, Syncee *target, bool override )
00104 {
00105 mAlgorithm->syncToTarget( source, target, override );
00106 }
00107
00108 void Syncer::setSyncAlgorithm( SyncAlgorithm *algorithm )
00109 {
00110 if ( mOwnAlgorithm ) delete mAlgorithm;
00111 mOwnAlgorithm = false;
00112 mAlgorithm = algorithm;
00113 }
00114
00115 void Syncer::setSyncUi( SyncUi *ui )
00116 {
00117 if ( mOwnUi ) delete mUi;
00118 mOwnUi = false;
00119 mUi = ui;
00120 mAlgorithm->setUi( ui );
00121 }
|