korganizer Library API Documentation

kowhatsnextview.cpp

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 #include <qlayout.h>
00021 #include <qtextbrowser.h>
00022 #include <qtextcodec.h>
00023 #include <qfileinfo.h>
00024 #include <qlabel.h>
00025 
00026 #include <kglobal.h>
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029 #include <kiconloader.h>
00030 #include <kmessagebox.h>
00031 
00032 #include <libkcal/calendar.h>
00033 
00034 #ifndef KORG_NOPRINTER
00035 #include "calprinter.h"
00036 #endif
00037 #include "koglobals.h"
00038 #include "koprefs.h"
00039 #include "koeventviewerdialog.h"
00040 
00041 #include "kowhatsnextview.h"
00042 
00043 using namespace KOrg;
00044 
00045 void WhatsNextTextBrowser::setSource(const QString& n)
00046 {
00047   kdDebug(5850) << "WhatsNextTextBrowser::setSource(): " << n << endl;
00048 
00049   if (n.startsWith("event:")) {
00050     emit showIncidence(n);
00051     return;
00052   } else if (n.startsWith("todo:")) {
00053     emit showIncidence(n);
00054     return;
00055   } else {
00056     QTextBrowser::setSource(n);
00057   }
00058 }
00059 
00060 KOWhatsNextView::KOWhatsNextView(Calendar *calendar, QWidget *parent,
00061                                  const char *name)
00062   : KOrg::BaseView(calendar, parent, name)
00063 {
00064   QLabel *dateLabel =
00065       new QLabel(KGlobal::locale()->formatDate(QDate::currentDate()),this);
00066   dateLabel->setMargin(2);
00067   dateLabel->setAlignment(AlignCenter);
00068 
00069   mView = new WhatsNextTextBrowser(this);
00070   connect(mView,SIGNAL(showIncidence(const QString &)),SLOT(showIncidence(const QString &)));
00071 
00072   mEventViewer = 0;
00073 
00074   QBoxLayout *topLayout = new QVBoxLayout(this);
00075   topLayout->addWidget(dateLabel);
00076   topLayout->addWidget(mView);
00077 }
00078 
00079 KOWhatsNextView::~KOWhatsNextView()
00080 {
00081 }
00082 
00083 int KOWhatsNextView::maxDatesHint()
00084 {
00085   return 0;
00086 }
00087 
00088 int KOWhatsNextView::currentDateCount()
00089 {
00090   return 0;
00091 }
00092 
00093 Incidence::List KOWhatsNextView::selectedIncidences()
00094 {
00095   Incidence::List eventList;
00096 
00097   return eventList;
00098 }
00099 
00100 
00101 void KOWhatsNextView::printPreview(CalPrinter *calPrinter, const QDate &fd,
00102                                const QDate &td)
00103 {
00104 #ifndef KORG_NOPRINTER
00105   calPrinter->preview(CalPrinter::Day, fd, td);
00106 #endif
00107 }
00108 
00109 void KOWhatsNextView::updateView()
00110 {
00111   KIconLoader kil("korganizer");
00112   QString *ipath = new QString();
00113   kil.loadIcon("korganizer",KIcon::NoGroup,32,KIcon::DefaultState,ipath);
00114 
00115   mText = "<table width=\"100%\">\n";
00116   mText += "<tr bgcolor=\"#3679AD\"><td><h1>";
00117   mText += "<img src=\"";
00118   mText += *ipath;
00119   mText += "\">";
00120   mText += "<font color=\"white\"> " + i18n("What's next?") + "</font></h1>";
00121   mText += "</td></tr>\n<tr><td>";
00122 
00123   Event::List events = calendar()->events( QDate::currentDate(), true );
00124   if (events.count() > 0) {
00125     mText += "<p></p>";
00126     kil.loadIcon("appointment",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00127     mText += "<h2><img src=\"";
00128     mText += *ipath;
00129     mText += "\">";
00130     mText += i18n("Events:") + "</h2>\n";
00131     mText += "<table>\n";
00132     Event::List::ConstIterator it;
00133     for( it = events.begin(); it != events.end(); ++it ) {
00134       Event *ev = *it;
00135       if (!ev->doesRecur() || ev->recursOn( QDate::currentDate())) {
00136         appendEvent(ev);
00137       }
00138     }
00139     mText += "</table>\n";
00140   }
00141 
00142   mTodos.clear();
00143   Todo::List todos = calendar()->todos();
00144   if ( todos.count() > 0 ) {
00145     kil.loadIcon("todo",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00146     mText += "<h2><img src=\"";
00147     mText += *ipath;
00148     mText += "\">";
00149     mText += i18n("To-Do:") + "</h2>\n";
00150     mText += "<ul>\n";
00151     Todo::List::ConstIterator it;
00152     for( it = todos.begin(); it != todos.end(); ++it ) {
00153       Todo *todo = *it;
00154       if ( !todo->isCompleted() && todo->hasDueDate() && todo->dtDue().date() <= QDate::currentDate() )
00155                   appendTodo(todo);
00156     }
00157     bool gotone = false;
00158     int priority = 1;
00159     while (!gotone && priority<6) {
00160       for( it = todos.begin(); it != todos.end(); ++it ) {
00161         Todo *todo = *it;
00162         if (!todo->isCompleted() && (todo->priority() == priority) ) {
00163           appendTodo(todo);
00164           gotone = true;
00165         }
00166       }
00167       priority++;
00168       kdDebug(5850) << "adding the todos..." << endl;
00169     }
00170     mText += "</ul>\n";
00171   }
00172 
00173   int replies = 0;
00174   events = calendar()->events(QDate::currentDate(), QDate(2975,12,6));
00175   Event::List::ConstIterator it2;
00176   for( it2 = events.begin(); it2 != events.end(); ++it2 ) {
00177     Event *ev = *it2;
00178     Attendee *me = ev->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
00179     if (me!=0) {
00180       if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00181         if (replies == 0) {
00182           mText += "<p></p>";
00183           kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00184           mText += "<h2><img src=\"";
00185           mText += *ipath;
00186           mText += "\">";
00187           mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00188           mText += "<table>\n";
00189         }
00190         replies++;
00191         appendEvent(ev,true);
00192       }
00193     }
00194   }
00195   todos = calendar()->todos();
00196   Todo::List::ConstIterator it3;
00197   for( it3 = todos.begin(); it3 != todos.end(); ++it3 ) {
00198     Todo *to = *it3;
00199     Attendee *me = to->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
00200     if (me!=0) {
00201       if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00202         if (replies == 0) {
00203           mText += "<p></p>";
00204           kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00205           mText += "<h2><img src=\"";
00206           mText += *ipath;
00207           mText += "\">";
00208           mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00209           mText += "<table>\n";
00210         }
00211         replies++;
00212         appendEvent(to);
00213       }
00214     }
00215     kdDebug () << "check for todo-replies..." << endl;
00216   }
00217   if (replies > 0 ) mText += "</table>\n";
00218 
00219 
00220   mText += "</td></tr>\n</table>\n";
00221 
00222   kdDebug(5850) << "KOWhatsNextView::updateView: text: " << mText << endl;
00223   mView->setText(mText);
00224 }
00225 
00226 void KOWhatsNextView::showDates(const QDate &, const QDate &)
00227 {
00228   updateView();
00229 }
00230 
00231 void KOWhatsNextView::showEvents( const Event::List & )
00232 {
00233 }
00234 
00235 void KOWhatsNextView::changeEventDisplay(Event *, int action)
00236 {
00237   switch(action) {
00238     case KOGlobals::EVENTADDED:
00239       break;
00240     case KOGlobals::EVENTEDITED:
00241       break;
00242     case KOGlobals::EVENTDELETED:
00243       break;
00244     default:
00245       kdDebug(5850) << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl;
00246   }
00247 }
00248 
00249 void KOWhatsNextView::appendEvent(Incidence *ev, bool reply)
00250 {
00251   kdDebug(5850) << "KOWhatsNextView::appendEvent(): " << ev->uid() << endl;
00252 
00253   mText += "<tr><td><b>";
00254   if (!ev->doesFloat()) {
00255     if (ev->type()=="Event") {
00256       Event *event = static_cast<Event *>(ev);
00257       if (reply) mText += "on " + event->dtStartDateStr() + ": ";
00258       mText += event->dtStartTimeStr() + " - " + event->dtEndTimeStr();
00259     }
00260   }
00261   mText += "</b></td><td><a ";
00262   if (ev->type()=="Event") mText += "href=\"event:";
00263   if (ev->type()=="Todo") mText += "href=\"todo:";
00264   mText += ev->uid() + "\">";
00265   mText += ev->summary();
00266   mText += "</a></td></tr>\n";
00267 }
00268 
00269 void KOWhatsNextView::appendTodo(Incidence *ev)
00270 {
00271   if ( mTodos.find( ev ) != mTodos.end() ) return;
00272 
00273   mTodos.append( ev );
00274 
00275   mText += "<li><a href=\"todo:" + ev->uid() + "\">";
00276   mText += ev->summary();
00277   mText += "</a></li>\n";
00278 }
00279 
00280 void KOWhatsNextView::createEventViewer()
00281 {
00282   if (!mEventViewer) {
00283     mEventViewer = new KOEventViewerDialog(this);
00284   }
00285 }
00286 
00287 // TODO: Create this function in CalendarView and remove it from here
00288 void KOWhatsNextView::showIncidence(const QString &uid)
00289 {
00290   kdDebug(5850) << "KOWhatsNextView::showIncidence(): " << uid << endl;
00291 
00292   if (uid.startsWith("event://")) {
00293     Event *event = calendar()->event(uid.mid(8));
00294     if (!event) return;
00295     createEventViewer();
00296     mEventViewer->setEvent(event);
00297   } else if (uid.startsWith("todo://")) {
00298     Todo *todo = calendar()->todo(uid.mid(7));
00299     if (!todo) return;
00300     createEventViewer();
00301     mEventViewer->setTodo(todo);
00302   }
00303   mEventViewer->show();
00304   mEventViewer->raise();
00305 }
00306 
00307 #include "kowhatsnextview.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:31 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003