diff options
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!"); |
