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
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036
00037 #include "urlhandlermanager.h"
00038
00039 #include "interfaces/urlhandler.h"
00040 #include "interfaces/bodyparturlhandler.h"
00041 #include "partNode.h"
00042 #include "partnodebodypart.h"
00043 #include "kmreaderwin.h"
00044 #include "kmkernel.h"
00045 #include "callback.h"
00046 #include "stl_util.h"
00047
00048 #include <kstandarddirs.h>
00049 #include <kurldrag.h>
00050 #include <kimproxy.h>
00051 #include <kurl.h>
00052
00053 #include <algorithm>
00054 using std::for_each;
00055 using std::remove;
00056 using std::find;
00057
00058 KMail::URLHandlerManager * KMail::URLHandlerManager::self = 0;
00059
00060 namespace {
00061 class KMailProtocolURLHandler : public KMail::URLHandler {
00062 public:
00063 KMailProtocolURLHandler() : KMail::URLHandler() {}
00064 ~KMailProtocolURLHandler() {}
00065
00066 bool handleClick( const KURL &, KMReaderWin * ) const;
00067 bool handleContextMenuRequest( const KURL & url, const QPoint &, KMReaderWin * ) const {
00068 return url.protocol() == "kmail";
00069 }
00070 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00071 };
00072
00073 class ExpandCollapseQuoteURLManager : public KMail::URLHandler {
00074 public:
00075 ExpandCollapseQuoteURLManager() : KMail::URLHandler() {}
00076 ~ExpandCollapseQuoteURLManager() {}
00077
00078 bool handleClick( const KURL &, KMReaderWin * ) const;
00079 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const {
00080 return false;
00081 }
00082 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00083
00084 };
00085
00086 class SMimeURLHandler : public KMail::URLHandler {
00087 public:
00088 SMimeURLHandler() : KMail::URLHandler() {}
00089 ~SMimeURLHandler() {}
00090
00091 bool handleClick( const KURL &, KMReaderWin * ) const;
00092 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const {
00093 return false;
00094 }
00095 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00096 };
00097
00098 class MailToURLHandler : public KMail::URLHandler {
00099 public:
00100 MailToURLHandler() : KMail::URLHandler() {}
00101 ~MailToURLHandler() {}
00102
00103 bool handleClick( const KURL &, KMReaderWin * ) const { return false; }
00104 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const {
00105 return false;
00106 }
00107 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00108 };
00109
00110 class HtmlAnchorHandler : public KMail::URLHandler {
00111 public:
00112 HtmlAnchorHandler() : KMail::URLHandler() {}
00113 ~HtmlAnchorHandler() {}
00114
00115 bool handleClick( const KURL &, KMReaderWin * ) const;
00116 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const {
00117 return false;
00118 }
00119 QString statusBarMessage( const KURL &, KMReaderWin * ) const { return QString::null; }
00120 };
00121
00122 class AttachmentURLHandler : public KMail::URLHandler {
00123 public:
00124 AttachmentURLHandler() : KMail::URLHandler() {}
00125 ~AttachmentURLHandler() {}
00126
00127 bool handleClick( const KURL &, KMReaderWin * ) const;
00128 bool handleShiftClick( const KURL &url, KMReaderWin *window ) const;
00129 bool handleDrag( const KURL &url, KMReaderWin *window ) const;
00130 bool willHandleDrag( const KURL &url, KMReaderWin *window ) const;
00131 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const;
00132 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00133 private:
00134 partNode* partNodeForUrl( const KURL &url, KMReaderWin *w ) const;
00135 bool attachmentIsInHeader( const KURL &url ) const;
00136 };
00137
00138 class ShowAuditLogURLHandler : public KMail::URLHandler {
00139 public:
00140 ShowAuditLogURLHandler() : KMail::URLHandler() {}
00141 ~ShowAuditLogURLHandler() {}
00142
00143 bool handleClick( const KURL &, KMReaderWin * ) const;
00144 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const;
00145 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00146 };
00147
00148
00149
00150 class InternalImageURLHandler : public KMail::URLHandler {
00151 public:
00152 InternalImageURLHandler() : KMail::URLHandler()
00153 {}
00154 ~InternalImageURLHandler()
00155 {}
00156 bool handleDrag( const KURL &url, KMReaderWin *window ) const;
00157 bool willHandleDrag( const KURL &url, KMReaderWin *window ) const;
00158 bool handleClick( const KURL &, KMReaderWin * ) const
00159 { return false; }
00160 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const
00161 { return false; }
00162 QString statusBarMessage( const KURL &, KMReaderWin * ) const
00163 { return QString(); }
00164 };
00165
00166 class FallBackURLHandler : public KMail::URLHandler {
00167 public:
00168 FallBackURLHandler() : KMail::URLHandler() {}
00169 ~FallBackURLHandler() {}
00170
00171 bool handleClick( const KURL &, KMReaderWin * ) const;
00172 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const;
00173 QString statusBarMessage( const KURL & url, KMReaderWin * ) const {
00174 return url.prettyURL();
00175 }
00176 };
00177
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187 class KMail::URLHandlerManager::BodyPartURLHandlerManager : public KMail::URLHandler {
00188 public:
00189 BodyPartURLHandlerManager() : KMail::URLHandler() {}
00190 ~BodyPartURLHandlerManager();
00191
00192 bool handleClick( const KURL &, KMReaderWin * ) const;
00193 bool handleContextMenuRequest( const KURL &, const QPoint &, KMReaderWin * ) const;
00194 QString statusBarMessage( const KURL &, KMReaderWin * ) const;
00195
00196 void registerHandler( const Interface::BodyPartURLHandler * handler );
00197 void unregisterHandler( const Interface::BodyPartURLHandler * handler );
00198
00199 private:
00200 typedef QValueVector<const Interface::BodyPartURLHandler*> BodyPartHandlerList;
00201 BodyPartHandlerList mHandlers;
00202 };
00203
00204 KMail::URLHandlerManager::BodyPartURLHandlerManager::~BodyPartURLHandlerManager() {
00205 for_each( mHandlers.begin(), mHandlers.end(),
00206 DeleteAndSetToZero<Interface::BodyPartURLHandler>() );
00207 }
00208
00209 void KMail::URLHandlerManager::BodyPartURLHandlerManager::registerHandler( const Interface::BodyPartURLHandler * handler ) {
00210 if ( !handler )
00211 return;
00212 unregisterHandler( handler );
00213 mHandlers.push_back( handler );
00214 }
00215
00216 void KMail::URLHandlerManager::BodyPartURLHandlerManager::unregisterHandler( const Interface::BodyPartURLHandler * handler ) {
00217
00218 mHandlers.erase( remove( mHandlers.begin(), mHandlers.end(), handler ), mHandlers.end() );
00219 }
00220
00221 static partNode * partNodeFromXKMailUrl( const KURL & url, KMReaderWin * w, QString * path ) {
00222 assert( path );
00223
00224 if ( !w || url.protocol() != "x-kmail" )
00225 return 0;
00226 const QString urlPath = url.path();
00227
00228
00229
00230 kdDebug( 5006 ) << "BodyPartURLHandler: urlPath == \"" << urlPath << "\"" << endl;
00231 if ( !urlPath.startsWith( "/bodypart/" ) )
00232 return 0;
00233
00234 const QStringList urlParts = QStringList::split( '/', urlPath.mid( 10 ), true );
00235 if ( urlParts.size() != 3 )
00236 return 0;
00237 bool ok = false;
00238 const int part_id = urlParts[1].toInt( &ok );
00239 if ( !ok )
00240 return 0;
00241 *path = KURL::decode_string( urlParts[2] );
00242 return w->partNodeForId( part_id );
00243 }
00244
00245 bool KMail::URLHandlerManager::BodyPartURLHandlerManager::handleClick( const KURL & url, KMReaderWin * w ) const {
00246 QString path;
00247 partNode * node = partNodeFromXKMailUrl( url, w, &path );
00248 if ( !node )
00249 return false;
00250 KMMessage *msg = w->message();
00251 if ( !msg ) return false;
00252 Callback callback( msg, w );
00253 KMail::PartNodeBodyPart part( *node, w->overrideCodec() );
00254 for ( BodyPartHandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00255 if ( (*it)->handleClick( &part, path, callback ) )
00256 return true;
00257 return false;
00258 }
00259
00260 bool KMail::URLHandlerManager::BodyPartURLHandlerManager::handleContextMenuRequest( const KURL & url, const QPoint & p, KMReaderWin * w ) const {
00261 QString path;
00262 partNode * node = partNodeFromXKMailUrl( url, w, &path );
00263 if ( !node )
00264 return false;
00265
00266 KMail::PartNodeBodyPart part( *node, w->overrideCodec() );
00267 for ( BodyPartHandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00268 if ( (*it)->handleContextMenuRequest( &part, path, p ) )
00269 return true;
00270 return false;
00271 }
00272
00273 QString KMail::URLHandlerManager::BodyPartURLHandlerManager::statusBarMessage( const KURL & url, KMReaderWin * w ) const {
00274 QString path;
00275 partNode * node = partNodeFromXKMailUrl( url, w, &path );
00276 if ( !node )
00277 return QString::null;
00278
00279 KMail::PartNodeBodyPart part( *node, w->overrideCodec() );
00280 for ( BodyPartHandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it ) {
00281 const QString msg = (*it)->statusBarMessage( &part, path );
00282 if ( !msg.isEmpty() )
00283 return msg;
00284 }
00285 return QString::null;
00286 }
00287
00288
00289
00290
00291
00292
00293
00294 KMail::URLHandlerManager::URLHandlerManager() {
00295 registerHandler( new KMailProtocolURLHandler() );
00296 registerHandler( new ExpandCollapseQuoteURLManager() );
00297 registerHandler( new SMimeURLHandler() );
00298 registerHandler( new MailToURLHandler() );
00299 registerHandler( new HtmlAnchorHandler() );
00300 registerHandler( new AttachmentURLHandler() );
00301 registerHandler( mBodyPartURLHandlerManager = new BodyPartURLHandlerManager() );
00302 registerHandler( new ShowAuditLogURLHandler() );
00303 registerHandler( new InternalImageURLHandler );
00304 registerHandler( new FallBackURLHandler() );
00305 }
00306
00307 KMail::URLHandlerManager::~URLHandlerManager() {
00308 for_each( mHandlers.begin(), mHandlers.end(),
00309 DeleteAndSetToZero<URLHandler>() );
00310 }
00311
00312 void KMail::URLHandlerManager::registerHandler( const URLHandler * handler ) {
00313 if ( !handler )
00314 return;
00315 unregisterHandler( handler );
00316 mHandlers.push_back( handler );
00317 }
00318
00319 void KMail::URLHandlerManager::unregisterHandler( const URLHandler * handler ) {
00320
00321 mHandlers.erase( remove( mHandlers.begin(), mHandlers.end(), handler ), mHandlers.end() );
00322 }
00323
00324 void KMail::URLHandlerManager::registerHandler( const Interface::BodyPartURLHandler * handler ) {
00325 if ( mBodyPartURLHandlerManager )
00326 mBodyPartURLHandlerManager->registerHandler( handler );
00327 }
00328
00329 void KMail::URLHandlerManager::unregisterHandler( const Interface::BodyPartURLHandler * handler ) {
00330 if ( mBodyPartURLHandlerManager )
00331 mBodyPartURLHandlerManager->unregisterHandler( handler );
00332 }
00333
00334 bool KMail::URLHandlerManager::handleClick( const KURL & url, KMReaderWin * w ) const {
00335 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00336 if ( (*it)->handleClick( url, w ) )
00337 return true;
00338 return false;
00339 }
00340
00341 bool KMail::URLHandlerManager::handleShiftClick( const KURL &url, KMReaderWin *window ) const
00342 {
00343 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00344 if ( (*it)->handleShiftClick( url, window ) )
00345 return true;
00346 return false;
00347 }
00348
00349 bool KMail::URLHandlerManager::willHandleDrag( const KURL &url, KMReaderWin *window ) const
00350 {
00351 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00352 if ( (*it)->willHandleDrag( url, window ) )
00353 return true;
00354 return false;
00355 }
00356
00357 bool KMail::URLHandlerManager::handleDrag( const KURL &url, KMReaderWin *window ) const
00358 {
00359 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00360 if ( (*it)->handleDrag( url, window ) )
00361 return true;
00362 return false;
00363 }
00364
00365 bool KMail::URLHandlerManager::handleContextMenuRequest( const KURL & url, const QPoint & p, KMReaderWin * w ) const {
00366 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it )
00367 if ( (*it)->handleContextMenuRequest( url, p, w ) )
00368 return true;
00369 return false;
00370 }
00371
00372 QString KMail::URLHandlerManager::statusBarMessage( const KURL & url, KMReaderWin * w ) const {
00373 for ( HandlerList::const_iterator it = mHandlers.begin() ; it != mHandlers.end() ; ++it ) {
00374 const QString msg = (*it)->statusBarMessage( url, w );
00375 if ( !msg.isEmpty() )
00376 return msg;
00377 }
00378 return QString::null;
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 #include "kmmessage.h"
00391 #include "kmreaderwin.h"
00392 #include "partNode.h"
00393 #include "kmmsgpart.h"
00394
00395 #include <ui/messagebox.h>
00396
00397 #include <klocale.h>
00398 #include <kprocess.h>
00399 #include <kmessagebox.h>
00400 #include <khtml_part.h>
00401
00402 #include <qstring.h>
00403
00404 namespace {
00405 bool KMailProtocolURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
00406 if ( url.protocol() == "kmail" ) {
00407 if ( !w )
00408 return false;
00409
00410 if ( url.path() == "showHTML" ) {
00411 w->setHtmlOverride( !w->htmlOverride() );
00412 w->update( true );
00413 return true;
00414 }
00415
00416 if ( url.path() == "loadExternal" ) {
00417 w->setHtmlLoadExtOverride( !w->htmlLoadExtOverride() );
00418 w->update( true );
00419 return true;
00420 }
00421
00422 if ( url.path() == "goOnline" ) {
00423 kmkernel->resumeNetworkJobs();
00424 return true;
00425 }
00426
00427 if ( url.path() == "decryptMessage" ) {
00428 w->setDecryptMessageOverwrite( true );
00429 w->update( true );
00430 return true;
00431 }
00432
00433 if ( url.path() == "showSignatureDetails" ) {
00434 w->setShowSignatureDetails( true );
00435 w->update( true );
00436 return true;
00437 }
00438
00439 if ( url.path() == "hideSignatureDetails" ) {
00440 w->setShowSignatureDetails( false );
00441 w->update( true );
00442 return true;
00443 }
00444
00445 if ( url.path() == "showAttachmentQuicklist" ) {
00446 w->saveRelativePosition();
00447 w->setShowAttachmentQuicklist( true );
00448 w->update( true );
00449 return true;
00450 }
00451
00452 if ( url.path() == "hideAttachmentQuicklist" ) {
00453 w->saveRelativePosition();
00454 w->setShowAttachmentQuicklist( false );
00455 w->update( true );
00456 return true;
00457 }
00458
00459 if ( url.path() == "showRawToltecMail" ) {
00460 w->saveRelativePosition();
00461 w->setShowRawToltecMail( true );
00462 w->update( true );
00463 return true;
00464 }
00465
00466
00467
00468
00469
00470
00471
00472 }
00473 return false;
00474 }
00475
00476 QString KMailProtocolURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
00477 if ( url.protocol() == "kmail" )
00478 {
00479 if ( url.path() == "showHTML" )
00480 return i18n("Turn on HTML rendering for this message.");
00481 if ( url.path() == "loadExternal" )
00482 return i18n("Load external references from the Internet for this message.");
00483 if ( url.path() == "goOnline" )
00484 return i18n("Work online.");
00485 if ( url.path() == "decryptMessage" )
00486 return i18n("Decrypt message.");
00487 if ( url.path() == "showSignatureDetails" )
00488 return i18n("Show signature details.");
00489 if ( url.path() == "hideSignatureDetails" )
00490 return i18n("Hide signature details.");
00491 if ( url.path() == "hideAttachmentQuicklist" )
00492 return i18n( "Hide attachment list" );
00493 if ( url.path() == "showAttachmentQuicklist" )
00494 return i18n( "Show attachment list" );
00495 }
00496 return QString::null ;
00497 }
00498 }
00499
00500 namespace {
00501
00502 bool ExpandCollapseQuoteURLManager::handleClick(
00503 const KURL & url, KMReaderWin * w ) const
00504 {
00505
00506
00507 if ( url.protocol() == "kmail" && url.path()=="levelquote" )
00508 {
00509 QString levelStr= url.query().mid( 1,url.query().length() );
00510 bool isNumber;
00511 int levelQuote= levelStr.toInt(&isNumber);
00512 if ( isNumber )
00513 w->slotLevelQuote( levelQuote );
00514 return true;
00515 }
00516 return false;
00517 }
00518 QString ExpandCollapseQuoteURLManager::statusBarMessage(
00519 const KURL & url, KMReaderWin * ) const
00520 {
00521 if ( url.protocol() == "kmail" && url.path() == "levelquote" )
00522 {
00523 QString query= url.query();
00524 if ( query.length()>=2 ) {
00525 if ( query[ 1 ] =='-' ) {
00526 return i18n("Expand all quoted text.");
00527 }
00528 else {
00529 return i18n("Collapse quoted text.");
00530 }
00531 }
00532 }
00533 return QString::null ;
00534 }
00535
00536 }
00537
00538
00539 extern bool foundSMIMEData( const QString aUrl, QString & displayName,
00540 QString & libName, QString & keyId );
00541
00542 namespace {
00543 bool SMimeURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
00544 if ( !url.hasRef() )
00545 return false;
00546 QString displayName, libName, keyId;
00547 if ( !foundSMIMEData( url.path() + '#' + url.ref(), displayName, libName, keyId ) )
00548 return false;
00549 KProcess cmp;
00550 cmp << "kleopatra" << "-query" << keyId;
00551 if ( !cmp.start( KProcess::DontCare ) )
00552 KMessageBox::error( w, i18n("Could not start certificate manager. "
00553 "Please check your installation."),
00554 i18n("KMail Error") );
00555 return true;
00556 }
00557
00558 QString SMimeURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
00559 QString displayName, libName, keyId;
00560 if ( !foundSMIMEData( url.path() + '#' + url.ref(), displayName, libName, keyId ) )
00561 return QString::null;
00562 return i18n("Show certificate 0x%1").arg( keyId );
00563 }
00564 }
00565
00566 namespace {
00567 bool HtmlAnchorHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
00568 if ( url.hasHost() || url.path() != "/" || !url.hasRef() )
00569 return false;
00570 if ( w && !w->htmlPart()->gotoAnchor( url.ref() ) )
00571 static_cast<QScrollView*>( w->htmlPart()->widget() )->ensureVisible( 0, 0 );
00572 return true;
00573 }
00574 }
00575
00576 namespace {
00577 QString MailToURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
00578 if ( url.protocol() != "mailto" )
00579 return QString::null;
00580 return KMMessage::decodeMailtoUrl( url.url() );
00581 }
00582 }
00583
00584 namespace {
00585
00586 partNode* AttachmentURLHandler::partNodeForUrl( const KURL &url, KMReaderWin *w ) const
00587 {
00588 if ( !w || !w->message() )
00589 return 0;
00590 if ( url.protocol() != "attachment" )
00591 return 0;
00592
00593 bool ok;
00594 int nodeId = url.path().toInt( &ok );
00595 if ( !ok )
00596 return 0;
00597
00598 partNode * node = w->partNodeForId( nodeId );
00599 return node;
00600 }
00601
00602 bool AttachmentURLHandler::attachmentIsInHeader( const KURL &url ) const
00603 {
00604 bool inHeader = false;
00605 const QString place = url.queryItem( "place" ).lower();
00606 if ( place != QString::null ) {
00607 inHeader = ( place == "header" );
00608 }
00609 return inHeader;
00610 }
00611
00612 bool AttachmentURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const
00613 {
00614 partNode * node = partNodeForUrl( url, w );
00615 if ( !node )
00616 return false;
00617
00618 const bool inHeader = attachmentIsInHeader( url );
00619 const bool shouldShowDialog = !node->isDisplayedEmbedded() || !inHeader;
00620 if ( inHeader )
00621 w->scrollToAttachment( node );
00622 if ( shouldShowDialog )
00623 w->openAttachment( node->nodeId(), w->tempFileUrlFromPartNode( node ).path() );
00624 return true;
00625 }
00626
00627 bool AttachmentURLHandler::handleShiftClick( const KURL &url, KMReaderWin *window ) const
00628 {
00629 partNode * node = partNodeForUrl( url, window );
00630 if ( !node )
00631 return false;
00632 if ( !window )
00633 return false;
00634 window->saveAttachment( window->tempFileUrlFromPartNode( node ) );
00635 return true;
00636 }
00637
00638 bool AttachmentURLHandler::willHandleDrag( const KURL &url, KMReaderWin *window ) const
00639 {
00640 return partNodeForUrl( url, window ) != 0;
00641 }
00642
00643 bool AttachmentURLHandler::handleDrag( const KURL &url, KMReaderWin *window ) const
00644 {
00645 partNode * node = partNodeForUrl( url, window );
00646 if ( !node )
00647 return false;
00648
00649 KURL file = window->tempFileUrlFromPartNode( node ).path();
00650 if ( !file.isEmpty() ) {
00651 QString icon = node->msgPart().iconName( KIcon::Small );
00652 KURLDrag* urlDrag = new KURLDrag( file, window );
00653 if ( !icon.isEmpty() ) {
00654 QPixmap iconMap( icon );
00655 urlDrag->setPixmap( iconMap );
00656 }
00657 urlDrag->drag();
00658 return true;
00659 }
00660 else
00661 return false;
00662 }
00663
00664 bool AttachmentURLHandler::handleContextMenuRequest( const KURL & url, const QPoint & p, KMReaderWin * w ) const
00665 {
00666 partNode * node = partNodeForUrl( url, w );
00667 if ( !node )
00668 return false;
00669
00670 w->showAttachmentPopup( node->nodeId(), w->tempFileUrlFromPartNode( node ).path(), p );
00671 return true;
00672 }
00673
00674 QString AttachmentURLHandler::statusBarMessage( const KURL & url, KMReaderWin * w ) const
00675 {
00676 partNode * node = partNodeForUrl( url, w );
00677 if ( !node )
00678 return QString::null;
00679
00680 const KMMessagePart & msgPart = node->msgPart();
00681 QString name = msgPart.fileName();
00682 if ( name.isEmpty() )
00683 name = msgPart.name();
00684 if ( !name.isEmpty() )
00685 return i18n( "Attachment: %1" ).arg( name );
00686 return i18n( "Attachment #%1 (unnamed)" ).arg( KMReaderWin::msgPartFromUrl( url ) );
00687 }
00688 }
00689
00690 namespace {
00691 static QString extractAuditLog( const KURL & url ) {
00692 if ( url.protocol() != "kmail" || url.path() != "showAuditLog" )
00693 return QString();
00694 assert( !url.queryItem( "log" ).isEmpty() );
00695 return url.queryItem( "log" );
00696 }
00697
00698 bool ShowAuditLogURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
00699 const QString auditLog = extractAuditLog( url );
00700 if ( auditLog.isEmpty() )
00701 return false;
00702 Kleo::MessageBox::auditLog( w, auditLog );
00703 return true;
00704 }
00705
00706 bool ShowAuditLogURLHandler::handleContextMenuRequest( const KURL & url, const QPoint &, KMReaderWin * w ) const
00707 {
00708 Q_UNUSED( w );
00709
00710 return !extractAuditLog( url ).isEmpty();
00711 }
00712
00713 QString ShowAuditLogURLHandler::statusBarMessage( const KURL & url, KMReaderWin * ) const {
00714 if ( extractAuditLog( url ).isEmpty() )
00715 return QString();
00716 else
00717 return i18n("Show GnuPG Audit Log for this operation");
00718 }
00719 }
00720
00721 namespace {
00722 bool InternalImageURLHandler::handleDrag( const KURL &url, KMReaderWin *window ) const
00723 {
00724 Q_UNUSED( window );
00725 const QString imagePath = locate( "data", "kmail/pics/" );
00726 if ( url.path().contains( imagePath ) ) {
00727
00728 return true;
00729 }
00730 return false;
00731 }
00732
00733 bool InternalImageURLHandler::willHandleDrag( const KURL &url, KMReaderWin *window ) const
00734 {
00735 Q_UNUSED( window );
00736 const QString imagePath = locate( "data", "kmail/pics/" );
00737 return url.path().contains( imagePath );
00738 }
00739 }
00740
00741 namespace {
00742 bool FallBackURLHandler::handleClick( const KURL & url, KMReaderWin * w ) const {
00743 if ( w )
00744 w->emitUrlClicked( url, Qt::LeftButton );
00745 return true;
00746 }
00747
00748 bool FallBackURLHandler::handleContextMenuRequest( const KURL & url, const QPoint & p, KMReaderWin * w ) const {
00749 if ( w )
00750 w->emitPopupMenu( url, p );
00751 return true;
00752 }
00753 }