/* ============================================================ * QupZilla - WebKit based browser * Copyright (C) 2010-2012 David Rosca * * 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 . * ============================================================ */ #include "qupzillaschemehandler.h" #include "globalfunctions.h" #include "qupzilla.h" #include "mainapplication.h" #include "tabbedwebview.h" #include "webpage.h" #include "speeddial.h" #include "pluginproxy.h" #include "plugininterface.h" #include "settings.h" #include #include #include #include QString authorString(const char* name, const QString &mail) { return QString("%1 <%2>").arg(QString::fromUtf8(name), mail); } QupZillaSchemeHandler::QupZillaSchemeHandler() { } 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(); QStringList knownPages; knownPages << "about" << "reportbug" << "start" << "speeddial" << "config"; if (knownPages.contains(m_pageName)) { 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())); } } void QupZillaSchemeReply::loadPage() { QTextStream stream(&m_buffer); stream.setCodec("UTF-8"); if (m_pageName == "about") { stream << aboutPage(); } else if (m_pageName == "reportbug") { stream << reportbugPage(); } else if (m_pageName == "start") { stream << startPage(); } else if (m_pageName == "speeddial") { stream << speeddialPage(); } else if (m_pageName == "config") { stream << configPage(); } 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); } QString QupZillaSchemeReply::reportbugPage() { 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 to disable" " all extensions first.
If this does not fix it, then please fill out this form: ")); 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
Note: Please read how to make a bug report here first.").arg("https://github.com/nowrep/QupZilla/wiki/Bug-Reports target=_blank")); bPage.replace("%FIELDS-ARE-REQUIRED%", tr("Please fill out all required fields!")); return bPage; } QString QupZillaSchemeReply::startPage() { static QString sPage; 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; } QString QupZillaSchemeReply::aboutPage() { static QString aPage; if (aPage.isEmpty()) { 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("Information about version")); aPage.replace("%COPYRIGHT%", tr("Copyright")); aPage.replace("%VERSION-INFO%", QString("
%1
%2
").arg(tr("Version"), QupZilla::VERSION #ifdef GIT_REVISION + " (" + GIT_REVISION + ")" #endif ) + QString("
%1
%2
").arg(tr("WebKit version"), QupZilla::WEBKITVERSION)); aPage.replace("%MAIN-DEVELOPER%", tr("Main developer")); aPage.replace("%MAIN-DEVELOPER-TEXT%", authorString(QupZilla::AUTHOR.toUtf8(), "nowrep@gmail.com")); aPage.replace("%CONTRIBUTORS%", tr("Contributors")); aPage.replace("%CONTRIBUTORS-TEXT%", authorString("Mladen Pejaković", "pejakm@gmail.com") + "
" + authorString("Bryan M Dunsmore", "dunsmoreb@gmail.com") + "
" + authorString("Mariusz Fik", "fisiu@opensuse.org") + "
" + authorString("Jan Rajnoha", "honza.rajny@hotmail.com") + "
" + authorString("Daniele Cocca", "jmc@chakra-project.org") ); aPage.replace("%TRANSLATORS%", tr("Translators")); aPage.replace("%TRANSLATORS-TEXT%", authorString("Heimen Stoffels", "vistausss@gmail.com") + " (Dutch)
" + authorString("Peter Vacula", "pvacula1989@gmail.com") + " (Slovak)
" + authorString("Ján Ďanovský", "dagsoftware@yahoo.com") + " (Slovak)
" + authorString("Jonathan Hooverman", "jonathan.hooverman@gmail.com") + " (German)
" + authorString("Federico Fabiani", "federico.fabiani85@gmail.com") + " (Italian)
" + authorString("Francesco Marinucci", "framarinucci@gmail.com") + " (Italian)
" + authorString("Jorge Sevilla", "jsevi@ozu.es") + " (Spanish)
" + authorString("Ștefan Comănescu", "sdfanq@gmail.com") + " (Romanian)
" + authorString("Michał Szymanowski", "tylkobuba@gmail.com") + " (Polish)
" + authorString("Mariusz Fik", "fisiu@opensuse.org") + " (Polish)
" + authorString("Jérôme Giry", "baikalink@hotmail.fr") + " (French)
" + authorString("Nicolas Ourceau", "lamessen@hotmail.fr") + " (French)
" + authorString("Vasilis Tsivikis", "vasitsiv.dev@gmail.com") + " (Greek)
" + authorString("Rustam Salakhutdinov", "salahutd@gmail.com") + " (Russian)
" + authorString("Oleg Brezhnev", "oleg-423@yandex.ru") + " (Russian)
" + authorString("Sérgio Marques", "smarquespt@gmail.com") + " (Portuguese)
" + authorString("Alexandre Carvalho", "alexandre05@live.com") + " (Brazilian Portuguese)
" + authorString("Mladen Pejaković", "pejakm@gmail.com") + " (Serbian)
" + authorString("Unink-Lio", "unink4451@163.com") + " (Chinese)
" + authorString("Wu Cheng-Hong", "stu2731652@gmail.com") + " (Traditional Chinese)
" + authorString("Widya Walesa", "walecha99@gmail.com") + " (Indonesian)
" + authorString("Beqa Arabuli", "arabulibeqa@gmail.com") + " (Georgian)
" + authorString("Daiki Noda", "sys.pdr.pdm9@gmail.com") + " (Japanese)
" + authorString("Gábor Oberle", "oberleg@myopera.com") + " (Hungarian)
" + authorString("Piccoro McKay Lenz", "mckaygerhard@gmail.com") + " (Venezulean Spanish)" ); } return aPage; } QString QupZillaSchemeReply::speeddialPage() { 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("Edit")); 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("%APPLY%", tr("Apply")); dPage.replace("%CLOSE%", tr("Close")); dPage.replace("%NEW-PAGE%", tr("New Page")); dPage.replace("%IMG_SETTINGS%", "qrc:html/setting.png"); dPage.replace("%SETTINGS-TITLE%", tr("Speed Dial settings")); dPage.replace("%TXT_PLACEMENT%", tr("Placement: ")); dPage.replace("%TXT_AUTO%", tr("Auto")); dPage.replace("%TXT_COVER%", tr("Cover")); dPage.replace("%TXT_FIT%", tr("Fit")); dPage.replace("%TXT_FWIDTH%", tr("Fit Width")); dPage.replace("%TXT_FHEIGHT%", tr("Fit Height")); dPage.replace("%TXT_NOTE%", tr("Use background image")); dPage.replace("%TXT_SELECTIMAGE%", tr("Select image")); dPage.replace("%TXT_NRROWS%", tr("Maximum pages in a row:")); dPage.replace("%TXT_SDSIZE%", tr("Change size of pages:")); } QString page = dPage; SpeedDial* dial = mApp->plugins()->speedDial(); page.replace("%INITIAL-SCRIPT%", dial->initialScript()); page.replace("%IMG_BACKGROUND%", dial->backgroundImage()); page.replace("%B_SIZE%", dial->backgroundImageSize()); page.replace("%ROW-PAGES%", QString::number(dial->pagesInRow())); page.replace("%SD-SIZE%", QString::number(dial->sdSize())); return page; } QString QupZillaSchemeReply::configPage() { static QString cPage; if (cPage.isEmpty()) { cPage.append(qz_readAllFileContents(":html/config.html")); cPage.replace("%FAVICON%", "qrc:icons/qupzilla.png"); cPage.replace("%BOX-BORDER%", "qrc:html/box-border.png"); cPage.replace("%ABOUT-IMG%", "qrc:icons/other/about.png"); cPage.replace("%TITLE%", tr("Configuration Information")); cPage.replace("%CONFIG%", tr("Configuration Information")); cPage.replace("%INFORMATIONS-ABOUT-VERSION%", tr("Information about version")); cPage.replace("%CONFIG-ABOUT%", tr("This page contains information about QupZilla's current configuration - relevant for troubleshooting. Please include this information when submitting bug reports.")); cPage.replace("%BROWSER-IDENTIFICATION%", tr("Browser Identification")); cPage.replace("%PATHS%", tr("Paths")); cPage.replace("%BUILD-CONFIG%", tr("Build Configuration")); cPage.replace("%PREFS%", tr("Preferences")); cPage.replace("%OPTION%", tr("Option")); cPage.replace("%VALUE%", tr("Value")); cPage.replace("%PLUGINS%", tr("Extensions")); cPage.replace("%PL-NAME%", tr("Name")); cPage.replace("%PL-VER%", tr("Version")); cPage.replace("%PL-AUTH%", tr("Author")); cPage.replace("%PL-DESC%", tr("Description")); cPage.replace("%VERSION-INFO%", QString("
%1
%2
").arg(tr("Application version"), QupZilla::VERSION #ifdef GIT_REVISION + " (" + GIT_REVISION + ")" #endif ) + QString("
%1
%2
").arg(tr("Qt version"), QT_VERSION_STR) + QString("
%1
%2
").arg(tr("WebKit version"), QupZilla::WEBKITVERSION) + QString("
%1
%2
").arg(tr("Build time"), QupZilla::BUILDTIME) + QString("
%1
%2
").arg(tr("Platform"), qz_buildSystem())); cPage.replace("%PATHS-TEXT%", QString("
%1
%2
").arg(tr("Profile"), mApp->currentProfilePath()) + QString("
%1
%2
").arg(tr("Settings"), mApp->currentProfilePath() + "settings.ini") + QString("
%1
%2
").arg(tr("Saved session"), mApp->currentProfilePath() + "session.dat") + QString("
%1
%2
").arg(tr("Pinned tabs"), mApp->currentProfilePath() + "pinnedtabs.dat") + QString("
%1
%2
").arg(tr("Data"), mApp->DATADIR) + QString("
%1
%2
").arg(tr("Themes"), mApp->THEMESDIR) + QString("
%1
%2
").arg(tr("Translations"), mApp->TRANSLATIONSDIR)); QString debugBuild = tr("Disabled"); QString webGLEnabled = tr("Disabled"); QString w7APIEnabled = tr("Disabled"); QString KDEIntegration = tr("Disabled"); QString portableBuild = tr("Disabled"); #ifdef QUPZILLA_DEBUG_BUILD debugBuild = tr("Enabled"); #endif #ifdef USE_WEBGL webGLEnabled = tr("Enabled"); #endif #if defined(Q_WS_WIN) && defined(W7API) w7APIEnabled = tr("Enabled"); #endif #if defined(Q_WS_X11) && defined(KDE) KDEIntegration = tr("Enabled"); #endif #ifdef PORTABLE_BUILD portableBuild = tr("Enabled"); #endif cPage.replace("%BUILD-CONFIG-TEXT%", QString("
%1
%2
").arg(tr("Debug build"), debugBuild) + QString("
%1
%2
").arg(tr("WebGL support"), webGLEnabled) + QString("
%1
%2
").arg(tr("Windows 7 API"), w7APIEnabled) + QString("
%1
%2
").arg(tr("KDE integration"), KDEIntegration) + QString("
%1
%2
").arg(tr("Portable build"), portableBuild)); } QString page = cPage; page.replace("%USER-AGENT%", mApp->getWindow()->weView()->page()->userAgentForUrl(QUrl())); QString pluginsString; const QList &availablePlugins = mApp->plugins()->getAvailablePlugins(); foreach(const Plugins::Plugin & plugin, availablePlugins) { PluginSpec spec = plugin.pluginSpec; pluginsString.append(QString("%1%2%3%4").arg( spec.name, spec.version, Qt::escape(spec.author), spec.description)); } if (pluginsString.isEmpty()) { pluginsString = QString("%1").arg(tr("No available extensions.")); } page.replace("%PLUGINS-INFO%", pluginsString); QString allGroupsString; QSettings* settings = Settings::globalSettings(); foreach(const QString & group, settings->childGroups()) { QString groupString = QString("[%1]").arg(group); settings->beginGroup(group); foreach(const QString & key, settings->childKeys()) { const QVariant &keyValue = settings->value(key); QString keyString; switch (keyValue.type()) { case QVariant::ByteArray: keyString = "QByteArray"; break; case QVariant::Point: { const QPoint point = keyValue.toPoint(); keyString = QString("QPoint(%1, %2)").arg(QString::number(point.x()), QString::number(point.y())); break; } case QVariant::StringList: keyString = keyValue.toStringList().join(","); break; default: keyString = keyValue.toString(); } if (keyString.isEmpty()) { keyString = "\"empty\""; } groupString.append(QString("%1%2").arg(key, Qt::escape(keyString))); } settings->endGroup(); allGroupsString.append(groupString); } page.replace("%PREFS-INFO%", allGroupsString); return page; }