[trojita] src/Gui: GUI: Extracting e-mail addresses from a message body
Jan Kundrát
null at kde.org
Mon Feb 13 00:08:39 UTC 2017
Git commit d42deaec263c1a0cd00d0391f0b75b48c3471b0d by Jan Kundrát.
Committed on 05/02/2017 at 14:37.
Pushed by gerrit into branch 'master'.
GUI: Extracting e-mail addresses from a message body
Right now, we delegate link copying to WebKit, which means that it will
use URLs like "mailto:foo at example.org". That is suboptimal from the
user's point of view; they typically just "want to have that e-mail
address".
This patch ensures that we do this fancy thing when the URL is really a
simple one -- pointing to exactly one recipient. As a fallback option,
all other cases are handled by the existing code which just copies the
URL as-is.
Please note that this does not fix the issue that the linked bugreport
complained about -- the header widget with e-mail addresses is a QLabel,
so we will have to do a slightly different dance for that.
Change-Id: I930f4eecd291af643c736701849d4c92fc8fc43d
CCBUG: 374830
M +18 -3 src/Gui/SimplePartWidget.cpp
M +1 -0 src/Gui/SimplePartWidget.h
https://commits.kde.org/trojita/d42deaec263c1a0cd00d0391f0b75b48c3471b0d
diff --git a/src/Gui/SimplePartWidget.cpp b/src/Gui/SimplePartWidget.cpp
index e9f85921..c2d6fd77 100644
--- a/src/Gui/SimplePartWidget.cpp
+++ b/src/Gui/SimplePartWidget.cpp
@@ -20,6 +20,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
+#include <QClipboard>
#include <QFileDialog>
#include <QFontDatabase>
#include <QMenu>
@@ -30,6 +31,7 @@
#include "SimplePartWidget.h"
#include "Common/MetaTypes.h"
#include "Common/Paths.h"
+#include "Composer/Mailto.h"
#include "Gui/MessageView.h" // so that the compiler knows that it's a QObject
#include "Gui/Util.h"
#include "Imap/Encoders.h"
@@ -85,6 +87,12 @@ SimplePartWidget::SimplePartWidget(QWidget *parent, Imap::Network::MsgPartNetAcc
connect(m_findAction, &QAction::triggered, this, &SimplePartWidget::searchDialogRequested);
addAction(m_findAction);
+ m_copyMail = new QAction(UiUtils::loadIcon(QStringLiteral("edit-copy")), tr("Copy e-mail address"), this);
+ connect(m_copyMail, &QAction::triggered, this, [this](){
+ QGuiApplication::clipboard()->setText(m_copyMail->data().toString());
+ });
+ this->addAction(m_copyMail);
+
setContextMenuPolicy(Qt::CustomContextMenu);
// It is actually OK to construct this widget without any connection to a messageView -- this is often used when
@@ -170,10 +178,17 @@ void SimplePartWidget::buildContextMenu(const QPoint &point, QMenu &menu) const
a = pageAction(QWebPage::SelectAll);
a->setIcon(UiUtils::loadIcon(QStringLiteral("edit-select-all")));
menu.addAction(a);
- if (!page()->mainFrame()->hitTestContent(point).linkUrl().isEmpty()) {
+ auto linkUrl = page()->mainFrame()->hitTestContent(point).linkUrl();
+ if (!linkUrl.isEmpty()) {
menu.addSeparator();
- a = pageAction(QWebPage::CopyLinkToClipboard);
- a->setIcon(UiUtils::loadIcon(QStringLiteral("edit-copy")));
+ auto oneMail = Composer::extractOneMailAddress(linkUrl);
+ if (!oneMail.isEmpty()) {
+ a = m_copyMail;
+ a->setData(oneMail);
+ } else {
+ a = pageAction(QWebPage::CopyLinkToClipboard);
+ a->setIcon(UiUtils::loadIcon(QStringLiteral("edit-copy")));
+ }
menu.addAction(a);
}
menu.addSeparator();
diff --git a/src/Gui/SimplePartWidget.h b/src/Gui/SimplePartWidget.h
index d04370c6..6c7b9a08 100644
--- a/src/Gui/SimplePartWidget.h
+++ b/src/Gui/SimplePartWidget.h
@@ -78,6 +78,7 @@ private:
QAction *m_savePart;
QAction *m_saveMessage;
QAction *m_findAction;
+ QAction *m_copyMail;
MessageView *m_messageView;
Imap::Network::MsgPartNetAccessManager *m_netAccessManager;
More information about the kde-doc-english
mailing list