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

KCal Library

  • kcal
incidence.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the kcal library.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
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 */
35 #include "incidence.h"
36 #include "calformat.h"
37 
38 #include "kpimutils/kfileio.h"
39 
40 #include <kglobal.h>
41 #include <klocale.h>
42 #include <kdebug.h>
43 #include <ktemporaryfile.h>
44 #include <kde_file.h>
45 
46 #include <QtCore/QList>
47 #include <QTextDocument> // for Qt::escape() and Qt::mightBeRichText()
48 #include <KMimeType>
49 
50 using namespace KCal;
51 
56 //@cond PRIVATE
57 class KCal::Incidence::Private
58 {
59  public:
60  Private()
61  : mDescriptionIsRich( false ),
62  mSummaryIsRich( false ),
63  mLocationIsRich( false ),
64  mRecurrence( 0 ),
65  mStatus( StatusNone ),
66  mSecrecy( SecrecyPublic ),
67  mPriority( 0 ),
68  mRelatedTo( 0 ),
69  mGeoLatitude( 0 ),
70  mGeoLongitude( 0 ),
71  mHasGeo( false )
72  {
73  mAlarms.setAutoDelete( true );
74  mAttachments.setAutoDelete( true );
75  }
76 
77  Private( const Private &p )
78  : mCreated( p.mCreated ),
79  mRevision( p.mRevision ),
80  mDescription( p.mDescription ),
81  mDescriptionIsRich( p.mDescriptionIsRich ),
82  mSummary( p.mSummary ),
83  mSummaryIsRich( p.mSummaryIsRich ),
84  mLocation( p.mLocation ),
85  mLocationIsRich( p.mLocationIsRich ),
86  mCategories( p.mCategories ),
87  mRecurrence( p.mRecurrence ),
88  mResources( p.mResources ),
89  mStatus( p.mStatus ),
90  mStatusString( p.mStatusString ),
91  mSecrecy( p.mSecrecy ),
92  mPriority( p.mPriority ),
93  mSchedulingID( p.mSchedulingID ),
94  mRelatedTo( p.mRelatedTo ),
95  mRelatedToUid( p.mRelatedToUid ),
96  mGeoLatitude( p.mGeoLatitude ),
97  mGeoLongitude( p.mGeoLongitude ),
98  mHasGeo( p.mHasGeo )
99  {
100  mAlarms.setAutoDelete( true );
101  mAttachments.setAutoDelete( true );
102  }
103 
104  void clear()
105  {
106  mAlarms.clearAll();
107  mAttachments.clearAll();
108  delete mRecurrence;
109  }
110 
111  KDateTime mCreated; // creation datetime
112  int mRevision; // revision number
113 
114  QString mDescription; // description string
115  bool mDescriptionIsRich; // description string is richtext.
116  QString mSummary; // summary string
117  bool mSummaryIsRich; // summary string is richtext.
118  QString mLocation; // location string
119  bool mLocationIsRich; // location string is richtext.
120  QStringList mCategories; // category list
121  mutable Recurrence *mRecurrence; // recurrence
122  Attachment::List mAttachments; // attachments list
123  Alarm::List mAlarms; // alarms list
124  QStringList mResources; // resources list (not calendar resources)
125  Status mStatus; // status
126  QString mStatusString; // status string, for custom status
127  Secrecy mSecrecy; // secrecy
128  int mPriority; // priority: 1 = highest, 2 = less, etc.
129  QString mSchedulingID; // ID for scheduling mails
130 
131  Incidence *mRelatedTo; // incidence this is related to
132  QString mRelatedToUid; // incidence (by Uid) this is related to
133  Incidence::List mRelations; // a list of incidences related to this
134  float mGeoLatitude; // Specifies latitude in decimal degrees
135  float mGeoLongitude; // Specifies longitude in decimal degrees
136  bool mHasGeo; // if incidence has geo data
137  QHash<Attachment *, QString> mTempFiles; // Temporary files for writing attachments to.
138 };
139 //@endcond
140 
141 Incidence::Incidence()
142  : IncidenceBase(), d( new KCal::Incidence::Private )
143 {
144  recreate();
145 }
146 
147 Incidence::Incidence( const Incidence &i )
148  : IncidenceBase( i ),
149  Recurrence::RecurrenceObserver(),
150  d( new KCal::Incidence::Private( *i.d ) )
151 {
152  init( i );
153 }
154 
155 void Incidence::init( const Incidence &i )
156 {
157  d->mRevision = i.d->mRevision;
158  d->mCreated = i.d->mCreated;
159  d->mDescription = i.d->mDescription;
160  d->mSummary = i.d->mSummary;
161  d->mCategories = i.d->mCategories;
162  d->mRelatedTo = i.d->mRelatedTo;
163  d->mRelatedToUid = i.d->mRelatedToUid;
164  d->mRelations = i.d->mRelations;
165  d->mResources = i.d->mResources;
166  d->mStatusString = i.d->mStatusString;
167  d->mStatus = i.d->mStatus;
168  d->mSecrecy = i.d->mSecrecy;
169  d->mPriority = i.d->mPriority;
170  d->mLocation = i.d->mLocation;
171  d->mGeoLatitude = i.d->mGeoLatitude;
172  d->mGeoLongitude = i.d->mGeoLongitude;
173  d->mHasGeo = i.d->mHasGeo;
174 
175  // Alarms and Attachments are stored in ListBase<...>, which is a QValueList<...*>.
176  // We need to really duplicate the objects stored therein, otherwise deleting
177  // i will also delete all attachments from this object (setAutoDelete...)
178  foreach ( Alarm *alarm, i.d->mAlarms ) {
179  Alarm *b = new Alarm( *alarm );
180  b->setParent( this );
181  d->mAlarms.append( b );
182  }
183 
184  foreach ( Attachment *attachment, i.d->mAttachments ) {
185  Attachment *a = new Attachment( *attachment );
186  d->mAttachments.append( a );
187  }
188 
189  if ( i.d->mRecurrence ) {
190  d->mRecurrence = new Recurrence( *( i.d->mRecurrence ) );
191  d->mRecurrence->addObserver( this );
192  } else {
193  d->mRecurrence = 0;
194  }
195 }
196 
197 Incidence::~Incidence()
198 {
199  Incidence::List relations = d->mRelations;
200  foreach ( Incidence *incidence, relations ) {
201  if ( incidence->relatedTo() == this ) {
202  incidence->setRelatedTo( 0 );
203  }
204  }
205 
206  if ( relatedTo() ) {
207  relatedTo()->removeRelation( this );
208  }
209  delete d->mRecurrence;
210  delete d;
211 }
212 
213 //@cond PRIVATE
214 // A string comparison that considers that null and empty are the same
215 static bool stringCompare( const QString &s1, const QString &s2 )
216 {
217  return ( s1.isEmpty() && s2.isEmpty() ) || ( s1 == s2 );
218 }
219 
220 //@endcond
221 Incidence &Incidence::operator=( const Incidence &other )
222 {
223  // check for self assignment
224  if ( &other == this ) {
225  return *this;
226  }
227 
228  d->clear();
229  //TODO: should relations be cleared out, as in destructor???
230  IncidenceBase::operator=( other );
231  init( other );
232  return *this;
233 }
234 
235 bool Incidence::operator==( const Incidence &i2 ) const
236 {
237  if ( alarms().count() != i2.alarms().count() ) {
238  return false; // no need to check further
239  }
240 
241  Alarm::List::ConstIterator a1 = alarms().constBegin();
242  Alarm::List::ConstIterator a1end = alarms().constEnd();
243  Alarm::List::ConstIterator a2 = i2.alarms().begin();
244  Alarm::List::ConstIterator a2end = i2.alarms().constEnd();
245  for ( ; a1 != a1end && a2 != a2end; ++a1, ++a2 ) {
246  if ( **a1 == **a2 ) {
247  continue;
248  } else {
249  return false;
250  }
251  }
252 
253  if ( !IncidenceBase::operator==( i2 ) ) {
254  return false;
255  }
256 
257  bool recurrenceEqual = ( d->mRecurrence == 0 && i2.d->mRecurrence == 0 );
258  if ( !recurrenceEqual ) {
259  recurrenceEqual = d->mRecurrence != 0 &&
260  i2.d->mRecurrence != 0 &&
261  *d->mRecurrence == *i2.d->mRecurrence;
262  }
263 
264  return
265  recurrenceEqual &&
266  created() == i2.created() &&
267  stringCompare( description(), i2.description() ) &&
268  stringCompare( summary(), i2.summary() ) &&
269  categories() == i2.categories() &&
270  // no need to compare mRelatedTo
271  stringCompare( relatedToUid(), i2.relatedToUid() ) &&
272  relations() == i2.relations() &&
273  attachments() == i2.attachments() &&
274  resources() == i2.resources() &&
275  d->mStatus == i2.d->mStatus &&
276  ( d->mStatus == StatusNone ||
277  stringCompare( d->mStatusString, i2.d->mStatusString ) ) &&
278  secrecy() == i2.secrecy() &&
279  priority() == i2.priority() &&
280  stringCompare( location(), i2.location() ) &&
281  stringCompare( schedulingID(), i2.schedulingID() );
282 }
283 
284 void Incidence::recreate()
285 {
286  KDateTime nowUTC = KDateTime::currentUtcDateTime();
287  setCreated( nowUTC );
288 
289  setUid( CalFormat::createUniqueId() );
290  setSchedulingID( QString() );
291 
292  setRevision( 0 );
293 
294  setLastModified( nowUTC );
295 }
296 
297 void Incidence::setReadOnly( bool readOnly )
298 {
299  IncidenceBase::setReadOnly( readOnly );
300  if ( d->mRecurrence ) {
301  d->mRecurrence->setRecurReadOnly( readOnly );
302  }
303 }
304 
305 void Incidence::setAllDay( bool allDay )
306 {
307  if ( mReadOnly ) {
308  return;
309  }
310  if ( recurrence() ) {
311  recurrence()->setAllDay( allDay );
312  }
313  IncidenceBase::setAllDay( allDay );
314 }
315 
316 void Incidence::setCreated( const KDateTime &created )
317 {
318  if ( mReadOnly ) {
319  return;
320  }
321 
322  d->mCreated = created.toUtc();
323 
324 // FIXME: Shouldn't we call updated for the creation date, too?
325 // updated();
326 }
327 
328 KDateTime Incidence::created() const
329 {
330  return d->mCreated;
331 }
332 
333 void Incidence::setRevision( int rev )
334 {
335  if ( mReadOnly ) {
336  return;
337  }
338 
339  d->mRevision = rev;
340 
341  updated();
342 }
343 
344 int Incidence::revision() const
345 {
346  return d->mRevision;
347 }
348 
349 void Incidence::setDtStart( const KDateTime &dt )
350 {
351  if ( d->mRecurrence ) {
352  d->mRecurrence->setStartDateTime( dt );
353  d->mRecurrence->setAllDay( allDay() );
354  }
355  IncidenceBase::setDtStart( dt );
356 }
357 
358 KDateTime Incidence::dtEnd() const
359 {
360  return KDateTime();
361 }
362 
363 void Incidence::shiftTimes( const KDateTime::Spec &oldSpec,
364  const KDateTime::Spec &newSpec )
365 {
366  IncidenceBase::shiftTimes( oldSpec, newSpec );
367  if ( d->mRecurrence ) {
368  d->mRecurrence->shiftTimes( oldSpec, newSpec );
369  }
370  for ( int i = 0, end = d->mAlarms.count(); i < end; ++i ) {
371  d->mAlarms[i]->shiftTimes( oldSpec, newSpec );
372  }
373 }
374 
375 void Incidence::setDescription( const QString &description, bool isRich )
376 {
377  if ( mReadOnly ) {
378  return;
379  }
380  d->mDescription = description;
381  d->mDescriptionIsRich = isRich;
382  updated();
383 }
384 
385 void Incidence::setDescription( const QString &description )
386 {
387  setDescription( description, Qt::mightBeRichText( description ) );
388 }
389 
390 QString Incidence::description() const
391 {
392  return d->mDescription;
393 }
394 
395 QString Incidence::richDescription() const
396 {
397  if ( descriptionIsRich() ) {
398  return d->mDescription;
399  } else {
400  return Qt::escape( d->mDescription ).replace( '\n', "<br/>" );
401  }
402 }
403 
404 bool Incidence::descriptionIsRich() const
405 {
406  return d->mDescriptionIsRich;
407 }
408 
409 void Incidence::setSummary( const QString &summary, bool isRich )
410 {
411  if ( mReadOnly ) {
412  return;
413  }
414  d->mSummary = summary;
415  d->mSummaryIsRich = isRich;
416  updated();
417 }
418 
419 void Incidence::setSummary( const QString &summary )
420 {
421  setSummary( summary, Qt::mightBeRichText( summary ) );
422 }
423 
424 QString Incidence::summary() const
425 {
426  return d->mSummary;
427 }
428 
429 QString Incidence::richSummary() const
430 {
431  if ( summaryIsRich() ) {
432  return d->mSummary;
433  } else {
434  return Qt::escape( d->mSummary ).replace( '\n', "<br/>" );
435  }
436 }
437 
438 bool Incidence::summaryIsRich() const
439 {
440  return d->mSummaryIsRich;
441 }
442 
443 void Incidence::setCategories( const QStringList &categories )
444 {
445  if ( mReadOnly ) {
446  return;
447  }
448  d->mCategories = categories;
449  updated();
450 }
451 
452 void Incidence::setCategories( const QString &catStr )
453 {
454  if ( mReadOnly ) {
455  return;
456  }
457  d->mCategories.clear();
458 
459  if ( catStr.isEmpty() ) {
460  return;
461  }
462 
463  d->mCategories = catStr.split( ',' );
464 
465  QStringList::Iterator it;
466  for ( it = d->mCategories.begin();it != d->mCategories.end(); ++it ) {
467  *it = (*it).trimmed();
468  }
469 
470  updated();
471 }
472 
473 QStringList Incidence::categories() const
474 {
475  return d->mCategories;
476 }
477 
478 QString Incidence::categoriesStr() const
479 {
480  return d->mCategories.join( "," );
481 }
482 
483 void Incidence::setRelatedToUid( const QString &relatedToUid )
484 {
485  if ( d->mRelatedToUid == relatedToUid ) {
486  return;
487  }
488  d->mRelatedToUid = relatedToUid;
489  updated();
490 }
491 
492 QString Incidence::relatedToUid() const
493 {
494  return d->mRelatedToUid;
495 }
496 
497 void Incidence::setRelatedTo( Incidence *incidence )
498 {
499  if ( d->mRelatedTo == incidence ) {
500  return;
501  }
502  if ( d->mRelatedTo ) {
503  d->mRelatedTo->removeRelation( this );
504  }
505  d->mRelatedTo = incidence;
506  if ( d->mRelatedTo ) {
507  d->mRelatedTo->addRelation( this );
508  if ( d->mRelatedTo->uid() != d->mRelatedToUid ) {
509  setRelatedToUid( d->mRelatedTo->uid() );
510  }
511  } else {
512  setRelatedToUid( QString() );
513  }
514 }
515 
516 Incidence *Incidence::relatedTo() const
517 {
518  return d->mRelatedTo;
519 }
520 
521 Incidence::List Incidence::relations() const
522 {
523  return d->mRelations;
524 }
525 
526 void Incidence::addRelation( Incidence *incidence )
527 {
528  if ( !d->mRelations.contains( incidence ) ) {
529  d->mRelations.append( incidence );
530  }
531 }
532 
533 void Incidence::removeRelation( Incidence *incidence )
534 {
535  d->mRelations.removeRef( incidence );
536  if ( d->mRelatedToUid == incidence->uid() ) {
537  d->mRelatedToUid.clear();
538  }
539 // if (incidence->getRelatedTo() == this) incidence->setRelatedTo(0);
540 }
541 
542 // %%%%%%%%%%%% Recurrence-related methods %%%%%%%%%%%%%%%%%%%%
543 
544 Recurrence *Incidence::recurrence() const
545 {
546  if ( !d->mRecurrence ) {
547  d->mRecurrence = new Recurrence();
548  d->mRecurrence->setStartDateTime( IncidenceBase::dtStart() );
549  d->mRecurrence->setAllDay( allDay() );
550  d->mRecurrence->setRecurReadOnly( mReadOnly );
551  d->mRecurrence->addObserver( const_cast<KCal::Incidence*>( this ) );
552  }
553 
554  return d->mRecurrence;
555 }
556 
557 void Incidence::clearRecurrence()
558 {
559  delete d->mRecurrence;
560  d->mRecurrence = 0;
561 }
562 
563 ushort Incidence::recurrenceType() const
564 {
565  if ( d->mRecurrence ) {
566  return d->mRecurrence->recurrenceType();
567  } else {
568  return Recurrence::rNone;
569  }
570 }
571 
572 bool Incidence::recurs() const
573 {
574  if ( d->mRecurrence ) {
575  return d->mRecurrence->recurs();
576  } else {
577  return false;
578  }
579 }
580 
581 bool Incidence::recursOn( const QDate &date,
582  const KDateTime::Spec &timeSpec ) const
583 {
584  return d->mRecurrence && d->mRecurrence->recursOn( date, timeSpec );
585 }
586 
587 bool Incidence::recursAt( const KDateTime &qdt ) const
588 {
589  return d->mRecurrence && d->mRecurrence->recursAt( qdt );
590 }
591 
592 QList<KDateTime> Incidence::startDateTimesForDate( const QDate &date,
593  const KDateTime::Spec &timeSpec ) const
594 {
595  KDateTime start = dtStart();
596  KDateTime end = endDateRecurrenceBase();
597 
598  QList<KDateTime> result;
599 
600  // TODO_Recurrence: Also work if only due date is given...
601  if ( !start.isValid() && ! end.isValid() ) {
602  return result;
603  }
604 
605  // if the incidence doesn't recur,
606  KDateTime kdate( date, timeSpec );
607  if ( !recurs() ) {
608  if ( !( start > kdate || end < kdate ) ) {
609  result << start;
610  }
611  return result;
612  }
613 
614  int days = start.daysTo( end );
615  // Account for possible recurrences going over midnight, while the original event doesn't
616  QDate tmpday( date.addDays( -days - 1 ) );
617  KDateTime tmp;
618  while ( tmpday <= date ) {
619  if ( recurrence()->recursOn( tmpday, timeSpec ) ) {
620  QList<QTime> times = recurrence()->recurTimesOn( tmpday, timeSpec );
621  foreach ( const QTime &time, times ) {
622  tmp = KDateTime( tmpday, time, start.timeSpec() );
623  if ( endDateForStart( tmp ) >= kdate ) {
624  result << tmp;
625  }
626  }
627  }
628  tmpday = tmpday.addDays( 1 );
629  }
630  return result;
631 }
632 
633 QList<KDateTime> Incidence::startDateTimesForDateTime( const KDateTime &datetime ) const
634 {
635  KDateTime start = dtStart();
636  KDateTime end = endDateRecurrenceBase();
637 
638  QList<KDateTime> result;
639 
640  // TODO_Recurrence: Also work if only due date is given...
641  if ( !start.isValid() && ! end.isValid() ) {
642  return result;
643  }
644 
645  // if the incidence doesn't recur,
646  if ( !recurs() ) {
647  if ( !( start > datetime || end < datetime ) ) {
648  result << start;
649  }
650  return result;
651  }
652 
653  int days = start.daysTo( end );
654  // Account for possible recurrences going over midnight, while the original event doesn't
655  QDate tmpday( datetime.date().addDays( -days - 1 ) );
656  KDateTime tmp;
657  while ( tmpday <= datetime.date() ) {
658  if ( recurrence()->recursOn( tmpday, datetime.timeSpec() ) ) {
659  // Get the times during the day (in start date's time zone) when recurrences happen
660  QList<QTime> times = recurrence()->recurTimesOn( tmpday, start.timeSpec() );
661  foreach ( const QTime &time, times ) {
662  tmp = KDateTime( tmpday, time, start.timeSpec() );
663  if ( !( tmp > datetime || endDateForStart( tmp ) < datetime ) ) {
664  result << tmp;
665  }
666  }
667  }
668  tmpday = tmpday.addDays( 1 );
669  }
670  return result;
671 }
672 
673 KDateTime Incidence::endDateForStart( const KDateTime &startDt ) const
674 {
675  KDateTime start = dtStart();
676  KDateTime end = endDateRecurrenceBase();
677  if ( !end.isValid() ) {
678  return start;
679  }
680  if ( !start.isValid() ) {
681  return end;
682  }
683 
684  return startDt.addSecs( start.secsTo( end ) );
685 }
686 
687 void Incidence::addAttachment( Attachment *attachment )
688 {
689  if ( mReadOnly || !attachment ) {
690  return;
691  }
692 
693  d->mAttachments.append( attachment );
694  updated();
695 }
696 
697 void Incidence::deleteAttachment( Attachment *attachment )
698 {
699  d->mAttachments.removeRef( attachment );
700 }
701 
702 void Incidence::deleteAttachments( const QString &mime )
703 {
704  Attachment::List::Iterator it = d->mAttachments.begin();
705  while ( it != d->mAttachments.end() ) {
706  if ( (*it)->mimeType() == mime ) {
707  d->mAttachments.removeRef( it );
708  } else {
709  ++it;
710  }
711  }
712 }
713 
714 Attachment::List Incidence::attachments() const
715 {
716  return d->mAttachments;
717 }
718 
719 Attachment::List Incidence::attachments( const QString &mime ) const
720 {
721  Attachment::List attachments;
722  Attachment::List::ConstIterator it;
723  foreach ( Attachment *attachment, d->mAttachments ) {
724  if ( attachment->mimeType() == mime ) {
725  attachments.append( attachment );
726  }
727  }
728  return attachments;
729 }
730 
731 void Incidence::clearAttachments()
732 {
733  d->mAttachments.clearAll();
734 }
735 
736 QString Incidence::writeAttachmentToTempFile( Attachment* attachment ) const
737 {
738  if ( d->mTempFiles.contains( attachment ) ) {
739  return d->mTempFiles.value( attachment );
740  }
741  KTemporaryFile *file = new KTemporaryFile();
742 
743  QStringList patterns = KMimeType::mimeType( attachment->mimeType() )->patterns();
744 
745  if ( !patterns.empty() ) {
746  file->setSuffix( QString( patterns.first() ).remove( '*' ) );
747  }
748  file->setAutoRemove( true );
749  file->open();
750  // read-only not to give the idea that it could be written to
751  file->setPermissions( QFile::ReadUser );
752  file->write( QByteArray::fromBase64( attachment->data() ) );
753  d->mTempFiles.insert( attachment, file->fileName() );
754  file->close();
755  return d->mTempFiles.value( attachment );
756 }
757 
758 void Incidence::clearTempFiles()
759 {
760  QHash<Attachment*, QString>::const_iterator it = d->mTempFiles.constBegin();
761  const QHash<Attachment*, QString>::const_iterator end = d->mTempFiles.constEnd();
762  for ( ; it != end; ++it )
763  {
764  QFile::remove( it.value() );
765  }
766  d->mTempFiles.clear();
767 }
768 
769 void Incidence::setResources( const QStringList &resources )
770 {
771  if ( mReadOnly ) {
772  return;
773  }
774 
775  d->mResources = resources;
776  updated();
777 }
778 
779 QStringList Incidence::resources() const
780 {
781  return d->mResources;
782 }
783 
784 void Incidence::setPriority( int priority )
785 {
786  if ( mReadOnly ) {
787  return;
788  }
789 
790  d->mPriority = priority;
791  updated();
792 }
793 
794 int Incidence::priority() const
795 {
796  return d->mPriority;
797 }
798 
799 void Incidence::setStatus( Incidence::Status status )
800 {
801  if ( mReadOnly || status == StatusX ) {
802  return;
803  }
804 
805  d->mStatus = status;
806  d->mStatusString.clear();
807  updated();
808 }
809 
810 void Incidence::setCustomStatus( const QString &status )
811 {
812  if ( mReadOnly ) {
813  return;
814  }
815 
816  d->mStatus = status.isEmpty() ? StatusNone : StatusX;
817  d->mStatusString = status;
818  updated();
819 }
820 
821 Incidence::Status Incidence::status() const
822 {
823  return d->mStatus;
824 }
825 
826 QString Incidence::statusStr() const
827 {
828  if ( d->mStatus == StatusX ) {
829  return d->mStatusString;
830  }
831 
832  return statusName( d->mStatus );
833 }
834 
835 QString Incidence::statusName( Incidence::Status status )
836 {
837  switch ( status ) {
838  case StatusTentative:
839  return i18nc( "@item event is tentative", "Tentative" );
840  case StatusConfirmed:
841  return i18nc( "@item event is definite", "Confirmed" );
842  case StatusCompleted:
843  return i18nc( "@item to-do is complete", "Completed" );
844  case StatusNeedsAction:
845  return i18nc( "@item to-do needs action", "Needs-Action" );
846  case StatusCanceled:
847  return i18nc( "@item event orto-do is canceled; journal is removed", "Canceled" );
848  case StatusInProcess:
849  return i18nc( "@item to-do is in process", "In-Process" );
850  case StatusDraft:
851  return i18nc( "@item journal is in draft form", "Draft" );
852  case StatusFinal:
853  return i18nc( "@item journal is in final form", "Final" );
854  case StatusX:
855  case StatusNone:
856  default:
857  return QString();
858  }
859 }
860 
861 void Incidence::setSecrecy( Incidence::Secrecy secrecy )
862 {
863  if ( mReadOnly ) {
864  return;
865  }
866 
867  d->mSecrecy = secrecy;
868  updated();
869 }
870 
871 Incidence::Secrecy Incidence::secrecy() const
872 {
873  return d->mSecrecy;
874 }
875 
876 QString Incidence::secrecyStr() const
877 {
878  return secrecyName( d->mSecrecy );
879 }
880 
881 QString Incidence::secrecyName( Incidence::Secrecy secrecy )
882 {
883  switch ( secrecy ) {
884  case SecrecyPublic:
885  return i18nc( "@item incidence access if for everyone", "Public" );
886  case SecrecyPrivate:
887  return i18nc( "@item incidence access is by owner only", "Private" );
888  case SecrecyConfidential:
889  return i18nc( "@item incidence access is by owner and a controlled group", "Confidential" );
890  default:
891  return QString(); // to make compilers happy
892  }
893 }
894 
895 QStringList Incidence::secrecyList()
896 {
897  QStringList list;
898  list << secrecyName( SecrecyPublic );
899  list << secrecyName( SecrecyPrivate );
900  list << secrecyName( SecrecyConfidential );
901 
902  return list;
903 }
904 
905 const Alarm::List &Incidence::alarms() const
906 {
907  return d->mAlarms;
908 }
909 
910 Alarm *Incidence::newAlarm()
911 {
912  Alarm *alarm = new Alarm( this );
913  d->mAlarms.append( alarm );
914  return alarm;
915 }
916 
917 void Incidence::addAlarm( Alarm *alarm )
918 {
919  d->mAlarms.append( alarm );
920  updated();
921 }
922 
923 void Incidence::removeAlarm( Alarm *alarm )
924 {
925  d->mAlarms.removeRef( alarm );
926  updated();
927 }
928 
929 void Incidence::clearAlarms()
930 {
931  d->mAlarms.clearAll();
932  updated();
933 }
934 
935 bool Incidence::isAlarmEnabled() const
936 {
937  foreach ( Alarm *alarm, d->mAlarms ) {
938  if ( alarm->enabled() ) {
939  return true;
940  }
941  }
942  return false;
943 }
944 
945 void Incidence::setLocation( const QString &location, bool isRich )
946 {
947  if ( mReadOnly ) {
948  return;
949  }
950 
951  d->mLocation = location;
952  d->mLocationIsRich = isRich;
953  updated();
954 }
955 
956 void Incidence::setLocation( const QString &location )
957 {
958  setLocation( location, Qt::mightBeRichText( location ) );
959 }
960 
961 QString Incidence::location() const
962 {
963  return d->mLocation;
964 }
965 
966 QString Incidence::richLocation() const
967 {
968  if ( locationIsRich() ) {
969  return d->mLocation;
970  } else {
971  return Qt::escape( d->mLocation ).replace( '\n', "<br/>" );
972  }
973 }
974 
975 bool Incidence::locationIsRich() const
976 {
977  return d->mLocationIsRich;
978 }
979 
980 void Incidence::setSchedulingID( const QString &sid )
981 {
982  d->mSchedulingID = sid;
983 }
984 
985 QString Incidence::schedulingID() const
986 {
987  if ( d->mSchedulingID.isNull() ) {
988  // Nothing set, so use the normal uid
989  return uid();
990  }
991  return d->mSchedulingID;
992 }
993 
994 bool Incidence::hasGeo() const
995 {
996  return d->mHasGeo;
997 }
998 
999 void Incidence::setHasGeo( bool hasGeo )
1000 {
1001  if ( mReadOnly ) {
1002  return;
1003  }
1004 
1005  d->mHasGeo = hasGeo;
1006  updated();
1007 }
1008 
1009 float &Incidence::geoLatitude() const
1010 {
1011  return d->mGeoLatitude;
1012 }
1013 
1014 void Incidence::setGeoLatitude( float geolatitude )
1015 {
1016  if ( mReadOnly ) {
1017  return;
1018  }
1019 
1020  d->mGeoLatitude = geolatitude;
1021  updated();
1022 }
1023 
1024 float &Incidence::geoLongitude() const
1025 {
1026  return d->mGeoLongitude;
1027 }
1028 
1029 void Incidence::setGeoLongitude( float geolongitude )
1030 {
1031  if ( mReadOnly ) {
1032  return;
1033  }
1034 
1035  d->mGeoLongitude = geolongitude;
1036  updated();
1037 }
1038 
1042 void Incidence::recurrenceUpdated( Recurrence *recurrence )
1043 {
1044  if ( recurrence == d->mRecurrence ) {
1045  updated();
1046  }
1047 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:29:14 by doxygen 1.8.3.1 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.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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