Commit f219ba5a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add support for viewer plugin (=> translator for the moment)

parent cb53517d
......@@ -44,6 +44,7 @@
#include <QApplication>
#include <QClipboard>
#include <QMenu>
#include <viewerplugintoolmanager.h>
#include <MessageViewer/WebHitTestResult>
#include <MessageViewer/WebHitTest>
......@@ -54,7 +55,8 @@ using namespace Akregator;
ArticleViewerWebEngine::ArticleViewerWebEngine(KActionCollection *ac, QWidget *parent)
: QWebEngineView(parent),
mActionCollection(ac),
mLastButtonClicked(LeftButton)
mLastButtonClicked(LeftButton),
mViewerPluginToolManager(Q_NULLPTR)
{
new MessageViewer::NetworkAccessManagerWebEngine(ac, this);
mPageEngine = new ArticleViewerWebEnginePage(this);
......@@ -233,6 +235,8 @@ void ArticleViewerWebEngine::slotWebHitFinished(const MessageViewer::WebHitTestR
popup.addSeparator();
mWebShortcutMenuManager->setSelectedText(page()->selectedText());
mWebShortcutMenuManager->addWebShortcutsToMenu(&popup);
popup.addSeparator();
popup.addActions(viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedSelection));
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
popup.addSeparator();
......@@ -392,6 +396,37 @@ bool ArticleViewerWebEngine::zoomTextOnlyInFrame() const
//return settings()->testAttribute(QWebEngineSettings::ZoomTextOnly);
}
void ArticleViewerWebEngine::createViewerPluginToolManager(KActionCollection *ac, QWidget *parent)
{
mViewerPluginToolManager = new MessageViewer::ViewerPluginToolManager(parent, this);
mViewerPluginToolManager->setActionCollection(ac);
mViewerPluginToolManager->setPluginName(QStringLiteral("akregator"));
mViewerPluginToolManager->setServiceTypeName(QStringLiteral("Akregator/ViewerPlugin"));
if (!mViewerPluginToolManager->initializePluginList()) {
qDebug() << " Impossible to initialize plugins";
}
mViewerPluginToolManager->createView();
connect(mViewerPluginToolManager, &MessageViewer::ViewerPluginToolManager::activatePlugin, this, &ArticleViewerWebEngine::slotActivatePlugin);
}
QList<QAction *> ArticleViewerWebEngine::viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features)
{
if (mViewerPluginToolManager) {
return mViewerPluginToolManager->viewerPluginActionList(features);
}
return QList<QAction *>();
}
void ArticleViewerWebEngine::slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface)
{
const QString text = selectedText();
if (!text.isEmpty()) {
interface->setText(text);
}
interface->showWidget();
}
void ArticleViewerWebEngine::slotZoomTextOnlyInFrame(bool textOnlyInFrame)
{
//settings()->setAttribute(QWebEngineSettings::ZoomTextOnly, textOnlyInFrame);
......
......@@ -21,11 +21,14 @@
#include <QWebEngineView>
#include <openurlrequest.h>
#include <shareserviceurlmanager.h>
#include <MessageViewer/ViewerPluginInterface>
class KActionCollection;
namespace MessageViewer
{
class WebHitTestResult;
class ViewerPluginToolManager;
class ViewerPluginInterface;
}
namespace PimCommon
{
......@@ -63,6 +66,8 @@ public:
bool zoomTextOnlyInFrame() const;
void createViewerPluginToolManager(KActionCollection *ac, QWidget *parent);
protected:
QUrl mCurrentUrl;
KActionCollection *mActionCollection;
......@@ -117,14 +122,17 @@ private Q_SLOTS:
void slotOpenLinkInBrowser();
void slotShowContextMenu(const QPoint &pos);
void slotWebHitFinished(const MessageViewer::WebHitTestResult &result);
void slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface);
protected:
ArticleViewerWebEnginePage *mPageEngine;
bool adblockEnabled() const;
void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE;
QList<QAction *> viewerPluginActionList(MessageViewer::ViewerPluginInterface::SpecificFeatureTypes features);
private:
MousePressedButtonType mLastButtonClicked;
MessageViewer::ViewerPluginToolManager *mViewerPluginToolManager;
//MessageViewer::WebViewAccessKey *mWebViewAccessKey;
};
}
......
......@@ -63,17 +63,7 @@ void ArticleViewerWebEngineWidgetNg::initializeLayout(KActionCollection *ac)
mArticleViewerNg->setObjectName(QStringLiteral("articleviewerng"));
layout->addWidget(mArticleViewerNg);
mViewerPluginToolManager = new MessageViewer::ViewerPluginToolManager(this, this);
mViewerPluginToolManager->setActionCollection(ac);
mViewerPluginToolManager->setPluginName(QStringLiteral("akregator"));
mViewerPluginToolManager->setServiceTypeName(QStringLiteral("Akregator/ViewerPlugin"));
if (!mViewerPluginToolManager->initializePluginList()) {
qDebug() << " Impossible to initialize plugins";
}
mViewerPluginToolManager->createView();
connect(mViewerPluginToolManager, &MessageViewer::ViewerPluginToolManager::activatePlugin, this, &ArticleViewerWebEngineWidgetNg::slotActivatePlugin);
mArticleViewerNg->createViewerPluginToolManager(ac, this);
mSliderContainer = new KPIMTextEdit::SlideContainer(this);
mSliderContainer->setObjectName(QStringLiteral("slidercontainer"));
......@@ -91,15 +81,6 @@ ArticleViewerWebEngineWidgetNg::~ArticleViewerWebEngineWidgetNg()
}
void ArticleViewerWebEngineWidgetNg::slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface)
{
const QString text = mArticleViewerNg->selectedText();
if (!text.isEmpty()) {
interface->setText(text);
}
interface->showWidget();
}
ArticleViewerWebEngine *ArticleViewerWebEngineWidgetNg::articleViewerNg() const
{
return mArticleViewerNg;
......@@ -119,12 +100,3 @@ void ArticleViewerWebEngineWidgetNg::slotSpeakText()
const QString text = mArticleViewerNg->selectedText();
mTextToSpeechWidget->say(text);
}
#if 0
QList<QAction *> ViewerPrivate::viewerPluginActionList(ViewerPluginInterface::SpecificFeatureTypes features)
{
if (mViewerPluginToolManager) {
return mViewerPluginToolManager->viewerPluginActionList(features);
}
return QList<QAction *>();
}
#endif
......@@ -50,7 +50,6 @@ public:
public Q_SLOTS:
void slotSpeakText();
void slotFind();
void slotActivatePlugin(MessageViewer::ViewerPluginInterface *interface);
private:
void initializeActions(KActionCollection *ac);
void initializeLayout(KActionCollection *ac);
......@@ -58,7 +57,6 @@ private:
ArticleViewerWebEngine *mArticleViewerNg;
KPIMTextEdit::TextToSpeechWidget *mTextToSpeechWidget;
KPIMTextEdit::SlideContainer *mSliderContainer;
MessageViewer::ViewerPluginToolManager *mViewerPluginToolManager;
};
}
#endif // ARTICLEVIEWERWEBENGINEWIDGETNG_H
......@@ -108,6 +108,8 @@ void WebEngineViewer::slotWebHitFinished(const MessageViewer::WebHitTestResult &
mWebShortcutMenuManager->setSelectedText(page()->selectedText());
mWebShortcutMenuManager->addWebShortcutsToMenu(&popup);
popup.addSeparator();
popup.addActions(viewerPluginActionList(MessageViewer::ViewerPluginInterface::NeedSelection));
popup.addSeparator();
popup.addAction(i18n("Open Ad Block settings"), this, SLOT(slotOpenBlockableItemsDialog()));
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment