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., 675 Mass Ave, Cambridge, MA 02139, 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 using namespace KOrg;
00043 #include "kowhatsnextview.moc"
00044 
00045 void WhatsNextTextBrowser::setSource(const QString& n)
00046 {
00047   kdDebug() << "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 QPtrList<Incidence> KOWhatsNextView::selectedIncidences()
00094 {
00095   QPtrList<Incidence> 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   QPtrList<Event> 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 *ev = events.first();
00133     while(ev) {
00134       if (!ev->recurrence()->doesRecur() || ev->recursOn( QDate::currentDate())) {
00135         appendEvent(ev);
00136       }
00137       ev = events.next();
00138     }
00139     mText += "</table>\n";
00140   }
00141 
00142   mTodos.clear();
00143   QPtrList<Todo> 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 *todo = todos.first();
00152     while(todo) {
00153       if ( todo->hasDueDate() && todo->dtDue().date() == QDate::currentDate() )
00154                   appendTodo(todo);
00155       todo = todos.next();
00156     }
00157     bool gotone = false;
00158     int priority = 1;
00159     while (!gotone && priority<6) {
00160       todo = todos.first();
00161       while(todo) {
00162         if (!todo->isCompleted() && (todo->priority() == priority) ) {
00163           appendTodo(todo);
00164           gotone = true;
00165         }
00166         todo = todos.next();
00167       }
00168       priority++;
00169       kdDebug() << "adding the todos..." << endl;
00170     }
00171     mText += "</ul>\n";
00172   }
00173 
00174   int replys = 0;
00175   events = calendar()->events(QDate::currentDate(), QDate(2975,12,6));
00176   if (events.count() > 0) {
00177     Event *ev = events.first();
00178     while(ev) {
00179       Attendee *me = ev->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
00180       if (me!=0) {
00181         if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00182           if (replys == 0) {
00183             mText += "<p></p>";
00184             kil.loadIcon("reply",KIcon::NoGroup,22,KIcon::DefaultState,ipath);
00185             mText += "<h2><img src=\"";
00186             mText += *ipath;
00187             mText += "\">";    
00188             mText += i18n("Events and To-Dos that need a reply:") + "</h2>\n";
00189             mText += "<table>\n";
00190           }
00191           replys++;
00192           appendEvent(ev,true);
00193         }
00194       }
00195       ev = events.next();
00196     }
00197   }
00198   todos = calendar()->todos();
00199   if (todos.count() > 0) {
00200     Todo *to = todos.first();
00201     while(to) {
00202       Attendee *me = to->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
00203       if (me!=0) {
00204         if (me->status()==Attendee::NeedsAction && me->RSVP()) {
00205           if (replys == 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           replys++;
00215           appendEvent(to);
00216         }
00217       }
00218       kdDebug () << "check for todo-replys..." << endl;
00219       to = todos.next();
00220     }
00221   }
00222   if (replys > 0 ) mText += "</table>\n";
00223 
00224 
00225   mText += "</td></tr>\n</table>\n";
00226 
00227   kdDebug() << "KOWhatsNextView::updateView: text: " << mText << endl;
00228   mView->setText(mText);
00229 }
00230 
00231 void KOWhatsNextView::showDates(const QDate &, const QDate &)
00232 {
00233   updateView();
00234 }
00235 
00236 void KOWhatsNextView::showEvents(QPtrList<Event>)
00237 {
00238 }
00239 
00240 void KOWhatsNextView::changeEventDisplay(Event *, int action)
00241 {
00242   switch(action) {
00243     case KOGlobals::EVENTADDED:
00244       break;
00245     case KOGlobals::EVENTEDITED:
00246       break;
00247     case KOGlobals::EVENTDELETED:
00248       break;
00249     default:
00250       kdDebug() << "KOWhatsNextView::changeEventDisplay(): Illegal action " << action << endl;
00251   }
00252 }
00253 
00254 void KOWhatsNextView::appendEvent(Incidence *ev, bool reply)
00255 {
00256   kdDebug() << "KOWhatsNextView::appendEvent(): " << ev->uid() << endl;
00257 
00258   mText += "<tr><td><b>";
00259   if (!ev->doesFloat()) {
00260     if (ev->type()=="Event") {
00261       Event *event = static_cast<Event *>(ev);
00262       if (reply) mText += "on " + event->dtStartDateStr() + ": ";
00263       mText += event->dtStartTimeStr() + " - " + event->dtEndTimeStr();
00264     }
00265   }
00266   mText += "</b></td><td><a ";
00267   if (ev->type()=="Event") mText += "href=\"event:";
00268   if (ev->type()=="Todo") mText += "href=\"todo:";
00269   mText += ev->uid() + "\">";
00270   mText += ev->summary();
00271   mText += "</a></td></tr>\n";
00272 }
00273 
00274 void KOWhatsNextView::appendTodo(Incidence *ev)
00275 {
00276   if ( mTodos.find( ev ) != mTodos.end() ) return;
00277 
00278   mTodos.append( ev );
00279 
00280   mText += "<li><a href=\"todo:" + ev->uid() + "\">";
00281   mText += ev->summary();
00282   mText += "</a></li>\n";
00283 }
00284 
00285 void KOWhatsNextView::createEventViewer()
00286 {
00287   if (!mEventViewer) {
00288     mEventViewer = new KOEventViewerDialog(this);
00289   }
00290 }
00291 
00292 // TODO: Create this function in CalendarView and remove it from here
00293 void KOWhatsNextView::showIncidence(const QString &uid)
00294 {
00295   kdDebug() << "KOWhatsNextView::showIncidence(): " << uid << endl;
00296 
00297   if (uid.startsWith("event://")) {
00298     Event *event = calendar()->event(uid.mid(8));
00299     if (!event) return;
00300     createEventViewer();
00301     mEventViewer->setEvent(event);
00302   } else if (uid.startsWith("todo://")) {
00303     Todo *todo = calendar()->todo(uid.mid(7));
00304     if (!todo) return;
00305     createEventViewer();
00306     mEventViewer->setTodo(todo);
00307   }
00308   mEventViewer->show();
00309   mEventViewer->raise();
00310 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:32 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001