kitchensync Library API Documentation

synctemplate.h

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002 Holger Freyther <zecke@handhelds.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 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 /*        QString type() const { return QString::fromLatin1(typeName); }*/
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
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 Wed Oct 17 09:54:21 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003