/* This file is part of KOrganizer. Copyright (c) 2001 Cornelius Schumacher This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "koprefs.h" #include #ifndef KORG_NODCOP #include #include "korganizer.h" #include "koprefs.h" #include "actionmanager.h" #endif #include "koeventviewer.h" //#ifndef KORG_NOKABC //#include //#define size count //#endif #ifdef DESKTOP_VERSION #include #include #include #include #include #else //DESKTOP_VERSION #include #include #endif //DESKTOP_VERSION KOEventViewer::KOEventViewer(QWidget *parent,const char *name) : QTextBrowser(parent,name) { mSyncMode = false; mColorMode = 0; } KOEventViewer::~KOEventViewer() { } void KOEventViewer::printMe() { #ifdef DESKTOP_VERSION KOPrintPrefs pp ( this ); if (!pp.exec() ) return; int scaleval = pp.printMode() ; QPrinter printer; if (!printer.setup() ) return; QPainter p; p.begin ( &printer ); QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer ); float dx, dy; int wid = (m.width() * 9)/10; dx = (float) wid/(float)contentsWidth (); dy = (float)(m.height()) / (float)contentsHeight (); float scale; // scale to fit the width or height of the paper if ( dx < dy ) scale = dx; else scale = dy; p.translate( m.width()/10,0 ); if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) { p.scale( scale, scale ); } drawContents ( &p, 0,0, contentsWidth (), contentsHeight () ); p.end(); #endif } void KOEventViewer::setSource(const QString& n) { if ( n.left(8) == "todo_uid" ) { int midstr = 9; #ifdef DESKTOP_VERSION midstr = 11; #endif qDebug("-%s- ", n.mid(midstr).latin1()); emit showIncidence( n.mid(midstr) ); return; } if ( n.left(3) == "uid" ) #ifdef DESKTOP_VERSION { KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); KABC::AddressBook::Iterator it; for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { // LR I do not understand, why the uid string is different on zaurus and desktop QString uid = "uid://"+(*it).uid(); //qDebug("for *%s* +%s+ ", n.latin1(), uid.latin1()); if (n == uid ) { //qDebug("found %s ",(*it).mobileHomePhone().latin1() ); QDialog dia( this,"dia123", true ); dia.setCaption( i18n("Details of attendee") ); QVBoxLayout lay ( &dia ); KABC::AddresseeView av ( &dia ); av.setAddressee( (*it) ); lay.addWidget( &av ); if ( QApplication::desktop()->width() < 480 ) dia.resize( 220, 240); else { dia.resize( 400,400); } dia.exec(); break; } } return; } #else { if ( "uid:organizer" == n ) { ExternalAppHandler::instance()->requestDetailsFromKAPI("", mCurrentIncidence->organizer(),""); return; } QPtrList attendees = mCurrentIncidence->attendees(); if (attendees.count()) { Attendee *a; for(a=attendees.first();a;a=attendees.next()) { if ( "uid:"+a->uid() == n ) { bool res = ExternalAppHandler::instance()->requestDetailsFromKAPI(a->name(), a->email(), a->uid()); return; } } } return; } //requestNameEmailUidListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); // the result should now arrive through method insertAttendees //QString uid = "uid:"+(*it).uid(); #endif if ( n.left(6) == "mailto" ) { // qDebug("KOEventViewer::setSource %s ", n.mid(7).latin1()); #ifndef DESKTOP_VERSION if ( n.mid(7,3) == "ALL" ) { mailToAttendees( true ); } else if ( n.mid(7,4) == "RSVP" ) { mailToAttendees( false ); } else { QCopEnvelope e("QPE/Application/ompi", "newMail(QString)" ); e << n.mid(7); } #endif } #ifndef KORG_NODCOP kdDebug() << "KOEventViewer::setSource(): " << n << endl; QString tmpStr; if (n.startsWith("mailto:")) { KApplication::kApplication()->invokeMailer(n.mid(7),QString::null); //emit showIncidence(n); return; } else if (n.startsWith("uid:")) { DCOPClient *client = KApplication::kApplication()->dcopClient(); const QByteArray noParamData; const QByteArray paramData; QByteArray replyData; QCString replyTypeStr; #define PING_ABBROWSER (client->call("kaddressbook", "KAddressBookIface", "interfaces()", noParamData, replyTypeStr, replyData)) bool foundAbbrowser = PING_ABBROWSER; if (foundAbbrowser) { //KAddressbook is already running, so just DCOP to it to bring up the contact editor //client->send("kaddressbook","KAddressBookIface", QDataStream arg(paramData, IO_WriteOnly); arg << n.mid(6); client->send("kaddressbook", "KAddressBookIface", "showContactEditor( QString )", paramData); return; } else { /* KaddressBook is not already running. Pass it the UID of the contact via the command line while starting it - its neater. We start it without its main interface */ KIconLoader* iconLoader = new KIconLoader(); QString iconPath = iconLoader->iconPath("go",KIcon::Small); ActionManager::setStartedKAddressBook(true); tmpStr = "kaddressbook --editor-only --uid "; tmpStr += KProcess::quote(n.mid(6)); KRun::runCommand(tmpStr,"KAddressBook",iconPath); return; } } else { //QTextBrowser::setSource(n); } #endif } void KOEventViewer::mailToAttendees( bool all ) { QPtrList attendees = mCurrentIncidence->attendees(); if (attendees.count() == 0) return; QStringList nameList; QStringList emailList; QStringList uidList; Attendee* a; for(a=attendees.first();a;a=attendees.next()) { if ( !all && !a->RSVP() ) continue; if (!a->email().isEmpty()) { nameList.append (a->name() ); emailList.append (a->email() ); uidList.append (a->uid() ); } } QString uid = "ComposeMailUIpick2"+mMailSubject; #ifndef DESKTOP_VERSION bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); #endif } void KOEventViewer::addTag(const QString & tag,const QString & text) { int number=text.contains("\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 KOEventViewer::setColorMode( int m ) { mColorMode = m; } void KOEventViewer::appendEvent(Event *event, int mode ) { mMailSubject = ""; mCurrentIncidence = event; bool shortDate = KOPrefs::instance()->mShortDateInViewer; bool wideScreen = ( QApplication::desktop()->width() >= 640 ); topLevelWidget()->setCaption(i18n("Event Viewer")); if ( mode == 0 ) { addTag("h2",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 += ""; } mMailSubject += i18n( "Meeting " )+ event->summary(); if (event->cancelled ()) { mText +=""; addTag("i",i18n("This event has been cancelled!")); mText.append("
"); mText += "
"; mMailSubject += i18n("(cancelled)"); } if (event->doesFloat()) { if (event->isMultiDay()) { mText.append(i18n("

From: %1

To: %2

") .arg(event->dtStartDateStr(shortDate)) .arg(event->dtEndDateStr(shortDate))); } 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("p",""+i18n("Location: ")+""+ deTag(event->location() ) ); mMailSubject += i18n(" at ") + event->location(); } if (event->recurrence()->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 ) { if ( wideScreen ){ addTag("p",i18n("Next recurrence is on:") +" " + KGlobal::locale()->formatDate( next.date(), shortDate ) ); } else { addTag("p",i18n("Next recurrence is on:") ); addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); } mMailSubject += i18n(" - " )+ KGlobal::locale()->formatDateTime( next, true ); } else { bool last; QDate nextd; nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); if ( last ) { if ( wideScreen ){ addTag("p",i18n("Last recurrence was on:") +" " + KGlobal::locale()->formatDate( nextd, shortDate )); } else{ addTag("p",i18n("Last recurrence was on:") ); addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); } } } } else { mMailSubject += i18n(" - " )+event->dtStartStr( true ); } if (event->isAlarmEnabled()) { Alarm *alarm =event->alarms().first() ; QDateTime t = alarm->time(); QString s =i18n("( %1 before )").arg( alarm->offsetText() ); if(wideScreen ){ addTag("p",i18n("Alarm on: ") + s +" "+ KGlobal::locale()->formatDateTime( t, shortDate )); }else{ 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 ( KOPrefs::instance()->mEVshowCreated ) { if(wideScreen ){ addTag("p",i18n("Created: ") +" "+KGlobal::locale()->formatDateTime( event->created(), shortDate )); }else{ addTag("p",i18n("Created: ") +" "); addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); } } if ( KOPrefs::instance()->mEVshowChanged ) { if(wideScreen ){ 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 )); } } if ( KOPrefs::instance()->mEVshowDetails ) { if (!event->description().isEmpty()) { addTag("p",i18n("Details: ")); addTag("p",deTag(event->description())); } } setText(mText); //QWhatsThis::add(this,mText); } void KOEventViewer::appendTodo(Todo *event, int mode ) { mMailSubject = ""; mCurrentIncidence = event; topLevelWidget()->setCaption(i18n("Todo Viewer")); bool shortDate = KOPrefs::instance()->mShortDateInViewer; bool wideScreen = ( QApplication::desktop()->width() >= 640 ); if (mode == 0 ) { addTag("h2",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 += ""; } mMailSubject += i18n( "Todo " )+ event->summary(); if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { mText +=""; addTag("i", i18n("

Completed on %1

").arg( event->completedStr(KOPrefs::instance()->mShortDateInViewer) ) ); 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 += "
"; mMailSubject += i18n("(cancelled)"); } if (event->recurrence()->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(KOPrefs::instance()->mShortDateInViewer))); } if (event->hasDueDate()) { mText.append(i18n("

Due on: %1

").arg(event->dtDueStr(KOPrefs::instance()->mShortDateInViewer))); mMailSubject += i18n(" - " )+event->dtDueStr( true ); } if (!event->location().isEmpty()) { addTag("p",""+i18n("Location: ")+""+ deTag(event->location() ) ); mMailSubject += i18n(" at ") + event->location(); } mText.append(i18n("

Priority: %2

") .arg(QString::number(event->priority()))); if (event->isAlarmEnabled()) { Alarm *alarm =event->alarms().first() ; QDateTime t = alarm->time(); QString s =i18n("( %1 before )").arg( alarm->offsetText() ); if ( wideScreen ) { addTag("p",i18n("Alarm on: ") + s +" "+ KGlobal::locale()->formatDateTime( t, shortDate )); } else { addTag("p",i18n("Alarm on: ") + s +" "); addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); } } addTag("p",""+i18n("Access: ") + "" + event->secrecyStr()); formatCategories(event); formatAttendees(event); if ( KOPrefs::instance()->mEVshowCreated ) { if(wideScreen ){ addTag("p",i18n("Created: ") +" "+KGlobal::locale()->formatDateTime( event->created(), shortDate )); } else { addTag("p",i18n("Created: ") +" "); addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); } } if ( KOPrefs::instance()->mEVshowChanged ) { if(wideScreen ){ 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 )); } } if ( event->relatedTo() ) { addTag("b",i18n("Parent todo:
")); QString t_name = "[" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] ";// +event->relatedTo()->summary()); mText += t_name; mText += "relatedTo()->uid() + "\">"; mText += deTag(event->relatedTo()->summary()); mText += "
"; // mText.append(deTag("[" +QString::number(event->relatedTo()->priority()) + "/" + QString::number(((Todo*)event->relatedTo())->percentComplete())+"%] " +event->relatedTo()->summary()) +"
"); } QPtrList Relations = event->relations(); Incidence *to; if ( Relations.first() ) addTag("b",i18n("Sub todos:
")); for (to=Relations.first();to;to=Relations.next()) { QString t_name = "[" +QString::number(((Todo*)to)->priority()) + "/" + QString::number(((Todo*)to)->percentComplete())+"%] ";// +to->relatedTo()->summary()); mText += t_name; mText += "uid() + "\">"; mText += deTag(to->summary()); mText += "
"; } if ( KOPrefs::instance()->mEVshowDetails ) { if (!event->description().isEmpty()) { addTag("p",i18n("Details: ")); addTag("p",deTag(event->description())); } } setText(mText); } void KOEventViewer::formatCategories(Incidence *event) { if (!event->categoriesStr().isEmpty()) { if (event->categories().count() == 1) { addTag("p",""+i18n("Category") + ": " + event->categoriesStrWithSpace()); } else { addTag("p",""+i18n("Categories")+": " + event->categoriesStrWithSpace() ) ; } } } void KOEventViewer::formatAttendees(Incidence *event) { QPtrList 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(""); addTag("h3",i18n("Attendees")); Attendee *a; mText.append(""); if ( (a_count+a_count_nr) > 1 ) { mText += ""; mText += i18n( "Mail to all" ); mText += " ( "; mText += ""; mText += i18n( " and " ); mText += " )"; mText += "
\n"; } if ( a_count_nr > 1 ) { mText += ""; mText += i18n( "Mail to selected" ); mText += " ( "; mText += i18n( " only )").arg ( iconPath ); mText += "
\n"; } } } void KOEventViewer::appendJournal(Journal *jour, int mode ) { bool shortDate = KOPrefs::instance()->mShortDateInViewer; QString text_d = i18n("Journal from: "); if ( !jour->summary().isEmpty() ) text_d = jour->summary(); if (mode == 0 ) { addTag("h2", text_d ); } else { if ( mode == 1 ) { addTag("h3",i18n( "Local: " ) + text_d ); } else { addTag("h3",i18n( "Remote: " ) + text_d ); } } topLevelWidget()->setCaption(i18n("Journal viewer")); mText.append(i18n("

%1

").arg(jour->dtStartDateStr(KOPrefs::instance()->mShortDateInViewer))); formatReadOnly(jour); addTag("p",""+i18n( "Last modified: " ) + ""+KGlobal::locale()->formatDateTime(jour->lastModified(),shortDate ) ); if (!jour->description().isEmpty()) { addTag("p",deTag(jour->description())); } setText(mText); } void KOEventViewer::formatReadOnly(Incidence *event) { int id = event->calID(); if ( id > 1 ) { addTag("p", "("+i18n("Calendar:")+" " + KOPrefs::instance()->getCalendar( id )->mName + ")"); } if (event->isReadOnly()) { addTag("p","(" + i18n("read-only") + ")"); } } void KOEventViewer::setSyncMode( bool b ) { mSyncMode = b; } void KOEventViewer::setTodo(Todo *event, bool clearV ) { if ( clearV ) clearEvents(); if ( mSyncMode ) { if ( clearV ) appendTodo(event,1 ); else appendTodo(event,2); } else appendTodo(event); } void KOEventViewer::setJournal(Journal *event, bool clearV ) { if ( clearV ) clearEvents(); if ( mSyncMode ) { if ( clearV ) appendJournal(event, 1); else appendJournal(event, 2); } else appendJournal(event); } void KOEventViewer::setEvent(Event *event) { clearEvents(); if ( mSyncMode ) appendEvent(event, 1); else appendEvent(event); } void KOEventViewer::addEvent(Event *event) { if ( mSyncMode ) appendEvent(event, 2); else appendEvent(event); } void KOEventViewer::clearEvents(bool now) { mText = ""; if (now) setText(mText); } void KOEventViewer::addText(QString text) { mText.append(text); setText(mText); } QString KOEventViewer::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; } void KOEventViewer::keyPressEvent ( QKeyEvent * e ) { switch ( e->key() ) { case Qt::Key_Return: case Qt::Key_Enter : e->ignore(); break; default: QTextBrowser::keyPressEvent ( e ); break; } }