kitchensync Library API Documentation

md5metatemplate.h

00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002,2003 Holger Freyther <freyther@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 #ifndef OPIE_HELPER_META_TEMPLATE_NEW_H 00022 #define OPIE_HELPER_META_TEMPLATE_NEW_H 00023 00024 #include <kmdcodec.h> 00025 00026 #include <syncer.h> 00027 #include <idhelper.h> 00028 00029 00030 #include "md5map.h" 00031 00032 namespace OpieHelper { 00033 00034 template <class Syncee = KSync::Syncee, class Entry = KSync::SyncEntry> 00035 class MD5Template { 00036 public: 00037 MD5Template(); 00038 virtual ~MD5Template(); 00039 00040 void doMeta( Syncee* newEntries, const MD5Map& ); 00041 void saveMeta( Syncee*, MD5Map& ); 00042 00043 protected: 00044 virtual QString string( Entry* ) = 0; 00045 00046 private: 00047 QString md5sum( const QString& ); 00048 }; 00049 00050 template<class Syncee, class Entry> 00051 MD5Template<Syncee, Entry>::MD5Template() { 00052 } 00053 template<class Syncee, class Entry> 00054 MD5Template<Syncee, Entry>::~MD5Template() { 00055 } 00056 template<class Syncee, class Entry> 00057 void MD5Template<Syncee, Entry>::doMeta( Syncee* newEntries, const MD5Map& map) { 00058 bool found; 00059 Entry* entryNew; 00067 for ( entryNew = (Entry*)newEntries->firstEntry(); 00068 entryNew != 0; 00069 entryNew = (Entry*)newEntries->nextEntry() ) { 00070 found = false; 00071 00072 /* 00073 * check if the MD5Map contains 00074 * the UID 00075 * if the md5 sums are not equal 00076 * set the modified state 00077 * ADDED set Added state 00078 */ 00079 if ( map.contains( entryNew->id() ) ) { 00080 found = true; 00081 QString str = map.md5sum( entryNew->id() ); 00082 QString newStr = string( entryNew ); 00083 00084 if ( str != md5sum( newStr ) ) { 00085 entryNew->setState( KSync::SyncEntry::Modified ); 00086 } 00087 } 00088 if (!found ) { 00089 entryNew->setState( KSync::SyncEntry::Added ); 00090 } 00091 } 00092 /* 00093 * Now find the deleted records 00094 */ 00095 MD5Map::Iterator it; 00096 MD5Map::Map ma = map.map(); 00097 for ( it = ma.begin(); it != ma.end(); ++it ) { 00098 entryNew = (Entry*)newEntries->findEntry( it.key() ); 00105 if (!entryNew) { 00106 // FIXME: Provide a way to create SyncEntries for deleted entries. 00107 #if 0 00108 entryNew = new Entry(); 00109 entryNew->setId( it.key() ); 00110 00111 /* add entry first and then to setState */ 00112 newEntries->addEntry( entryNew ); 00113 entryNew->setState( KSync::SyncEntry::Removed ); 00114 #endif 00115 } 00116 } 00117 00118 } 00119 template<class Syncee, class Entry> 00120 void MD5Template<Syncee, Entry>::saveMeta( Syncee* syncee, MD5Map& map) { 00121 map.clear(); 00122 for ( Entry* entry = (Entry*)syncee->firstEntry(); 00123 entry != 0; entry = (Entry*)syncee->nextEntry() ) { 00124 00125 /* only save meta for not deleted SyncEntries! */ 00126 if ( entry->state() != KSync::SyncEntry::Removed ) { 00127 map.insert( entry->id(), md5sum( string( entry ) ) ); 00128 } 00129 } 00130 } 00131 template<class Syncee, class Entry> 00132 QString MD5Template<Syncee, Entry>::md5sum( const QString& base ) { 00133 KMD5 sum(base.local8Bit() ); 00134 QString str = QString::fromLatin1( sum.hexDigest().data() ); 00135 00136 return str; 00137 } 00138 } 00139 00140 00141 #endif
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