korganizer
koeventviewer.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 <kpopupmenu.h>
00037
00038 #include <tqcursor.h>
00039 #include <tqregexp.h>
00040 #include <tqtooltip.h>
00041
00042 KOEventViewer::KOEventViewer( Calendar *calendar, TQWidget *parent, const char *name )
00043 : TQTextBrowser( parent, name ), mCalendar( calendar ), mDefaultText("")
00044 {
00045 mIncidence = 0;
00046 connect( this, TQT_SIGNAL(highlighted(const TQString &)), TQT_SLOT(message(const TQString &)) );
00047 }
00048
00049 KOEventViewer::~KOEventViewer()
00050 {
00051 }
00052
00053 void KOEventViewer::message( const TQString &link )
00054 {
00055 mAttachLink = TQString();
00056 if ( link.isEmpty() ) {
00057 TQToolTip::remove( this );
00058 return;
00059 }
00060
00061 TQString ttStr;
00062 if ( link.startsWith( "kmail:" ) ) {
00063 ttStr = i18n( "Open the message in KMail" );
00064 } else if ( link.startsWith( "mailto:" ) ) {
00065 ttStr = i18n( "Send an email message to %1" ).arg( link.mid( 7 ) );
00066 } else if ( link.startsWith( "uid:" ) ) {
00067 ttStr = i18n( "Lookup the contact in KAddressbook" );
00068 } else if ( link.startsWith( "ATTACH:" ) ) {
00069 TQString tmp = link;
00070 tmp.remove( TQRegExp( "^ATTACH://" ) );
00071 TQString uid = tmp.section( ':', 0, 0 );
00072 TQString name = tmp.section( ':', -1, -1 );
00073 ttStr = i18n( "View attachment \"%1\"" ).arg( name );
00074 mAttachLink = link;
00075 } else {
00076 ttStr = i18n( "Launch a viewer on the link" );
00077 }
00078
00079 TQToolTip::add( this, ttStr );
00080 }
00081
00082 void KOEventViewer::readSettings( KConfig * config )
00083 {
00084 if ( config ) {
00085
00086
00087 #if 0
00088 config->setGroup( TQString("EventViewer-%1").arg( name() ) );
00089 int zoomFactor = config->readNumEntry("ZoomFactor", pointSize() );
00090 zoomTo( zoomFactor/2 );
00091 kdDebug(5850) << " KOEventViewer: restoring the pointSize: "<< pointSize()
00092 << ", zoomFactor: " << zoomFactor << endl;
00093 #endif
00094 }
00095 }
00096
00097 void KOEventViewer::writeSettings( KConfig * config )
00098 {
00099 if ( config ) {
00100 kdDebug(5850) << " KOEventViewer: saving the zoomFactor: "<< pointSize() << endl;
00101 config->setGroup( TQString("EventViewer-%1").arg( name() ) );
00102 config->writeEntry("ZoomFactor", pointSize() );
00103 }
00104 }
00105
00106 void KOEventViewer::setSource( const TQString &n )
00107 {
00108 UriHandler::process( parentWidget(), n );
00109 }
00110
00111 bool KOEventViewer::appendIncidence( Incidence *incidence, const TQDate &date )
00112 {
00113 addText( IncidenceFormatter::extensiveDisplayStr( mCalendar, incidence, date ) );
00114 return true;
00115 }
00116
00117 void KOEventViewer::setCalendar( Calendar *calendar )
00118 {
00119 mCalendar = calendar;
00120 }
00121
00122 void KOEventViewer::setIncidence( Incidence *incidence, const TQDate &date )
00123 {
00124 clearEvents();
00125 if( incidence ) {
00126 appendIncidence( incidence, date );
00127 mIncidence = incidence;
00128 } else {
00129 clearEvents( true );
00130 mIncidence = 0;
00131 }
00132 }
00133
00134 void KOEventViewer::clearEvents( bool now )
00135 {
00136 mText = "";
00137 if ( now ) setText( mDefaultText );
00138 }
00139
00140 void KOEventViewer::addText( const TQString &text )
00141 {
00142 mText.append( text );
00143 setText( mText );
00144 }
00145
00146 void KOEventViewer::setDefaultText( const TQString &text )
00147 {
00148 mDefaultText = text;
00149 }
00150
00151 void KOEventViewer::changeIncidenceDisplay( Incidence *incidence, const TQDate &date, int action )
00152 {
00153 if ( mIncidence && ( incidence->uid() == mIncidence->uid() ) ) {
00154 switch ( action ) {
00155 case KOGlobals::INCIDENCEEDITED:
00156 setIncidence( incidence, date );
00157 break;
00158 case KOGlobals::INCIDENCEDELETED:
00159 setIncidence( 0, date );
00160 break;
00161 }
00162 }
00163 }
00164
00165 void KOEventViewer::contentsContextMenuEvent( TQContextMenuEvent *e )
00166 {
00167 TQString name = UriHandler::attachmentNameFromUri( mAttachLink );
00168 TQString uid = UriHandler::uidFromUri( mAttachLink );
00169 if ( name.isEmpty() || uid.isEmpty() ) {
00170 TQTextBrowser::contentsContextMenuEvent( e );
00171 return;
00172 }
00173
00174 KPopupMenu *menu = new KPopupMenu();
00175 menu->insertItem( i18n( "Open Attachment" ), 0 );
00176 menu->insertItem( i18n( "Save Attachment As..." ), 1 );
00177
00178 switch( menu->exec( TQCursor::pos(), 0 ) ) {
00179 case 0:
00180 AttachmentHandler::view( parentWidget(), name, uid );
00181 break;
00182 case 1:
00183 AttachmentHandler::saveAs( parentWidget(), name, uid );
00184 break;
00185 default:
00186 break;
00187 }
00188 }
00189
00190 #include "koeventviewer.moc"
|