kalarm

alarmcalendar.h

00001 /*
00002  *  alarmcalendar.h  -  KAlarm calendar file access
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2006 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program 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
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef ALARMCALENDAR_H
00022 #define ALARMCALENDAR_H
00023 
00024 #include <qobject.h>
00025 #include <kurl.h>
00026 #include <libkcal/calendarlocal.h>
00027 #include "alarmevent.h"
00028 
00029 class KConfig;
00030 
00031 
00036 class AlarmCalendar : public QObject
00037 {
00038         Q_OBJECT
00039     public:
00040         virtual ~AlarmCalendar();
00041         bool                  valid() const                       { return mUrl.isValid(); }
00042         KAEvent::Status       type() const                        { return mType; }
00043         bool                  open();
00044         int                   load();
00045         bool                  reload();
00046         bool                  save();
00047         void                  close();
00048         void                  startUpdate();
00049         bool                  endUpdate();
00050         KCal::Event*          event(const QString& uniqueID);
00051         KCal::Event::List     events();
00052         KCal::Event::List     eventsWithAlarms(const QDateTime& from, const QDateTime& to);
00053         KCal::Event*          addEvent(KAEvent&, bool useEventID = false);
00054         void                  updateEvent(const KAEvent&);
00055         bool                  deleteEvent(const QString& eventID, bool save = false);
00056         void                  emitEmptyStatus();
00057         void                  purgeAll()                          { purge(0); }
00058         void                  setPurgeDays(int days);
00059         void                  purgeIfQueued();    // must only be called from KAlarmApp::processQueue()
00060         bool                  isOpen() const                      { return mOpen; }
00061         QString               path() const                        { return mUrl.prettyURL(); }
00062         QString               urlString() const                   { return mUrl.url(); }
00063 
00064         static QString        icalProductId();
00065         static bool           initialiseCalendars();
00066         static void           terminateCalendars();
00067         static AlarmCalendar* activeCalendar()        { return mCalendars[ACTIVE]; }
00068         static AlarmCalendar* expiredCalendar()       { return mCalendars[EXPIRED]; }
00069         static AlarmCalendar* displayCalendar()       { return mCalendars[DISPLAY]; }
00070         static AlarmCalendar* templateCalendar()      { return mCalendars[TEMPLATE]; }
00071         static AlarmCalendar* activeCalendarOpen()    { return calendarOpen(ACTIVE); }
00072         static AlarmCalendar* expiredCalendarOpen()   { return calendarOpen(EXPIRED); }
00073         static AlarmCalendar* displayCalendarOpen()   { return calendarOpen(DISPLAY); }
00074         static AlarmCalendar* templateCalendarOpen()  { return calendarOpen(TEMPLATE); }
00075         static bool           importAlarms(QWidget*);
00076         static const KCal::Event* getEvent(const QString& uniqueID);
00077 
00078         enum CalID { ACTIVE, EXPIRED, DISPLAY, TEMPLATE, NCALS };
00079 
00080     signals:
00081         void                  calendarSaved(AlarmCalendar*);
00082         void                  purged();
00083         void                  emptyStatus(bool empty);
00084 
00085     private slots:
00086         void                  slotPurge();
00087 
00088     private:
00089         AlarmCalendar(const QString& file, CalID, const QString& icalFile = QString::null,
00090                       const QString& configKey = QString::null);
00091         bool                  create();
00092         bool                  saveCal(const QString& newFile = QString::null);
00093         void                  purge(int daysToKeep);
00094         void                  startPurgeTimer();
00095         static AlarmCalendar* createCalendar(CalID, KConfig*, QString& writePath, const QString& configKey = QString::null);
00096         static AlarmCalendar* calendarOpen(CalID);
00097 
00098         static AlarmCalendar* mCalendars[NCALS];   // the calendars
00099 
00100         KCal::CalendarLocal*  mCalendar;
00101         KURL                  mUrl;                // URL of current calendar file
00102         KURL                  mICalUrl;            // URL of iCalendar file
00103         QString               mLocalFile;          // calendar file, or local copy if it's a remote file
00104         QString               mConfigKey;          // config file key for this calendar's URL
00105         KAEvent::Status       mType;               // what type of events the calendar file is for
00106         int                   mPurgeDays;          // how long to keep alarms, 0 = don't keep, -1 = keep indefinitely
00107         bool                  mOpen;               // true if the calendar file is open
00108         int                   mPurgeDaysQueued;    // >= 0 to purge the calendar when called from KAlarmApp::processLoop()
00109         int                   mUpdateCount;        // nesting level of group of calendar update calls
00110         bool                  mUpdateSave;         // save() was called while mUpdateCount > 0
00111         bool                  mVCal;               // true if calendar file is in VCal format
00112 };
00113 
00114 #endif // ALARMCALENDAR_H
KDE Home | KDE Accessibility Home | Description of Access Keys