File indexing completed on 2025-01-26 04:47:11
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "urlhandlerwebengine.h" 0008 #include "akregator_debug.h" 0009 #include "articleviewer-ng/webengine/articleviewerwebengine.h" 0010 #include <KEmailAddress> 0011 #include <KLocalizedString> 0012 #include <PimCommon/BroadcastStatus> 0013 #include <QApplication> 0014 #include <QClipboard> 0015 #include <QDesktopServices> 0016 #include <QMenu> 0017 #include <QUrlQuery> 0018 using namespace Akregator; 0019 0020 bool AkregatorConfigHandler::handleClick(const QUrl &url, ArticleViewerWebEngine *article) const 0021 { 0022 if (url.scheme() == QLatin1StringView("config")) { 0023 if (url.path() == QLatin1StringView("/disable_introduction")) { 0024 article->disableIntroduction(); 0025 return true; 0026 } 0027 } 0028 return false; 0029 } 0030 0031 bool AkregatorConfigHandler::handleContextMenuRequest(const QUrl &url, const QPoint &, ArticleViewerWebEngine *) const 0032 { 0033 return url.scheme() == QLatin1StringView("config"); 0034 } 0035 0036 QString AkregatorConfigHandler::statusBarMessage(const QUrl &url, ArticleViewerWebEngine *) const 0037 { 0038 if (url.scheme() == QLatin1StringView("config")) { 0039 if (url.path() == QLatin1StringView("/disable_introduction")) { 0040 return i18n("Disable Introduction"); 0041 } 0042 } 0043 return {}; 0044 } 0045 0046 QString MailToURLHandlerWebEngine::statusBarMessage(const QUrl &url, ArticleViewerWebEngine *) const 0047 { 0048 if (url.scheme() == QLatin1StringView("mailto")) { 0049 return KEmailAddress::decodeMailtoUrl(url); 0050 } 0051 return {}; 0052 } 0053 0054 bool MailToURLHandlerWebEngine::handleContextMenuRequest(const QUrl &url, const QPoint &p, ArticleViewerWebEngine *) const 0055 { 0056 if (url.scheme() == QLatin1StringView("mailto")) { 0057 auto menu = new QMenu(); 0058 QAction *copy = menu->addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("&Copy Email Address")); 0059 0060 QAction *a = menu->exec(p); 0061 if (a == copy) { 0062 const QString fullEmail = KEmailAddress::decodeMailtoUrl(url); 0063 if (!fullEmail.isEmpty()) { 0064 QClipboard *clip = QApplication::clipboard(); 0065 clip->setText(fullEmail, QClipboard::Clipboard); 0066 clip->setText(fullEmail, QClipboard::Selection); 0067 PimCommon::BroadcastStatus::instance()->setStatusMsg(i18n("Address copied to clipboard.")); 0068 } 0069 } 0070 delete menu; 0071 0072 return true; 0073 } 0074 return false; 0075 } 0076 0077 bool MailToURLHandlerWebEngine::handleClick(const QUrl &url, ArticleViewerWebEngine *) const 0078 { 0079 if (url.scheme() == QLatin1StringView("mailto")) { 0080 QDesktopServices::openUrl(url); 0081 return true; 0082 } 0083 return false; 0084 } 0085 0086 bool ActionURLHandlerWebEngine::handleContextMenuRequest(const QUrl &url, const QPoint &, ArticleViewerWebEngine *) const 0087 { 0088 return url.scheme() == QLatin1StringView("akregatoraction"); 0089 } 0090 0091 QString ActionURLHandlerWebEngine::statusBarMessage(const QUrl &url, ArticleViewerWebEngine *) const 0092 { 0093 if (url.scheme() == QLatin1StringView("akregatoraction")) { 0094 const QString urlPath(url.path()); 0095 if (urlPath == QLatin1StringView("delete")) { 0096 return i18n("Delete Article"); 0097 } else if (urlPath == QLatin1StringView("markAsRead")) { 0098 return i18n("Mark Article as Read"); 0099 } else if (urlPath == QLatin1StringView("markAsUnRead")) { 0100 return i18n("Mark Article as Unread"); 0101 } else if (urlPath == QLatin1StringView("markAsImportant")) { 0102 return i18n("Change Important Flag"); 0103 } else if (urlPath == QLatin1StringView("sendUrlArticle")) { 0104 return i18n("Send the URL of the article"); 0105 } else if (urlPath == QLatin1StringView("sendFileArticle")) { 0106 return i18n("Send the Html Page of Article"); 0107 } else if (urlPath == QLatin1StringView("openInExternalBrowser")) { 0108 return i18n("Open In External Browser"); 0109 } else if (urlPath == QLatin1StringView("openInBackgroundTab")) { 0110 return i18n("Open In Background Tab"); 0111 } 0112 return {}; 0113 } 0114 return {}; 0115 } 0116 0117 bool ActionURLHandlerWebEngine::handleClick(const QUrl &url, ArticleViewerWebEngine *articleViewer) const 0118 { 0119 if (url.scheme() == QLatin1StringView("akregatoraction")) { 0120 const QString urlPath(url.path()); 0121 if (url.hasQuery()) { 0122 const QUrlQuery urlQuery(url); 0123 const QString articleId = urlQuery.queryItemValue(QStringLiteral("id")); 0124 const QString feed = urlQuery.queryItemValue(QStringLiteral("feed")); 0125 if (!articleId.isEmpty()) { 0126 if (urlPath == QLatin1StringView("delete")) { 0127 articleViewer->setArticleAction(ArticleViewerWebEngine::DeleteAction, articleId, feed); 0128 return true; 0129 } else if (urlPath == QLatin1StringView("markAsRead")) { 0130 articleViewer->setArticleAction(ArticleViewerWebEngine::MarkAsRead, articleId, feed); 0131 return true; 0132 } else if (urlPath == QLatin1StringView("markAsUnRead")) { 0133 articleViewer->setArticleAction(ArticleViewerWebEngine::MarkAsUnRead, articleId, feed); 0134 return true; 0135 } else if (urlPath == QLatin1StringView("markAsImportant")) { 0136 articleViewer->setArticleAction(ArticleViewerWebEngine::MarkAsImportant, articleId, feed); 0137 return true; 0138 } else if (urlPath == QLatin1StringView("sendUrlArticle")) { 0139 articleViewer->setArticleAction(ArticleViewerWebEngine::SendUrlArticle, articleId, feed); 0140 return true; 0141 } else if (urlPath == QLatin1StringView("sendFileArticle")) { 0142 articleViewer->setArticleAction(ArticleViewerWebEngine::SendFileArticle, articleId, feed); 0143 return true; 0144 } else if (urlPath == QLatin1StringView("openInExternalBrowser")) { 0145 articleViewer->setArticleAction(ArticleViewerWebEngine::OpenInExternalBrowser, articleId, feed); 0146 return true; 0147 } else if (urlPath == QLatin1StringView("openInBackgroundTab")) { 0148 articleViewer->setArticleAction(ArticleViewerWebEngine::OpenInBackgroundTab, articleId, feed); 0149 return true; 0150 } 0151 } 0152 } else { 0153 qCWarning(AKREGATOR_LOG) << "Undefined article id"; 0154 return true; 0155 } 0156 } 0157 return false; 0158 }