korganizer 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 
00020 #include <qcstring.h>
00021 
00022 #include <klocale.h>
00023 #include <kapplication.h>
00024 #include <libkcal/event.h>
00025 #include <libkcal/todo.h>
00026 #include <kdebug.h>
00027 #include <kiconloader.h>
00028 #include <krun.h>
00029 #include <kprocess.h>
00030 #ifndef KORG_NOKABC
00031  #include <kabc/stdaddressbook.h>
00032 #endif
00033 
00034 #ifndef KORG_NODCOP
00035 #include <dcopclient.h>
00036 #include "korganizer.h"
00037 #endif
00038 
00039 #include "koeventviewer.h"
00040 #include "koeventviewer.moc"
00041 
00042 KOEventViewer::KOEventViewer(QWidget *parent,const char *name)
00043   : QTextBrowser(parent,name)
00044 {
00045 }
00046 
00047 KOEventViewer::~KOEventViewer()
00048 {
00049 }
00050 
00051 void KOEventViewer::setSource(const QString& n)
00052 {
00053 #ifndef KORG_NODCOP
00054   kdDebug() << "KOEventViewer::setSource(): " << n << endl;
00055   QString tmpStr;
00056   if (n.startsWith("mailto:")) {
00057     KApplication::kApplication()->invokeMailer(n.mid(7),QString::null);
00058     //emit showIncidence(n);
00059     return;
00060   } else if (n.startsWith("uid:")) {
00061     DCOPClient *client = KApplication::kApplication()->dcopClient();
00062     const QByteArray noParamData;
00063     const QByteArray paramData;
00064     QByteArray replyData;
00065     QCString replyTypeStr;
00066     #define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()",  noParamData, replyTypeStr, replyData))
00067     bool foundAbbrowser = PING_ABBROWSER;
00068 
00069     if (foundAbbrowser) {
00070       //KAddressbook is already running, so just DCOP to it to bring up the contact editor
00071       //client->send("kaddressbook","KAddressBookIface",
00072       QDataStream arg(paramData, IO_WriteOnly);
00073       arg << n.mid(6);
00074       client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )",  paramData);
00075       return;
00076     } else {
00077       /*
00078         KaddressBook is not already running.  Pass it the UID of the contact via the command line while starting it - its neater.
00079         We start it without its main interface
00080       */
00081       KIconLoader* iconLoader = new KIconLoader();
00082       QString iconPath = iconLoader->iconPath("go",KIcon::Small);
00083       KOrganizer::setStartedKAddressBook(true);
00084       tmpStr = "kaddressbook --editor-only --uid ";
00085       tmpStr += KProcess::quote(n.mid(6));
00086       KRun::runCommand(tmpStr,"KAddressBook",iconPath);
00087       return;
00088     }
00089   } else {
00090     //QTextBrowser::setSource(n);
00091   }
00092 #endif
00093 }
00094 
00095 void KOEventViewer::addTag(const QString & tag,const QString & text)
00096 {
00097   int number=text.contains("\n");
00098   QString str = "<" + tag + ">";
00099   QString tmpText=text;
00100   QString tmpStr=str;
00101   if(number !=-1) 
00102     {
00103       if (number > 0) {
00104         int pos=0;
00105         QString tmp;
00106         for(int i=0;i<=number;i++) {
00107           pos=tmpText.find("\n");
00108           tmp=tmpText.left(pos);
00109           tmpText=tmpText.right(tmpText.length()-pos-1);
00110           tmpStr+=tmp+"<br>";
00111         }
00112       }
00113       else tmpStr += tmpText;
00114       tmpStr+="</" + tag + ">";
00115       mText.append(tmpStr);
00116     }
00117   else
00118     {
00119       str += text + "</" + tag + ">";
00120       mText.append(str);
00121     }
00122 }
00123 
00124 void KOEventViewer::appendEvent(Event *event)
00125 {
00126   addTag("h1",event->summary());
00127   
00128   if (!event->location().isEmpty()) {
00129     addTag("b",i18n("Location: "));
00130     mText.append(event->location()+"<br>");
00131   }
00132   if (event->doesFloat()) {
00133     if (event->isMultiDay()) {
00134       mText.append(i18n("<b>From:</b> %1 <b>To:</b> %2")
00135                    .arg(event->dtStartDateStr())
00136                    .arg(event->dtEndDateStr()));
00137     } else {
00138       mText.append(i18n("<b>On:</b> %1").arg(event->dtStartDateStr()));
00139     }
00140   } else {
00141     if (event->isMultiDay()) {
00142       mText.append(i18n("<b>From:</b> %1 <b>To:</b> %2")
00143                    .arg(event->dtStartStr())
00144                    .arg(event->dtEndStr()));
00145     } else {
00146       mText.append(i18n("<b>On:</b> %1 <b>From:</b> %2 <b>To:</b> %3")
00147                    .arg(event->dtStartDateStr())
00148                    .arg(event->dtStartTimeStr())
00149                    .arg(event->dtEndTimeStr()));
00150     }
00151   }
00152 
00153   if (!event->description().isEmpty()) addTag("p",event->description());
00154 
00155   formatCategories(event);
00156 
00157   if (event->recurrence()->doesRecur()) {
00158     addTag("p","<em>" + i18n("This is a recurring event.") + "</em>");
00159   }
00160 
00161   formatReadOnly(event);
00162   formatAttendees(event);
00163 
00164   setText(mText);
00165 }
00166 
00167 void KOEventViewer::appendTodo(Todo *event)
00168 {
00169   addTag("h1",event->summary());
00170 
00171   if (!event->location().isEmpty()) {
00172     addTag("b",i18n("Location: "));
00173     mText.append(event->location()+"<br>");
00174   }
00175   if (event->hasDueDate()) {
00176     mText.append(i18n("<b>Due on:</b> %1").arg(event->dtDueStr()));
00177   }
00178 
00179   if (!event->description().isEmpty()) addTag("p",event->description());
00180 
00181   formatCategories(event);
00182 
00183   mText.append(i18n("<p><b>Priority:</b> %2</p>")
00184                .arg(QString::number(event->priority())));
00185 
00186   mText.append(i18n("<p><i>%1 % completed</i></p>")
00187                     .arg(event->percentComplete()));
00188 
00189   formatReadOnly(event);
00190   formatAttendees(event);
00191 
00192   setText(mText);
00193 }
00194 
00195 void KOEventViewer::formatCategories(Incidence *event)
00196 {
00197   if (!event->categoriesStr().isEmpty()) {
00198     if (event->categories().count() == 1) {
00199       addTag("h2",i18n("Category"));
00200     } else {
00201       addTag("h2",i18n("Categories"));
00202     }
00203     addTag("p",event->categoriesStr());
00204   }
00205 }
00206 
00207 void KOEventViewer::formatAttendees(Incidence *event)
00208 {
00209   QPtrList<Attendee> attendees = event->attendees();
00210   if (attendees.count()) {
00211     KIconLoader* iconLoader = new KIconLoader();
00212     QString iconPath = iconLoader->iconPath("mail_generic",KIcon::Small);
00213     addTag("h3",i18n("Organizer"));
00214     mText.append("<ul><li>");
00215 #ifndef KORG_NOKABC
00216     KABC::AddressBook *add_book = KABC::StdAddressBook::self();
00217     KABC::Addressee::List addressList;
00218     addressList = add_book->findByEmail(event->organizer());
00219     KABC::Addressee o = addressList.first();
00220     if (!o.isEmpty() && addressList.size()<2) {
00221       mText += "<a href=\"uid:" + o.uid() + "\">";
00222       mText += o.formattedName();
00223       mText += "</a>\n";
00224     } else {
00225       mText.append(event->organizer());
00226     }
00227 #else
00228     mText.append(event->organizer());
00229 #endif
00230     if (iconPath) {
00231       mText += " <a href=\"mailto:" + event->organizer() + "\">";
00232       mText += "<IMG src=\"" + iconPath + "\">";
00233       mText += "</a>\n";
00234     }
00235     mText.append("</li></ul>");
00236 
00237     addTag("h3",i18n("Attendees"));
00238     Attendee *a;
00239     mText.append("<ul>");
00240     for(a=attendees.first();a;a=attendees.next()) {
00241 #ifndef KORG_NOKABC
00242       if (a->name().isEmpty()) {
00243         addressList = add_book->findByEmail(a->email());
00244         KABC::Addressee o = addressList.first();
00245         if (!o.isEmpty() && addressList.size()<2) {
00246           mText += "<a href=\"uid:" + o.uid() + "\">";
00247           mText += o.formattedName();
00248           mText += "</a>\n";
00249         } else {
00250           mText += "<li>";
00251           mText.append(a->email());
00252           mText += "\n";
00253         }
00254       } else {
00255         mText += "<li><a href=\"uid:" + a->uid() + "\">";
00256         if (!a->name().isEmpty()) mText += a->name();
00257         else mText += a->email();
00258         mText += "</a>\n";
00259       }
00260 #else
00261       mText += "<li><a href=\"uid:" + a->uid() + "\">";
00262       if (!a->name().isEmpty()) mText += a->name();
00263       else mText += a->email();
00264       mText += "</a>\n";
00265 #endif
00266       kdDebug() << "formatAttendees: uid = " << a->uid() << endl;
00267 
00268       if (!a->email().isEmpty()) {
00269         if (iconPath) {
00270           mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">";
00271           mText += "<IMG src=\"" + iconPath + "\">";
00272           mText += "</a>\n";
00273         }
00274       }
00275     }
00276     mText.append("</li></ul>");
00277   }
00278 }
00279 
00280 void KOEventViewer::formatReadOnly(Incidence *event)
00281 {
00282   if (event->isReadOnly()) {
00283     addTag("p","<em>(" + i18n("read-only") + ")</em>");
00284   }
00285 }
00286 
00287 
00288 void KOEventViewer::setTodo(Todo *event)
00289 {
00290   clearEvents();
00291   appendTodo(event);
00292 }
00293 
00294 void KOEventViewer::setEvent(Event *event)
00295 {
00296   clearEvents();
00297   appendEvent(event);
00298 }
00299 
00300 void KOEventViewer::addEvent(Event *event)
00301 {
00302   appendEvent(event);
00303 }
00304 
00305 void KOEventViewer::clearEvents(bool now)
00306 {
00307   mText = "";
00308   if (now) setText(mText);
00309 }
00310 
00311 void KOEventViewer::addText(QString text)
00312 {
00313   mText.append(text);
00314   setText(mText);
00315 }
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:31 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001