ksync

calendarsyncee.cpp

00001 /*
00002     This file is part of ksync.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <kdebug.h>
00023 
00024 #include "calendarsyncee.h"
00025 
00026 CalendarSyncEntry::CalendarSyncEntry(Incidence *incidence) :
00027   mIncidence(incidence)
00028 {
00029 }
00030 
00031 QString CalendarSyncEntry::name()
00032 {
00033   return mIncidence->summary();
00034 }
00035 
00036 QString CalendarSyncEntry::id()
00037 {
00038   return mIncidence->uid();
00039 }
00040 
00041 QString CalendarSyncEntry::timestamp()
00042 {
00043   return mIncidence->lastModified().toString();
00044 }
00045 
00046 bool CalendarSyncEntry::equals(KSyncEntry *entry)
00047 {
00048   CalendarSyncEntry *calEntry = dynamic_cast<CalendarSyncEntry *>(entry);
00049   if (!calEntry) {
00050     kdDebug() << "CalendarSyncee::addEntry(): Wrong type." << endl;
00051     return false;
00052   }
00053 
00054   if (mIncidence->uid() != calEntry->incidence()->uid()) return false;
00055   if (mIncidence->lastModified() != calEntry->incidence()->lastModified())
00056     return false;
00057 
00058   return true;
00059 }
00060 
00061 CalendarSyncee::CalendarSyncee()
00062 {
00063   mCalendar = new CalendarLocal( QString::fromLatin1( "UTC" ) );
00064 
00065   mEntries.setAutoDelete(true);
00066 }
00067 
00068 CalendarSyncee::~CalendarSyncee()
00069 {
00070   delete mCalendar;
00071 }
00072 
00073 bool CalendarSyncee::read()
00074 {
00075   mCalendar->close();
00076   return mCalendar->load(filename());
00077 }
00078 
00079 bool CalendarSyncee::write()
00080 {
00081   return mCalendar->save(filename());
00082 }
00083 
00084 
00085 CalendarSyncEntry *CalendarSyncee::firstEntry()
00086 {
00087   mEvents = mCalendar->events();
00088   mCurrentEvent = mEvents.begin();
00089   return createEntry( *mCurrentEvent );
00090 }
00091 
00092 CalendarSyncEntry *CalendarSyncee::nextEntry()
00093 {
00094   ++mCurrentEvent;
00095   return createEntry( *mCurrentEvent );
00096 }
00097 
00098 #if 0
00099 CalendarSyncEntry *CalendarSyncee::findEntry(const QString &id)
00100 {
00101   Event *event = mCalendar->getEvent(id);
00102   return createEntry(event);
00103 }
00104 #endif
00105 
00106 void CalendarSyncee::addEntry(KSyncEntry *entry)
00107 {
00108   CalendarSyncEntry *calEntry = dynamic_cast<CalendarSyncEntry *>(entry);
00109   if (!calEntry) {
00110     kdDebug() << "CalendarSyncee::addEntry(): SyncEntry has wrong type."
00111               << endl;
00112   } else {
00113     Event *sourceEvent = dynamic_cast<Event *>(calEntry->incidence());
00114     if (!sourceEvent) {
00115       kdDebug() << "CalendarSyncee::addEntry(): Incidence is not of type Event."
00116                 << endl;
00117     } else {
00118       kdDebug() << "Cloning..." << endl;
00119       Event *event = dynamic_cast<Event *>(sourceEvent->clone());
00120       kdDebug() << "Cloning...." << endl;
00121       mCalendar->addEvent(event);
00122       kdDebug() << "Cloning....." << endl;
00123     }
00124   }
00125 }
00126 
00127 void CalendarSyncee::removeEntry(KSyncEntry *entry)
00128 {
00129   CalendarSyncEntry *calEntry = dynamic_cast<CalendarSyncEntry *>(entry);
00130   if (!calEntry) {
00131     kdDebug() << "CalendarSyncee::removeEntry(): SyncEntry has wrong type."
00132               << endl;
00133   } else {
00134     Event *ev = dynamic_cast<Event *>(calEntry->incidence());
00135     if (ev) {
00136       mCalendar->deleteEvent(ev);
00137     } else {
00138       kdDebug() << "CalendarSyncee::removeEntry(): Incidence has wrong type."
00139                 << endl;
00140     }
00141   }
00142 }
00143 
00144 CalendarSyncEntry *CalendarSyncee::createEntry(Incidence *incidence)
00145 {
00146   if (incidence) {
00147     CalendarSyncEntry *entry = new CalendarSyncEntry(incidence);
00148     mEntries.append(entry);
00149     return entry;
00150   } else {
00151     return 0;
00152   }
00153 }
KDE Home | KDE Accessibility Home | Description of Access Keys