synctemplate.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KSYNC_GENERICSYNCEE_H
00022 #define KSYNC_GENERICSYNCEE_H
00023
00024 #include <qstring.h>
00025 #include <qstringlist.h>
00026
00027 #include <kdebug.h>
00028
00029 #include "syncee.h"
00030
00034 namespace KSync {
00035 template <class Entry= SyncEntry>
00036 class SyncTemplate : public Syncee {
00037 public:
00038 typedef QPtrList<Entry> PtrList;
00039 SyncTemplate(uint i = 0) : Syncee(i) {
00040 mList.setAutoDelete( true );
00041 };
00042 ~SyncTemplate() { };
00043
00044
00048 QString type() const { return QString::fromLatin1("SyncTemplate"); }
00049 Syncee* clone() {
00050 SyncTemplate* temp = new SyncTemplate<Entry>();
00051 temp->setSyncMode( syncMode() );
00052 temp->setFirstSync( firstSync() );
00053 Entry* entry;
00054 for ( entry = mList.first(); entry != 0; entry = mList.next() ) {
00055 temp->addEntry( (Entry*)entry->clone() );
00056 }
00057 return temp;
00058 };
00059
00060 SyncEntry* firstEntry() {
00061 return mList.first();
00062 }
00063 SyncEntry* nextEntry() {
00064 return mList.next();
00065 }
00066 SyncEntry::PtrList added() {
00067 return find( SyncEntry::Added );
00068 }
00069 SyncEntry::PtrList modified() {
00070 return find( SyncEntry::Modified );
00071 }
00072 SyncEntry::PtrList removed() {
00073 return find(SyncEntry::Removed );
00074 }
00075 void addEntry( SyncEntry* entry ) {
00076 kdDebug(5230) << "addEntry " << entry->type() << endl;
00077 Entry* tempEntry = dynamic_cast<Entry*> ( entry );
00078 if ( tempEntry == 0l ) {
00079 kdDebug(5230) << "could not cast" << endl;
00080 return;
00081 };
00082 tempEntry->setSyncee( this );
00083 if ( tempEntry->state() == SyncEntry::Undefined ) {
00084 if ( hasChanged( tempEntry ) )
00085 tempEntry->setState( SyncEntry::Modified );
00086 }
00087 mList.append( tempEntry );
00088 }
00089 void removeEntry( SyncEntry* entry ) {
00090 Entry* tempEntry = dynamic_cast<Entry*> ( entry );
00091 if ( tempEntry == 0l )
00092 return;
00093 mList.remove( tempEntry );
00094 }
00095
00096 bool writeBackup( const QString & ) { return false; }
00097 bool restoreBackup( const QString & ) { return false; }
00098
00099 protected:
00100 SyncEntry::PtrList find( int state ) {
00101 kdDebug(5230) << "find state " << state << endl;
00102 SyncEntry::PtrList found;
00103 Entry* entry;
00104 for (entry = mList.first(); entry != 0; entry = mList.next() ) {
00105 if ( entry->state() == state ) {
00106 kdDebug(5230) << "matched state in find " << entry->state() << endl;
00107 found.append( entry );
00108 }
00109 }
00110 return found;
00111 }
00112 PtrList mList;
00113
00114 };
00115 }
00116
00117
00118 #endif
This file is part of the documentation for kitchensync Library Version 3.3.2.