-rw-r--r-- | libkcal/calendar.cpp | 5 | ||||
-rw-r--r-- | libkcal/calendar.h | 9 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 56 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 6 |
4 files changed, 71 insertions, 5 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index f4350d9..5092d1a 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -48,16 +48,17 @@ Calendar::Calendar( const QString &timeZoneId ) | |||
48 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Calendar::init() | 51 | void Calendar::init() |
52 | { | 52 | { |
53 | mObserver = 0; | 53 | mObserver = 0; |
54 | mNewObserver = false; | 54 | mNewObserver = false; |
55 | mUndoIncidence = 0; | 55 | mUndoIncidence = 0; |
56 | mDeleteIncidencesOnClose = true; | ||
56 | mModified = false; | 57 | mModified = false; |
57 | mDefaultCalendar = 1; | 58 | mDefaultCalendar = 1; |
58 | // Setup default filter, which does nothing | 59 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 60 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 61 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 62 | mFilter->setEnabled(false); |
62 | 63 | ||
63 | // initialize random numbers. This is a hack, and not | 64 | // initialize random numbers. This is a hack, and not |
@@ -107,16 +108,20 @@ void Calendar::init() | |||
107 | } | 108 | } |
108 | 109 | ||
109 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
110 | { | 111 | { |
111 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
112 | if ( mUndoIncidence ) | 113 | if ( mUndoIncidence ) |
113 | delete mUndoIncidence; | 114 | delete mUndoIncidence; |
114 | } | 115 | } |
116 | void Calendar::setDontDeleteIncidencesOnClose () | ||
117 | { | ||
118 | mDeleteIncidencesOnClose = false; | ||
119 | } | ||
115 | void Calendar::setDefaultCalendar( int d ) | 120 | void Calendar::setDefaultCalendar( int d ) |
116 | { | 121 | { |
117 | mDefaultCalendar = d; | 122 | mDefaultCalendar = d; |
118 | } | 123 | } |
119 | int Calendar::defaultCalendar() | 124 | int Calendar::defaultCalendar() |
120 | { | 125 | { |
121 | return mDefaultCalendar; | 126 | return mDefaultCalendar; |
122 | } | 127 | } |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4c6760f..73f82bb 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -69,16 +69,18 @@ public: | |||
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | ||
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | ||
77 | 79 | ||
78 | /** | 80 | /** |
79 | Sync changes in memory to persistant storage. | 81 | Sync changes in memory to persistant storage. |
80 | */ | 82 | */ |
81 | virtual void save() = 0; | 83 | virtual void save() = 0; |
82 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 84 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
83 | virtual void removeSyncInfo( QString syncProfile) = 0; | 85 | virtual void removeSyncInfo( QString syncProfile) = 0; |
84 | virtual bool isSaving() { return false; } | 86 | virtual bool isSaving() { return false; } |
@@ -297,20 +299,23 @@ public: | |||
297 | useful for the calendar loading code. | 299 | useful for the calendar loading code. |
298 | */ | 300 | */ |
299 | void setLoadedProductId( const QString & ); | 301 | void setLoadedProductId( const QString & ); |
300 | /** | 302 | /** |
301 | Return product id taken from file that has been loaded. Returns | 303 | Return product id taken from file that has been loaded. Returns |
302 | QString::null, if no calendar has been loaded. | 304 | QString::null, if no calendar has been loaded. |
303 | */ | 305 | */ |
304 | QString loadedProductId(); | 306 | QString loadedProductId(); |
305 | void setDefaultCalendar( int ); | ||
306 | int defaultCalendar(); | 307 | int defaultCalendar(); |
308 | void setDontDeleteIncidencesOnClose (); | ||
309 | public slots: | ||
310 | void setDefaultCalendar( int ); | ||
307 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 311 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
308 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 312 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
313 | virtual void setReadOnly( int id, bool enable ) = 0; | ||
309 | virtual void setDefaultCalendarEnabledOnly() = 0; | 314 | virtual void setDefaultCalendarEnabledOnly() = 0; |
310 | signals: | 315 | signals: |
311 | void calendarChanged(); | 316 | void calendarChanged(); |
312 | void calendarSaved(); | 317 | void calendarSaved(); |
313 | void calendarLoaded(); | 318 | void calendarLoaded(); |
314 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 319 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
315 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 320 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
316 | 321 | ||
@@ -329,25 +334,27 @@ public: | |||
329 | are returned, which are completely included in the range. | 334 | are returned, which are completely included in the range. |
330 | */ | 335 | */ |
331 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 336 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
332 | bool inclusive = false ) = 0; | 337 | bool inclusive = false ) = 0; |
333 | 338 | ||
334 | Incidence *mNextAlarmIncidence; | 339 | Incidence *mNextAlarmIncidence; |
335 | Incidence *mUndoIncidence; | 340 | Incidence *mUndoIncidence; |
336 | int mDefaultCalendar; | 341 | int mDefaultCalendar; |
342 | bool mDeleteIncidencesOnClose; | ||
337 | 343 | ||
338 | private: | 344 | private: |
339 | void init(); | 345 | void init(); |
340 | 346 | ||
341 | QString mOwner; // who the calendar belongs to | 347 | QString mOwner; // who the calendar belongs to |
342 | QString mOwnerEmail; // email address of the owner | 348 | QString mOwnerEmail; // email address of the owner |
343 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 349 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
344 | bool mLocalTime; // use local time, not UTC or a time zone | 350 | bool mLocalTime; // use local time, not UTC or a time zone |
345 | 351 | ||
352 | |||
346 | CalFilter *mFilter; | 353 | CalFilter *mFilter; |
347 | CalFilter *mDefaultFilter; | 354 | CalFilter *mDefaultFilter; |
348 | 355 | ||
349 | 356 | ||
350 | QString mTimeZoneId; | 357 | QString mTimeZoneId; |
351 | 358 | ||
352 | Observer *mObserver; | 359 | Observer *mObserver; |
353 | bool mNewObserver; | 360 | bool mNewObserver; |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index c5500bf..e48122a 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -60,19 +60,57 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId) | |||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | ||
70 | } | ||
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | ||
72 | { | ||
73 | CalendarLocal calendar( timeZoneId() ); | ||
74 | calendar.setDefaultCalendar( id ); | ||
75 | if ( calendar.load( name ) ) { | ||
76 | addCalendar( &calendar ); | ||
77 | return true; | ||
78 | } | ||
79 | return false; | ||
80 | } | ||
81 | void CalendarLocal::addCalendar( Calendar* cal ) | ||
82 | { | ||
83 | cal->setDontDeleteIncidencesOnClose(); | ||
84 | { | ||
85 | QPtrList<Event> EventList = cal->rawEvents(); | ||
86 | Event * ev = EventList.first(); | ||
87 | while ( ev ) { | ||
88 | mEventList.append( ev ); | ||
89 | ev = EventList.next(); | ||
90 | } | ||
91 | } | ||
92 | { | ||
93 | QPtrList<Todo> TodoList = cal->rawTodos(); | ||
94 | Todo * ev = TodoList.first(); | ||
95 | while ( ev ) { | ||
96 | mTodoList.append( ev ); | ||
97 | ev = TodoList.next(); | ||
98 | } | ||
99 | } | ||
100 | { | ||
101 | QPtrList<Journal> JournalList = cal->journals(); | ||
102 | Journal * ev = JournalList.first(); | ||
103 | while ( ev ) { | ||
104 | mJournalList.append( ev ); | ||
105 | ev = JournalList.next(); | ||
106 | } | ||
107 | } | ||
69 | } | 108 | } |
70 | |||
71 | bool CalendarLocal::load( const QString &fileName ) | 109 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 110 | { |
73 | FileStorage storage( this, fileName ); | 111 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 112 | return storage.load(); |
75 | } | 113 | } |
76 | 114 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 115 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 116 | { |
@@ -751,16 +789,30 @@ void CalendarLocal::setCalendarEnabled( int id, bool enable ) | |||
751 | 789 | ||
752 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 790 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
753 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 791 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
754 | 792 | ||
755 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 793 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
756 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 794 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
757 | 795 | ||
758 | } | 796 | } |
797 | |||
798 | void CalendarLocal::setReadOnly( int id, bool enable ) | ||
799 | { | ||
800 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
801 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
802 | |||
803 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
804 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
805 | |||
806 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
807 | if ( it->calID() == id ) it->setReadOnly( enable ); | ||
808 | |||
809 | } | ||
810 | |||
759 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 811 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
760 | { | 812 | { |
761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 813 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
762 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 814 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
763 | 815 | ||
764 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 816 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
765 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 817 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
766 | 818 | ||
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index b25fcbe..65f6aa7 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -38,17 +38,18 @@ class CalendarLocal : public Calendar | |||
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | 46 | void addCalendar( Calendar* ); | |
47 | bool addCalendarFile( QString name, int id ); | ||
47 | /** | 48 | /** |
48 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 49 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
49 | calendar. Any information already present is lost. | 50 | calendar. Any information already present is lost. |
50 | @return true, if successfull, false on error. | 51 | @return true, if successfull, false on error. |
51 | @param fileName the name of the calendar on disk. | 52 | @param fileName the name of the calendar on disk. |
52 | */ | 53 | */ |
53 | bool load( const QString &fileName ); | 54 | bool load( const QString &fileName ); |
54 | /** | 55 | /** |
@@ -174,19 +175,20 @@ class CalendarLocal : public Calendar | |||
174 | Get unfiltered events in a range of dates. If inclusive is set to true, | 175 | Get unfiltered events in a range of dates. If inclusive is set to true, |
175 | only events are returned, which are completely included in the range. | 176 | only events are returned, which are completely included in the range. |
176 | */ | 177 | */ |
177 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 178 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
178 | bool inclusive = false ); | 179 | bool inclusive = false ); |
179 | Todo *todo( QString, QString ); | 180 | Todo *todo( QString, QString ); |
180 | Event *event( QString, QString ); | 181 | Event *event( QString, QString ); |
181 | 182 | ||
182 | 183 | public slots: | |
183 | void setCalendarEnabled( int id, bool enable ); | 184 | void setCalendarEnabled( int id, bool enable ); |
184 | void setAlarmEnabled( int id, bool enable ); | 185 | void setAlarmEnabled( int id, bool enable ); |
186 | void setReadOnly( int id, bool enable ); | ||
185 | void setDefaultCalendarEnabledOnly(); | 187 | void setDefaultCalendarEnabledOnly(); |
186 | 188 | ||
187 | protected: | 189 | protected: |
188 | 190 | ||
189 | // Event* mNextAlarmEvent; | 191 | // Event* mNextAlarmEvent; |
190 | QString mNextSummary; | 192 | QString mNextSummary; |
191 | QString mNextAlarmEventDateTimeString; | 193 | QString mNextAlarmEventDateTimeString; |
192 | QString mLastAlarmNotificationString; | 194 | QString mLastAlarmNotificationString; |