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 QStringList myEmails( KOPrefs::instance()->allEmails() );
00177 int replies = 0;
00178 events = calendar()->events(QDate::currentDate(), QDate(2975,12,6));
00179 Event::List::ConstIterator it2;
00180 for( it2 = events.begin(); it2 != events.end(); ++it2 ) {
00181 Event *ev = *it2;
00182 Attendee *me = ev->attendeeByMails( myEmails );
00183 if (me!=0) {
00184 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00185 if (replies == 0) {
00186 mText += "<p></p>";
00187 kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00188 mText += "<h2><img src=\"";
00189 mText += *ipath;
00190 mText += "\">";
00191 mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00192 mText += "<table>\n";
00193 }
00194 replies++;
00195 appendEvent(ev,true);
00196 }
00197 }
00198 }
00199 todos = calendar()->todos();
00200 Todo::List::ConstIterator it3;
00201 for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) {
00202 Todo *to = *it3;
00203 Attendee *me = to->attendeeByMails( myEmails );
00204 if (me!=0) {
00205 if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00206 if (replies == 0) {
00207 mText += "<p></p>";
00208 kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00209 mText += "<h2><img src=\"";
00210 mText += *ipath;
00211 mText += "\">";
00212 mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00213 mText += "<table>\n";
00214 }
00215 replies++;
00216 appendEvent(to);
00217 }
00218 }
00219 kdDebug () << "check for todo-replies..." << endl;
00220 }
00221 if (replies > 0 ) mText += "</table>\n";
00222
00223
00224 mText += "</td></tr>\n</table>\n";
00225
00226 kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl;
00227 mView->setText(mText);
00228 }
00229
00230 void KOWhatsNextView::showDates(const QDate &, const QDate &)
00231 {
00232 updateView();
00233 }
00234
00235 void KOWhatsNextView::showIncidences( const Incidence::List & )
00236 {
00237 }
00238
00239 void KOWhatsNextView::changeIncidenceDisplay(Incidence *, int action)
00240 {
00241 switch(action) {
00242 case KOGlobals::INCIDENCEADDED:
00243 break;
00244 case KOGlobals::INCIDENCEEDITED:
00245 break;
00246 case KOGlobals::INCIDENCEDELETED:
00247 break;
00248 default:
00249 kdDebug(5850) << "KOWhatsNextView::changeIncidenceDisplay(): Illegal action " << action << endl;
00250 }
00251 }
00252
00253 void KOWhatsNextView::appendEvent(Incidence *ev, bool reply)
00254 {
00255 kdDebug(5850) << "KOWhatsNextView::appendEvent(): " << ev->uid() << endl;
00256
00257 mText += "<tr><td><b>";
00258 if (!ev->doesFloat()) {
00259 if (ev->type()=="Event") {
00260 Event *event = static_cast<Event *>(ev);
00261 if (reply) mText += "on " + event->dtStartDateStr() + ": ";
00262 mText += event->dtStartTimeStr() + " - " + event->dtEndTimeStr();
00263 }
00264 }
00265 mText += "</b></td><td><a ";
00266 if (ev->type()=="Event") mText += "href=\"event:";
00267 if (ev->type()=="Todo") mText += "href=\"todo:";
00268 mText += ev->uid() + "\">";
00269 mText += ev->summary();
00270 mText += "</a></td></tr>\n";
00271 }
00272
00273 void KOWhatsNextView::appendTodo(Incidence *ev)
00274 {
00275 if ( mTodos.find( ev ) != mTodos.end() ) return;
00276
00277 mTodos.append( ev );
00278
00279 mText += "<li><a href=\"todo:" + ev->uid() + "\">";
00280 mText += ev->summary();
00281 mText += "</a></li>\n";
00282 }
00283
00284 void KOWhatsNextView::showIncidence( const QString &uid )
00285 {
00286 kdDebug(5850) << "KOWhatsNextView::showIncidence(): " << uid << endl;
00287 Incidence *incidence = 0;
00288
00289 if ( uid.startsWith( "event://" ) ) {
00290 incidence = calendar()->incidence( uid.mid( 8 ) );
00291 } else if ( uid.startsWith( "todo://" ) ) {
00292 incidence = calendar()->incidence( uid.mid( 7 ) );
00293 }
00294 if ( incidence ) emit showIncidenceSignal( incidence );
00295 }
00296
00297 #include "kowhatsnextview.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.