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

KCal Library

  • kcal
scheduler.cpp
1 /*
2  This file is part of the kcal library.
3 
4  Copyright (c) 2001,2004 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 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 */
22 
23 #include "scheduler.h"
24 #include "calendar.h"
25 #ifndef KDEPIM_NO_KRESOURCES
26 #include "calendarresources.h"
27 #endif
28 #include "event.h"
29 #include "todo.h"
30 #include "freebusy.h"
31 #include "freebusycache.h"
32 #include "icalformat.h"
33 #include "assignmentvisitor.h"
34 
35 #include <klocale.h>
36 #include <kdebug.h>
37 #include <kmessagebox.h>
38 #include <kstandarddirs.h>
39 
40 using namespace KCal;
41 
42 //@cond PRIVATE
43 class KCal::ScheduleMessage::Private
44 {
45  public:
46  Private() {}
47 
48  IncidenceBase *mIncidence;
49  iTIPMethod mMethod;
50  Status mStatus;
51  QString mError;
52 };
53 //@endcond
54 
55 ScheduleMessage::ScheduleMessage( IncidenceBase *incidence,
56  iTIPMethod method,
57  ScheduleMessage::Status status )
58  : d( new KCal::ScheduleMessage::Private )
59 {
60  d->mIncidence = incidence;
61  d->mMethod = method;
62  d->mStatus = status;
63 }
64 
65 ScheduleMessage::~ScheduleMessage()
66 {
67  delete d;
68 }
69 
70 IncidenceBase *ScheduleMessage::event()
71 {
72  return d->mIncidence;
73 }
74 
75 iTIPMethod ScheduleMessage::method()
76 {
77  return d->mMethod;
78 }
79 
80 ScheduleMessage::Status ScheduleMessage::status()
81 {
82  return d->mStatus;
83 }
84 
85 QString ScheduleMessage::statusName( ScheduleMessage::Status status )
86 {
87  switch( status ) {
88  case PublishNew:
89  return i18nc( "@item this is a new scheduling message",
90  "New Scheduling Message" );
91  case PublishUpdate:
92  return i18nc( "@item this is an update to an existing scheduling message",
93  "Updated Scheduling Message" );
94  case Obsolete:
95  return i18nc( "@item obsolete status", "Obsolete" );
96  case RequestNew:
97  return i18nc( "@item this is a request for a new scheduling message",
98  "New Scheduling Message Request" );
99  case RequestUpdate:
100  return i18nc( "@item this is a request for an update to an existing scheduling message",
101  "Updated Scheduling Message Request" );
102  default:
103  return i18nc( "@item unknown status", "Unknown Status: %1", int( status ) );
104  }
105 }
106 
107 QString ScheduleMessage::error()
108 {
109  return d->mError;
110 }
111 
112 //@cond PRIVATE
113 struct KCal::Scheduler::Private
114 {
115  Private()
116  : mFreeBusyCache( 0 )
117  {
118  }
119  FreeBusyCache *mFreeBusyCache;
120 };
121 //@endcond
122 
123 Scheduler::Scheduler( Calendar *calendar ) : d( new KCal::Scheduler::Private )
124 {
125  mCalendar = calendar;
126  mFormat = new ICalFormat();
127  mFormat->setTimeSpec( calendar->timeSpec() );
128 }
129 
130 Scheduler::~Scheduler()
131 {
132  delete mFormat;
133  delete d;
134 }
135 
136 void Scheduler::setFreeBusyCache( FreeBusyCache *c )
137 {
138  d->mFreeBusyCache = c;
139 }
140 
141 FreeBusyCache *Scheduler::freeBusyCache() const
142 {
143  return d->mFreeBusyCache;
144 }
145 
146 bool Scheduler::acceptTransaction( IncidenceBase *incidence,
147  iTIPMethod method,
148  ScheduleMessage::Status status )
149 {
150  return acceptTransaction( incidence, method, status, QString() );
151 }
152 
153 bool Scheduler::acceptTransaction( IncidenceBase *incidence,
154  iTIPMethod method,
155  ScheduleMessage::Status status,
156  const QString &email )
157 {
158  kDebug() << "method=" << methodName( method );
159 
160  switch ( method ) {
161  case iTIPPublish:
162  return acceptPublish( incidence, status, method );
163  case iTIPRequest:
164  return acceptRequest( incidence, status, email );
165  case iTIPAdd:
166  return acceptAdd( incidence, status );
167  case iTIPCancel:
168  return acceptCancel( incidence, status, email );
169  case iTIPDeclineCounter:
170  return acceptDeclineCounter( incidence, status );
171  case iTIPReply:
172  return acceptReply( incidence, status, method );
173  case iTIPRefresh:
174  return acceptRefresh( incidence, status );
175  case iTIPCounter:
176  return acceptCounter( incidence, status );
177  default:
178  break;
179  }
180  deleteTransaction( incidence );
181  return false;
182 }
183 
184 QString Scheduler::methodName( iTIPMethod method )
185 {
186  switch ( method ) {
187  case iTIPPublish:
188  return QLatin1String( "Publish" );
189  case iTIPRequest:
190  return QLatin1String( "Request" );
191  case iTIPRefresh:
192  return QLatin1String( "Refresh" );
193  case iTIPCancel:
194  return QLatin1String( "Cancel" );
195  case iTIPAdd:
196  return QLatin1String( "Add" );
197  case iTIPReply:
198  return QLatin1String( "Reply" );
199  case iTIPCounter:
200  return QLatin1String( "Counter" );
201  case iTIPDeclineCounter:
202  return QLatin1String( "Decline Counter" );
203  default:
204  return QLatin1String( "Unknown" );
205  }
206 }
207 
208 QString Scheduler::translatedMethodName( iTIPMethod method )
209 {
210  switch ( method ) {
211  case iTIPPublish:
212  return i18nc( "@item event, to-do, journal or freebusy posting", "Publish" );
213  case iTIPRequest:
214  return i18nc( "@item event, to-do or freebusy scheduling requests", "Request" );
215  case iTIPReply:
216  return i18nc( "@item event, to-do or freebusy reply to request", "Reply" );
217  case iTIPAdd:
218  return i18nc(
219  "@item event, to-do or journal additional property request", "Add" );
220  case iTIPCancel:
221  return i18nc( "@item event, to-do or journal cancellation notice", "Cancel" );
222  case iTIPRefresh:
223  return i18nc( "@item event or to-do description update request", "Refresh" );
224  case iTIPCounter:
225  return i18nc( "@item event or to-do submit counter proposal", "Counter" );
226  case iTIPDeclineCounter:
227  return i18nc( "@item event or to-do decline a counter proposal", "Decline Counter" );
228  default:
229  return i18nc( "@item no method", "Unknown" );
230  }
231 }
232 
233 bool Scheduler::deleteTransaction( IncidenceBase * )
234 {
235  return true;
236 }
237 
238 bool Scheduler::acceptPublish( IncidenceBase *newIncBase,
239  ScheduleMessage::Status status,
240  iTIPMethod method )
241 {
242  if( newIncBase->type() == "FreeBusy" ) {
243  return acceptFreeBusy( newIncBase, method );
244  }
245 
246  bool res = false;
247 
248  kDebug() << "status=" << ScheduleMessage::statusName( status );
249 
250  Incidence *newInc = static_cast<Incidence *>( newIncBase );
251  Incidence *calInc = mCalendar->incidence( newIncBase->uid() );
252  switch ( status ) {
253  case ScheduleMessage::Unknown:
254  case ScheduleMessage::PublishNew:
255  case ScheduleMessage::PublishUpdate:
256  if ( calInc && newInc ) {
257  if ( ( newInc->revision() > calInc->revision() ) ||
258  ( newInc->revision() == calInc->revision() &&
259  newInc->lastModified() > calInc->lastModified() ) ) {
260  AssignmentVisitor visitor;
261  const QString oldUid = calInc->uid();
262  if ( !visitor.assign( calInc, newInc ) ) {
263  kError() << "assigning different incidence types";
264  } else {
265  calInc->setSchedulingID( newInc->uid() );
266  calInc->setUid( oldUid );
267  res = true;
268  }
269  }
270  }
271  break;
272  case ScheduleMessage::Obsolete:
273  res = true;
274  break;
275  default:
276  break;
277  }
278  deleteTransaction( newIncBase );
279  return res;
280 }
281 
282 bool Scheduler::acceptRequest( IncidenceBase *incidence,
283  ScheduleMessage::Status status )
284 {
285  return acceptRequest( incidence, status, QString() );
286 }
287 
288 bool Scheduler::acceptRequest( IncidenceBase *incidence,
289  ScheduleMessage::Status status,
290  const QString &email )
291 {
292  Incidence *inc = static_cast<Incidence *>( incidence );
293  if ( !inc ) {
294  return false;
295  }
296  if ( inc->type() == "FreeBusy" ) {
297  // reply to this request is handled in korganizer's incomingdialog
298  return true;
299  }
300 
301  const Incidence::List existingIncidences = mCalendar->incidencesFromSchedulingID( inc->uid() );
302  kDebug() << "status=" << ScheduleMessage::statusName( status )
303  << ": found " << existingIncidences.count()
304  << " incidences with schedulingID " << inc->schedulingID();
305  Incidence::List::ConstIterator incit = existingIncidences.begin();
306  for ( ; incit != existingIncidences.end() ; ++incit ) {
307  Incidence *i = *incit;
308  kDebug() << "Considering this found event ("
309  << ( i->isReadOnly() ? "readonly" : "readwrite" )
310  << ") :" << mFormat->toString( i );
311  // If it's readonly, we can't possible update it.
312  if ( i->isReadOnly() ) {
313  continue;
314  }
315  if ( i->revision() <= inc->revision() ) {
316  // The new incidence might be an update for the found one
317  bool isUpdate = true;
318  // Code for new invitations:
319  // If you think we could check the value of "status" to be RequestNew: we can't.
320  // It comes from a similar check inside libical, where the event is compared to
321  // other events in the calendar. But if we have another version of the event around
322  // (e.g. shared folder for a group), the status could be RequestNew, Obsolete or Updated.
323  kDebug() << "looking in " << i->uid() << "'s attendees";
324  // This is supposed to be a new request, not an update - however we want to update
325  // the existing one to handle the "clicking more than once on the invitation" case.
326  // So check the attendee status of the attendee.
327  const KCal::Attendee::List attendees = i->attendees();
328  KCal::Attendee::List::ConstIterator ait;
329  for ( ait = attendees.begin(); ait != attendees.end(); ++ait ) {
330  if( (*ait)->email() == email && (*ait)->status() == Attendee::NeedsAction ) {
331  // This incidence wasn't created by me - it's probably in a shared folder
332  // and meant for someone else, ignore it.
333  kDebug() << "ignoring " << i->uid() << " since I'm still NeedsAction there";
334  isUpdate = false;
335  break;
336  }
337  }
338  if ( isUpdate ) {
339  if ( i->revision() == inc->revision() &&
340  i->lastModified() > inc->lastModified() ) {
341  // This isn't an update - the found incidence was modified more recently
342  kDebug() << "This isn't an update - the found incidence was modified more recently";
343  deleteTransaction( i );
344  return false;
345  }
346  kDebug() << "replacing existing incidence " << i->uid();
347  bool res = true;
348  AssignmentVisitor visitor;
349  const QString oldUid = i->uid();
350  if ( !visitor.assign( i, inc ) ) {
351  kError() << "assigning different incidence types";
352  res = false;
353  } else {
354  i->setUid( oldUid );
355  i->setSchedulingID( inc->uid() );
356  }
357  deleteTransaction( incidence );
358  return res;
359  }
360  } else {
361  // This isn't an update - the found incidence has a bigger revision number
362  kDebug() << "This isn't an update - the found incidence has a bigger revision number";
363  deleteTransaction( incidence );
364  return false;
365  }
366  }
367 
368  // Move the uid to be the schedulingID and make a unique UID
369  inc->setSchedulingID( inc->uid() );
370  inc->setUid( CalFormat::createUniqueId() );
371  // in case this is an update and we didn't find the to-be-updated incidence,
372  // ask whether we should create a new one, or drop the update
373  if ( existingIncidences.count() > 0 || inc->revision() == 0 ||
374  KMessageBox::questionYesNo(
375  0,
376  i18nc( "@info",
377  "The event, to-do or journal to be updated could not be found. "
378  "Maybe it has already been deleted, or the calendar that "
379  "contains it is disabled. Press 'Store' to create a new "
380  "one or 'Throw away' to discard this update." ),
381  i18nc( "@title", "Discard this update?" ),
382  KGuiItem( i18nc( "@option", "Store" ) ),
383  KGuiItem( i18nc( "@option", "Throw away" ) ),
384  "AcceptCantFindIncidence" ) == KMessageBox::Yes ) {
385  kDebug() << "Storing new incidence with scheduling uid=" << inc->schedulingID()
386  << " and uid=" << inc->uid();
387 
388 #ifndef KDEPIM_NO_KRESOURCES
389  CalendarResources *stdcal = dynamic_cast<CalendarResources *>( mCalendar );
390  if( stdcal && !stdcal->hasCalendarResources() ) {
391  KMessageBox::sorry(
392  0,
393  i18nc( "@info", "No calendars found, unable to save the invitation." ) );
394  return false;
395  }
396 
397  // FIXME: This is a nasty hack, since we need to set a parent for the
398  // resource selection dialog. However, we don't have any UI methods
399  // in the calendar, only in the CalendarResources::DestinationPolicy
400  // So we need to type-cast it and extract it from the CalendarResources
401  QWidget *tmpparent = 0;
402  if ( stdcal ) {
403  tmpparent = stdcal->dialogParentWidget();
404  stdcal->setDialogParentWidget( 0 );
405  }
406 #endif
407 
408  TryAgain:
409  bool success = false;
410 #ifndef KDEPIM_NO_KRESOURCES
411  if ( stdcal )
412  success = stdcal->addIncidence( inc );
413  else
414 #endif
415  success = mCalendar->addIncidence( inc );
416 
417  if ( !success ) {
418 #ifndef KDEPIM_NO_KRESOURCES
419  ErrorFormat *e = stdcal ? stdcal->exception() : 0;
420 #else
421  ErrorFormat *e = 0;
422 #endif
423 
424  if ( e && e->errorCode() == KCal::ErrorFormat::UserCancel &&
425  KMessageBox::warningYesNo(
426  0,
427  i18nc( "@info",
428  "You canceled the save operation. Therefore, the appointment will not be "
429  "stored in your calendar even though you accepted the invitation. "
430  "Are you certain you want to discard this invitation? " ),
431  i18nc( "@title", "Discard this invitation?" ),
432  KGuiItem( i18nc( "@option", "Discard" ) ),
433  KGuiItem( i18nc( "@option", "Go Back to Folder Selection" ) ) ) == KMessageBox::Yes ) {
434  KMessageBox::information(
435  0,
436  i18nc( "@info",
437  "The invitation \"%1\" was not saved to your calendar "
438  "but you are still listed as an attendee for that appointment.\n"
439  "If you mistakenly accepted the invitation or do not plan to attend, please "
440  "notify the organizer %2 and ask them to remove you from the attendee list.",
441  inc->summary(), inc->organizer().fullName() ) );
442  deleteTransaction( incidence );
443  return true;
444  } else {
445  goto TryAgain;
446  }
447 
448  // We can have a failure if the user pressed [cancel] in the resource
449  // selectdialog, so check the exception.
450  if ( !e ||
451  ( e && ( e->errorCode() != KCal::ErrorFormat::UserCancel &&
452  e->errorCode() != KCal::ErrorFormat::NoWritableFound ) ) ) {
453  QString errMessage = i18nc( "@info", "Unable to save %1 \"%2\".",
454  i18n( inc->type() ), inc->summary() );
455  KMessageBox::sorry( 0, errMessage );
456  }
457  return false;
458  }
459  }
460  deleteTransaction( incidence );
461  return true;
462 }
463 
464 bool Scheduler::acceptAdd( IncidenceBase *incidence, ScheduleMessage::Status /* status */)
465 {
466  deleteTransaction( incidence );
467  return false;
468 }
469 
470 bool Scheduler::acceptCancel( IncidenceBase *incidence,
471  ScheduleMessage::Status status,
472  const QString &attendee )
473 {
474  Incidence *inc = static_cast<Incidence *>( incidence );
475  if ( !inc ) {
476  return false;
477  }
478 
479  if ( inc->type() == "FreeBusy" ) {
480  // reply to this request is handled in korganizer's incomingdialog
481  return true;
482  }
483 
484  const Incidence::List existingIncidences = mCalendar->incidencesFromSchedulingID( inc->uid() );
485  kDebug() << "Scheduler::acceptCancel="
486  << ScheduleMessage::statusName( status )
487  << ": found " << existingIncidences.count()
488  << " incidences with schedulingID " << inc->schedulingID();
489 
490  bool ret = false;
491  Incidence::List::ConstIterator incit = existingIncidences.begin();
492  for ( ; incit != existingIncidences.end() ; ++incit ) {
493  Incidence *i = *incit;
494  kDebug() << "Considering this found event ("
495  << ( i->isReadOnly() ? "readonly" : "readwrite" )
496  << ") :" << mFormat->toString( i );
497 
498  // If it's readonly, we can't possible remove it.
499  if ( i->isReadOnly() ) {
500  continue;
501  }
502 
503  // Code for new invitations:
504  // We cannot check the value of "status" to be RequestNew because
505  // "status" comes from a similar check inside libical, where the event
506  // is compared to other events in the calendar. But if we have another
507  // version of the event around (e.g. shared folder for a group), the
508  // status could be RequestNew, Obsolete or Updated.
509  kDebug() << "looking in " << i->uid() << "'s attendees";
510 
511  // This is supposed to be a new request, not an update - however we want
512  // to update the existing one to handle the "clicking more than once
513  // on the invitation" case. So check the attendee status of the attendee.
514  bool isMine = true;
515  const KCal::Attendee::List attendees = i->attendees();
516  KCal::Attendee::List::ConstIterator ait;
517  for ( ait = attendees.begin(); ait != attendees.end(); ++ait ) {
518  if ( (*ait)->email() == attendee &&
519  (*ait)->status() == Attendee::NeedsAction ) {
520  // This incidence wasn't created by me - it's probably in a shared
521  // folder and meant for someone else, ignore it.
522  kDebug() << "ignoring " << i->uid()
523  << " since I'm still NeedsAction there";
524  isMine = false;
525  break;
526  }
527  }
528 
529  if ( isMine ) {
530  kDebug() << "removing existing incidence " << i->uid();
531  if ( i->type() == "Event" ) {
532  Event *event = mCalendar->event( i->uid() );
533  ret = ( event && mCalendar->deleteEvent( event ) );
534  } else if ( i->type() == "Todo" ) {
535  Todo *todo = mCalendar->todo( i->uid() );
536  ret = ( todo && mCalendar->deleteTodo( todo ) );
537  }
538  deleteTransaction( incidence );
539  return ret;
540  }
541  }
542 
543  // in case we didn't find the to-be-removed incidence
544  if ( existingIncidences.count() > 0 && inc->revision() > 0 ) {
545  KMessageBox::information(
546  0,
547  i18nc( "@info",
548  "The event or task could not be removed from your calendar. "
549  "Maybe it has already been deleted or is not owned by you. "
550  "Or it might belong to a read-only or disabled calendar." ) );
551  }
552  deleteTransaction( incidence );
553  return ret;
554 }
555 
556 bool Scheduler::acceptCancel( IncidenceBase *incidence,
557  ScheduleMessage::Status status )
558 {
559  Q_UNUSED( status );
560 
561  const IncidenceBase *toDelete = mCalendar->incidenceFromSchedulingID( incidence->uid() );
562 
563  bool ret = true;
564  if ( toDelete ) {
565  if ( toDelete->type() == "Event" ) {
566  Event *event = mCalendar->event( toDelete->uid() );
567  ret = ( event && mCalendar->deleteEvent( event ) );
568  } else if ( toDelete->type() == "Todo" ) {
569  Todo *todo = mCalendar->todo( toDelete->uid() );
570  ret = ( todo && mCalendar->deleteTodo( todo ) );
571  }
572  } else {
573  // only complain if we failed to determine the toDelete incidence
574  // on non-initial request.
575  Incidence *inc = static_cast<Incidence *>( incidence );
576  if ( inc->revision() > 0 ) {
577  ret = false;
578  }
579  }
580 
581  if ( !ret ) {
582  KMessageBox::information(
583  0,
584  i18nc( "@info",
585  "The event or task to be canceled could not be removed from your calendar. "
586  "Maybe it has already been deleted or is not owned by you. "
587  "Or it might belong to a read-only or disabled calendar." ) );
588  }
589  deleteTransaction( incidence );
590  return ret;
591 }
592 
593 bool Scheduler::acceptDeclineCounter( IncidenceBase *incidence,
594  ScheduleMessage::Status status )
595 {
596  Q_UNUSED( status );
597  deleteTransaction( incidence );
598  return false;
599 }
600 
601 bool Scheduler::acceptReply( IncidenceBase *incidence,
602  ScheduleMessage::Status status,
603  iTIPMethod method )
604 {
605  Q_UNUSED( status );
606  if ( incidence->type() == "FreeBusy" ) {
607  return acceptFreeBusy( incidence, method );
608  }
609  bool ret = false;
610  Event *ev = mCalendar->event( incidence->uid() );
611  Todo *to = mCalendar->todo( incidence->uid() );
612 
613  // try harder to find the correct incidence
614  if ( !ev && !to ) {
615  const Incidence::List list = mCalendar->incidences();
616  for ( Incidence::List::ConstIterator it=list.constBegin(), end=list.constEnd();
617  it != end; ++it ) {
618  if ( (*it)->schedulingID() == incidence->uid() ) {
619  ev = dynamic_cast<Event*>( *it );
620  to = dynamic_cast<Todo*>( *it );
621  break;
622  }
623  }
624  }
625 
626  if ( ev || to ) {
627  //get matching attendee in calendar
628  kDebug() << "match found!";
629  Attendee::List attendeesIn = incidence->attendees();
630  Attendee::List attendeesEv;
631  Attendee::List attendeesNew;
632  if ( ev ) {
633  attendeesEv = ev->attendees();
634  }
635  if ( to ) {
636  attendeesEv = to->attendees();
637  }
638  Attendee::List::ConstIterator inIt;
639  Attendee::List::ConstIterator evIt;
640  for ( inIt = attendeesIn.constBegin(); inIt != attendeesIn.constEnd(); ++inIt ) {
641  Attendee *attIn = *inIt;
642  bool found = false;
643  for ( evIt = attendeesEv.constBegin(); evIt != attendeesEv.constEnd(); ++evIt ) {
644  Attendee *attEv = *evIt;
645  if ( attIn->email().toLower() == attEv->email().toLower() ) {
646  //update attendee-info
647  kDebug() << "update attendee";
648  attEv->setStatus( attIn->status() );
649  attEv->setDelegate( attIn->delegate() );
650  attEv->setDelegator( attIn->delegator() );
651  ret = true;
652  found = true;
653  }
654  }
655  if ( !found && attIn->status() != Attendee::Declined ) {
656  attendeesNew.append( attIn );
657  }
658  }
659 
660  bool attendeeAdded = false;
661  for ( Attendee::List::ConstIterator it = attendeesNew.constBegin();
662  it != attendeesNew.constEnd(); ++it ) {
663  Attendee *attNew = *it;
664  QString msg =
665  i18nc( "@info", "%1 wants to attend %2 but was not invited.",
666  attNew->fullName(),
667  ( ev ? ev->summary() : to->summary() ) );
668  if ( !attNew->delegator().isEmpty() ) {
669  msg = i18nc( "@info", "%1 wants to attend %2 on behalf of %3.",
670  attNew->fullName(),
671  ( ev ? ev->summary() : to->summary() ), attNew->delegator() );
672  }
673  if ( KMessageBox::questionYesNo(
674  0, msg, i18nc( "@title", "Uninvited attendee" ),
675  KGuiItem( i18nc( "@option", "Accept Attendance" ) ),
676  KGuiItem( i18nc( "@option", "Reject Attendance" ) ) ) != KMessageBox::Yes ) {
677  KCal::Incidence *cancel = dynamic_cast<Incidence*>( incidence );
678  if ( cancel ) {
679  cancel->addComment(
680  i18nc( "@info",
681  "The organizer rejected your attendance at this meeting." ) );
682  }
683  performTransaction( cancel ? cancel : incidence, iTIPCancel, attNew->fullName() );
684  // ### can't delete cancel here because it is aliased to incidence which
685  // is accessed in the next loop iteration (CID 4232)
686  // delete cancel;
687  continue;
688  }
689 
690  Attendee *a = new Attendee( attNew->name(), attNew->email(), attNew->RSVP(),
691  attNew->status(), attNew->role(), attNew->uid() );
692  a->setDelegate( attNew->delegate() );
693  a->setDelegator( attNew->delegator() );
694  if ( ev ) {
695  ev->addAttendee( a );
696  } else if ( to ) {
697  to->addAttendee( a );
698  }
699  ret = true;
700  attendeeAdded = true;
701  }
702 
703  // send update about new participants
704  if ( attendeeAdded ) {
705  bool sendMail = false;
706  if ( ev || to ) {
707  if ( KMessageBox::questionYesNo(
708  0,
709  i18nc( "@info",
710  "An attendee was added to the incidence. "
711  "Do you want to email the attendees an update message?" ),
712  i18nc( "@title", "Attendee Added" ),
713  KGuiItem( i18nc( "@option", "Send Messages" ) ),
714  KGuiItem( i18nc( "@option", "Do Not Send" ) ) ) == KMessageBox::Yes ) {
715  sendMail = true;
716  }
717  }
718 
719  if ( ev ) {
720  ev->setRevision( ev->revision() + 1 );
721  if ( sendMail ) {
722  performTransaction( ev, iTIPRequest );
723  }
724  }
725  if ( to ) {
726  to->setRevision( to->revision() + 1 );
727  if ( sendMail ) {
728  performTransaction( to, iTIPRequest );
729  }
730  }
731  }
732 
733  if ( ret ) {
734  // We set at least one of the attendees, so the incidence changed
735  // Note: This should not result in a sequence number bump
736  if ( ev ) {
737  ev->updated();
738  } else if ( to ) {
739  to->updated();
740  }
741  }
742  if ( to ) {
743  // for VTODO a REPLY can be used to update the completion status of
744  // a to-do. see RFC2446 3.4.3
745  Todo *update = dynamic_cast<Todo*> ( incidence );
746  Q_ASSERT( update );
747  if ( update && ( to->percentComplete() != update->percentComplete() ) ) {
748  to->setPercentComplete( update->percentComplete() );
749  to->updated();
750  }
751  }
752  } else {
753  kError() << "No incidence for scheduling.";
754  }
755 
756  if ( ret ) {
757  deleteTransaction( incidence );
758  }
759  return ret;
760 }
761 
762 bool Scheduler::acceptRefresh( IncidenceBase *incidence, ScheduleMessage::Status status )
763 {
764  Q_UNUSED( status );
765  // handled in korganizer's IncomingDialog
766  deleteTransaction( incidence );
767  return false;
768 }
769 
770 bool Scheduler::acceptCounter( IncidenceBase *incidence, ScheduleMessage::Status status )
771 {
772  Q_UNUSED( status );
773  deleteTransaction( incidence );
774  return false;
775 }
776 
777 bool Scheduler::acceptFreeBusy( IncidenceBase *incidence, iTIPMethod method )
778 {
779  if ( !d->mFreeBusyCache ) {
780  kError() << "KCal::Scheduler: no FreeBusyCache.";
781  return false;
782  }
783 
784  FreeBusy *freebusy = static_cast<FreeBusy *>(incidence);
785 
786  kDebug() << "freeBusyDirName:" << freeBusyDir();
787 
788  Person from;
789  if( method == iTIPPublish ) {
790  from = freebusy->organizer();
791  }
792  if ( ( method == iTIPReply ) && ( freebusy->attendeeCount() == 1 ) ) {
793  Attendee *attendee = freebusy->attendees().first();
794  from.setName( attendee->name() );
795  from.setEmail( attendee->email() );
796  }
797 
798  if ( !d->mFreeBusyCache->saveFreeBusy( freebusy, from ) ) {
799  return false;
800  }
801 
802  deleteTransaction( incidence );
803  return true;
804 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 11 2012 12:15:49 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