Removed some webengine junk.

This commit is contained in:
Martin Rotter 2016-04-01 07:41:55 +02:00
parent 4952c3da32
commit e43a7606c8
10 changed files with 8 additions and 397 deletions

View file

@ -3,7 +3,7 @@
Main:
▪ Internal web browser and message preview window now use component based on Chromium/Blink (QtWebEngine).
▪ Internal web browser and message preview window now use component based on Chromium/Blink (QtWebEngine). Note that new QtWebEngine lacks some features and those were thus removed from RSS Guard, including Adblock, mouse gestures and some other features. Note that I was force to switch to this component because old Qt WebKit component will be removed from Qt.
▪ RSS Guard now uses only Qt 5.6 or higher.
Added:

View file

@ -382,7 +382,6 @@ void FormSettings::onProxyTypeChanged(int index) {
void FormSettings::loadBrowser() {
// Load settings of web browser GUI.
m_ui->m_checkMouseGestures->setChecked(m_settings->value(GROUP(Browser), SETTING(Browser::GesturesEnabled)).toBool());
m_ui->m_checkQueueTabs->setChecked(m_settings->value(GROUP(Browser), SETTING(Browser::QueueTabs)).toBool());
m_ui->m_cmbExternalBrowserPreset->addItem(tr("Opera 12 or older"), QSL("-nosession %1"));
m_ui->m_txtExternalBrowserExecutable->setText(m_settings->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserExecutable)).toString());
@ -403,7 +402,6 @@ void FormSettings::loadBrowser() {
void FormSettings::saveBrowser() {
// Save settings of GUI of web browser.
m_settings->setValue(GROUP(Browser), Browser::CustomExternalBrowserEnabled, m_ui->m_grpCustomExternalBrowser->isChecked());
m_settings->setValue(GROUP(Browser), Browser::GesturesEnabled, m_ui->m_checkMouseGestures->isChecked());
m_settings->setValue(GROUP(Browser), Browser::QueueTabs, m_ui->m_checkQueueTabs->isChecked());
m_settings->setValue(GROUP(Browser), Browser::CustomExternalBrowserExecutable, m_ui->m_txtExternalBrowserExecutable->text());
m_settings->setValue(GROUP(Browser), Browser::CustomExternalBrowserArguments, m_ui->m_txtExternalBrowserArguments->text());

View file

@ -88,7 +88,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>3</number>
<number>5</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -470,7 +470,7 @@ Authors of this application are NOT responsible for lost data.</string>
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="m_tabIconSkin">
<attribute name="title">
@ -913,7 +913,7 @@ Authors of this application are NOT responsible for lost data.</string>
<item row="2" column="0">
<widget class="QCheckBox" name="m_checkEnablePlugins">
<property name="text">
<string>Enable external plugins based on NPAPI</string>
<string>Enable external plugins</string>
</property>
</widget>
</item>
@ -924,32 +924,6 @@ Authors of this application are NOT responsible for lost data.</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkMouseGestures">
<property name="text">
<string>Enable mouse gestures</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="m_lblMouseGestures">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Mouse gestures work with middle mouse button. Possible gestures are:
• previous web page (drag mouse left),
• next web page (drag mouse right),
• reload current web page (drag mouse up),
• open new web browser tab (drag mouse down).</string>
</property>
<property name="indent">
<number>20</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabExternalBrowser">
@ -1639,7 +1613,6 @@ Authors of this application are NOT responsible for lost data.</string>
<tabstop>m_checkEnableJavascript</tabstop>
<tabstop>m_checkEnablePlugins</tabstop>
<tabstop>m_checkAutoLoadImages</tabstop>
<tabstop>m_checkMouseGestures</tabstop>
<tabstop>m_grpCustomExternalBrowser</tabstop>
<tabstop>m_txtExternalBrowserExecutable</tabstop>
<tabstop>m_btnExternalBrowserExecutable</tabstop>

View file

@ -238,9 +238,6 @@ DKEY Keyboard::ID = "keyboard";
// Web browser.
DKEY Browser::ID = "browser";
DKEY Browser::GesturesEnabled = "gestures_enabled";
DVALUE(bool) Browser::GesturesEnabledDef = true;
DKEY Browser::JavascriptEnabled = "enable_javascript";
DVALUE(bool) Browser::JavascriptEnabledDef = true;

View file

@ -267,9 +267,6 @@ namespace Keyboard {
namespace Browser {
KEY ID;
KEY GesturesEnabled;
VALUE(bool) GesturesEnabledDef;
KEY JavascriptEnabled;
VALUE(bool) JavascriptEnabledDef;

View file

@ -18,7 +18,6 @@
#include "network-web/webbrowser.h"
#include "definitions/definitions.h"
#include "network-web/webpage.h"
#include "network-web/webview.h"
#include "network-web/networkfactory.h"
#include "miscellaneous/skinfactory.h"
@ -191,8 +190,6 @@ void WebBrowser::createConnections() {
// Connect this WebBrowser to global TabWidget.
TabWidget *tab_widget = qApp->mainForm()->tabWidget();
connect(m_webView, SIGNAL(newTabRequested()), tab_widget, SLOT(addEmptyBrowser()));
connect(m_webView, SIGNAL(linkMiddleClicked(QUrl)), tab_widget, SLOT(addLinkedBrowser(QUrl)));
// Change location textbox status according to webpage status.
connect(m_webView, SIGNAL(loadStarted()), this, SLOT(onLoadingStarted()));
@ -316,7 +313,6 @@ void WebBrowser::setupIcons() {
m_actionForward->setIcon(qApp->icons()->fromTheme(QSL("go-next")));
m_actionReload->setIcon(qApp->icons()->fromTheme(QSL("go-refresh")));
m_actionStop->setIcon(qApp->icons()->fromTheme(QSL("go-stop")));
m_webView->setupIcons();
}
QIcon WebBrowser::icon() const {

View file

@ -1,25 +0,0 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2016 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "network-web/webpage.h"
WebPage::WebPage(QObject *parent) : QWebEnginePage(parent) {
}
WebPage::~WebPage() {
}

View file

@ -1,33 +0,0 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2016 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// RSS Guard is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef WEBPAGE_H
#define WEBPAGE_H
#include <QWebEnginePage>
class WebPage : public QWebEnginePage {
Q_OBJECT
public:
// Constructors and destructors.
explicit WebPage(QObject *parent = 0);
virtual ~WebPage();
};
#endif // WEBPAGE_H

View file

@ -18,259 +18,20 @@
#include "network-web/webview.h"
#include "definitions/definitions.h"
#include "miscellaneous/settings.h"
#include "miscellaneous/skinfactory.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "network-web/webpage.h"
#include "network-web/webfactory.h"
#include "gui/messagebox.h"
#include "gui/dialogs/formmain.h"
#include <QStyleOptionFrameV3>
#include <QAction>
#include <QMenu>
#include <QDir>
#include <QFile>
#include <QWebEnginePage>
#include <QContextMenuEvent>
#include <QDateTime>
#include <QClipboard>
#include <QFileDialog>
#include <QtPrintSupport/QPrintPreviewDialog>
#include <QWheelEvent>
WebView::WebView(QWidget *parent)
: QWebEngineView(parent), m_page(new WebPage(this)) {
: QWebEngineView(parent), m_page(new QWebEnginePage(this)) {
setPage(m_page);
initializeActions();
createConnections();
}
WebView::~WebView() {
qDebug("Destroying WebView.");
}
void WebView::copySelectedText() {
Application::clipboard()->setText(selectedText());
}
void WebView::openLinkInNewTab() {
emit linkMiddleClicked(m_contextLinkUrl);
}
void WebView::openLinkExternally() {
WebFactory::instance()->openUrlInExternalBrowser(m_contextLinkUrl.toString());
}
void WebView::openImageInNewTab() {
emit linkMiddleClicked(m_contextImageUrl);
}
void WebView::searchTextViaGoogle() {
emit linkMiddleClicked(QString(GOOGLE_SEARCH_URL).arg((selectedText())));
}
void WebView::saveCurrentPageToFile() {
QString selected_file;
const QString implicit_file_base_name = tr("source_page");
// NOTE: It is good to always ask for destination here, since download manager
// is not displaying afterwards because this is *not* real download actually.
//if (qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::AlwaysPromptForFilename)).toBool()) {
const QString filter_html = tr("HTML web pages (*.html)");
QString filter;
QString selected_filter;
const QString filename_for_prompt = qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::TargetExplicitDirectory)).toString() +
QDir::separator() + implicit_file_base_name + QL1S(".html");
// Add more filters here.
filter += filter_html;
selected_file = QFileDialog::getSaveFileName(this, tr("Select destination file for web page"),
filename_for_prompt, filter, &selected_filter);
if (!selected_file.isEmpty()) {
qApp->settings()->setValue(GROUP(Downloads), Downloads::TargetExplicitDirectory,
QDir::toNativeSeparators(QFileInfo(selected_file).absolutePath()));
}
/*}
else {
QString base_folder = qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::TargetDirectory)).toString();
if (!base_folder.endsWith(QDir::separator())) {
base_folder += QDir::separator();
}
selected_file = base_folder + implicit_file_base_name + QL1S(".html");
if (QFile::exists(selected_file)) {
int file_suffix = 0;
QString subsequent_file_name;
do {
subsequent_file_name = base_folder + QString(implicit_file_base_name + QL1S("-%1.html")).arg(file_suffix++);
} while (QFile::exists(subsequent_file_name));
selected_file = subsequent_file_name;
}
}*/
if (!selected_file.isEmpty()) {
page()->toHtml([this, selected_file](const QString &html) {
QFile selected_file_handle(selected_file);
if (selected_file_handle.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) {
QTextStream str(&selected_file_handle);
str.setCodec("UTF-16");
str << html;
selected_file_handle.close();
}
else {
MessageBox::show(this, QMessageBox::Critical, tr("Cannot save web page"),
tr("Web page cannot be saved because destination file is not writtable."));
}
});
}
}
void WebView::createConnections() {
connect(m_actionSavePageAs, SIGNAL(triggered()), this, SLOT(saveCurrentPageToFile()));
connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(printCurrentPage()));
connect(m_actionOpenLinkNewTab, SIGNAL(triggered()), this, SLOT(openLinkInNewTab()));
connect(m_actionOpenImageNewTab, SIGNAL(triggered()), this, SLOT(openImageInNewTab()));
connect(m_actionOpenLinkExternally, SIGNAL(triggered()), this, SLOT(openLinkExternally()));
connect(m_actionLookupText, SIGNAL(triggered()), this, SLOT(searchTextViaGoogle()));
}
void WebView::setupIcons() {
m_actionPrint->setIcon(qApp->icons()->fromTheme(QSL("print-web-page")));
m_actionCopySelectedItem->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
m_actionCopyLink->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
m_actionCopyImage->setIcon(qApp->icons()->fromTheme(QSL("edit-copy-image")));
m_actionSaveHyperlinkAs->setIcon(qApp->icons()->fromTheme(QSL("document-download")));
m_actionSaveImageAs->setIcon(qApp->icons()->fromTheme(QSL("document-download")));
m_actionCopyImageUrl->setIcon(qApp->icons()->fromTheme(QSL("edit-copy")));
m_actionOpenLinkThisTab->setIcon(qApp->icons()->fromTheme(QSL("item-open-internal")));
m_actionOpenLinkNewTab->setIcon(qApp->icons()->fromTheme(QSL("item-open-internal")));
m_actionOpenLinkExternally->setIcon(qApp->icons()->fromTheme(QSL("item-open-external")));
m_actionOpenImageNewTab->setIcon(qApp->icons()->fromTheme(QSL("edit-copy-image")));
m_actionLookupText->setIcon(qApp->icons()->fromTheme(QSL("item-search-google")));
}
void WebView::initializeActions() {
m_actionPrint = new QAction(tr("Print"), this);
m_actionPrint->setToolTip(tr("Print current web page."));
m_actionCopySelectedItem = pageAction(QWebEnginePage::Copy);
m_actionCopySelectedItem->setParent(this);
m_actionSaveHyperlinkAs = pageAction(QWebEnginePage::DownloadLinkToDisk);
m_actionSaveHyperlinkAs->setParent(this);
m_actionCopyLink = pageAction(QWebEnginePage::CopyLinkToClipboard);
m_actionCopyLink->setParent(this);
m_actionCopyImage = pageAction(QWebEnginePage::CopyImageToClipboard);
m_actionCopyImage->setParent(this);
m_actionSaveImageAs = pageAction(QWebEnginePage::DownloadImageToDisk);
m_actionSaveImageAs->setParent(this);
m_actionSavePageAs = new QAction(qApp->icons()->fromTheme(QSL("document-download")), tr("Save page as..."), this);
m_actionCopyImageUrl = pageAction(QWebEnginePage::CopyImageUrlToClipboard);
m_actionCopyImageUrl->setParent(this);
m_actionOpenLinkNewTab = pageAction(QWebEnginePage::OpenLinkInNewTab);
m_actionOpenLinkNewTab->setParent(this);
m_actionOpenLinkThisTab = pageAction(QWebEnginePage::OpenLinkInThisWindow);
m_actionOpenLinkThisTab->setParent(this);
m_actionOpenLinkExternally = new QAction(tr("Open link in external browser"), this);
// TODO: bude fungovat?
m_actionOpenImageNewTab = pageAction(QWebEnginePage::OpenLinkInNewTab);
m_actionOpenImageNewTab->setParent(this);
m_actionLookupText = new QAction("", this);
}
void WebView::setActionTexts() {
m_actionCopySelectedItem->setText(tr("Copy selection"));
m_actionCopySelectedItem->setToolTip(tr("Copies current selection into the clipboard."));
m_actionSaveHyperlinkAs->setText(tr("Save target as..."));
m_actionSaveHyperlinkAs->setToolTip(tr("Download content from the hyperlink."));
m_actionCopyLink->setText(tr("Copy link url"));
m_actionCopyLink->setToolTip(tr("Copy link url to clipboard."));
m_actionCopyImage->setText(tr("Copy image"));
m_actionCopyImage->setToolTip(tr("Copy image to clipboard."));
m_actionSaveImageAs->setText(tr("Save image as..."));
m_actionSaveImageAs->setToolTip(tr("Save image to disk."));
m_actionCopyImageUrl->setText(tr("Copy image url"));
m_actionCopyImageUrl->setToolTip(tr("Copy image url to clipboard."));
m_actionOpenLinkNewTab->setText(tr("Open link in new tab"));
m_actionOpenLinkNewTab->setToolTip(tr("Open this hyperlink in new tab."));
m_actionOpenLinkThisTab->setText(tr("Follow link"));
m_actionOpenLinkThisTab->setToolTip(tr("Open the hyperlink in this tab."));
m_actionOpenLinkExternally->setToolTip(tr("Open the hyperlink in external browser."));
m_actionOpenImageNewTab->setText(tr("Open image in new tab"));
m_actionOpenImageNewTab->setToolTip(tr("Open this image in this tab."));
}
void WebView::printCurrentPage() {
QScopedPointer<QPrintPreviewDialog> print_preview(new QPrintPreviewDialog(this));
connect(print_preview.data(), SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
print_preview.data()->exec();
}
void WebView::mousePressEvent(QMouseEvent *event) {
if (event->button() & Qt::MiddleButton) {
m_gestureOrigin = event->pos();
}
else {
QWebEngineView::mousePressEvent(event);
}
}
void WebView::mouseReleaseEvent(QMouseEvent *event) {
if (event->button() & Qt::MiddleButton) {
const bool are_gestures_enabled = qApp->settings()->value(GROUP(Browser), SETTING(Browser::GesturesEnabled)).toBool();
if (are_gestures_enabled) {
const QPoint release_point = event->pos();
int left_move = m_gestureOrigin.x() - release_point.x();
int right_move = -left_move;
int top_move = m_gestureOrigin.y() - release_point.y();
int bottom_move = -top_move;
int total_max = qMax(qMax(qMax(left_move, right_move), qMax(top_move, bottom_move)), 40);
if (total_max == left_move) {
back();
}
else if (total_max == right_move) {
forward();
}
else if (total_max == top_move) {
reload();
}
else if (total_max == bottom_move) {
emit newTabRequested();
}
}
}
QWebEngineView::mouseReleaseEvent(event);
}
void WebView::contextMenuEvent(QContextMenuEvent *event) {
QWebEngineView::contextMenuEvent(event);
}
void WebView::wheelEvent(QWheelEvent *event) {
if (event->modifiers() & Qt::ControlModifier) {
if (event->delta() > 0) {

View file

@ -21,10 +21,6 @@
#include <QWebEngineView>
class QAction;
class QPaintEvent;
class WebPage;
class WebView : public QWebEngineView {
Q_OBJECT
@ -34,20 +30,11 @@ class WebView : public QWebEngineView {
virtual ~WebView();
// Page accessor.
inline WebPage *page() const {
inline QWebEnginePage *page() const {
return m_page;
}
void setupIcons();
signals:
// Is emitted if user wants to open some hyperlink in new
// web browser tab.
void linkMiddleClicked(const QUrl &link_url);
// User wants to open new empty web browser tab.
void newTabRequested();
// Emitted if user changes zoom factor via CTRL + mouse wheel combo.
void zoomFactorChanged();
@ -57,52 +44,12 @@ class WebView : public QWebEngineView {
bool decreaseWebPageZoom();
bool resetWebPageZoom();
void copySelectedText();
void openLinkInNewTab();
void openLinkExternally();
void openImageInNewTab();
void searchTextViaGoogle();
void saveCurrentPageToFile();
void printCurrentPage();
protected:
// Initializes all actions.
void initializeActions();
void setActionTexts();
// Creates necessary connections.
void createConnections();
// Customize mouse wheeling.
void wheelEvent(QWheelEvent *event);
// Provides custom mouse actions.
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent *event);
private:
WebPage *m_page;
QAction *m_actionPrint;
QAction *m_actionCopySelectedItem;
QAction *m_actionCopyLink;
QAction *m_actionCopyImage;
QAction *m_actionSavePageAs;
QAction *m_actionSaveHyperlinkAs;
QAction *m_actionSaveImageAs;
QAction *m_actionCopyImageUrl;
QAction *m_actionOpenLinkThisTab;
QAction *m_actionOpenLinkNewTab;
QAction *m_actionOpenLinkExternally;
QAction *m_actionOpenImageNewTab;
QAction *m_actionLookupText;
QPoint m_gestureOrigin;
QUrl m_contextLinkUrl;
QUrl m_contextImageUrl;
QWebEnginePage *m_page;
};
#endif // BASEWEBVIEW_H