kitchensync Library API Documentation

standardsync.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include "standardsync.h"
00023 
00024 #include "syncer.h"
00025 #include "syncee.h"
00026 
00027 #include <kdebug.h>
00028 
00029 using namespace KSync;
00030 
00031 void StandardSync::syncToTarget( Syncee *source, Syncee *target, bool override )
00032 {
00033   kdDebug(5250) << "StandardSync::syncToTarget(): from: "
00034                 << source->identifier()
00035                 << " to: " << target->identifier() << "  override: "
00036                 << override  << endl;
00037 
00038   SyncEntry *sourceEntry;
00039   for( sourceEntry = source->firstEntry(); sourceEntry;
00040        sourceEntry = source->nextEntry() ) {
00041     kdDebug(5250) << "SYNC: sourceEntry: " << sourceEntry->id()
00042                   << " (" << sourceEntry->name() << ")"
00043                   << " " << long( sourceEntry ) << endl;
00044     if ( sourceEntry->dontSync() ) {
00045       kdDebug(5250) << "SYNC:   source don't sync" << endl;
00046       continue;
00047     }
00048     SyncEntry *targetEntry = target->findEntry( sourceEntry->id() );
00049     if ( targetEntry ) {
00050       kdDebug(5250) << "SYNC:   targetEntry: " << targetEntry->id()
00051                     << " (" << targetEntry->name() << ")"
00052                     << " " << long( targetEntry ) << endl;
00053       if ( targetEntry->dontSync() ) {
00054         kdDebug(5250) << "SYNC:   target don't sync" << endl;
00055         continue;
00056       }
00057       kdDebug(5250) << "SYNC:   entry exists" << endl;
00058       // Entry already exists in target
00059       if ( sourceEntry->equals( targetEntry ) ) {
00060         // Entries are equal, no action required
00061         kdDebug(5250) << "SYNC:   equal" << endl;
00062       } else {
00063         kdDebug(5250) << "SYNC:   entries are different" << endl;
00064         // Entries are different, resolve conflict
00065         if ( override ) {
00066           // Force override
00067           target->replaceEntry( targetEntry, sourceEntry );
00068           kdDebug(5250) << "SYNC:   force replace" << endl;
00069         } else {
00070           if ( source->hasChanged( sourceEntry ) &&
00071                target->hasChanged( targetEntry ) ) {
00072             // Both entries have changed
00073             kdDebug(5250) << "SYNC:   Both have changed" << endl;
00074             SyncEntry *result = deconflict( sourceEntry, targetEntry );
00075             if ( !result ) {
00076               kdDebug(5250) << "SYNC:   no decision" << endl;
00077               sourceEntry->setDontSync( true );
00078               targetEntry->setDontSync( true );
00079             } else {
00080               if ( result == sourceEntry ) {
00081                 kdDebug(5250) << "SYNC:   take source" << endl;
00082                 target->replaceEntry( targetEntry, sourceEntry );
00083               } else {
00084                 kdDebug(5250) << "SYNC:   take target" << endl;
00085               }
00086             }
00087           } else if ( source->hasChanged( sourceEntry ) &&
00088                       !target->hasChanged( targetEntry ) ) {
00089             // take source entry
00090             target->replaceEntry( targetEntry, sourceEntry );
00091             kdDebug(5250) << "SYNC:   source changed, target not" << endl;
00092             kdDebug(5250) << "SYNC:   Take source entry." << endl;
00093           } else if ( !source->hasChanged( sourceEntry ) &&
00094                       target->hasChanged( targetEntry ) ) {
00095             // take target entry, no action required
00096             kdDebug(5250) << "SYNC:   target changed, source not" << endl;
00097             kdDebug(5250) << "SYNC:   Take target entry." << endl;
00098           } else {
00099             kdDebug(5250) << "SYNC:   nothing has changed." << endl;
00100           }
00101         }
00102       }
00103     } else {
00104       // New entry
00105       target->addEntry( sourceEntry );
00106       kdDebug(5250) << "SYNC:   New entry." << endl;
00107     }
00108   }
00109 }
KDE Logo
This file is part of the documentation for kitchensync Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:41:09 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003