diff options
| author | Mike Skec <skec@protonmail.ch> | 2020-12-30 15:36:04 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2020-12-30 11:10:54 +0100 |
| commit | 91c794d3a6341048b4b38eafbb7ae286aad53f68 (patch) | |
| tree | 0b41b05cb00ec9fff0d085d0779ba1f6b8ef0e5f /src/protocols/filehandler.cpp | |
| parent | 4c24c4a2fbd47115fb5a4449172723ace7059ce1 (diff) | |
Now support file:// directory listings
Diffstat (limited to 'src/protocols/filehandler.cpp')
| -rw-r--r-- | src/protocols/filehandler.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
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 <QUrl> #include <QFile> #include <QFileInfo> +#include <QDir> 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!"); |
