From e5814f2bae65e9b757a26e8b263d5e868dbb2f41 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Wed, 30 Dec 2020 16:38:06 +1100 Subject: Add preference to show hidden files in directory listings also improved listing code so that files and dirs with spaces now display and function properly --- src/dialogs/settingsdialog.cpp | 16 ++++++++++++++ src/dialogs/settingsdialog.hpp | 4 ++++ src/dialogs/settingsdialog.ui | 47 +++++++++++++++++++++++++++++++++++------- src/kristall.hpp | 1 + src/main.cpp | 3 +++ src/protocols/filehandler.cpp | 13 ++++++++---- 6 files changed, 73 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/dialogs/settingsdialog.cpp b/src/dialogs/settingsdialog.cpp index 563c728..269a0bd 100644 --- a/src/dialogs/settingsdialog.cpp +++ b/src/dialogs/settingsdialog.cpp @@ -218,6 +218,12 @@ void SettingsDialog::setOptions(const GenericSettings &options) this->ui->scheme_error->setChecked(true); } + if(this->current_options.show_hidden_files_in_dirs) { + this->ui->show_hidden_files->setChecked(true); + } else { + this->ui->hide_hidden_files->setChecked(true); + } + this->ui->max_redirects->setValue(this->current_options.max_redirections); this->ui->redirection_mode->setCurrentIndex(0); @@ -610,6 +616,16 @@ void SettingsDialog::on_scheme_error_clicked() this->current_options.use_os_scheme_handler = false; } +void SettingsDialog::on_show_hidden_files_clicked() +{ + this->current_options.show_hidden_files_in_dirs = true; +} + +void SettingsDialog::on_hide_hidden_files_clicked() +{ + this->current_options.show_hidden_files_in_dirs = false; +} + void SettingsDialog::on_redirection_mode_currentIndexChanged(int index) { this->current_options.redirection_policy = GenericSettings::RedirectionWarning(this->ui->redirection_mode->itemData(index).toInt()); diff --git a/src/dialogs/settingsdialog.hpp b/src/dialogs/settingsdialog.hpp index 671c059..0334ecf 100644 --- a/src/dialogs/settingsdialog.hpp +++ b/src/dialogs/settingsdialog.hpp @@ -114,6 +114,10 @@ private slots: void on_scheme_error_clicked(); + void on_show_hidden_files_clicked(); + + void on_hide_hidden_files_clicked(); + void on_redirection_mode_currentIndexChanged(int index); void on_max_redirects_valueChanged(int arg1); diff --git a/src/dialogs/settingsdialog.ui b/src/dialogs/settingsdialog.ui index 2de52d3..8a84c5f 100644 --- a/src/dialogs/settingsdialog.ui +++ b/src/dialogs/settingsdialog.ui @@ -242,37 +242,68 @@ + + + Hidden files in file:// directories + + + + + + + + + Show + + + hiddenFilesBtnGroup + + + + + + + Hide + + + hiddenFilesBtnGroup + + + + + + Max. Number of Redirections - + 5 - + Redirection Handling - + - + Network Timeout - + ms @@ -285,14 +316,14 @@ - + Additional toolbar buttons - + Home @@ -921,6 +952,8 @@ gophermap_text scheme_os_default scheme_error + show_hidden_files + hide_hidden_files max_redirects redirection_mode network_timeout diff --git a/src/kristall.hpp b/src/kristall.hpp index 2fef256..343a548 100644 --- a/src/kristall.hpp +++ b/src/kristall.hpp @@ -38,6 +38,7 @@ struct GenericSettings TextDisplay text_display = FormattedText; bool enable_text_decoration = false; bool use_os_scheme_handler = false; + bool show_hidden_files_in_dirs = false; TextDisplay gophermap_display = FormattedText; int max_redirections = 5; RedirectionWarning redirection_policy = WarnOnHostChange; diff --git a/src/main.cpp b/src/main.cpp index d658567..8fe2c64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -342,6 +342,8 @@ void GenericSettings::load(QSettings &settings) use_os_scheme_handler = settings.value("use_os_scheme_handler", false).toBool(); + show_hidden_files_in_dirs = settings.value("show_hidden_files_in_dirs", false).toBool(); + max_redirections = settings.value("max_redirections", 5).toInt(); redirection_policy = RedirectionWarning(settings.value("redirection_policy ", WarnOnHostChange).toInt()); @@ -363,6 +365,7 @@ void GenericSettings::save(QSettings &settings) const settings.setValue("theme", theme_name); settings.setValue("gophermap_display", (gophermap_display == FormattedText) ? "rendered" : "text"); settings.setValue("use_os_scheme_handler", use_os_scheme_handler); + settings.setValue("show_hidden_files_in_dirs", show_hidden_files_in_dirs); settings.setValue("max_redirections", max_redirections); settings.setValue("redirection_policy", int(redirection_policy)); settings.setValue("network_timeout", network_timeout); diff --git a/src/protocols/filehandler.cpp b/src/protocols/filehandler.cpp index e31f354..c53b3e1 100644 --- a/src/protocols/filehandler.cpp +++ b/src/protocols/filehandler.cpp @@ -1,5 +1,7 @@ #include "filehandler.hpp" +#include "../kristall.hpp" + #include #include #include @@ -49,14 +51,17 @@ bool FileHandler::startRequest(const QUrl &url, RequestOptions options) QString page; page += QString("# Index of %1\n").arg(url.path()); + auto filters = QDir::Dirs | QDir::Files | QDir::NoDot; + if (kristall::options.show_hidden_files_in_dirs) filters |= QDir::Hidden; + dir.setFilter(filters); + // 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]); + page += QString("=> file://%1 %2\n") + .arg(QUrl(dir.filePath(dir[i])).toString(QUrl::FullyEncoded), + dir[i]); } emit this->requestComplete(page.toUtf8(), "text/gemini"); -- cgit v1.2.3