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 
00027 #include "urihandler.h"
00028 
00029 #include <libkcal/calendar.h>
00030 #include <libkcal/incidence.h>
00031 #include <libkcal/incidenceformatter.h>
00032 #include <kdebug.h>
00033 #include <koglobals.h>
00034 
00035 KOEventViewer::KOEventViewer( Calendar *calendar, QWidget *parent, const char *name )
00036   : QTextBrowser( parent, name ), mCalendar( calendar ), mDefaultText("")
00037 {
00038   mIncidence = 0;
00039 }
00040 
00041 KOEventViewer::~KOEventViewer()
00042 {
00043 }
00044 
00045 void KOEventViewer::readSettings( KConfig * config )
00046 {
00047   if ( config ) {
00048 // With each restart of KOrganizer the font site gets halfed. What should this
00049 // be good for?
00050 #if 0
00051     config->setGroup( QString("EventViewer-%1").arg( name() )  );
00052     int zoomFactor = config->readNumEntry("ZoomFactor", pointSize() );
00053     zoomTo( zoomFactor/2 );
00054     kdDebug(5850) << " KOEventViewer: restoring the pointSize:  "<< pointSize()
00055       << ", zoomFactor: " << zoomFactor << endl;
00056 #endif
00057   }
00058 }
00059 
00060 void KOEventViewer::writeSettings( KConfig * config )
00061 {
00062   if ( config ) {
00063     kdDebug(5850) << " KOEventViewer: saving the zoomFactor: "<< pointSize() << endl;
00064     config->setGroup( QString("EventViewer-%1").arg( name() ) );
00065     config->writeEntry("ZoomFactor", pointSize() );
00066   }
00067 }
00068 
00069 void KOEventViewer::setSource( const QString &n )
00070 {
00071   UriHandler::process( n );
00072 }
00073 
00074 bool KOEventViewer::appendIncidence( Incidence *incidence, const QDate &date )
00075 {
00076   addText( IncidenceFormatter::extensiveDisplayStr( mCalendar, incidence, date ) );
00077   return true;
00078 }
00079 
00080 void KOEventViewer::setCalendar( Calendar *calendar )
00081 {
00082   mCalendar = calendar;
00083 }
00084 
00085 void KOEventViewer::setIncidence( Incidence *incidence, const QDate &date )
00086 {
00087   clearEvents();
00088   if( incidence ) {
00089     appendIncidence( incidence, date );
00090     mIncidence = incidence;
00091   } else {
00092     clearEvents( true );
00093     mIncidence = 0;
00094   }
00095 }
00096 
00097 void KOEventViewer::clearEvents( bool now )
00098 {
00099   mText = "";
00100   if ( now ) setText( mDefaultText );
00101 }
00102 
00103 void KOEventViewer::addText( const QString &text )
00104 {
00105   mText.append( text );
00106   setText( mText );
00107 }
00108 
00109 void KOEventViewer::setDefaultText( const QString &text )
00110 {
00111   mDefaultText = text;
00112 }
00113 
00114 void KOEventViewer::changeIncidenceDisplay( Incidence *incidence, const QDate &date, int action )
00115 {
00116   if ( mIncidence && ( incidence->uid() == mIncidence->uid() ) ) {
00117     switch (action ) {
00118       case KOGlobals::INCIDENCEEDITED:{
00119         setIncidence( incidence, date );
00120         break;
00121       }
00122       case KOGlobals::INCIDENCEDELETED: {
00123         setIncidence( 0, date );
00124         break;
00125       }
00126     }
00127   }
00128 }
00129 
00130 #include "koeventviewer.moc"