File indexing completed on 2024-05-19 04:59:22

0001 /* ============================================================
0002 * VerticalTabs plugin for Falkon
0003 * Copyright (C) 2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "verticaltabsschemehandler.h"
0019 
0020 #include "qztools.h"
0021 
0022 #include <QIcon>
0023 #include <QUrlQuery>
0024 #include <QWebEngineUrlRequestJob>
0025 
0026 VerticalTabsSchemeHandler::VerticalTabsSchemeHandler(QObject *parent)
0027     : ExtensionSchemeHandler(parent)
0028 {
0029 }
0030 
0031 void VerticalTabsSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
0032 {
0033     const auto parts = job->requestUrl().path().split(QL1C('/'), Qt::SkipEmptyParts);
0034     if (!parts.isEmpty()) {
0035         if (parts.at(0) == QL1S("group")) {
0036             setReply(job, QByteArrayLiteral("text/html"), groupPage());
0037             return;
0038         }
0039     }
0040     setReply(job, QByteArrayLiteral("text/html"), indexPage());
0041 }
0042 
0043 QByteArray VerticalTabsSchemeHandler::indexPage() const
0044 {
0045     QString page = QzTools::readAllFileContents(QSL(":verticaltabs/data/index.html"));
0046 
0047     page.replace(QSL("%NAME%"), tr("Vertical Tabs"));
0048 
0049     return page.toUtf8();
0050 }
0051 
0052 QByteArray VerticalTabsSchemeHandler::groupPage() const
0053 {
0054     QString page = QzTools::readAllFileContents(QSL(":verticaltabs/data/group.html"));
0055 
0056     page.replace(QSL("%FAVICON%"), QzTools::pixmapToDataUrl(QIcon(QSL(":verticaltabs/data/group.svg")).pixmap(16)).toString());
0057     page.replace(QSL("%NEW-GROUP%"), tr("New Group"));
0058 
0059     return page.toUtf8();
0060 }