kmail

urlhandlermanager.cpp
1/*
2 urlhandlermanager.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2002-2003 Klarälvdalens Datakonsult AB
6 Copyright (c) 2003 Marc Mutz <mutz@kde.org>
7
8 KMail is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License, version 2, as
10 published by the Free Software Foundation.
11
12 KMail is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the TQt library by Trolltech AS, Norway (or with modified versions
24 of TQt that use the same license as TQt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 TQt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
30 your version.
31*/
32
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "urlhandlermanager.h"
38
39#include "interfaces/urlhandler.h"
40#include "interfaces/bodyparturlhandler.h"
41#include "partNode.h"
42#include "partnodebodypart.h"
43#include "kmreaderwin.h"
44#include "kmkernel.h"
45#include "callback.h"
46#include "stl_util.h"
47
48#include <tdestandarddirs.h>
49#include <kurldrag.h>
50#include <tdeimproxy.h>
51#include <kurl.h>
52
53#include <algorithm>
54using std::for_each;
55using std::remove;
56using std::find;
57
58KMail::URLHandlerManager * KMail::URLHandlerManager::self = 0;
59
60namespace {
61 class KMailProtocolURLHandler : public KMail::URLHandler {
62 public:
63 KMailProtocolURLHandler() : KMail::URLHandler() {}
64 ~KMailProtocolURLHandler() {}
65
66 bool handleClick( const KURL &, KMReaderWin * ) const;
67 bool handleContextMenuRequest( const KURL & url, const TQPoint &, KMReaderWin * ) const {
68 return url.protocol() == "kmail";
69 }
70 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
71 };
72
73 class ExpandCollapseQuoteURLManager : public KMail::URLHandler {
74 public:
75 ExpandCollapseQuoteURLManager() : KMail::URLHandler() {}
76 ~ExpandCollapseQuoteURLManager() {}
77
78 bool handleClick( const KURL &, KMReaderWin * ) const;
79 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const {
80 return false;
81 }
82 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
83
84 };
85
86 class SMimeURLHandler : public KMail::URLHandler {
87 public:
88 SMimeURLHandler() : KMail::URLHandler() {}
89 ~SMimeURLHandler() {}
90
91 bool handleClick( const KURL &, KMReaderWin * ) const;
92 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const {
93 return false;
94 }
95 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
96 };
97
98 class MailToURLHandler : public KMail::URLHandler {
99 public:
100 MailToURLHandler() : KMail::URLHandler() {}
101 ~MailToURLHandler() {}
102
103 bool handleClick( const KURL &, KMReaderWin * ) const { return false; }
104 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const {
105 return false;
106 }
107 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
108 };
109
110 class HtmlAnchorHandler : public KMail::URLHandler {
111 public:
112 HtmlAnchorHandler() : KMail::URLHandler() {}
113 ~HtmlAnchorHandler() {}
114
115 bool handleClick( const KURL &, KMReaderWin * ) const;
116 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const {
117 return false;
118 }
119 TQString statusBarMessage( const KURL &, KMReaderWin * ) const { return TQString(); }
120 };
121
122 class AttachmentURLHandler : public KMail::URLHandler {
123 public:
124 AttachmentURLHandler() : KMail::URLHandler() {}
125 ~AttachmentURLHandler() {}
126
127 bool handleClick( const KURL &, KMReaderWin * ) const;
128 bool handleShiftClick( const KURL &url, KMReaderWin *window ) const;
129 bool handleDrag( const KURL &url, const TQString& imagePath, KMReaderWin *window ) const;
130 bool willHandleDrag( const KURL &url, const TQString& imagePath, KMReaderWin *window ) const;
131 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const;
132 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
133 private:
134 partNode* partNodeForUrl( const KURL &url, KMReaderWin *w ) const;
135 bool attachmentIsInHeader( const KURL &url ) const;
136 };
137
138 class ShowAuditLogURLHandler : public KMail::URLHandler {
139 public:
140 ShowAuditLogURLHandler() : KMail::URLHandler() {}
141 ~ShowAuditLogURLHandler() {}
142
143 bool handleClick( const KURL &, KMReaderWin * ) const;
144 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const;
145 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
146 };
147
148 // Handler that prevents dragging of internal images added by KMail, such as the envelope image
149 // in the enterprise header
150 class InternalImageURLHandler : public KMail::URLHandler {
151 public:
152 InternalImageURLHandler() : KMail::URLHandler()
153 {}
154 ~InternalImageURLHandler()
155 {}
156 bool handleDrag( const KURL &url, const TQString& imagePath, KMReaderWin *window ) const;
157 bool willHandleDrag( const KURL &url, const TQString& imagePath, KMReaderWin *window ) const;
158 bool handleClick( const KURL &, KMReaderWin * ) const
159 { return false; }
160 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const
161 { return false; }
162 TQString statusBarMessage( const KURL &, KMReaderWin * ) const
163 { return TQString(); }
164 };
165
166 class FallBackURLHandler : public KMail::URLHandler {
167 public:
168 FallBackURLHandler() : KMail::URLHandler() {}
169 ~FallBackURLHandler() {}
170
171 bool handleClick( const KURL &, KMReaderWin * ) const;
172 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const;
173 TQString statusBarMessage( const KURL & url, KMReaderWin * ) const {
174 return url.prettyURL();
175 }
176 };
177
178} // anon namespace
179
180
181//
182//
183// BodyPartURLHandlerManager
184//
185//
186
187class KMail::URLHandlerManager::BodyPartURLHandlerManager : public KMail::URLHandler {
188public:
189 BodyPartURLHandlerManager() : KMail::URLHandler() {}
190 ~BodyPartURLHandlerManager();
191
192 bool handleClick( const KURL &, KMReaderWin * ) const;
193 bool handleContextMenuRequest( const KURL &, const TQPoint &, KMReaderWin * ) const;
194 TQString statusBarMessage( const KURL &, KMReaderWin * ) const;
195
196 void registerHandler( const Interface::BodyPartURLHandler * handler );
197 void unregisterHandler( const Interface::BodyPartURLHandler * handler );
198
199private:
200 typedef TQValueVector<const Interface::BodyPartURLHandler*> BodyPartHandlerList;
201 BodyPartHandlerList mHandlers;
202};
203
204KMail::URLHandlerManager::BodyPartURLHandlerManager::~BodyPartURLHandlerManager() {
205 for_each( mHandlers.begin(), mHandlers.end(),
206 DeleteAndSetToZero<Interface::BodyPartURLHandler>() );
207}
208
209void KMail::URLHandlerManager::BodyPartURLHandlerManager::registerHandler( const Interface::BodyPartURLHandler * handler ) {
210 if ( !handler )
211 return;
212 unregisterHandler( handler ); // don't produce duplicates
213 mHandlers.push_back( handler );
214}
215
216void KMail::URLHandlerManager::BodyPartURLHandlerManager::unregisterHandler( const Interface::BodyPartURLHandler * handler ) {
217 // don't delete them, only remove them from the list!
218 mHandlers.erase( remove( mHandlers.begin(), mHandlers.end(), handler ), mHandlers.end() );
219}
220
221static partNode * partNodeFromXKMailUrl( const KURL & url, KMReaderWin * w, TQString * path ) {
222 assert( path );
223
224 if ( !w || url.protocol() != "x-kmail" )
225 return 0;
226 const TQString urlPath = url.path();
227
228 // urlPath format is: /bodypart/<random number>/<part id>/<path>
229
230 kdDebug( 5006 ) << "BodyPartURLHandler: urlPath == \"" << urlPath << "\"" << endl;
231 if ( !urlPath.startsWith( "/bodypart/" ) )
232 return 0;
233
234 const TQStringList urlParts = TQStringList::split( '/', urlPath.mid( 10 ), true );
235 if ( urlParts.size() != 3 )
236 return 0;
237 bool ok = false;
238 const int part_id = urlParts[1].toInt( &ok );
239 if ( !ok )
240 return 0;
241 *path = KURL::decode_string( urlParts[2] );
242 return w->partNodeForId( part_id );
243}
244
245bool KMail::URLHandlerManager::BodyPartURLHandlerManager::handleClick( const KURL & url, KMReaderWin * w ) const {
246 TQString path;
247 partNode * node = partNodeFromXKMailUrl( url, w, &path );
248 if ( !node )
249 return false;
250 KMMessage *msg = w->message();
251 if ( !msg ) return false;
252 Callback callback( msg, w );
253 KMail::PartNodeBodyPart part( *node, w->overrideCodec() );
254 for ( BodyPartHandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
255 if ( (*it)->handleClick( &part, path, callback ) )
256 return true;
257 return false;
258}
259
260bool KMail::URLHandlerManager::BodyPartURLHandlerManager::handleContextMenuRequest( const KURL & url, const TQPoint & p, KMReaderWin * w ) const {
261 TQString path;
262 partNode * node = partNodeFromXKMailUrl( url, w, &path );
263 if ( !node )
264 return false;
265
266 KMail::PartNodeBodyPart part( *node, w->overrideCodec() );
267 for ( BodyPartHandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
268 if ( (*it)->handleContextMenuRequest( &part, path, p ) )
269 return true;
270 return false;
271}
272
273TQString KMail::URLHandlerManager::BodyPartURLHandlerManager::statusBarMessage( const KURL & url, KMReaderWin * w ) const {
274 TQString path;
275 partNode * node = partNodeFromXKMailUrl( url, w, &path );
276 if ( !node )
277 return TQString();
278
279 KMail::PartNodeBodyPart part( *node, w->overrideCodec() );
280 for ( BodyPartHandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it ) {
281 const TQString msg = (*it)->statusBarMessage( &part, path );
282 if ( !msg.isEmpty() )
283 return msg;
284 }
285 return TQString();
286}
287
288//
289//
290// URLHandlerManager
291//
292//
293
294KMail::URLHandlerManager::URLHandlerManager() {
295 registerHandler( new KMailProtocolURLHandler() );
296 registerHandler( new ExpandCollapseQuoteURLManager() );
297 registerHandler( new SMimeURLHandler() );
298 registerHandler( new MailToURLHandler() );
299 registerHandler( new HtmlAnchorHandler() );
300 registerHandler( new AttachmentURLHandler() );
301 registerHandler( mBodyPartURLHandlerManager = new BodyPartURLHandlerManager() );
302 registerHandler( new ShowAuditLogURLHandler() );
303 registerHandler( new InternalImageURLHandler );
304 registerHandler( new FallBackURLHandler() );
305}
306
307KMail::URLHandlerManager::~URLHandlerManager() {
308 for_each( mHandlers.begin(), mHandlers.end(),
309 DeleteAndSetToZero<URLHandler>() );
310}
311
312void KMail::URLHandlerManager::registerHandler( const URLHandler * handler ) {
313 if ( !handler )
314 return;
315 unregisterHandler( handler ); // don't produce duplicates
316 mHandlers.push_back( handler );
317}
318
319void KMail::URLHandlerManager::unregisterHandler( const URLHandler * handler ) {
320 // don't delete them, only remove them from the list!
321 mHandlers.erase( remove( mHandlers.begin(), mHandlers.end(), handler ), mHandlers.end() );
322}
323
324void KMail::URLHandlerManager::registerHandler( const Interface::BodyPartURLHandler * handler ) {
325 if ( mBodyPartURLHandlerManager )
326 mBodyPartURLHandlerManager->registerHandler( handler );
327}
328
329void KMail::URLHandlerManager::unregisterHandler( const Interface::BodyPartURLHandler * handler ) {
330 if ( mBodyPartURLHandlerManager )
331 mBodyPartURLHandlerManager->unregisterHandler( handler );
332}
333
334bool KMail::URLHandlerManager::handleClick( const KURL & url, KMReaderWin * w ) const {
335 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
336 if ( (*it)->handleClick( url, w ) )
337 return true;
338 return false;
339}
340
341bool KMail::URLHandlerManager::handleShiftClick( const KURL &url, KMReaderWin *window ) const
342{
343 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
344 if ( (*it)->handleShiftClick( url, window ) )
345 return true;
346 return false;
347}
348
349bool KMail::URLHandlerManager::willHandleDrag( const KURL &url, const TQString& imagePath,
350 KMReaderWin *window ) const
351{
352 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
353 if ( (*it)->willHandleDrag( url, imagePath, window ) )
354 return true;
355 return false;
356}
357
358bool KMail::URLHandlerManager::handleDrag( const KURL &url, const TQString& imagePath,
359 KMReaderWin *window ) const
360{
361 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
362 if ( (*it)->handleDrag( url, imagePath, window ) )
363 return true;
364 return false;
365}
366
367bool KMail::URLHandlerManager::handleContextMenuRequest( const KURL & url, const TQPoint & p, KMReaderWin * w ) const {
368 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
369 if ( (*it)->handleContextMenuRequest( url, p, w ) )
370 return true;
371 return false;
372}
373
374TQString KMail::URLHandlerManager::statusBarMessage( const KURL & url, KMReaderWin * w ) const {
375 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it ) {
376 const TQString msg = (*it)->statusBarMessage( url, w );
377 if ( !msg.isEmpty() )
378 return msg;
379 }
380 return TQString();
381}
382
383
384//
385//
386// URLHandler
387//
388//
389
390// these includes are temporary and should not be needed for the code
391// above this line, so they appear only here:
392#include "kmmessage.h"
393#include "kmreaderwin.h"
394#include "partNode.h"
395#include "kmmsgpart.h"
396
397#include <ui/messagebox.h>
398
399#include <tdelocale.h>
400#include <tdeprocess.h>
401#include <tdemessagebox.h>
402#include <tdehtml_part.h>
403
404#include <tqstring.h>
405
406namespace {
407 bool KMailProtocolURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
408 if ( url.protocol() == "kmail" ) {
409 if ( !w )
410 return false;
411
412 if ( url.path() == "showHTML" ) {
413 w->setHtmlOverride( !w->htmlOverride() );
414 w->update( true );
415 return true;
416 }
417
418 if ( url.path() == "loadExternal" ) {
420 w->update( true );
421 return true;
422 }
423
424 if ( url.path() == "goOnline" ) {
425 kmkernel->resumeNetworkJobs();
426 return true;
427 }
428
429 if ( url.path() == "decryptMessage" ) {
431 w->update( true );
432 return true;
433 }
434
435 if ( url.path() == "showSignatureDetails" ) {
436 w->setShowSignatureDetails( true );
437 w->update( true );
438 return true;
439 }
440
441 if ( url.path() == "hideSignatureDetails" ) {
442 w->setShowSignatureDetails( false );
443 w->update( true );
444 return true;
445 }
446
447 if ( url.path() == "showAttachmentQuicklist" ) {
449 w->setShowAttachmentQuicklist( true );
450 w->update( true );
451 return true;
452 }
453
454 if ( url.path() == "hideAttachmentQuicklist" ) {
456 w->setShowAttachmentQuicklist( false );
457 w->update( true );
458 return true;
459 }
460
461 if ( url.path() == "showRawToltecMail" ) {
463 w->setShowRawToltecMail( true );
464 w->update( true );
465 return true;
466 }
467
468// if ( url.path() == "startIMApp" )
469// {
470// kmkernel->imProxy()->startPreferredApp();
471// return true;
472// }
473// //FIXME: handle startIMApp urls in their own handler, or rename this one
474 }
475 return false;
476 }
477
478 TQString KMailProtocolURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
479 if ( url.protocol() == "kmail" )
480 {
481 if ( url.path() == "showHTML" )
482 return i18n("Turn on HTML rendering for this message.");
483 if ( url.path() == "loadExternal" )
484 return i18n("Load external references from the Internet for this message.");
485 if ( url.path() == "goOnline" )
486 return i18n("Work online.");
487 if ( url.path() == "decryptMessage" )
488 return i18n("Decrypt message.");
489 if ( url.path() == "showSignatureDetails" )
490 return i18n("Show signature details.");
491 if ( url.path() == "hideSignatureDetails" )
492 return i18n("Hide signature details.");
493 if ( url.path() == "hideAttachmentQuicklist" )
494 return i18n( "Hide attachment list" );
495 if ( url.path() == "showAttachmentQuicklist" )
496 return i18n( "Show attachment list" );
497 }
498 return TQString() ;
499 }
500}
501
502namespace {
503
504 bool ExpandCollapseQuoteURLManager::handleClick(
505 const KURL & url, KMReaderWin * w ) const
506 {
507 // kmail:levelquote/?num -> the level quote to collapse.
508 // kmail:levelquote/?-num -> expand all levels quote.
509 if ( url.protocol() == "kmail" && url.path()=="levelquote" )
510 {
511 TQString levelStr= url.query().mid( 1,url.query().length() );
512 bool isNumber;
513 int levelQuote= levelStr.toInt(&isNumber);
514 if ( isNumber )
515 w->slotLevelQuote( levelQuote );
516 return true;
517 }
518 return false;
519 }
520 TQString ExpandCollapseQuoteURLManager::statusBarMessage(
521 const KURL & url, KMReaderWin * ) const
522 {
523 if ( url.protocol() == "kmail" && url.path() == "levelquote" )
524 {
525 TQString query= url.query();
526 if ( query.length()>=2 ) {
527 if ( query[ 1 ] =='-' ) {
528 return i18n("Expand all quoted text.");
529 }
530 else {
531 return i18n("Collapse quoted text.");
532 }
533 }
534 }
535 return TQString() ;
536 }
537
538}
539
540// defined in kmreaderwin.cpp...
541extern bool foundSMIMEData( const TQString aUrl, TQString & displayName,
542 TQString & libName, TQString & keyId );
543
544namespace {
545 bool SMimeURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
546 if ( !url.hasRef() )
547 return false;
548 TQString displayName, libName, keyId;
549 if ( !foundSMIMEData( url.path() + '#' + url.ref(), displayName, libName, keyId ) )
550 return false;
551 TDEProcess cmp;
552 cmp << "kleopatra" << "-query" << keyId;
553 if ( !cmp.start( TDEProcess::DontCare ) )
554 KMessageBox::error( w, i18n("Could not start certificate manager. "
555 "Please check your installation."),
556 i18n("KMail Error") );
557 return true;
558 }
559
560 TQString SMimeURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
561 TQString displayName, libName, keyId;
562 if ( !foundSMIMEData( url.path() + '#' + url.ref(), displayName, libName, keyId ) )
563 return TQString();
564 return i18n("Show certificate 0x%1").arg( keyId );
565 }
566}
567
568namespace {
569 bool HtmlAnchorHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
570 if ( url.hasHost() || url.path() != "/" || !url.hasRef() )
571 return false;
572 if ( w && !w->htmlPart()->gotoAnchor( url.ref() ) )
573 static_cast<TQScrollView*>( w->htmlPart()->widget() )->ensureVisible( 0, 0 );
574 return true;
575 }
576}
577
578namespace {
579 TQString MailToURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
580 if ( url.protocol() != "mailto" )
581 return TQString();
582 return KMMessage::decodeMailtoUrl( url.url() );
583 }
584}
585
586namespace {
587
588 partNode* AttachmentURLHandler::partNodeForUrl( const KURL &url, KMReaderWin *w ) const
589 {
590 if ( !w || !w->message() )
591 return 0;
592 if ( url.protocol() != "attachment" )
593 return 0;
594
595 bool ok;
596 int nodeId = url.path().toInt( &ok );
597 if ( !ok )
598 return 0;
599
600 partNode * node = w->partNodeForId( nodeId );
601 return node;
602 }
603
604 bool AttachmentURLHandler::attachmentIsInHeader( const KURL &url ) const
605 {
606 bool inHeader = false;
607 const TQString place = url.queryItem( "place" ).lower();
608 if ( place != TQString() ) {
609 inHeader = ( place == "header" );
610 }
611 return inHeader;
612 }
613
614 bool AttachmentURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const
615 {
616 partNode * node = partNodeForUrl( url, w );
617 if ( !node )
618 return false;
619
620 const bool inHeader = attachmentIsInHeader( url );
621 const bool shouldShowDialog = !node->isDisplayedEmbedded() || !inHeader;
622 if ( inHeader )
623 w->scrollToAttachment( node );
624 if ( shouldShowDialog )
625 w->openAttachment( node->nodeId(), w->tempFileUrlFromPartNode( node ).path() );
626 return true;
627 }
628
629 bool AttachmentURLHandler::handleShiftClick( const KURL &url, KMReaderWin *window ) const
630 {
631 partNode * node = partNodeForUrl( url, window );
632 if ( !node )
633 return false;
634 if ( !window )
635 return false;
636 window->saveAttachment( window->tempFileUrlFromPartNode( node ) );
637 return true;
638 }
639
640 bool AttachmentURLHandler::willHandleDrag( const KURL &url, const TQString& imagePath,
641 KMReaderWin *window ) const
642 {
643 Q_UNUSED( imagePath );
644 return partNodeForUrl( url, window ) != 0;
645 }
646
647 bool AttachmentURLHandler::handleDrag( const KURL &url, const TQString& imagePath,
648 KMReaderWin *window ) const
649 {
650 Q_UNUSED( imagePath );
651 const partNode * node = partNodeForUrl( url, window );
652 if ( !node )
653 return false;
654
655 KURL file = window->tempFileUrlFromPartNode( node ).path();
656 if ( !file.isEmpty() ) {
657 TQString icon = node->msgPart().iconName( TDEIcon::Small );
658 KURLDrag* urlDrag = new KURLDrag( file, window );
659 if ( !icon.isEmpty() ) {
660 TQPixmap iconMap( icon );
661 urlDrag->setPixmap( iconMap );
662 }
663 urlDrag->drag();
664 return true;
665 }
666 else {
667 return false;
668 }
669 }
670
671 bool AttachmentURLHandler::handleContextMenuRequest( const KURL & url, const TQPoint & p, KMReaderWin * w ) const
672 {
673 partNode * node = partNodeForUrl( url, w );
674 if ( !node )
675 return false;
676
677 w->showAttachmentPopup( node->nodeId(), w->tempFileUrlFromPartNode( node ).path(), p );
678 return true;
679 }
680
681 TQString AttachmentURLHandler::statusBarMessage( const KURL & url, KMReaderWin * w ) const
682 {
683 partNode * node = partNodeForUrl( url, w );
684 if ( !node )
685 return TQString();
686
687 const KMMessagePart & msgPart = node->msgPart();
688 TQString name = msgPart.fileName();
689 if ( name.isEmpty() )
690 name = msgPart.name();
691 if ( !name.isEmpty() )
692 return i18n( "Attachment: %1" ).arg( name );
693 return i18n( "Attachment #%1 (unnamed)" ).arg( KMReaderWin::msgPartFromUrl( url ) );
694 }
695}
696
697namespace {
698 static TQString extractAuditLog( const KURL & url ) {
699 if ( url.protocol() != "kmail" || url.path() != "showAuditLog" )
700 return TQString();
701 assert( !url.queryItem( "log" ).isEmpty() );
702 return url.queryItem( "log" );
703 }
704
705 bool ShowAuditLogURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
706 const TQString auditLog = extractAuditLog( url );
707 if ( auditLog.isEmpty() )
708 return false;
709 Kleo::MessageBox::auditLog( w, auditLog );
710 return true;
711 }
712
713 bool ShowAuditLogURLHandler::handleContextMenuRequest( const KURL & url, const TQPoint &, KMReaderWin * w ) const
714 {
715 Q_UNUSED( w );
716 // disable RMB for my own links:
717 return !extractAuditLog( url ).isEmpty();
718 }
719
720 TQString ShowAuditLogURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
721 if ( extractAuditLog( url ).isEmpty() )
722 return TQString();
723 else
724 return i18n("Show GnuPG Audit Log for this operation");
725 }
726}
727
728namespace {
729 bool InternalImageURLHandler::handleDrag( const KURL &url, const TQString& imagePath,
730 KMReaderWin *window ) const
731 {
732 Q_UNUSED( window );
733 Q_UNUSED( url );
734 const TQString kmailImagePath = locate( "data", "kmail/pics/" );
735 if ( imagePath.contains( kmailImagePath ) ) {
736 // Do nothing, don't start a drag
737 return true;
738 }
739 return false;
740 }
741
742 bool InternalImageURLHandler::willHandleDrag( const KURL &url, const TQString& imagePath,
743 KMReaderWin *window ) const
744 {
745 Q_UNUSED( window );
746 Q_UNUSED( url );
747 const TQString kmailImagePath = locate( "data", "kmail/pics/" );
748 return imagePath.contains( kmailImagePath );
749 }
750}
751
752namespace {
753 bool FallBackURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
754 if ( w )
755 w->emitUrlClicked( url, TQt::LeftButton );
756 return true;
757 }
758
759 bool FallBackURLHandler::handleContextMenuRequest( const KURL & url, const TQPoint & p, KMReaderWin * w ) const {
760 if ( w )
761 w->emitPopupMenu( url, p );
762 return true;
763 }
764}
This is a Mime Message.
Definition: kmmessage.h:68
static TQString decodeMailtoUrl(const TQString &url)
Decodes a mailto URL.
Definition: kmmessage.cpp:3473
This class implements a "reader window", that is a window used for reading or viewing messages.
Definition: kmreaderwin.h:75
void setDecryptMessageOverwrite(bool overwrite=true)
Enforce message decryption.
Definition: kmreaderwin.h:326
const TQTextCodec * overrideCodec() const
Get codec corresponding to the currently selected override character encoding.
void setShowSignatureDetails(bool showDetails=true)
Show signature details.
Definition: kmreaderwin.h:332
KMMessage * message(KMFolder **folder=0) const
Returns the current message or 0 if none.
bool htmlLoadExtOverride() const
Get the load external references override setting.
Definition: kmreaderwin.h:203
void scrollToAttachment(const partNode *node)
Scrolls to the given attachment and marks it with a yellow border.
static int msgPartFromUrl(const KURL &url)
Returns id of message part from given URL or -1 if invalid.
TDEHTMLPart * htmlPart() const
Access to the TDEHTMLPart used for the viewer.
Definition: kmreaderwin.h:297
void setHtmlLoadExtOverride(bool loadExtOverride)
Override default load external references setting.
void saveRelativePosition()
Saves the relative position of the scroll view.
bool htmlOverride() const
Override default html mail setting.
Definition: kmreaderwin.h:199
void update(KMail::Interface::Observable *)
an implemenation of the BodyPart interface using partNodes
Singleton to manage the list of URLHandlers.
An interface to reader link handlers.
Definition: urlhandler.h:49
virtual bool handleClick(const KURL &url, KMReaderWin *w) const =0
Called when LMB-clicking on a link in the reader.
virtual bool handleDrag(const KURL &url, const TQString &imagePath, KMReaderWin *window) const
Called when starting a drag with the given URL.
Definition: urlhandler.h:87
virtual bool handleContextMenuRequest(const KURL &url, const TQPoint &p, KMReaderWin *w) const =0
Called when RMB-clicking on a link in the reader.
virtual bool handleShiftClick(const KURL &url, KMReaderWin *window) const
Called when shift-clicking the link in the reader.
Definition: urlhandler.h:65
virtual TQString statusBarMessage(const KURL &url, KMReaderWin *w) const =0
Called when hovering over a link.
virtual bool willHandleDrag(const KURL &url, const TQString &imagePath, KMReaderWin *window) const
Definition: urlhandler.h:74
folderdiaquotatab.h
Definition: aboutdata.cpp:40