korganizer Library API Documentation

koeventviewer.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 */
00020 
00021 #include "koeventviewer.h"
00022 
00023 #include "kocore.h"
00024 #include "urihandler.h"
00025 
00026 #include <libkcal/event.h>
00027 #include <libkcal/todo.h>
00028 
00029 #include <kiconloader.h>
00030 #include <klocale.h>
00031 #include <kapplication.h>
00032 #include <kdebug.h>
00033 #ifndef KORG_NOKABC
00034  #include <kabc/stdaddressbook.h>
00035 #endif
00036 
00037 KOEventViewer::KOEventViewer(QWidget *parent,const char *name)
00038   : QTextBrowser(parent,name)
00039 {
00040 }
00041 
00042 KOEventViewer::~KOEventViewer()
00043 {
00044 }
00045 
00046 void KOEventViewer::setSource( const QString &n )
00047 {
00048   UriHandler::process( n );
00049 }
00050 
00051 void KOEventViewer::addTag(const QString & tag,const QString & text)
00052 {
00053   int number=text.contains("\n");
00054   QString str = "<" + tag + ">";
00055   QString tmpText=text;
00056   QString tmpStr=str;
00057   if(number !=-1)
00058     {
00059       if (number > 0) {
00060         int pos=0;
00061         QString tmp;
00062         for(int i=0;i<=number;i++) {
00063           pos=tmpText.find("\n");
00064           tmp=tmpText.left(pos);
00065           tmpText=tmpText.right(tmpText.length()-pos-1);
00066           tmpStr+=tmp+"<br>";
00067         }
00068       }
00069       else tmpStr += tmpText;
00070       tmpStr+="</" + tag + ">";
00071       mText.append(tmpStr);
00072     }
00073   else
00074     {
00075       str += text + "</" + tag + ">";
00076       mText.append(str);
00077     }
00078 }
00079 
00080 void KOEventViewer::appendEvent(Event *event)
00081 {
00082   addTag("h1",event->summary());
00083 
00084   if (!event->location().isEmpty()) {
00085     addTag("b",i18n("Location: "));
00086     mText.append(event->location()+"<br>");
00087   }
00088   if (event->doesFloat()) {
00089     if (event->isMultiDay()) {
00090       mText.append(i18n("<b>From:</b> %1 <b>To:</b> %2")
00091                    .arg(event->dtStartDateStr())
00092                    .arg(event->dtEndDateStr()));
00093     } else {
00094       mText.append(i18n("<b>On:</b> %1").arg(event->dtStartDateStr()));
00095     }
00096   } else {
00097     if (event->isMultiDay()) {
00098       mText.append(i18n("<b>From:</b> %1 <b>To:</b> %2")
00099                    .arg(event->dtStartStr())
00100                    .arg(event->dtEndStr()));
00101     } else {
00102       mText.append(i18n("<b>On:</b> %1 <b>From:</b> %2 <b>To:</b> %3")
00103                    .arg(event->dtStartDateStr())
00104                    .arg(event->dtStartTimeStr())
00105                    .arg(event->dtEndTimeStr()));
00106     }
00107   }
00108 
00109   if (!event->description().isEmpty()) addTag("p",event->description());
00110 
00111   formatCategories(event);
00112 
00113   if (event->doesRecur()) {
00114     addTag("p","<em>" + i18n("This is a recurring event.") + "</em>");
00115   }
00116 
00117   formatReadOnly( event );
00118   formatAttendees( event );
00119   formatAttachments( event );
00120 
00121   setText( mText );
00122 }
00123 
00124 void KOEventViewer::appendTodo( Todo *todo )
00125 {
00126   addTag( "h1", todo->summary() );
00127 
00128   if ( !todo->location().isEmpty() ) {
00129     addTag( "b", i18n("Location:") );
00130     mText.append( todo->location() + "<br>" );
00131   }
00132   if ( todo->hasDueDate() ) {
00133     mText.append( i18n("<b>Due on:</b> %1").arg( todo->dtDueStr() ) );
00134   }
00135 
00136   if ( !todo->description().isEmpty() ) addTag( "p", todo->description() );
00137 
00138   formatCategories( todo );
00139 
00140   mText.append( i18n("<p><b>Priority:</b> %2</p>")
00141                 .arg( QString::number( todo->priority() ) ) );
00142 
00143   mText.append( i18n("<p><i>%1 % completed</i></p>")
00144                      .arg( todo->percentComplete() ) );
00145 
00146   formatReadOnly( todo );
00147   formatAttendees( todo );
00148   formatAttachments( todo );
00149 
00150   setText( mText );
00151 }
00152 
00153 void KOEventViewer::formatCategories(Incidence *event)
00154 {
00155   if (!event->categoriesStr().isEmpty()) {
00156     if (event->categories().count() == 1) {
00157       addTag("h2",i18n("Category"));
00158     } else {
00159       addTag("h2",i18n("Categories"));
00160     }
00161     addTag("p",event->categoriesStr());
00162   }
00163 }
00164 
00165 void KOEventViewer::formatAttendees(Incidence *event)
00166 {
00167   Attendee::List attendees = event->attendees();
00168   if ( attendees.count() ) {
00169     KIconLoader* iconLoader = new KIconLoader();
00170     QString iconPath = iconLoader->iconPath("mail_generic",KIcon::Small);
00171     addTag("h3",i18n("Organizer"));
00172     mText.append("<ul><li>");
00173 #ifndef KORG_NOKABC
00174     KABC::AddressBook *add_book = KABC::StdAddressBook::self();
00175     KABC::Addressee::List addressList;
00176     addressList = add_book->findByEmail(event->organizer());
00177     KABC::Addressee o = addressList.first();
00178     if ( !o.isEmpty() && addressList.size() < 2 ) {
00179       addLink( "uid" + o.uid(), o.formattedName() );
00180     } else {
00181       mText.append( event->organizer() );
00182     }
00183 #else
00184     mText.append( event->organizer() );
00185 #endif
00186     if ( !iconPath.isNull() ) {
00187       addLink( "mailto:" + event->organizer(),
00188                "<img src=\"" + iconPath + "\">" );
00189     }
00190     mText.append("</li></ul>");
00191 
00192     addTag("h3",i18n("Attendees"));
00193     mText.append("<ul>");
00194     Attendee::List::ConstIterator it;
00195     for( it = attendees.begin(); it != attendees.end(); ++it ) {
00196       Attendee *a = *it;
00197 #ifndef KORG_NOKABC
00198       if ( a->name().isEmpty() ) {
00199         addressList = add_book->findByEmail( a->email() );
00200         KABC::Addressee o = addressList.first();
00201         if ( !o.isEmpty() && addressList.size() < 2 ) {
00202           addLink( "uid" + o.uid(), o.formattedName() );
00203         } else {
00204           mText += "<li>";
00205           mText.append( a->email() );
00206           mText += "\n";
00207         }
00208       } else {
00209         mText += "<li><a href=\"uid:" + a->uid() + "\">";
00210         if (!a->name().isEmpty()) mText += a->name();
00211         else mText += a->email();
00212         mText += "</a>\n";
00213       }
00214 #else
00215       mText += "<li><a href=\"uid:" + a->uid() + "\">";
00216       if (!a->name().isEmpty()) mText += a->name();
00217       else mText += a->email();
00218       mText += "</a>\n";
00219 #endif
00220       kdDebug(5850) << "formatAttendees: uid = " << a->uid() << endl;
00221 
00222       if (!a->email().isEmpty()) {
00223         if (!iconPath.isNull()) {
00224           mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">";
00225           mText += "<img src=\"" + iconPath + "\">";
00226           mText += "</a>\n";
00227         }
00228       }
00229     }
00230     mText.append("</li></ul>");
00231   }
00232 }
00233 
00234 void KOEventViewer::formatReadOnly( Incidence *i )
00235 {
00236   if ( i->isReadOnly() ) {
00237     addTag( "p", "<em>(" + i18n("read-only") + ")</em>" );
00238   }
00239 }
00240 
00241 void KOEventViewer::formatAttachments( Incidence *i )
00242 {
00243   Attachment::List as = i->attachments();
00244   if ( as.count() > 0 ) {
00245     mText += "<ul>";
00246     Attachment::List::ConstIterator it;
00247     for( it = as.begin(); it != as.end(); ++it ) {
00248       if ( (*it)->isUri() ) {
00249         mText += "<li>";
00250         addLink( (*it)->uri(), (*it)->uri() );
00251         mText += "</li>";
00252       }
00253     }
00254     mText += "</ul>";
00255   }
00256 }
00257 
00258 void KOEventViewer::setTodo(Todo *event)
00259 {
00260   clearEvents();
00261   appendTodo(event);
00262 }
00263 
00264 void KOEventViewer::setEvent(Event *event)
00265 {
00266   clearEvents();
00267   appendEvent(event);
00268 }
00269 
00270 void KOEventViewer::addEvent(Event *event)
00271 {
00272   appendEvent(event);
00273 }
00274 
00275 void KOEventViewer::clearEvents(bool now)
00276 {
00277   mText = "";
00278   if (now) setText(mText);
00279 }
00280 
00281 void KOEventViewer::addText( const QString &text )
00282 {
00283   mText.append( text );
00284   setText( mText );
00285 }
00286 
00287 void KOEventViewer::addLink( const QString &ref, const QString &text,
00288                              bool newline )
00289 {
00290   mText += "<a href=\"" + ref + "\">" + text + "</a>";
00291   if ( newline ) mText += "\n";
00292 }
00293 
00294 #include "koeventviewer.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:29 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003