summaryrefslogtreecommitdiffabout
path: root/korganizer/kowhatsnextview.cpp
Unidiff
Diffstat (limited to 'korganizer/kowhatsnextview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kowhatsnextview.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/korganizer/kowhatsnextview.cpp b/korganizer/kowhatsnextview.cpp
index 5f14bfa..219f7c3 100644
--- a/korganizer/kowhatsnextview.cpp
+++ b/korganizer/kowhatsnextview.cpp
@@ -18,193 +18,209 @@
18*/ 18*/
19 19
20#include <qlayout.h> 20#include <qlayout.h>
21#include <qtextbrowser.h> 21#include <qtextbrowser.h>
22#include <qtextcodec.h> 22#include <qtextcodec.h>
23#include <qfileinfo.h> 23#include <qfileinfo.h>
24#include <qlabel.h> 24#include <qlabel.h>
25 25
26#include <qapplication.h> 26#include <qapplication.h>
27 27
28#include <kglobal.h> 28#include <kglobal.h>
29#include <klocale.h> 29#include <klocale.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include <kiconloader.h> 31#include <kiconloader.h>
32#include <kmessagebox.h> 32#include <kmessagebox.h>
33 33
34#include <libkcal/calendar.h> 34#include <libkcal/calendar.h>
35 35
36#ifndef KORG_NOPRINTER 36#ifndef KORG_NOPRINTER
37#include "calprinter.h" 37#include "calprinter.h"
38#endif 38#endif
39#include "koglobals.h" 39#include "koglobals.h"
40#include "koprefs.h" 40#include "koprefs.h"
41#include "koeventviewerdialog.h" 41#include "koeventviewerdialog.h"
42#include <qstylesheet.h> 42#include <qstylesheet.h>
43#include "kowhatsnextview.h" 43#include "kowhatsnextview.h"
44using namespace KOrg; 44using namespace KOrg;
45 45
46void WhatsNextTextBrowser::setSource(const QString& n) 46void WhatsNextTextBrowser::setSource(const QString& n)
47{ 47{
48 48
49 if (n.startsWith("event:")) { 49 if (n.startsWith("event:")) {
50 emit showIncidence(n); 50 emit showIncidence(n);
51 return; 51 return;
52 } else if (n.startsWith("todo:")) { 52 } else if (n.startsWith("todo:")) {
53 emit showIncidence(n); 53 emit showIncidence(n);
54 return; 54 return;
55 } else { 55 } else {
56 QTextBrowser::setSource(n); 56 QTextBrowser::setSource(n);
57 } 57 }
58} 58}
59 59
60KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent, 60KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
61 const char *name) 61 const char *name)
62 : KOrg::BaseView(calendar, parent, name) 62 : KOrg::BaseView(calendar, parent, name)
63{ 63{
64 // mDateLabel = 64 // mDateLabel =
65 // new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this); 65 // new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this);
66 // mDateLabel->setMargin(2); 66 // mDateLabel->setMargin(2);
67 // mDateLabel->setAlignment(AlignCenter); 67 // mDateLabel->setAlignment(AlignCenter);
68 setFont( KOPrefs::instance()->mWhatsNextFont ); 68 setFont( KOPrefs::instance()->mWhatsNextFont );
69 mView = new WhatsNextTextBrowser(this); 69 mView = new WhatsNextTextBrowser(this);
70 connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &))); 70 connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &)));
71 QStyleSheet* stsh = mView->styleSheet(); 71 QStyleSheet* stsh = mView->styleSheet();
72 QStyleSheetItem * style ; 72 QStyleSheetItem * style ;
73 style = stsh->item ("h2" ); 73 style = stsh->item ("h2" );
74 if ( style ) { 74 if ( style ) {
75 style->setMargin(QStyleSheetItem::MarginAll,0); 75 style->setMargin(QStyleSheetItem::MarginAll,0);
76 } 76 }
77 style = stsh->item ("h3" ); 77 style = stsh->item ("h3" );
78 if ( style ) { 78 if ( style ) {
79 style->setMargin(QStyleSheetItem::MarginAll,0); 79 style->setMargin(QStyleSheetItem::MarginAll,0);
80 } 80 }
81 mEventViewer = 0; 81 mEventViewer = 0;
82 82
83 QBoxLayout *topLayout = new QVBoxLayout(this); 83 QBoxLayout *topLayout = new QVBoxLayout(this);
84 // topLayout->addWidget(mDateLabel); 84 // topLayout->addWidget(mDateLabel);
85 topLayout->addWidget(mView); 85 topLayout->addWidget(mView);
86 mTimer = new QTimer( this ); 86 mTimer = new QTimer( this );
87 connect(mTimer,SIGNAL( timeout() ),this, SLOT(updateView())); 87 connect(mTimer,SIGNAL( timeout() ),this, SLOT(updateView()));
88 88
89 connect(mView->horizontalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer())); 89 connect(mView->horizontalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer()));
90 connect(mView->verticalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer())); 90 connect(mView->verticalScrollBar (),SIGNAL( sliderReleased () ),this, SLOT(restartTimer()));
91} 91}
92 92
93KOWhatsNextView::~KOWhatsNextView() 93KOWhatsNextView::~KOWhatsNextView()
94{ 94{
95} 95}
96 96
97int KOWhatsNextView::maxDatesHint() 97int KOWhatsNextView::maxDatesHint()
98{ 98{
99 return 0; 99 return 0;
100} 100}
101 101
102int KOWhatsNextView::currentDateCount() 102int KOWhatsNextView::currentDateCount()
103{ 103{
104 return 0; 104 return 0;
105} 105}
106 106
107QPtrList<Incidence> KOWhatsNextView::selectedIncidences() 107QPtrList<Incidence> KOWhatsNextView::selectedIncidences()
108{ 108{
109 QPtrList<Incidence> eventList; 109 QPtrList<Incidence> eventList;
110 110
111 return eventList; 111 return eventList;
112} 112}
113 113
114 114void KOWhatsNextView::printMe()
115{
116#ifdef DESKTOP_VERSION
117 QPrinter printer;
118 if (!printer.setup() )
119 return;
120 QTextBrowser tb;
121 tb.setFixedSize( 600, 4000 );
122 QPainter::redirect ( tb.viewport(), &printer );
123 updateView();
124 tb.setText( mText );
125 tb.show();
126 tb.repaint();
127 tb.hide();
128 KMessageBox::information( this, i18n("Printing What's Next View!\n\nPlease close after\nprinting is finished."));
129#endif
130}
115void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd, 131void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
116 const QDate &td) 132 const QDate &td)
117{ 133{
118#ifndef KORG_NOPRINTER 134#ifndef KORG_NOPRINTER
119 calPrinter->preview(CalPrinter::Day, fd, td); 135 calPrinter->preview(CalPrinter::Day, fd, td);
120#endif 136#endif
121} 137}
122void KOWhatsNextView::updateConfig() 138void KOWhatsNextView::updateConfig()
123{ 139{
124 setFont( KOPrefs::instance()->mWhatsNextFont ); 140 setFont( KOPrefs::instance()->mWhatsNextFont );
125 updateView(); 141 updateView();
126 142
127} 143}
128void KOWhatsNextView::showEvent ( QShowEvent * e ) 144void KOWhatsNextView::showEvent ( QShowEvent * e )
129{ 145{
130 //qDebug("KOWhatsNextView::showEvent "); 146 //qDebug("KOWhatsNextView::showEvent ");
131 restartTimer(); 147 restartTimer();
132 QWidget::showEvent ( e ); 148 QWidget::showEvent ( e );
133} 149}
134void KOWhatsNextView::hideEvent ( QHideEvent * e) 150void KOWhatsNextView::hideEvent ( QHideEvent * e)
135{ 151{
136 //qDebug(" KOWhatsNextView::hideEvent"); 152 //qDebug(" KOWhatsNextView::hideEvent");
137 mTimer->stop(); 153 mTimer->stop();
138 QWidget::hideEvent ( e ); 154 QWidget::hideEvent ( e );
139} 155}
140void KOWhatsNextView::restartTimer() 156void KOWhatsNextView::restartTimer()
141{ 157{
142 //qDebug("KOWhatsNextView::restartTimer() "); 158 //qDebug("KOWhatsNextView::restartTimer() ");
143 mTimer->start( 300000 ); 159 mTimer->start( 300000 );
144 //mTimer->start( 5000 ); 160 //mTimer->start( 5000 );
145} 161}
146void KOWhatsNextView::updateView() 162void KOWhatsNextView::updateView()
147{ 163{
148 if ( mTimer->isActive() ) 164 if ( mTimer->isActive() )
149 restartTimer(); 165 restartTimer();
150 //qDebug("KOWhatsNextView::updateView() "); 166 //qDebug("KOWhatsNextView::updateView() ");
151 // mDateLabel->setText(KGlobal::locale()->formatDate(QDate::currentDate())); 167 // mDateLabel->setText(KGlobal::locale()->formatDate(QDate::currentDate()));
152 KIconLoader kil("korganizer"); 168 KIconLoader kil("korganizer");
153 QString ipath;// = new QString(); 169 QString ipath;// = new QString();
154 // kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,&ipath); 170 // kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,&ipath);
155 //<big><big><strong>" + date + "</strong></big></big>\n"; 171 //<big><big><strong>" + date + "</strong></big></big>\n";
156 mText = "<table width=\"100%\">\n"; 172 mText = "<table width=\"100%\">\n";
157 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 173 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
158#ifdef DESKTOP_VERSION 174#ifdef DESKTOP_VERSION
159 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h1>"; 175 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h1>";
160#else 176#else
161 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>"; 177 mText += "<tr bgcolor=\"#5699CD\"><td align=\"center\"><h2>";
162#endif 178#endif
163 // mText += "<img src=\""; 179 // mText += "<img src=\"";
164 // mText += ipath; 180 // mText += ipath;
165 // mText += "\">"; 181 // mText += "\">";
166 mEventDate = QDate::currentDate(); 182 mEventDate = QDate::currentDate();
167#ifdef DESKTOP_VERSION 183#ifdef DESKTOP_VERSION
168 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h1>"; 184 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h1>";
169#else 185#else
170 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h2>"; 186 mText += "<font color=\"#FFFFFF\"> <em>" + KGlobal::locale()->formatDate( mEventDate , false )+"</em></font></h2>";
171#endif 187#endif
172 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; 188 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
173 int iii; 189 int iii;
174 mTodos.clear(); 190 mTodos.clear();
175 QPtrList<Event> events; 191 QPtrList<Event> events;
176 QPtrList<Todo> todos = calendar()->todos(); 192 QPtrList<Todo> todos = calendar()->todos();
177 Todo * todo; 193 Todo * todo;
178 //mText += "<h2>" + i18n("Events: ") + "</h2>\n"; 194 //mText += "<h2>" + i18n("Events: ") + "</h2>\n";
179 int daysToShow = KOPrefs::instance()->mWhatsNextDays ; 195 int daysToShow = KOPrefs::instance()->mWhatsNextDays ;
180 bool itemAdded = false; 196 bool itemAdded = false;
181 for ( iii = 0; iii < daysToShow; ++iii ) { 197 for ( iii = 0; iii < daysToShow; ++iii ) {
182 QString date; 198 QString date;
183 itemAdded = false; 199 itemAdded = false;
184 events = calendar()->events( mEventDate, true ); 200 events = calendar()->events( mEventDate, true );
185 201
186 if ( iii == 0 ) { // today !!! 202 if ( iii == 0 ) { // today !!!
187 todo = todos.first(); 203 todo = todos.first();
188 while(todo) { 204 while(todo) {
189 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() < mEventDate ) { 205 if ( !todo->isCompleted() &&todo->hasDueDate() && todo->dtDue().date() < mEventDate ) {
190 if ( ! itemAdded ) { 206 if ( ! itemAdded ) {
191 appendDay ( iii, mEventDate ); 207 appendDay ( iii, mEventDate );
192 //itemAdded = true; 208 //itemAdded = true;
193 209
194 } //bool reply=false, bool notRed = true, bool appendTable = false); 210 } //bool reply=false, bool notRed = true, bool appendTable = false);
195 appendEvent(todo, false, false, !itemAdded ); 211 appendEvent(todo, false, false, !itemAdded );
196 itemAdded = true; 212 itemAdded = true;
197 } 213 }
198 todo = todos.next(); 214 todo = todos.next();
199 } 215 }
200 } 216 }
201 217
202 218
203 if (events.count() > 0) { 219 if (events.count() > 0) {
204 // mText += "<p></p>"; 220 // mText += "<p></p>";
205 // kil.loadIcon("month",KIcon::NoGroup,22,KIcon::DefaultState,&ipath); 221 // kil.loadIcon("month",KIcon::NoGroup,22,KIcon::DefaultState,&ipath);
206 // mText += "<h2>"; 222 // mText += "<h2>";
207 //mText += " <img src=\""; 223 //mText += " <img src=\"";
208 //mText += ipath; 224 //mText += ipath;
209 //mText += "\">"; 225 //mText += "\">";
210 if ( ! itemAdded ) { 226 if ( ! itemAdded ) {
@@ -581,128 +597,129 @@ bool KOWhatsNextView::appendEvent(Incidence *ev, bool reply, bool notRed, bool a
581 597
582bool KOWhatsNextView::appendTodo(Incidence *ev, QString ind , bool isSub ) 598bool KOWhatsNextView::appendTodo(Incidence *ev, QString ind , bool isSub )
583{ 599{
584 if ( mTodos.find( ev ) != mTodos.end() ) return false; 600 if ( mTodos.find( ev ) != mTodos.end() ) return false;
585 601
586 mTodos.append( ev ); 602 mTodos.append( ev );
587 if ( !isSub ) 603 if ( !isSub )
588 mText += "<p>"; 604 mText += "<p>";
589 else 605 else
590 mText += "<li>"; 606 mText += "<li>";
591 mText += "[" +QString::number(ev->priority()) + "/" + QString::number(((Todo*)ev)->percentComplete())+"%] "; 607 mText += "[" +QString::number(ev->priority()) + "/" + QString::number(((Todo*)ev)->percentComplete())+"%] ";
592 608
593 609
594 mText += ind; 610 mText += ind;
595 bool needClose = false; 611 bool needClose = false;
596 if ( ev->cancelled() ) { 612 if ( ev->cancelled() ) {
597 mText += "<font color=\"#F00000\">[c"; 613 mText += "<font color=\"#F00000\">[c";
598 needClose =true; 614 needClose =true;
599 615
600 } 616 }
601 if ( ev->isAlarmEnabled() ) { 617 if ( ev->isAlarmEnabled() ) {
602 if ( !needClose) 618 if ( !needClose)
603 mText +="["; 619 mText +="[";
604 mText += "a"; 620 mText += "a";
605 needClose =true; 621 needClose =true;
606 622
607 } 623 }
608 624
609 if ( ev->description().length() > 0 ) { 625 if ( ev->description().length() > 0 ) {
610 if ( !needClose) 626 if ( !needClose)
611 mText +="["; 627 mText +="[";
612 mText += "i"; 628 mText += "i";
613 needClose =true; 629 needClose =true;
614 } 630 }
615 // if ( ev->recurrence()->doesRecur() ) { 631 // if ( ev->recurrence()->doesRecur() ) {
616 // if ( !needClose) 632 // if ( !needClose)
617 // mText +="("; 633 // mText +="(";
618 // mText += "r"; 634 // mText += "r";
619 // needClose =true; 635 // needClose =true;
620 // } 636 // }
621 if ( needClose ) 637 if ( needClose )
622 mText += "] "; 638 mText += "] ";
623 if ( ev->cancelled() ) 639 if ( ev->cancelled() )
624 mText += "</font>"; 640 mText += "</font>";
625 mText += "<a href=\"todo:" + ev->uid() + "\">"; 641 mText += "<a href=\"todo:" + ev->uid() + "\">";
626 mText += ev->summary(); 642 mText += ev->summary();
627 mText += "</a>"; 643 mText += "</a>";
628 if ( ((Todo*)ev)->hasDueDate () ) { 644 if ( ((Todo*)ev)->hasDueDate () ) {
629 QString year = ""; 645 QString year = "";
630 int ye = ((Todo*)ev)->dtDue().date().year(); 646 int ye = ((Todo*)ev)->dtDue().date().year();
631 if ( QDateTime::currentDateTime().date().year() != ye ) 647 if ( QDateTime::currentDateTime().date().year() != ye )
632 year = QString::number( ye ); 648 year = QString::number( ye );
633 QString dfs = KGlobal::locale()->dateFormatShort(); 649 QString dfs = KGlobal::locale()->dateFormatShort();
634 KGlobal::locale()->setDateFormatShort("%d.%b"); 650 KGlobal::locale()->setDateFormatShort("%d.%b");
635 mText +="<font color=\"#00A000\"> [" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true, KLocale::Userdefined) + "."+ year +"]</font>"; 651 mText +="<font color=\"#00A000\"> [" + KGlobal::locale()->formatDate(((Todo*)ev)->dtDue().date(), true, KLocale::Userdefined) + "."+ year +"]</font>";
636 KGlobal::locale()->setDateFormatShort(dfs); 652 KGlobal::locale()->setDateFormatShort(dfs);
637 } 653 }
638 if ( KOPrefs::instance()->mWNViewShowLocation ) 654 if ( KOPrefs::instance()->mWNViewShowLocation )
639 if ( !ev->location().isEmpty() ) 655 if ( !ev->location().isEmpty() )
640 mText += " ("+ev->location() +")"; 656 mText += " ("+ev->location() +")";
641 if ( !isSub ) { 657 if ( !isSub ) {
642 if ( ((Todo*)ev)->relatedTo()&& KOPrefs::instance()->mWNViewShowsParents) 658 if ( ((Todo*)ev)->relatedTo()&& KOPrefs::instance()->mWNViewShowsParents)
643 mText += " ["+ev->relatedTo()->summary() +"]"; 659 mText += " ["+ev->relatedTo()->summary() +"]";
644 mText += "</p>\n"; 660 mText += "</p>\n";
645 } 661 }
646 else { 662 else {
647 ind += "-"; 663 ind += "-";
648 mText += "</li>\n"; 664 mText += "</li>\n";
649 } 665 }
650 QPtrList<Incidence> Relations = ev->relations(); 666 QPtrList<Incidence> Relations = ev->relations();
651 Incidence *to; 667 Incidence *to;
652 for (to=Relations.first();to;to=Relations.next()) { 668 for (to=Relations.first();to;to=Relations.next()) {
653 if (!((Todo*)to)->isCompleted()) 669 if (!((Todo*)to)->isCompleted())
654 appendTodo( to, ind , true ); 670 appendTodo( to, ind , true );
655 } 671 }
656 672
657 return true; 673 return true;
658} 674}
659 675
660/* 676/*
661 void KOWhatsNextView::createEventViewer() 677 void KOWhatsNextView::createEventViewer()
662 { 678 {
663 if (!mEventViewer) { 679 if (!mEventViewer) {
664 680
665 mEventViewer = new KOEventViewerDialog(this); 681 mEventViewer = new KOEventViewerDialog(this);
666 } 682 }
667 } 683 }
668*/ 684*/
669void KOWhatsNextView::setEventViewer(KOEventViewerDialog* v ) 685void KOWhatsNextView::setEventViewer(KOEventViewerDialog* v )
670{ 686{
671 mEventViewer = v; 687 mEventViewer = v;
672} 688}
673 689
674// TODO: Create this function in CalendarView and remove it from here 690// TODO: Create this function in CalendarView and remove it from here
675void KOWhatsNextView::showIncidence(const QString &uid) 691void KOWhatsNextView::showIncidence(const QString &uid)
676{ 692{
693
677 if ( !mEventViewer ) { 694 if ( !mEventViewer ) {
678 qDebug("KOWhatsNextView::showIncidence::sorry, no event viewer set "); 695 qDebug("KOWhatsNextView::showIncidence::sorry, no event viewer set ");
679 return; 696 return;
680 } 697 }
681 //kdDebug() << "KOWhatsNextView::showIncidence(): " << uid << endl; 698 //kdDebug() << "KOWhatsNextView::showIncidence(): " << uid << endl;
682 //qDebug("KOWhatsNextView::showIncidence %s ", uid.latin1()); 699 //qDebug("KOWhatsNextView::showIncidence %s ", uid.latin1());
683 if (uid.startsWith("event:")) { 700 if (uid.startsWith("event:")) {
684#ifdef DESKTOP_VERSION 701#ifdef DESKTOP_VERSION
685 Event *event = calendar()->event(uid.mid(8)); 702 Event *event = calendar()->event(uid.mid(8));
686#else 703#else
687 Event *event = calendar()->event(uid.mid(6)); 704 Event *event = calendar()->event(uid.mid(6));
688#endif 705#endif
689 //qDebug("event %d uid %s ", event, uid.mid(6).latin1()); 706 //qDebug("event %d uid %s ", event, uid.mid(6).latin1());
690 if (!event) return; 707 if (!event) return;
691 //createEventViewer(); 708 //createEventViewer();
692 mEventViewer->setEvent(event); 709 mEventViewer->setEvent(event);
693 } else if (uid.startsWith("todo:")) { 710 } else if (uid.startsWith("todo:")) {
694#ifdef DESKTOP_VERSION 711#ifdef DESKTOP_VERSION
695 Todo *todo = calendar()->todo(uid.mid(7)); 712 Todo *todo = calendar()->todo(uid.mid(7));
696#else 713#else
697 Todo *todo = calendar()->todo(uid.mid(5)); 714 Todo *todo = calendar()->todo(uid.mid(5));
698#endif 715#endif
699 if (!todo) return; 716 if (!todo) return;
700 //createEventViewer(); 717 //createEventViewer();
701 mEventViewer->setTodo(todo); 718 mEventViewer->setTodo(todo);
702 } else { 719 } else {
703 return; 720 return;
704 721
705 } 722 }
706 mEventViewer->showMe(); 723 mEventViewer->showMe();
707 mEventViewer->raise(); 724 mEventViewer->raise();
708} 725}