kalarmd Library API Documentation

adcalendar.cpp

00001 /*
00002     KDE Alarm Daemon.
00003 
00004     This file is part of the KDE alarm daemon.
00005     Copyright (c) 2001 David Jarvie <software@astrojar.org.uk>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include <kdebug.h>
00027 
00028 #include "adcalendar.h"
00029 
00030 ADCalendar::ADCalendar(const QString& url, const QCString& appname, Type type)
00031   : ADCalendarBase(url, appname, type),
00032     available_( false ),
00033     enabled_(true)
00034 {
00035   loadFile();
00036 }
00037 
00038 ADCalendar *ADCalendarFactory::create(const QString& url, const QCString& appname, ADCalendarBase::Type type)
00039 {
00040   return new ADCalendar(url, appname, type);
00041 }
00042 
00043 /*
00044  * Check whether all the alarms for the event with the given ID have already
00045  * been handled.
00046  */
00047 bool ADCalendar::eventHandled(const Event* event, const QValueList<QDateTime>& alarmtimes)
00048 {
00049   EventsMap::ConstIterator it = eventsHandled_.find(event->uid());
00050   if (it == eventsHandled_.end())
00051     return false;
00052 
00053   int oldCount = it.data().alarmTimes.count();
00054   int count = alarmtimes.count();
00055   for (int i = 0;  i < count;  ++i) {
00056     if (alarmtimes[i].isValid()) {
00057       if (i >= oldCount                              // is it an additional alarm?
00058       ||  !it.data().alarmTimes[i].isValid()         // or has it just become due?
00059       ||  it.data().alarmTimes[i].isValid()          // or has it changed?
00060        && alarmtimes[i] != it.data().alarmTimes[i])
00061         return false;     // this alarm has changed
00062     }
00063   }
00064   return true;
00065 }
00066 
00067 /*
00068  * Remember that the specified alarms for the event with the given ID have been
00069  * handled.
00070  */
00071 void ADCalendar::setEventHandled(const Event* event, const QValueList<QDateTime>& alarmtimes)
00072 {
00073   if (event)
00074   {
00075     kdDebug(5900) << "ADCalendar::setEventHandled(" << event->uid() << ")\n";
00076     EventsMap::Iterator it = eventsHandled_.find(event->uid());
00077     if (it != eventsHandled_.end())
00078     {
00079       // Update the existing entry for the event
00080       it.data().alarmTimes = alarmtimes;
00081       it.data().eventSequence = event->revision();
00082     }
00083     else
00084       eventsHandled_.insert(event->uid(),EventItem(urlString(),
00085                                                    event->revision(),
00086                                                    alarmtimes));
00087   }
00088 }
00089 
00090 /*
00091  * Clear all memory of events handled for the specified calendar.
00092  */
00093 void ADCalendar::clearEventsHandled(const QString& calendarURL)
00094 {
00095   for (EventsMap::Iterator it = eventsHandled_.begin();  it != eventsHandled_.end();  )
00096   {
00097     if (it.data().calendarURL == calendarURL)
00098     {
00099       EventsMap::Iterator i = it;
00100       ++it;                      // prevent iterator becoming invalid with remove()
00101       eventsHandled_.remove(i);
00102     }
00103     else
00104       ++it;
00105   }
00106 }
KDE Logo
This file is part of the documentation for kalarmd Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:04 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003