35#include <QWebEngineProfile>
36#include <QWebEngineUrlRequestJob>
37#include <QtWebEngineCoreVersion>
40static QString authorString(
const char* name,
const QString &mail)
42 return QSL(
"%1 <<a href=\"mailto:%2\">%2</a>>").arg(QString::fromUtf8(name), mail);
46 : QWebEngineUrlSchemeHandler(parent)
52 if (handleRequest(job)) {
56 QStringList knownPages;
57 knownPages <<
QSL(
"about") <<
QSL(
"start") <<
QSL(
"speeddial") <<
QSL(
"config") <<
QSL(
"restore");
59 if (knownPages.contains(job->requestUrl().path()))
62 job->fail(QWebEngineUrlRequestJob::UrlInvalid);
65bool FalkonSchemeHandler::handleRequest(QWebEngineUrlRequestJob *job)
67 QUrlQuery query(job->requestUrl());
68 if (!query.isEmpty() && job->requestUrl().path() ==
QL1S(
"restore")) {
69 if (
mApp->restoreManager()) {
70 if (query.hasQueryItem(
QSL(
"new-session"))) {
71 mApp->restoreManager()->clearRestoreData();
72 }
else if (query.hasQueryItem(
QSL(
"restore-session"))) {
73 mApp->restoreSession(
nullptr,
mApp->restoreManager()->restoreData());
76 mApp->destroyRestoreManager();
77 job->redirect(QUrl(
QSL(
"falkon:start")));
79 }
else if (job->requestUrl().path() ==
QL1S(
"reportbug")) {
92 m_pageName = m_job->requestUrl().path();
96void FalkonSchemeReply::loadPage()
103 if (m_pageName == QLatin1String(
"about")) {
104 contents = aboutPage();
105 }
else if (m_pageName == QLatin1String(
"start")) {
106 contents = startPage();
107 }
else if (m_pageName == QLatin1String(
"speeddial")) {
108 contents = speeddialPage();
109 }
else if (m_pageName == QLatin1String(
"config")) {
110 contents = configPage();
111 }
else if (m_pageName == QLatin1String(
"restore")) {
112 contents = restorePage();
115 QMutexLocker lock(&m_mutex);
116 m_buffer.setData(contents.toUtf8());
117 m_buffer.open(QIODevice::ReadOnly);
127 QMutexLocker lock(&m_mutex);
128 return m_buffer.bytesAvailable();
133 QMutexLocker lock(&m_mutex);
134 return m_buffer.read(data, maxSize);
145QString FalkonSchemeReply::startPage()
147 static QString sPage;
149 if (!sPage.isEmpty()) {
154 sPage.replace(QLatin1String(
"%ABOUT-IMG%"),
QSL(
"qrc:icons/other/startpage.svg"));
155 sPage.replace(QLatin1String(
"%ABOUT-IMG-DARK%"),
QSL(
"qrc:icons/other/startpage-dark.svg"));
157 sPage.replace(QLatin1String(
"%TITLE%"), tr(
"Start Page"));
158 sPage.replace(QLatin1String(
"%BUTTON-LABEL%"), tr(
"Search on Web"));
159 sPage.replace(QLatin1String(
"%SEARCH-BY%"), tr(
"Search results provided by DuckDuckGo"));
160 sPage.replace(QLatin1String(
"%WWW%"), QString::fromLatin1(
Qz::WIKIADDRESS));
161 sPage.replace(QLatin1String(
"%ABOUT-FALKON%"), tr(
"About Falkon"));
162 sPage.replace(QLatin1String(
"%PRIVATE-BROWSING%"),
mApp->isPrivate() ? tr(
"<h1>Private Browsing</h1>") : QString());
168QString FalkonSchemeReply::aboutPage()
170 static QString aPage;
172 if (aPage.isEmpty()) {
174 aPage.replace(QLatin1String(
"%ABOUT-IMG%"),
QSL(
"qrc:icons/other/about.svg"));
175 aPage.replace(QLatin1String(
"%ABOUT-IMG-DARK%"),
QSL(
"qrc:icons/other/about-dark.svg"));
178 aPage.replace(QLatin1String(
"%TITLE%"), tr(
"About Falkon"));
179 aPage.replace(QLatin1String(
"%ABOUT-FALKON%"), tr(
"About Falkon"));
180 aPage.replace(QLatin1String(
"%INFORMATIONS-ABOUT-VERSION%"), tr(
"Information about version"));
181 aPage.replace(QLatin1String(
"%COPYRIGHT%"), tr(
"Copyright"));
183 aPage.replace(QLatin1String(
"%VERSION-INFO%"),
184 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"Version"),
185#ifdef FALKON_GIT_REVISION
191 aPage.replace(QLatin1String(
"%MAIN-DEVELOPER%"), tr(
"Main developer"));
192 aPage.replace(QLatin1String(
"%MAIN-DEVELOPER-TEXT%"), authorString(
Qz::AUTHOR,
QSL(
"nowrep@gmail.com")));
199QString FalkonSchemeReply::speeddialPage()
201 static QString dPage;
203 if (dPage.isEmpty()) {
205 dPage.replace(QLatin1String(
"%IMG_PLUS%"), QLatin1String(
"qrc:html/plus.svg"));
206 dPage.replace(QLatin1String(
"%IMG_CLOSE%"), QLatin1String(
"qrc:html/close.svg"));
207 dPage.replace(QLatin1String(
"%IMG_EDIT%"), QLatin1String(
"qrc:html/edit.svg"));
208 dPage.replace(QLatin1String(
"%IMG_RELOAD%"), QLatin1String(
"qrc:html/reload.svg"));
209 dPage.replace(QLatin1String(
"%LOADING-IMG%"), QLatin1String(
"qrc:html/loading.gif"));
210 dPage.replace(QLatin1String(
"%IMG_SETTINGS%"), QLatin1String(
"qrc:html/configure.svg"));
212 dPage.replace(QLatin1String(
"%SITE-TITLE%"), tr(
"Speed Dial"));
213 dPage.replace(QLatin1String(
"%ADD-TITLE%"), tr(
"Add New Page"));
214 dPage.replace(QLatin1String(
"%TITLE-EDIT%"), tr(
"Edit"));
215 dPage.replace(QLatin1String(
"%TITLE-REMOVE%"), tr(
"Remove"));
216 dPage.replace(QLatin1String(
"%TITLE-RELOAD%"), tr(
"Reload"));
217 dPage.replace(QLatin1String(
"%TITLE-WARN%"), tr(
"Are you sure you want to remove this speed dial?"));
218 dPage.replace(QLatin1String(
"%TITLE-WARN-REL%"), tr(
"Are you sure you want to reload all speed dials?"));
219 dPage.replace(QLatin1String(
"%TITLE-FETCHTITLE%"), tr(
"Load title from page"));
220 dPage.replace(QLatin1String(
"%JAVASCRIPT-DISABLED%"), tr(
"SpeedDial requires enabled JavaScript."));
221 dPage.replace(QLatin1String(
"%URL%"), tr(
"Url"));
222 dPage.replace(QLatin1String(
"%TITLE%"), tr(
"Title"));
223 dPage.replace(QLatin1String(
"%APPLY%"), tr(
"Apply"));
224 dPage.replace(QLatin1String(
"%CANCEL%"), tr(
"Cancel"));
225 dPage.replace(QLatin1String(
"%NEW-PAGE%"), tr(
"New Page"));
226 dPage.replace(QLatin1String(
"%SETTINGS-TITLE%"), tr(
"Speed Dial settings"));
227 dPage.replace(QLatin1String(
"%TXT_PLACEMENT%"), tr(
"Placement: "));
228 dPage.replace(QLatin1String(
"%TXT_AUTO%"), tr(
"Auto"));
229 dPage.replace(QLatin1String(
"%TXT_COVER%"), tr(
"Cover"));
230 dPage.replace(QLatin1String(
"%TXT_FIT%"), tr(
"Fit"));
231 dPage.replace(QLatin1String(
"%TXT_FWIDTH%"), tr(
"Fit Width"));
232 dPage.replace(QLatin1String(
"%TXT_FHEIGHT%"), tr(
"Fit Height"));
233 dPage.replace(QLatin1String(
"%TXT_NOTE%"), tr(
"Use custom wallpaper"));
234 dPage.replace(QLatin1String(
"%TXT_SELECTIMAGE%"), tr(
"Click to select image"));
235 dPage.replace(QLatin1String(
"%TXT_NRROWS%"), tr(
"Maximum pages in a row:"));
236 dPage.replace(QLatin1String(
"%TXT_SDSIZE%"), tr(
"Change size of pages:"));
237 dPage.replace(QLatin1String(
"%TXT_CNTRDLS%"), tr(
"Center speed dials"));
238 dPage.replace(QLatin1String(
"%TXT_LOCKDIALS%"), tr(
"Lock the position of SpeedDial entries."));
242 QString page = dPage;
245 page.replace(QLatin1String(
"%INITIAL-SCRIPT%"), QString::fromLatin1(dial->
initialScript().toUtf8().toBase64()));
246 page.replace(QLatin1String(
"%IMG_BACKGROUND%"), dial->
backgroundImage());
249 page.replace(QLatin1String(
"%ROW-PAGES%"), QString::number(dial->
pagesInRow()));
250 page.replace(QLatin1String(
"%SD-SIZE%"), QString::number(dial->
sdSize()));
251 page.replace(QLatin1String(
"%SD-CENTER%"), dial->
sdCenter() ?
QSL(
"true") :
QSL(
"false"));
252 page.replace(QLatin1String(
"%LOCK-DIALS%"), dial->
lockDials() ?
QSL(
"true") :
QSL(
"false"));
257QString FalkonSchemeReply::restorePage()
259 static QString rPage;
261 if (rPage.isEmpty()) {
264 rPage.replace(QLatin1String(
"%TITLE%"), tr(
"Restore Session"));
265 rPage.replace(QLatin1String(
"%OOPS%"), tr(
"Oops, Falkon crashed."));
266 rPage.replace(QLatin1String(
"%APOLOGIZE%"), tr(
"We apologize for this. Would you like to restore the last saved state?"));
267 rPage.replace(QLatin1String(
"%TRY-REMOVING%"), tr(
"Try removing one or more tabs that you think cause troubles"));
268 rPage.replace(QLatin1String(
"%START-NEW%"), tr(
"Or you can start completely new session"));
269 rPage.replace(QLatin1String(
"%WINDOW%"), tr(
"Window"));
270 rPage.replace(QLatin1String(
"%WINDOWS-AND-TABS%"), tr(
"Windows and Tabs"));
271 rPage.replace(QLatin1String(
"%BUTTON-START-NEW%"), tr(
"Start New Session"));
272 rPage.replace(QLatin1String(
"%BUTTON-RESTORE%"), tr(
"Restore"));
273 rPage.replace(QLatin1String(
"%JAVASCRIPT-DISABLED%"), tr(
"Requires enabled JavaScript."));
280QString FalkonSchemeReply::configPage()
282 static QString cPage;
284 if (cPage.isEmpty()) {
286 cPage.replace(QLatin1String(
"%ABOUT-IMG%"),
QSL(
"qrc:icons/other/about.svg"));
287 cPage.replace(QLatin1String(
"%ABOUT-IMG-DARK%"),
QSL(
"qrc:icons/other/about-dark.svg"));
289 cPage.replace(QLatin1String(
"%TITLE%"), tr(
"Configuration Information"));
290 cPage.replace(QLatin1String(
"%CONFIG%"), tr(
"Configuration Information"));
291 cPage.replace(QLatin1String(
"%INFORMATIONS-ABOUT-VERSION%"), tr(
"Information about version"));
292 cPage.replace(QLatin1String(
"%CONFIG-ABOUT%"), tr(
"This page contains information about Falkon's current configuration - relevant for troubleshooting. Please include this information when submitting bug reports."));
293 cPage.replace(QLatin1String(
"%BROWSER-IDENTIFICATION%"), tr(
"Browser Identification"));
294 cPage.replace(QLatin1String(
"%PATHS%"), tr(
"Paths"));
295 cPage.replace(QLatin1String(
"%BUILD-CONFIG%"), tr(
"Build Configuration"));
296 cPage.replace(QLatin1String(
"%PREFS%"), tr(
"Preferences"));
297 cPage.replace(QLatin1String(
"%OPTION%"), tr(
"Option"));
298 cPage.replace(QLatin1String(
"%VALUE%"), tr(
"Value"));
299 cPage.replace(QLatin1String(
"%PLUGINS%"), tr(
"Extensions"));
300 cPage.replace(QLatin1String(
"%PL-NAME%"), tr(
"Name"));
301 cPage.replace(QLatin1String(
"%PL-VER%"), tr(
"Version"));
302 cPage.replace(QLatin1String(
"%PL-AUTH%"), tr(
"Author"));
303 cPage.replace(QLatin1String(
"%PL-DESC%"), tr(
"Description"));
308 for (
const QString &path : paths) {
309 if (!out.isEmpty()) {
310 out.append(
QSL(
"<br>"));
317 cPage.replace(QLatin1String(
"%VERSION-INFO%"),
318 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"Application version"),
319#ifdef FALKON_GIT_REVISION
325 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"Qt version"), QString::fromLatin1(qVersion())) +
326 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"QtWebEngine version"),
QSL(QTWEBENGINECORE_VERSION_STR)) +
329 cPage.replace(QLatin1String(
"%PATHS-TEXT%"),
338 QString debugBuild = tr(
"<b>Enabled</b>");
340 QString debugBuild = tr(
"Disabled");
344#if defined(Q_OS_WIN) && defined(W7API)
345 QString w7APIEnabled = tr(
"<b>Enabled</b>");
347 QString w7APIEnabled = tr(
"Disabled");
351 QString portableBuild =
mApp->isPortable() ? tr(
"<b>Enabled</b>") : tr(
"Disabled");
353 cPage.replace(QLatin1String(
"%BUILD-CONFIG-TEXT%"),
354 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"Debug build"), debugBuild) +
356 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"Windows 7 API"), w7APIEnabled) +
358 QSL(
"<dt>%1</dt><dd>%2<dd>").arg(tr(
"Portable build"), portableBuild));
363 QString page = cPage;
364 page.replace(QLatin1String(
"%USER-AGENT%"),
mApp->webProfile()->httpUserAgent());
366 QString pluginsString;
367 const QList<Plugins::Plugin> &availablePlugins =
mApp->plugins()->availablePlugins();
371 pluginsString.append(
QSL(
"<tr><td>%1</td><td>%2</td><td>%3</td><td>%4</td></tr>").arg(
375 if (pluginsString.isEmpty()) {
376 pluginsString =
QSL(
"<tr><td colspan=4 class=\"no-available-plugins\">%1</td></tr>").arg(tr(
"No available extensions."));
379 page.replace(QLatin1String(
"%PLUGINS-INFO%"), pluginsString);
381 QString allGroupsString;
383 const auto groups = settings->childGroups();
384 for (
const QString &group : groups) {
385 QString groupString =
QSL(
"<tr><th colspan=\"2\">[%1]</th></tr>").arg(group);
386 settings->beginGroup(group);
388 const auto keys = settings->childKeys();
389 for (
const QString &key : keys) {
390 const QVariant keyValue = settings->value(key);
393 switch (keyValue.typeId()) {
394 case QMetaType::QByteArray:
395 keyString = QLatin1String(
"QByteArray");
398 case QMetaType::QPoint: {
399 const QPoint point = keyValue.toPoint();
400 keyString =
QSL(
"QPoint(%1, %2)").arg(point.x()).arg(point.y());
404 case QMetaType::QStringList:
405 keyString = keyValue.toStringList().join(
QSL(
","));
409 keyString = keyValue.toString();
412 if (keyString.isEmpty()) {
413 keyString = QLatin1String(
"\"empty\"");
416 groupString.append(
QSL(
"<tr><td>%1</td><td>%2</td></tr>").arg(key, keyString.toHtmlEscaped()));
419 settings->endGroup();
420 allGroupsString.append(groupString);
423 page.replace(QLatin1String(
"%PREFS-INFO%"), allGroupsString);
static QStringList allPaths(Path type)
static QString currentProfilePath()
FalkonSchemeHandler(QObject *parent=nullptr)
void requestStarted(QWebEngineUrlRequestJob *job) Q_DECL_OVERRIDE
FalkonSchemeReply(QWebEngineUrlRequestJob *job, QObject *parent=nullptr)
qint64 writeData(const char *data, qint64 len) Q_DECL_OVERRIDE
qint64 bytesAvailable() const Q_DECL_OVERRIDE
qint64 readData(char *data, qint64 maxSize) Q_DECL_OVERRIDE
static QIcon standardIcon(QStyle::StandardPixmap icon)
static QString defaultSessionPath()
static QSettings * globalSettings()
QString backgroundImageSize()
QString backgroundImageUrl()
QString backgroundImage()
FALKON_EXPORT const char * AUTHOR
FALKON_EXPORT const char * VERSION
FALKON_EXPORT const char * BUGSADDRESS
FALKON_EXPORT const char * WIKIADDRESS