qtopia/md5metatemplate.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00074
00075
00076
00077
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
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
00107 #if 0
00108 entryNew = new Entry();
00109 entryNew->setId( it.key() );
00110
00111
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
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
This file is part of the documentation for kitchensync Library Version 3.3.2.