korganizer
koeventviewer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "koeventviewer.h"
00027 #include "urihandler.h"
00028 #include "korganizerinterface.h"
00029 #include "koglobals.h"
00030
00031 #include <libkdepim/kdepimprotocols.h>
00032
00033 #include <kcal/incidence.h>
00034 #include <kcal/incidenceformatter.h>
00035
00036 #include <kapplication.h>
00037 #include <kdebug.h>
00038 #include <ktoolinvocation.h>
00039 #include <kconfiggroup.h>
00040
00041 #include <QRegExp>
00042
00043 KOEventViewer::KOEventViewer( QWidget *parent )
00044 : KTextBrowser( parent ), mDefaultText( "" )
00045 {
00046 mIncidence = 0;
00047 setNotifyClick( true );
00048 }
00049
00050 KOEventViewer::~KOEventViewer()
00051 {
00052 }
00053
00054 void KOEventViewer::readSettings( KConfig *config )
00055 {
00056 if ( config ) {
00057
00058
00059 #if 0
00060 config->setGroup( QString( "EventViewer-%1" ).arg( name() ) );
00061 int zoomFactor = config->readEntry( "ZoomFactor", fontPointSize() );
00062 zoomTo( zoomFactor / 2 );
00063 kDebug(5850) << " KOEventViewer: restoring the fontPointSize:" << fontPointSize()
00064 << ", zoomFactor: " << zoomFactor;
00065 #endif
00066 }
00067 }
00068
00069 void KOEventViewer::writeSettings( KConfig *config )
00070 {
00071 if ( config ) {
00072 kDebug() << "saving the zoomFactor:" << fontPointSize();
00073 KConfigGroup configGroup( config, QString( "EventViewer-%1" ).arg( objectName() ) );
00074 configGroup.writeEntry( "ZoomFactor", fontPointSize() );
00075 }
00076 }
00077
00078 void KOEventViewer::setSource( const QUrl &name )
00079 {
00080 QString uri = name.toString();
00081
00082
00083 if ( uri.startsWith( KDEPIMPROTOCOL_CONTACT ) ||
00084 uri.startsWith( KDEPIMPROTOCOL_EMAIL ) ||
00085 uri.startsWith( QString( KDEPIMPROTOCOL_INCIDENCE ).section( ':', 0, 0 ) ) ||
00086 uri.startsWith( KDEPIMPROTOCOL_NEWSARTICLE ) ||
00087 uri.startsWith( "mailto:" ) )
00088 {
00089 uri.replace( QRegExp( "^([^:]+:)/+" ), "\\1" );
00090 }
00091
00092 UriHandler::process( uri );
00093 }
00094
00095 bool KOEventViewer::appendIncidence( Incidence *incidence )
00096 {
00097 QString codeForIncidence = IncidenceFormatter::extensiveDisplayString( incidence );
00098 addText( codeForIncidence );
00099 return true;
00100 }
00101
00102 void KOEventViewer::setIncidence( Incidence *incidence )
00103 {
00104 clearEvents();
00105 if( incidence ) {
00106 appendIncidence( incidence );
00107 mIncidence = incidence;
00108 } else {
00109 clearEvents( true );
00110 mIncidence = 0;
00111 }
00112 }
00113
00114 void KOEventViewer::clearEvents( bool now )
00115 {
00116 mText = "";
00117 if ( now ) {
00118 setText( mDefaultText );
00119 }
00120 }
00121
00122 void KOEventViewer::addText( const QString &text )
00123 {
00124 mText.append( text );
00125 setText( mText );
00126 }
00127
00128 void KOEventViewer::setDefaultText( const QString &text )
00129 {
00130 mDefaultText = text;
00131 }
00132
00133 void KOEventViewer::changeIncidenceDisplay( Incidence *incidence, int action )
00134 {
00135 if ( mIncidence && ( incidence->uid() == mIncidence->uid() ) ) {
00136 switch ( action ) {
00137 case KOGlobals::INCIDENCEEDITED:
00138 {
00139 setIncidence( incidence );
00140 break;
00141 }
00142 case KOGlobals::INCIDENCEDELETED:
00143 {
00144 setIncidence( 0 );
00145 break;
00146 }
00147 }
00148 }
00149 }
00150
00151 void KOEventViewer::editIncidence()
00152 {
00153 if ( mIncidence ) {
00154
00155 KToolInvocation::startServiceByDesktopPath( "korganizer" );
00156
00157 OrgKdeKorganizerKorganizerInterface korganizerIface(
00158 "org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
00159 korganizerIface.editIncidence( mIncidence->uid() );
00160 }
00161 }
00162
00163 void KOEventViewer::showIncidenceContext()
00164 {
00165 if ( mIncidence ) {
00166
00167 KToolInvocation::startServiceByDesktopPath( "korganizer" );
00168
00169 OrgKdeKorganizerKorganizerInterface korganizerIface(
00170 "org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
00171 korganizerIface.showIncidenceContext( mIncidence->uid() );
00172 }
00173 }
00174
00175 #include "koeventviewer.moc"