kitchensync Library API Documentation

todosyncee.cpp

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 
00022 #include <kstaticdeleter.h>
00023 
00024 #include <libkcal/calformat.h>
00025 
00026 #include "incidencetemplate.h"
00027 #include "todosyncee.h"
00028 
00029 
00030 using namespace KSync;
00031 using namespace KCal;
00032 
00033 /* A test for the template
00034 void testIt() {
00035     TodoSyncee* syncee = new TodoSyncee();
00036     syncee->setSyncMode( Syncee::FirstSync );
00037     delete syncee;
00038 }
00039 */
00040 
00041 TodoSyncEntry::TodoSyncEntry( KCal::Todo *todo, Syncee *parent )
00042     : SyncEntry( parent ), mTodo( todo )
00043 {
00044     if (!mTodo )
00045         mTodo = new KCal::Todo;
00046 }
00047 
00048 TodoSyncEntry::TodoSyncEntry( const TodoSyncEntry& entry)
00049     : SyncEntry( entry )
00050 {
00051     mTodo = (KCal::Todo*)entry.mTodo->clone();
00052 }
00053 
00054 TodoSyncEntry::~TodoSyncEntry()
00055 {
00056     delete mTodo;
00057 }
00058 
00059 KCal::Todo* TodoSyncEntry::todo()
00060 {
00061     return mTodo;
00062 }
00063 
00064 QString TodoSyncEntry::type() const
00065 {
00066     return QString::fromLatin1("TodoSyncEntry");
00067 }
00068 
00069 QString TodoSyncEntry::name()
00070 {
00071     return mTodo->summary();
00072 }
00073 
00074 QString TodoSyncEntry::id()
00075 {
00076     return mTodo->uid();
00077 }
00078 
00079 void TodoSyncEntry::setId(const QString& id )
00080 {
00081     mTodo->setUid( id );
00082 }
00083 
00084 QString TodoSyncEntry::timestamp()
00085 {
00086     return mTodo->lastModified().toString();
00087 }
00088 
00089 SyncEntry* TodoSyncEntry::clone()
00090 {
00091     return new TodoSyncEntry( *this );
00092 }
00093 
00094 bool TodoSyncEntry::equals(SyncEntry* entry )
00095 {
00096     TodoSyncEntry* todoEntry = dynamic_cast<TodoSyncEntry*> (entry );
00097     if (!todoEntry )
00098         return false;
00099 
00100     if (mTodo->uid() != todoEntry->todo()->uid() ) return false;
00101     if (mTodo->lastModified() != todoEntry->todo()->lastModified() ) return false;
00102     return true;
00103 }
00104 
00105 typedef MergeBase<Todo, TodoSyncee> MergeTodo;
00106 static MergeTodo* mergeTodoMap = 0l;
00107 static KStaticDeleter<MergeTodo> MergeTodoDeleter;
00108 
00109 static void mergeDue( Todo* const dest, const Todo* const src)
00110 {
00111      dest->setDtDue( src->dtDue() );
00112 }
00113 
00114 static void mergeStart( Todo* const dest, const Todo* const src)
00115 {
00116      dest->setHasStartDate( src->hasStartDate() );
00117 }
00118 
00119 static void mergeComp( Todo* const dest, const Todo* const src)
00120 {
00121      dest->setCompleted( src->isCompleted() );
00122 }
00123 
00124 static void mergePer( Todo* const dest, const Todo* const src)
00125 {
00126      dest->setPercentComplete( src->percentComplete() );
00127 }
00128 
00129 static MergeTodo* mapTo() {
00130         if (!mergeTodoMap ) {
00131             MergeTodoDeleter.setObject( mergeTodoMap, new MergeTodo );
00132 
00133             mergeTodoMap->add( TodoSyncee::DtDue, mergeDue );
00134             mergeTodoMap->add( TodoSyncee::StartDate, mergeStart );
00135             mergeTodoMap->add( TodoSyncee::Completed, mergeComp );
00136             mergeTodoMap->add( TodoSyncee::Percent, mergePer );
00137         }
00138         return mergeTodoMap;
00139 }
00140 
00141 bool TodoSyncEntry::mergeWith( SyncEntry* entry )
00142 {
00143     if ( entry->name() != name() || !syncee() || !entry->syncee() )
00144         return false;
00145 
00146     TodoSyncEntry* toEn = static_cast<TodoSyncEntry*>(entry);
00147     QBitArray da = toEn->syncee()->bitArray();
00148     QBitArray hier = syncee()->bitArray();
00149     for ( uint i = 0; i < da.size() && i < hier.size() ; i++ ) {
00150         if (da[i] && !hier[i] ) {
00151             mapTo()->invoke(i, mTodo, toEn->mTodo );
00152         }
00153     }
00154 
00155     return true;
00156 }
00157 
00159 TodoSyncee::TodoSyncee()
00160     : SyncTemplate<TodoSyncEntry>(TodoSyncee::Percent+1)
00161 {
00162 }
00163 
00164 QString TodoSyncee::type() const
00165 {
00166     return QString::fromLatin1("TodoSyncee");
00167 }
00168 
00169 Syncee* TodoSyncee::clone()
00170 {
00171     TodoSyncee* temp = new TodoSyncee();
00172     temp->setSyncMode( syncMode() );
00173     temp->setFirstSync( firstSync() );
00174     temp->setSupports( bitArray() );
00175     temp->setSource( source() );
00176     TodoSyncEntry* entry;
00177     for ( entry = mList.first(); entry != 0; entry = mList.next() ) {
00178         temp->addEntry( entry->clone() );
00179     }
00180     return temp;
00181 }
00182 
00183 QString TodoSyncee::newId() const
00184 {
00185     return KCal::CalFormat::createUniqueId();
00186 }
00187 
00188 
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