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 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 00023 */ 00024 00025 #include "koeventviewer.h" 00026 00027 #include "urihandler.h" 00028 00029 #include <libkcal/event.h> 00030 #include <libkcal/todo.h> 00031 #include <libkcal/journal.h> 00032 00033 #include <kiconloader.h> 00034 #include <klocale.h> 00035 #include <kapplication.h> 00036 #include <kdebug.h> 00037 #ifndef KORG_NOKABC 00038 #include <kabc/stdaddressbook.h> 00039 #endif 00040 00041 KOEventViewer::KOEventViewer( QWidget *parent, const char *name ) 00042 : QTextBrowser( parent, name ) 00043 { 00044 } 00045 00046 KOEventViewer::~KOEventViewer() 00047 { 00048 } 00049 00050 void KOEventViewer::setSource( const QString &n ) 00051 { 00052 UriHandler::process( n ); 00053 } 00054 00055 void KOEventViewer::addTag( const QString & tag, const QString & text ) 00056 { 00057 int numLineBreaks = text.contains( "\n" ); 00058 QString str = "<" + tag + ">"; 00059 QString tmpText = text; 00060 QString tmpStr = str; 00061 if( numLineBreaks >= 0 ) { 00062 if ( numLineBreaks > 0) { 00063 int pos = 0; 00064 QString tmp; 00065 for( int i = 0; i <= numLineBreaks; i++ ) { 00066 pos = tmpText.find( "\n" ); 00067 tmp = tmpText.left( pos ); 00068 tmpText = tmpText.right( tmpText.length() - pos - 1 ); 00069 tmpStr += tmp + "<br>"; 00070 } 00071 } else { 00072 tmpStr += tmpText; 00073 } 00074 tmpStr += "</" + tag + ">"; 00075 mText.append( tmpStr ); 00076 } else { 00077 str += text + "</" + tag + ">"; 00078 mText.append( str ); 00079 } 00080 } 00081 00082 void KOEventViewer::appendEvent( Event *event ) 00083 { 00084 addTag( "h1", event->summary() ); 00085 00086 if ( !event->location().isEmpty() ) { 00087 addTag( "b", i18n("Location: ") ); 00088 mText.append( event->location() + "<br>" ); 00089 } 00090 if ( event->doesFloat() ) { 00091 if ( event->isMultiDay() ) { 00092 mText.append( i18n("<b>From:</b> %1 <b>To:</b> %2") 00093 .arg( event->dtStartDateStr() ) 00094 .arg( event->dtEndDateStr() ) ); 00095 } else { 00096 mText.append( i18n("<b>On:</b> %1").arg( event->dtStartDateStr() ) ); 00097 } 00098 } else { 00099 if ( event->isMultiDay() ) { 00100 mText.append( i18n("<b>From:</b> %1 <b>To:</b> %2") 00101 .arg( event->dtStartStr() ) 00102 .arg( event->dtEndStr() ) ); 00103 } else { 00104 mText.append( i18n("<b>On:</b> %1 <b>From:</b> %2 <b>To:</b> %3") 00105 .arg( event->dtStartDateStr() ) 00106 .arg( event->dtStartTimeStr() ) 00107 .arg( event->dtEndTimeStr() ) ); 00108 } 00109 } 00110 00111 if ( !event->description().isEmpty() ) addTag( "p", event->description() ); 00112 00113 formatCategories( event ); 00114 00115 if ( event->doesRecur() ) { 00116 QDateTime dt = event->recurrence()->getNextDateTime( 00117 QDateTime::currentDateTime() ); 00118 addTag( "p", "<em>" + 00119 i18n("This is a recurring event. The next occurrence will be on %1.").arg( 00120 KGlobal::locale()->formatDateTime( dt, true ) ) + "</em>" ); 00121 } 00122 00123 formatReadOnly( event ); 00124 formatAttendees( event ); 00125 formatAttachments( event ); 00126 00127 setText( mText ); 00128 } 00129 00130 void KOEventViewer::appendTodo( Todo *todo ) 00131 { 00132 addTag( "h1", todo->summary() ); 00133 00134 if ( !todo->location().isEmpty() ) { 00135 addTag( "b", i18n("Location:") ); 00136 mText.append( todo->location() + "<br>" ); 00137 } 00138 if ( todo->hasDueDate() ) { 00139 mText.append( i18n("<b>Due on:</b> %1").arg( todo->dtDueStr() ) ); 00140 } 00141 00142 if ( !todo->description().isEmpty() ) addTag( "p", todo->description() ); 00143 00144 formatCategories( todo ); 00145 00146 mText.append( i18n("<p><b>Priority:</b> %2</p>") 00147 .arg( QString::number( todo->priority() ) ) ); 00148 00149 mText.append( i18n("<p><i>%1 % completed</i></p>") 00150 .arg( todo->percentComplete() ) ); 00151 00152 if ( todo->doesRecur() ) { 00153 QDateTime dt = todo->recurrence()->getNextDateTime( 00154 QDateTime::currentDateTime() ); 00155 addTag( "p", "<em>" + 00156 i18n("This is a recurring todo. The next occurrence will be on %1.").arg( 00157 KGlobal::locale()->formatDateTime( dt, true ) ) + "</em>" ); 00158 } 00159 formatReadOnly( todo ); 00160 formatAttendees( todo ); 00161 formatAttachments( todo ); 00162 00163 setText( mText ); 00164 } 00165 00166 void KOEventViewer::appendJournal( Journal *journal ) 00167 { 00168 addTag( "h1", i18n("Journal for %1").arg( journal->dtStartDateStr( false ) ) ); 00169 addTag( "p", journal->description() ); 00170 setText( mText ); 00171 } 00172 00173 void KOEventViewer::formatCategories( Incidence *event ) 00174 { 00175 if ( !event->categoriesStr().isEmpty() ) { 00176 if ( event->categories().count() == 1 ) { 00177 addTag( "h2", i18n("Category") ); 00178 } else { 00179 addTag( "h2", i18n("Categories") ); 00180 } 00181 addTag( "p", event->categoriesStr() ); 00182 } 00183 } 00184 00185 void KOEventViewer::formatAttendees( Incidence *event ) 00186 { 00187 Attendee::List attendees = event->attendees(); 00188 if ( attendees.count() ) { 00189 KIconLoader* iconLoader = new KIconLoader(); 00190 QString iconPath = iconLoader->iconPath( "mail_generic", KIcon::Small ); 00191 addTag( "h3", i18n("Organizer") ); 00192 mText.append( "<ul><li>" ); 00193 #ifndef KORG_NOKABC 00194 KABC::AddressBook *add_book = KABC::StdAddressBook::self(); 00195 KABC::Addressee::List addressList; 00196 addressList = add_book->findByEmail( event->organizer() ); 00197 KABC::Addressee o = addressList.first(); 00198 if ( !o.isEmpty() && addressList.size() < 2 ) { 00199 addLink( "uid" + o.uid(), o.formattedName() ); 00200 } else { 00201 mText.append( event->organizer() ); 00202 } 00203 #else 00204 mText.append( event->organizer() ); 00205 #endif 00206 if ( !iconPath.isNull() ) { 00207 addLink( "mailto:" + event->organizer(), 00208 "<img src=\"" + iconPath + "\">" ); 00209 } 00210 mText.append( "</li></ul>" ); 00211 00212 addTag( "h3", i18n("Attendees") ); 00213 mText.append( "<ul>" ); 00214 Attendee::List::ConstIterator it; 00215 for( it = attendees.begin(); it != attendees.end(); ++it ) { 00216 Attendee *a = *it; 00217 #ifndef KORG_NOKABC 00218 if ( a->name().isEmpty() ) { 00219 addressList = add_book->findByEmail( a->email() ); 00220 KABC::Addressee o = addressList.first(); 00221 if ( !o.isEmpty() && addressList.size() < 2 ) { 00222 addLink( "uid" + o.uid(), o.formattedName() ); 00223 } else { 00224 mText += "<li>"; 00225 mText.append( a->email() ); 00226 mText += "\n"; 00227 } 00228 } else { 00229 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 00230 if ( !a->name().isEmpty() ) mText += a->name(); 00231 else mText += a->email(); 00232 mText += "</a>\n"; 00233 } 00234 #else 00235 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 00236 if ( !a->name().isEmpty() ) mText += a->name(); 00237 else mText += a->email(); 00238 mText += "</a>\n"; 00239 #endif 00240 kdDebug(5850) << "formatAttendees: uid = " << a->uid() << endl; 00241 00242 if ( !a->email().isEmpty() ) { 00243 if ( !iconPath.isNull() ) { 00244 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; 00245 mText += "<img src=\"" + iconPath + "\">"; 00246 mText += "</a>\n"; 00247 } 00248 } 00249 } 00250 mText.append( "</li></ul>" ); 00251 } 00252 } 00253 00254 void KOEventViewer::formatReadOnly( Incidence *i ) 00255 { 00256 if ( i->isReadOnly() ) { 00257 addTag( "p", "<em>(" + i18n("read-only") + ")</em>" ); 00258 } 00259 } 00260 00261 void KOEventViewer::formatAttachments( Incidence *i ) 00262 { 00263 Attachment::List as = i->attachments(); 00264 if ( as.count() > 0 ) { 00265 mText += "<ul>"; 00266 Attachment::List::ConstIterator it; 00267 for( it = as.begin(); it != as.end(); ++it ) { 00268 if ( (*it)->isUri() ) { 00269 mText += "<li>"; 00270 addLink( (*it)->uri(), (*it)->uri() ); 00271 mText += "</li>"; 00272 } 00273 } 00274 mText += "</ul>"; 00275 } 00276 } 00277 00278 void KOEventViewer::setTodo( Todo *event ) 00279 { 00280 clearEvents(); 00281 appendTodo( event ); 00282 } 00283 00284 void KOEventViewer::setEvent( Event *event ) 00285 { 00286 clearEvents(); 00287 appendEvent( event ); 00288 } 00289 00290 void KOEventViewer::setJournal( Journal *journal ) 00291 { 00292 clearEvents(); 00293 appendJournal( journal ); 00294 } 00295 00296 void KOEventViewer::clearEvents( bool now ) 00297 { 00298 mText = ""; 00299 if ( now ) setText( mText ); 00300 } 00301 00302 void KOEventViewer::addText( const QString &text ) 00303 { 00304 mText.append( text ); 00305 setText( mText ); 00306 } 00307 00308 void KOEventViewer::addLink( const QString &ref, const QString &text, 00309 bool newline ) 00310 { 00311 mText += "<a href=\"" + ref + "\">" + text + "</a>"; 00312 if ( newline ) mText += "\n"; 00313 } 00314 00315 #include "koeventviewer.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:24 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003