korganizer

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #include "koglobals.h"
00027 #include "urihandler.h"
00028 
00029 #include <libkcal/attachmenthandler.h>
00030 #include <libkcal/calendar.h>
00031 #include <libkcal/incidence.h>
00032 #include <libkcal/incidenceformatter.h>
00033 
00034 #include <kdebug.h>
00035 #include <klocale.h>
00036 #include <kmdcodec.h>
00037 #include <kpopupmenu.h>
00038 
00039 #include <qcursor.h>
00040 #include <qregexp.h>
00041 #include <qtooltip.h>
00042 
00043 KOEventViewer::KOEventViewer( Calendar *calendar, QWidget *parent, const char *name )
00044   : QTextBrowser( parent, name ), mCalendar( calendar ), mDefaultText("")
00045 {
00046   mIncidence = 0;
00047   connect( this, SIGNAL(highlighted(const QString &)), SLOT(message(const QString &)) );
00048 }
00049 
00050 KOEventViewer::~KOEventViewer()
00051 {
00052 }
00053 
00054 void KOEventViewer::message( const QString &link )
00055 {
00056   mAttachLink = QString();
00057   if ( link.isEmpty() ) {
00058     QToolTip::remove( this );
00059     return;
00060   }
00061 
00062   QString ttStr;
00063   if ( link.startsWith( "kmail:" ) ) {
00064     ttStr = i18n( "Open the message in KMail" );
00065   } else if ( link.startsWith( "mailto:" ) ) {
00066     ttStr = i18n( "Send an email message to %1" ).arg( link.mid( 7 ) );
00067   } else if ( link.startsWith( "uid:" ) ) {
00068     ttStr = i18n( "Lookup the contact in KAddressbook" );
00069   } else if ( link.startsWith( "ATTACH:" ) ) {
00070     QString tmp = link;
00071     tmp.remove( QRegExp( "^ATTACH://" ) );
00072     QString uid = tmp.section( ':', 0, 0 );
00073     QString name = tmp.section( ':', -1, -1 );
00074     const QCString decodedName = KCodecs::base64Decode(name.utf8());
00075     name = QString::fromUtf8(decodedName.data(), decodedName.length());
00076     ttStr = i18n( "View attachment \"%1\"" ).arg( name );
00077     mAttachLink = link;
00078   } else {  // no special URI, let KDE handle it
00079     ttStr = i18n( "Launch a viewer on the link" );
00080   }
00081 
00082   QToolTip::add( this, ttStr );
00083 }
00084 
00085 void KOEventViewer::readSettings( KConfig * config )
00086 {
00087   if ( config ) {
00088 // With each restart of KOrganizer the font site gets halfed. What should this
00089 // be good for?
00090 #if 0
00091     config->setGroup( QString("EventViewer-%1").arg( name() )  );
00092     int zoomFactor = config->readNumEntry("ZoomFactor", pointSize() );
00093     zoomTo( zoomFactor/2 );
00094     kdDebug(5850) << " KOEventViewer: restoring the pointSize:  "<< pointSize()
00095       << ", zoomFactor: " << zoomFactor << endl;
00096 #endif
00097   }
00098 }
00099 
00100 void KOEventViewer::writeSettings( KConfig * config )
00101 {
00102   if ( config ) {
00103     kdDebug(5850) << " KOEventViewer: saving the zoomFactor: "<< pointSize() << endl;
00104     config->setGroup( QString("EventViewer-%1").arg( name() ) );
00105     config->writeEntry("ZoomFactor", pointSize() );
00106   }
00107 }
00108 
00109 void KOEventViewer::setSource( const QString &n )
00110 {
00111   UriHandler::process( parentWidget(), n );
00112 }
00113 
00114 bool KOEventViewer::appendIncidence( Incidence *incidence, const QDate &date )
00115 {
00116   addText( IncidenceFormatter::extensiveDisplayStr( mCalendar, incidence, date ) );
00117   return true;
00118 }
00119 
00120 void KOEventViewer::setCalendar( Calendar *calendar )
00121 {
00122   mCalendar = calendar;
00123 }
00124 
00125 void KOEventViewer::setIncidence( Incidence *incidence, const QDate &date )
00126 {
00127   clearEvents();
00128   if( incidence ) {
00129     appendIncidence( incidence, date );
00130     mIncidence = incidence;
00131   } else {
00132     clearEvents( true );
00133     mIncidence = 0;
00134   }
00135 }
00136 
00137 void KOEventViewer::clearEvents( bool now )
00138 {
00139   mText = "";
00140   if ( now ) setText( mDefaultText );
00141 }
00142 
00143 void KOEventViewer::addText( const QString &text )
00144 {
00145   mText.append( text );
00146   setText( mText );
00147 }
00148 
00149 void KOEventViewer::setDefaultText( const QString &text )
00150 {
00151   mDefaultText = text;
00152 }
00153 
00154 void KOEventViewer::changeIncidenceDisplay( Incidence *incidence, const QDate &date, int action )
00155 {
00156   if ( mIncidence && ( incidence->uid() == mIncidence->uid() ) ) {
00157     switch ( action ) {
00158     case KOGlobals::INCIDENCEEDITED:
00159       setIncidence( incidence, date );
00160       break;
00161     case KOGlobals::INCIDENCEDELETED:
00162       setIncidence( 0, date );
00163       break;
00164     }
00165   }
00166 }
00167 
00168 void KOEventViewer::contentsContextMenuEvent( QContextMenuEvent *e )
00169 {
00170   QString name = UriHandler::attachmentNameFromUri( mAttachLink );
00171   QString uid = UriHandler::uidFromUri( mAttachLink );
00172   if ( name.isEmpty() || uid.isEmpty() ) {
00173     QTextBrowser::contentsContextMenuEvent( e );
00174     return;
00175   }
00176 
00177   KPopupMenu *menu = new KPopupMenu();
00178   menu->insertItem( i18n( "Open Attachment" ), 0 );
00179   menu->insertItem( i18n( "Save Attachment As..." ), 1 );
00180 
00181   switch( menu->exec( QCursor::pos(), 0 ) ) {
00182   case 0: // open
00183     AttachmentHandler::view( parentWidget(), name, uid );
00184     break;
00185   case 1: // save as
00186     AttachmentHandler::saveAs( parentWidget(), name, uid );
00187     break;
00188   default:
00189     break;
00190   }
00191 }
00192 
00193 #include "koeventviewer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys