00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "htmlexport.h"
00024 #include "htmlexportsettings.h"
00025 #include "incidenceformatter.h"
00026 #include "calendar.h"
00027 #include "event.h"
00028 #include "todo.h"
00029 #ifndef KORG_NOKABC
00030 #include "kabc/stdaddressbook.h"
00031 #endif
00032
00033 #include <kglobal.h>
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036 #include <kcalendarsystem.h>
00037
00038 #include <QtCore/QFile>
00039 #include <QtCore/QTextStream>
00040 #include <QtCore/QTextCodec>
00041 #include <QtCore/QRegExp>
00042 #include <QtCore/QMap>
00043 #include <QtGui/QApplication>
00044
00045 using namespace KCal;
00046
00047 static QString cleanChars( const QString &txt );
00048
00049
00050 class KCal::HtmlExport::Private
00051 {
00052 public:
00053 Private( Calendar *calendar, HTMLExportSettings *settings )
00054 : mCalendar( calendar ),
00055 mSettings( settings )
00056 {}
00057
00058 Calendar *mCalendar;
00059 HTMLExportSettings *mSettings;
00060 QMap<QDate,QString> mHolidayMap;
00061 };
00062
00063
00064 HtmlExport::HtmlExport( Calendar *calendar, HTMLExportSettings *settings )
00065 : d( new Private( calendar, settings ) )
00066 {
00067 }
00068
00069 HtmlExport::~HtmlExport()
00070 {
00071 delete d;
00072 }
00073
00074 bool HtmlExport::save( const QString &fileName )
00075 {
00076 QString fn( fileName );
00077 if ( fn.isEmpty() && d->mSettings ) {
00078 fn = d->mSettings->outputFile();
00079 }
00080 if ( !d->mSettings || fn.isEmpty() ) {
00081 return false;
00082 }
00083 QFile f( fileName );
00084 if ( !f.open( QIODevice::WriteOnly ) ) {
00085 return false;
00086 }
00087 QTextStream ts( &f );
00088 bool success = save( &ts );
00089 f.close();
00090 return success;
00091 }
00092
00093 bool HtmlExport::save( QTextStream *ts )
00094 {
00095 if ( !d->mSettings ) {
00096 return false;
00097 }
00098 ts->setCodec( "UTF-8" );
00099
00100 *ts << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" ";
00101 *ts << "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"<<endl;
00102
00103 *ts << "<html><head>" << endl;
00104 *ts << " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=";
00105 *ts << "UTF-8\" />"<<endl;
00106 if ( !d->mSettings->pageTitle().isEmpty() ) {
00107 *ts << " <title>" << d->mSettings->pageTitle() << "</title>"<<endl;
00108 }
00109 *ts << " <style type=\"text/css\">"<<endl;
00110 *ts << styleSheet();
00111 *ts << " </style>"<<endl;
00112 *ts << "</head><body>"<<endl;
00113
00114
00115
00116
00117 if ( d->mSettings->eventView() || d->mSettings->monthView() || d->mSettings->weekView() ) {
00118 if ( !d->mSettings->eventTitle().isEmpty() ) {
00119 *ts << "<h1>" << d->mSettings->eventTitle() << "</h1>"<<endl;
00120 }
00121
00122
00123 if ( d->mSettings->weekView() ) {
00124 createWeekView( ts );
00125 }
00126
00127 if ( d->mSettings->monthView() ) {
00128 createMonthView( ts );
00129 }
00130
00131 if ( d->mSettings->eventView() ) {
00132 createEventList( ts );
00133 }
00134 }
00135
00136
00137 if ( d->mSettings->todoView() ) {
00138 if ( !d->mSettings->todoListTitle().isEmpty() ) {
00139 *ts << "<h1>" << d->mSettings->todoListTitle() << "</h1>"<<endl;
00140 }
00141 createTodoList( ts );
00142 }
00143
00144
00145 if ( d->mSettings->journalView() ) {
00146 if ( !d->mSettings->journalTitle().isEmpty() ) {
00147 *ts << "<h1>" << d->mSettings->journalTitle() << "</h1>"<<endl;
00148 }
00149 createJournalView( ts );
00150 }
00151
00152
00153 if ( d->mSettings->freeBusyView() ) {
00154 if ( !d->mSettings->freeBusyTitle().isEmpty() ) {
00155 *ts << "<h1>" << d->mSettings->freeBusyTitle() << "</h1>"<<endl;
00156 }
00157 createFreeBusyView( ts );
00158 }
00159
00160 createFooter( ts );
00161
00162
00163 *ts << "</body></html>"<<endl;
00164
00165 return true;
00166 }
00167
00168 void HtmlExport::createMonthView( QTextStream *ts )
00169 {
00170 QDate start = fromDate();
00171 start.setYMD( start.year(), start.month(), 1 );
00172
00173 QDate end( start.year(), start.month(), start.daysInMonth() );
00174
00175 int startmonth = start.month();
00176 int startyear = start.year();
00177
00178 while ( start < toDate() ) {
00179
00180 QDate hDate( start.year(), start.month(), 1 );
00181 QString hMon = hDate.toString( "MMMM" );
00182 QString hYear = hDate.toString( "yyyy" );
00183 *ts << "<h2>"
00184 << i18nc( "@title month and year", "%1 %2", hMon, hYear )
00185 << "</h2>"<<endl;
00186 if ( KGlobal::locale()->weekStartDay() == 1 ) {
00187 start = start.addDays( 1 - start.dayOfWeek() );
00188 } else {
00189 if ( start.dayOfWeek() != 7 ) {
00190 start = start.addDays( -start.dayOfWeek() );
00191 }
00192 }
00193 *ts << "<table border=\"1\">"<<endl;
00194
00195
00196 *ts << " <tr>";
00197 for ( int i=0; i < 7; ++i ) {
00198 *ts << "<th>" << KGlobal::locale()->calendar()->weekDayName( start.addDays(i) ) << "</th>";
00199 }
00200 *ts << "</tr>"<<endl;
00201
00202
00203 while ( start <= end ) {
00204 *ts << " <tr>"<<endl;
00205 for ( int i=0; i < 7; ++i ) {
00206 *ts << " <td valign=\"top\"><table border=\"0\">";
00207
00208 *ts << "<tr><td ";
00209 if ( d->mHolidayMap.contains( start ) || start.dayOfWeek() == 7 ) {
00210 *ts << "class=\"dateholiday\"";
00211 } else {
00212 *ts << "class=\"date\"";
00213 }
00214 *ts << ">" << QString::number( start.day() );
00215
00216 if ( d->mHolidayMap.contains( start ) ) {
00217 *ts << " <em>" << d->mHolidayMap[start] << "</em>";
00218 }
00219
00220 *ts << "</td></tr><tr><td valign=\"top\">";
00221
00222
00223 if ( start >= fromDate() && start <= toDate() ) {
00224 Event::List events = d->mCalendar->events( start, d->mCalendar->timeSpec(),
00225 EventSortStartDate,
00226 SortDirectionAscending );
00227 if ( events.count() ) {
00228 *ts << "<table>";
00229 Event::List::ConstIterator it;
00230 for ( it = events.constBegin(); it != events.constEnd(); ++it ) {
00231 if ( checkSecrecy( *it ) ) {
00232 createEvent( ts, *it, start, false );
00233 }
00234 }
00235 *ts << "</table>";
00236 } else {
00237 *ts << " ";
00238 }
00239 }
00240
00241 *ts << "</td></tr></table></td>"<<endl;
00242 start = start.addDays( 1 );
00243 }
00244 *ts << " </tr>"<<endl;
00245 }
00246 *ts << "</table>"<<endl;
00247 startmonth += 1;
00248 if ( startmonth > 12 ) {
00249 startyear += 1;
00250 startmonth = 1;
00251 }
00252 start.setYMD( startyear, startmonth, 1 );
00253 end.setYMD( start.year(), start.month(), start.daysInMonth() );
00254 }
00255 }
00256
00257 void HtmlExport::createEventList( QTextStream *ts )
00258 {
00259 int columns = 3;
00260 *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">"<<endl;
00261 *ts << " <tr>"<<endl;
00262 *ts << " <th class=\"sum\">" << i18nc( "@title:column event start time",
00263 "Start Time" ) << "</th>"<<endl;
00264 *ts << " <th>" << i18nc( "@title:column event end time",
00265 "End Time" ) << "</th>"<<endl;
00266 *ts << " <th>" << i18nc( "@title:column event description",
00267 "Event" ) << "</th>"<<endl;
00268 if ( d->mSettings->eventLocation() ) {
00269 *ts << " <th>" << i18nc( "@title:column event locatin",
00270 "Location" ) << "</th>"<<endl;
00271 ++columns;
00272 }
00273 if ( d->mSettings->eventCategories() ) {
00274 *ts << " <th>" << i18nc( "@title:column event categories",
00275 "Categories" ) << "</th>"<<endl;
00276 ++columns;
00277 }
00278 if ( d->mSettings->eventAttendees() ) {
00279 *ts << " <th>" << i18nc( "@title:column event attendees",
00280 "Attendees" ) << "</th>"<<endl;
00281 ++columns;
00282 }
00283
00284 *ts << " </tr>"<<endl;
00285
00286 for ( QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1) ) {
00287 kDebug() << "Getting events for" << dt.toString();
00288 Event::List events = d->mCalendar->events( dt, d->mCalendar->timeSpec(),
00289 EventSortStartDate,
00290 SortDirectionAscending );
00291 if ( events.count() ) {
00292 *ts << " <tr><td colspan=\"" << QString::number( columns )
00293 << "\" class=\"datehead\"><i>"
00294 << KGlobal::locale()->formatDate( dt )
00295 << "</i></td></tr>"<<endl;
00296
00297 Event::List::ConstIterator it;
00298 for ( it = events.constBegin(); it != events.constEnd(); ++it ) {
00299 if ( checkSecrecy( *it ) ) {
00300 createEvent( ts, *it, dt );
00301 }
00302 }
00303 }
00304 }
00305
00306 *ts << "</table>"<<endl;
00307 }
00308
00309 void HtmlExport::createEvent ( QTextStream *ts, Event *event,
00310 QDate date, bool withDescription )
00311 {
00312 kDebug() << event->summary();
00313 *ts << " <tr>"<<endl;
00314
00315 if ( !event->allDay() ) {
00316 if ( event->isMultiDay( d->mCalendar->timeSpec() ) && ( event->dtStart().date() != date ) ) {
00317 *ts << " <td> </td>"<<endl;
00318 } else {
00319 *ts << " <td valign=\"top\">"
00320 << IncidenceFormatter::timeToString( event->dtStart(), true, d->mCalendar->timeSpec() )
00321 << "</td>"<<endl;
00322 }
00323 if ( event->isMultiDay( d->mCalendar->timeSpec() ) && ( event->dtEnd().date() != date ) ) {
00324 *ts << " <td> </td>"<<endl;
00325 } else {
00326 *ts << " <td valign=\"top\">"
00327 << IncidenceFormatter::timeToString( event->dtEnd(), true, d->mCalendar->timeSpec() )
00328 << "</td>"<<endl;
00329 }
00330 } else {
00331 *ts << " <td> </td><td> </td>"<<endl;
00332 }
00333
00334 *ts << " <td class=\"sum\">"<<endl;
00335 *ts << " <b>" << cleanChars( event->summary() ) << "</b>"<<endl;
00336 if ( withDescription && !event->description().isEmpty() ) {
00337 *ts << " <p>" << breakString( cleanChars( event->description() ) ) << "</p>"<<endl;
00338 }
00339 *ts << " </td>"<<endl;
00340
00341 if ( d->mSettings->eventLocation() ) {
00342 *ts << " <td>"<<endl;
00343 formatLocation( ts, event );
00344 *ts << " </td>"<<endl;
00345 }
00346
00347 if ( d->mSettings->eventCategories() ) {
00348 *ts << " <td>"<<endl;
00349 formatCategories( ts, event );
00350 *ts << " </td>"<<endl;
00351 }
00352
00353 if ( d->mSettings->eventAttendees() ) {
00354 *ts << " <td>"<<endl;
00355 formatAttendees( ts, event );
00356 *ts << " </td>"<<endl;
00357 }
00358
00359 *ts << " </tr>"<<endl;
00360 }
00361
00362 void HtmlExport::createTodoList ( QTextStream *ts )
00363 {
00364 Todo::List rawTodoList = d->mCalendar->todos();
00365
00366 int index = 0;
00367 while ( index < rawTodoList.count() ) {
00368 Todo *ev = rawTodoList[ index ];
00369 Todo *subev = ev;
00370 if ( ev->relatedTo() ) {
00371 if ( ev->relatedTo()->type() == "Todo" ) {
00372 if ( !rawTodoList.contains( static_cast<Todo *>( ev->relatedTo() ) ) ) {
00373 rawTodoList.append( static_cast<Todo *>( ev->relatedTo() ) );
00374 }
00375 }
00376 }
00377 index = rawTodoList.indexOf( subev );
00378 ++index;
00379 }
00380
00381
00382
00383 Todo::List todoList;
00384 Todo::List::ConstIterator it;
00385 for ( int i = 1; i <= 9; ++i ) {
00386 for ( it = rawTodoList.constBegin(); it != rawTodoList.constEnd(); ++it ) {
00387 if ( (*it)->priority() == i && checkSecrecy( *it ) ) {
00388 todoList.append( *it );
00389 }
00390 }
00391 }
00392 for ( it = rawTodoList.constBegin(); it != rawTodoList.constEnd(); ++it ) {
00393 if ( (*it)->priority() == 0 && checkSecrecy( *it ) ) {
00394 todoList.append( *it );
00395 }
00396 }
00397
00398 int columns = 3;
00399 *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">"<<endl;
00400 *ts << " <tr>"<<endl;
00401 *ts << " <th class=\"sum\">" << i18nc( "@title:column", "To-do" ) << "</th>"<<endl;
00402 *ts << " <th>" << i18nc( "@title:column to-do priority", "Priority" ) << "</th>"<<endl;
00403 *ts << " <th>" << i18nc( "@title:column to-do percent completed", "Completed" ) << "</th>"<<endl;
00404 if ( d->mSettings->taskDueDate() ) {
00405 *ts << " <th>" << i18nc( "@title:column to-do due date", "Due Date" ) << "</th>"<<endl;
00406 ++columns;
00407 }
00408 if ( d->mSettings->taskLocation() ) {
00409 *ts << " <th>" << i18nc( "@title:column to-do location", "Location" ) << "</th>"<<endl;
00410 ++columns;
00411 }
00412 if ( d->mSettings->taskCategories() ) {
00413 *ts << " <th>" << i18nc( "@title:column to-do categories", "Categories" ) << "</th>"<<endl;
00414 ++columns;
00415 }
00416 if ( d->mSettings->taskAttendees() ) {
00417 *ts << " <th>" << i18nc( "@title:column to-do attendees", "Attendees" ) << "</th>"<<endl;
00418 ++columns;
00419 }
00420 *ts << " </tr>"<<endl;
00421
00422
00423 for ( it = todoList.constBegin(); it != todoList.constEnd(); ++it ) {
00424 if ( !(*it)->relatedTo() ) {
00425 createTodo( ts, *it );
00426 }
00427 }
00428
00429
00430 for ( it = todoList.constBegin(); it != todoList.constEnd(); ++it ) {
00431 Incidence::List relations = (*it)->relations();
00432 if ( relations.count() ) {
00433
00434 *ts << " <tr>"<<endl;
00435 *ts << " <td class=\"subhead\" colspan=";
00436 *ts << "\"" << QString::number(columns) << "\"";
00437 *ts << "><a name=\"sub" << (*it)->uid() << "\"></a>"
00438 << i18nc( "@title:column sub-to-dos of the parent to-do",
00439 "Sub-To-dos of: " ) << "<a href=\"#"
00440 << (*it)->uid() << "\"><b>" << cleanChars( (*it)->summary() )
00441 << "</b></a></td>"<<endl;
00442 *ts << " </tr>"<<endl;
00443
00444 Todo::List sortedList;
00445
00446
00447 for ( int i = 1; i <= 9; ++i ) {
00448 Incidence::List::ConstIterator it2;
00449 for ( it2 = relations.constBegin(); it2 != relations.constEnd(); ++it2 ) {
00450 Todo *ev3 = dynamic_cast<Todo *>( *it2 );
00451 if ( ev3 && ev3->priority() == i ) {
00452 sortedList.append( ev3 );
00453 }
00454 }
00455 }
00456 Incidence::List::ConstIterator it2;
00457 for ( it2 = relations.constBegin(); it2 != relations.constEnd(); ++it2 ) {
00458 Todo *ev3 = dynamic_cast<Todo *>( *it2 );
00459 if ( ev3 && ev3->priority() == 0 ) {
00460 sortedList.append( ev3 );
00461 }
00462 }
00463
00464 Todo::List::ConstIterator it3;
00465 for ( it3 = sortedList.constBegin(); it3 != sortedList.constEnd(); ++it3 ) {
00466 createTodo( ts, *it3 );
00467 }
00468 }
00469 }
00470
00471 *ts << "</table>"<<endl;
00472 }
00473
00474 void HtmlExport::createTodo( QTextStream *ts, Todo *todo )
00475 {
00476 kDebug();
00477
00478 bool completed = todo->isCompleted();
00479 Incidence::List relations = todo->relations();
00480
00481 *ts << "<tr>"<<endl;
00482
00483 *ts << " <td class=\"sum";
00484 if (completed) *ts << "done";
00485 *ts << "\">"<<endl;
00486 *ts << " <a name=\"" << todo->uid() << "\"></a>"<<endl;
00487 *ts << " <b>" << cleanChars( todo->summary() ) << "</b>"<<endl;
00488 if ( !todo->description().isEmpty() ) {
00489 *ts << " <p>" << breakString( cleanChars( todo->description() ) ) << "</p>"<<endl;
00490 }
00491 if ( relations.count() ) {
00492 *ts << " <div align=\"right\"><a href=\"#sub" << todo->uid()
00493 << "\">" << i18nc( "@title:column sub-to-dos of the parent to-do",
00494 "Sub-To-dos" ) << "</a></div>"<<endl;
00495 }
00496 *ts << " </td>"<<endl;
00497
00498 *ts << " <td";
00499 if ( completed ) {
00500 *ts << " class=\"done\"";
00501 }
00502 *ts << ">"<<endl;
00503 *ts << " " << todo->priority() <<endl;
00504 *ts << " </td>"<<endl;
00505
00506 *ts << " <td";
00507 if ( completed ) {
00508 *ts << " class=\"done\"";
00509 }
00510 *ts << ">"<<endl;
00511 *ts << " " << i18nc( "@info/plain to-do percent complete",
00512 "%1 %", todo->percentComplete() ) <<endl;
00513 *ts << " </td>"<<endl;
00514
00515 if ( d->mSettings->taskDueDate() ) {
00516 *ts << " <td";
00517 if ( completed ) {
00518 *ts << " class=\"done\"";
00519 }
00520 *ts << ">"<<endl;
00521 if ( todo->hasDueDate() ) {
00522 *ts << " " << IncidenceFormatter::dateToString(todo->dtDue(true)) <<endl;
00523 } else {
00524 *ts << " "<<endl;
00525 }
00526 *ts << " </td>"<<endl;
00527 }
00528
00529 if ( d->mSettings->taskLocation() ) {
00530 *ts << " <td";
00531 if ( completed ) {
00532 *ts << " class=\"done\"";
00533 }
00534 *ts << ">"<<endl;
00535 formatLocation( ts, todo );
00536 *ts << " </td>"<<endl;
00537 }
00538
00539 if ( d->mSettings->taskCategories() ) {
00540 *ts << " <td";
00541 if ( completed ) {
00542 *ts << " class=\"done\"";
00543 }
00544 *ts << ">"<<endl;
00545 formatCategories( ts, todo );
00546 *ts << " </td>"<<endl;
00547 }
00548
00549 if ( d->mSettings->taskAttendees() ) {
00550 *ts << " <td";
00551 if ( completed ) {
00552 *ts << " class=\"done\"";
00553 }
00554 *ts << ">"<<endl;
00555 formatAttendees( ts, todo );
00556 *ts << " </td>"<<endl;
00557 }
00558
00559 *ts << "</tr>"<<endl;
00560 }
00561
00562 void HtmlExport::createWeekView( QTextStream *ts )
00563 {
00564 Q_UNUSED( ts );
00565
00566 }
00567
00568 void HtmlExport::createJournalView( QTextStream *ts )
00569 {
00570 Q_UNUSED( ts );
00571
00572
00573 }
00574
00575 void HtmlExport::createFreeBusyView( QTextStream *ts )
00576 {
00577 Q_UNUSED( ts );
00578
00579 }
00580
00581 bool HtmlExport::checkSecrecy( Incidence *incidence )
00582 {
00583 int secrecy = incidence->secrecy();
00584 if ( secrecy == Incidence::SecrecyPublic ) {
00585 return true;
00586 }
00587 if ( secrecy == Incidence::SecrecyPrivate && !d->mSettings->excludePrivate() ) {
00588 return true;
00589 }
00590 if ( secrecy == Incidence::SecrecyConfidential &&
00591 !d->mSettings->excludeConfidential() ) {
00592 return true;
00593 }
00594 return false;
00595 }
00596
00597 void HtmlExport::formatLocation( QTextStream *ts, Incidence *incidence )
00598 {
00599 if ( !incidence->location().isEmpty() ) {
00600 *ts << " " << cleanChars( incidence->location() ) <<endl;
00601 } else {
00602 *ts << " "<<endl;
00603 }
00604 }
00605
00606 void HtmlExport::formatCategories( QTextStream *ts, Incidence *incidence )
00607 {
00608 if ( !incidence->categoriesStr().isEmpty() ) {
00609 *ts << " " << cleanChars( incidence->categoriesStr() ) <<endl;
00610 } else {
00611 *ts << " "<<endl;
00612 }
00613 }
00614
00615 void HtmlExport::formatAttendees( QTextStream *ts, Incidence *incidence )
00616 {
00617 Attendee::List attendees = incidence->attendees();
00618 if ( attendees.count() ) {
00619 *ts << "<em>";
00620 #ifndef KORG_NOKABC
00621 KABC::AddressBook *add_book = KABC::StdAddressBook::self( true );
00622 KABC::Addressee::List addressList;
00623 addressList = add_book->findByEmail( incidence->organizer().email() );
00624 if ( !addressList.isEmpty() ) {
00625 KABC::Addressee o = addressList.first();
00626 if ( !o.isEmpty() && addressList.size() < 2 ) {
00627 *ts << "<a href=\"mailto:" << incidence->organizer().email() << "\">";
00628 *ts << cleanChars( o.formattedName() ) << "</a>"<<endl;
00629 } else {
00630 *ts << incidence->organizer().fullName();
00631 }
00632 }
00633 #else
00634 *ts << incidence->organizer().fullName();
00635 #endif
00636 *ts << "</em><br />";
00637 Attendee::List::ConstIterator it;
00638 for ( it = attendees.constBegin(); it != attendees.constEnd(); ++it ) {
00639 Attendee *a = *it;
00640 if ( !a->email().isEmpty() ) {
00641 *ts << "<a href=\"mailto:" << a->email();
00642 *ts << "\">" << cleanChars( a->name() ) << "</a>";
00643 } else {
00644 *ts << " " << cleanChars( a->name() );
00645 }
00646 *ts << "<br />" <<endl;
00647 }
00648 } else {
00649 *ts << " "<<endl;
00650 }
00651 }
00652
00653 QString HtmlExport::breakString( const QString &text )
00654 {
00655 int number = text.count( "\n" );
00656 if ( number <= 0 ) {
00657 return text;
00658 } else {
00659 QString out;
00660 QString tmpText = text;
00661 int pos = 0;
00662 QString tmp;
00663 for ( int i = 0; i <= number; ++i ) {
00664 pos = tmpText.indexOf( "\n" );
00665 tmp = tmpText.left( pos );
00666 tmpText = tmpText.right( tmpText.length() - pos - 1 );
00667 out += tmp + "<br />";
00668 }
00669 return out;
00670 }
00671 }
00672
00673 void HtmlExport::createFooter( QTextStream *ts )
00674 {
00675
00676 QString trailer = i18nc( "@info/plain", "This page was created " );
00677
00678
00679
00680
00681
00682 if ( !d->mSettings->eMail().isEmpty() ) {
00683 if ( !d->mSettings->name().isEmpty() ) {
00684 trailer += i18nc( "@info/plain page creator email link with name",
00685 "by <link url='mailto:%1'>%2</link>",
00686 d->mSettings->eMail(), d->mSettings->name() );
00687 } else {
00688 trailer += i18nc( "@info/plain page creator email link",
00689 "by <link url='mailto:%1'>%2</link>",
00690 d->mSettings->eMail(), d->mSettings->eMail() );
00691 }
00692 } else {
00693 if ( !d->mSettings->name().isEmpty() ) {
00694 trailer += i18nc( "@info/plain page creator name only",
00695 "by %1 ", d->mSettings->name() );
00696 }
00697 }
00698 if ( !d->mSettings->creditName().isEmpty() ) {
00699 if ( !d->mSettings->creditURL().isEmpty() ) {
00700 trailer += i18nc( "@info/plain page credit with name and link",
00701 "with <link url='%1'>%2</link>",
00702 d->mSettings->creditURL(), d->mSettings->creditName() );
00703 } else {
00704 trailer += i18nc( "@info/plain page credit name only",
00705 "with %1", d->mSettings->creditName() );
00706 }
00707 }
00708 *ts << "<p>" << trailer << "</p>"<<endl;
00709 }
00710
00711 QString cleanChars( const QString &text )
00712 {
00713 QString txt = text;
00714 txt = txt.replace( '&', "&" );
00715 txt = txt.replace( '<', "<" );
00716 txt = txt.replace( '>', ">" );
00717 txt = txt.replace( '\"', """ );
00718 txt = txt.replace( QString::fromUtf8( "ä" ), "ä" );
00719 txt = txt.replace( QString::fromUtf8( "Ä" ), "Ä" );
00720 txt = txt.replace( QString::fromUtf8( "ö" ), "ö" );
00721 txt = txt.replace( QString::fromUtf8( "Ö" ), "Ö" );
00722 txt = txt.replace( QString::fromUtf8( "ü" ), "ü" );
00723 txt = txt.replace( QString::fromUtf8( "Ü" ), "Ü" );
00724 txt = txt.replace( QString::fromUtf8( "ß" ), "ß" );
00725 txt = txt.replace( QString::fromUtf8( "€" ), "€" );
00726 txt = txt.replace( QString::fromUtf8( "é" ), "é" );
00727
00728 return txt;
00729 }
00730
00731 QString HtmlExport::styleSheet() const
00732 {
00733 if ( !d->mSettings->styleSheet().isEmpty() ) {
00734 return d->mSettings->styleSheet();
00735 }
00736
00737 QString css;
00738
00739 if ( QApplication::isRightToLeft() ) {
00740 css += " body { background-color:white; color:black; direction: rtl }\n";
00741 css += " td { text-align:center; background-color:#eee }\n";
00742 css += " th { text-align:center; background-color:#228; color:white }\n";
00743 css += " td.sumdone { background-color:#ccc }\n";
00744 css += " td.done { background-color:#ccc }\n";
00745 css += " td.subhead { text-align:center; background-color:#ccf }\n";
00746 css += " td.datehead { text-align:center; background-color:#ccf }\n";
00747 css += " td.space { background-color:white }\n";
00748 css += " td.dateholiday { color:red }\n";
00749 } else {
00750 css += " body { background-color:white; color:black }\n";
00751 css += " td { text-align:center; background-color:#eee }\n";
00752 css += " th { text-align:center; background-color:#228; color:white }\n";
00753 css += " td.sum { text-align:left }\n";
00754 css += " td.sumdone { text-align:left; background-color:#ccc }\n";
00755 css += " td.done { background-color:#ccc }\n";
00756 css += " td.subhead { text-align:center; background-color:#ccf }\n";
00757 css += " td.datehead { text-align:center; background-color:#ccf }\n";
00758 css += " td.space { background-color:white }\n";
00759 css += " td.date { text-align:left }\n";
00760 css += " td.dateholiday { text-align:left; color:red }\n";
00761 }
00762
00763 return css;
00764 }
00765
00766 void HtmlExport::addHoliday( const QDate &date, const QString &name )
00767 {
00768 if ( d->mHolidayMap[date].isEmpty() ) {
00769 d->mHolidayMap[date] = name;
00770 } else {
00771 d->mHolidayMap[date] = i18nc( "@info/plain holiday by date and name",
00772 "%1, %2", d->mHolidayMap[date], name );
00773 }
00774 }
00775
00776 QDate HtmlExport::fromDate() const
00777 {
00778 return d->mSettings->dateStart().date();
00779 }
00780
00781 QDate HtmlExport::toDate() const
00782 {
00783 return d->mSettings->dateEnd().date();
00784 }