koeventviewer.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 #include <libkdepim/email.h>
00033
00034 #include <kiconloader.h>
00035 #include <klocale.h>
00036 #include <kapplication.h>
00037 #include <kdebug.h>
00038 #ifndef KORG_NOKABC
00039 #include <kabc/stdaddressbook.h>
00040 #endif
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 UriHandler::process( n );
00054 }
00055
00056 void KOEventViewer::addTag( const QString & tag, const QString & text )
00057 {
00058 int numLineBreaks = text.contains( "\n" );
00059 QString str = "<" + tag + ">";
00060 QString tmpText = text;
00061 QString tmpStr = str;
00062 if( numLineBreaks >= 0 ) {
00063 if ( numLineBreaks > 0) {
00064 int pos = 0;
00065 QString tmp;
00066 for( int i = 0; i <= numLineBreaks; i++ ) {
00067 pos = tmpText.find( "\n" );
00068 tmp = tmpText.left( pos );
00069 tmpText = tmpText.right( tmpText.length() - pos - 1 );
00070 tmpStr += tmp + "<br>";
00071 }
00072 } else {
00073 tmpStr += tmpText;
00074 }
00075 tmpStr += "</" + tag + ">";
00076 mText.append( tmpStr );
00077 } else {
00078 str += text + "</" + tag + ">";
00079 mText.append( str );
00080 }
00081 }
00082
00083 void KOEventViewer::appendEvent( Event *event )
00084 {
00085 addTag( "h1", event->summary() );
00086
00087 if ( !event->location().isEmpty() ) {
00088 addTag( "b", i18n("Location: ") );
00089 mText.append( event->location() + "<br>" );
00090 }
00091 if ( event->doesFloat() ) {
00092 if ( event->isMultiDay() ) {
00093 mText.append( i18n("<b>From:</b> %1 <b>To:</b> %2")
00094 .arg( event->dtStartDateStr() )
00095 .arg( event->dtEndDateStr() ) );
00096 } else {
00097 mText.append( i18n("<b>On:</b> %1").arg( event->dtStartDateStr() ) );
00098 }
00099 } else {
00100 if ( event->isMultiDay() ) {
00101 mText.append( i18n("<b>From:</b> %1 <b>To:</b> %2")
00102 .arg( event->dtStartStr() )
00103 .arg( event->dtEndStr() ) );
00104 } else {
00105 mText.append( i18n("<b>On:</b> %1 <b>From:</b> %2 <b>To:</b> %3")
00106 .arg( event->dtStartDateStr() )
00107 .arg( event->dtStartTimeStr() )
00108 .arg( event->dtEndTimeStr() ) );
00109 }
00110 }
00111
00112 if ( !event->description().isEmpty() ) addTag( "p", event->description() );
00113
00114 formatCategories( event );
00115
00116 if ( event->doesRecur() ) {
00117 QDateTime dt = event->recurrence()->getNextDateTime(
00118 QDateTime::currentDateTime() );
00119 addTag( "p", "<em>" +
00120 i18n("This is a recurring event. The next occurrence will be on %1.").arg(
00121 KGlobal::locale()->formatDateTime( dt, true ) ) + "</em>" );
00122 }
00123
00124 formatReadOnly( event );
00125 formatAttendees( event );
00126 formatAttachments( event );
00127
00128 setText( mText );
00129 }
00130
00131 void KOEventViewer::appendTodo( Todo *todo )
00132 {
00133 addTag( "h1", todo->summary() );
00134
00135 if ( !todo->location().isEmpty() ) {
00136 addTag( "b", i18n("Location:") );
00137 mText.append( todo->location() + "<br>" );
00138 }
00139 if ( todo->hasDueDate() ) {
00140 mText.append( i18n("<b>Due on:</b> %1").arg( todo->dtDueStr() ) );
00141 }
00142
00143 if ( !todo->description().isEmpty() ) addTag( "p", todo->description() );
00144
00145 formatCategories( todo );
00146
00147 mText.append( i18n("<p><b>Priority:</b> %2</p>")
00148 .arg( QString::number( todo->priority() ) ) );
00149
00150 mText.append( i18n("<p><i>%1 % completed</i></p>")
00151 .arg( todo->percentComplete() ) );
00152
00153 if ( todo->doesRecur() ) {
00154 QDateTime dt = todo->recurrence()->getNextDateTime(
00155 QDateTime::currentDateTime() );
00156 addTag( "p", "<em>" +
00157 i18n("This is a recurring todo. The next occurrence will be on %1.").arg(
00158 KGlobal::locale()->formatDateTime( dt, true ) ) + "</em>" );
00159 }
00160 formatReadOnly( todo );
00161 formatAttendees( todo );
00162 formatAttachments( todo );
00163
00164 setText( mText );
00165 }
00166
00167 void KOEventViewer::appendJournal( Journal *journal )
00168 {
00169 addTag( "h1", i18n("Journal for %1").arg( journal->dtStartDateStr( false ) ) );
00170 addTag( "p", journal->description() );
00171 setText( mText );
00172 }
00173
00174 void KOEventViewer::formatCategories( Incidence *event )
00175 {
00176 if ( !event->categoriesStr().isEmpty() ) {
00177 if ( event->categories().count() == 1 ) {
00178 addTag( "h2", i18n("Category") );
00179 } else {
00180 addTag( "h2", i18n("Categories") );
00181 }
00182 addTag( "p", event->categoriesStr() );
00183 }
00184 }
00185
00186 void KOEventViewer::linkPerson( const QString& email, QString name,
00187 QString uid, const QString& iconPath )
00188 {
00189 #ifndef KORG_NOKABC
00190
00191
00192 if ( !email.isEmpty() && ( name.isEmpty() || uid.isEmpty() ) ) {
00193 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
00194 KABC::Addressee::List addressList = add_book->findByEmail( email );
00195 KABC::Addressee o = addressList.first();
00196 if ( !o.isEmpty() && addressList.size() < 2 ) {
00197 if ( name.isEmpty() )
00198
00199 name = o.formattedName();
00200 uid = o.uid();
00201 } else
00202
00203 uid = "";
00204 }
00205 #else
00206
00207 uid = "";
00208 #endif
00209 kdDebug(5850) << "formatAttendees: uid = " << uid << endl;
00210
00211
00212 mText += "<li>";
00213 if ( !uid.isEmpty() ) {
00214
00215 if ( name.isEmpty() )
00216
00217 addLink( "uid:" + uid, email );
00218 else
00219 addLink( "uid:" + uid, name );
00220 } else {
00221
00222 mText += ( name.isEmpty() ? email : name );
00223 }
00224 mText += '\n';
00225
00226
00227 if ( !email.isEmpty() && !iconPath.isNull() ) {
00228 KCal::Person person( name, email );
00229 KURL mailto;
00230 mailto.setProtocol( "mailto" );
00231 mailto.setPath( person.fullName() );
00232 addLink( mailto.url(), "<img src=\"" + iconPath + "\">" );
00233 }
00234 mText += "</li>\n";
00235 }
00236
00237 void KOEventViewer::formatAttendees( Incidence *event )
00238 {
00239 Attendee::List attendees = event->attendees();
00240 if ( attendees.count() ) {
00241 KIconLoader iconLoader;
00242 const QString iconPath = iconLoader.iconPath( "mail_generic",
00243 KIcon::Small );
00244
00245
00246 addTag( "h3", i18n("Organizer") );
00247 mText.append( "<ul>" );
00248 linkPerson( event->organizer().email(), event->organizer().name(), "", iconPath );
00249 mText += "</ul>";
00250
00251
00252 addTag( "h3", i18n("Attendees") );
00253 mText.append( "<ul>" );
00254 Attendee::List::ConstIterator it;
00255 for( it = attendees.begin(); it != attendees.end(); ++it ) {
00256 Attendee *a = *it;
00257 linkPerson( a->email(), a->name(), a->uid(), iconPath );
00258 }
00259 mText.append( "</ul>" );
00260 }
00261 }
00262
00263 void KOEventViewer::formatReadOnly( Incidence *i )
00264 {
00265 if ( i->isReadOnly() ) {
00266 addTag( "p", "<em>(" + i18n("read-only") + ")</em>" );
00267 }
00268 }
00269
00270 void KOEventViewer::formatAttachments( Incidence *i )
00271 {
00272 Attachment::List as = i->attachments();
00273 if ( as.count() > 0 ) {
00274 mText += "<ul>";
00275 Attachment::List::ConstIterator it;
00276 for( it = as.begin(); it != as.end(); ++it ) {
00277 if ( (*it)->isUri() ) {
00278 mText += "<li>";
00279 addLink( (*it)->uri(), (*it)->uri() );
00280 mText += "</li>";
00281 }
00282 }
00283 mText += "</ul>";
00284 }
00285 }
00286
00287 void KOEventViewer::setTodo( Todo *event )
00288 {
00289 clearEvents();
00290 appendTodo( event );
00291 }
00292
00293 void KOEventViewer::setEvent( Event *event )
00294 {
00295 clearEvents();
00296 appendEvent( event );
00297 }
00298
00299 void KOEventViewer::setJournal( Journal *journal )
00300 {
00301 clearEvents();
00302 appendJournal( journal );
00303 }
00304
00305 void KOEventViewer::clearEvents( bool now )
00306 {
00307 mText = "";
00308 if ( now ) setText( mText );
00309 }
00310
00311 void KOEventViewer::addText( const QString &text )
00312 {
00313 mText.append( text );
00314 setText( mText );
00315 }
00316
00317 void KOEventViewer::addLink( const QString &ref, const QString &text,
00318 bool newline )
00319 {
00320 mText += "<a href=\"" + ref + "\">" + text + "</a>";
00321 if ( newline ) mText += "\n";
00322 }
00323
00324 #include "koeventviewer.moc"
This file is part of the documentation for korganizer Library Version 3.3.2.