summaryrefslogtreecommitdiffabout
path: root/korganizer/kowhatsnextview.cpp
Unidiff
Diffstat (limited to 'korganizer/kowhatsnextview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kowhatsnextview.cpp650
1 files changed, 650 insertions, 0 deletions
diff --git a/korganizer/kowhatsnextview.cpp b/korganizer/kowhatsnextview.cpp
new file mode 100644
index 0000000..ffaea37
--- a/dev/null
+++ b/korganizer/kowhatsnextview.cpp
@@ -0,0 +1,650 @@
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 <qlayout.h>
21#include <qtextbrowser.h>
22#include <qtextcodec.h>
23#include <qfileinfo.h>
24#include <qlabel.h>
25
26#include <qapplication.h>
27
28#include <kglobal.h>
29#include <klocale.h>
30#include <kdebug.h>
31#include <kiconloader.h>
32#include <kmessagebox.h>
33
34#include <libkcal/calendar.h>
35
36#ifndef KORG_NOPRINTER
37#include "calprinter.h"
38#endif
39#include "koglobals.h"
40#include "koprefs.h"
41#include "koeventviewerdialog.h"
42
43#include "kowhatsnextview.h"
44using namespace KOrg;
45#include "kowhatsnextview.moc"
46
47void WhatsNextTextBrowser::setSource(const QString& n)
48{
49
50 if (n.startsWith("event:")) {
51 emit showIncidence(n);
52 return;
53 } else if (n.startsWith("todo:")) {
54 emit showIncidence(n);
55 return;
56 } else {
57 QTextBrowser::setSource(n);
58 }
59}
60
61KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
62 const char *name)
63 : KOrg::BaseView(calendar, parent, name)
64{
65 // mDateLabel =
66 // new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this);
67 // mDateLabel->setMargin(2);
68 // mDateLabel->setAlignment(AlignCenter);
69 setFont( KOPrefs::instance()->mWhatsNextFont );
70 mView = new WhatsNextTextBrowser(this);
71 connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &)));
72
73 mEventViewer = 0;
74
75 QBoxLayout *topLayout = new QVBoxLayout(this);
76 // topLayout->addWidget(mDateLabel);
77 topLayout->addWidget(mView);
78}
79
80KOWhatsNextView::~KOWhatsNextView()
81{
82}
83
84int KOWhatsNextView::maxDatesHint()
85{
86 return 0;
87}
88
89int KOWhatsNextView::currentDateCount()
90{
91 return 0;
92}
93
94QPtrList<Incidence> KOWhatsNextView::selectedIncidences()
95{
96 QPtrList<Incidence> eventList;
97
98 return eventList;
99}
100
101
102void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
103 const QDate &td)
104{
105#ifndef KORG_NOPRINTER
106 calPrinter->preview(CalPrinter::Day, fd, td);
107#endif
108}
109void KOWhatsNextView::updateConfig()
110{
111 setFont( KOPrefs::instance()->mWhatsNextFont );
112 updateView();
113
114}
115void KOWhatsNextView::updateView()
116{
117
118 // mDateLabel->setText(KGlobal::locale()->formatDate(QDate::currentDate()));
119 KIconLoader kil("korganizer");
120 QString ipath;// = new QString();
121 // kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,&ipath);
122 //<big><big><strong>" + date + "</strong></big></big>\n";
123 mText = "<table width=\"100%\">\n";
124 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
125#ifdef DESKTOP_VERSION
126 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h1>";
127#else
128 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
129#endif
130 // mText += "<img src=\"";
131 // mText += ipath;
132 // mText += "\">";
133 mEventDate = QDate::currentDate();
134#ifdef DESKTOP_VERSION
135 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h1>";
136#else
137 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h2>";
138#endif
139 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
140 int iii;
141 mTodos.clear();
142 QPtrList<Event> events;
143 QPtrList<Todo> todos = calendar()->todos();
144 Todo * todo;
145 //mText += "<h2>" + i18n("Events: ") + "</h2>\n";
146 int daysToShow = KOPrefs::instance()->mWhatsNextDays ;
147 bool itemAdded = false;
148 for ( iii = 0; iii < daysToShow; ++iii ) {
149 QString date;
150 itemAdded = false;
151 events = calendar()->events( mEventDate, true );
152
153 if ( iii == 0 ) { // today !!!
154 todo = todos.first();
155 while(todo) {
156 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() < mEventDate ) {
157 if ( ! itemAdded ) {
158 appendDay ( iii, mEventDate );
159 itemAdded = true;
160
161 }
162 appendEvent(todo);
163 }
164 todo = todos.next();
165 }
166 }
167
168
169 if (events.count() > 0) {
170 // mText += "<p></p>";
171 // kil.loadIcon("month",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
172 // mText += "<h2>";
173 //mText += " <img src=\"";
174 //mText += ipath;
175 //mText += "\">";
176 if ( ! itemAdded ) {
177 appendDay ( iii, mEventDate );
178 itemAdded = true;
179
180 }
181 Event *ev = events.first();
182 while(ev) {
183 //qDebug("+++++event append %s", ev->summary().latin1());
184 if ( true /*!ev->recurrence()->doesRecur() || ev->recursOn( mEventDate)*/) {
185 appendEvent(ev, false , iii!= 0 );
186 }
187 ev = events.next();
188 }
189
190 //mText += "</table>\n";
191 }
192
193 todo = todos.first();
194 while(todo) {
195 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() == mEventDate ) {
196 if ( ! itemAdded ) {
197 appendDay ( iii, mEventDate );
198 itemAdded = true;
199 }
200 appendEvent(todo);
201 }
202 todo = todos.next();
203 }
204 if ( !itemAdded && iii == 0 ) {
205 // appendDay ( iii, mEventDate );
206 //mText += "<table>";
207 // mText += "<b><font color=\"#000080\"><em>"+i18n("No event, nothing to do.") +"</em></font></b>\n";
208 mText += "<h3 align=\"center\"><font color=\"#008000\"><em>"+i18n("No event, nothing to do. ") +"</em></font></h3>\n";
209 //mText +="</table>";
210 }
211 if ( itemAdded )
212 mText += "</table>\n";
213 mEventDate = mEventDate.addDays( 1 );
214 }
215
216 int topmostPrios = KOPrefs::instance()->mWhatsNextPrios;
217 if (todos.count() > 0 && topmostPrios > 0 ) {
218 // kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
219 // mText += "<h2>";
220 //<img src=\"";
221 // mText += ipath;
222 // mText += "\">";
223 // mText += i18n("Overdue To-Do:") + "</h2>\n";
224
225 //mText += "<ul>\n";
226 bool gotone = false;
227 int priority = 1;
228 int priosFound = 0;
229#ifdef DESKTOP_VERSION
230 mText +="<p></p>";
231#endif
232
233 mText +="<big><big><strong><em><font color=\"#000080\">" + i18n("Incomplete Todo:") + "</font></em></strong></big></big>\n";
234 mText += "<ul>\n";
235 while (!gotone && priority<6) {
236 todo = todos.first();
237 while(todo) {
238 if (!todo->isCompleted() && (todo->priority() == priority) ) {
239 if ( appendTodo(todo) )
240 gotone = true;
241 }
242 todo = todos.next();
243 }
244 if ( gotone ) {
245 gotone = false;
246 ++priosFound;
247 if ( priosFound == topmostPrios )
248 break;
249 }
250 priority++;
251 // kdDebug() << "adding the todos..." << endl;
252 }
253 mText += "</ul>\n";
254 }
255
256 int replys = 0;
257 events = calendar()->events(QDate::currentDate(), QDate(2975,12,6));
258 if (events.count() > 0) {
259 Event *ev = events.first();
260 while(ev) {
261 Attendee *me = ev->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
262 if (me!=0) {
263 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
264 if (replys == 0) {
265 mText += "<p></p>";
266 // kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
267 mText += "<h2>";
268 //<img src=\"";
269 // mText += ipath;
270 // mText += "\">";
271 mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
272 mText += "<table>\n";
273 }
274 replys++;
275 appendEvent(ev,true);
276 }
277 }
278 ev = events.next();
279 }
280 }
281 todos = calendar()->todos();
282 if (todos.count() > 0) {
283 Todo *to = todos.first();
284 while(to) {
285 Attendee *me = to->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
286 if (me!=0) {
287 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
288 if (replys == 0) {
289 mText += "<p></p>";
290 // kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
291 mText += "<h2>";
292 //<img src=\"";
293 // mText += ipath;
294 // mText += "\">";
295 mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
296 mText += "<table>\n";
297 }
298 replys++;
299 appendEvent(to);
300 }
301 }
302 kdDebug () << "check for todo-replys..." << endl;
303 to = todos.next();
304 }
305 }
306 if (replys > 0 ) mText += "</table>\n";
307
308
309 mText += "</td></tr>\n</table>\n";
310
311 kdDebug() << "KOWhatsNextView::updateView: text: " << mText << endl;
312 mView->setText(mText);
313 mView->setFocus();
314
315 // QPixmap bPix = SmallIcon( "back" );
316 // qDebug("xxxxxxxxxxxxxxxxxxxxx ");
317 // QWidget* test = new QWidget();
318 // test->setBackgroundMode(FixedPixmap );
319 // test->setBackgroundPixmap ( bPix );
320 // test->resize( 300, 400 );
321 // test->show();
322 // mView->setBackgroundMode(FixedPixmap );
323 // mView->setBackgroundPixmap ( bPix );
324}
325
326void KOWhatsNextView::appendDay( int i, QDate eventDate )
327{
328 QString date;
329 QString day = KGlobal::locale()->formatDate( eventDate , KOPrefs::instance()->mShortDateInViewer);
330 if ( ! KOPrefs::instance()->mShortDateInViewer && QApplication::desktop()->width() < 320 ) {
331 if ( i == 0 ) {
332 mText += "<table>\n";
333 return;//date = "<em><font color=\"#008000\"><em>" + day+"</font></em>";
334 }
335 else if ( i == 1 )
336 date = "<em><font color=\"#000080\">" + day + "</font></em>" ;
337 else date = "<em><font color=\"#000080\">" + day + "</font></em>";
338 //mText += "<h2>" + date + "</h2>\n";
339 mText += "<big><big><strong>" + date + "</strong></big></big>\n";
340 mText += "<table>\n";
341
342
343
344 } else {
345 if ( i == 0 ) {
346 mText += "<table>\n";
347 return;// date = "<font color=\"#008000\"><em>" +i18n("Today: ") +"</em>" + day+"</font>";
348 }
349
350#ifdef DESKTOP_VERSION
351 else if ( i == 1 ) {
352 date = "<h2><em><font color=\"#000080\">" + i18n("Tomorrow: ") + day +"</font></em></h2>" ;
353 }
354 else date = "<h2><em><font color=\"#000080\">" + i18n("In %1 days: ").arg( i ) +day + "</font></em></h2>";
355#else
356 else if ( i == 1 ) {
357 date = "<em><font color=\"#000080\">" + i18n("Tomorrow: ") + day +"</font></em>" ;
358 }
359 else date = "<em><font color=\"#000080\">" + i18n("In %1 days: ").arg( i ) +day + "</font></em>";
360
361#endif
362 //mText += "<h2>" + date + "</h2>\n";
363 mText += "<big><big><strong>" + date + "</strong></big></big>\n";
364 mText += "<table>\n";
365 }
366}
367
368
369void KOWhatsNextView::showDates(const QDate &, const QDate &)
370{
371 updateView();
372}
373
374void KOWhatsNextView::showEvents(QPtrList<Event>)
375{
376}
377
378void KOWhatsNextView::changeEventDisplay(Event *, int action)
379{
380 switch(action) {
381 case KOGlobals::EVENTADDED:
382 updateView();
383 break;
384 case KOGlobals::EVENTEDITED:
385 updateView();
386 break;
387 case KOGlobals::EVENTDELETED:
388 updateView();
389 break;
390 default:
391 updateView();
392 kdDebug() << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl;
393 }
394}
395
396void KOWhatsNextView::appendEvent(Incidence *ev, bool reply, bool notRed )
397{
398 if ( !KOPrefs::instance()->mShowSyncEvents && ev->uid().left(21) == QString("last-syncEvent-device") )
399 return;
400 QDateTime cdt = QDateTime::currentDateTime();
401 mText += "<tr><td><b>";
402 if (ev->type()=="Event") {
403
404 if (!ev->doesFloat()) {
405 Event *event = static_cast<Event *>(ev);
406 QDateTime st,end;
407 if ( event->recurrence()->doesRecur() ) {
408 QDate recDate= mEventDate;
409 int days = event->dtStart().date().daysTo (event->dtEnd().date() );
410 while ( ! event->recursOn( recDate ) ) {
411 recDate = recDate.addDays( -1 );
412
413 }
414 st = QDateTime ( recDate, event->dtStart().time() );
415 end = QDateTime ( recDate.addDays( days ), event->dtEnd().time() );
416 }
417 else {
418 st = event->dtStart();
419 end = event->dtEnd();
420 }
421
422 if (reply) mText += "on " + event->dtStartDateStr() + ": ";
423 QString dateText;
424 // qDebug("%s %s %s %s ", mEventDate.toString().latin1(),event->summary().latin1(), st .toString().latin1(),end.toString().latin1() );
425 if ( st.date() < mEventDate )
426 dateText = "++:++-";
427 else
428 dateText = event->dtStartTimeStr() + "-";
429 if ( end.date() > mEventDate )
430 dateText += "++:++";
431 else
432 dateText += event->dtEndTimeStr();
433 if ( notRed )
434 mText += dateText;
435 else {
436 if ( end < cdt )
437 mText += "<font color=\"#F00000\">" + dateText + "</font>";
438 else if ( st < cdt )
439 mText += "<font color=\"#008000\">" + dateText + "</font>";
440 else
441 mText += dateText;
442 }
443
444 } else {
445 mText += i18n("Allday:");
446
447 }
448 } else {
449 mTodos.append( ev );
450 mText += i18n("ToDo:");
451 if ( ((Todo*)ev)->dtDue().date() < QDate::currentDate() ) {
452 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
453 QString dfs = KGlobal::locale()->dateFormatShort();
454 KGlobal::locale()->setIntDateFormat( 3 );
455 KGlobal::locale()->setDateFormatShort("%d.%b");
456 mText +="<font color=\"#F00000\">" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true) + "</font>";
457
458 KGlobal::locale()->setDateFormatShort(dfs);
459 KGlobal::locale()->setIntDateFormat( KOPrefs::instance()->mPreferredDate );
460 } else {
461 if (!ev->doesFloat() )
462 if( ( (Todo*)ev)->dtDue() < cdt ) {
463 mText +="<font color=\"#F00000\">" + ((Todo*)ev)->dtDueTimeStr() + "</font>";
464
465
466 } else
467 mText +=((Todo*)ev)->dtDueTimeStr();
468 mTodos.append( ev );
469 }
470 }
471 mText += "</b></td><td>";
472 bool needClose = false;
473 if ( ev->cancelled() ) {
474 mText += "<font color=\"#F00000\">[c";
475 needClose =true;
476
477 }
478 if ( ev->isAlarmEnabled() ) {
479 if ( !needClose)
480 mText +="[";
481 mText += "a";
482 needClose =true;
483
484 }
485 if ( ev->description().length() > 0 ) {
486 if ( !needClose)
487 mText +="[";
488 mText += "i";
489 needClose =true;
490 }
491 if ( ev->recurrence()->doesRecur() ) {
492 if ( !needClose)
493 mText +="[";
494 mText += "r";
495 needClose =true;
496 }
497 if ( needClose ) {
498 mText += "] ";
499 }
500 if ( ev->cancelled() )
501 mText += "</font>";
502 mText += "<a ";
503 if (ev->type()=="Event") mText += "href=\"event:";
504 if (ev->type()=="Todo") mText += "href=\"todo:";
505 mText += ev->uid() + "\">";
506 if ( ev->summary().length() > 0 )
507 mText += ev->summary();
508 else
509 mText += i18n("-no summary-");
510 mText += "</a>";
511 if ( KOPrefs::instance()->mWNViewShowLocation )
512 if ( !ev->location().isEmpty() )
513 mText += " ("+ev->location() +")";
514 if ( ev->relatedTo() && KOPrefs::instance()->mWNViewShowsParents)
515 mText += " ["+ev->relatedTo()->summary() +"]";
516 mText += "</td></tr>\n";
517}
518
519bool KOWhatsNextView::appendTodo(Incidence *ev, QString ind , bool isSub )
520{
521 if ( mTodos.find( ev ) != mTodos.end() ) return false;
522
523 mTodos.append( ev );
524 if ( !isSub )
525 mText += "<p>";
526 else
527 mText += "<li>";
528 mText += "[" +QString::number(ev->priority()) + "/" + QString::number(((Todo*)ev)->percentComplete())+"%] ";
529
530
531 mText += ind;
532 bool needClose = false;
533 if ( ev->cancelled() ) {
534 mText += "<font color=\"#F00000\">[c";
535 needClose =true;
536
537 }
538 if ( ev->isAlarmEnabled() ) {
539 if ( !needClose)
540 mText +="[";
541 mText += "a";
542 needClose =true;
543
544 }
545
546 if ( ev->description().length() > 0 ) {
547 if ( !needClose)
548 mText +="[";
549 mText += "i";
550 needClose =true;
551 }
552 // if ( ev->recurrence()->doesRecur() ) {
553 // if ( !needClose)
554 // mText +="(";
555 // mText += "r";
556 // needClose =true;
557 // }
558 if ( needClose )
559 mText += "] ";
560 if ( ev->cancelled() )
561 mText += "</font>";
562 mText += "<a href=\"todo:" + ev->uid() + "\">";
563 mText += ev->summary();
564 mText += "</a>";
565 if ( ((Todo*)ev)->hasDueDate () ) {
566 QString year = "";
567 int ye = ((Todo*)ev)->dtDue().date().year();
568 if ( QDateTime::currentDateTime().date().year() != ye )
569 year = QString::number( ye );
570 QString dfs = KGlobal::locale()->dateFormatShort();
571 KGlobal::locale()->setIntDateFormat( 3 );
572 KGlobal::locale()->setDateFormatShort("%d.%b");
573 mText +="<font color=\"#00A000\"> [" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true) + "."+ year +"]</font>";
574
575 KGlobal::locale()->setDateFormatShort(dfs);
576 KGlobal::locale()->setIntDateFormat( KOPrefs::instance()->mPreferredDate );
577 }
578 if ( KOPrefs::instance()->mWNViewShowLocation )
579 if ( !ev->location().isEmpty() )
580 mText += " ("+ev->location() +")";
581 if ( !isSub ) {
582 if ( ((Todo*)ev)->relatedTo()&& KOPrefs::instance()->mWNViewShowsParents)
583 mText += " ["+ev->relatedTo()->summary() +"]";
584 mText += "</p>\n";
585 }
586 else {
587 ind += "-";
588 mText += "</li>\n";
589 }
590 QPtrList<Incidence> Relations = ev->relations();
591 Incidence *to;
592 for (to=Relations.first();to;to=Relations.next()) {
593 if (!((Todo*)to)->isCompleted())
594 appendTodo( to, ind , true );
595 }
596
597 return true;
598}
599
600/*
601 void KOWhatsNextView::createEventViewer()
602 {
603 if (!mEventViewer) {
604
605 mEventViewer = new KOEventViewerDialog(this);
606 }
607 }
608*/
609void KOWhatsNextView::setEventViewer(KOEventViewerDialog* v )
610{
611 if ( mEventViewer )
612 delete mEventViewer;
613 mEventViewer = v;
614}
615
616// TODO: Create this function in CalendarView and remove it from here
617void KOWhatsNextView::showIncidence(const QString &uid)
618{
619 if ( !mEventViewer ) {
620 qDebug("KOWhatsNextView::showIncidence::sorry, no event viewer set ");
621 return;
622 }
623 //kdDebug() << "KOWhatsNextView::showIncidence(): " << uid << endl;
624 //qDebug("KOWhatsNextView::showIncidence %s ", uid.latin1());
625 if (uid.startsWith("event:")) {
626#ifdef DESKTOP_VERSION
627 Event *event = calendar()->event(uid.mid(8));
628#else
629 Event *event = calendar()->event(uid.mid(6));
630#endif
631 //qDebug("event %d uid %s ", event, uid.mid(6).latin1());
632 if (!event) return;
633 //createEventViewer();
634 mEventViewer->setEvent(event);
635 } else if (uid.startsWith("todo:")) {
636#ifdef DESKTOP_VERSION
637 Todo *todo = calendar()->todo(uid.mid(7));
638#else
639 Todo *todo = calendar()->todo(uid.mid(5));
640#endif
641 if (!todo) return;
642 //createEventViewer();
643 mEventViewer->setTodo(todo);
644 } else {
645 return;
646
647 }
648 mEventViewer->showMe();
649 mEventViewer->raise();
650}