1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
/*
This file is part of KOrganizer.
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <qlistview.h>
#include <qfile.h>
#include <qdir.h>
#include <qmap.h>
#include <kglobal.h>
#include <klocale.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include <libkcal/incidence.h>
#include <libkcal/event.h>
#include <libkcal/calendar.h>
#include <libkcal/freebusy.h>
#include <libkcal/attendee.h>
#include <libkcal/calendarresources.h>
#include <libkcal/resourcecalendar.h>
#include <kresources/resourceselectdialog.h>
#ifndef KORG_NOMAIL
#include "mailscheduler.h"
#else
#include <libkcal/dummyscheduler.h>
#endif
#include "incomingdialog.h"
#include "koeventviewerdialog.h"
#include "kocounterdialog.h"
#include "koprefs.h"
#ifndef KORG_NOKABC
#include <kabc/stdaddressbook.h>
#define size count
#endif
ScheduleItemIn::ScheduleItemIn(QListView *parent,IncidenceBase *ev,
Scheduler::Method method,ScheduleMessage::Status status)
: QListViewItem(parent)
{
mIncidence = ev;
mMethod = method;
mStatus = status;
setText(6,Scheduler::translatedMethodName(mMethod)+" ");
setText(7,ScheduleMessage::statusName(status));
}
/* Visitor */
ScheduleItemVisitor::ScheduleItemVisitor(ScheduleItemIn *item)
{
mItem = item;
}
ScheduleItemVisitor::~ScheduleItemVisitor()
{
}
bool ScheduleItemVisitor::visit(Event *e)
{
mItem->setText(0,e->summary());
mItem->setText(1,e->dtStartDateStr());
if (e->doesFloat()) {
mItem->setText(2,i18n("no time "));
mItem->setText(4,i18n("no time "));
}
else {
mItem->setText(2,e->dtStartTimeStr());
mItem->setText(4,e->dtEndTimeStr());
}
if (e->hasEndDate()) {
mItem->setText(3,e->dtEndDateStr());
}
else {
mItem->setText(3,"");
}
mItem->setText(5,e->organizer()+" ");
return true;
}
bool ScheduleItemVisitor::visit(Todo *e)
{
mItem->setText(0,e->summary());
if (e->hasStartDate()) {
mItem->setText(1,e->dtStartDateStr());
if (!e->doesFloat()) {
mItem->setText(2,e->dtStartTimeStr());
}
}
if (e->hasDueDate()) {
mItem->setText(1,e->dtDueDateStr());
if (!e->doesFloat()) {
mItem->setText(2,e->dtDueTimeStr());
}
}
mItem->setText(5,e->organizer()+" ");
return true;
}
bool ScheduleItemVisitor::visit(Journal *)
{
return false;
}
/*
* Constructs a IncomingDialog which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
IncomingDialog::IncomingDialog(Calendar *calendar,OutgoingDialog *outgoing,
QWidget* parent,const char* name,bool modal,WFlags fl) :
IncomingDialog_base(parent,name,modal,fl)
{
mCalendar = calendar;
mOutgoing = outgoing;
#ifndef KORG_NOMAIL
mScheduler = new MailScheduler(mCalendar);
#else
mScheduler = new DummyScheduler(mCalendar);
#endif
mMessageListView->setColumnAlignment(1,AlignHCenter);
mMessageListView->setColumnAlignment(2,AlignHCenter);
mMessageListView->setColumnAlignment(3,AlignHCenter);
mMessageListView->setColumnAlignment(4,AlignHCenter);
QObject::connect(mMessageListView,SIGNAL(doubleClicked(QListViewItem *)),
this,SLOT(showEvent(QListViewItem *)));
retrieve();
}
/*
* Destroys the object and frees any allocated resources
*/
IncomingDialog::~IncomingDialog()
{
// no need to delete child widgets, Qt does it all for us
}
void IncomingDialog::setOutgoingDialog(OutgoingDialog *outgoing)
{
mOutgoing = outgoing;
}
void IncomingDialog::retrieve()
{
QPtrList <ScheduleMessage> messages = mScheduler->retrieveTransactions();
ScheduleMessage *message;
for(message = messages.first();message;message = messages.next()) {
IncidenceBase *inc = message->event();
Scheduler::Method method = (Scheduler::Method)message->method();
ScheduleMessage::Status status = message->status();
ScheduleItemIn *item = new ScheduleItemIn(mMessageListView,inc,method,status);
if(inc->type()!="FreeBusy") {
Incidence *incidence = static_cast<Incidence *>(inc);
ScheduleItemVisitor v(item);
if (!incidence->accept(v)) delete item;
} else {
FreeBusy *fb = static_cast<FreeBusy *>(item->event());
item->setText(0, "FreeBusy");
item->setText(1, KGlobal::locale()->formatDate( fb->dtStart().date() ) );
item->setText(2, KGlobal::locale()->formatTime( fb->dtStart().time() ) );
item->setText(3, KGlobal::locale()->formatDate( fb->dtEnd().date() ) );
item->setText(4, KGlobal::locale()->formatTime( fb->dtEnd().time() ) );
item->setText(5, fb->organizer());
}
automaticAction(item);
}
emit numMessagesChanged(mMessageListView->childCount());
}
void IncomingDialog::acceptAllMessages()
{
bool success = false;
ScheduleItemIn *item = (ScheduleItemIn *)mMessageListView->firstChild();
while(item) {
ScheduleItemIn *nextitem = (ScheduleItemIn *)(item->nextSibling());
if (acceptMessage(item)) success = true;
item = nextitem;
}
if (success) emit calendarUpdated();
}
void IncomingDialog::acceptMessage()
{
ScheduleItemIn *item = (ScheduleItemIn *)mMessageListView->selectedItem();
if (item) {
if (acceptMessage(item)) emit calendarUpdated();
}
}
bool IncomingDialog::acceptMessage(ScheduleItemIn *item)
{
switch (item->method()) {
case Scheduler::Refresh:
return incomeRefresh(item);
break;
case Scheduler::Counter:
return incomeCounter(item);
break;
case Scheduler::Declinecounter:
return incomeDeclineCounter(item);
break;
case Scheduler::Add:
return incomeAdd(item);
break;
case Scheduler::Request:
return incomeRequest(item);
break;
default:
return incomeDefault(item);
}
return false;
}
void IncomingDialog::rejectMessage()
{
ScheduleItemIn *item = (ScheduleItemIn *)mMessageListView->selectedItem();
if (item) {
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
}
}
void IncomingDialog::showEvent(QListViewItem *item)
{
IncidenceBase *incidence = ((ScheduleItemIn *)item)->event();
if( incidence && incidence->type() == "Event" ) {
Event *event = static_cast<Event *>(incidence);
KOEventViewerDialog *eventViewer = new KOEventViewerDialog(this);
eventViewer->setEvent(event);
eventViewer->show();
}
}
bool IncomingDialog::incomeRefresh(ScheduleItemIn *item)
{
Event *ev = mCalendar->event(item->event()->uid());
if (ev) {
//user interaction before??
Attendee *att;
QPtrList<Attendee> attlist = ev->attendees();
for (att=attlist.first(); att; att=attlist.next()) {
Event *event = new Event(*ev);
mOutgoing->addMessage(event,Scheduler::Request,att->email());
delete(event);
}
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return true;
}
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return false;
}
bool IncomingDialog::incomeCounter(ScheduleItemIn *item)
{
IncidenceBase *incidence = ((ScheduleItemIn *)item)->event();
// currently only events supportet - attetion at insertion below!
if ( incidence->type() != "Event" ) return false;
Event *counterEvent = static_cast<Event *>( incidence );
Event *even = mCalendar->event(counterEvent->uid());
KOCounterDialog *eventViewer = new KOCounterDialog(this);
eventViewer->addText(i18n("counter proposal event","<b>Counter-event:</b><p>"));
eventViewer->addEvent(counterEvent);
eventViewer->addText("<hr>");
eventViewer->addText(i18n("<b>Original event:</b><p>"));
if (even) eventViewer->addEvent(even);
else eventViewer->addText(i18n("A corresponding event is missing in your calendar!"));
eventViewer->addText("<hr>");
eventViewer->addText(i18n("If this counter-event is a good proposal for your event, press 'Accept'. All Attendees will then get the new version of this event"));
eventViewer->show();
eventViewer->exec();
if (eventViewer->result()) {
kdDebug() << "IncomingDialog::Counter:Accept" << endl;
int revision = 0;
if (even) {
revision = even->revision();
mCalendar->deleteEvent(even);
}
mCalendar->addIncidence(counterEvent);
even = mCalendar->event(item->event()->uid());
if (even) {
if (revision < even->revision())
even->setRevision(even->revision()+1);
else
even->setRevision(revision+1);
Event *ev = new Event(*even);
mOutgoing->addMessage(ev,Scheduler::Request);
delete(ev);
}
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return true;
} else {
kdDebug() << "IncomingDialog::Counter:Decline" << endl;
//the counter-sender's email is missing...
//now every attendee gets an declinecounter :-(
mOutgoing->addMessage(counterEvent,Scheduler::Declinecounter);
delete item;
emit numMessagesChanged(mMessageListView->childCount());
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return true;
}
//mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return false;
}
bool IncomingDialog::incomeDeclineCounter(ScheduleItemIn *item)
{
Event *even = mCalendar->event(item->event()->uid());
if (even) {
mOutgoing->addMessage(even,Scheduler::Refresh);
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return true;
}
mScheduler->deleteTransaction(item->event());
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return false;
}
bool IncomingDialog::incomeAdd(ScheduleItemIn *item)
{
IncidenceBase *incidence = ((ScheduleItemIn *)item)->event();
if (incidence->type() == "Event" ) {
Event *refr = static_cast<Event *>( incidence );
mOutgoing->addMessage(refr,Scheduler::Refresh);
mScheduler->deleteTransaction( incidence );
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return true;
}
else {
kdDebug() << "IncomingDialog::incomeAdd - only Events are supportet yet" << endl;
mScheduler->deleteTransaction( incidence );
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return false;
}
}
bool IncomingDialog::incomeDefault(ScheduleItemIn *item)
{
if (mScheduler->acceptTransaction(item->event(),item->method(),item->status())) {
delete item;
emit numMessagesChanged(mMessageListView->childCount());
return true;
}
else {
KMessageBox::error(this,i18n("Unable to accept the IMIP-message. It may be a problem with the email addresses."));
kdDebug() << "IncomingDialog::acceptMessage(): Error!" << endl;
return false;
}
return false;
}
bool IncomingDialog::incomeRequest(ScheduleItemIn *item)
{
if (item->event()->type()=="FreeBusy") {
//handel freebusy request
IncidenceBase *inc = item->event();
QDateTime start = inc->dtStart();
QDateTime end = start.addDays(inc->duration()/86400);
FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
freebusy->setOrganizer(inc->organizer());
Attendee *att = new Attendee(KOPrefs::instance()->fullName(),
KOPrefs::instance()->email());
freebusy->addAttendee(att);
kdDebug() << "calendarview: schedule_publish_freebusy: startDate: "
<< KGlobal::locale()->formatDateTime( start ) << " End Date: "
<< KGlobal::locale()->formatDateTime( end ) << endl;
if (mOutgoing->addMessage(freebusy,Scheduler::Reply)) {
delete item;
emit numMessagesChanged(mMessageListView->childCount());
delete(freebusy);
return true;
}
return false;
} else {
return incomeDefault(item);
}
return false;
}
bool IncomingDialog::automaticAction(ScheduleItemIn *item)
{
bool autoAction = false;
IncidenceBase *inc = item->event();
Scheduler::Method method = item->method();
if( inc->type()=="FreeBusy" ) {
if ( method==Scheduler::Request ) {
if ( KOPrefs::instance()->mIMIPAutoFreeBusy==KOPrefs::addressbookAuto ) {
// reply freebusy information
if ( checkOrganizerInAddressbook(inc->organizer()) ) {
incomeRequest(item);
}
} else return false;
} else {
if ( method==Scheduler::Reply ) {
if ( KOPrefs::instance()->mIMIPAutoFreeBusy==KOPrefs::addressbookAuto ) {
// insert freebusy information
//if ( checkAttendeesInAddressbook(inc) )
} else return false;
} else {
if ( method==Scheduler::Publish) {
if ( KOPrefs::instance()->mIMIPAutoFreeBusy==KOPrefs::addressbookAuto ) {
// insert freebusy information
//if ( checkOrganizerInAddressbook(inc->organizer()) )
}
} else return false;
}
}
}
if ( inc->type()=="Event" ) {
if ( method==Scheduler::Request || method==Scheduler::Publish ) {
if ( KOPrefs::instance()->mIMIPAutoInsertRequest==KOPrefs::addressbookAuto ) {
// insert event
if ( checkOrganizerInAddressbook(inc->organizer()) )
autoAction = acceptMessage(item);
} else return false;
} else {
if ( method==Scheduler::Reply ) {
if ( KOPrefs::instance()->mIMIPAutoInsertReply==KOPrefs::addressbookAuto ) {
// update event information
if ( checkAttendeesInAddressbook(inc) )
autoAction = acceptMessage(item);
} else return false;
} else {
if ( method==Scheduler::Refresh ) {
if ( KOPrefs::instance()->mIMIPAutoRefresh==KOPrefs::addressbookAuto ) {
// send refresh-information
if ( checkAttendeesInAddressbook(inc) )
autoAction = acceptMessage(item);
else return false;
} else return false;
} else return false;
}
}
}
return autoAction;
}
bool IncomingDialog::checkOrganizerInAddressbook(QString organizer)
{
bool inBook = false;
#ifndef KORG_NOKABC
KABC::AddressBook *add_book = KABC::StdAddressBook::self();
KABC::Addressee::List addressList;
addressList = add_book->findByEmail(organizer);
if ( addressList.size()>0 ) inBook = true;
#endif
return inBook;
}
bool IncomingDialog::checkAttendeesInAddressbook(IncidenceBase *inc)
{
bool inBook = false;
#ifndef KORG_NOKABC
KABC::AddressBook *add_book = KABC::StdAddressBook::self();
KABC::Addressee::List addressList;
QPtrList <Attendee> attendees;
Attendee *att;
attendees = inc->attendees();
for (att=attendees.first();att;att=attendees.next()) {
addressList = add_book->findByEmail(att->email());
if (addressList.size()>0 ) inBook = true;
}
#endif
return inBook;
}
//#include "incomingdialog.moc"
|