Diffstat (limited to 'korganizer/koeventviewer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/koeventviewer.cpp | 510 |
1 files changed, 510 insertions, 0 deletions
diff --git a/korganizer/koeventviewer.cpp b/korganizer/koeventviewer.cpp new file mode 100644 index 0000000..9f8bd9b --- a/dev/null +++ b/korganizer/koeventviewer.cpp | |||
@@ -0,0 +1,510 @@ | |||
1 | /* | ||
2 | This file is part of KOrganizer. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #include <qcstring.h> | ||
21 | #include <qwhatsthis.h> | ||
22 | #include <qdialog.h> | ||
23 | #include <qapplication.h> | ||
24 | #include <qlabel.h> | ||
25 | #include <qlayout.h> | ||
26 | |||
27 | #include <klocale.h> | ||
28 | #include <kapplication.h> | ||
29 | #include <libkcal/event.h> | ||
30 | #include <libkcal/todo.h> | ||
31 | #include <kdebug.h> | ||
32 | #include <kiconloader.h> | ||
33 | #include <krun.h> | ||
34 | #include <kglobal.h> | ||
35 | #include <kprocess.h> | ||
36 | #include "koprefs.h" | ||
37 | |||
38 | #include <libkdepim/addresseeview.h> | ||
39 | #include <kabc/stdaddressbook.h> | ||
40 | |||
41 | #ifndef KORG_NODCOP | ||
42 | #include <dcopclient.h> | ||
43 | #include "korganizer.h" | ||
44 | #include "koprefs.h" | ||
45 | #include "actionmanager.h" | ||
46 | #endif | ||
47 | |||
48 | #include "koeventviewer.h" | ||
49 | #include "koeventviewer.moc" | ||
50 | #ifndef KORG_NOKABC | ||
51 | #include <kabc/stdaddressbook.h> | ||
52 | #define size count | ||
53 | #endif | ||
54 | KOEventViewer::KOEventViewer(QWidget *parent,const char *name) | ||
55 | : QTextBrowser(parent,name) | ||
56 | { | ||
57 | mSyncMode = false; | ||
58 | mColorMode = 0; | ||
59 | } | ||
60 | |||
61 | KOEventViewer::~KOEventViewer() | ||
62 | { | ||
63 | } | ||
64 | |||
65 | void KOEventViewer::setSource(const QString& n) | ||
66 | { | ||
67 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | ||
68 | KABC::AddressBook::Iterator it; | ||
69 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | ||
70 | // LR I do not understand, why the uid string is different on zaurus and desktop | ||
71 | #ifdef DESKTOP_VERSION | ||
72 | QString uid = "uid://"+(*it).uid(); | ||
73 | #else | ||
74 | QString uid = "uid:"+(*it).uid(); | ||
75 | #endif | ||
76 | //qDebug("for *%s* +%s+ ", n.latin1(), uid.latin1()); | ||
77 | if (n == uid ) { | ||
78 | //qDebug("found %s ",(*it).mobileHomePhone().latin1() ); | ||
79 | QDialog dia( this,"dia123", true ); | ||
80 | dia.setCaption( i18n("Details of attendee") ); | ||
81 | QVBoxLayout lay ( &dia ); | ||
82 | KPIM::AddresseeView av ( &dia ); | ||
83 | av.setAddressee( (*it) ); | ||
84 | lay.addWidget( &av ); | ||
85 | if ( QApplication::desktop()->width() < 480 ) | ||
86 | dia.resize( 220, 240); | ||
87 | else { | ||
88 | dia.resize( 400,400); | ||
89 | |||
90 | } | ||
91 | dia.exec(); | ||
92 | break; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | |||
97 | #ifndef KORG_NODCOP | ||
98 | kdDebug() << "KOEventViewer::setSource(): " << n << endl; | ||
99 | QString tmpStr; | ||
100 | if (n.startsWith("mailto:")) { | ||
101 | KApplication::kApplication()->invokeMailer(n.mid(7),QString::null); | ||
102 | //emit showIncidence(n); | ||
103 | return; | ||
104 | } else if (n.startsWith("uid:")) { | ||
105 | DCOPClient *client = KApplication::kApplication()->dcopClient(); | ||
106 | const QByteArray noParamData; | ||
107 | const QByteArray paramData; | ||
108 | QByteArray replyData; | ||
109 | QCString replyTypeStr; | ||
110 | #define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()", noParamData, replyTypeStr, replyData)) | ||
111 | bool foundAbbrowser = PING_ABBROWSER; | ||
112 | |||
113 | if (foundAbbrowser) { | ||
114 | //KAddressbook is already running, so just DCOP to it to bring up the contact editor | ||
115 | //client->send("kaddressbook","KAddressBookIface", | ||
116 | QDataStream arg(paramData, IO_WriteOnly); | ||
117 | arg << n.mid(6); | ||
118 | client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )", paramData); | ||
119 | return; | ||
120 | } else { | ||
121 | /* | ||
122 | KaddressBook is not already running. Pass it the UID of the contact via the command line while starting it - its neater. | ||
123 | We start it without its main interface | ||
124 | */ | ||
125 | KIconLoader* iconLoader = new KIconLoader(); | ||
126 | QString iconPath = iconLoader->iconPath("go",KIcon::Small); | ||
127 | ActionManager::setStartedKAddressBook(true); | ||
128 | tmpStr = "kaddressbook --editor-only --uid "; | ||
129 | tmpStr += KProcess::quote(n.mid(6)); | ||
130 | KRun::runCommand(tmpStr,"KAddressBook",iconPath); | ||
131 | return; | ||
132 | } | ||
133 | } else { | ||
134 | //QTextBrowser::setSource(n); | ||
135 | } | ||
136 | #endif | ||
137 | } | ||
138 | |||
139 | void KOEventViewer::addTag(const QString & tag,const QString & text) | ||
140 | { | ||
141 | int number=text.contains("\n"); | ||
142 | QString str = "<" + tag + ">"; | ||
143 | QString tmpText=text; | ||
144 | QString tmpStr=str; | ||
145 | if(number !=-1) | ||
146 | { | ||
147 | if (number > 0) { | ||
148 | int pos=0; | ||
149 | QString tmp; | ||
150 | for(int i=0;i<=number;i++) { | ||
151 | pos=tmpText.find("\n"); | ||
152 | tmp=tmpText.left(pos); | ||
153 | tmpText=tmpText.right(tmpText.length()-pos-1); | ||
154 | tmpStr+=tmp+"<br>"; | ||
155 | } | ||
156 | } | ||
157 | else tmpStr += tmpText; | ||
158 | tmpStr+="</" + tag + ">"; | ||
159 | mText.append(tmpStr); | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | str += text + "</" + tag + ">"; | ||
164 | mText.append(str); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | void KOEventViewer::setColorMode( int m ) | ||
169 | { | ||
170 | mColorMode = m; | ||
171 | } | ||
172 | void KOEventViewer::appendEvent(Event *event, int mode ) | ||
173 | { | ||
174 | mCurrentIncidence = event; | ||
175 | bool shortDate = KOPrefs::instance()->mShortDateInViewer; | ||
176 | topLevelWidget()->setCaption(i18n("Event Viewer")); | ||
177 | if ( mode == 0 ) { | ||
178 | addTag("h2",event->summary()); | ||
179 | } | ||
180 | else { | ||
181 | if ( mColorMode == 1 ) { | ||
182 | mText +="<font color=\"#00A000\">"; | ||
183 | } | ||
184 | if ( mColorMode == 2 ) { | ||
185 | mText +="<font color=\"#C00000\">"; | ||
186 | } | ||
187 | // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; | ||
188 | if ( mode == 1 ) { | ||
189 | addTag("h2",i18n( "Local: " ) +event->summary()); | ||
190 | } else { | ||
191 | addTag("h2",i18n( "Remote: " ) +event->summary()); | ||
192 | } | ||
193 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | ||
194 | if ( mColorMode ) | ||
195 | mText += "</font>"; | ||
196 | } | ||
197 | if (event->cancelled ()) { | ||
198 | mText +="<font color=\"#B00000\">"; | ||
199 | addTag("i",i18n("This event has been cancelled!")); | ||
200 | mText.append("<br>"); | ||
201 | mText += "</font>"; | ||
202 | } | ||
203 | if (!event->location().isEmpty()) { | ||
204 | addTag("b",i18n("Location: ")); | ||
205 | mText.append(event->location()+"<br>"); | ||
206 | } | ||
207 | if (event->doesFloat()) { | ||
208 | if (event->isMultiDay()) { | ||
209 | mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") | ||
210 | .arg(event->dtStartDateStr(shortDate)) | ||
211 | .arg(event->dtEndDateStr(shortDate))); | ||
212 | } else { | ||
213 | mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); | ||
214 | } | ||
215 | } else { | ||
216 | if (event->isMultiDay()) { | ||
217 | mText.append(i18n("<p><b>From:</b> %1</p> ") | ||
218 | .arg(event->dtStartStr( shortDate))); | ||
219 | mText.append(i18n("<p><b>To:</b> %1</p>") | ||
220 | .arg(event->dtEndStr(shortDate))); | ||
221 | } else { | ||
222 | mText.append(i18n("<p><b>On:</b> %1</p> ") | ||
223 | .arg(event->dtStartDateStr( shortDate ))); | ||
224 | mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") | ||
225 | .arg(event->dtStartTimeStr()) | ||
226 | .arg(event->dtEndTimeStr())); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | if (event->recurrence()->doesRecur()) { | ||
231 | |||
232 | QString recurText = event->recurrence()->recurrenceText(); | ||
233 | addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); | ||
234 | bool last; | ||
235 | QDate start = QDate::currentDate(); | ||
236 | QDate next; | ||
237 | next = event->recurrence()->getPreviousDate( start , &last ); | ||
238 | if ( !last ) { | ||
239 | next = event->recurrence()->getNextDate( start.addDays( - 1 ) ); | ||
240 | addTag("p",i18n("<b>Next recurrence is on:</b>") ); | ||
241 | addTag("p", KGlobal::locale()->formatDate( next, shortDate )); | ||
242 | } else { | ||
243 | addTag("p",i18n("<b>Last recurrence was on:</b>") ); | ||
244 | addTag("p", KGlobal::locale()->formatDate( next, shortDate )); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | |||
249 | if (event->isAlarmEnabled()) { | ||
250 | Alarm *alarm =event->alarms().first() ; | ||
251 | QDateTime t = alarm->time(); | ||
252 | int min = t.secsTo( event->dtStart() )/60; | ||
253 | QString s =i18n("( %1 min before )").arg( min ); | ||
254 | addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); | ||
255 | addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); | ||
256 | //addTag("p",s); | ||
257 | } | ||
258 | |||
259 | addTag("b",i18n("Access: ")); | ||
260 | mText.append(event->secrecyStr()+"<br>"); | ||
261 | if (!event->description().isEmpty()) { | ||
262 | addTag("p",i18n("<b>Details: </b>")); | ||
263 | addTag("p",event->description()); | ||
264 | } | ||
265 | |||
266 | formatCategories(event); | ||
267 | |||
268 | formatReadOnly(event); | ||
269 | formatAttendees(event); | ||
270 | |||
271 | setText(mText); | ||
272 | //QWhatsThis::add(this,mText); | ||
273 | |||
274 | } | ||
275 | |||
276 | void KOEventViewer::appendTodo(Todo *event, int mode ) | ||
277 | { | ||
278 | mCurrentIncidence = event; | ||
279 | topLevelWidget()->setCaption(i18n("Todo Viewer")); | ||
280 | bool shortDate = KOPrefs::instance()->mShortDateInViewer; | ||
281 | if (mode == 0 ) | ||
282 | addTag("h2",event->summary()); | ||
283 | else { | ||
284 | if ( mColorMode == 1 ) { | ||
285 | mText +="<font color=\"#00A000\">"; | ||
286 | } | ||
287 | if ( mColorMode == 2 ) { | ||
288 | mText +="<font color=\"#B00000\">"; | ||
289 | } | ||
290 | if ( mode == 1 ) { | ||
291 | addTag("h2",i18n( "Local: " ) +event->summary()); | ||
292 | } else { | ||
293 | addTag("h2",i18n( "Remote: " ) +event->summary()); | ||
294 | } | ||
295 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | ||
296 | if ( mColorMode ) | ||
297 | mText += "</font>"; | ||
298 | } | ||
299 | if (event->cancelled ()) { | ||
300 | mText +="<font color=\"#B00000\">"; | ||
301 | addTag("i",i18n("This todo has been cancelled!")); | ||
302 | mText.append("<br>"); | ||
303 | mText += "</font>"; | ||
304 | } | ||
305 | |||
306 | if (!event->location().isEmpty()) { | ||
307 | addTag("b",i18n("Location: ")); | ||
308 | mText.append(event->location()+"<br>"); | ||
309 | } | ||
310 | if (event->hasDueDate()) { | ||
311 | mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(KOPrefs::instance()->mShortDateInViewer))); | ||
312 | } | ||
313 | addTag("b",i18n("Access: ")); | ||
314 | mText.append(event->secrecyStr()+"<br>"); | ||
315 | if (!event->description().isEmpty()) { | ||
316 | addTag("p",i18n("<b>Details: </b>")); | ||
317 | addTag("p",event->description()); | ||
318 | } | ||
319 | |||
320 | formatCategories(event); | ||
321 | |||
322 | mText.append(i18n("<p><b>Priority:</b> %2</p>") | ||
323 | .arg(QString::number(event->priority()))); | ||
324 | |||
325 | mText.append(i18n("<p><i>%1 % completed</i></p>") | ||
326 | .arg(event->percentComplete())); | ||
327 | |||
328 | formatReadOnly(event); | ||
329 | formatAttendees(event); | ||
330 | |||
331 | setText(mText); | ||
332 | } | ||
333 | |||
334 | void KOEventViewer::formatCategories(Incidence *event) | ||
335 | { | ||
336 | if (!event->categoriesStr().isEmpty()) { | ||
337 | if (event->categories().count() == 1) { | ||
338 | addTag("h3",i18n("Category")); | ||
339 | } else { | ||
340 | addTag("h3",i18n("Categories")); | ||
341 | } | ||
342 | addTag("p",event->categoriesStr()); | ||
343 | } | ||
344 | } | ||
345 | void KOEventViewer::formatAttendees(Incidence *event) | ||
346 | { | ||
347 | QPtrList<Attendee> attendees = event->attendees(); | ||
348 | if (attendees.count()) { | ||
349 | |||
350 | |||
351 | QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); | ||
352 | addTag("h3",i18n("Organizer")); | ||
353 | mText.append("<ul><li>"); | ||
354 | #ifndef KORG_NOKABC | ||
355 | |||
356 | KABC::AddressBook *add_book = KABC::StdAddressBook::self(); | ||
357 | KABC::Addressee::List addressList; | ||
358 | addressList = add_book->findByEmail(event->organizer()); | ||
359 | KABC::Addressee o = addressList.first(); | ||
360 | if (!o.isEmpty() && addressList.size()<2) { | ||
361 | mText += "<a href=\"uid:" + o.uid() + "\">"; | ||
362 | mText += o.formattedName(); | ||
363 | mText += "</a>\n"; | ||
364 | } else { | ||
365 | mText.append(event->organizer()); | ||
366 | } | ||
367 | #else | ||
368 | mText.append(event->organizer()); | ||
369 | #endif | ||
370 | |||
371 | if (iconPath) { | ||
372 | mText += " <a href=\"mailto:" + event->organizer() + "\">"; | ||
373 | mText += "<IMG src=\"" + iconPath + "\">"; | ||
374 | mText += "</a>\n"; | ||
375 | } | ||
376 | mText.append("</li></ul>"); | ||
377 | |||
378 | addTag("h3",i18n("Attendees")); | ||
379 | Attendee *a; | ||
380 | mText.append("<ul>"); | ||
381 | for(a=attendees.first();a;a=attendees.next()) { | ||
382 | #ifndef KORG_NOKABC | ||
383 | if (a->name().isEmpty()) { | ||
384 | addressList = add_book->findByEmail(a->email()); | ||
385 | KABC::Addressee o = addressList.first(); | ||
386 | if (!o.isEmpty() && addressList.size()<2) { | ||
387 | mText += "<a href=\"uid:" + o.uid() + "\">"; | ||
388 | mText += o.formattedName(); | ||
389 | mText += "</a>\n"; | ||
390 | } else { | ||
391 | mText += "<li>"; | ||
392 | mText.append(a->email()); | ||
393 | mText += "\n"; | ||
394 | } | ||
395 | } else { | ||
396 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | ||
397 | if (!a->name().isEmpty()) mText += a->name(); | ||
398 | else mText += a->email(); | ||
399 | mText += "</a>\n"; | ||
400 | } | ||
401 | #else | ||
402 | //qDebug("nokabc "); | ||
403 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | ||
404 | if (!a->name().isEmpty()) mText += a->name(); | ||
405 | else mText += a->email(); | ||
406 | mText += "</a>\n"; | ||
407 | #endif | ||
408 | |||
409 | if (!a->email().isEmpty()) { | ||
410 | if (iconPath) { | ||
411 | mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; | ||
412 | mText += "<IMG src=\"" + iconPath + "\">"; | ||
413 | mText += "</a>\n"; | ||
414 | } | ||
415 | } | ||
416 | if (a->status() != Attendee::NeedsAction ) | ||
417 | mText +="[" + a->statusStr() + "] "; | ||
418 | if (a->role() == Attendee::Chair ) | ||
419 | mText +="(" + a->roleStr().left(1) + ".)"; | ||
420 | } | ||
421 | mText.append("</li></ul>"); | ||
422 | } | ||
423 | |||
424 | } | ||
425 | void KOEventViewer::appendJournal(Journal *jour, int mode ) | ||
426 | { | ||
427 | bool shortDate = KOPrefs::instance()->mShortDateInViewer; | ||
428 | if (mode == 0 ) | ||
429 | addTag("h2",i18n("Journal from: ")); | ||
430 | else { | ||
431 | if ( mode == 1 ) { | ||
432 | addTag("h2",i18n( "Local: " ) +i18n("Journal from: ")); | ||
433 | } else { | ||
434 | addTag("h2",i18n( "Remote: " ) +i18n("Journal from: ")); | ||
435 | } | ||
436 | addTag("h3",i18n( "Last modified " ) + KGlobal::locale()->formatDateTime(jour->lastModified(),shortDate ) ); | ||
437 | } | ||
438 | topLevelWidget()->setCaption("Journal Viewer"); | ||
439 | mText.append(i18n("<h3> %1 </h3> ").arg(jour->dtStartDateStr(KOPrefs::instance()->mShortDateInViewer))); | ||
440 | if (!jour->description().isEmpty()) { | ||
441 | addTag("p",jour->description()); | ||
442 | } | ||
443 | setText(mText); | ||
444 | } | ||
445 | |||
446 | void KOEventViewer::formatReadOnly(Incidence *event) | ||
447 | { | ||
448 | if (event->isReadOnly()) { | ||
449 | addTag("p","<em>(" + i18n("read-only") + ")</em>"); | ||
450 | } | ||
451 | } | ||
452 | void KOEventViewer::setSyncMode( bool b ) | ||
453 | { | ||
454 | mSyncMode = b; | ||
455 | } | ||
456 | |||
457 | |||
458 | void KOEventViewer::setTodo(Todo *event, bool clearV ) | ||
459 | { | ||
460 | if ( clearV ) | ||
461 | clearEvents(); | ||
462 | if ( mSyncMode ) { | ||
463 | if ( clearV ) | ||
464 | appendTodo(event,1 ); | ||
465 | else | ||
466 | appendTodo(event,2); | ||
467 | } else | ||
468 | appendTodo(event); | ||
469 | } | ||
470 | void KOEventViewer::setJournal(Journal *event, bool clearV ) | ||
471 | { | ||
472 | if ( clearV ) | ||
473 | clearEvents(); | ||
474 | if ( mSyncMode ) { | ||
475 | if ( clearV ) | ||
476 | appendJournal(event, 1); | ||
477 | else | ||
478 | appendJournal(event, 2); | ||
479 | } else | ||
480 | appendJournal(event); | ||
481 | } | ||
482 | |||
483 | void KOEventViewer::setEvent(Event *event) | ||
484 | { | ||
485 | clearEvents(); | ||
486 | if ( mSyncMode ) | ||
487 | appendEvent(event, 1); | ||
488 | else | ||
489 | appendEvent(event); | ||
490 | } | ||
491 | |||
492 | void KOEventViewer::addEvent(Event *event) | ||
493 | { | ||
494 | if ( mSyncMode ) | ||
495 | appendEvent(event, 2); | ||
496 | else | ||
497 | appendEvent(event); | ||
498 | } | ||
499 | |||
500 | void KOEventViewer::clearEvents(bool now) | ||
501 | { | ||
502 | mText = ""; | ||
503 | if (now) setText(mText); | ||
504 | } | ||
505 | |||
506 | void KOEventViewer::addText(QString text) | ||
507 | { | ||
508 | mText.append(text); | ||
509 | setText(mText); | ||
510 | } | ||