From ddbc60fd2c1dab03ca6f430a436fadca4649fae3 Mon Sep 17 00:00:00 2001 From: Allen Winter Date: Fri, 14 Nov 2008 00:53:37 +0000 Subject: [PATCH] if the email address exists in the addressbook, put the "open in addressbook" option on the context menu; else put the "add to addressbook option". BUG: 174332 svn path=/trunk/KDE/kdepim/; revision=884027 --- kmmainwidget.cpp | 54 +++++++++++++++++++++++++++------------------ kmreadermainwin.cpp | 41 ++++++++++++++++++++-------------- 2 files changed, 57 insertions(+), 38 deletions(-) diff --git a/kmmainwidget.cpp b/kmmainwidget.cpp index b9ba0cc44..11dabb052 100644 --- a/kmmainwidget.cpp +++ b/kmmainwidget.cpp @@ -158,6 +158,9 @@ using KMail::TemplateParser; #include "commands/exporttohtml.h" #include "messagetree.h" +#include +#include + #ifdef Nepomuk_FOUND #include #endif @@ -3371,7 +3374,7 @@ void KMMainWidget::slotMarkAll() } //----------------------------------------------------------------------------- -void KMMainWidget::slotMsgPopup(KMMessage &msg, const KUrl &aUrl, const QPoint& aPoint) +void KMMainWidget::slotMsgPopup( KMMessage &msg, const KUrl &aUrl, const QPoint &aPoint ) { mMessageListView->activateMessage( &msg ); // make sure that this message is the active one @@ -3382,23 +3385,29 @@ void KMMainWidget::slotMsgPopup(KMMessage &msg, const KUrl &aUrl, const QPoint& updateMessageMenu(); - KMenu * menu = new KMenu; + KMenu *menu = new KMenu; mUrlCurrent = aUrl; bool urlMenuAdded = false; - if (!aUrl.isEmpty()) - { - if (aUrl.protocol() == "mailto") - { + if ( !aUrl.isEmpty() ) { + if ( aUrl.protocol() == "mailto" ) { // popup on a mailto URL menu->addAction( mMsgView->mailToComposeAction() ); menu->addAction( mMsgView->mailToReplyAction() ); menu->addAction( mMsgView->mailToForwardAction() ); menu->addSeparator(); - menu->addAction( mMsgView->addAddrBookAction() ); - menu->addAction( mMsgView->openAddrBookAction() ); + + QString email = KPIMUtils::firstEmailAddress( aUrl.path() ); + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); + KABC::Addressee::List addresseeList = addressBook->findByEmail( email ); + + if ( addresseeList.count() == 0 ) { + menu->addAction( mMsgView->addAddrBookAction() ); + } else { + menu->addAction( mMsgView->openAddrBookAction() ); + } menu->addAction( mMsgView->copyURLAction() ); } else { // popup on a not-mailto URL @@ -3408,25 +3417,24 @@ void KMMainWidget::slotMsgPopup(KMMessage &msg, const KUrl &aUrl, const QPoint& menu->addAction( mMsgView->copyURLAction() ); } - urlMenuAdded=true; - kDebug( 0 ) <<" URL is:" << aUrl; + urlMenuAdded = true; + kDebug() <<" URL is:" << aUrl; } - - if(mMsgView && !mMsgView->copyText().isEmpty()) { - if ( urlMenuAdded ) + if ( mMsgView && !mMsgView->copyText().isEmpty() ) { + if ( urlMenuAdded ) { menu->addSeparator(); + } menu->addAction( mMsgActions->replyMenu() ); menu->addSeparator(); menu->addAction( mMsgView->copyAction() ); menu->addAction( mMsgView->selectAllAction() ); - } else if ( !urlMenuAdded ) - { + } else if ( !urlMenuAdded ) { // popup somewhere else (i.e., not a URL) on the message - if (!mMessageListView->currentMessage()) // no messages - { + if (!mMessageListView->currentMessage()) { + // no messages delete menu; return; } @@ -3435,8 +3443,9 @@ void KMMainWidget::slotMsgPopup(KMMessage &msg, const KUrl &aUrl, const QPoint& menu->addAction( mUseAction ); } else { - if ( !mFolder->isSent() ) + if ( !mFolder->isSent() ) { menu->addAction( mMsgActions->replyMenu() ); + } menu->addAction( mForwardActionMenu ); } menu->addAction(editAction()); @@ -3451,7 +3460,7 @@ void KMMainWidget::slotMsgPopup(KMMessage &msg, const KUrl &aUrl, const QPoint& menu->addSeparator(); menu->addAction( viewSourceAction() ); - if(mMsgView) { + if ( mMsgView ) { menu->addAction( mMsgView->toggleFixFontAction() ); } menu->addSeparator(); @@ -3461,16 +3470,17 @@ void KMMainWidget::slotMsgPopup(KMMessage &msg, const KUrl &aUrl, const QPoint& menu->addAction( mExportToHtmlAction ); menu->addSeparator(); - if( mFolder->isTrash() ) + if ( mFolder->isTrash() ) { menu->addAction( mDeleteAction ); - else + } else { menu->addAction( mTrashAction ); + } menu->addSeparator(); menu->addAction( mMsgActions->createTodoAction() ); } KAcceleratorManager::manage(menu); - menu->exec(aPoint, 0); + menu->exec( aPoint, 0 ); delete menu; } diff --git a/kmreadermainwin.cpp b/kmreadermainwin.cpp index bb74c0b07..d0abb6de5 100644 --- a/kmreadermainwin.cpp +++ b/kmreadermainwin.cpp @@ -51,6 +51,9 @@ #include "kmmsgdict.h" #include "mainfolderview.h" +#include +#include + KMReaderMainWin::KMReaderMainWin( bool htmlOverride, bool htmlLoadExtOverride, char *name ) : KMail::SecondaryWindow( name ? name : "readerwindow#" ), @@ -379,16 +382,15 @@ void KMReaderMainWin::updateMessageMenu() //----------------------------------------------------------------------------- -void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KUrl &aUrl, const QPoint& aPoint) +void KMReaderMainWin::slotMsgPopup( KMMessage &aMsg, const KUrl &aUrl, const QPoint &aPoint ) { - KMenu * menu = new KMenu; + KMenu *menu = new KMenu; mUrl = aUrl; mMsg = &aMsg; - bool urlMenuAdded=false; + bool urlMenuAdded = false; - if (!aUrl.isEmpty()) - { - if (aUrl.protocol() == "mailto") { + if ( !aUrl.isEmpty() ) { + if ( aUrl.protocol() == "mailto" ) { // popup on a mailto URL menu->addAction( mReaderWin->mailToComposeAction() ); if ( mMsg ) { @@ -396,8 +398,15 @@ void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KUrl &aUrl, const QPoi menu->addAction( mReaderWin->mailToForwardAction() ); menu->addSeparator(); } - menu->addAction( mReaderWin->addAddrBookAction() ); - menu->addAction( mReaderWin->openAddrBookAction() ); + QString email = KPIMUtils::firstEmailAddress( aUrl.path() ); + KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true ); + KABC::Addressee::List addresseeList = addressBook->findByEmail( email ); + + if ( addresseeList.count() == 0 ) { + menu->addAction( mReaderWin->addAddrBookAction() ); + } else { + menu->addAction( mReaderWin->openAddrBookAction() ); + } menu->addAction( mReaderWin->copyAction() ); } else { // popup on a not-mailto URL @@ -406,22 +415,22 @@ void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KUrl &aUrl, const QPoi menu->addAction( mReaderWin->urlSaveAsAction() ); menu->addAction( mReaderWin->copyURLAction() ); } - urlMenuAdded=true; + urlMenuAdded = true; } - if(!mReaderWin->copyText().isEmpty()) { - if ( urlMenuAdded ) + if ( !mReaderWin->copyText().isEmpty() ) { + if ( urlMenuAdded ) { menu->addSeparator(); + } menu->addAction( mMsgActions->replyMenu() ); menu->addSeparator(); menu->addAction( mReaderWin->copyAction() ); menu->addAction( mReaderWin->selectAllAction() ); - } else if ( !urlMenuAdded ) - { + } else if ( !urlMenuAdded ) { // popup somewhere else (i.e., not a URL) on the message - if (!mMsg) // no message - { + if (!mMsg) { + // no message delete menu; return; } @@ -451,7 +460,7 @@ void KMReaderMainWin::slotMsgPopup(KMMessage &aMsg, const KUrl &aUrl, const QPoi menu->addAction( mSaveAtmAction ); menu->addAction( mMsgActions->createTodoAction() ); } - menu->exec(aPoint, 0); + menu->exec( aPoint, 0 ); delete menu; }