• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 API Reference
  • KDE Home
  • Contact Us
 

KCal Library

  • kcal
resourcecached.cpp
1 /*
2  This file is part of the kcal library.
3 
4  Copyright © 2006 by David Jarvie <software@astrojar.org.uk>
5  Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
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
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "resourcecached.h"
24 #include "calendarlocal.h"
25 #include "event.h"
26 #include "exceptions.h"
27 #include "incidence.h"
28 #include "journal.h"
29 #include "todo.h"
30 
31 #include "kresources/idmapper.h"
32 
33 #include <kconfiggroup.h>
34 #include <kdebug.h>
35 #include <klocale.h>
36 #include <kstandarddirs.h>
37 #include <kurl.h>
38 
39 #include <QtCore/QDateTime>
40 #include <QtCore/QDataStream>
41 #include <QtCore/QFile>
42 #include <QtCore/QString>
43 #include <QtCore/QTimer>
44 
45 #include "resourcecached.moc"
46 
47 using namespace KCal;
48 
49 //@cond PRIVATE
50 class ResourceCached::Private
51 {
52  public:
53  Private()
54  : mCalendar( QLatin1String( "UTC" ) ),
55  mReloadPolicy( ResourceCached::ReloadNever ),
56  mReloadInterval( 10 ),
57  mInhibitReload( false ),
58  mReloaded( false ),
59  mSavePending( false ),
60  mSavePolicy( ResourceCached::SaveNever ),
61  mSaveInterval( 10 ),
62  mIdMapper( "kcal/uidmaps/" )
63  {}
64 
65  CalendarLocal mCalendar;
66 
67  int mReloadPolicy;
68  int mReloadInterval;
69  QTimer mReloadTimer;
70  bool mInhibitReload; // true to prevent downloads by load(DefaultCache)
71  bool mReloaded; // true once it has been downloaded
72  bool mSavePending; // true if a save of changes has been scheduled on the timer
73 
74  int mSavePolicy;
75  int mSaveInterval;
76  QTimer mSaveTimer;
77 
78  KDateTime mLastLoad;
79  KDateTime mLastSave;
80 
81  QMap<KCal::Incidence *,bool> mAddedIncidences;
82  QMap<KCal::Incidence *,bool> mChangedIncidences;
83  QMap<KCal::Incidence *,bool> mDeletedIncidences;
84 
85  KRES::IdMapper mIdMapper;
86 };
87 //@endcond
88 
89 ResourceCached::ResourceCached()
90  : ResourceCalendar(),
91  d( new Private )
92 {
93  connect( &d->mReloadTimer, SIGNAL(timeout()), SLOT(slotReload()) );
94  connect( &d->mSaveTimer, SIGNAL(timeout()), SLOT(slotSave()) );
95 }
96 
97 ResourceCached::ResourceCached( const KConfigGroup &group )
98  : ResourceCalendar( group ),
99  d( new Private )
100 {
101  connect( &d->mReloadTimer, SIGNAL(timeout()), SLOT(slotReload()) );
102  connect( &d->mSaveTimer, SIGNAL(timeout()), SLOT(slotSave()) );
103 }
104 
105 ResourceCached::~ResourceCached()
106 {
107  delete d;
108 }
109 
110 CalendarLocal *ResourceCached::calendar() const
111 {
112  return &d->mCalendar;
113 }
114 
115 bool ResourceCached::defaultReloadInhibited() const
116 {
117  return d->mInhibitReload;
118 }
119 
120 bool ResourceCached::reloaded() const
121 {
122  return d->mReloaded;
123 }
124 
125 void ResourceCached::setReloaded( bool done )
126 {
127  d->mReloaded = done;
128 }
129 
130 void ResourceCached::setReloadPolicy( int i )
131 {
132  d->mReloadPolicy = i;
133 
134  setupReloadTimer();
135 }
136 
137 int ResourceCached::reloadPolicy() const
138 {
139  return d->mReloadPolicy;
140 }
141 
142 void ResourceCached::setReloadInterval( int minutes )
143 {
144  d->mReloadInterval = minutes;
145 }
146 
147 int ResourceCached::reloadInterval() const
148 {
149  return d->mReloadInterval;
150 }
151 
152 bool ResourceCached::inhibitDefaultReload( bool inhibit )
153 {
154  if ( inhibit == d->mInhibitReload ) {
155  return false;
156  }
157  d->mInhibitReload = inhibit;
158  return true;
159 }
160 
161 void ResourceCached::setSavePolicy( int i )
162 {
163  d->mSavePolicy = i;
164 
165  setupSaveTimer();
166 }
167 
168 int ResourceCached::savePolicy() const
169 {
170  return d->mSavePolicy;
171 }
172 
173 void ResourceCached::setSaveInterval( int minutes )
174 {
175  d->mSaveInterval = minutes;
176 }
177 
178 int ResourceCached::saveInterval() const
179 {
180  return d->mSaveInterval;
181 }
182 
183 void ResourceCached::readConfig( const KConfigGroup &group )
184 {
185  d->mReloadPolicy = group.readEntry( "ReloadPolicy", int(ReloadNever) );
186  d->mReloadInterval = group.readEntry( "ReloadInterval", 10 );
187 
188  d->mSaveInterval = group.readEntry( "SaveInterval", 10 );
189  d->mSavePolicy = group.readEntry( "SavePolicy", int(SaveNever) );
190 
191  QDateTime curDt = QDateTime::currentDateTime();
192  QDateTime dt = group.readEntry( "LastLoad", curDt );
193  d->mLastLoad = KDateTime( dt, KDateTime::UTC );
194  dt = group.readEntry( "LastSave", curDt );
195  d->mLastSave = KDateTime( dt, KDateTime::UTC );
196 
197  setupSaveTimer();
198  setupReloadTimer();
199 }
200 
201 void ResourceCached::setupSaveTimer()
202 {
203  if ( d->mSavePolicy == SaveInterval ) {
204  kDebug() << "start save timer (interval " << d->mSaveInterval << "mins)";
205  d->mSaveTimer.start( d->mSaveInterval * 60 * 1000 ); // n minutes
206  } else {
207  d->mSaveTimer.stop();
208  }
209 }
210 
211 void ResourceCached::setupReloadTimer()
212 {
213  if ( d->mReloadPolicy == ReloadInterval ) {
214  kDebug() << "start reload timer (interval " << d->mReloadInterval << "mins)";
215  d->mReloadTimer.start( d->mReloadInterval * 60 * 1000 ); // n minutes
216  } else {
217  d->mReloadTimer.stop();
218  }
219 }
220 
221 void ResourceCached::writeConfig( KConfigGroup &group )
222 {
223  group.writeEntry( "ReloadPolicy", d->mReloadPolicy );
224  group.writeEntry( "ReloadInterval", d->mReloadInterval );
225 
226  group.writeEntry( "SavePolicy", d->mSavePolicy );
227  group.writeEntry( "SaveInterval", d->mSaveInterval );
228 
229  group.writeEntry( "LastLoad", d->mLastLoad.toUtc().dateTime() );
230  group.writeEntry( "LastSave", d->mLastSave.toUtc().dateTime() );
231 }
232 
233 bool ResourceCached::addEvent( Event *event )
234 {
235  return d->mCalendar.addEvent( event );
236 }
237 
238 // probably not really efficient, but...it works for now.
239 bool ResourceCached::deleteEvent( Event *event )
240 {
241  kDebug();
242 
243  return d->mCalendar.deleteEvent( event );
244 }
245 
246 void ResourceCached::deleteAllEvents()
247 {
248  d->mCalendar.deleteAllEvents();
249 }
250 
251 Event *ResourceCached::event( const QString &uid )
252 {
253  return d->mCalendar.event( uid );
254 }
255 
256 Event::List ResourceCached::rawEventsForDate( const QDate &qd, const KDateTime::Spec &timeSpec,
257  EventSortField sortField,
258  SortDirection sortDirection )
259 {
260  Event::List list = d->mCalendar.rawEventsForDate( qd, timeSpec, sortField, sortDirection );
261 
262  return list;
263 }
264 
265 Event::List ResourceCached::rawEvents( const QDate &start, const QDate &end,
266  const KDateTime::Spec &timeSpec, bool inclusive )
267 {
268  return d->mCalendar.rawEvents( start, end, timeSpec, inclusive );
269 }
270 
271 Event::List ResourceCached::rawEventsForDate( const KDateTime &kdt )
272 {
273  return d->mCalendar.rawEventsForDate( kdt );
274 }
275 
276 Event::List ResourceCached::rawEvents( EventSortField sortField, SortDirection sortDirection )
277 {
278  return d->mCalendar.rawEvents( sortField, sortDirection );
279 }
280 
281 bool ResourceCached::addTodo( Todo *todo )
282 {
283  return d->mCalendar.addTodo( todo );
284 }
285 
286 bool ResourceCached::deleteTodo( Todo *todo )
287 {
288  return d->mCalendar.deleteTodo( todo );
289 }
290 
291 void ResourceCached::deleteAllTodos()
292 {
293  d->mCalendar.deleteAllTodos();
294 }
295 
296 bool ResourceCached::deleteJournal( Journal *journal )
297 {
298  return d->mCalendar.deleteJournal( journal );
299 }
300 
301 void ResourceCached::deleteAllJournals()
302 {
303  d->mCalendar.deleteAllJournals();
304 }
305 
306 Todo::List ResourceCached::rawTodos( TodoSortField sortField, SortDirection sortDirection )
307 {
308  return d->mCalendar.rawTodos( sortField, sortDirection );
309 }
310 
311 Todo *ResourceCached::todo( const QString &uid )
312 {
313  return d->mCalendar.todo( uid );
314 }
315 
316 Todo::List ResourceCached::rawTodosForDate( const QDate &date )
317 {
318  return d->mCalendar.rawTodosForDate( date );
319 }
320 
321 bool ResourceCached::addJournal( Journal *journal )
322 {
323  return d->mCalendar.addJournal( journal );
324 }
325 
326 Journal *ResourceCached::journal( const QString &uid )
327 {
328  return d->mCalendar.journal( uid );
329 }
330 
331 Journal::List ResourceCached::rawJournals( JournalSortField sortField, SortDirection sortDirection )
332 {
333  return d->mCalendar.rawJournals( sortField, sortDirection );
334 }
335 
336 Journal::List ResourceCached::rawJournalsForDate( const QDate &date )
337 {
338  return d->mCalendar.rawJournalsForDate( date );
339 }
340 
341 Alarm::List ResourceCached::alarmsTo( const KDateTime &to )
342 {
343  return d->mCalendar.alarmsTo( to );
344 }
345 
346 Alarm::List ResourceCached::alarms( const KDateTime &from, const KDateTime &to )
347 {
348  return d->mCalendar.alarms( from, to );
349 }
350 
351 void ResourceCached::setTimeSpec( const KDateTime::Spec &timeSpec )
352 {
353  d->mCalendar.setTimeSpec( timeSpec );
354 }
355 
356 KDateTime::Spec ResourceCached::timeSpec() const
357 {
358  return d->mCalendar.timeSpec();
359 }
360 
361 void ResourceCached::setTimeZoneId( const QString &tzid )
362 {
363  d->mCalendar.setTimeZoneId( tzid );
364 }
365 
366 QString ResourceCached::timeZoneId() const
367 {
368  return d->mCalendar.timeZoneId();
369 }
370 
371 void ResourceCached::shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec )
372 {
373  d->mCalendar.shiftTimes( oldSpec, newSpec );
374 }
375 
376 void ResourceCached::clearChanges()
377 {
378  d->mAddedIncidences.clear();
379  d->mChangedIncidences.clear();
380  d->mDeletedIncidences.clear();
381 }
382 
383 bool ResourceCached::load( CacheAction action )
384 {
385  kDebug() << resourceName();
386 
387  setReceivedLoadError( false );
388 
389  bool success = true;
390  if ( !isOpen() ) {
391  success = open(); //krazy:exclude=syscalls open is a class method
392  }
393  if ( success ) {
394  bool update = false;
395  switch ( action ) {
396  case DefaultCache:
397  if ( !d->mReloaded && !d->mInhibitReload ) {
398  update = checkForReload();
399  }
400  break;
401  case NoSyncCache:
402  break;
403  case SyncCache:
404  update = true;
405  break;
406  }
407  success = doLoad( update );
408  }
409  if ( !success && !receivedLoadError() ) {
410  loadError();
411  }
412 
413  // If the resource is read-only, we need to set its incidences to read-only,
414  // too. This can't be done at a lower-level, since the read-only setting
415  // happens at this level
416  if ( !noReadOnlyOnLoad() && readOnly() ) {
417  Incidence::List incidences( rawIncidences() );
418  Incidence::List::Iterator it;
419  for ( it = incidences.begin(); it != incidences.end(); ++it ) {
420  (*it)->setReadOnly( true );
421  }
422  }
423 
424  kDebug() << "Done loading resource" << resourceName();
425 
426  if ( success ) {
427  emit resourceLoaded( this );
428  }
429 
430  return success;
431 }
432 
433 bool ResourceCached::load()
434 {
435  return load( SyncCache );
436 }
437 
438 bool ResourceCached::loadFromCache()
439 {
440  setIdMapperIdentifier();
441  d->mIdMapper.load();
442 
443  if ( !KStandardDirs::exists( cacheFile() ) ) {
444  return false;
445  }
446  d->mCalendar.load( cacheFile() );
447  if ( !noReadOnlyOnLoad() && readOnly() ) {
448  Incidence::List incidences( rawIncidences() );
449  Incidence::List::Iterator it;
450  for ( it = incidences.begin(); it != incidences.end(); ++it ) {
451  (*it)->setReadOnly( true );
452  }
453  }
454  return true;
455 }
456 
457 bool ResourceCached::save( CacheAction action, Incidence *incidence )
458 {
459  if ( !incidence && ( d->mSavePolicy == SaveAlways || d->mSavePolicy == SaveDelayed ) ) {
460  d->mSaveTimer.stop(); // in case it's called manually while save is pending
461  }
462  d->mSavePending = false;
463  if ( saveInhibited() ) {
464  return true;
465  }
466  if ( !readOnly() ) {
467  kDebug() << "Save resource" << resourceName();
468 
469  setReceivedSaveError( false );
470 
471  if ( !isOpen() ) {
472  return true;
473  }
474  bool upload = false;
475  switch ( action ) {
476  case DefaultCache:
477  upload = checkForSave();
478  break;
479  case NoSyncCache:
480  break;
481  case SyncCache:
482  upload = true;
483  break;
484  }
485  bool success = incidence ? doSave( upload, incidence ) : doSave( upload );
486  if ( !success && !receivedSaveError() ) {
487  saveError();
488  } else {
489  emit resourceSaved( this );
490  }
491  return success;
492  } else {
493  // Read-only, just don't save...
494  kDebug() << "Don't save read-only resource" << resourceName();
495  return true;
496  }
497 }
498 
499 bool ResourceCached::save( Incidence *incidence )
500 {
501  return save( SyncCache, incidence );
502 }
503 
504 bool ResourceCached::doSave( bool syncCache, Incidence *incidence )
505 {
506  Q_UNUSED( incidence );
507  return doSave( syncCache );
508 }
509 
510 void ResourceCached::saveToCache()
511 {
512  kDebug() << cacheFile();
513 
514  setIdMapperIdentifier();
515  d->mIdMapper.save();
516 
517  d->mCalendar.save( cacheFile() );
518 }
519 
520 void ResourceCached::setIdMapperIdentifier()
521 {
522  d->mIdMapper.setIdentifier( type() + '_' + identifier() );
523 }
524 
525 void ResourceCached::clearCache()
526 {
527  d->mCalendar.close();
528 }
529 
530 void ResourceCached::cleanUpEventCache( const Event::List &eventList )
531 {
532  CalendarLocal calendar ( QLatin1String( "UTC" ) );
533 
534  if ( KStandardDirs::exists( cacheFile() ) ) {
535  calendar.load( cacheFile() );
536  } else {
537  return;
538  }
539 
540  Event::List list = calendar.events();
541  Event::List::ConstIterator cacheIt, it;
542  for ( cacheIt = list.constBegin(); cacheIt != list.constEnd(); ++cacheIt ) {
543  bool found = false;
544  for ( it = eventList.begin(); it != eventList.end(); ++it ) {
545  if ( (*it)->uid() == (*cacheIt)->uid() ) {
546  found = true;
547  break;
548  }
549  }
550 
551  if ( !found ) {
552  d->mIdMapper.removeRemoteId( d->mIdMapper.remoteId( (*cacheIt)->uid() ) );
553  Event *event = d->mCalendar.event( (*cacheIt)->uid() );
554  if ( event ) {
555  d->mCalendar.deleteEvent( event );
556  }
557  }
558  }
559 
560  calendar.close();
561 }
562 
563 void ResourceCached::cleanUpTodoCache( const Todo::List &todoList )
564 {
565  CalendarLocal calendar ( QLatin1String( "UTC" ) );
566 
567  if ( KStandardDirs::exists( cacheFile() ) ) {
568  calendar.load( cacheFile() );
569  } else {
570  return;
571  }
572 
573  Todo::List list = calendar.todos();
574  Todo::List::ConstIterator cacheIt, it;
575  for ( cacheIt = list.constBegin(); cacheIt != list.constEnd(); ++cacheIt ) {
576 
577  bool found = false;
578  for ( it = todoList.constBegin(); it != todoList.constEnd(); ++it ) {
579  if ( (*it)->uid() == (*cacheIt)->uid() ) {
580  found = true;
581  }
582  }
583 
584  if ( !found ) {
585  d->mIdMapper.removeRemoteId( d->mIdMapper.remoteId( (*cacheIt)->uid() ) );
586  Todo *todo = d->mCalendar.todo( (*cacheIt)->uid() );
587  if ( todo ) {
588  d->mCalendar.deleteTodo( todo );
589  }
590  }
591  }
592 
593  calendar.close();
594 }
595 
596 KRES::IdMapper &ResourceCached::idMapper()
597 {
598  return d->mIdMapper;
599 }
600 
601 QString ResourceCached::cacheFile() const
602 {
603  return KStandardDirs::locateLocal( "cache", "kcal/kresources/" + identifier() );
604 }
605 
606 QString ResourceCached::changesCacheFile( const QString &type ) const
607 {
608  return KStandardDirs::locateLocal( "cache", "kcal/changescache/" + identifier() + '_' + type );
609 }
610 
611 void ResourceCached::saveChangesCache( const QMap<Incidence *, bool> &map, const QString &type )
612 {
613  CalendarLocal calendar ( QLatin1String( "UTC" ) );
614 
615  bool isEmpty = true;
616  QMap<Incidence *,bool>::ConstIterator it;
617  for ( it = map.begin(); it != map.end(); ++it ) {
618  isEmpty = false;
619  calendar.addIncidence( it.key()->clone() );
620  }
621 
622  if ( !isEmpty ) {
623  calendar.save( changesCacheFile( type ) );
624  } else {
625  QFile file( changesCacheFile( type ) );
626  file.remove();
627  }
628 
629  calendar.close();
630 }
631 
632 void ResourceCached::saveChangesCache()
633 {
634  saveChangesCache( d->mAddedIncidences, "added" );
635  saveChangesCache( d->mDeletedIncidences, "deleted" );
636  saveChangesCache( d->mChangedIncidences, "changed" );
637 }
638 
639 void ResourceCached::loadChangesCache( QMap<Incidence *, bool> &map, const QString &type )
640 {
641  CalendarLocal calendar ( QLatin1String( "UTC" ) );
642 
643  if ( KStandardDirs::exists( changesCacheFile( type ) ) ) {
644  calendar.load( changesCacheFile( type ) );
645  } else {
646  return;
647  }
648 
649  const Incidence::List list = calendar.incidences();
650  Incidence::List::ConstIterator it;
651  for ( it = list.begin(); it != list.end(); ++it ) {
652  map.insert( (*it)->clone(), true );
653  }
654 
655  calendar.close();
656 }
657 
658 void ResourceCached::loadChangesCache()
659 {
660  loadChangesCache( d->mAddedIncidences, "added" );
661  loadChangesCache( d->mDeletedIncidences, "deleted" );
662  loadChangesCache( d->mChangedIncidences, "changed" );
663 }
664 
665 void ResourceCached::calendarIncidenceAdded( Incidence *i )
666 {
667  kDebug() << i->uid();
668 
669  QMap<Incidence *,bool>::ConstIterator it;
670  it = d->mAddedIncidences.constFind( i );
671  if ( it == d->mAddedIncidences.constEnd() ) {
672  d->mAddedIncidences.insert( i, true );
673  }
674 
675  checkForAutomaticSave();
676 }
677 
678 void ResourceCached::calendarIncidenceChanged( Incidence *i )
679 {
680  kDebug() << i->uid();
681 
682  QMap<Incidence *,bool>::ConstIterator it;
683  it = d->mChangedIncidences.constFind( i );
684  // FIXME: If you modify an added incidence, there's no need to add it to d->mChangedIncidences!
685  if ( it == d->mChangedIncidences.constEnd() ) {
686  d->mChangedIncidences.insert( i, true );
687  }
688 
689  checkForAutomaticSave();
690 }
691 
692 void ResourceCached::calendarIncidenceDeleted( Incidence *i )
693 {
694  kDebug() << i->uid();
695 
696  QMap<Incidence *,bool>::ConstIterator it;
697  it = d->mDeletedIncidences.constFind( i );
698  if ( it == d->mDeletedIncidences.constEnd() ) {
699  d->mDeletedIncidences.insert( i, true );
700  }
701 
702  checkForAutomaticSave();
703 }
704 
705 Incidence::List ResourceCached::addedIncidences() const
706 {
707  Incidence::List added;
708  QMap<Incidence *,bool>::ConstIterator it;
709  for ( it = d->mAddedIncidences.constBegin(); it != d->mAddedIncidences.constEnd(); ++it ) {
710  added.append( it.key() );
711  }
712  return added;
713 }
714 
715 Incidence::List ResourceCached::changedIncidences() const
716 {
717  Incidence::List changed;
718  QMap<Incidence *,bool>::ConstIterator it;
719  for ( it = d->mChangedIncidences.constBegin(); it != d->mChangedIncidences.constEnd(); ++it ) {
720  changed.append( it.key() );
721  }
722  return changed;
723 }
724 
725 Incidence::List ResourceCached::deletedIncidences() const
726 {
727  Incidence::List deleted;
728  QMap<Incidence *,bool>::ConstIterator it;
729  for ( it = d->mDeletedIncidences.constBegin(); it != d->mDeletedIncidences.constEnd(); ++it ) {
730  deleted.append( it.key() );
731  }
732  return deleted;
733 }
734 
735 Incidence::List ResourceCached::allChanges() const
736 {
737  Incidence::List changes;
738  QMap<Incidence *,bool>::ConstIterator it;
739  for ( it = d->mAddedIncidences.constBegin(); it != d->mAddedIncidences.constEnd(); ++it ) {
740  changes.append( it.key() );
741  }
742  for ( it = d->mChangedIncidences.constBegin(); it != d->mChangedIncidences.constEnd(); ++it ) {
743  changes.append( it.key() );
744  }
745  for ( it = d->mDeletedIncidences.constBegin(); it != d->mDeletedIncidences.constEnd(); ++it ) {
746  changes.append( it.key() );
747  }
748  return changes;
749 }
750 
751 bool ResourceCached::hasChanges() const
752 {
753  return !( d->mAddedIncidences.isEmpty() && d->mChangedIncidences.isEmpty() &&
754  d->mDeletedIncidences.isEmpty() );
755 }
756 
757 void ResourceCached::clearChange( Incidence *incidence )
758 {
759  clearChange( incidence->uid() );
760 }
761 
762 void ResourceCached::clearChange( const QString &uid )
763 {
764  QMap<Incidence *, bool>::Iterator it;
765 
766  for ( it = d->mAddedIncidences.begin(); it != d->mAddedIncidences.end(); ++it ) {
767  if ( it.key()->uid() == uid ) {
768  d->mAddedIncidences.erase( it );
769  break;
770  }
771  }
772 
773  for ( it = d->mChangedIncidences.begin(); it != d->mChangedIncidences.end(); ++it ) {
774  if ( it.key()->uid() == uid ) {
775  d->mChangedIncidences.erase( it );
776  break;
777  }
778  }
779 
780  for ( it = d->mDeletedIncidences.begin(); it != d->mDeletedIncidences.end(); ++it ) {
781  if ( it.key()->uid() == uid ) {
782  d->mDeletedIncidences.erase( it );
783  break;
784  }
785  }
786 }
787 
788 void ResourceCached::enableChangeNotification()
789 {
790  d->mCalendar.registerObserver( this );
791 }
792 
793 void ResourceCached::disableChangeNotification()
794 {
795  d->mCalendar.unregisterObserver( this );
796 }
797 
798 void ResourceCached::slotReload()
799 {
800  if ( !isActive() ) {
801  return;
802  }
803 
804  kDebug();
805 
806  load( SyncCache );
807 }
808 
809 void ResourceCached::slotSave()
810 {
811  if ( !isActive() ) {
812  return;
813  }
814 
815  kDebug();
816 
817  save( SyncCache );
818 }
819 
820 void ResourceCached::checkForAutomaticSave()
821 {
822  if ( d->mSavePolicy == SaveAlways ) {
823  kDebug() << "save now";
824  d->mSavePending = true;
825  d->mSaveTimer.setSingleShot( true );
826  d->mSaveTimer.start( 1 * 1000 ); // 1 second
827  } else if ( d->mSavePolicy == SaveDelayed ) {
828  kDebug() << "save delayed";
829  d->mSavePending = true;
830  d->mSaveTimer.setSingleShot( true );
831  d->mSaveTimer.start( 15 * 1000 ); // 15 seconds
832  }
833 }
834 
835 bool ResourceCached::checkForReload()
836 {
837  if ( d->mReloadPolicy == ReloadNever ) {
838  return false;
839  }
840  if ( d->mReloadPolicy == ReloadOnStartup ) {
841  return !d->mReloaded;
842  }
843  return true;
844 }
845 
846 bool ResourceCached::checkForSave()
847 {
848  if ( d->mSavePolicy == SaveNever ) {
849  return false;
850  }
851  return true;
852 }
853 
854 void ResourceCached::addInfoText( QString &txt ) const
855 {
856  if ( d->mLastLoad.isValid() ) {
857  txt += "<br>";
858  txt += i18n( "Last loaded: %1",
859  KGlobal::locale()->formatDateTime( d->mLastLoad.toUtc().dateTime() ) );
860  }
861  if ( d->mLastSave.isValid() ) {
862  txt += "<br>";
863  txt += i18n( "Last saved: %1",
864  KGlobal::locale()->formatDateTime( d->mLastSave.toUtc().dateTime() ) );
865  }
866 }
867 
868 void ResourceCached::doClose()
869 {
870  if ( d->mSavePending ) {
871  d->mSaveTimer.stop();
872  }
873  if ( d->mSavePending || d->mSavePolicy == SaveOnExit || d->mSavePolicy == SaveInterval ) {
874  save( SyncCache );
875  }
876  d->mCalendar.close();
877 }
878 
879 bool ResourceCached::doOpen()
880 {
881  kDebug() << "Opening resource" << resourceName();
882  return true;
883 }
884 
885 void KCal::ResourceCached::setOwner( const Person &owner )
886 {
887  d->mCalendar.setOwner( owner );
888 }
889 
890 Person KCal::ResourceCached::owner() const
891 {
892  return d->mCalendar.owner();
893 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 4 2012 14:36:42 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal