2 Copyright (c) 2016 Montel Laurent <montel@kde.org>
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "webviewer.h"
19 #include "actionmanager.h"
21 #include "webkit/urlhandlermanager.h"
23 #include <KPIMTextEdit/TextToSpeech>
24 #include <MessageViewer/AdBlockBlockableItemsDialog>
26 #include <KIO/KUriFilterSearchProviderActions>
27 #include <KActionCollection>
28 #include <KActionMenu>
29 #include <KLocalizedString>
31 #include <QContextMenuEvent>
33 #include <QWebHistory>
35 using namespace Akregator
;
37 WebViewer::WebViewer(KActionCollection
*ac
, QWidget
*parent
)
38 : ArticleViewerNg(ac
, parent
)
40 settings()->setAttribute(QWebSettings::JavascriptEnabled
, true);
41 settings()->setAttribute(QWebSettings::JavaEnabled
, true);
42 settings()->setAttribute(QWebSettings::PluginsEnabled
, true);
43 settings()->setAttribute(QWebSettings::DnsPrefetchEnabled
, true);
44 settings()->setAttribute(QWebSettings::AutoLoadImages
, true);
47 WebViewer::~WebViewer()
52 void WebViewer::displayContextMenu(const QPoint
&pos
)
54 mContextMenuHitResult
= page()->mainFrame()->hitTestContent(pos
);
55 mCurrentUrl
= mContextMenuHitResult
.linkUrl();
56 if (URLHandlerManager::instance()->handleContextMenuRequest(mCurrentUrl
, mapToGlobal(pos
), this)) {
60 QWebHistory
*history
= page()->history();
61 bool needSeparator
= false;
62 if (history
->canGoBack()) {
63 popup
.addAction(pageAction(QWebPage::Back
));
67 if (history
->canGoForward()) {
68 popup
.addAction(pageAction(QWebPage::Forward
));
74 popup
.addAction(pageAction(QWebPage::Stop
));
76 popup
.addAction(pageAction(QWebPage::Reload
));
79 const bool contentSelected
= mContextMenuHitResult
.isContentSelected();
80 if (!mCurrentUrl
.isEmpty() && !contentSelected
) {
81 popup
.addAction(createOpenLinkInNewTabAction(mCurrentUrl
, this, SLOT(slotOpenLinkInForegroundTab()), &popup
));
82 popup
.addAction(createOpenLinkInExternalBrowserAction(mCurrentUrl
, this, SLOT(slotOpenLinkInBrowser()), &popup
));
84 popup
.addAction(mActionCollection
->action(QStringLiteral("savelinkas")));
85 popup
.addAction(mActionCollection
->action(QStringLiteral("copylinkaddress")));
86 if (!mContextMenuHitResult
.imageUrl().isEmpty()) {
88 popup
.addAction(mActionCollection
->action(QStringLiteral("copy_image_location")));
89 popup
.addAction(mActionCollection
->action(QStringLiteral("saveas_imageurl")));
90 if (adblockEnabled()) {
92 popup
.addAction(mActionCollection
->action(QStringLiteral("adblock_image")));
96 popup
.addActions(viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedUrl
));
98 popup
.addAction(mShareServiceManager
->menu());
100 if (contentSelected
) {
101 popup
.addAction(ActionManager::getInstance()->action(QStringLiteral("viewer_copy")));
102 popup
.addSeparator();
103 mWebShortcutMenuManager
->setSelectedText(page()->selectedText());
104 mWebShortcutMenuManager
->addWebShortcutsToMenu(&popup
);
105 popup
.addSeparator();
106 popup
.addActions(viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedSelection
));
107 popup
.addSeparator();
109 popup
.addAction(ActionManager::getInstance()->action(QStringLiteral("viewer_print")));
110 popup
.addAction(ActionManager::getInstance()->action(QStringLiteral("viewer_printpreview")));
111 popup
.addSeparator();
112 popup
.addAction(i18n("Open Ad Block settings"), this, SLOT(slotOpenBlockableItemsDialog()));
114 popup
.addSeparator();
115 popup
.addAction(ActionManager::getInstance()->action(QStringLiteral("find_in_messages")));
116 if (KPIMTextEdit::TextToSpeech::self()->isReady()) {
117 popup
.addSeparator();
118 popup
.addAction(ActionManager::getInstance()->action(QStringLiteral("speak_text")));
120 popup
.exec(mapToGlobal(pos
));
123 void WebViewer::slotOpenBlockableItemsDialog()
125 QPointer
<MessageViewer::AdBlockBlockableItemsDialog
> dlg
= new MessageViewer::AdBlockBlockableItemsDialog(this);
126 dlg
->setWebFrame(page()->mainFrame());