Falkon Develop
Cross-platform Qt-based web browser
verticaltabsschemehandler.cpp
Go to the documentation of this file.
1/* ============================================================
2* VerticalTabs plugin for Falkon
3* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19
20#include "qztools.h"
21
22#include <QIcon>
23#include <QUrlQuery>
24#include <QWebEngineUrlRequestJob>
25
28{
29}
30
31void VerticalTabsSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
32{
33 const auto parts = job->requestUrl().path().split(QL1C('/'), Qt::SkipEmptyParts);
34 if (!parts.isEmpty()) {
35 if (parts.at(0) == QL1S("group")) {
36 setReply(job, QByteArrayLiteral("text/html"), groupPage());
37 return;
38 }
39 }
40 setReply(job, QByteArrayLiteral("text/html"), indexPage());
41}
42
43QByteArray VerticalTabsSchemeHandler::indexPage() const
44{
45 QString page = QzTools::readAllFileContents(QSL(":verticaltabs/data/index.html"));
46
47 page.replace(QSL("%NAME%"), tr("Vertical Tabs"));
48
49 return page.toUtf8();
50}
51
52QByteArray VerticalTabsSchemeHandler::groupPage() const
53{
54 QString page = QzTools::readAllFileContents(QSL(":verticaltabs/data/group.html"));
55
56 page.replace(QSL("%FAVICON%"), QzTools::pixmapToDataUrl(QIcon(QSL(":verticaltabs/data/group.svg")).pixmap(16)).toString());
57 page.replace(QSL("%NEW-GROUP%"), tr("New Group"));
58
59 return page.toUtf8();
60}
void setReply(QWebEngineUrlRequestJob *job, const QByteArray &contentType, const QByteArray &content)
static QUrl pixmapToDataUrl(const QPixmap &pix)
Definition: qztools.cpp:83
static QString readAllFileContents(const QString &filename)
Definition: qztools.cpp:98
void requestStarted(QWebEngineUrlRequestJob *job) override
VerticalTabsSchemeHandler(QObject *parent=nullptr)
#define QL1S(x)
Definition: qzcommon.h:44
#define QL1C(x)
Definition: qzcommon.h:48
#define QSL(x)
Definition: qzcommon.h:40