From 91c794d3a6341048b4b38eafbb7ae286aad53f68 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Wed, 30 Dec 2020 15:36:04 +1100 Subject: Now support file:// directory listings --- src/protocols/filehandler.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/protocols') diff --git a/src/protocols/filehandler.cpp b/src/protocols/filehandler.cpp index d53f13b..e31f354 100644 --- a/src/protocols/filehandler.cpp +++ b/src/protocols/filehandler.cpp @@ -4,6 +4,7 @@ #include #include #include +#include FileHandler::FileHandler() { @@ -41,6 +42,25 @@ bool FileHandler::startRequest(const QUrl &url, RequestOptions options) emit this->requestComplete(data, mime); } + else if (QDir dir = QDir(url.path()); dir.exists()) + { + // URL points to directory - we create Gemtext + // page which lists contents of directory. + QString page; + page += QString("# Index of %1\n").arg(url.path()); + + // Iterate over files in the directory, and add links to each. + for (unsigned i = 0; i < dir.count(); ++i) + { + // Skip '.' directory. + if (dir[i] == ".") continue; + + // Add link to page. + page += QString("=> file://%1 %2\n").arg(dir.filePath(dir[i]), dir[i]); + } + + emit this->requestComplete(page.toUtf8(), "text/gemini"); + } else { emit this->networkError(ResourceNotFound, "The requested file does not exist!"); -- cgit v1.2.3