aboutsummaryrefslogtreecommitdiff
path: root/src/abouthandler.cpp
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-16 22:01:59 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-16 22:01:59 +0200
commita3f3e3933c4a2522e233917a6795c6e9d677e65c (patch)
tree6e1bd483bbd5e8ca6fee4566e544de48bfa754a6 /src/abouthandler.cpp
parentbc18d9356828f1ae40d3b4ce5432b30ca13cfc15 (diff)
downloadkristall-a3f3e3933c4a2522e233917a6795c6e9d677e65c.tar.gz
Refactoring: Changes internal structure of requests and unifies a lot of code. Now all errors are handled the same.
Diffstat (limited to 'src/abouthandler.cpp')
-rw-r--r--src/abouthandler.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/abouthandler.cpp b/src/abouthandler.cpp
new file mode 100644
index 0000000..a836cf2
--- /dev/null
+++ b/src/abouthandler.cpp
@@ -0,0 +1,60 @@
+#include "abouthandler.hpp"
+#include "kristall.hpp"
+
+#include <QUrl>
+#include <QFile>
+
+AboutHandler::AboutHandler()
+{
+
+}
+
+bool AboutHandler::supportsScheme(const QString &scheme) const
+{
+ return (scheme == "about");
+}
+
+bool AboutHandler::startRequest(const QUrl &url)
+{
+ 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;
+}