25 #include "incidencechanger.h"
26 #include "koglobals.h"
28 #include "kogroupware.h"
29 #include "mailscheduler.h"
31 #include <libkcal/freebusy.h>
32 #include <libkcal/dndfactory.h>
34 #include <tdemessagebox.h>
35 #include <tdelocale.h>
37 bool IncidenceChanger::beginChange(
Incidence *incidence,
44 kdDebug(5850) <<
"IncidenceChanger::beginChange for incidence \""
45 << incidence->
summary() <<
"\"" << endl;
52 return calRes->
beginChange( incidence, res, subRes );
55 bool IncidenceChanger::sendGroupwareMessage(
Incidence *incidence,
57 KOGlobals::HowChanged action,
60 if ( KOPrefs::instance()->thatIsMe( incidence->organizer().email() ) && incidence->
attendeeCount()>0
61 && !KOPrefs::instance()->mUseGroupwareCommunication ) {
62 emit schedule( method, incidence );
64 }
else if( KOPrefs::instance()->mUseGroupwareCommunication ) {
66 KOGroupware::instance()->sendICalMessage( parent, method, incidence, action,
false );
71 void IncidenceChanger::cancelAttendees(
Incidence *incidence )
73 if ( KOPrefs::instance()->mUseGroupwareCommunication ) {
74 if ( KMessageBox::questionYesNo( 0, i18n(
"Some attendees were removed "
75 "from the incidence. Shall cancel messages be sent to these attendees?"),
76 i18n(
"Attendees Removed" ), i18n(
"Send Messages"), i18n(
"Do Not Send") ) == KMessageBox::Yes ) {
84 KCal::MailScheduler scheduler( mCalendar );
85 scheduler.performTransaction( incidence, Scheduler::Cancel );
90 bool IncidenceChanger::endChange(
Incidence *incidence,
103 kdDebug(5850) <<
"IncidenceChanger::endChange for incidence \""
104 << incidence->
summary() <<
"\"" << endl;
111 return calRes->
endChange( incidence, res, subRes );
114 bool IncidenceChanger::deleteIncidence(
Incidence *incidence, TQWidget *parent )
116 if ( !incidence )
return true;
117 kdDebug(5850)<<
"IncidenceChanger::deleteIncidence for incidence \""<<incidence->
summary()<<
"\""<<endl;
118 bool doDelete = sendGroupwareMessage( incidence, KCal::Scheduler::Cancel,
119 KOGlobals::INCIDENCEDELETED, parent );
123 emit incidenceToBeDeleted( incidence );
124 doDelete = mCalendar->deleteIncidence( incidence );
125 if ( !KOPrefs::instance()->thatIsMe( tmp->organizer().email() ) ) {
126 const TQStringList myEmails = KOPrefs::instance()->allEmails();
127 bool notifyOrganizer =
false;
128 for ( TQStringList::ConstIterator it = myEmails.begin(); it != myEmails.end(); ++it ) {
129 TQString email = *it;
132 if ( me->
status() == KCal::Attendee::Accepted || me->
status() == KCal::Attendee::Delegated )
133 notifyOrganizer =
true;
135 newMe->
setStatus( KCal::Attendee::Declined );
142 if ( !KOGroupware::instance()->doNotNotify() && notifyOrganizer ) {
143 KCal::MailScheduler scheduler( mCalendar );
144 scheduler.performTransaction( tmp, Scheduler::Reply );
147 KOGroupware::instance()->setDoNotNotify(
false );
149 emit incidenceDeleted( incidence );
154 bool IncidenceChanger::cutIncidences(
const Incidence::List &incidences,
157 Incidence::List::ConstIterator it;
158 bool doDelete =
true;
159 Incidence::List incsToCut;
160 for ( it = incidences.constBegin(); it != incidences.constEnd(); ++it ) {
162 doDelete = sendGroupwareMessage( *it, KCal::Scheduler::Cancel,
163 KOGlobals::INCIDENCEDELETED, parent );
165 emit incidenceToBeDeleted( *it );
166 incsToCut.append( *it );
173 if ( factory.cutIncidences( incsToCut ) ) {
174 for ( it = incsToCut.constBegin(); it != incsToCut.constEnd(); ++it ) {
175 emit incidenceDeleted( *it );
177 return !incsToCut.isEmpty();
183 bool IncidenceChanger::cutIncidence(
Incidence *incidence, TQWidget *parent )
185 Incidence::List incidences;
186 incidences.append( incidence );
187 return cutIncidences( incidences, parent );
198 return incidence->
accept( *
this );
205 Event *ev2 =
dynamic_cast<Event*
>(mIncidence2);
206 if ( event && ev2 ) {
207 return *
event == *ev2;
210 return ( ev2 == event );
215 Todo *to2 =
dynamic_cast<Todo*
>( mIncidence2 );
217 return *todo == *to2;
220 return ( todo == to2 );
226 if ( journal && j2 ) {
227 return *journal == *j2;
230 return ( journal == j2 );
240 return ( fb2 == fb );
256 return incidence->
accept( *
this );
263 Event *ev2 =
dynamic_cast<Event*
>( mIncidence2 );
264 if ( event && ev2 ) {
273 Todo *to2 =
dynamic_cast<Todo*
>( mIncidence2 );
284 if ( journal && j2 ) {
309 return ( v.act( inc1, inc2 ) );
315 return v.act( inc1, inc2 );
318 bool IncidenceChanger::myAttendeeStatusChanged(
Incidence *oldInc,
Incidence *newInc )
322 if ( oldMe && newMe && ( oldMe->
status() != newMe->
status() ) )
329 KOGlobals::WhatChanged action,
332 return changeIncidence( oldinc, newinc, action, parent, 0 );
336 KOGlobals::WhatChanged action,
338 int dontAskForGroupware )
340 kdDebug(5850)<<
"IncidenceChanger::changeIncidence for incidence \""<<newinc->
summary()<<
"\" ( old one was \""<<oldinc->
summary()<<
"\")"<<endl;
341 if ( incidencesEqual( newinc, oldinc ) ) {
343 kdDebug(5850) <<
"Incidence not changed\n";
345 kdDebug(5850) <<
"Incidence changed\n";
346 bool attendeeStatusChanged = myAttendeeStatusChanged( oldinc, newinc );
354 if ( KOPrefs::instance()->mUseGroupwareCommunication ) {
355 success = KOGroupware::instance()->sendICalMessage(
357 KCal::Scheduler::Request,
358 newinc, KOGlobals::INCIDENCEEDITED, attendeeStatusChanged, dontAskForGroupware );
363 emit incidenceChanged( oldinc, newinc, action );
366 assignIncidence( newinc, oldinc );
373 bool IncidenceChanger::addIncidence(
Incidence *incidence,
377 return addIncidence( incidence, res, subRes, parent, 0 );
380 bool IncidenceChanger::addIncidence(
Incidence *incidence,
382 TQWidget *parent,
int dontAskForGroupware )
385 if( stdcal && !stdcal->hasCalendarResources() ) {
388 i18n(
"No calendars found, unable to save %1 \"%2\"." ).
389 arg( i18n( incidence->type() ) ).
391 kdDebug(5850) <<
"IncidenceChanger: No calendars found" << endl;
399 TQWidget *tmpparent = 0;
408 TQString pSubRes = subRes;
412 pRes = stdcal->
resource( incidence );
414 pResName = pRes->resourceName();
423 bool success =
false;
425 success = stdcal->
addIncidence( incidence, pRes, pSubRes );
427 success = mCalendar->addIncidence( incidence );
438 if ( pResName.isEmpty() ) {
439 errMessage = i18n(
"Unable to save %1 \"%2\"." ).
440 arg( i18n( incidence->type() ) ).
443 errMessage = i18n(
"Unable to save %1 \"%2\" to calendar %3." ).
444 arg( i18n( incidence->type() ) ).
448 KMessageBox::sorry( parent, errMessage );
450 kdDebug(5850) <<
"IncidenceChanger: Can't add incidence" << endl;
454 if ( KOPrefs::instance()->mUseGroupwareCommunication ) {
455 if ( !KOGroupware::instance()->sendICalMessage(
457 KCal::Scheduler::Request,
458 incidence, KOGlobals::INCIDENCEADDED,
false, dontAskForGroupware ) ) {
461 i18n(
"Attempt to send the scheduling message failed. "
462 "Please check your Group Scheduling settings. "
463 "Contact your system administrator for more help.") );
467 emit incidenceAdded( incidence );
472 #include "incidencechanger.moc"
473 #include "incidencechangerbase.moc"
void setStatus(PartStat s)
ResourceCalendar * resource(Incidence *incidence)
void setDialogParentWidget(TQWidget *parent)
bool addIncidence(Incidence *incidence)
TDE_DEPRECATED bool beginChange(Incidence *incidence)
TQWidget * dialogParentWidget()
TDE_DEPRECATED bool endChange(Incidence *incidence)
ErrorFormat * exception() const
virtual bool visit(Event *)
int attendeeCount() const
Attendee * attendeeByMail(const TQString &) const
Attendee * attendeeByMails(const TQStringList &, const TQString &email=TQString()) const
virtual bool accept(Visitor &)
void addAttendee(Attendee *attendee, bool doUpdate=true)
virtual Incidence * clone()=0
void setRevision(int rev)
virtual TQString subresourceIdentifier(Incidence *incidence)
virtual bool subresourceWritable(const TQString &) const
virtual bool canHaveSubresources() const
virtual const TQString labelForSubresource(const TQString &resource) const