summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 8c4dde1..18f1af8 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,341 +1,347 @@
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 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 if ( mDeleteIncidencesOnClose ) 68 if ( mDeleteIncidencesOnClose )
69 close(); 69 close();
70} 70}
71bool CalendarLocal::addCalendarFile( QString name, int id ) 71bool CalendarLocal::addCalendarFile( QString name, int id )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( id ); 74 calendar.setDefaultCalendar( id );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 addCalendar( &calendar ); 76 addCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81void CalendarLocal::setSyncEventsReadOnly() 81void CalendarLocal::setSyncEventsReadOnly()
82{ 82{
83 Event * ev; 83 Event * ev;
84 ev = mEventList.first(); 84 ev = mEventList.first();
85 while ( ev ) { 85 while ( ev ) {
86 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 86 if ( ev->uid().left(15) == QString("last-syncEvent-") )
87 ev->setReadOnly( true ); 87 ev->setReadOnly( true );
88 ev = mEventList.next(); 88 ev = mEventList.next();
89 } 89 }
90} 90}
91void CalendarLocal::addCalendar( Calendar* cal ) 91void CalendarLocal::addCalendar( Calendar* cal )
92{ 92{
93 cal->setDontDeleteIncidencesOnClose(); 93 cal->setDontDeleteIncidencesOnClose();
94 { 94 {
95 QPtrList<Event> EventList = cal->rawEvents(); 95 QPtrList<Event> EventList = cal->rawEvents();
96 Event * ev = EventList.first(); 96 Event * ev = EventList.first();
97 while ( ev ) { 97 while ( ev ) {
98 ev->unRegisterObserver( cal ); 98 ev->unRegisterObserver( cal );
99 ev->registerObserver( this ); 99 ev->registerObserver( this );
100 mEventList.append( ev ); 100 mEventList.append( ev );
101 ev = EventList.next(); 101 ev = EventList.next();
102 } 102 }
103 } 103 }
104 { 104 {
105 105
106 QPtrList<Todo> TodoList = cal->rawTodos(); 106 QPtrList<Todo> TodoList = cal->rawTodos();
107 Todo * ev = TodoList.first(); 107 Todo * ev = TodoList.first();
108 while ( ev ) { 108 while ( ev ) {
109 QString rel = ev->relatedToUid(); 109 QString rel = ev->relatedToUid();
110 if ( !rel.isEmpty() ){ 110 if ( !rel.isEmpty() ){
111 ev->setRelatedTo ( 0 ); 111 ev->setRelatedTo ( 0 );
112 ev->setRelatedToUid( rel ); 112 ev->setRelatedToUid( rel );
113 } 113 }
114 ev = TodoList.next(); 114 ev = TodoList.next();
115 } 115 }
116 //TodoList = cal->rawTodos(); 116 //TodoList = cal->rawTodos();
117 ev = TodoList.first(); 117 ev = TodoList.first();
118 while ( ev ) { 118 while ( ev ) {
119 ev->unRegisterObserver( cal ); 119 ev->unRegisterObserver( cal );
120 ev->registerObserver( this ); 120 ev->registerObserver( this );
121 mTodoList.append( ev ); 121 mTodoList.append( ev );
122 setupRelations( ev ); 122 setupRelations( ev );
123 ev = TodoList.next(); 123 ev = TodoList.next();
124 } 124 }
125 } 125 }
126 { 126 {
127 QPtrList<Journal> JournalList = cal->journals(); 127 QPtrList<Journal> JournalList = cal->journals();
128 Journal * ev = JournalList.first(); 128 Journal * ev = JournalList.first();
129 while ( ev ) { 129 while ( ev ) {
130 ev->unRegisterObserver( cal ); 130 ev->unRegisterObserver( cal );
131 ev->registerObserver( this ); 131 ev->registerObserver( this );
132 mJournalList.append( ev ); 132 mJournalList.append( ev );
133 ev = JournalList.next(); 133 ev = JournalList.next();
134 } 134 }
135 } 135 }
136 setModified( true ); 136 setModified( true );
137} 137}
138bool CalendarLocal::load( const QString &fileName ) 138bool CalendarLocal::load( const QString &fileName )
139{ 139{
140 FileStorage storage( this, fileName ); 140 FileStorage storage( this, fileName );
141 return storage.load(); 141 return storage.load();
142} 142}
143 143
144bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 144bool CalendarLocal::save( const QString &fileName, CalFormat *format )
145{ 145{
146 FileStorage storage( this, fileName, format ); 146 FileStorage storage( this, fileName, format );
147 return storage.save(); 147 return storage.save();
148} 148}
149 149
150void CalendarLocal::stopAllTodos()
151{
152 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
153 it->setRunning( false );
154
155}
150void CalendarLocal::close() 156void CalendarLocal::close()
151{ 157{
152 158
153 Todo * i; 159 Todo * i;
154 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 160 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
155 161
156 mEventList.setAutoDelete( true ); 162 mEventList.setAutoDelete( true );
157 mTodoList.setAutoDelete( true ); 163 mTodoList.setAutoDelete( true );
158 mJournalList.setAutoDelete( false ); 164 mJournalList.setAutoDelete( false );
159 165
160 mEventList.clear(); 166 mEventList.clear();
161 mTodoList.clear(); 167 mTodoList.clear();
162 mJournalList.clear(); 168 mJournalList.clear();
163 169
164 mEventList.setAutoDelete( false ); 170 mEventList.setAutoDelete( false );
165 mTodoList.setAutoDelete( false ); 171 mTodoList.setAutoDelete( false );
166 mJournalList.setAutoDelete( false ); 172 mJournalList.setAutoDelete( false );
167 173
168 setModified( false ); 174 setModified( false );
169} 175}
170 176
171bool CalendarLocal::addAnniversaryNoDup( Event *event ) 177bool CalendarLocal::addAnniversaryNoDup( Event *event )
172{ 178{
173 QString cat; 179 QString cat;
174 bool isBirthday = true; 180 bool isBirthday = true;
175 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 181 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
176 isBirthday = false; 182 isBirthday = false;
177 cat = i18n( "Anniversary" ); 183 cat = i18n( "Anniversary" );
178 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
179 isBirthday = true; 185 isBirthday = true;
180 cat = i18n( "Birthday" ); 186 cat = i18n( "Birthday" );
181 } else { 187 } else {
182 qDebug("addAnniversaryNoDup called without fitting category! "); 188 qDebug("addAnniversaryNoDup called without fitting category! ");
183 return false; 189 return false;
184 } 190 }
185 Event * eve; 191 Event * eve;
186 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
187 if ( !(eve->categories().contains( cat ) )) 193 if ( !(eve->categories().contains( cat ) ))
188 continue; 194 continue;
189 // now we have an event with fitting category 195 // now we have an event with fitting category
190 if ( eve->dtStart().date() != event->dtStart().date() ) 196 if ( eve->dtStart().date() != event->dtStart().date() )
191 continue; 197 continue;
192 // now we have an event with fitting category+date 198 // now we have an event with fitting category+date
193 if ( eve->summary() != event->summary() ) 199 if ( eve->summary() != event->summary() )
194 continue; 200 continue;
195 // now we have an event with fitting category+date+summary 201 // now we have an event with fitting category+date+summary
196 return false; 202 return false;
197 } 203 }
198 return addEvent( event ); 204 return addEvent( event );
199 205
200} 206}
201bool CalendarLocal::addEventNoDup( Event *event ) 207bool CalendarLocal::addEventNoDup( Event *event )
202{ 208{
203 Event * eve; 209 Event * eve;
204 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
205 if ( *eve == *event ) { 211 if ( *eve == *event ) {
206 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
207 return false; 213 return false;
208 } 214 }
209 } 215 }
210 return addEvent( event ); 216 return addEvent( event );
211} 217}
212 218
213bool CalendarLocal::addEvent( Event *event ) 219bool CalendarLocal::addEvent( Event *event )
214{ 220{
215 insertEvent( event ); 221 insertEvent( event );
216 222
217 event->registerObserver( this ); 223 event->registerObserver( this );
218 224
219 setModified( true ); 225 setModified( true );
220 event->setCalID( mDefaultCalendar ); 226 event->setCalID( mDefaultCalendar );
221 event->setCalEnabled( true ); 227 event->setCalEnabled( true );
222 228
223 return true; 229 return true;
224} 230}
225 231
226void CalendarLocal::deleteEvent( Event *event ) 232void CalendarLocal::deleteEvent( Event *event )
227{ 233{
228 if ( mUndoIncidence ) delete mUndoIncidence; 234 if ( mUndoIncidence ) delete mUndoIncidence;
229 mUndoIncidence = event->clone(); 235 mUndoIncidence = event->clone();
230 if ( mEventList.removeRef( event ) ) { 236 if ( mEventList.removeRef( event ) ) {
231 setModified( true ); 237 setModified( true );
232 } 238 }
233} 239}
234 240
235 241
236Event *CalendarLocal::event( const QString &uid ) 242Event *CalendarLocal::event( const QString &uid )
237{ 243{
238 Event *event; 244 Event *event;
239 Event *retVal = 0; 245 Event *retVal = 0;
240 for ( event = mEventList.first(); event; event = mEventList.next() ) { 246 for ( event = mEventList.first(); event; event = mEventList.next() ) {
241 if ( event->calEnabled() && event->uid() == uid ) { 247 if ( event->calEnabled() && event->uid() == uid ) {
242 if ( retVal ) { 248 if ( retVal ) {
243 if ( retVal->calID() > event->calID() ) { 249 if ( retVal->calID() > event->calID() ) {
244 retVal = event; 250 retVal = event;
245 } 251 }
246 } else { 252 } else {
247 retVal = event; 253 retVal = event;
248 } 254 }
249 } 255 }
250 } 256 }
251 return retVal; 257 return retVal;
252} 258}
253bool CalendarLocal::addTodoNoDup( Todo *todo ) 259bool CalendarLocal::addTodoNoDup( Todo *todo )
254{ 260{
255 Todo * eve; 261 Todo * eve;
256 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 262 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
257 if ( *eve == *todo ) { 263 if ( *eve == *todo ) {
258 //qDebug("duplicate todo found! not inserted! "); 264 //qDebug("duplicate todo found! not inserted! ");
259 return false; 265 return false;
260 } 266 }
261 } 267 }
262 return addTodo( todo ); 268 return addTodo( todo );
263} 269}
264bool CalendarLocal::addTodo( Todo *todo ) 270bool CalendarLocal::addTodo( Todo *todo )
265{ 271{
266 mTodoList.append( todo ); 272 mTodoList.append( todo );
267 273
268 todo->registerObserver( this ); 274 todo->registerObserver( this );
269 275
270 // Set up subtask relations 276 // Set up subtask relations
271 setupRelations( todo ); 277 setupRelations( todo );
272 278
273 setModified( true ); 279 setModified( true );
274 todo->setCalID( mDefaultCalendar ); 280 todo->setCalID( mDefaultCalendar );
275 todo->setCalEnabled( true ); 281 todo->setCalEnabled( true );
276 return true; 282 return true;
277} 283}
278 284
279void CalendarLocal::deleteTodo( Todo *todo ) 285void CalendarLocal::deleteTodo( Todo *todo )
280{ 286{
281 // Handle orphaned children 287 // Handle orphaned children
282 if ( mUndoIncidence ) delete mUndoIncidence; 288 if ( mUndoIncidence ) delete mUndoIncidence;
283 removeRelations( todo ); 289 removeRelations( todo );
284 mUndoIncidence = todo->clone(); 290 mUndoIncidence = todo->clone();
285 291
286 if ( mTodoList.removeRef( todo ) ) { 292 if ( mTodoList.removeRef( todo ) ) {
287 setModified( true ); 293 setModified( true );
288 } 294 }
289} 295}
290 296
291QPtrList<Todo> CalendarLocal::rawTodos() 297QPtrList<Todo> CalendarLocal::rawTodos()
292{ 298{
293 QPtrList<Todo> el; 299 QPtrList<Todo> el;
294 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 300 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
295 if ( it->calEnabled() ) el.append( it ); 301 if ( it->calEnabled() ) el.append( it );
296 return el; 302 return el;
297} 303}
298Todo *CalendarLocal::todo( QString syncProf, QString id ) 304Todo *CalendarLocal::todo( QString syncProf, QString id )
299{ 305{
300 Todo *todo; 306 Todo *todo;
301 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 307 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
302 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 308 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
303 } 309 }
304 310
305 return 0; 311 return 0;
306} 312}
307void CalendarLocal::removeSyncInfo( QString syncProfile) 313void CalendarLocal::removeSyncInfo( QString syncProfile)
308{ 314{
309 QPtrList<Incidence> all = rawIncidences() ; 315 QPtrList<Incidence> all = rawIncidences() ;
310 Incidence *inc; 316 Incidence *inc;
311 for ( inc = all.first(); inc; inc = all.next() ) { 317 for ( inc = all.first(); inc; inc = all.next() ) {
312 inc->removeID( syncProfile ); 318 inc->removeID( syncProfile );
313 } 319 }
314 if ( syncProfile.isEmpty() ) { 320 if ( syncProfile.isEmpty() ) {
315 QPtrList<Event> el; 321 QPtrList<Event> el;
316 Event *todo; 322 Event *todo;
317 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 323 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
318 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 324 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
319 el.append( todo ); 325 el.append( todo );
320 } 326 }
321 for ( todo = el.first(); todo; todo = el.next() ) { 327 for ( todo = el.first(); todo; todo = el.next() ) {
322 deleteIncidence ( todo ); 328 deleteIncidence ( todo );
323 } 329 }
324 } else { 330 } else {
325 Event *lse = event( "last-syncEvent-"+ syncProfile); 331 Event *lse = event( "last-syncEvent-"+ syncProfile);
326 if ( lse ) 332 if ( lse )
327 deleteIncidence ( lse ); 333 deleteIncidence ( lse );
328 } 334 }
329} 335}
330QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 336QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
331{ 337{
332 QPtrList<Event> el; 338 QPtrList<Event> el;
333 Event *todo; 339 Event *todo;
334 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 340 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
335 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 341 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
336 if ( todo->summary().left(3) == "E: " ) 342 if ( todo->summary().left(3) == "E: " )
337 el.append( todo ); 343 el.append( todo );
338 } 344 }
339 345
340 return el; 346 return el;
341 347