2011-09-23 22:06:21 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-10-17 09:57:07 +02:00
|
|
|
* Copyright (C) 2010-2011 David Rosca
|
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-10-19 16:49:04 +02:00
|
|
|
QString authorString(const QString &name, const QString &mail)
|
|
|
|
{
|
|
|
|
return QString("%1 <<a href=mailto:%2>%2</a>>").arg(name, mail);
|
|
|
|
}
|
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
QupZillaSchemeHandler::QupZillaSchemeHandler(QObject* parent) :
|
|
|
|
QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QNetworkReply* QupZillaSchemeHandler::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice* outgoingData)
|
|
|
|
{
|
|
|
|
Q_UNUSED(outgoingData)
|
|
|
|
|
|
|
|
if (op != QNetworkAccessManager::GetOperation)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
QupZillaSchemeReply* reply = new QupZillaSchemeReply(request);
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
QupZillaSchemeReply::QupZillaSchemeReply(const QNetworkRequest &req, QObject *parent)
|
|
|
|
: QNetworkReply(parent)
|
|
|
|
{
|
|
|
|
setOperation(QNetworkAccessManager::GetOperation);
|
|
|
|
setRequest(req);
|
|
|
|
setUrl(req.url());
|
|
|
|
|
|
|
|
m_pageName = req.url().path();
|
2011-10-01 20:06:38 +02:00
|
|
|
if (m_pageName == "about" || m_pageName == "reportbug" || m_pageName == "start") {
|
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);
|
|
|
|
} else {
|
|
|
|
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);
|
|
|
|
if (m_pageName == "about")
|
|
|
|
stream << aboutPage();
|
2011-09-19 20:49:39 +02:00
|
|
|
else if (m_pageName == "reportbug")
|
|
|
|
stream << reportbugPage();
|
2011-10-01 20:06:38 +02:00
|
|
|
else if (m_pageName == "start")
|
|
|
|
stream << startPage();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QupZillaSchemeReply::readData(char *data, qint64 maxSize)
|
|
|
|
{
|
|
|
|
return m_buffer.read(data, maxSize);
|
|
|
|
}
|
|
|
|
|
2011-09-19 20:49:39 +02:00
|
|
|
QString QupZillaSchemeReply::reportbugPage()
|
|
|
|
{
|
|
|
|
QString page;
|
|
|
|
page.append(qz_readAllFileContents(":html/reportbug.html"));
|
|
|
|
page.replace("%FAVICON%", qz_pixmapToByteArray(QPixmap(":icons/qupzilla.png")));
|
|
|
|
page.replace("%BOX-BORDER%", qz_pixmapToByteArray(QPixmap(":html/box-border.png")));
|
|
|
|
|
|
|
|
page.replace("%TITLE%", tr("Report issue"));
|
|
|
|
page.replace("%REPORT-ISSUE%", tr("Report issue"));
|
2011-10-21 22:33:10 +02:00
|
|
|
page.replace("%PLUGINS-TEXT%", tr("If you are experiencing problems with QupZilla, please try first disable"
|
2011-09-19 20:49:39 +02:00
|
|
|
" all plugins. <br/>If it won't help, then please fill this form: "));
|
|
|
|
page.replace("%EMAIL%", tr("Your E-mail"));
|
|
|
|
page.replace("%TYPE%", tr("Issue type"));
|
|
|
|
page.replace("%PRIORITY%", tr("Priority"));
|
|
|
|
page.replace("%LOW%", tr("Low"));
|
|
|
|
page.replace("%NORMAL%", tr("Normal"));
|
|
|
|
page.replace("%HIGH%", tr("High"));
|
|
|
|
page.replace("%DESCRIPTION%", tr("Issue description"));
|
|
|
|
page.replace("%SEND%", tr("Send"));
|
|
|
|
page.replace("%E-MAIL-OPTIONAL%", tr("E-mail is optional"));
|
|
|
|
page.replace("%FIELDS-ARE-REQUIRED%", tr("Please fill all required fields!"));
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2011-10-01 20:06:38 +02:00
|
|
|
QString QupZillaSchemeReply::startPage()
|
|
|
|
{
|
|
|
|
QString page;
|
|
|
|
page.append(qz_readAllFileContents(":html/start.html"));
|
|
|
|
page.replace("%FAVICON%", qz_pixmapToByteArray(QPixmap(":icons/qupzilla.png")));
|
|
|
|
page.replace("%BOX-BORDER%", qz_pixmapToByteArray(QPixmap(":html/box-border.png")));
|
|
|
|
page.replace("%ABOUT-IMG%", qz_pixmapToByteArray(QPixmap(":icons/other/about.png")));
|
|
|
|
|
|
|
|
page.replace("%TITLE%", tr("Start Page"));
|
|
|
|
page.replace("%BUTTON-LABEL%", tr("Google Search"));
|
|
|
|
page.replace("%SEARCH-BY-GOOGLE%", tr("Search results provided by Google"));
|
2011-10-02 17:39:59 +02:00
|
|
|
page.replace("%WWW%", QupZilla::WIKIADDRESS);
|
2011-10-01 20:06:38 +02:00
|
|
|
page.replace("%ABOUT-QUPZILLA%", tr("About QupZilla"));
|
|
|
|
|
|
|
|
return page;
|
|
|
|
}
|
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
QString QupZillaSchemeReply::aboutPage()
|
|
|
|
{
|
|
|
|
QString page;
|
|
|
|
page.append(qz_readAllFileContents(":html/about.html"));
|
|
|
|
page.replace("%FAVICON%", qz_pixmapToByteArray(QPixmap(":icons/qupzilla.png")));
|
|
|
|
page.replace("%BOX-BORDER%", qz_pixmapToByteArray(QPixmap(":html/box-border.png")));
|
|
|
|
page.replace("%ABOUT-IMG%", qz_pixmapToByteArray(QPixmap(":icons/other/about.png")));
|
|
|
|
page.replace("%COPYRIGHT-INCLUDE%", qz_readAllFileContents(":html/copyright"));
|
|
|
|
|
|
|
|
page.replace("%TITLE%", tr("About QupZilla"));
|
|
|
|
page.replace("%ABOUT-QUPZILLA%", tr("About QupZilla"));
|
|
|
|
page.replace("%INFORMATIONS-ABOUT-VERSION%", tr("Informations about version"));
|
|
|
|
page.replace("%BROWSER-IDENTIFICATION%", tr("Browser Identification"));
|
|
|
|
page.replace("%PATHS%", tr("Paths"));
|
|
|
|
page.replace("%COPYRIGHT%", tr("Copyright"));
|
|
|
|
|
|
|
|
page.replace("%VERSION-INFO%",
|
|
|
|
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) +
|
2011-10-07 15:37:49 +02:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Platform"), qz_buildSystem()));
|
2011-09-18 15:35:44 +02:00
|
|
|
page.replace("%USER-AGENT%", mApp->getWindow()->weView()->webPage()->userAgentForUrl(QUrl()));
|
|
|
|
page.replace("%PATHS-TEXT%",
|
2011-10-15 13:16:22 +02:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Profile"), mApp->getActiveProfilPath()) +
|
2011-09-18 15:35:44 +02:00
|
|
|
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") +
|
2011-10-15 13:16:22 +02:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Data"), mApp->DATADIR) +
|
2011-09-18 15:35:44 +02:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Themes"), mApp->THEMESDIR) +
|
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Plugins"), mApp->PLUGINSDIR) +
|
2011-10-07 15:37:49 +02:00
|
|
|
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Translations"), mApp->TRANSLATIONSDIR));
|
2011-10-15 13:16:22 +02:00
|
|
|
page.replace("%MAIN-DEVELOPER%", tr("Main developer"));
|
2011-10-19 16:49:04 +02:00
|
|
|
page.replace("%MAIN-DEVELOPER-TEXT%", authorString(QupZilla::AUTHOR, "nowrep@gmail.com"));
|
2011-10-15 13:16:22 +02:00
|
|
|
page.replace("%CONTRIBUTORS%", tr("Contributors"));
|
2011-10-19 16:49:04 +02:00
|
|
|
page.replace("%CONTRIBUTORS-TEXT%", authorString("Daniele Cocca", "jmc@chakra-project.org") + "<br/>" +
|
|
|
|
authorString("Jan Rajnoha", "honza.rajny@hotmail.com")
|
|
|
|
);
|
2011-10-15 13:16:22 +02:00
|
|
|
page.replace("%TRANSLATORS%", tr("Translators"));
|
2011-10-19 16:49:04 +02:00
|
|
|
page.replace("%TRANSLATORS-TEXT%", authorString("Heimen Stoffels", "vistausss@gmail.com") + " (Dutch)<br/>" +
|
|
|
|
authorString("Peter Vacula", "pvacula1989@gmail.com") + " (Slovak)<br/>" +
|
2011-10-21 22:33:10 +02:00
|
|
|
authorString("Ján Ďanovský", "dagsoftware@yahoo.com") + " (Slovak)<br/>" +
|
2011-10-20 17:56:01 +02:00
|
|
|
authorString("Jonathan Hooverman", "jonathan.hooverman@gmail.com") + " (German)<br/>" +
|
2011-11-05 10:22:24 +01:00
|
|
|
authorString("Unink-Lio", "unink4451@163.com") + " (Chinese)<br/>" +
|
|
|
|
authorString("Federico Fabiani", "federico.fabiani85@gmail.com") + " (Italy)<br/>" +
|
|
|
|
authorString("Francesco Marinucci", "framarinucci@gmail.com") + " (Italy)"
|
|
|
|
);
|
2011-10-15 13:16:22 +02:00
|
|
|
|
2011-09-18 15:35:44 +02:00
|
|
|
return page;
|
|
|
|
}
|