mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-13 10:32:11 +01:00
Remove no longer used classes
This commit is contained in:
parent
6d026969f7
commit
dd71761854
|
@ -128,7 +128,6 @@ SOURCES += \
|
||||||
navigation/reloadstopbutton.cpp \
|
navigation/reloadstopbutton.cpp \
|
||||||
navigation/siteicon.cpp \
|
navigation/siteicon.cpp \
|
||||||
navigation/websearchbar.cpp \
|
navigation/websearchbar.cpp \
|
||||||
#network/cabundleupdater.cpp \
|
|
||||||
network/networkmanager.cpp \
|
network/networkmanager.cpp \
|
||||||
network/networkproxyfactory.cpp \
|
network/networkproxyfactory.cpp \
|
||||||
network/networkurlinterceptor.cpp \
|
network/networkurlinterceptor.cpp \
|
||||||
|
@ -152,16 +151,12 @@ SOURCES += \
|
||||||
other/checkboxdialog.cpp \
|
other/checkboxdialog.cpp \
|
||||||
other/iconchooser.cpp \
|
other/iconchooser.cpp \
|
||||||
other/licenseviewer.cpp \
|
other/licenseviewer.cpp \
|
||||||
#other/pagescreen.cpp \
|
|
||||||
other/qzsettings.cpp \
|
other/qzsettings.cpp \
|
||||||
other/siteinfo.cpp \
|
other/siteinfo.cpp \
|
||||||
other/siteinfowidget.cpp \
|
other/siteinfowidget.cpp \
|
||||||
#other/sourceviewer.cpp \
|
|
||||||
#other/sourceviewersearch.cpp \
|
|
||||||
other/statusbarmessage.cpp \
|
other/statusbarmessage.cpp \
|
||||||
other/updater.cpp \
|
other/updater.cpp \
|
||||||
other/useragentmanager.cpp \
|
other/useragentmanager.cpp \
|
||||||
#plugins/clicktoflash.cpp \
|
|
||||||
plugins/pluginproxy.cpp \
|
plugins/pluginproxy.cpp \
|
||||||
plugins/plugins.cpp \
|
plugins/plugins.cpp \
|
||||||
plugins/speeddial.cpp \
|
plugins/speeddial.cpp \
|
||||||
|
@ -322,7 +317,6 @@ HEADERS += \
|
||||||
navigation/reloadstopbutton.h \
|
navigation/reloadstopbutton.h \
|
||||||
navigation/siteicon.h \
|
navigation/siteicon.h \
|
||||||
navigation/websearchbar.h \
|
navigation/websearchbar.h \
|
||||||
#network/cabundleupdater.h \
|
|
||||||
network/networkmanager.h \
|
network/networkmanager.h \
|
||||||
network/networkproxyfactory.h \
|
network/networkproxyfactory.h \
|
||||||
network/networkurlinterceptor.h \
|
network/networkurlinterceptor.h \
|
||||||
|
@ -349,16 +343,12 @@ HEADERS += \
|
||||||
other/checkboxdialog.h \
|
other/checkboxdialog.h \
|
||||||
other/iconchooser.h \
|
other/iconchooser.h \
|
||||||
other/licenseviewer.h \
|
other/licenseviewer.h \
|
||||||
#other/pagescreen.h \
|
|
||||||
other/qzsettings.h \
|
other/qzsettings.h \
|
||||||
other/siteinfo.h \
|
other/siteinfo.h \
|
||||||
other/siteinfowidget.h \
|
other/siteinfowidget.h \
|
||||||
#other/sourceviewer.h \
|
|
||||||
#other/sourceviewersearch.h \
|
|
||||||
other/statusbarmessage.h \
|
other/statusbarmessage.h \
|
||||||
other/updater.h \
|
other/updater.h \
|
||||||
other/useragentmanager.h \
|
other/useragentmanager.h \
|
||||||
#plugins/clicktoflash.h \
|
|
||||||
plugins/plugininterface.h \
|
plugins/plugininterface.h \
|
||||||
plugins/pluginproxy.h \
|
plugins/pluginproxy.h \
|
||||||
plugins/plugins.h \
|
plugins/plugins.h \
|
||||||
|
@ -460,10 +450,8 @@ FORMS += \
|
||||||
other/clearprivatedata.ui \
|
other/clearprivatedata.ui \
|
||||||
other/checkboxdialog.ui \
|
other/checkboxdialog.ui \
|
||||||
other/iconchooser.ui \
|
other/iconchooser.ui \
|
||||||
#other/pagescreen.ui \
|
|
||||||
other/siteinfo.ui \
|
other/siteinfo.ui \
|
||||||
other/siteinfowidget.ui \
|
other/siteinfowidget.ui \
|
||||||
other/sourceviewersearch.ui \
|
|
||||||
preferences/acceptlanguage.ui \
|
preferences/acceptlanguage.ui \
|
||||||
preferences/addacceptlanguage.ui \
|
preferences/addacceptlanguage.ui \
|
||||||
preferences/autofillmanager.ui \
|
preferences/autofillmanager.ui \
|
||||||
|
|
|
@ -1,152 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "cabundleupdater.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "networkmanager.h"
|
|
||||||
#include "browserwindow.h"
|
|
||||||
#include "datapaths.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QFile>
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
CaBundleUpdater::CaBundleUpdater(NetworkManager* manager, QObject* parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_manager(manager)
|
|
||||||
, m_progress(Start)
|
|
||||||
, m_reply(0)
|
|
||||||
, m_latestBundleVersion(0)
|
|
||||||
{
|
|
||||||
m_bundleVersionFileName = DataPaths::path(DataPaths::Config) + QL1S("/certificates/bundle_version");
|
|
||||||
m_bundleFileName = DataPaths::path(DataPaths::Config) + QL1S("/certificates/ca-bundle.crt");
|
|
||||||
m_lastUpdateFileName = DataPaths::path(DataPaths::Config) + QL1S("/certificates/last_update");
|
|
||||||
|
|
||||||
// Make sure the certificates directory exists
|
|
||||||
QDir certDir(DataPaths::path(DataPaths::Config) + QL1S("/certificates"));
|
|
||||||
if (!certDir.exists())
|
|
||||||
certDir.mkpath(certDir.absolutePath());
|
|
||||||
|
|
||||||
int updateTime = 30 * 1000;
|
|
||||||
|
|
||||||
// Check immediately on first run
|
|
||||||
if (!QFile(m_lastUpdateFileName).exists()) {
|
|
||||||
updateTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTimer::singleShot(updateTime, this, SLOT(start()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CaBundleUpdater::start()
|
|
||||||
{
|
|
||||||
QFile updateFile(m_lastUpdateFileName);
|
|
||||||
bool updateNow = false;
|
|
||||||
|
|
||||||
if (updateFile.exists()) {
|
|
||||||
if (updateFile.open(QFile::ReadOnly)) {
|
|
||||||
QDateTime updateTime = QDateTime::fromString(updateFile.readAll());
|
|
||||||
updateNow = updateTime.addDays(5) < QDateTime::currentDateTime();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qWarning() << "CaBundleUpdater::start cannot open file for reading" << m_lastUpdateFileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
updateNow = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateNow) {
|
|
||||||
m_progress = CheckLastUpdate;
|
|
||||||
|
|
||||||
QUrl url = QUrl::fromEncoded(QString(Qz::WWWADDRESS + QL1S("/certs/bundle_version")).toUtf8());
|
|
||||||
m_reply = m_manager->get(QNetworkRequest(url));
|
|
||||||
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CaBundleUpdater::replyFinished()
|
|
||||||
{
|
|
||||||
if (m_progress == CheckLastUpdate) {
|
|
||||||
QByteArray response = m_reply->readAll().trimmed();
|
|
||||||
m_reply->close();
|
|
||||||
m_reply->deleteLater();
|
|
||||||
|
|
||||||
if (m_reply->error() != QNetworkReply::NoError || response.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok;
|
|
||||||
|
|
||||||
m_latestBundleVersion = response.toInt(&ok);
|
|
||||||
if (!ok || m_latestBundleVersion <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int currentBundleVersion = QzTools::readAllFileContents(m_bundleVersionFileName).trimmed().toInt(&ok);
|
|
||||||
if (!ok)
|
|
||||||
currentBundleVersion = 0;
|
|
||||||
|
|
||||||
QFile file(m_lastUpdateFileName);
|
|
||||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
|
||||||
qWarning() << "CaBundleUpdater::replyFinished cannot open file for writing" << m_lastUpdateFileName;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
file.write(QDateTime::currentDateTime().toString().toUtf8());
|
|
||||||
|
|
||||||
if (m_latestBundleVersion > currentBundleVersion) {
|
|
||||||
m_progress = LoadBundle;
|
|
||||||
|
|
||||||
QUrl url = QUrl::fromEncoded(QString(Qz::WWWADDRESS + QL1S("/certs/ca-bundle.crt")).toUtf8());
|
|
||||||
m_reply = m_manager->get(QNetworkRequest(url));
|
|
||||||
connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (m_progress == LoadBundle) {
|
|
||||||
QByteArray response = m_reply->readAll();
|
|
||||||
m_reply->close();
|
|
||||||
m_reply->deleteLater();
|
|
||||||
|
|
||||||
if (m_reply->error() != QNetworkReply::NoError || response.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(m_bundleVersionFileName);
|
|
||||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
|
||||||
qWarning() << "CaBundleUpdater::replyFinished cannot open file for writing" << m_bundleVersionFileName;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.write(QByteArray::number(m_latestBundleVersion));
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
file.setFileName(m_bundleFileName);
|
|
||||||
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
|
|
||||||
qWarning() << "CaBundleUpdater::replyFinished cannot open file for writing" << m_bundleFileName;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.write(response);
|
|
||||||
|
|
||||||
// Reload newly downloaded certificates
|
|
||||||
mApp->networkManager()->loadSettings();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,61 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#ifndef CABUNDLEUPDATER_H
|
|
||||||
#define CABUNDLEUPDATER_H
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "qzcommon.h"
|
|
||||||
|
|
||||||
class QNetworkReply;
|
|
||||||
|
|
||||||
class NetworkManager;
|
|
||||||
|
|
||||||
class QUPZILLA_EXPORT CaBundleUpdater : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit CaBundleUpdater(NetworkManager* manager, QObject* parent = 0);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void start();
|
|
||||||
void replyFinished();
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum Progress { Start, CheckLastUpdate, LoadBundle };
|
|
||||||
|
|
||||||
NetworkManager* m_manager;
|
|
||||||
Progress m_progress;
|
|
||||||
QNetworkReply* m_reply;
|
|
||||||
|
|
||||||
QString m_bundleVersionFileName;
|
|
||||||
QString m_bundleFileName;
|
|
||||||
QString m_lastUpdateFileName;
|
|
||||||
|
|
||||||
int m_latestBundleVersion;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CABUNDLEUPDATER_H
|
|
|
@ -1,236 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "sourceviewer.h"
|
|
||||||
#include "tabbedwebview.h"
|
|
||||||
#include "htmlhighlighter.h"
|
|
||||||
#include "sourceviewersearch.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "enhancedmenu.h"
|
|
||||||
#include "plaineditwithlines.h"
|
|
||||||
|
|
||||||
#include <QBoxLayout>
|
|
||||||
#include <QMenuBar>
|
|
||||||
#include <QStatusBar>
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QInputDialog>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
SourceViewer::SourceViewer(QWebEngineFrame* frame, const QString &selectedHtml)
|
|
||||||
: QWidget(0)
|
|
||||||
, m_frame(frame)
|
|
||||||
, m_selectedHtml(selectedHtml)
|
|
||||||
{
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
setWindowTitle(tr("Source of ") + QzTools::frameUrl(frame).toString());
|
|
||||||
m_layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
|
||||||
m_sourceEdit = new PlainEditWithLines(this);
|
|
||||||
m_sourceEdit->setObjectName("sourceviewer-textedit");
|
|
||||||
m_sourceEdit->setReadOnly(true);
|
|
||||||
m_sourceEdit->setUndoRedoEnabled(false);
|
|
||||||
|
|
||||||
m_statusBar = new QStatusBar(this);
|
|
||||||
m_statusBar->showMessage(QzTools::frameUrl(frame).toString());
|
|
||||||
|
|
||||||
QMenuBar* menuBar = new QMenuBar(this);
|
|
||||||
m_layout->addWidget(m_sourceEdit);
|
|
||||||
m_layout->addWidget(m_statusBar);
|
|
||||||
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
m_layout->setSpacing(0);
|
|
||||||
m_layout->setMenuBar(menuBar);
|
|
||||||
|
|
||||||
QFont font;
|
|
||||||
font.setFamily("Tahoma");
|
|
||||||
font.setFixedPitch(true);
|
|
||||||
font.setPointSize(10);
|
|
||||||
|
|
||||||
m_sourceEdit->setFont(font);
|
|
||||||
new HtmlHighlighter(m_sourceEdit->document());
|
|
||||||
|
|
||||||
resize(650, 600);
|
|
||||||
QzTools::centerWidgetToParent(this, frame->page()->view());
|
|
||||||
|
|
||||||
QMenu* menuFile = new QMenu(tr("File"));
|
|
||||||
menuFile->addAction(tr("Load in page"), this, SLOT(loadInPage()));
|
|
||||||
menuFile->addAction(QIcon::fromTheme("document-save"), tr("Save as..."), this, SLOT(save()))->setShortcut(QKeySequence("Ctrl+S"));
|
|
||||||
menuFile->addSeparator();
|
|
||||||
menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close"), this, SLOT(close()))->setShortcut(QKeySequence("Ctrl+W"));
|
|
||||||
menuBar->addMenu(menuFile);
|
|
||||||
|
|
||||||
QMenu* menuEdit = new QMenu(tr("Edit"));
|
|
||||||
m_actionUndo = menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("Undo"), m_sourceEdit, SLOT(undo()));
|
|
||||||
m_actionRedo = menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("Redo"), m_sourceEdit, SLOT(redo()));
|
|
||||||
menuEdit->addSeparator();
|
|
||||||
m_actionCut = menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("Cut"), m_sourceEdit, SLOT(cut()));
|
|
||||||
m_actionCopy = menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("Copy"), m_sourceEdit, SLOT(copy()));
|
|
||||||
m_actionPaste = menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("Paste"), m_sourceEdit, SLOT(paste()));
|
|
||||||
menuEdit->addSeparator();
|
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select All"), m_sourceEdit, SLOT(selectAll()))->setShortcut(QKeySequence("Ctrl+A"));
|
|
||||||
menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("Find"), this, SLOT(findText()))->setShortcut(QKeySequence("Ctrl+F"));
|
|
||||||
menuEdit->addSeparator();
|
|
||||||
menuEdit->addAction(QIcon::fromTheme("go-jump"), tr("Go to Line..."), this, SLOT(goToLine()))->setShortcut(QKeySequence("Ctrl+L"));
|
|
||||||
menuBar->addMenu(menuEdit);
|
|
||||||
|
|
||||||
m_actionUndo->setShortcut(QKeySequence("Ctrl+Z"));
|
|
||||||
m_actionRedo->setShortcut(QKeySequence("Ctrl+Shift+Z"));
|
|
||||||
m_actionCut->setShortcut(QKeySequence("Ctrl+X"));
|
|
||||||
m_actionCopy->setShortcut(QKeySequence("Ctrl+C"));
|
|
||||||
m_actionPaste->setShortcut(QKeySequence("Ctrl+V"));
|
|
||||||
|
|
||||||
QMenu* menuView = new QMenu(tr("View"));
|
|
||||||
menuView->addAction(QIcon::fromTheme(QSL("view-refresh")), tr("Reload"), this, SLOT(reload()))->setShortcut(QKeySequence("F5"));
|
|
||||||
menuView->addSeparator();
|
|
||||||
menuView->addAction(tr("Editable"), this, SLOT(setTextEditable()))->setCheckable(true);
|
|
||||||
menuView->addAction(tr("Word Wrap"), this, SLOT(setTextWordWrap()))->setCheckable(true);
|
|
||||||
menuView->actions().at(3)->setChecked(true);
|
|
||||||
menuBar->addMenu(menuView);
|
|
||||||
|
|
||||||
connect(m_sourceEdit, SIGNAL(copyAvailable(bool)), this, SLOT(copyAvailable(bool)));
|
|
||||||
connect(m_sourceEdit, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailable(bool)));
|
|
||||||
connect(m_sourceEdit, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailable(bool)));
|
|
||||||
connect(menuEdit, SIGNAL(aboutToShow()), this, SLOT(pasteAvailable()));
|
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(loadSource()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::copyAvailable(bool yes)
|
|
||||||
{
|
|
||||||
m_actionCopy->setEnabled(yes);
|
|
||||||
m_actionCut->setEnabled(yes);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::redoAvailable(bool available)
|
|
||||||
{
|
|
||||||
m_actionRedo->setEnabled(available);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::undoAvailable(bool available)
|
|
||||||
{
|
|
||||||
m_actionUndo->setEnabled(available);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::pasteAvailable()
|
|
||||||
{
|
|
||||||
m_actionPaste->setEnabled(m_sourceEdit->canPaste());
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::loadInPage()
|
|
||||||
{
|
|
||||||
if (m_frame) {
|
|
||||||
m_frame.data()->setHtml(m_sourceEdit->toPlainText(), m_frame.data()->baseUrl());
|
|
||||||
m_statusBar->showMessage(tr("Source loaded in page"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_statusBar->showMessage(tr("Cannot load in page. Page has been closed."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::loadSource()
|
|
||||||
{
|
|
||||||
m_actionUndo->setEnabled(false);
|
|
||||||
m_actionRedo->setEnabled(false);
|
|
||||||
m_actionCut->setEnabled(false);
|
|
||||||
m_actionCopy->setEnabled(false);
|
|
||||||
m_actionPaste->setEnabled(false);
|
|
||||||
|
|
||||||
QString html = m_frame.data()->toHtml();
|
|
||||||
// Remove AdBlock element hiding rules
|
|
||||||
html.remove(QzRegExp("<style type=\"text/css\">\n/\\* AdBlock for QupZilla \\*/\n.*\\{display:none !important;\\}[\n]*</style>"));
|
|
||||||
m_sourceEdit->setPlainText(html);
|
|
||||||
|
|
||||||
// Highlight selectedHtml
|
|
||||||
if (!m_selectedHtml.isEmpty()) {
|
|
||||||
m_sourceEdit->find(m_selectedHtml, QTextDocument::FindWholeWords);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sourceEdit->setShowingCursor(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::save()
|
|
||||||
{
|
|
||||||
QString filePath = QzTools::getSaveFileName("SourceViewer-Save", this, tr("Save file..."), QDir::homePath() + "/source_code.html");
|
|
||||||
if (filePath.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(filePath);
|
|
||||||
if (!file.open(QFile::WriteOnly)) {
|
|
||||||
QMessageBox::critical(this, tr("Error!"), tr("Cannot write to file!"));
|
|
||||||
m_statusBar->showMessage(tr("Error writing to file"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
file.write(m_sourceEdit->toPlainText().toUtf8());
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
m_statusBar->showMessage(tr("Source successfully saved"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::findText()
|
|
||||||
{
|
|
||||||
if (m_layout->count() > 2) {
|
|
||||||
SourceViewerSearch* search = qobject_cast<SourceViewerSearch*>(m_layout->itemAt(1)->widget());
|
|
||||||
search->activateLineEdit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SourceViewerSearch* s = new SourceViewerSearch(this);
|
|
||||||
m_layout->insertWidget(1, s);
|
|
||||||
s->activateLineEdit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::reload()
|
|
||||||
{
|
|
||||||
if (m_frame) {
|
|
||||||
m_sourceEdit->clear();
|
|
||||||
loadSource();
|
|
||||||
|
|
||||||
m_statusBar->showMessage(tr("Source reloaded"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_statusBar->showMessage(tr("Cannot reload source. Page has been closed."));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::setTextEditable()
|
|
||||||
{
|
|
||||||
m_sourceEdit->setReadOnly(!m_sourceEdit->isReadOnly());
|
|
||||||
m_sourceEdit->setUndoRedoEnabled(true);
|
|
||||||
|
|
||||||
m_statusBar->showMessage(tr("Editable changed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::setTextWordWrap()
|
|
||||||
{
|
|
||||||
m_sourceEdit->setWordWrapMode((m_sourceEdit->wordWrapMode() == QTextOption::NoWrap) ? QTextOption::WordWrap : QTextOption::NoWrap);
|
|
||||||
|
|
||||||
m_statusBar->showMessage(tr("Word Wrap changed"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewer::goToLine()
|
|
||||||
{
|
|
||||||
int line = QInputDialog::getInt(this, tr("Go to Line..."), tr("Enter line number"), 0, 1, 5000);
|
|
||||||
if (line == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sourceEdit->goToLine(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,73 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#ifndef SOURCEVIEWER_H
|
|
||||||
#define SOURCEVIEWER_H
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
#include "qzcommon.h"
|
|
||||||
|
|
||||||
class PlainEditWithLines;
|
|
||||||
|
|
||||||
class QBoxLayout;
|
|
||||||
class QStatusBar;
|
|
||||||
class QWebEngineFrame;
|
|
||||||
|
|
||||||
class QUPZILLA_EXPORT SourceViewer : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit SourceViewer(QWebEngineFrame* frame, const QString &selectedHtml);
|
|
||||||
PlainEditWithLines* sourceEdit() { return m_sourceEdit; }
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void copyAvailable(bool yes);
|
|
||||||
void redoAvailable(bool available);
|
|
||||||
void undoAvailable(bool available);
|
|
||||||
void pasteAvailable();
|
|
||||||
|
|
||||||
void loadInPage();
|
|
||||||
void loadSource();
|
|
||||||
void save();
|
|
||||||
void findText();
|
|
||||||
void reload();
|
|
||||||
void setTextEditable();
|
|
||||||
void setTextWordWrap();
|
|
||||||
void goToLine();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QBoxLayout* m_layout;
|
|
||||||
PlainEditWithLines* m_sourceEdit;
|
|
||||||
QPointer<QWebEngineFrame> m_frame;
|
|
||||||
QStatusBar* m_statusBar;
|
|
||||||
|
|
||||||
QString m_selectedHtml;
|
|
||||||
|
|
||||||
QAction* m_actionUndo;
|
|
||||||
QAction* m_actionRedo;
|
|
||||||
QAction* m_actionCut;
|
|
||||||
QAction* m_actionCopy;
|
|
||||||
QAction* m_actionPaste;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // SOURCEVIEWER_H
|
|
|
@ -1,138 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#include "sourceviewersearch.h"
|
|
||||||
#include "ui_sourceviewersearch.h"
|
|
||||||
#include "sourceviewer.h"
|
|
||||||
#include "iconprovider.h"
|
|
||||||
#include "plaineditwithlines.h"
|
|
||||||
|
|
||||||
#include <QShortcut>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
SourceViewerSearch::SourceViewerSearch(SourceViewer* parent)
|
|
||||||
: AnimatedWidget(AnimatedWidget::Up)
|
|
||||||
, m_sourceViewer(parent)
|
|
||||||
, ui(new Ui::SourceViewerSearch)
|
|
||||||
, m_findFlags(0)
|
|
||||||
{
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
ui->setupUi(widget());
|
|
||||||
ui->closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
|
|
||||||
|
|
||||||
ui->next->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowForward));
|
|
||||||
|
|
||||||
ui->previous->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
|
||||||
ui->lineEdit->setFocus();
|
|
||||||
connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide()));
|
|
||||||
connect(ui->lineEdit, SIGNAL(textEdited(QString)), this, SLOT(next()));
|
|
||||||
connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(next()));
|
|
||||||
connect(ui->next, SIGNAL(clicked()), this, SLOT(next()));
|
|
||||||
connect(ui->previous, SIGNAL(clicked()), this, SLOT(previous()));
|
|
||||||
connect(ui->wholeWords, SIGNAL(toggled(bool)), SLOT(searchWholeWords()));
|
|
||||||
connect(this, SIGNAL(performSearch()), SLOT(find()));
|
|
||||||
|
|
||||||
QShortcut* findNextAction = new QShortcut(QKeySequence("F3"), this);
|
|
||||||
connect(findNextAction, SIGNAL(activated()), this, SLOT(next()));
|
|
||||||
|
|
||||||
QShortcut* findPreviousAction = new QShortcut(QKeySequence("Shift+F3"), this);
|
|
||||||
connect(findPreviousAction, SIGNAL(activated()), this, SLOT(previous()));
|
|
||||||
|
|
||||||
startAnimation();
|
|
||||||
parent->installEventFilter(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewerSearch::activateLineEdit()
|
|
||||||
{
|
|
||||||
ui->lineEdit->setFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewerSearch::next()
|
|
||||||
{
|
|
||||||
m_findFlags &= (~QTextDocument::FindBackward);
|
|
||||||
emit performSearch();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewerSearch::previous()
|
|
||||||
{
|
|
||||||
m_findFlags |= QTextDocument::FindBackward;
|
|
||||||
emit performSearch();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewerSearch::searchWholeWords()
|
|
||||||
{
|
|
||||||
if (ui->wholeWords->isChecked()) {
|
|
||||||
m_findFlags |= QTextDocument::FindWholeWords;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_findFlags &= (~QTextDocument::FindWholeWords);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SourceViewerSearch::find()
|
|
||||||
{
|
|
||||||
bool found = find(m_findFlags);
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->lineEdit->setProperty("notfound", QVariant(!found));
|
|
||||||
|
|
||||||
ui->lineEdit->style()->unpolish(ui->lineEdit);
|
|
||||||
ui->lineEdit->style()->polish(ui->lineEdit);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SourceViewerSearch::find(QTextDocument::FindFlags flags)
|
|
||||||
{
|
|
||||||
QString string = ui->lineEdit->text();
|
|
||||||
if (string.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (string != m_lastSearchedString) {
|
|
||||||
QTextCursor cursor = m_sourceViewer->sourceEdit()->textCursor();
|
|
||||||
cursor.setPosition(cursor.selectionStart());
|
|
||||||
cursor.clearSelection();
|
|
||||||
m_sourceViewer->sourceEdit()->setTextCursor(cursor);
|
|
||||||
m_lastSearchedString = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!m_sourceViewer->sourceEdit()->find(string, flags)) {
|
|
||||||
QTextCursor cursor = m_sourceViewer->sourceEdit()->textCursor();
|
|
||||||
m_sourceViewer->sourceEdit()->moveCursor((flags == QTextDocument::FindBackward) ? QTextCursor::End : QTextCursor::Start);
|
|
||||||
if (!m_sourceViewer->sourceEdit()->find(string, flags)) {
|
|
||||||
cursor.clearSelection();
|
|
||||||
m_sourceViewer->sourceEdit()->setTextCursor(cursor);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SourceViewerSearch::eventFilter(QObject* obj, QEvent* event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent*>(event)->key() == Qt::Key_Escape) {
|
|
||||||
hide();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AnimatedWidget::eventFilter(obj, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,66 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
#ifndef SOURCEVIEWERSEARCH_H
|
|
||||||
#define SOURCEVIEWERSEARCH_H
|
|
||||||
|
|
||||||
#include <QTextDocument>
|
|
||||||
|
|
||||||
#include "qzcommon.h"
|
|
||||||
#include "animatedwidget.h"
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
namespace Ui
|
|
||||||
{
|
|
||||||
class SourceViewerSearch;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SourceViewer;
|
|
||||||
|
|
||||||
class QUPZILLA_EXPORT SourceViewerSearch : public AnimatedWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit SourceViewerSearch(SourceViewer* parent = 0);
|
|
||||||
|
|
||||||
void activateLineEdit();
|
|
||||||
bool eventFilter(QObject* obj, QEvent* event);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void performSearch();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void next();
|
|
||||||
void previous();
|
|
||||||
void searchWholeWords();
|
|
||||||
void find();
|
|
||||||
bool find(QTextDocument::FindFlags);
|
|
||||||
|
|
||||||
private:
|
|
||||||
SourceViewer* m_sourceViewer;
|
|
||||||
Ui::SourceViewerSearch* ui;
|
|
||||||
|
|
||||||
QString m_lastSearchedString;
|
|
||||||
QTextDocument::FindFlags m_findFlags;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // SOURCEVIEWERSEARCH_H
|
|
|
@ -1,121 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>SourceViewerSearch</class>
|
|
||||||
<widget class="QWidget" name="SourceViewerSearch">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>677</width>
|
|
||||||
<height>38</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>4</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="MacToolButton" name="closeButton">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="autoRaise">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Search: </string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="FocusSelectLineEdit" name="lineEdit">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>Search...</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="MacToolButton" name="previous">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="autoRaise">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="MacToolButton" name="next">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<property name="autoRaise">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="wholeWords">
|
|
||||||
<property name="text">
|
|
||||||
<string>Whole words</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>MacToolButton</class>
|
|
||||||
<extends>QToolButton</extends>
|
|
||||||
<header>mactoolbutton.h</header>
|
|
||||||
</customwidget>
|
|
||||||
<customwidget>
|
|
||||||
<class>FocusSelectLineEdit</class>
|
|
||||||
<extends>QLineEdit</extends>
|
|
||||||
<header>focusselectlineedit.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
|
@ -1,326 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
/* ============================================================
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 by Benjamin C. Meyer <ben@meyerhome.net>
|
|
||||||
* Copyright (C) 2010 by Matthieu Gicquel <matgic78@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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 2 of
|
|
||||||
* the License or (at your option) version 3 or any later version
|
|
||||||
* accepted by the membership of KDE e.V. (or its successor approved
|
|
||||||
* by the membership of KDE e.V.), which shall act as a proxy
|
|
||||||
* defined in Section 14 of version 3 of the license.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* ============================================================ */
|
|
||||||
#include "clicktoflash.h"
|
|
||||||
#include "clickablelabel.h"
|
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "pluginproxy.h"
|
|
||||||
#include "squeezelabelv2.h"
|
|
||||||
#include "webpage.h"
|
|
||||||
#include "qztools.h"
|
|
||||||
#include "browserwindow.h"
|
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QFormLayout>
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QWebEngineView>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
#include <QWebHitTestResult>
|
|
||||||
|
|
||||||
QUrl ClickToFlash::acceptedUrl;
|
|
||||||
QStringList ClickToFlash::acceptedArgNames;
|
|
||||||
QStringList ClickToFlash::acceptedArgValues;
|
|
||||||
|
|
||||||
ClickToFlash::ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNames, const QStringList &argumentValues, WebPage* parentPage)
|
|
||||||
: QWidget()
|
|
||||||
, m_argumentNames(argumentNames)
|
|
||||||
, m_argumentValues(argumentValues)
|
|
||||||
, m_toolButton(0)
|
|
||||||
, m_layout1(0)
|
|
||||||
, m_layout2(0)
|
|
||||||
, m_frame(0)
|
|
||||||
, m_url(pluginUrl)
|
|
||||||
, m_page(parentPage)
|
|
||||||
{
|
|
||||||
m_layout1 = new QHBoxLayout(this);
|
|
||||||
m_frame = new QFrame(this);
|
|
||||||
m_frame->setObjectName("click2flash-frame");
|
|
||||||
m_frame->setContentsMargins(0, 0, 0, 0);
|
|
||||||
m_layout2 = new QHBoxLayout(m_frame);
|
|
||||||
m_toolButton = new QToolButton(this);
|
|
||||||
m_toolButton->setObjectName("click2flash-toolbutton");
|
|
||||||
|
|
||||||
m_toolButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
m_toolButton->setCursor(Qt::PointingHandCursor);
|
|
||||||
m_layout2->addWidget(m_toolButton);
|
|
||||||
m_layout1->addWidget(m_frame);
|
|
||||||
m_layout1->setContentsMargins(0, 0, 0, 0);
|
|
||||||
m_layout2->setContentsMargins(0, 0, 0, 0);
|
|
||||||
|
|
||||||
connect(m_toolButton, SIGNAL(clicked()), this, SLOT(load()));
|
|
||||||
setMinimumSize(27, 27);
|
|
||||||
|
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
|
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(ensurePluginVisible()));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ClickToFlash::isAlreadyAccepted(const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues)
|
|
||||||
{
|
|
||||||
return (url == acceptedUrl &&
|
|
||||||
argumentNames == acceptedArgNames &&
|
|
||||||
argumentValues == acceptedArgValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::ensurePluginVisible()
|
|
||||||
{
|
|
||||||
// Well, kind of a dirty workaround, but it works.
|
|
||||||
// I don't know any other method how to show our plugin
|
|
||||||
// and adjust it on the proper position in page
|
|
||||||
|
|
||||||
// Scheduling adjustingPage rather than actually changing zoomFactor
|
|
||||||
// right now, as it is CPU intensive when there is lot of click2flash
|
|
||||||
// objects on page
|
|
||||||
|
|
||||||
m_page->scheduleAdjustPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::customContextMenuRequested(const QPoint &pos)
|
|
||||||
{
|
|
||||||
QMenu menu;
|
|
||||||
menu.addAction(tr("Object blocked by ClickToFlash"));
|
|
||||||
menu.addAction(tr("Show more information about object"), this, SLOT(showInfo()));
|
|
||||||
menu.addSeparator();
|
|
||||||
menu.addAction(tr("Delete object"), this, SLOT(hideObject()));
|
|
||||||
menu.addAction(tr("Add %1 to whitelist").arg(m_url.host()), this, SLOT(toWhitelist()));
|
|
||||||
menu.actions().at(0)->setEnabled(false);
|
|
||||||
menu.exec(mapToGlobal(pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::toWhitelist()
|
|
||||||
{
|
|
||||||
mApp->plugins()->c2f_addWhitelist(m_url.host());
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::hideObject()
|
|
||||||
{
|
|
||||||
findElement();
|
|
||||||
if (!m_element.isNull()) {
|
|
||||||
m_element.setStyleProperty("visibility", "hidden");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
//deleteLater(); //Well, it should be there, but therefore it sometimes crashes
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::findElement()
|
|
||||||
{
|
|
||||||
if (!m_toolButton) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget* parent = parentWidget();
|
|
||||||
QWebEngineView* view = 0;
|
|
||||||
while (parent) {
|
|
||||||
if (QWebEngineView* aView = qobject_cast<QWebEngineView*>(parent)) {
|
|
||||||
view = aView;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
parent = parent->parentWidget();
|
|
||||||
}
|
|
||||||
if (!view) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPoint objectPos = view->mapFromGlobal(m_toolButton->mapToGlobal(m_toolButton->pos()));
|
|
||||||
QWebEngineFrame* objectFrame = view->page()->frameAt(objectPos);
|
|
||||||
QWebHitTestResult hitResult;
|
|
||||||
QWebElement hitElement;
|
|
||||||
|
|
||||||
if (objectFrame) {
|
|
||||||
hitResult = objectFrame->hitTestContent(objectPos);
|
|
||||||
hitElement = hitResult.element();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hitElement.isNull() && (hitElement.tagName().compare("embed", Qt::CaseInsensitive) == 0 ||
|
|
||||||
hitElement.tagName().compare("object", Qt::CaseInsensitive) == 0)) {
|
|
||||||
m_element = hitElement;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HitTestResult failed, trying to find element by src
|
|
||||||
// attribute in elements at all frames on page (less accurate)
|
|
||||||
|
|
||||||
QList<QWebEngineFrame*> frames;
|
|
||||||
frames.append(objectFrame);
|
|
||||||
frames.append(view->page()->mainFrame());
|
|
||||||
|
|
||||||
while (!frames.isEmpty()) {
|
|
||||||
QWebEngineFrame* frame = frames.takeFirst();
|
|
||||||
if (!frame) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QWebElement docElement = frame->documentElement();
|
|
||||||
|
|
||||||
QWebElementCollection elements;
|
|
||||||
elements.append(docElement.findAll(QLatin1String("embed")));
|
|
||||||
elements.append(docElement.findAll(QLatin1String("object")));
|
|
||||||
|
|
||||||
foreach (const QWebElement &element, elements) {
|
|
||||||
if (!checkElement(element) && !checkUrlOnElement(element)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
m_element = element;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
frames += frame->childFrames();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::load()
|
|
||||||
{
|
|
||||||
findElement();
|
|
||||||
if (m_element.isNull()) {
|
|
||||||
qWarning("Click2Flash: Cannot find Flash object.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/*
|
|
||||||
Old code caused sometimes flashing of the whole browser window and then somehow
|
|
||||||
ruined rendering of opacity effects, etc..
|
|
||||||
|
|
||||||
QWebElement substitute = m_element.clone();
|
|
||||||
substitute.setAttribute(QLatin1String("type"), "application/futuresplash");
|
|
||||||
m_element.replace(substitute);
|
|
||||||
|
|
||||||
So asynchronous JavaScript code is used to remove element from page and then substitute
|
|
||||||
it with unblocked Flash. The JavaScript code is:
|
|
||||||
|
|
||||||
var qz_c2f_clone = this.cloneNode(true);
|
|
||||||
var qz_c2f_parentNode = this.parentNode;
|
|
||||||
var qz_c2f_substituteElement = document.createElement(this.tagName);
|
|
||||||
|
|
||||||
qz_c2f_substituteElement.width = this.width;
|
|
||||||
qz_c2f_substituteElement.height = this.height;
|
|
||||||
qz_c2f_substituteElement.type = "application/futuresplash";
|
|
||||||
|
|
||||||
this.parentNode.replaceChild(qz_c2f_substituteElement, this);
|
|
||||||
|
|
||||||
setTimeout(function(){
|
|
||||||
qz_c2f_parentNode.replaceChild(qz_c2f_clone, qz_c2f_substituteElement);
|
|
||||||
}, 250);
|
|
||||||
*/
|
|
||||||
|
|
||||||
acceptedUrl = m_url;
|
|
||||||
acceptedArgNames = m_argumentNames;
|
|
||||||
acceptedArgValues = m_argumentValues;
|
|
||||||
|
|
||||||
QString js = "var qz_c2f_clone=this.cloneNode(true);var qz_c2f_parentNode=this.parentNode;"
|
|
||||||
"var qz_c2f_substituteElement=document.createElement(this.tagName);"
|
|
||||||
"qz_c2f_substituteElement.width=this.width;qz_c2f_substituteElement.height=this.height;"
|
|
||||||
"qz_c2f_substituteElement.type=\"application/futuresplash\";"
|
|
||||||
"this.parentNode.replaceChild(qz_c2f_substituteElement,this);setTimeout(function(){"
|
|
||||||
"qz_c2f_parentNode.replaceChild(qz_c2f_clone,qz_c2f_substituteElement);},250);";
|
|
||||||
|
|
||||||
m_element.evaluateJavaScript(js);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ClickToFlash::checkUrlOnElement(QWebElement el)
|
|
||||||
{
|
|
||||||
QString checkString = el.attribute("src");
|
|
||||||
if (checkString.isEmpty()) {
|
|
||||||
checkString = el.attribute("data");
|
|
||||||
}
|
|
||||||
if (checkString.isEmpty()) {
|
|
||||||
checkString = el.attribute("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
checkString = m_page->url().resolved(QUrl(checkString)).toString(QUrl::RemoveQuery);
|
|
||||||
|
|
||||||
return m_url.toEncoded().contains(checkString.toUtf8());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ClickToFlash::checkElement(QWebElement el)
|
|
||||||
{
|
|
||||||
if (m_argumentNames == el.attributeNames()) {
|
|
||||||
foreach (const QString &name, m_argumentNames) {
|
|
||||||
if (m_argumentValues.indexOf(el.attribute(name)) == -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClickToFlash::showInfo()
|
|
||||||
{
|
|
||||||
QWidget* widg = new QWidget();
|
|
||||||
widg->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
widg->setWindowTitle(tr("Flash Object"));
|
|
||||||
QFormLayout* lay = new QFormLayout(widg);
|
|
||||||
QLabel* attrib = new QLabel(tr("<b>Attribute Name</b>"));
|
|
||||||
QLabel* value = new QLabel(tr("<b>Value</b>"));
|
|
||||||
if (isRightToLeft()) {
|
|
||||||
widg->setLayoutDirection(Qt::LeftToRight);
|
|
||||||
attrib->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
||||||
value->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
||||||
}
|
|
||||||
|
|
||||||
lay->addRow(attrib, value);
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
foreach (const QString &name, m_argumentNames) {
|
|
||||||
QString value = m_argumentValues.at(i);
|
|
||||||
SqueezeLabelV2* valueLabel = new SqueezeLabelV2(value);
|
|
||||||
valueLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
|
||||||
|
|
||||||
lay->addRow(new SqueezeLabelV2(name), valueLabel);
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0) {
|
|
||||||
lay->addRow(new QLabel(tr("No more information available.")));
|
|
||||||
}
|
|
||||||
|
|
||||||
widg->setMaximumHeight(500);
|
|
||||||
QzTools::centerWidgetToParent(widg, m_page->view());
|
|
||||||
widg->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,106 +0,0 @@
|
||||||
/* ============================================================
|
|
||||||
* QupZilla - WebKit based browser
|
|
||||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* ============================================================ */
|
|
||||||
/* ============================================================
|
|
||||||
*
|
|
||||||
* Copyright (C) 2009 by Benjamin C. Meyer <ben@meyerhome.net>
|
|
||||||
* Copyright (C) 2010 by Matthieu Gicquel <matgic78@gmail.com>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* This program 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 2 of
|
|
||||||
* the License or (at your option) version 3 or any later version
|
|
||||||
* accepted by the membership of KDE e.V. (or its successor approved
|
|
||||||
* by the membership of KDE e.V.), which shall act as a proxy
|
|
||||||
* defined in Section 14 of version 3 of the license.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* ============================================================ */
|
|
||||||
|
|
||||||
#ifndef CLICKTOFLASH_H
|
|
||||||
#define CLICKTOFLASH_H
|
|
||||||
|
|
||||||
#if QTWEBENGINE_DISABLED
|
|
||||||
|
|
||||||
#include "qzcommon.h"
|
|
||||||
|
|
||||||
// Qt Includes
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QWebElement>
|
|
||||||
|
|
||||||
class QToolButton;
|
|
||||||
class QHBoxLayout;
|
|
||||||
class QFrame;
|
|
||||||
|
|
||||||
class WebPage;
|
|
||||||
|
|
||||||
class QUPZILLA_EXPORT ClickToFlash : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit ClickToFlash(const QUrl &pluginUrl, const QStringList &argumentNames, const QStringList &argumentValues, WebPage* parentPage);
|
|
||||||
|
|
||||||
static bool isAlreadyAccepted(const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void load();
|
|
||||||
void customContextMenuRequested(const QPoint &pos);
|
|
||||||
void toWhitelist();
|
|
||||||
void findElement();
|
|
||||||
|
|
||||||
void hideObject();
|
|
||||||
void showInfo();
|
|
||||||
|
|
||||||
void ensurePluginVisible();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool checkElement(QWebElement el);
|
|
||||||
bool checkUrlOnElement(QWebElement el);
|
|
||||||
QStringList m_argumentNames;
|
|
||||||
QStringList m_argumentValues;
|
|
||||||
QWebElement m_element;
|
|
||||||
|
|
||||||
QToolButton* m_toolButton;
|
|
||||||
QHBoxLayout* m_layout1;
|
|
||||||
QHBoxLayout* m_layout2;
|
|
||||||
QFrame* m_frame;
|
|
||||||
/**
|
|
||||||
used to find the right QWebElement between the ones of the different plugins
|
|
||||||
*/
|
|
||||||
const QUrl m_url;
|
|
||||||
|
|
||||||
static QUrl acceptedUrl;
|
|
||||||
static QStringList acceptedArgNames;
|
|
||||||
static QStringList acceptedArgValues;
|
|
||||||
|
|
||||||
WebPage* m_page;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CLICKTOFLASH_H
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user