summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-10-22 16:49:42 (UTC)
committer zautrix <zautrix>2005-10-22 16:49:42 (UTC)
commit3ec18dd19fdf4eb7e763b8022f90de83249facfd (patch) (unidiff)
treeabc6c8568c33b70afd8abc46ae9495e5d862cba1 /libkcal
parentc643664ae97e757afda1012dc998b49e6cc2d575 (diff)
downloadkdepimpi-3ec18dd19fdf4eb7e763b8022f90de83249facfd.zip
kdepimpi-3ec18dd19fdf4eb7e763b8022f90de83249facfd.tar.gz
kdepimpi-3ec18dd19fdf4eb7e763b8022f90de83249facfd.tar.bz2
fixxx
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.h2
-rw-r--r--libkcal/calendarlocal.cpp26
-rw-r--r--libkcal/calendarlocal.h1
3 files changed, 28 insertions, 1 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 3f6895d..4b8b3ff 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -66,315 +66,317 @@ public:
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
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; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0; 79 virtual bool mergeCalendarFile( QString name ) = 0;
80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; 80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0;
81 virtual void setSyncEventsReadOnly() = 0; 81 virtual void setSyncEventsReadOnly() = 0;
82 virtual void stopAllTodos() = 0; 82 virtual void stopAllTodos() = 0;
83 virtual void clearUndo( Incidence * newUndo ); 83 virtual void clearUndo( Incidence * newUndo );
84 84
85 /** 85 /**
86 Sync changes in memory to persistant storage. 86 Sync changes in memory to persistant storage.
87 */ 87 */
88 virtual void save() = 0; 88 virtual void save() = 0;
89 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 89 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
90 virtual void removeSyncInfo( QString syncProfile) = 0; 90 virtual void removeSyncInfo( QString syncProfile) = 0;
91 virtual bool isSaving() { return false; } 91 virtual bool isSaving() { return false; }
92 92
93 /** 93 /**
94 Return the owner of the calendar's full name. 94 Return the owner of the calendar's full name.
95 */ 95 */
96 const QString &getOwner() const; 96 const QString &getOwner() const;
97 /** 97 /**
98 Set the owner of the calendar. Should be owner's full name. 98 Set the owner of the calendar. Should be owner's full name.
99 */ 99 */
100 void setOwner( const QString &os ); 100 void setOwner( const QString &os );
101 /** 101 /**
102 Return the email address of the calendar owner. 102 Return the email address of the calendar owner.
103 */ 103 */
104 const QString &getEmail(); 104 const QString &getEmail();
105 /** 105 /**
106 Set the email address of the calendar owner. 106 Set the email address of the calendar owner.
107 */ 107 */
108 void setEmail( const QString & ); 108 void setEmail( const QString & );
109 109
110 /** 110 /**
111 Set time zone from a timezone string (e.g. -2:00) 111 Set time zone from a timezone string (e.g. -2:00)
112 */ 112 */
113 void setTimeZone( const QString &tz ); 113 void setTimeZone( const QString &tz );
114 /** 114 /**
115 Set time zone from a minutes value (e.g. -60) 115 Set time zone from a minutes value (e.g. -60)
116 */ 116 */
117 void setTimeZone( int tz ); 117 void setTimeZone( int tz );
118 /** 118 /**
119 Return time zone as offest in minutes. 119 Return time zone as offest in minutes.
120 */ 120 */
121 int getTimeZone() const; 121 int getTimeZone() const;
122 /** 122 /**
123 Compute an ISO 8601 format string from the time zone. 123 Compute an ISO 8601 format string from the time zone.
124 */ 124 */
125 QString getTimeZoneStr() const; 125 QString getTimeZoneStr() const;
126 /** 126 /**
127 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 127 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
128 values). 128 values).
129 */ 129 */
130 void setTimeZoneId( const QString & ); 130 void setTimeZoneId( const QString & );
131 /** 131 /**
132 Return time zone id. 132 Return time zone id.
133 */ 133 */
134 QString timeZoneId() const; 134 QString timeZoneId() const;
135 /** 135 /**
136 Use local time, not UTC or a time zone. 136 Use local time, not UTC or a time zone.
137 */ 137 */
138 void setLocalTime(); 138 void setLocalTime();
139 /** 139 /**
140 Return whether local time is being used. 140 Return whether local time is being used.
141 */ 141 */
142 bool isLocalTime() const; 142 bool isLocalTime() const;
143 143
144 /** 144 /**
145 Add an incidence to calendar. 145 Add an incidence to calendar.
146 146
147 @return true on success, false on error. 147 @return true on success, false on error.
148 */ 148 */
149 virtual bool addIncidence( Incidence * ); 149 virtual bool addIncidence( Incidence * );
150 150
151 // Adds an incidence and all relatedto incidences to the cal 151 // Adds an incidence and all relatedto incidences to the cal
152 void addIncidenceBranch( Incidence * ); 152 void addIncidenceBranch( Incidence * );
153 /** 153 /**
154 Return filtered list of all incidences of this calendar. 154 Return filtered list of all incidences of this calendar.
155 */ 155 */
156 virtual QPtrList<Incidence> incidences(); 156 virtual QPtrList<Incidence> incidences();
157 157
158 /** 158 /**
159 Return unfiltered list of all incidences of this calendar. 159 Return unfiltered list of all incidences of this calendar.
160 */ 160 */
161 virtual QPtrList<Incidence> rawIncidences(); 161 virtual QPtrList<Incidence> rawIncidences();
162 162
163 /** 163 /**
164 Adds a Event to this calendar object. 164 Adds a Event to this calendar object.
165 @param anEvent a pointer to the event to add 165 @param anEvent a pointer to the event to add
166 166
167 @return true on success, false on error. 167 @return true on success, false on error.
168 */ 168 */
169 virtual bool addEventNoDup( Event *event ) = 0; 169 virtual bool addEventNoDup( Event *event ) = 0;
170 virtual bool addAnniversaryNoDup( Event *event ) = 0; 170 virtual bool addAnniversaryNoDup( Event *event ) = 0;
171 virtual bool addEvent( Event *anEvent ) = 0; 171 virtual bool addEvent( Event *anEvent ) = 0;
172 /** 172 /**
173 Delete event from calendar. 173 Delete event from calendar.
174 */ 174 */
175 virtual void deleteEvent( Event * ) = 0; 175 virtual void deleteEvent( Event * ) = 0;
176 /** 176 /**
177 Retrieves an event on the basis of the unique string ID. 177 Retrieves an event on the basis of the unique string ID.
178 */ 178 */
179 virtual Event *event( const QString &UniqueStr ) = 0; 179 virtual Event *event( const QString &UniqueStr ) = 0;
180 virtual Event *event( QString, QString ) = 0; 180 virtual Event *event( QString, QString ) = 0;
181 /** 181 /**
182 Builds and then returns a list of all events that match for the 182 Builds and then returns a list of all events that match for the
183 date specified. useful for dayView, etc. etc. 183 date specified. useful for dayView, etc. etc.
184 The calendar filter is applied. 184 The calendar filter is applied.
185 */ 185 */
186 QPtrList<Event> events( const QDate &date, bool sorted = false); 186 QPtrList<Event> events( const QDate &date, bool sorted = false);
187 /** 187 /**
188 Get events, which occur on the given date. 188 Get events, which occur on the given date.
189 The calendar filter is applied. 189 The calendar filter is applied.
190 */ 190 */
191 QPtrList<Event> events( const QDateTime &qdt ); 191 QPtrList<Event> events( const QDateTime &qdt );
192 /** 192 /**
193 Get events in a range of dates. If inclusive is set to true, only events 193 Get events in a range of dates. If inclusive is set to true, only events
194 are returned, which are completely included in the range. 194 are returned, which are completely included in the range.
195 The calendar filter is applied. 195 The calendar filter is applied.
196 */ 196 */
197 QPtrList<Event> events( const QDate &start, const QDate &end, 197 QPtrList<Event> events( const QDate &start, const QDate &end,
198 bool inclusive = false); 198 bool inclusive = false);
199 /** 199 /**
200 Return filtered list of all events in calendar. 200 Return filtered list of all events in calendar.
201 */ 201 */
202 virtual QPtrList<Event> events(); 202 virtual QPtrList<Event> events();
203 /** 203 /**
204 Return unfiltered list of all events in calendar. 204 Return unfiltered list of all events in calendar.
205 */ 205 */
206 virtual QPtrList<Event> rawEvents() = 0; 206 virtual QPtrList<Event> rawEvents() = 0;
207 207
208 /** 208 /**
209 Add a todo to the todolist. 209 Add a todo to the todolist.
210 210
211 @return true on success, false on error. 211 @return true on success, false on error.
212 */ 212 */
213 virtual bool addTodo( Todo *todo ) = 0; 213 virtual bool addTodo( Todo *todo ) = 0;
214 virtual bool addTodoNoDup( Todo *todo ) = 0; 214 virtual bool addTodoNoDup( Todo *todo ) = 0;
215 /** 215 /**
216 Remove a todo from the todolist. 216 Remove a todo from the todolist.
217 */ 217 */
218 virtual void deleteTodo( Todo * ) = 0; 218 virtual void deleteTodo( Todo * ) = 0;
219 virtual void deleteJournal( Journal * ) = 0; 219 virtual void deleteJournal( Journal * ) = 0;
220 /** 220 /**
221 Return filterd list of todos. 221 Return filterd list of todos.
222 */ 222 */
223 virtual QPtrList<Todo> todos(); 223 virtual QPtrList<Todo> todos();
224 /** 224 /**
225 Searches todolist for an event with this unique string identifier, 225 Searches todolist for an event with this unique string identifier,
226 returns a pointer or null. 226 returns a pointer or null.
227 */ 227 */
228 virtual Todo *todo( const QString &uid ) = 0; 228 virtual Todo *todo( const QString &uid ) = 0;
229 virtual Todo *todo( QString, QString ) = 0; 229 virtual Todo *todo( QString, QString ) = 0;
230 /** 230 /**
231 Returns list of todos due on the specified date. 231 Returns list of todos due on the specified date.
232 */ 232 */
233 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 233 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
234 /** 234 /**
235 Return unfiltered list of todos. 235 Return unfiltered list of todos.
236 */ 236 */
237 virtual QPtrList<Todo> rawTodos() = 0; 237 virtual QPtrList<Todo> rawTodos() = 0;
238 238
239 /** 239 /**
240 Add a Journal entry to calendar. 240 Add a Journal entry to calendar.
241 241
242 @return true on success, false on error. 242 @return true on success, false on error.
243 */ 243 */
244 virtual bool addJournal( Journal * ) = 0; 244 virtual bool addJournal( Journal * ) = 0;
245 /** 245 /**
246 Return Journal for given date. 246 Return Journal for given date.
247 */ 247 */
248 virtual Journal *journal( const QDate & ) = 0; 248 virtual Journal *journal( const QDate & ) = 0;
249 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; 249 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0;
250 /** 250 /**
251 Return Journal with given UID. 251 Return Journal with given UID.
252 */ 252 */
253 virtual Journal *journal( const QString &UID ) = 0; 253 virtual Journal *journal( const QString &UID ) = 0;
254 /** 254 /**
255 Return list of all Journal entries. 255 Return list of all Journal entries.
256 */ 256 */
257 virtual QPtrList<Journal> journals() = 0; 257 virtual QPtrList<Journal> journals() = 0;
258 258
259 /** 259 /**
260 Searches all incidence types for an incidence with this unique 260 Searches all incidence types for an incidence with this unique
261 string identifier, returns a pointer or null. 261 string identifier, returns a pointer or null.
262 */ 262 */
263 Incidence* incidence( const QString&UID ); 263 Incidence* incidence( const QString&UID );
264 264
265 /** 265 /**
266 Setup relations for an incidence. 266 Setup relations for an incidence.
267 */ 267 */
268 virtual void setupRelations( Incidence * ); 268 virtual void setupRelations( Incidence * );
269 /** 269 /**
270 Remove all relations to an incidence 270 Remove all relations to an incidence
271 */ 271 */
272 virtual void removeRelations( Incidence * ); 272 virtual void removeRelations( Incidence * );
273 273
274 /** 274 /**
275 Set calendar filter, which filters events for the events() functions. 275 Set calendar filter, which filters events for the events() functions.
276 The Filter object is owned by the caller. 276 The Filter object is owned by the caller.
277 */ 277 */
278 void setFilter( CalFilter * ); 278 void setFilter( CalFilter * );
279 /** 279 /**
280 Return calendar filter. 280 Return calendar filter.
281 */ 281 */
282 CalFilter *filter(); 282 CalFilter *filter();
283 virtual QDateTime nextAlarm( int daysTo ) = 0; 283 virtual QDateTime nextAlarm( int daysTo ) = 0;
284 virtual QString nextSummary( ) const = 0; 284 virtual QString nextSummary( ) const = 0;
285 virtual void reInitAlarmSettings() = 0; 285 virtual void reInitAlarmSettings() = 0;
286 virtual QDateTime nextAlarmEventDateTime() const = 0; 286 virtual QDateTime nextAlarmEventDateTime() const = 0;
287 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 287 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
288 /** 288 /**
289 Return all alarms, which ocur in the given time interval. 289 Return all alarms, which ocur in the given time interval.
290 */ 290 */
291 virtual Alarm::List alarms( const QDateTime &from, 291 virtual Alarm::List alarms( const QDateTime &from,
292 const QDateTime &to ) = 0; 292 const QDateTime &to ) = 0;
293 293
294 class Observer { 294 class Observer {
295 public: 295 public:
296 virtual void calendarModified( bool, Calendar * ) = 0; 296 virtual void calendarModified( bool, Calendar * ) = 0;
297 }; 297 };
298 298
299 void registerObserver( Observer * ); 299 void registerObserver( Observer * );
300 300
301 void setModified( bool ); 301 void setModified( bool );
302 302
303 /** 303 /**
304 Set product id returned by loadedProductId(). This function is only 304 Set product id returned by loadedProductId(). This function is only
305 useful for the calendar loading code. 305 useful for the calendar loading code.
306 */ 306 */
307 void setLoadedProductId( const QString & ); 307 void setLoadedProductId( const QString & );
308 /** 308 /**
309 Return product id taken from file that has been loaded. Returns 309 Return product id taken from file that has been loaded. Returns
310 QString::null, if no calendar has been loaded. 310 QString::null, if no calendar has been loaded.
311 */ 311 */
312 QString loadedProductId(); 312 QString loadedProductId();
313 int defaultCalendar(); 313 int defaultCalendar();
314 void setDontDeleteIncidencesOnClose (); 314 void setDontDeleteIncidencesOnClose ();
315 public slots: 315 public slots:
316 void setDefaultCalendar( int ); 316 void setDefaultCalendar( int );
317 virtual void setCalendarEnabled( int id, bool enable ) = 0; 317 virtual void setCalendarEnabled( int id, bool enable ) = 0;
318 virtual void setAlarmEnabled( int id, bool enable ) = 0; 318 virtual void setAlarmEnabled( int id, bool enable ) = 0;
319 virtual void setReadOnly( int id, bool enable ) = 0; 319 virtual void setReadOnly( int id, bool enable ) = 0;
320 virtual void setDefaultCalendarEnabledOnly() = 0; 320 virtual void setDefaultCalendarEnabledOnly() = 0;
321 virtual void setCalendarRemove( int id ) = 0; 321 virtual void setCalendarRemove( int id ) = 0;
322 virtual void getIncidenceCount( int calId, int& events, int & todos, int & journals) = 0;
323
322 signals: 324 signals:
323 void calendarChanged(); 325 void calendarChanged();
324 void calendarSaved(); 326 void calendarSaved();
325 void calendarLoaded(); 327 void calendarLoaded();
326 void addAlarm(const QDateTime &qdt, const QString &noti ); 328 void addAlarm(const QDateTime &qdt, const QString &noti );
327 void removeAlarm(const QDateTime &qdt, const QString &noti ); 329 void removeAlarm(const QDateTime &qdt, const QString &noti );
328 330
329 protected: 331 protected:
330 /** 332 /**
331 Get unfiltered events, which occur on the given date. 333 Get unfiltered events, which occur on the given date.
332 */ 334 */
333 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 335 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
334 /** 336 /**
335 Get unfiltered events, which occur on the given date. 337 Get unfiltered events, which occur on the given date.
336 */ 338 */
337 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 339 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
338 bool sorted = false ) = 0; 340 bool sorted = false ) = 0;
339 /** 341 /**
340 Get events in a range of dates. If inclusive is set to true, only events 342 Get events in a range of dates. If inclusive is set to true, only events
341 are returned, which are completely included in the range. 343 are returned, which are completely included in the range.
342 */ 344 */
343 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 345 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
344 bool inclusive = false ) = 0; 346 bool inclusive = false ) = 0;
345 347
346 Incidence *mNextAlarmIncidence; 348 Incidence *mNextAlarmIncidence;
347 Incidence *mUndoIncidence; 349 Incidence *mUndoIncidence;
348 int mDefaultCalendar; 350 int mDefaultCalendar;
349 bool mDeleteIncidencesOnClose; 351 bool mDeleteIncidencesOnClose;
350 352
351private: 353private:
352 void init(); 354 void init();
353 355
354 QString mOwner; // who the calendar belongs to 356 QString mOwner; // who the calendar belongs to
355 QString mOwnerEmail; // email address of the owner 357 QString mOwnerEmail; // email address of the owner
356 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 358 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
357 bool mLocalTime; // use local time, not UTC or a time zone 359 bool mLocalTime; // use local time, not UTC or a time zone
358 360
359 361
360 CalFilter *mFilter; 362 CalFilter *mFilter;
361 CalFilter *mDefaultFilter; 363 CalFilter *mDefaultFilter;
362 364
363 365
364 QString mTimeZoneId; 366 QString mTimeZoneId;
365 367
366 Observer *mObserver; 368 Observer *mObserver;
367 bool mNewObserver; 369 bool mNewObserver;
368 370
369 bool mModified; 371 bool mModified;
370 372
371 QString mLoadedProductId; 373 QString mLoadedProductId;
372 374
373 // This list is used to put together related todos 375 // This list is used to put together related todos
374 QDict<Incidence> mOrphans; 376 QDict<Incidence> mOrphans;
375 QDict<Incidence> mOrphanUids; 377 QDict<Incidence> mOrphanUids;
376}; 378};
377 379
378} 380}
379 381
380#endif 382#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 1a1c6be..0ddfeca 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -199,527 +199,551 @@ void CalendarLocal::addCalendar( Calendar* cal )
199 { 199 {
200 200
201 QPtrList<Todo> TodoList = cal->rawTodos(); 201 QPtrList<Todo> TodoList = cal->rawTodos();
202 Todo * ev = TodoList.first(); 202 Todo * ev = TodoList.first();
203 while ( ev ) { 203 while ( ev ) {
204 QString rel = ev->relatedToUid(); 204 QString rel = ev->relatedToUid();
205 if ( !rel.isEmpty() ){ 205 if ( !rel.isEmpty() ){
206 ev->setRelatedTo ( 0 ); 206 ev->setRelatedTo ( 0 );
207 ev->setRelatedToUid( rel ); 207 ev->setRelatedToUid( rel );
208 } 208 }
209 ev = TodoList.next(); 209 ev = TodoList.next();
210 } 210 }
211 //TodoList = cal->rawTodos(); 211 //TodoList = cal->rawTodos();
212 ev = TodoList.first(); 212 ev = TodoList.first();
213 while ( ev ) { 213 while ( ev ) {
214 ev->unRegisterObserver( cal ); 214 ev->unRegisterObserver( cal );
215 ev->registerObserver( this ); 215 ev->registerObserver( this );
216 mTodoList.append( ev ); 216 mTodoList.append( ev );
217 setupRelations( ev ); 217 setupRelations( ev );
218 ev = TodoList.next(); 218 ev = TodoList.next();
219 } 219 }
220 } 220 }
221 { 221 {
222 QPtrList<Journal> JournalList = cal->journals(); 222 QPtrList<Journal> JournalList = cal->journals();
223 Journal * ev = JournalList.first(); 223 Journal * ev = JournalList.first();
224 while ( ev ) { 224 while ( ev ) {
225 ev->unRegisterObserver( cal ); 225 ev->unRegisterObserver( cal );
226 ev->registerObserver( this ); 226 ev->registerObserver( this );
227 mJournalList.append( ev ); 227 mJournalList.append( ev );
228 ev = JournalList.next(); 228 ev = JournalList.next();
229 } 229 }
230 } 230 }
231 setModified( true ); 231 setModified( true );
232} 232}
233bool CalendarLocal::load( const QString &fileName ) 233bool CalendarLocal::load( const QString &fileName )
234{ 234{
235 FileStorage storage( this, fileName ); 235 FileStorage storage( this, fileName );
236 return storage.load(); 236 return storage.load();
237} 237}
238 238
239bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 239bool CalendarLocal::save( const QString &fileName, CalFormat *format )
240{ 240{
241 FileStorage storage( this, fileName, format ); 241 FileStorage storage( this, fileName, format );
242 return storage.save(); 242 return storage.save();
243} 243}
244 244
245void CalendarLocal::stopAllTodos() 245void CalendarLocal::stopAllTodos()
246{ 246{
247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
248 it->setRunning( false ); 248 it->setRunning( false );
249 249
250} 250}
251void CalendarLocal::close() 251void CalendarLocal::close()
252{ 252{
253 253
254 Todo * i; 254 Todo * i;
255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
256 256
257 mEventList.setAutoDelete( true ); 257 mEventList.setAutoDelete( true );
258 mTodoList.setAutoDelete( true ); 258 mTodoList.setAutoDelete( true );
259 mJournalList.setAutoDelete( true ); 259 mJournalList.setAutoDelete( true );
260 260
261 mEventList.clear(); 261 mEventList.clear();
262 mTodoList.clear(); 262 mTodoList.clear();
263 mJournalList.clear(); 263 mJournalList.clear();
264 264
265 mEventList.setAutoDelete( false ); 265 mEventList.setAutoDelete( false );
266 mTodoList.setAutoDelete( false ); 266 mTodoList.setAutoDelete( false );
267 mJournalList.setAutoDelete( false ); 267 mJournalList.setAutoDelete( false );
268 268
269 setModified( false ); 269 setModified( false );
270} 270}
271 271
272bool CalendarLocal::addAnniversaryNoDup( Event *event ) 272bool CalendarLocal::addAnniversaryNoDup( Event *event )
273{ 273{
274 QString cat; 274 QString cat;
275 bool isBirthday = true; 275 bool isBirthday = true;
276 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 276 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
277 isBirthday = false; 277 isBirthday = false;
278 cat = i18n( "Anniversary" ); 278 cat = i18n( "Anniversary" );
279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
280 isBirthday = true; 280 isBirthday = true;
281 cat = i18n( "Birthday" ); 281 cat = i18n( "Birthday" );
282 } else { 282 } else {
283 qDebug("addAnniversaryNoDup called without fitting category! "); 283 qDebug("addAnniversaryNoDup called without fitting category! ");
284 return false; 284 return false;
285 } 285 }
286 Event * eve; 286 Event * eve;
287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
288 if ( !(eve->categories().contains( cat ) )) 288 if ( !(eve->categories().contains( cat ) ))
289 continue; 289 continue;
290 // now we have an event with fitting category 290 // now we have an event with fitting category
291 if ( eve->dtStart().date() != event->dtStart().date() ) 291 if ( eve->dtStart().date() != event->dtStart().date() )
292 continue; 292 continue;
293 // now we have an event with fitting category+date 293 // now we have an event with fitting category+date
294 if ( eve->summary() != event->summary() ) 294 if ( eve->summary() != event->summary() )
295 continue; 295 continue;
296 // now we have an event with fitting category+date+summary 296 // now we have an event with fitting category+date+summary
297 return false; 297 return false;
298 } 298 }
299 return addEvent( event ); 299 return addEvent( event );
300 300
301} 301}
302bool CalendarLocal::addEventNoDup( Event *event ) 302bool CalendarLocal::addEventNoDup( Event *event )
303{ 303{
304 Event * eve; 304 Event * eve;
305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
306 if ( *eve == *event ) { 306 if ( *eve == *event ) {
307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
308 return false; 308 return false;
309 } 309 }
310 } 310 }
311 return addEvent( event ); 311 return addEvent( event );
312} 312}
313 313
314bool CalendarLocal::addEvent( Event *event ) 314bool CalendarLocal::addEvent( Event *event )
315{ 315{
316 insertEvent( event ); 316 insertEvent( event );
317 317
318 event->registerObserver( this ); 318 event->registerObserver( this );
319 319
320 setModified( true ); 320 setModified( true );
321 if ( event->calID() == 0 ) 321 if ( event->calID() == 0 )
322 event->setCalID( mDefaultCalendar ); 322 event->setCalID( mDefaultCalendar );
323 event->setCalEnabled( true ); 323 event->setCalEnabled( true );
324 324
325 return true; 325 return true;
326} 326}
327 327
328void CalendarLocal::deleteEvent( Event *event ) 328void CalendarLocal::deleteEvent( Event *event )
329{ 329{
330 clearUndo(event); 330 clearUndo(event);
331 if ( mEventList.removeRef( event ) ) { 331 if ( mEventList.removeRef( event ) ) {
332 setModified( true ); 332 setModified( true );
333 } 333 }
334} 334}
335 335
336 336
337Event *CalendarLocal::event( const QString &uid ) 337Event *CalendarLocal::event( const QString &uid )
338{ 338{
339 Event *event; 339 Event *event;
340 Event *retVal = 0; 340 Event *retVal = 0;
341 for ( event = mEventList.first(); event; event = mEventList.next() ) { 341 for ( event = mEventList.first(); event; event = mEventList.next() ) {
342 if ( event->calEnabled() && event->uid() == uid ) { 342 if ( event->calEnabled() && event->uid() == uid ) {
343 if ( retVal ) { 343 if ( retVal ) {
344 if ( retVal->calID() > event->calID() ) { 344 if ( retVal->calID() > event->calID() ) {
345 retVal = event; 345 retVal = event;
346 } 346 }
347 } else { 347 } else {
348 retVal = event; 348 retVal = event;
349 } 349 }
350 } 350 }
351 } 351 }
352 return retVal; 352 return retVal;
353} 353}
354bool CalendarLocal::addTodoNoDup( Todo *todo ) 354bool CalendarLocal::addTodoNoDup( Todo *todo )
355{ 355{
356 Todo * eve; 356 Todo * eve;
357 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 357 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
358 if ( *eve == *todo ) { 358 if ( *eve == *todo ) {
359 //qDebug("duplicate todo found! not inserted! "); 359 //qDebug("duplicate todo found! not inserted! ");
360 return false; 360 return false;
361 } 361 }
362 } 362 }
363 return addTodo( todo ); 363 return addTodo( todo );
364} 364}
365bool CalendarLocal::addTodo( Todo *todo ) 365bool CalendarLocal::addTodo( Todo *todo )
366{ 366{
367 mTodoList.append( todo ); 367 mTodoList.append( todo );
368 368
369 todo->registerObserver( this ); 369 todo->registerObserver( this );
370 370
371 // Set up subtask relations 371 // Set up subtask relations
372 setupRelations( todo ); 372 setupRelations( todo );
373 373
374 setModified( true ); 374 setModified( true );
375 if ( todo->calID() == 0 ) 375 if ( todo->calID() == 0 )
376 todo->setCalID( mDefaultCalendar ); 376 todo->setCalID( mDefaultCalendar );
377 todo->setCalEnabled( true ); 377 todo->setCalEnabled( true );
378 return true; 378 return true;
379} 379}
380 380
381void CalendarLocal::deleteTodo( Todo *todo ) 381void CalendarLocal::deleteTodo( Todo *todo )
382{ 382{
383 // Handle orphaned children 383 // Handle orphaned children
384 removeRelations( todo ); 384 removeRelations( todo );
385 clearUndo(todo); 385 clearUndo(todo);
386 386
387 if ( mTodoList.removeRef( todo ) ) { 387 if ( mTodoList.removeRef( todo ) ) {
388 setModified( true ); 388 setModified( true );
389 } 389 }
390} 390}
391 391
392QPtrList<Todo> CalendarLocal::rawTodos() 392QPtrList<Todo> CalendarLocal::rawTodos()
393{ 393{
394 QPtrList<Todo> el; 394 QPtrList<Todo> el;
395 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 395 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
396 if ( it->calEnabled() ) el.append( it ); 396 if ( it->calEnabled() ) el.append( it );
397 return el; 397 return el;
398} 398}
399Todo *CalendarLocal::todo( QString syncProf, QString id ) 399Todo *CalendarLocal::todo( QString syncProf, QString id )
400{ 400{
401 Todo *todo; 401 Todo *todo;
402 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 402 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
403 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 403 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
404 } 404 }
405 405
406 return 0; 406 return 0;
407} 407}
408void CalendarLocal::removeSyncInfo( QString syncProfile) 408void CalendarLocal::removeSyncInfo( QString syncProfile)
409{ 409{
410 QPtrList<Incidence> all = rawIncidences() ; 410 QPtrList<Incidence> all = rawIncidences() ;
411 Incidence *inc; 411 Incidence *inc;
412 for ( inc = all.first(); inc; inc = all.next() ) { 412 for ( inc = all.first(); inc; inc = all.next() ) {
413 inc->removeID( syncProfile ); 413 inc->removeID( syncProfile );
414 } 414 }
415 if ( syncProfile.isEmpty() ) { 415 if ( syncProfile.isEmpty() ) {
416 QPtrList<Event> el; 416 QPtrList<Event> el;
417 Event *todo; 417 Event *todo;
418 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 418 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
419 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 419 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
420 el.append( todo ); 420 el.append( todo );
421 } 421 }
422 for ( todo = el.first(); todo; todo = el.next() ) { 422 for ( todo = el.first(); todo; todo = el.next() ) {
423 deleteIncidence ( todo ); 423 deleteIncidence ( todo );
424 } 424 }
425 } else { 425 } else {
426 Event *lse = event( "last-syncEvent-"+ syncProfile); 426 Event *lse = event( "last-syncEvent-"+ syncProfile);
427 if ( lse ) 427 if ( lse )
428 deleteIncidence ( lse ); 428 deleteIncidence ( lse );
429 } 429 }
430} 430}
431QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 431QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
432{ 432{
433 QPtrList<Event> el; 433 QPtrList<Event> el;
434 Event *todo; 434 Event *todo;
435 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 435 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
436 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 436 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
437 if ( todo->summary().left(3) == "E: " ) 437 if ( todo->summary().left(3) == "E: " )
438 el.append( todo ); 438 el.append( todo );
439 } 439 }
440 440
441 return el; 441 return el;
442 442
443} 443}
444Event *CalendarLocal::event( QString syncProf, QString id ) 444Event *CalendarLocal::event( QString syncProf, QString id )
445{ 445{
446 Event *todo; 446 Event *todo;
447 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 447 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
448 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 448 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
449 } 449 }
450 450
451 return 0; 451 return 0;
452} 452}
453Todo *CalendarLocal::todo( const QString &uid ) 453Todo *CalendarLocal::todo( const QString &uid )
454{ 454{
455 Todo *todo;; 455 Todo *todo;
456 Todo *retVal = 0; 456 Todo *retVal = 0;
457 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 457 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
458 if ( todo->calEnabled() && todo->uid() == uid ) { 458 if ( todo->calEnabled() && todo->uid() == uid ) {
459 if ( retVal ) { 459 if ( retVal ) {
460 if ( retVal->calID() > todo->calID() ) { 460 if ( retVal->calID() > todo->calID() ) {
461 retVal = todo; 461 retVal = todo;
462 } 462 }
463 } else { 463 } else {
464 retVal = todo; 464 retVal = todo;
465 } 465 }
466 } 466 }
467 } 467 }
468 return retVal; 468 return retVal;
469} 469}
470void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
471{
472 events = 0;
473 todos = 0;
474 journals = 0;
475 {
476 Todo *todo;
477 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
478 if ( todo->calID() == calId )
479 ++todos;
480 }
481 }
482 {
483 Event *todo;
484 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
485 if ( todo->calID() == calId )
486 ++events;
487
488 }
489 }
490 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
491 if ( it->calID() == calId ) ++journals;
492
493}
470QString CalendarLocal::nextSummary() const 494QString CalendarLocal::nextSummary() const
471{ 495{
472 return mNextSummary; 496 return mNextSummary;
473} 497}
474QDateTime CalendarLocal::nextAlarmEventDateTime() const 498QDateTime CalendarLocal::nextAlarmEventDateTime() const
475{ 499{
476 return mNextAlarmEventDateTime; 500 return mNextAlarmEventDateTime;
477} 501}
478void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 502void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
479{ 503{
480 //mNextAlarmIncidence 504 //mNextAlarmIncidence
481 //mNextAlarmDateTime 505 //mNextAlarmDateTime
482 //return mNextSummary; 506 //return mNextSummary;
483 //return mNextAlarmEventDateTime; 507 //return mNextAlarmEventDateTime;
484 bool newNextAlarm = false; 508 bool newNextAlarm = false;
485 bool computeNextAlarm = false; 509 bool computeNextAlarm = false;
486 bool ok; 510 bool ok;
487 int offset; 511 int offset;
488 QDateTime nextA; 512 QDateTime nextA;
489 // QString nextSum; 513 // QString nextSum;
490 //QDateTime nextEvent; 514 //QDateTime nextEvent;
491 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 515 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
492 computeNextAlarm = true; 516 computeNextAlarm = true;
493 } else { 517 } else {
494 if ( ! deleted ) { 518 if ( ! deleted ) {
495 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 519 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
496 if ( ok ) { 520 if ( ok ) {
497 if ( nextA < mNextAlarmDateTime ) { 521 if ( nextA < mNextAlarmDateTime ) {
498 deRegisterAlarm(); 522 deRegisterAlarm();
499 mNextAlarmDateTime = nextA; 523 mNextAlarmDateTime = nextA;
500 mNextSummary = incidence->summary(); 524 mNextSummary = incidence->summary();
501 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 525 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
502 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 526 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
503 newNextAlarm = true; 527 newNextAlarm = true;
504 mNextAlarmIncidence = incidence; 528 mNextAlarmIncidence = incidence;
505 } else { 529 } else {
506 if ( incidence == mNextAlarmIncidence ) { 530 if ( incidence == mNextAlarmIncidence ) {
507 computeNextAlarm = true; 531 computeNextAlarm = true;
508 } 532 }
509 } 533 }
510 } else { 534 } else {
511 if ( mNextAlarmIncidence == incidence ) { 535 if ( mNextAlarmIncidence == incidence ) {
512 computeNextAlarm = true; 536 computeNextAlarm = true;
513 } 537 }
514 } 538 }
515 } else { // deleted 539 } else { // deleted
516 if ( incidence == mNextAlarmIncidence ) { 540 if ( incidence == mNextAlarmIncidence ) {
517 computeNextAlarm = true; 541 computeNextAlarm = true;
518 } 542 }
519 } 543 }
520 } 544 }
521 if ( computeNextAlarm ) { 545 if ( computeNextAlarm ) {
522 deRegisterAlarm(); 546 deRegisterAlarm();
523 nextA = nextAlarm( 1000 ); 547 nextA = nextAlarm( 1000 );
524 if (! mNextAlarmIncidence ) { 548 if (! mNextAlarmIncidence ) {
525 return; 549 return;
526 } 550 }
527 newNextAlarm = true; 551 newNextAlarm = true;
528 } 552 }
529 if ( newNextAlarm ) 553 if ( newNextAlarm )
530 registerAlarm(); 554 registerAlarm();
531} 555}
532QString CalendarLocal:: getAlarmNotification() 556QString CalendarLocal:: getAlarmNotification()
533{ 557{
534 QString ret; 558 QString ret;
535 // this should not happen 559 // this should not happen
536 if (! mNextAlarmIncidence ) 560 if (! mNextAlarmIncidence )
537 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 561 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
538 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 562 Alarm* alarm = mNextAlarmIncidence->alarms().first();
539 if ( alarm->type() == Alarm::Procedure ) { 563 if ( alarm->type() == Alarm::Procedure ) {
540 ret = "proc_alarm" + alarm->programFile()+"+++"; 564 ret = "proc_alarm" + alarm->programFile()+"+++";
541 } else { 565 } else {
542 ret = "audio_alarm" +alarm->audioFile() +"+++"; 566 ret = "audio_alarm" +alarm->audioFile() +"+++";
543 } 567 }
544 ret += "cal_alarm"+ mNextSummary.left( 25 ); 568 ret += "cal_alarm"+ mNextSummary.left( 25 );
545 if ( mNextSummary.length() > 25 ) 569 if ( mNextSummary.length() > 25 )
546 ret += "\n" + mNextSummary.mid(25, 25 ); 570 ret += "\n" + mNextSummary.mid(25, 25 );
547 ret+= "\n"+mNextAlarmEventDateTimeString; 571 ret+= "\n"+mNextAlarmEventDateTimeString;
548 return ret; 572 return ret;
549} 573}
550void CalendarLocal::registerAlarm() 574void CalendarLocal::registerAlarm()
551{ 575{
552 mLastAlarmNotificationString = getAlarmNotification(); 576 mLastAlarmNotificationString = getAlarmNotification();
553 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 577 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
554 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 578 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
555// #ifndef DESKTOP_VERSION 579// #ifndef DESKTOP_VERSION
556// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 580// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
557// #endif 581// #endif
558} 582}
559void CalendarLocal::deRegisterAlarm() 583void CalendarLocal::deRegisterAlarm()
560{ 584{
561 if ( mLastAlarmNotificationString.isNull() ) 585 if ( mLastAlarmNotificationString.isNull() )
562 return; 586 return;
563 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 587 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
564 588
565 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 589 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
566 mNextAlarmEventDateTime = QDateTime(); 590 mNextAlarmEventDateTime = QDateTime();
567// #ifndef DESKTOP_VERSION 591// #ifndef DESKTOP_VERSION
568// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 592// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
569// #endif 593// #endif
570} 594}
571 595
572QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 596QPtrList<Todo> CalendarLocal::todos( const QDate &date )
573{ 597{
574 QPtrList<Todo> todos; 598 QPtrList<Todo> todos;
575 599
576 Todo *todo; 600 Todo *todo;
577 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 601 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
578 if ( !todo->calEnabled() ) continue; 602 if ( !todo->calEnabled() ) continue;
579 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 603 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
580 todos.append( todo ); 604 todos.append( todo );
581 } 605 }
582 } 606 }
583 607
584 filter()->apply( &todos ); 608 filter()->apply( &todos );
585 return todos; 609 return todos;
586} 610}
587void CalendarLocal::reInitAlarmSettings() 611void CalendarLocal::reInitAlarmSettings()
588{ 612{
589 if ( !mNextAlarmIncidence ) { 613 if ( !mNextAlarmIncidence ) {
590 nextAlarm( 1000 ); 614 nextAlarm( 1000 );
591 } 615 }
592 deRegisterAlarm(); 616 deRegisterAlarm();
593 mNextAlarmIncidence = 0; 617 mNextAlarmIncidence = 0;
594 checkAlarmForIncidence( 0, false ); 618 checkAlarmForIncidence( 0, false );
595 619
596} 620}
597 621
598 622
599 623
600QDateTime CalendarLocal::nextAlarm( int daysTo ) 624QDateTime CalendarLocal::nextAlarm( int daysTo )
601{ 625{
602 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 626 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
603 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 627 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
604 QDateTime next; 628 QDateTime next;
605 Event *e; 629 Event *e;
606 bool ok; 630 bool ok;
607 bool found = false; 631 bool found = false;
608 int offset; 632 int offset;
609 mNextAlarmIncidence = 0; 633 mNextAlarmIncidence = 0;
610 for( e = mEventList.first(); e; e = mEventList.next() ) { 634 for( e = mEventList.first(); e; e = mEventList.next() ) {
611 if ( !e->calEnabled() ) continue; 635 if ( !e->calEnabled() ) continue;
612 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 636 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
613 if ( ok ) { 637 if ( ok ) {
614 if ( next < nextA ) { 638 if ( next < nextA ) {
615 nextA = next; 639 nextA = next;
616 found = true; 640 found = true;
617 mNextSummary = e->summary(); 641 mNextSummary = e->summary();
618 mNextAlarmEventDateTime = next.addSecs(offset ) ; 642 mNextAlarmEventDateTime = next.addSecs(offset ) ;
619 mNextAlarmIncidence = (Incidence *) e; 643 mNextAlarmIncidence = (Incidence *) e;
620 } 644 }
621 } 645 }
622 } 646 }
623 Todo *t; 647 Todo *t;
624 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 648 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
625 if ( !t->calEnabled() ) continue; 649 if ( !t->calEnabled() ) continue;
626 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 650 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
627 if ( ok ) { 651 if ( ok ) {
628 if ( next < nextA ) { 652 if ( next < nextA ) {
629 nextA = next; 653 nextA = next;
630 found = true; 654 found = true;
631 mNextSummary = t->summary(); 655 mNextSummary = t->summary();
632 mNextAlarmEventDateTime = next.addSecs(offset ); 656 mNextAlarmEventDateTime = next.addSecs(offset );
633 mNextAlarmIncidence = (Incidence *) t; 657 mNextAlarmIncidence = (Incidence *) t;
634 } 658 }
635 } 659 }
636 } 660 }
637 if ( mNextAlarmIncidence ) { 661 if ( mNextAlarmIncidence ) {
638 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 662 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
639 mNextAlarmDateTime = nextA; 663 mNextAlarmDateTime = nextA;
640 } 664 }
641 return nextA; 665 return nextA;
642} 666}
643Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 667Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
644{ 668{
645 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 669 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
646} 670}
647 671
648Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 672Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
649{ 673{
650 674
651 Alarm::List alarms; 675 Alarm::List alarms;
652 676
653 Event *e; 677 Event *e;
654 678
655 for( e = mEventList.first(); e; e = mEventList.next() ) { 679 for( e = mEventList.first(); e; e = mEventList.next() ) {
656 if ( !e->calEnabled() ) continue; 680 if ( !e->calEnabled() ) continue;
657 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 681 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
658 else appendAlarms( alarms, e, from, to ); 682 else appendAlarms( alarms, e, from, to );
659 } 683 }
660 684
661 Todo *t; 685 Todo *t;
662 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 686 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
663 if ( !t->calEnabled() ) continue; 687 if ( !t->calEnabled() ) continue;
664 appendAlarms( alarms, t, from, to ); 688 appendAlarms( alarms, t, from, to );
665 } 689 }
666 690
667 return alarms; 691 return alarms;
668} 692}
669 693
670void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 694void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
671 const QDateTime &from, const QDateTime &to ) 695 const QDateTime &from, const QDateTime &to )
672{ 696{
673 QPtrList<Alarm> alarmList = incidence->alarms(); 697 QPtrList<Alarm> alarmList = incidence->alarms();
674 Alarm *alarm; 698 Alarm *alarm;
675 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 699 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
676// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 700// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
677// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 701// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
678 if ( alarm->enabled() ) { 702 if ( alarm->enabled() ) {
679 if ( alarm->time() >= from && alarm->time() <= to ) { 703 if ( alarm->time() >= from && alarm->time() <= to ) {
680 alarms.append( alarm ); 704 alarms.append( alarm );
681 } 705 }
682 } 706 }
683 } 707 }
684} 708}
685 709
686void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 710void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
687 Incidence *incidence, 711 Incidence *incidence,
688 const QDateTime &from, 712 const QDateTime &from,
689 const QDateTime &to ) 713 const QDateTime &to )
690{ 714{
691 715
692 QPtrList<Alarm> alarmList = incidence->alarms(); 716 QPtrList<Alarm> alarmList = incidence->alarms();
693 Alarm *alarm; 717 Alarm *alarm;
694 QDateTime qdt; 718 QDateTime qdt;
695 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 719 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
696 if (incidence->recursOn(from.date())) { 720 if (incidence->recursOn(from.date())) {
697 qdt.setTime(alarm->time().time()); 721 qdt.setTime(alarm->time().time());
698 qdt.setDate(from.date()); 722 qdt.setDate(from.date());
699 } 723 }
700 else qdt = alarm->time(); 724 else qdt = alarm->time();
701 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 725 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
702 if ( alarm->enabled() ) { 726 if ( alarm->enabled() ) {
703 if ( qdt >= from && qdt <= to ) { 727 if ( qdt >= from && qdt <= to ) {
704 alarms.append( alarm ); 728 alarms.append( alarm );
705 } 729 }
706 } 730 }
707 } 731 }
708} 732}
709 733
710 734
711/****************************** PROTECTED METHODS ****************************/ 735/****************************** PROTECTED METHODS ****************************/
712 736
713// after changes are made to an event, this should be called. 737// after changes are made to an event, this should be called.
714void CalendarLocal::update( IncidenceBase *incidence ) 738void CalendarLocal::update( IncidenceBase *incidence )
715{ 739{
716 incidence->setSyncStatus( Event::SYNCMOD ); 740 incidence->setSyncStatus( Event::SYNCMOD );
717 incidence->setLastModified( QDateTime::currentDateTime() ); 741 incidence->setLastModified( QDateTime::currentDateTime() );
718 // we should probably update the revision number here, 742 // we should probably update the revision number here,
719 // or internally in the Event itself when certain things change. 743 // or internally in the Event itself when certain things change.
720 // need to verify with ical documentation. 744 // need to verify with ical documentation.
721 745
722 setModified( true ); 746 setModified( true );
723} 747}
724 748
725void CalendarLocal::insertEvent( Event *event ) 749void CalendarLocal::insertEvent( Event *event )
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index a7a85c8..ca0bd98 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,230 +1,231 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_CALENDARLOCAL_H 22#ifndef KCAL_CALENDARLOCAL_H
23#define KCAL_CALENDARLOCAL_H 23#define KCAL_CALENDARLOCAL_H
24 24
25#include "calendar.h" 25#include "calendar.h"
26 26
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class CalFormat;
30 30
31/** 31/**
32 This class provides a calendar stored as a local file. 32 This class provides a calendar stored as a local file.
33*/ 33*/
34class CalendarLocal : public Calendar 34class CalendarLocal : public Calendar
35{ 35{
36 public: 36 public:
37 /** 37 /**
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 void addCalendar( Calendar* ); 46 void addCalendar( Calendar* );
47 bool addCalendarFile( QString name, int id ); 47 bool addCalendarFile( QString name, int id );
48 bool mergeCalendarFile( QString name ); 48 bool mergeCalendarFile( QString name );
49 bool mergeCalendar( Calendar* cal ); 49 bool mergeCalendar( Calendar* cal );
50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); 50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates );
51 void setSyncEventsReadOnly(); 51 void setSyncEventsReadOnly();
52 void stopAllTodos(); 52 void stopAllTodos();
53 /** 53 /**
54 Loads a calendar on disk in vCalendar or iCalendar format into the current 54 Loads a calendar on disk in vCalendar or iCalendar format into the current
55 calendar. Any information already present is lost. 55 calendar. Any information already present is lost.
56 @return true, if successfull, false on error. 56 @return true, if successfull, false on error.
57 @param fileName the name of the calendar on disk. 57 @param fileName the name of the calendar on disk.
58 */ 58 */
59 bool load( const QString &fileName ); 59 bool load( const QString &fileName );
60 /** 60 /**
61 Writes out the calendar to disk in the specified \a format. 61 Writes out the calendar to disk in the specified \a format.
62 CalendarLocal takes ownership of the CalFormat object. 62 CalendarLocal takes ownership of the CalFormat object.
63 @return true, if successfull, false on error. 63 @return true, if successfull, false on error.
64 @param fileName the name of the file 64 @param fileName the name of the file
65 */ 65 */
66 bool save( const QString &fileName, CalFormat *format = 0 ); 66 bool save( const QString &fileName, CalFormat *format = 0 );
67 67
68 /** 68 /**
69 Clears out the current calendar, freeing all used memory etc. etc. 69 Clears out the current calendar, freeing all used memory etc. etc.
70 */ 70 */
71 void close(); 71 void close();
72 72
73 void save() {} 73 void save() {}
74 74
75 /** 75 /**
76 Add Event to calendar. 76 Add Event to calendar.
77 */ 77 */
78 void removeSyncInfo( QString syncProfile); 78 void removeSyncInfo( QString syncProfile);
79 bool addAnniversaryNoDup( Event *event ); 79 bool addAnniversaryNoDup( Event *event );
80 bool addEventNoDup( Event *event ); 80 bool addEventNoDup( Event *event );
81 bool addEvent( Event *event ); 81 bool addEvent( Event *event );
82 /** 82 /**
83 Deletes an event from this calendar. 83 Deletes an event from this calendar.
84 */ 84 */
85 void deleteEvent( Event *event ); 85 void deleteEvent( Event *event );
86 86
87 /** 87 /**
88 Retrieves an event on the basis of the unique string ID. 88 Retrieves an event on the basis of the unique string ID.
89 */ 89 */
90 Event *event( const QString &uid ); 90 Event *event( const QString &uid );
91 /** 91 /**
92 Return unfiltered list of all events in calendar. 92 Return unfiltered list of all events in calendar.
93 */ 93 */
94 QPtrList<Event> rawEvents(); 94 QPtrList<Event> rawEvents();
95 QPtrList<Event> getExternLastSyncEvents(); 95 QPtrList<Event> getExternLastSyncEvents();
96 /** 96 /**
97 Add a todo to the todolist. 97 Add a todo to the todolist.
98 */ 98 */
99 bool addTodo( Todo *todo ); 99 bool addTodo( Todo *todo );
100 bool addTodoNoDup( Todo *todo ); 100 bool addTodoNoDup( Todo *todo );
101 /** 101 /**
102 Remove a todo from the todolist. 102 Remove a todo from the todolist.
103 */ 103 */
104 void deleteTodo( Todo * ); 104 void deleteTodo( Todo * );
105 /** 105 /**
106 Searches todolist for an event with this unique string identifier, 106 Searches todolist for an event with this unique string identifier,
107 returns a pointer or null. 107 returns a pointer or null.
108 */ 108 */
109 Todo *todo( const QString &uid ); 109 Todo *todo( const QString &uid );
110 /** 110 /**
111 Return list of all todos. 111 Return list of all todos.
112 */ 112 */
113 QPtrList<Todo> rawTodos(); 113 QPtrList<Todo> rawTodos();
114 /** 114 /**
115 Returns list of todos due on the specified date. 115 Returns list of todos due on the specified date.
116 */ 116 */
117 QPtrList<Todo> todos( const QDate &date ); 117 QPtrList<Todo> todos( const QDate &date );
118 /** 118 /**
119 Return list of all todos. 119 Return list of all todos.
120 120
121 Workaround because compiler does not recognize function of base class. 121 Workaround because compiler does not recognize function of base class.
122 */ 122 */
123 QPtrList<Todo> todos() { return Calendar::todos(); } 123 QPtrList<Todo> todos() { return Calendar::todos(); }
124 124
125 /** 125 /**
126 Add a Journal entry to calendar. 126 Add a Journal entry to calendar.
127 */ 127 */
128 bool addJournal( Journal * ); 128 bool addJournal( Journal * );
129 /** 129 /**
130 Remove a Journal from the calendar. 130 Remove a Journal from the calendar.
131 */ 131 */
132 void deleteJournal( Journal * ); 132 void deleteJournal( Journal * );
133 /** 133 /**
134 Return Journal for given date. 134 Return Journal for given date.
135 */ 135 */
136 Journal *journal( const QDate & ); 136 Journal *journal( const QDate & );
137 QPtrList<Journal> journals4Date( const QDate & ); 137 QPtrList<Journal> journals4Date( const QDate & );
138 /** 138 /**
139 Return Journal with given UID. 139 Return Journal with given UID.
140 */ 140 */
141 Journal *journal( const QString &uid ); 141 Journal *journal( const QString &uid );
142 /** 142 /**
143 Return list of all Journals stored in calendar. 143 Return list of all Journals stored in calendar.
144 */ 144 */
145 QPtrList<Journal> journals(); 145 QPtrList<Journal> journals();
146 146
147 /** 147 /**
148 Return all alarms, which ocur in the given time interval. 148 Return all alarms, which ocur in the given time interval.
149 */ 149 */
150 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 150 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
151 151
152 /** 152 /**
153 Return all alarms, which ocur before given date. 153 Return all alarms, which ocur before given date.
154 */ 154 */
155 Alarm::List alarmsTo( const QDateTime &to ); 155 Alarm::List alarmsTo( const QDateTime &to );
156 156
157 QDateTime nextAlarm( int daysTo ) ; 157 QDateTime nextAlarm( int daysTo ) ;
158 QDateTime nextAlarmEventDateTime() const; 158 QDateTime nextAlarmEventDateTime() const;
159 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 159 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
160 void registerAlarm(); 160 void registerAlarm();
161 void deRegisterAlarm(); 161 void deRegisterAlarm();
162 QString getAlarmNotification(); 162 QString getAlarmNotification();
163 QString nextSummary() const ; 163 QString nextSummary() const ;
164 /** 164 /**
165 This method should be called whenever a Event is modified directly 165 This method should be called whenever a Event is modified directly
166 via it's pointer. It makes sure that the calendar is internally 166 via it's pointer. It makes sure that the calendar is internally
167 consistent. 167 consistent.
168 */ 168 */
169 void update( IncidenceBase *incidence ); 169 void update( IncidenceBase *incidence );
170 170
171 /** 171 /**
172 Builds and then returns a list of all events that match for the 172 Builds and then returns a list of all events that match for the
173 date specified. useful for dayView, etc. etc. 173 date specified. useful for dayView, etc. etc.
174 */ 174 */
175 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 175 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
176 /** 176 /**
177 Get unfiltered events for date \a qdt. 177 Get unfiltered events for date \a qdt.
178 */ 178 */
179 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 179 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
180 /** 180 /**
181 Get unfiltered events in a range of dates. If inclusive is set to true, 181 Get unfiltered events in a range of dates. If inclusive is set to true,
182 only events are returned, which are completely included in the range. 182 only events are returned, which are completely included in the range.
183 */ 183 */
184 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 184 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
185 bool inclusive = false ); 185 bool inclusive = false );
186 Todo *todo( QString, QString ); 186 Todo *todo( QString, QString );
187 Event *event( QString, QString ); 187 Event *event( QString, QString );
188 void getIncidenceCount( int calId, int& events, int & todos, int & journals);
188 189
189public slots: 190public slots:
190 void setCalendarEnabled( int id, bool enable ); 191 void setCalendarEnabled( int id, bool enable );
191 void setAlarmEnabled( int id, bool enable ); 192 void setAlarmEnabled( int id, bool enable );
192 void setReadOnly( int id, bool enable ); 193 void setReadOnly( int id, bool enable );
193 void setDefaultCalendarEnabledOnly(); 194 void setDefaultCalendarEnabledOnly();
194 void setCalendarRemove( int id ); 195 void setCalendarRemove( int id );
195 196
196 protected: 197 protected:
197 198
198 // Event* mNextAlarmEvent; 199 // Event* mNextAlarmEvent;
199 QString mNextSummary; 200 QString mNextSummary;
200 QString mNextAlarmEventDateTimeString; 201 QString mNextAlarmEventDateTimeString;
201 QString mLastAlarmNotificationString; 202 QString mLastAlarmNotificationString;
202 QDateTime mNextAlarmEventDateTime; 203 QDateTime mNextAlarmEventDateTime;
203 QDateTime mNextAlarmDateTime; 204 QDateTime mNextAlarmDateTime;
204 void reInitAlarmSettings(); 205 void reInitAlarmSettings();
205 206
206 /** Notification function of IncidenceBase::Observer. */ 207 /** Notification function of IncidenceBase::Observer. */
207 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 208 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
208 209
209 /** inserts an event into its "proper place" in the calendar. */ 210 /** inserts an event into its "proper place" in the calendar. */
210 void insertEvent( Event *event ); 211 void insertEvent( Event *event );
211 212
212 /** Append alarms of incidence in interval to list of alarms. */ 213 /** Append alarms of incidence in interval to list of alarms. */
213 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 214 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
214 const QDateTime &from, const QDateTime &to ); 215 const QDateTime &from, const QDateTime &to );
215 216
216 /** Append alarms of recurring events in interval to list of alarms. */ 217 /** Append alarms of recurring events in interval to list of alarms. */
217 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 218 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
218 const QDateTime &from, const QDateTime &to ); 219 const QDateTime &from, const QDateTime &to );
219 220
220 private: 221 private:
221 void init(); 222 void init();
222 223
223 QPtrList<Event> mEventList; 224 QPtrList<Event> mEventList;
224 QPtrList<Todo> mTodoList; 225 QPtrList<Todo> mTodoList;
225 QPtrList<Journal> mJournalList; 226 QPtrList<Journal> mJournalList;
226}; 227};
227 228
228} 229}
229 230
230#endif 231#endif