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 <tqobject.h> 00025 #include <kurl.h> 00026 #include <libkcal/calendarlocal.h> 00027 #include "alarmevent.h" 00028 00029 class TDEConfig; 00030 00031 00036 class AlarmCalendar : public TQObject 00037 { 00038 Q_OBJECT 00039 00040 public: 00041 virtual ~AlarmCalendar(); 00042 bool valid() const { return mUrl.isValid(); } 00043 KAEvent::Status type() const { return mType; } 00044 bool open(); 00045 int load(); 00046 bool reload(); 00047 bool save(); 00048 void close(); 00049 void startUpdate(); 00050 bool endUpdate(); 00051 KCal::Event* event(const TQString& uniqueID); 00052 KCal::Event::List events(); 00053 KCal::Event::List eventsWithAlarms(const TQDateTime& from, const TQDateTime& to); 00054 KCal::Event* addEvent(KAEvent&, bool useEventID = false); 00055 void updateEvent(const KAEvent&); 00056 bool deleteEvent(const TQString& eventID, bool save = false); 00057 void emitEmptyStatus(); 00058 void purgeAll() { purge(0); } 00059 void setPurgeDays(int days); 00060 void purgeIfQueued(); // must only be called from KAlarmApp::processQueue() 00061 bool isOpen() const { return mOpen; } 00062 TQString path() const { return mUrl.prettyURL(); } 00063 TQString urlString() const { return mUrl.url(); } 00064 00065 static TQString icalProductId(); 00066 static bool initialiseCalendars(); 00067 static void terminateCalendars(); 00068 static AlarmCalendar* activeCalendar() { return mCalendars[ACTIVE]; } 00069 static AlarmCalendar* expiredCalendar() { return mCalendars[EXPIRED]; } 00070 static AlarmCalendar* displayCalendar() { return mCalendars[DISPLAY]; } 00071 static AlarmCalendar* templateCalendar() { return mCalendars[TEMPLATE]; } 00072 static AlarmCalendar* activeCalendarOpen() { return calendarOpen(ACTIVE); } 00073 static AlarmCalendar* expiredCalendarOpen() { return calendarOpen(EXPIRED); } 00074 static AlarmCalendar* displayCalendarOpen() { return calendarOpen(DISPLAY); } 00075 static AlarmCalendar* templateCalendarOpen() { return calendarOpen(TEMPLATE); } 00076 static bool importAlarms(TQWidget*); 00077 static const KCal::Event* getEvent(const TQString& uniqueID); 00078 00079 enum CalID { ACTIVE, EXPIRED, DISPLAY, TEMPLATE, NCALS }; 00080 00081 signals: 00082 void calendarSaved(AlarmCalendar*); 00083 void purged(); 00084 void emptyStatus(bool empty); 00085 00086 private slots: 00087 void slotPurge(); 00088 00089 private: 00090 AlarmCalendar(const TQString& file, CalID, const TQString& icalFile = TQString(), 00091 const TQString& configKey = TQString()); 00092 bool create(); 00093 bool saveCal(const TQString& newFile = TQString()); 00094 void purge(int daysToKeep); 00095 void startPurgeTimer(); 00096 static AlarmCalendar* createCalendar(CalID, TDEConfig*, TQString& writePath, const TQString& configKey = TQString()); 00097 static AlarmCalendar* calendarOpen(CalID); 00098 00099 static AlarmCalendar* mCalendars[NCALS]; // the calendars 00100 00101 KCal::CalendarLocal* mCalendar; 00102 KURL mUrl; // URL of current calendar file 00103 KURL mICalUrl; // URL of iCalendar file 00104 TQString mLocalFile; // calendar file, or local copy if it's a remote file 00105 TQString mConfigKey; // config file key for this calendar's URL 00106 KAEvent::Status mType; // what type of events the calendar file is for 00107 int mPurgeDays; // how long to keep alarms, 0 = don't keep, -1 = keep indefinitely 00108 bool mOpen; // true if the calendar file is open 00109 int mPurgeDaysQueued; // >= 0 to purge the calendar when called from KAlarmApp::processLoop() 00110 int mUpdateCount; // nesting level of group of calendar update calls 00111 bool mUpdateSave; // save() was called while mUpdateCount > 0 00112 bool mVCal; // true if calendar file is in VCal format 00113 }; 00114 00115 #endif // ALARMCALENDAR_H