kalarmd Library API Documentation

adcalendarbase.h

00001 /*
00002     Calendar access for KDE Alarm Daemon and KDE Alarm Daemon GUI.
00003 
00004     This file is part of the KDE alarm daemon.
00005     Copyright (c) 2001, 2005 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 #ifndef ADCALENDARBASE_H
00027 #define ADCALENDARBASE_H
00028 
00029 #include <qstringlist.h>
00030 #include <libkcal/calendarlocal.h>
00031 namespace KIO {
00032   class Job;
00033 }
00034 class AlarmDaemon;
00035 
00036 using namespace KCal;
00037 
00038 // Base class for Alarm Daemon calendar access
00039 class ADCalendarBase : public CalendarLocal
00040 {
00041     Q_OBJECT
00042   public:
00043     enum Type { KORGANIZER = 0, KALARM = 1 };
00044     ADCalendarBase(const QString& url, const QCString& appname, Type);
00045     ~ADCalendarBase()  { }
00046 
00047     const QString&   urlString() const   { return mUrlString; }
00048     int              urlIndex() const    { return mUrlIndex; }
00049     const QCString&  appName() const     { return mAppName; }
00050     int              rcIndex() const     { return mRcIndex; }
00051     const QDateTime& lastCheck() const   { return mLastCheck; }
00052     bool             loaded() const      { return mLoaded; }
00053     Type             actionType() const  { return mActionType; }
00054 
00055     virtual void setEnabled( bool ) = 0;
00056     virtual bool enabled() const = 0;
00057 
00058     virtual void setAvailable( bool ) = 0;
00059     virtual bool available() const = 0;
00060 
00061     // client has registered since calendar was
00062     // constructed, but has not since added the
00063     // calendar. Monitoring is disabled.
00064     void setUnregistered( bool u ) { mUnregistered = u; }
00065     bool unregistered() const { return mUnregistered; }
00066 
00067     virtual bool loadFile() = 0;
00068     bool         downloading() const  { return !mTempFileName.isNull(); }
00069 
00070     void         setRcIndex(int i)                  { mRcIndex = i; }
00071     void         setLastCheck(const QDateTime& dt)  { mLastCheck = dt; }
00072 
00073     virtual void setEventHandled(const Event*, const QValueList<QDateTime> &) = 0;
00074     virtual bool eventHandled(const Event*, const QValueList<QDateTime> &) = 0;
00075 
00076     // Check status of mLoadedConnected and set it to true
00077     bool         setLoadedConnected();  
00078 
00079     void         dump() const;
00080 
00081   signals:
00082     void         loaded(ADCalendarBase*, bool success);
00083 
00084   protected:
00085     bool         loadFile_();
00086 
00087   private:
00088     ADCalendarBase(const ADCalendarBase&);             // prohibit copying
00089     ADCalendarBase& operator=(const ADCalendarBase&);  // prohibit copying
00090     void         loadLocalFile( const QString& filename );
00091 
00092   private slots:
00093     void         slotDownloadJobResult( KIO::Job * );
00094 
00095   protected:
00096     struct EventKey
00097     {
00098       EventKey() : calendarIndex(-1) { }
00099       EventKey(const QString& id, int cal) : eventID(id), calendarIndex(cal) { }
00100       bool    operator<(const EventKey& k) const
00101                      { return (calendarIndex == k.calendarIndex)
00102                             ? (eventID < k.eventID) : (calendarIndex < k.calendarIndex);
00103                      }
00104       QString eventID;
00105       int     calendarIndex;
00106     };
00107     struct EventItem
00108     {
00109       EventItem() : eventSequence(0) { }
00110       EventItem(int seqno, const QValueList<QDateTime>& alarmtimes)
00111         : eventSequence(seqno), alarmTimes(alarmtimes) {}
00112       int                   eventSequence;
00113       QValueList<QDateTime> alarmTimes;
00114     };
00115 
00116     typedef QMap<EventKey, EventItem>  EventsMap;   // event ID, calendar URL/event sequence num
00117     static EventsMap   mEventsHandled; // IDs of displayed KALARM type events
00118     static QStringList mCalendarUrls;  // URLs of all calendars ever opened
00119 
00120   private:
00121     QString           mUrlString;     // calendar file URL
00122     QCString          mAppName;       // name of application owning this calendar
00123     Type              mActionType;    // action to take on event
00124     QDateTime         mLastCheck;     // time at which calendar was last checked for alarms
00125     QString           mTempFileName;  // temporary file used if currently downloading, else null
00126     int               mUrlIndex;      // unique index to URL in mCalendarUrls
00127     int               mRcIndex;       // index within 'clients' RC file for this calendar's entry
00128     bool              mLoaded;        // true if calendar file is currently loaded
00129     bool              mLoadedConnected; // true if the loaded() signal has been connected to AlarmDaemon
00130     bool              mUnregistered;  // client has registered, but has not since added the calendar
00131 };
00132 
00133 typedef QPtrList<ADCalendarBase> CalendarList;
00134 
00135 class ADCalendarBaseFactory
00136 {
00137   public:
00138     virtual ADCalendarBase *create(const QString& url, const QCString& appname, ADCalendarBase::Type) = 0;
00139 };
00140 
00141 
00142 #endif
KDE Logo
This file is part of the documentation for kalarmd Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:41:06 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003