#include "kincidenceformatter.h" #include #include #include #ifdef DEKTOP_VERSION #include //Added by qt3to4: #include #define size count #endif KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; static KStaticDeleter insd; QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) { // #ifndef QT_NO_INPUTDIALOG // return QInputDialog::getItem( caption, label, items, current, editable ); // #else // return QString::null; // #endif mDetails = details; mCreated = created ; mModified = modified; mText = ""; if ( inc->typeID() == eventID ) setEvent((Event *) inc ); else if ( inc->typeID() == todoID ) setTodo((Todo *) inc ); return mText; } KIncidenceFormatter* KIncidenceFormatter::instance() { if (!mInstance) { mInstance = insd.setObject(new KIncidenceFormatter()); } return mInstance; } KIncidenceFormatter::~KIncidenceFormatter() { if (mInstance == this) mInstance = insd.setObject(0); //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); } KIncidenceFormatter::KIncidenceFormatter() { mColorMode = 0; } void KIncidenceFormatter::setEvent(Event *event) { int mode = 0; mCurrentIncidence = event; bool shortDate = true; if ( mode == 0 ) { addTag("h3",deTag(event->summary())); formatReadOnly(event); } else { if ( mColorMode == 1 ) { mText +=""; } if ( mColorMode == 2 ) { mText +=""; } // mText +="" + i18n("O-due!") + ""; if ( mode == 1 ) { addTag("h2",i18n( "Local: " ) +deTag(event->summary())); } else { addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); } formatReadOnly(event); addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); if ( mColorMode ) mText += ""; } if (event->cancelled ()) { mText +=""; addTag("i",i18n("This event has been cancelled!")); mText.append("
"); mText += "
"; } if (event->doesFloat()) { if (event->isMultiDay()) { mText.append(i18n("

From: %1

To: %2

") .arg(event->dtStartDateStr(shortDate)) .arg(event->dtEndDateStr(shortDate))); mText.append(i18n("

Duration: %1 days

") .arg(event->dtStart().daysTo(event->dtEnd())+1)); } else { mText.append(i18n("

On: %1

").arg(event->dtStartDateStr( shortDate ))); } } else { if (event->isMultiDay()) { mText.append(i18n("

From: %1

") .arg(event->dtStartStr( shortDate))); mText.append(i18n("

To: %1

") .arg(event->dtEndStr(shortDate))); } else { mText.append(i18n("

From: %1 To: %2

") .arg(event->dtStartTimeStr()) .arg(event->dtEndTimeStr())); mText.append(i18n("

On: %1

") .arg(event->dtStartDateStr( shortDate ))); } } if (!event->location().isEmpty()) { addTag("b",i18n("Location: ")); mText.append(deTag(event->location())+"
"); } if (event->doesRecur()) { QString recurText = event->recurrence()->recurrenceText(); addTag("p","" + i18n("This is a %1 recurring event.").arg(recurText ) + ""); bool ok; QDate start = QDate::currentDate(); QDateTime next; next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); if ( ok ) { addTag("p",i18n("Next recurrence is on:") ); addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); } else { bool last; QDate nextd; nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); if ( last ) { addTag("p",i18n("Last recurrence was on:") ); addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); } } } if (event->isAlarmEnabled()) { Alarm *alarm =event->alarms().first() ; QDateTime t = alarm->time(); if (event->doesRecur()) { bool ok = false; int offset = 0; QDateTime next = event->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; if ( ok ) { t = next; } } QString s =i18n("( %1 before )").arg( alarm->offsetText() ); addTag("p",i18n("Alarm on: ") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); //addTag("p",s); } addTag("p",i18n("Access: ") +event->secrecyStr() ); // mText.append(event->secrecyStr()+"
"); formatCategories(event); formatAttendees(event); if ( mCreated ) { #ifdef DESKTOP_VERSION addTag("p",i18n("Created: ") +" "+KGlobal::locale()->formatDateTime( event->created(), shortDate )); #else addTag("p",i18n("Created: ") +" "); addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); #endif } if ( mModified ) { #ifdef DESKTOP_VERSION addTag("p",i18n("Last modified: ") +" "+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); #else addTag("p",i18n("Last modified: ") +" "); addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); #endif } if ( mDetails ) { if (!event->description().isEmpty()) { addTag("p",i18n("Details: ")); addTag("p",deTag(event->description())); } } } void KIncidenceFormatter::setTodo(Todo *event ) { int mode = 0; mCurrentIncidence = event; bool shortDate = true; if (mode == 0 ) { addTag("h3",deTag(event->summary())); formatReadOnly(event); } else { if ( mColorMode == 1 ) { mText +=""; } if ( mColorMode == 2 ) { mText +=""; } if ( mode == 1 ) { addTag("h2",i18n( "Local: " ) +deTag(event->summary())); } else { addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); } formatReadOnly(event); addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); if ( mColorMode ) mText += ""; } if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { mText +=""; addTag("i", i18n("

Completed on %1

").arg( event->completedStr(shortDate) ) ); mText += "
"; } else { mText.append(i18n("

%1 % completed

") .arg(event->percentComplete())); } if (event->cancelled ()) { mText +=""; addTag("i",i18n("This todo has been cancelled!")); mText.append("
"); mText += "
"; } if (event->doesRecur()) { QString recurText = event->recurrence()->recurrenceText(); addTag("p","" + i18n("This is a %1 recurring todo.").arg(recurText ) + ""); } if (event->hasStartDate()) { mText.append(i18n("

Start on: %1

").arg(event->dtStartStr(shortDate))); } if (event->hasDueDate()) { mText.append(i18n("

Due on: %1

").arg(event->dtDueStr(shortDate))); } if (!event->location().isEmpty()) { addTag("b",i18n("Location: ")); mText.append(deTag(event->location())+"
"); } mText.append(i18n("

Priority: %2

") .arg(QString::number(event->priority()))); if (event->isAlarmEnabled()) { Alarm *alarm =event->alarms().first() ; QDateTime t = alarm->time(); if (event->doesRecur()) { bool ok = false; int offset = 0; QDateTime next = event->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; if ( ok ) { t = next; } } QString s =i18n("( %1 before )").arg( alarm->offsetText() ); addTag("p",i18n("Alarm on: ") + s +" "); addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); //addTag("p",s); } addTag("p",i18n("Access: ") +event->secrecyStr() ); formatCategories(event); formatAttendees(event); if ( mCreated ) { #ifdef DESKTOP_VERSION addTag("p",i18n("Created: ") +" "+KGlobal::locale()->formatDateTime( event->created(), shortDate )); #else addTag("p",i18n("Created: ") +" "); addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); #endif } if ( mModified ) { #ifdef DESKTOP_VERSION addTag("p",i18n("Last modified: ") +" "+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); #else addTag("p",i18n("Last modified: ") +" "); addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); #endif } if ( mDetails ) { if (!event->description().isEmpty()) { addTag("p",i18n("Details: ")); addTag("p",deTag(event->description())); } } } void KIncidenceFormatter::setJournal(Journal* ) { } void KIncidenceFormatter::formatCategories(Incidence *event) { if (!event->categoriesStr().isEmpty()) { addTag("p",i18n("Categories: ")+event->categoriesStrWithSpace() ); //mText.append(event->categoriesStr()); } } void KIncidenceFormatter::addTag(const QString & tag,const QString & text) { int number=text.count("\n"); QString str = "<" + tag + ">"; QString tmpText=text; QString tmpStr=str; if(number !=-1) { if (number > 0) { int pos=0; QString tmp; for(int i=0;i<=number;i++) { pos=tmpText.find("\n"); tmp=tmpText.left(pos); tmpText=tmpText.right(tmpText.length()-pos-1); tmpStr+=tmp+"
"; } } else tmpStr += tmpText; tmpStr+=""; mText.append(tmpStr); } else { str += text + ""; mText.append(str); } } void KIncidenceFormatter::formatAttendees(Incidence *event) { Q3PtrList attendees = event->attendees(); if (attendees.count()) { QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); addTag("h3",i18n("Organizer")); mText.append("
  • "); #if 0 //ndef KORG_NOKABC KABC::AddressBook *add_book = KABC::StdAddressBook::self(); KABC::Addressee::List addressList; addressList = add_book->findByEmail(event->organizer()); KABC::Addressee o = addressList.first(); if (!o.isEmpty() && addressList.size()<2) { mText += ""; mText += o.formattedName(); mText += "\n"; } else { mText.append(event->organizer()); } #else mText.append(event->organizer()); #endif if (!iconPath.isEmpty()) { mText += " organizer() + "\">"; mText += ""; mText += "\n"; } mText.append("
"); addTag("h3",i18n("Attendees")); Attendee *a; mText.append(""); } } void KIncidenceFormatter::formatReadOnly(Incidence *event) { if (event->isReadOnly()) { addTag("p","(" + i18n("read-only") + ")"); } } QString KIncidenceFormatter::deTag(QString text) { #if QT_VERSION >= 0x030000 text.replace( '<' , "<" ); text.replace( '>' , ">" ); #else if ( text.find ('<') >= 0 ) { text.replace( QRegExp("<") , "<" ); } if ( text.find ('>') >= 0 ) { text.replace( QRegExp(">") , ">" ); } #endif return text; }