kitchensync Library API Documentation

syncer.cpp

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 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 *s = mSyncees.first(); 00066 while( s ) { 00067 if ( !s->loadLog() ) { 00068 kdError() << "Syncer::sync(): Unable to load sync log for Syncee '" 00069 << s->identifier() << "'" << endl; 00070 } 00071 s = mSyncees.next(); 00072 } 00073 00074 Syncee *target = mSyncees.last(); 00075 00076 if ( !target ) { 00077 kdWarning() << "Syncer::sync(): No Syncees set." << endl; 00078 return; 00079 } 00080 00081 Syncee *syncee = mSyncees.first(); 00082 while ( syncee != target ) { 00083 syncToTarget( syncee, target ); 00084 syncee = mSyncees.next(); 00085 } 00086 if ( !target->saveLog() ) { 00087 kdDebug() << "Syncer::sync() failed to save target log." << endl; 00088 } 00089 syncee = mSyncees.first(); 00090 while ( syncee != target ) { 00091 syncToTarget( target, syncee, true ); 00092 if ( !syncee->saveLog() ) { 00093 kdDebug() << "Syncer::sync() failed to save syncee log." << endl; 00094 } 00095 syncee = mSyncees.next(); 00096 } 00097 } 00098 00099 void Syncer::syncAllToTarget( Syncee *target, bool writeback ) 00100 { 00101 Syncee *syncee = mSyncees.first(); 00102 while ( syncee ) { 00103 syncToTarget(syncee,target); 00104 syncee = mSyncees.next(); 00105 } 00106 00107 if ( !target->saveLog() ) { 00108 kdDebug() << "Syncer::syncAllToTarget() failed to save target log." << endl; 00109 } 00110 00111 if ( writeback ) { 00112 for ( Syncee *syncee = mSyncees.first(); syncee; 00113 syncee = mSyncees.next() ) { 00114 syncToTarget( target, syncee, true ); 00115 } 00116 } 00117 } 00118 00119 void Syncer::syncToTarget( Syncee *source, Syncee *target, bool override ) 00120 { 00121 mAlgorithm->syncToTarget( source, target, override ); 00122 } 00123 00124 void Syncer::setSyncAlgorithm( SyncAlgorithm *algorithm ) 00125 { 00126 if ( mOwnAlgorithm ) delete mAlgorithm; 00127 mOwnAlgorithm = false; 00128 mAlgorithm = algorithm; 00129 } 00130 00131 void Syncer::setSyncUi( SyncUi *ui ) 00132 { 00133 if ( mOwnUi ) delete mUi; 00134 mOwnUi = false; 00135 mUi = ui; 00136 mAlgorithm->setUi( ui ); 00137 }
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003