summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
Unidiff
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index a662eeb..b7990d4 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -107,382 +107,383 @@ void Calendar::init()
107// KOPrefs::instance()->writeConfig(); 107// KOPrefs::instance()->writeConfig();
108} 108}
109 109
110Calendar::~Calendar() 110Calendar::~Calendar()
111{ 111{
112 delete mDefaultFilter; 112 delete mDefaultFilter;
113 if ( mUndoIncidence ) 113 if ( mUndoIncidence )
114 delete mUndoIncidence; 114 delete mUndoIncidence;
115} 115}
116void Calendar::setDontDeleteIncidencesOnClose () 116void Calendar::setDontDeleteIncidencesOnClose ()
117{ 117{
118 mDeleteIncidencesOnClose = false; 118 mDeleteIncidencesOnClose = false;
119} 119}
120void Calendar::setDefaultCalendar( int d ) 120void Calendar::setDefaultCalendar( int d )
121{ 121{
122 mDefaultCalendar = d; 122 mDefaultCalendar = d;
123} 123}
124int Calendar::defaultCalendar() 124int Calendar::defaultCalendar()
125{ 125{
126 return mDefaultCalendar; 126 return mDefaultCalendar;
127} 127}
128const QString &Calendar::getOwner() const 128const QString &Calendar::getOwner() const
129{ 129{
130 return mOwner; 130 return mOwner;
131} 131}
132 132
133bool Calendar::undoDeleteIncidence() 133bool Calendar::undoDeleteIncidence()
134{ 134{
135 if (!mUndoIncidence) 135 if (!mUndoIncidence)
136 return false; 136 return false;
137 addIncidence(mUndoIncidence); 137 addIncidence(mUndoIncidence);
138 mUndoIncidence = 0; 138 mUndoIncidence = 0;
139 return true; 139 return true;
140} 140}
141void Calendar::setOwner(const QString &os) 141void Calendar::setOwner(const QString &os)
142{ 142{
143 int i; 143 int i;
144 mOwner = os; 144 mOwner = os;
145 i = mOwner.find(','); 145 i = mOwner.find(',');
146 if (i != -1) 146 if (i != -1)
147 mOwner = mOwner.left(i); 147 mOwner = mOwner.left(i);
148 148
149 setModified( true ); 149 setModified( true );
150} 150}
151 151
152void Calendar::setTimeZone(const QString & tz) 152void Calendar::setTimeZone(const QString & tz)
153{ 153{
154 bool neg = FALSE; 154 bool neg = FALSE;
155 int hours, minutes; 155 int hours, minutes;
156 QString tmpStr(tz); 156 QString tmpStr(tz);
157 157
158 if (tmpStr.left(1) == "-") 158 if (tmpStr.left(1) == "-")
159 neg = TRUE; 159 neg = TRUE;
160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
161 tmpStr.remove(0, 1); 161 tmpStr.remove(0, 1);
162 hours = tmpStr.left(2).toInt(); 162 hours = tmpStr.left(2).toInt();
163 if (tmpStr.length() > 2) 163 if (tmpStr.length() > 2)
164 minutes = tmpStr.right(2).toInt(); 164 minutes = tmpStr.right(2).toInt();
165 else 165 else
166 minutes = 0; 166 minutes = 0;
167 mTimeZone = (60*hours+minutes); 167 mTimeZone = (60*hours+minutes);
168 if (neg) 168 if (neg)
169 mTimeZone = -mTimeZone; 169 mTimeZone = -mTimeZone;
170 mLocalTime = false; 170 mLocalTime = false;
171 171
172 setModified( true ); 172 setModified( true );
173} 173}
174 174
175QString Calendar::getTimeZoneStr() const 175QString Calendar::getTimeZoneStr() const
176{ 176{
177 if (mLocalTime) 177 if (mLocalTime)
178 return ""; 178 return "";
179 QString tmpStr; 179 QString tmpStr;
180 int hours = abs(mTimeZone / 60); 180 int hours = abs(mTimeZone / 60);
181 int minutes = abs(mTimeZone % 60); 181 int minutes = abs(mTimeZone % 60);
182 bool neg = mTimeZone < 0; 182 bool neg = mTimeZone < 0;
183 183
184 tmpStr.sprintf("%c%.2d%.2d", 184 tmpStr.sprintf("%c%.2d%.2d",
185 (neg ? '-' : '+'), 185 (neg ? '-' : '+'),
186 hours, minutes); 186 hours, minutes);
187 return tmpStr; 187 return tmpStr;
188} 188}
189 189
190void Calendar::setTimeZone(int tz) 190void Calendar::setTimeZone(int tz)
191{ 191{
192 mTimeZone = tz; 192 mTimeZone = tz;
193 mLocalTime = false; 193 mLocalTime = false;
194 194
195 setModified( true ); 195 setModified( true );
196} 196}
197 197
198int Calendar::getTimeZone() const 198int Calendar::getTimeZone() const
199{ 199{
200 return mTimeZone; 200 return mTimeZone;
201} 201}
202 202
203void Calendar::setTimeZoneId(const QString &id) 203void Calendar::setTimeZoneId(const QString &id)
204{ 204{
205 mTimeZoneId = id; 205 mTimeZoneId = id;
206 mLocalTime = false; 206 mLocalTime = false;
207 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 207 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
208 if ( mTimeZone > 1000) 208 if ( mTimeZone > 1000)
209 setLocalTime(); 209 setLocalTime();
210 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 210 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
211 setModified( true ); 211 setModified( true );
212} 212}
213 213
214QString Calendar::timeZoneId() const 214QString Calendar::timeZoneId() const
215{ 215{
216 return mTimeZoneId; 216 return mTimeZoneId;
217} 217}
218 218
219void Calendar::setLocalTime() 219void Calendar::setLocalTime()
220{ 220{
221 //qDebug("Calendar::setLocalTime() "); 221 //qDebug("Calendar::setLocalTime() ");
222 mLocalTime = true; 222 mLocalTime = true;
223 mTimeZone = 0; 223 mTimeZone = 0;
224 mTimeZoneId = ""; 224 mTimeZoneId = "";
225 225
226 setModified( true ); 226 setModified( true );
227} 227}
228 228
229bool Calendar::isLocalTime() const 229bool Calendar::isLocalTime() const
230{ 230{
231 return mLocalTime; 231 return mLocalTime;
232} 232}
233 233
234const QString &Calendar::getEmail() 234const QString &Calendar::getEmail()
235{ 235{
236 return mOwnerEmail; 236 return mOwnerEmail;
237} 237}
238 238
239void Calendar::setEmail(const QString &e) 239void Calendar::setEmail(const QString &e)
240{ 240{
241 mOwnerEmail = e; 241 mOwnerEmail = e;
242 242
243 setModified( true ); 243 setModified( true );
244} 244}
245 245
246void Calendar::setFilter(CalFilter *filter) 246void Calendar::setFilter(CalFilter *filter)
247{ 247{
248 mFilter = filter; 248 mFilter = filter;
249} 249}
250 250
251CalFilter *Calendar::filter() 251CalFilter *Calendar::filter()
252{ 252{
253 return mFilter; 253 return mFilter;
254} 254}
255 255
256QPtrList<Incidence> Calendar::incidences() 256QPtrList<Incidence> Calendar::incidences()
257{ 257{
258 QPtrList<Incidence> incidences; 258 QPtrList<Incidence> incidences;
259 259
260 Incidence *i; 260 Incidence *i;
261 261
262 QPtrList<Event> e = events(); 262 QPtrList<Event> e = events();
263 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 263 for( i = e.first(); i; i = e.next() ) incidences.append( i );
264 264
265 QPtrList<Todo> t = todos(); 265 QPtrList<Todo> t = todos();
266 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 266 for( i = t.first(); i; i = t.next() ) incidences.append( i );
267 267
268 QPtrList<Journal> j = journals(); 268 QPtrList<Journal> j = journals();
269 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 269 for( i = j.first(); i; i = j.next() ) incidences.append( i );
270 270
271 return incidences; 271 return incidences;
272} 272}
273 273
274void Calendar::resetPilotStat(int id ) 274void Calendar::resetPilotStat(int id )
275{ 275{
276 QPtrList<Incidence> incidences; 276 QPtrList<Incidence> incidences;
277 277
278 Incidence *i; 278 Incidence *i;
279 279
280 QPtrList<Event> e = rawEvents(); 280 QPtrList<Event> e = rawEvents();
281 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 281 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
282 282
283 QPtrList<Todo> t = rawTodos(); 283 QPtrList<Todo> t = rawTodos();
284 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 284 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
285 285
286 QPtrList<Journal> j = journals(); 286 QPtrList<Journal> j = journals();
287 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 287 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
288} 288}
289void Calendar::resetTempSyncStat() 289void Calendar::resetTempSyncStat()
290{ 290{
291 QPtrList<Incidence> incidences; 291 QPtrList<Incidence> incidences;
292 292
293 Incidence *i; 293 Incidence *i;
294 294
295 QPtrList<Event> e = rawEvents(); 295 QPtrList<Event> e = rawEvents();
296 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 296 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
297 297
298 QPtrList<Todo> t = rawTodos(); 298 QPtrList<Todo> t = rawTodos();
299 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 299 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
300 300
301 QPtrList<Journal> j = journals(); 301 QPtrList<Journal> j = journals();
302 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 302 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
303} 303}
304QPtrList<Incidence> Calendar::rawIncidences() 304QPtrList<Incidence> Calendar::rawIncidences()
305{ 305{
306 QPtrList<Incidence> incidences; 306 QPtrList<Incidence> incidences;
307 307
308 Incidence *i; 308 Incidence *i;
309 309
310 QPtrList<Event> e = rawEvents(); 310 QPtrList<Event> e = rawEvents();
311 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 311 for( i = e.first(); i; i = e.next() ) incidences.append( i );
312 312
313 QPtrList<Todo> t = rawTodos(); 313 QPtrList<Todo> t = rawTodos();
314 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 314 for( i = t.first(); i; i = t.next() ) incidences.append( i );
315 315
316 QPtrList<Journal> j = journals(); 316 QPtrList<Journal> j = journals();
317 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 317 for( i = j.first(); i; i = j.next() ) incidences.append( i );
318 318
319 return incidences; 319 return incidences;
320} 320}
321 321
322QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 322QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
323{ 323{
324 QPtrList<Event> el = rawEventsForDate(date,sorted); 324 QPtrList<Event> el = rawEventsForDate(date,sorted);
325 mFilter->apply(&el); 325 mFilter->apply(&el);
326 return el; 326 return el;
327} 327}
328 328
329QPtrList<Event> Calendar::events( const QDateTime &qdt ) 329QPtrList<Event> Calendar::events( const QDateTime &qdt )
330{ 330{
331 QPtrList<Event> el = rawEventsForDate(qdt); 331 QPtrList<Event> el = rawEventsForDate(qdt);
332 mFilter->apply(&el); 332 mFilter->apply(&el);
333 return el; 333 return el;
334} 334}
335 335
336QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 336QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
337 bool inclusive) 337 bool inclusive)
338{ 338{
339 QPtrList<Event> el = rawEvents(start,end,inclusive); 339 QPtrList<Event> el = rawEvents(start,end,inclusive);
340 mFilter->apply(&el); 340 mFilter->apply(&el);
341 return el; 341 return el;
342} 342}
343 343
344QPtrList<Event> Calendar::events() 344QPtrList<Event> Calendar::events()
345{ 345{
346 QPtrList<Event> el = rawEvents(); 346 QPtrList<Event> el = rawEvents();
347 mFilter->apply(&el); 347 mFilter->apply(&el);
348 return el; 348 return el;
349} 349}
350void Calendar::addIncidenceBranch(Incidence *i) 350void Calendar::addIncidenceBranch(Incidence *i)
351{ 351{
352 addIncidence( i ); 352 addIncidence( i );
353 Incidence * inc; 353 Incidence * inc;
354 QPtrList<Incidence> Relations = i->relations(); 354 QPtrList<Incidence> Relations = i->relations();
355 for (inc=Relations.first();inc;inc=Relations.next()) { 355 for (inc=Relations.first();inc;inc=Relations.next()) {
356 addIncidenceBranch( inc ); 356 addIncidenceBranch( inc );
357 } 357 }
358} 358}
359 359
360bool Calendar::addIncidence(Incidence *i) 360bool Calendar::addIncidence(Incidence *i)
361{ 361{
362 Incidence::AddVisitor<Calendar> v(this); 362 Incidence::AddVisitor<Calendar> v(this);
363 i->setCalID( mDefaultCalendar ); 363 if ( i->calID() == 0 )
364 i->setCalID( mDefaultCalendar );
364 i->setCalEnabled( true ); 365 i->setCalEnabled( true );
365 return i->accept(v); 366 return i->accept(v);
366} 367}
367void Calendar::deleteIncidence(Incidence *in) 368void Calendar::deleteIncidence(Incidence *in)
368{ 369{
369 if ( in->typeID() == eventID ) 370 if ( in->typeID() == eventID )
370 deleteEvent( (Event*) in ); 371 deleteEvent( (Event*) in );
371 else if ( in->typeID() == todoID ) 372 else if ( in->typeID() == todoID )
372 deleteTodo( (Todo*) in); 373 deleteTodo( (Todo*) in);
373 else if ( in->typeID() == journalID ) 374 else if ( in->typeID() == journalID )
374 deleteJournal( (Journal*) in ); 375 deleteJournal( (Journal*) in );
375} 376}
376 377
377Incidence* Calendar::incidence( const QString& uid ) 378Incidence* Calendar::incidence( const QString& uid )
378{ 379{
379 Incidence* i; 380 Incidence* i;
380 381
381 if( (i = todo( uid )) != 0 ) 382 if( (i = todo( uid )) != 0 )
382 return i; 383 return i;
383 if( (i = event( uid )) != 0 ) 384 if( (i = event( uid )) != 0 )
384 return i; 385 return i;
385 if( (i = journal( uid )) != 0 ) 386 if( (i = journal( uid )) != 0 )
386 return i; 387 return i;
387 388
388 return 0; 389 return 0;
389} 390}
390 391
391QPtrList<Todo> Calendar::todos() 392QPtrList<Todo> Calendar::todos()
392{ 393{
393 QPtrList<Todo> tl = rawTodos(); 394 QPtrList<Todo> tl = rawTodos();
394 mFilter->apply( &tl ); 395 mFilter->apply( &tl );
395 return tl; 396 return tl;
396} 397}
397 398
398// When this is called, the todo have already been added to the calendar. 399// When this is called, the todo have already been added to the calendar.
399// This method is only about linking related todos 400// This method is only about linking related todos
400void Calendar::setupRelations( Incidence *incidence ) 401void Calendar::setupRelations( Incidence *incidence )
401{ 402{
402 QString uid = incidence->uid(); 403 QString uid = incidence->uid();
403 //qDebug("Calendar::setupRelations "); 404 //qDebug("Calendar::setupRelations ");
404 // First, go over the list of orphans and see if this is their parent 405 // First, go over the list of orphans and see if this is their parent
405 while( Incidence* i = mOrphans[ uid ] ) { 406 while( Incidence* i = mOrphans[ uid ] ) {
406 mOrphans.remove( uid ); 407 mOrphans.remove( uid );
407 i->setRelatedTo( incidence ); 408 i->setRelatedTo( incidence );
408 incidence->addRelation( i ); 409 incidence->addRelation( i );
409 mOrphanUids.remove( i->uid() ); 410 mOrphanUids.remove( i->uid() );
410 } 411 }
411 412
412 // Now see about this incidences parent 413 // Now see about this incidences parent
413 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 414 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
414 // This incidence has a uid it is related to, but is not registered to it yet 415 // This incidence has a uid it is related to, but is not registered to it yet
415 // Try to find it 416 // Try to find it
416 Incidence* parent = this->incidence( incidence->relatedToUid() ); 417 Incidence* parent = this->incidence( incidence->relatedToUid() );
417 if( parent ) { 418 if( parent ) {
418 // Found it 419 // Found it
419 incidence->setRelatedTo( parent ); 420 incidence->setRelatedTo( parent );
420 parent->addRelation( incidence ); 421 parent->addRelation( incidence );
421 } else { 422 } else {
422 // Not found, put this in the mOrphans list 423 // Not found, put this in the mOrphans list
423 mOrphans.insert( incidence->relatedToUid(), incidence ); 424 mOrphans.insert( incidence->relatedToUid(), incidence );
424 mOrphanUids.insert( incidence->uid(), incidence ); 425 mOrphanUids.insert( incidence->uid(), incidence );
425 } 426 }
426 } 427 }
427} 428}
428 429
429// If a task with subtasks is deleted, move it's subtasks to the orphans list 430// If a task with subtasks is deleted, move it's subtasks to the orphans list
430void Calendar::removeRelations( Incidence *incidence ) 431void Calendar::removeRelations( Incidence *incidence )
431{ 432{
432 // qDebug("Calendar::removeRelations "); 433 // qDebug("Calendar::removeRelations ");
433 QString uid = incidence->uid(); 434 QString uid = incidence->uid();
434 435
435 QPtrList<Incidence> relations = incidence->relations(); 436 QPtrList<Incidence> relations = incidence->relations();
436 for( Incidence* i = relations.first(); i; i = relations.next() ) 437 for( Incidence* i = relations.first(); i; i = relations.next() )
437 if( !mOrphanUids.find( i->uid() ) ) { 438 if( !mOrphanUids.find( i->uid() ) ) {
438 mOrphans.insert( uid, i ); 439 mOrphans.insert( uid, i );
439 mOrphanUids.insert( i->uid(), i ); 440 mOrphanUids.insert( i->uid(), i );
440 i->setRelatedTo( 0 ); 441 i->setRelatedTo( 0 );
441 i->setRelatedToUid( uid ); 442 i->setRelatedToUid( uid );
442 } 443 }
443 444
444 // If this incidence is related to something else, tell that about it 445 // If this incidence is related to something else, tell that about it
445 if( incidence->relatedTo() ) 446 if( incidence->relatedTo() )
446 incidence->relatedTo()->removeRelation( incidence ); 447 incidence->relatedTo()->removeRelation( incidence );
447 448
448 // Remove this one from the orphans list 449 // Remove this one from the orphans list
449 if( mOrphanUids.remove( uid ) ) 450 if( mOrphanUids.remove( uid ) )
450 // This incidence is located in the orphans list - it should be removed 451 // This incidence is located in the orphans list - it should be removed
451 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 452 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
452 // Removing wasn't that easy 453 // Removing wasn't that easy
453 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 454 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
454 if( it.current()->uid() == uid ) { 455 if( it.current()->uid() == uid ) {
455 mOrphans.remove( it.currentKey() ); 456 mOrphans.remove( it.currentKey() );
456 break; 457 break;
457 } 458 }
458 } 459 }
459 } 460 }
460} 461}
461 462
462void Calendar::registerObserver( Observer *observer ) 463void Calendar::registerObserver( Observer *observer )
463{ 464{
464 mObserver = observer; 465 mObserver = observer;
465 mNewObserver = true; 466 mNewObserver = true;
466} 467}
467 468
468void Calendar::setModified( bool modified ) 469void Calendar::setModified( bool modified )
469{ 470{
470 if ( mObserver ) mObserver->calendarModified( modified, this ); 471 if ( mObserver ) mObserver->calendarModified( modified, this );
471 if ( modified != mModified || mNewObserver ) { 472 if ( modified != mModified || mNewObserver ) {
472 mNewObserver = false; 473 mNewObserver = false;
473 // if ( mObserver ) mObserver->calendarModified( modified, this ); 474 // if ( mObserver ) mObserver->calendarModified( modified, this );
474 mModified = modified; 475 mModified = modified;
475 } 476 }
476} 477}
477 478
478void Calendar::setLoadedProductId( const QString &id ) 479void Calendar::setLoadedProductId( const QString &id )
479{ 480{
480 mLoadedProductId = id; 481 mLoadedProductId = id;
481} 482}
482 483
483QString Calendar::loadedProductId() 484QString Calendar::loadedProductId()
484{ 485{
485 return mLoadedProductId; 486 return mLoadedProductId;
486} 487}
487 488
488//#include "calendar.moc" 489//#include "calendar.moc"