korganizer

koeventviewer.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include "koeventviewer.h"
26 #include "koglobals.h"
27 #include "urihandler.h"
28 
30 #include <libkcal/calendar.h>
31 #include <libkcal/incidence.h>
32 #include <libkcal/incidenceformatter.h>
33 
34 #include <kdebug.h>
35 #include <tdelocale.h>
36 #include <tdepopupmenu.h>
37 
38 #include <tqcursor.h>
39 #include <tqregexp.h>
40 #include <tqtooltip.h>
41 
42 KOEventViewer::KOEventViewer( Calendar *calendar, TQWidget *parent, const char *name )
43  : TQTextBrowser( parent, name ), mCalendar( calendar ), mDefaultText("")
44 {
45  mIncidence = 0;
46  connect( this, TQ_SIGNAL(highlighted(const TQString &)), TQ_SLOT(message(const TQString &)) );
47 }
48 
49 KOEventViewer::~KOEventViewer()
50 {
51 }
52 
53 void KOEventViewer::message( const TQString &link )
54 {
55  mAttachLink = TQString();
56  if ( link.isEmpty() ) {
57  TQToolTip::remove( this );
58  return;
59  }
60 
61  TQString ttStr;
62  if ( link.startsWith( "kmail:" ) ) {
63  ttStr = i18n( "Open the message in KMail" );
64  } else if ( link.startsWith( "mailto:" ) ) {
65  ttStr = i18n( "Send an email message to %1" ).arg( link.mid( 7 ) );
66  } else if ( link.startsWith( "uid:" ) ) {
67  ttStr = i18n( "Lookup the contact in KAddressbook" );
68  } else if ( link.startsWith( "ATTACH:" ) ) {
69  TQString tmp = link;
70  tmp.remove( TQRegExp( "^ATTACH://" ) );
71  TQString uid = tmp.section( ':', 0, 0 );
72  TQString name = tmp.section( ':', -1, -1 );
73  ttStr = i18n( "View attachment \"%1\"" ).arg( name );
74  mAttachLink = link;
75  } else { // no special URI, let KDE handle it
76  ttStr = i18n( "Launch a viewer on the link" );
77  }
78 
79  TQToolTip::add( this, ttStr );
80 }
81 
82 void KOEventViewer::readSettings( TDEConfig * config )
83 {
84  if ( config ) {
85 // With each restart of KOrganizer the font site gets halfed. What should this
86 // be good for?
87 #if 0
88  config->setGroup( TQString("EventViewer-%1").arg( name() ) );
89  int zoomFactor = config->readNumEntry("ZoomFactor", pointSize() );
90  zoomTo( zoomFactor/2 );
91  kdDebug(5850) << " KOEventViewer: restoring the pointSize: "<< pointSize()
92  << ", zoomFactor: " << zoomFactor << endl;
93 #endif
94  }
95 }
96 
97 void KOEventViewer::writeSettings( TDEConfig * config )
98 {
99  if ( config ) {
100  kdDebug(5850) << " KOEventViewer: saving the zoomFactor: "<< pointSize() << endl;
101  config->setGroup( TQString("EventViewer-%1").arg( name() ) );
102  config->writeEntry("ZoomFactor", pointSize() );
103  }
104 }
105 
106 void KOEventViewer::setSource( const TQString &n )
107 {
108  UriHandler::process( parentWidget(), n );
109 }
110 
111 bool KOEventViewer::appendIncidence( Incidence *incidence, const TQDate &date )
112 {
113  addText( IncidenceFormatter::extensiveDisplayStr( mCalendar, incidence, date ) );
114  return true;
115 }
116 
118 {
119  mCalendar = calendar;
120 }
121 
122 void KOEventViewer::setIncidence( Incidence *incidence, const TQDate &date )
123 {
124  clearEvents();
125  if( incidence ) {
126  appendIncidence( incidence, date );
127  mIncidence = incidence;
128  } else {
129  clearEvents( true );
130  mIncidence = 0;
131  }
132 }
133 
135 {
136  mText = "";
137  if ( now ) setText( mDefaultText );
138 }
139 
140 void KOEventViewer::addText( const TQString &text )
141 {
142  mText.append( text );
143  setText( mText );
144 }
145 
146 void KOEventViewer::setDefaultText( const TQString &text )
147 {
148  mDefaultText = text;
149 }
150 
151 void KOEventViewer::changeIncidenceDisplay( Incidence *incidence, const TQDate &date, int action )
152 {
153  if ( mIncidence && ( incidence->uid() == mIncidence->uid() ) ) {
154  switch ( action ) {
155  case KOGlobals::INCIDENCEEDITED:
156  setIncidence( incidence, date );
157  break;
158  case KOGlobals::INCIDENCEDELETED:
159  setIncidence( 0, date );
160  break;
161  }
162  }
163 }
164 
165 void KOEventViewer::contentsContextMenuEvent( TQContextMenuEvent *e )
166 {
167  TQString name = UriHandler::attachmentNameFromUri( mAttachLink );
168  TQString uid = UriHandler::uidFromUri( mAttachLink );
169  if ( name.isEmpty() || uid.isEmpty() ) {
170  TQTextBrowser::contentsContextMenuEvent( e );
171  return;
172  }
173 
174  TDEPopupMenu *menu = new TDEPopupMenu();
175  menu->insertItem( i18n( "Open Attachment" ), 0 );
176  menu->insertItem( i18n( "Save Attachment As..." ), 1 );
177 
178  switch( menu->exec( TQCursor::pos(), 0 ) ) {
179  case 0: // open
180  AttachmentHandler::view( parentWidget(), name, uid );
181  break;
182  case 1: // save as
183  AttachmentHandler::saveAs( parentWidget(), name, uid );
184  break;
185  default:
186  break;
187  }
188 }
189 
190 #include "koeventviewer.moc"
TQString uid() const
void setIncidence(Incidence *incidence, const TQDate &date)
Show given incidence in viewer.
void clearEvents(bool now=false)
Clear viewer.
void setCalendar(Calendar *calendar)
Set the Calendar associated with this viewer.
void setSource(const TQString &)
Reimplemented from TQTextBrowser to handle links.
void setDefaultText(const TQString &text)
Set the default text that is showed when there aren't a incidence to show.
void addText(const TQString &text)
Add given text to currently shown content.