Git commit 434f677d4909e751ef59d2c8b5e2899b05eae022 by Jan Kundrát. Committed on 06/02/2017 at 11:29. Pushed by gerrit into branch 'master'.
GUI: Clipboard copying of e-mail addresses from the header view Previously, the context menu offered some options for accessing the QLabel (this class is actually just a pretty QLabel)'s text, for selecting all of it, and copying stuff. The most important, IMHO, is to have access to the actual e-mail address (as requested by the associated bugreport), and to the human readable text for the sake of completeness. The code is still a tad inconsistent because the List-Post header for indicating an active mailing list does not currently use the OneEnvelopeAddress class. Mailing list addresses will therefore remain unaffected by this patch; their copy action is still going to copy a complete mailto: URL. BUG: 374830 Change-Id: I4e515045d0241e4c1064389aa777f58e72c7c999 M +26 -2 src/Gui/OneEnvelopeAddress.cpp M +2 -0 src/Gui/OneEnvelopeAddress.h https://commits.kde.org/trojita/434f677d4909e751ef59d2c8b5e2899b05eae022 diff --git a/src/Gui/OneEnvelopeAddress.cpp b/src/Gui/OneEnvelopeAddress.cpp index 922b0945..f0445ed4 100644 --- a/src/Gui/OneEnvelopeAddress.cpp +++ b/src/Gui/OneEnvelopeAddress.cpp @@ -20,15 +20,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "OneEnvelopeAddress.h" + +#include <QClipboard> +#include <QContextMenuEvent> #include <QDesktopServices> -#include <QHeaderView> #include <QFontMetrics> +#include <QGuiApplication> +#include <QHeaderView> +#include <QMenu> #include <QUrlQuery> +#include "Composer/Mailto.h" #include "Gui/MessageView.h" +#include "Gui/OneEnvelopeAddress.h" #include "Gui/Util.h" #include "Plugins/PluginManager.h" #include "Plugins/AddressbookPlugin.h" +#include "UiUtils/IconLoader.h" namespace Gui { @@ -127,4 +134,21 @@ void OneEnvelopeAddress::finishOnLinkHovered(const QStringList &matchingDisplayN setToolTip(m_link + tr("<hr/><b>Address Book:</b><br/>") + identities); } +void OneEnvelopeAddress::contextMenuEvent(QContextMenuEvent *e) +{ + QScopedPointer<QMenu> menu(new QMenu(this)); + // NOTE: when QT_VERSION >= QT_VERSION_CHECK(5,6,0), we can get rid of this verbose code and just call menu->addAction(...) + auto a = new QAction(UiUtils::loadIcon(QStringLiteral("edit-copy")), tr("Copy e-mail address"), menu.data()); + connect(a, &QAction::triggered, this, [this](){ + QGuiApplication::clipboard()->setText(Composer::extractOneMailAddress(m_address.asUrl())); + }); + menu->addAction(a); + a = new QAction(tr("Copy text"), this); + connect(a, &QAction::triggered, this, [this]() { + QGuiApplication::clipboard()->setText(m_address.prettyName(Imap::Message::MailAddress::FORMAT_JUST_NAME)); + }); + menu->addAction(a); + menu->exec(e->globalPos()); +} + } diff --git a/src/Gui/OneEnvelopeAddress.h b/src/Gui/OneEnvelopeAddress.h index d8d1833d..3fab287d 100644 --- a/src/Gui/OneEnvelopeAddress.h +++ b/src/Gui/OneEnvelopeAddress.h @@ -48,6 +48,8 @@ public: OneEnvelopeAddress(QWidget *parent, const Imap::Message::MailAddress &address, MessageView *messageView, const Position lastOneInRow); + virtual void contextMenuEvent(QContextMenuEvent *e) override; + private slots: void onLinkHovered(const QString &target); void finishOnLinkHovered(const QStringList &matchingDisplayNames);
