2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-12-15 18:34:48 +01:00
|
|
|
* Copyright (C) 2010-2011 David Rosca <nowrep@gmail.com>
|
2011-09-23 22:06:21 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-09-18 15:35:44 +02:00
|
|
|
#include "qupzillaschemehandler.h"
|
|
|
|
#include "globalfunctions.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "webpage.h"
|
2011-12-02 23:25:27 +01:00
|
|
|
#include "speeddial.h"
|
2011-12-09 21:56:01 +01:00
|
|
|
#include "pluginproxy.h"
|
2011-09-18 15:35:44 +02:00
|
|
|
|
2011-10-19 16:49:04 +02:00
|
|
|
QString authorString(const QString &name, const QString &mail)
|
|
|
|
{
|
2011-11-12 09:45:32 +01:00
|
|
|
return QString("%1 <<a href=\"mailto:%2\">%2</a>>").arg(name, mail);
|
2011-10-19 16:49:04 +02:00
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
QupZillaSchemeHandler::QupZillaSchemeHandler(QObject* parent)
|
|
|
|
: QObject(parent)
|
2011-09-18 15:35:44 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QNetworkReply* QupZillaSchemeHandler::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
|
|
|
|
{
|
|
|
|
Q_UNUSED(outgoingData)
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (op != QNetworkAccessManager::GetOperation) {
|
2011-09-18 15:35:44 +02:00
|
|
|
return 0;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
|
|
|
QupZillaSchemeReply* reply = new QupZillaSchemeReply(request);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QupZillaSchemeReply::QupZillaSchemeReply(const QNetworkRequest &req, QObject* parent)
|
2011-09-18 15:35:44 +02:00
|
|
|
: QNetworkReply(parent)
|
|
|
|
{
|
|
|
|
setOperation(QNetworkAccessManager::GetOperation);
|
|
|
|
setRequest(req);
|
|
|
|
setUrl(req.url());
|
|
|
|
|
|
|
|
m_pageName = req.url().path();
|
2011-12-02 23:25:27 +01:00
|
|
|
if (m_pageName == "about" || m_pageName == "reportbug" || m_pageName == "start" || m_pageName == "speeddial") {
|
2011-09-18 15:35:44 +02:00
|
|
|
m_buffer.open(QIODevice::ReadWrite);
|
|
|
|
setError(QNetworkReply::NoError, tr("No Error"));
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(loadPage()));
|
|
|
|
open(QIODevice::ReadOnly);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-09-18 15:35:44 +02:00
|
|
|
setError(QNetworkReply::HostNotFoundError, tr("Not Found"));
|
|
|
|
QTimer::singleShot(0, this, SLOT(delayedFinish()));
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 20:49:39 +02:00
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
void QupZillaSchemeReply::loadPage()
|
|
|
|
{
|
|
|
|
QTextStream stream(&m_buffer);
|
2011-12-02 23:25:27 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_pageName == "about") {
|
2011-09-18 15:35:44 +02:00
|
|
|
stream << aboutPage();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (m_pageName == "reportbug") {
|
2011-09-19 20:49:39 +02:00
|
|
|
stream << reportbugPage();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (m_pageName == "start") {
|
2011-10-01 20:06:38 +02:00
|
|
|
stream << startPage();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-02 23:25:27 +01:00
|
|
|
else if (m_pageName == "speeddial") {
|
|
|
|
stream << speeddialPage();
|
|
|
|
}
|
2011-09-18 15:35:44 +02:00
|
|
|
|
|
|
|
stream.flush();
|
|
|
|
m_buffer.reset();
|
|
|
|
|
|
|
|
setHeader(QNetworkRequest::ContentTypeHeader, QByteArray("text/html"));
|
|
|
|
setHeader(QNetworkRequest::ContentLengthHeader, m_buffer.bytesAvailable());
|
|
|
|
setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200);
|
|
|
|
setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QByteArray("Ok"));
|
|
|
|
emit metaDataChanged();
|
|
|
|
emit downloadProgress(m_buffer.size(), m_buffer.size());
|
|
|
|
|
|
|
|
emit readyRead();
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QupZillaSchemeReply::delayedFinish()
|
|
|
|
{
|
|
|
|
emit error(QNetworkReply::HostNotFoundError);
|
|
|
|
emit finished();
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QupZillaSchemeReply::bytesAvailable() const
|
|
|
|
{
|
|
|
|
return m_buffer.bytesAvailable() + QNetworkReply::bytesAvailable();
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
qint64 QupZillaSchemeReply::readData(char* data, qint64 maxSize)
|
2011-09-18 15:35:44 +02:00
|
|
|
{
|
|
|
|
return m_buffer.read(data, maxSize);
|
|
|
|
}
|
|
|
|
|
2011-09-19 20:49:39 +02:00
|
|
|
QString QupZillaSchemeReply::reportbugPage()
|
|
|
|
{
|
2011-12-24 12:21:23 +01:00
|
|
|
static QString bPage;
|
|
|
|
|
|
|
|
if (!bPage.isEmpty()) {
|
|
|
|
return bPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
bPage.append(qz_readAllFileContents(":html/reportbug.html"));
|
|
|
|
bPage.replace("%FAVICON%", "qrc:icons/qupzilla.png");
|
|
|
|
bPage.replace("%BOX-BORDER%", "qrc:html/box-border.png");
|
|
|
|
|
|
|
|
bPage.replace("%TITLE%", tr("Report Issue"));
|
|
|
|
bPage.replace("%REPORT-ISSUE%", tr("Report Issue"));
|
|
|
|
bPage.replace("%PLUGINS-TEXT%", tr("If you are experiencing problems with QupZilla, please try first disable"
|
2011-12-24 13:31:32 +01:00
|
|
|
" all plugins. <br/>If it won't help, then please fill this form: "));
|
2011-12-24 12:21:23 +01:00
|
|
|
bPage.replace("%EMAIL%", tr("Your E-mail"));
|
|
|
|
bPage.replace("%TYPE%", tr("Issue type"));
|
|
|
|
bPage.replace("%DESCRIPTION%", tr("Issue description"));
|
|
|
|
bPage.replace("%SEND%", tr("Send"));
|
|
|
|
bPage.replace("%E-MAIL-OPTIONAL%", tr("E-mail is optional<br/><b>Note: </b>Please use English language only."));
|
|
|
|
bPage.replace("%FIELDS-ARE-REQUIRED%", tr("Please fill all required fields!"));
|
|
|
|
|
|
|
|
return bPage;
|
2011-09-19 20:49:39 +02:00
|
|
|
}
|
|
|
|
|
2011-10-01 20:06:38 +02:00
|
|
|
QString QupZillaSchemeReply::startPage()
|
|
|
|
{
|
2011-12-24 12:21:23 +01:00
|
|
|
static QString sPage;
|
2011-10-01 20:06:38 +02:00
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
if (!sPage.isEmpty()) {
|
|
|
|
return sPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
sPage.append(qz_readAllFileContents(":html/start.html"));
|
|
|
|
sPage.replace("%FAVICON%", "qrc:icons/qupzilla.png");
|
|
|
|
sPage.replace("%BOX-BORDER%", "qrc:html/box-border.png");
|
|
|
|
sPage.replace("%ABOUT-IMG%", "qrc:icons/other/about.png");
|
|
|
|
|
|
|
|
sPage.replace("%TITLE%", tr("Start Page"));
|
|
|
|
sPage.replace("%BUTTON-LABEL%", tr("Google Search"));
|
|
|
|
sPage.replace("%SEARCH-BY-GOOGLE%", tr("Search results provided by Google"));
|
|
|
|
sPage.replace("%WWW%", QupZilla::WIKIADDRESS);
|
|
|
|
sPage.replace("%ABOUT-QUPZILLA%", tr("About QupZilla"));
|
|
|
|
|
|
|
|
return sPage;
|
2011-10-01 20:06:38 +02:00
|
|
|
}
|
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
QString QupZillaSchemeReply::aboutPage()
|
|
|
|
{
|
2011-12-24 12:21:23 +01:00
|
|
|
static QString aPage;
|
|
|
|
|
|
|
|
if (!aPage.isEmpty()) {
|
|
|
|
return aPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPage.append(qz_readAllFileContents(":html/about.html"));
|
|
|
|
aPage.replace("%FAVICON%", "qrc:icons/qupzilla.png");
|
|
|
|
aPage.replace("%BOX-BORDER%", "qrc:html/box-border.png");
|
|
|
|
aPage.replace("%ABOUT-IMG%", "qrc:icons/other/about.png");
|
|
|
|
aPage.replace("%COPYRIGHT-INCLUDE%", Qt::escape(qz_readAllFileContents(":html/copyright")));
|
|
|
|
|
|
|
|
aPage.replace("%TITLE%", tr("About QupZilla"));
|
|
|
|
aPage.replace("%ABOUT-QUPZILLA%", tr("About QupZilla"));
|
|
|
|
aPage.replace("%INFORMATIONS-ABOUT-VERSION%", tr("Informations about version"));
|
|
|
|
aPage.replace("%BROWSER-IDENTIFICATION%", tr("Browser Identification"));
|
|
|
|
aPage.replace("%PATHS%", tr("Paths"));
|
|
|
|
aPage.replace("%COPYRIGHT%", tr("Copyright"));
|
|
|
|
|
|
|
|
aPage.replace("%VERSION-INFO%",
|
2011-12-24 13:31:32 +01:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Version"), QupZilla::VERSION) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("WebKit version"), QupZilla::WEBKITVERSION) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Build time"), QupZilla::BUILDTIME) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Platform"), qz_buildSystem()));
|
2011-12-24 12:21:23 +01:00
|
|
|
aPage.replace("%USER-AGENT%", WebPage::UserAgent);
|
|
|
|
aPage.replace("%PATHS-TEXT%",
|
2011-12-24 13:31:32 +01:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), mApp->getActiveProfilPath()) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Settings"), mApp->getActiveProfilPath() + "settings.ini") +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Saved session"), mApp->getActiveProfilPath() + "session.dat") +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Pinned tabs"), mApp->getActiveProfilPath() + "pinnedtabs.dat") +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Data"), mApp->DATADIR) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Themes"), mApp->THEMESDIR) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Plugins"), mApp->PLUGINSDIR) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Translations"), mApp->TRANSLATIONSDIR));
|
2011-12-24 12:21:23 +01:00
|
|
|
aPage.replace("%MAIN-DEVELOPER%", tr("Main developer"));
|
|
|
|
aPage.replace("%MAIN-DEVELOPER-TEXT%", authorString(QupZilla::AUTHOR, "nowrep@gmail.com"));
|
|
|
|
aPage.replace("%CONTRIBUTORS%", tr("Contributors"));
|
|
|
|
aPage.replace("%CONTRIBUTORS-TEXT%", authorString("Bryan M Dunsmore", "dunsmoreb@gmail.com") + "<br/>" +
|
2011-12-24 13:31:32 +01:00
|
|
|
authorString("Daniele Cocca", "jmc@chakra-project.org") + "<br/>" +
|
|
|
|
authorString("Jan Rajnoha", "honza.rajny@hotmail.com")
|
|
|
|
);
|
2011-12-24 12:21:23 +01:00
|
|
|
aPage.replace("%TRANSLATORS%", tr("Translators"));
|
|
|
|
aPage.replace("%TRANSLATORS-TEXT%", authorString("Heimen Stoffels", "vistausss@gmail.com") + " (Dutch)<br/>" +
|
2011-12-24 13:31:32 +01:00
|
|
|
authorString("Peter Vacula", "pvacula1989@gmail.com") + " (Slovak)<br/>" +
|
|
|
|
authorString("Ján Ďanovský", "dagsoftware@yahoo.com") + " (Slovak)<br/>" +
|
|
|
|
authorString("Jonathan Hooverman", "jonathan.hooverman@gmail.com") + " (German)<br/>" +
|
|
|
|
authorString("Unink-Lio", "unink4451@163.com") + " (Chinese)<br/>" +
|
|
|
|
authorString("Federico Fabiani", "federico.fabiani85@gmail.com") + " (Italy)<br/>" +
|
|
|
|
authorString("Francesco Marinucci", "framarinucci@gmail.com") + " (Italy)<br/>" +
|
|
|
|
authorString("Jorge Sevilla", "jsevi@ozu.es") + " (Spanish)<br/>" +
|
2011-12-25 20:26:55 +01:00
|
|
|
authorString("Michał Szymanowski", "tylkobuba@gmail.com") + " (Polish)<br/>" +
|
|
|
|
authorString("Jérôme Giry", "baikalink@hotmail.fr") + " (French)<br/>" +
|
2011-12-25 22:06:25 +01:00
|
|
|
authorString("Nicolas Ourceau", "lamessen@hotmail.fr") + " (French)<br/>" +
|
2011-12-27 19:10:53 +01:00
|
|
|
authorString("Vasilis Tsivikis", "vasitsiv.dev@gmail.com") + " (Greek)<br/>" +
|
2011-12-28 11:39:34 +01:00
|
|
|
authorString("Alexander Maslov", "it@delta-z.ru") + " (Russian)<br/>" +
|
|
|
|
authorString("Oleg Brezhnev", "oleg-423@yandex.ru") + " (Russian)<br/>"
|
2011-12-24 13:31:32 +01:00
|
|
|
);
|
2011-10-15 13:16:22 +02:00
|
|
|
|
2011-12-24 12:21:23 +01:00
|
|
|
return aPage;
|
2011-09-18 15:35:44 +02:00
|
|
|
}
|
2011-12-02 23:25:27 +01:00
|
|
|
|
|
|
|
QString QupZillaSchemeReply::speeddialPage()
|
|
|
|
{
|
2011-12-24 12:21:23 +01:00
|
|
|
static QString dPage;
|
|
|
|
|
|
|
|
if (dPage.isEmpty()) {
|
|
|
|
dPage.append(qz_readAllFileContents(":html/speeddial.html"));
|
|
|
|
dPage.replace("%FAVICON%", "qrc:icons/qupzilla.png");
|
|
|
|
dPage.replace("%IMG_PLUS%", "qrc:html/plus.png");
|
|
|
|
dPage.replace("%BOX-BORDER%", "qrc:html/box-border-small.png");
|
|
|
|
dPage.replace("%IMG_CLOSE%", "qrc:html/close.png");
|
|
|
|
dPage.replace("%IMG_EDIT%", "qrc:html/edit.png");
|
|
|
|
dPage.replace("%IMG_RELOAD%", "qrc:html/reload.png");
|
|
|
|
|
|
|
|
dPage.replace("%SITE-TITLE%", tr("Speed Dial"));
|
|
|
|
dPage.replace("%ADD-TITLE%", tr("Add New Page"));
|
|
|
|
dPage.replace("%TITLE-EDIT%", tr("Apply"));
|
|
|
|
dPage.replace("%TITLE-REMOVE%", tr("Remove"));
|
|
|
|
dPage.replace("%TITLE-RELOAD%", tr("Reload"));
|
|
|
|
dPage.replace("%TITLE-FETCHTITLE%", tr("Load title from page"));
|
|
|
|
dPage.replace("%JQUERY%", "qrc:html/jquery.js");
|
|
|
|
dPage.replace("%JQUERY-UI%", "qrc:html/jquery-ui.js");
|
|
|
|
dPage.replace("%LOADING-IMG%", "qrc:html/loading.gif");
|
|
|
|
dPage.replace("%URL%", tr("Url"));
|
|
|
|
dPage.replace("%TITLE%", tr("Title"));
|
|
|
|
dPage.replace("%EDIT%", tr("Edit"));
|
|
|
|
dPage.replace("%NEW-PAGE%", tr("New Page"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QString page = dPage;
|
2011-12-02 23:25:27 +01:00
|
|
|
page.replace("%INITIAL-SCRIPT%", mApp->plugins()->speedDial()->initialScript());
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|