kalarmd Library API Documentation

koeventviewer.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     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 // $Id: koeventviewer.cpp,v 1.7 2002/01/16 16:57:02 cschumac Exp $
00025 
00026 #include <klocale.h>
00027 
00028 #include <libkcal/event.h>
00029 #include <libkcal/todo.h>
00030 
00031 #include "compat.h"
00032 
00033 #include "koeventviewer.h"
00034 #include "koeventviewer.moc"
00035 
00036 KOEventViewer::KOEventViewer(QWidget *parent,const char *name)
00037   : QTextView(parent,name)
00038 {
00039 }
00040 
00041 KOEventViewer::~KOEventViewer()
00042 {
00043 }
00044 
00045 void KOEventViewer::addTag(const QString & tag,const QString & text)
00046 {
00047   int number=text.contains("\n");
00048   QString str = "<" + tag + ">";
00049   QString tmpText=text;
00050   QString tmpStr=str;
00051   if(number !=-1)  
00052     {
00053       int pos=0;
00054       QString tmp;
00055       for(int i=0;i<=number;i++)
00056         {
00057           pos=tmpText.find("\n");
00058           tmp=tmpText.left(pos);
00059           tmpText=tmpText.right(tmpText.length()-pos-1);
00060           tmpStr+=tmp+"<br>";
00061         }
00062       tmpStr+="</" + tag + ">";
00063       mText.append(tmpStr);
00064     }
00065   else
00066     {
00067       str += text + "</" + tag + ">";
00068       mText.append(str);
00069     }
00070 }
00071 
00072 void KOEventViewer::appendEvent(Event *event)
00073 {
00074   addTag("h1",event->summary());
00075   
00076   if (event->doesFloat()) {
00077     if (event->isMultiDay()) {
00078       mText.append(i18n("<b>From:</b> %1 <b>To:</b> %2")
00079                    .arg(event->dtStartDateStr())
00080                    .arg(event->dtEndDateStr()));
00081     } else {
00082       mText.append(i18n("<b>On:</b> %1").arg(event->dtStartDateStr()));
00083     }
00084   } else {
00085     if (event->isMultiDay()) {
00086       mText.append(i18n("<b>From:</b> %1 <b>To:</b> %2")
00087                    .arg(event->dtStartStr())
00088                    .arg(event->dtEndStr()));
00089     } else {
00090       mText.append(i18n("<b>On:</b> %1 <b>From:</b> %2 <b>To:</b> %3")
00091                    .arg(event->dtStartDateStr())
00092                    .arg(event->dtStartTimeStr())
00093                    .arg(event->dtEndTimeStr()));
00094     }
00095   }
00096 
00097   if (!event->description().isEmpty()) addTag("p",event->description());
00098 
00099   formatCategories(event);
00100   formatAttendees(event);
00101 
00102   if (event->recurrence()->doesRecur()) {
00103     addTag("p","<em>" + i18n("This is a recurring event.") + "</em>");
00104   }
00105 
00106   formatReadOnly(event);
00107 
00108   setText(mText);
00109 }
00110 
00111 void KOEventViewer::appendTodo(Todo *event)
00112 {
00113   addTag("h1",event->summary());
00114   
00115   if (event->hasDueDate()) {
00116     mText.append(i18n("<b>Due on:</b> %1").arg(event->dtDueStr()));
00117   }
00118 
00119   if (!event->description().isEmpty()) addTag("p",event->description());  
00120 
00121   formatCategories(event);
00122   formatAttendees(event);
00123 
00124   mText.append(i18n("<p><b>Priority:</b> %2</p>")
00125                .arg(QString::number(event->priority())));
00126 
00127   mText.append(i18n("<p><i>%1 % completed</i></p>")
00128                     .arg(event->percentComplete()));
00129 
00130   formatReadOnly(event);
00131 
00132   setText(mText);
00133 }
00134 
00135 void KOEventViewer::formatCategories(Incidence *event)
00136 {
00137   if (!event->categoriesStr().isEmpty()) {
00138     if (event->categories().count() == 1) {
00139       addTag("h2",i18n("Category"));
00140     } else {
00141       addTag("h2",i18n("Categories"));
00142     }
00143     addTag("p",event->categoriesStr());
00144   }
00145 }
00146 
00147 void KOEventViewer::formatAttendees(Incidence *event)
00148 {
00149   QPtrList<Attendee> attendees = event->attendees();
00150   if (attendees.count()) {
00151     addTag("h2",i18n("Attendees"));
00152     Attendee *a;
00153     mText.append("<ul>");
00154     for(a=attendees.first();a;a=attendees.next()) {
00155       QString str = a->name();
00156       if (!a->email().isEmpty()) str += " &lt;" + a->email() + "&gt;";
00157       addTag("li",str);
00158     }
00159     mText.append("</ul>");
00160   }
00161 }
00162 
00163 void KOEventViewer::formatReadOnly(Incidence *event)
00164 {
00165   if (event->isReadOnly()) {
00166     addTag("p","<em>(" + i18n("read-only") + ")</em>");
00167   }
00168 }
00169 
00170 
00171 void KOEventViewer::setTodo(Todo *event)
00172 {
00173   clearEvents();
00174   appendTodo(event);
00175 }
00176 
00177 void KOEventViewer::setEvent(Event *event)
00178 {
00179   clearEvents();
00180   appendEvent(event);
00181 }
00182 
00183 void KOEventViewer::clearEvents(bool now)
00184 {
00185   mText = "";
00186   if (now) setText(mText);
00187 }
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:22 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001