From 75ec461eeaa851cb5c53f4cfffc434e3e529ed1d Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Mon, 22 Jun 2020 21:10:04 +0200 Subject: Restructures the project source and cleans up a bit --- src/protocols/abouthandler.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/protocols/abouthandler.cpp (limited to 'src/protocols/abouthandler.cpp') diff --git a/src/protocols/abouthandler.cpp b/src/protocols/abouthandler.cpp new file mode 100644 index 0000000..01eefff --- /dev/null +++ b/src/protocols/abouthandler.cpp @@ -0,0 +1,61 @@ +#include "abouthandler.hpp" +#include "kristall.hpp" + +#include +#include + +AboutHandler::AboutHandler() +{ + +} + +bool AboutHandler::supportsScheme(const QString &scheme) const +{ + return (scheme == "about"); +} + +bool AboutHandler::startRequest(const QUrl &url, ProtocolHandler::RequestOptions options) +{ + Q_UNUSED(options) + if (url.path() == "blank") + { + emit this->requestComplete("", "text/gemini"); + } + else if (url.path() == "favourites") + { + QByteArray document; + + document.append("# Favourites\n"); + document.append("\n"); + + for (auto const &fav : global_favourites.getAll()) + { + document.append("=> " + fav.toString().toUtf8() + "\n"); + } + + this->requestComplete(document, "text/gemini"); + } + else + { + QFile file(QString(":/about/%1.gemini").arg(url.path())); + if (file.open(QFile::ReadOnly)) + { + emit this->requestComplete(file.readAll(), "text/gemini"); + } + else + { + emit this->networkError(ResourceNotFound, "The requested resource does not exist."); + } + } + return true; +} + +bool AboutHandler::isInProgress() const +{ + return false; +} + +bool AboutHandler::cancelRequest() +{ + return true; +} -- cgit v1.2.3