aboutsummaryrefslogtreecommitdiff
path: root/src/schemes/NullSchemeHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/schemes/NullSchemeHandler.cpp')
-rw-r--r--src/schemes/NullSchemeHandler.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/schemes/NullSchemeHandler.cpp b/src/schemes/NullSchemeHandler.cpp
new file mode 100644
index 0000000..203e673
--- /dev/null
+++ b/src/schemes/NullSchemeHandler.cpp
@@ -0,0 +1,46 @@
+#include "NullSchemeHandler.hpp"
+#include <qstringview.h>
+#include <qwebengineurlrequestjob.h>
+
+void NullSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job) {
+ auto url = job->requestUrl();
+
+ if (url.host() == "docs") {
+ QBuffer *buffer = new QBuffer(job);
+ buffer->setData(read_static_docs_file(url.path()));
+ buffer->open(QIODevice::ReadOnly);
+ job->reply(get_content_type(url.path()), buffer);
+ } else {
+ job->reply("text/html", new QBuffer(job));
+ }
+}
+
+QByteArray NullSchemeHandler::read_static_docs_file(const QString &path) {
+ QFile file(NULL_DOCS_DIR + path);
+ if (!file.exists())
+ return read_index_html();
+
+ if (file.open(QIODevice::ReadOnly)) {
+ auto contents = file.readAll();
+ file.close();
+ return contents;
+ }
+ return QByteArray{};
+}
+
+QByteArray NullSchemeHandler::read_index_html() {
+ QFile file(NULL_DOCS_DIR + QString("/index.html"));
+ qDebug() << ":::" << file.exists();
+ if (file.open(QIODevice::ReadOnly)) {
+ auto contents = file.readAll();
+ file.close();
+ return contents;
+ }
+ return QByteArray{};
+}
+
+QByteArray NullSchemeHandler::get_content_type(const QString &path) {
+ if (path.endsWith(".css"))
+ return "text/css";
+ return "text/html";
+}