kowhatsnextview.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qlayout.h>
00026 #include <qtextbrowser.h>
00027 #include <qtextcodec.h>
00028 #include <qfileinfo.h>
00029 #include <qlabel.h>
00030
00031 #include <kglobal.h>
00032 #include <klocale.h>
00033 #include <kdebug.h>
00034 #include <kiconloader.h>
00035 #include <kmessagebox.h>
00036
00037 #include <libkcal/calendar.h>
00038
00039 #ifndef KORG_NOPRINTER
00040 #include "calprinter.h"
00041 #endif
00042 #include "koglobals.h"
00043 #include "koprefs.h"
00044 #include "koeventviewerdialog.h"
00045
00046 #include "kowhatsnextview.h"
00047
00048 using namespace KOrg;
00049
00050 void WhatsNextTextBrowser::setSource(const QString& n)
00051 {
00052 kdDebug(5850) << "WhatsNextTextBrowser::setSource(): " << n << endl;
00053
00054 if (n.startsWith("event:")) {
00055 emit showIncidence(n);
00056 return;
00057 } else if (n.startsWith("todo:")) {
00058 emit showIncidence(n);
00059 return;
00060 } else {
00061 QTextBrowser::setSource(n);
00062 }
00063 }
00064
00065 KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
00066 const char *name)
00067 : KOrg::BaseView(calendar, parent, name)
00068 {
00069 QLabel *dateLabel =
00070 new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this);
00071 dateLabel->setMargin(2);
00072 dateLabel->setAlignment(AlignCenter);
00073
00074 mView = new WhatsNextTextBrowser(this);
00075 connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &)));
00076
00077 QBoxLayout *topLayout = new QVBoxLayout(this);
00078 topLayout->addWidget(dateLabel);
00079 topLayout->addWidget(mView);
00080 }
00081
00082 KOWhatsNextView::~KOWhatsNextView()
00083 {
00084 }
00085
00086 int KOWhatsNextView::maxDatesHint()
00087 {
00088 return 0;
00089 }
00090
00091 int KOWhatsNextView::currentDateCount()
00092 {
00093 return 0;
00094 }
00095
00096 Incidence::List KOWhatsNextView::selectedIncidences()
00097 {
00098 Incidence::List eventList;
00099
00100 return eventList;
00101 }
00102
00103
00104 void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
00105 const QDate &td)
00106 {
00107 #ifndef KORG_NOPRINTER
00108 calPrinter->preview(CalPrinter::Day, fd, td);
00109 #endif
00110 }
00111
00112 void KOWhatsNextView::updateView()
00113 {
00114 KIconLoader kil("korganizer");
00115 QString *ipath = new QString();
00116 kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,ipath);
00117
00118 mText = "<table width=\"100%\">\n";
00119 mText += "<tr bgcolor=\"#3679AD\"><td><h1>";
00120 mText += "<img src=\"";
00121 mText += *ipath;
00122 mText += "\">";
00123 mText += "<font color=\"white\"> " + i18n("What's next?") + "</font></h1>";
00124 mText += "</td></tr>\n<tr><td>";
00125
00126 Event::List events = calendar()->events( QDate::currentDate(), true );
00127 if (events.count() > 0) {
00128 mText += "<p></p>";
00129 kil.loadIcon("appointment",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00130 mText += "<h2><img src=\"";
00131 mText += *ipath;
00132 mText += "\">";
00133 mText += i18n("Events:") + "</h2>\n";
00134 mText += "<table>\n";
00135 Event::List::ConstIterator it;
00136 for( it = events.begin(); it != events.end(); ++it ) {
00137 Event *ev = *it;
00138 if (!ev->doesRecur() || ev->recursOn( QDate::currentDate())) {
00139 appendEvent(ev);
00140 }
00141 }
00142 mText += "</table>\n";
00143 }
00144
00145 mTodos.clear();
00146 Todo::List todos = calendar()->todos();
00147 if ( todos.count() > 0 ) {
00148 kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00149 mText += "<h2><img src=\"";
00150 mText += *ipath;
00151 mText += "\">";
00152 mText += i18n("To-Do:") + "</h2>\n";
00153 mText += "<ul>\n";
00154 Todo::List::ConstIterator it;
00155 for( it = todos.begin(); it != todos.end(); ++it ) {
00156 Todo *todo = *it;
00157 if ( !todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
00158 appendTodo(todo);
00159 }
00160 bool gotone = false;
00161 int priority = 1;
00162 while (!gotone && priority<6) {
00163 for( it = todos.begin(); it != todos.end(); ++it ) {
00164 Todo *todo = *it;
00165 if (!todo->isCompleted() && (todo->priority() == priority) ) {
00166 appendTodo(todo);
00167 gotone = true;
00168 }
00169 }
00170 priority++;
00171 kdDebug(5850) << "adding the todos..." << endl;
00172 }
00173 mText += "</ul>\n";
00174 }
00175
00176 int replies = 0;
00177 events = calendar()->events(QDate::currentDate(), QDate(2975,12,6));
00178 Event::List::ConstIterator it2;
00179 for( it2 = events.begin(); it2 != events.end(); ++it2 ) {
00180 Event *ev = *it2;
00181 Attendee *me = ev->attendeeByMails( KOPrefs::instance()->allEmails() );
00182 if (me!=0) {
00183 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00184 if (replies == 0) {
00185 mText += "<p></p>";
00186 kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00187 mText += "<h2><img src=\"";
00188 mText += *ipath;
00189 mText += "\">";
00190 mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00191 mText += "<table>\n";
00192 }
00193 replies++;
00194 appendEvent(ev,true);
00195 }
00196 }
00197 }
00198 todos = calendar()->todos();
00199 Todo::List::ConstIterator it3;
00200 for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) {
00201 Todo *to = *it3;
00202 Attendee *me = to->attendeeByMails( KOPrefs::instance()->allEmails() );
00203 if (me!=0) {
00204 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00205 if (replies == 0) {
00206 mText += "<p></p>";
00207 kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00208 mText += "<h2><img src=\"";
00209 mText += *ipath;
00210 mText += "\">";
00211 mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00212 mText += "<table>\n";
00213 }
00214 replies++;
00215 appendEvent(to);
00216 }
00217 }
00218 kdDebug () << "check for todo-replies..." << endl;
00219 }
00220 if (replies > 0 ) mText += "</table>\n";
00221
00222
00223 mText += "</td></tr>\n</table>\n";
00224
00225 kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl;
00226 mView->setText(mText);
00227 }
00228
00229 void KOWhatsNextView::showDates(const QDate &, const QDate &)
00230 {
00231 updateView();
00232 }
00233
00234 void KOWhatsNextView::showIncidences( const Incidence::List & )
00235 {
00236 }
00237
00238 void KOWhatsNextView::changeIncidenceDisplay(Incidence *, int action)
00239 {
00240 switch(action) {
00241 case KOGlobals::INCIDENCEADDED:
00242 break;
00243 case KOGlobals::INCIDENCEEDITED:
00244 break;
00245 case KOGlobals::INCIDENCEDELETED:
00246 break;
00247 default:
00248 kdDebug(5850) << "KOWhatsNextView::changeIncidenceDisplay(): Illegal action " << action << endl;
00249 }
00250 }
00251
00252 void KOWhatsNextView::appendEvent(Incidence *ev, bool reply)
00253 {
00254 kdDebug(5850) << "KOWhatsNextView::appendEvent(): " << ev->uid() << endl;
00255
00256 mText += "<tr><td><b>";
00257 if (!ev->doesFloat()) {
00258 if (ev->type()=="Event") {
00259 Event *event = static_cast<Event *>(ev);
00260 if (reply) mText += "on " + event->dtStartDateStr() + ": ";
00261 mText += event->dtStartTimeStr() + " - " + event->dtEndTimeStr();
00262 }
00263 }
00264 mText += "</b></td><td><a ";
00265 if (ev->type()=="Event") mText += "href=\"event:";
00266 if (ev->type()=="Todo") mText += "href=\"todo:";
00267 mText += ev->uid() + "\">";
00268 mText += ev->summary();
00269 mText += "</a></td></tr>\n";
00270 }
00271
00272 void KOWhatsNextView::appendTodo(Incidence *ev)
00273 {
00274 if ( mTodos.find( ev ) != mTodos.end() ) return;
00275
00276 mTodos.append( ev );
00277
00278 mText += "<li><a href=\"todo:" + ev->uid() + "\">";
00279 mText += ev->summary();
00280 mText += "</a></li>\n";
00281 }
00282
00283 void KOWhatsNextView::showIncidence( const QString &uid )
00284 {
00285 kdDebug(5850) << "KOWhatsNextView::showIncidence(): " << uid << endl;
00286 Incidence *incidence = 0;
00287
00288 if ( uid.startsWith( "event://" ) ) {
00289 incidence = calendar()->incidence( uid.mid( 8 ) );
00290 } else if ( uid.startsWith( "todo://" ) ) {
00291 incidence = calendar()->incidence( uid.mid( 7 ) );
00292 }
00293 if ( incidence ) emit showIncidenceSignal( incidence );
00294 }
00295
00296 #include "kowhatsnextview.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.