diff options
author | 2024-10-02 20:56:43 +0300 | |
---|---|---|
committer | 2024-11-22 20:48:31 +0300 | |
commit | f271339aa1c9d55c2865b379d39b423faf22365e (patch) | |
tree | e2cb5c2d4b0a2249d40205d3c14d1fbd56ed4949 /src | |
parent | 71a87f8f41c191f4144a556f9158f17640cd5ad6 (diff) | |
download | newsboat-f271339aa1c9d55c2865b379d39b423faf22365e.tar.gz newsboat-f271339aa1c9d55c2865b379d39b423faf22365e.tar.zst newsboat-f271339aa1c9d55c2865b379d39b423faf22365e.zip |
Remove remaining implicit conversions from {File,Dir}BrowserFormAction
Diffstat (limited to 'src')
-rw-r--r-- | src/dirbrowserformaction.cpp | 31 | ||||
-rw-r--r-- | src/filebrowserformaction.cpp | 28 | ||||
-rw-r--r-- | src/filepath.cpp | 20 |
3 files changed, 44 insertions, 35 deletions
diff --git a/src/dirbrowserformaction.cpp b/src/dirbrowserformaction.cpp index 92e26175..49cda190 100644 --- a/src/dirbrowserformaction.cpp +++ b/src/dirbrowserformaction.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "dirbrowserformaction.h" #include <algorithm> @@ -177,31 +175,31 @@ void DirBrowserFormAction::update_title(const Filepath& working_directory) FmtStrFormatter fmt; fmt.register_fmt('N', PROGRAM_NAME); fmt.register_fmt('V', utils::program_version()); - fmt.register_fmt('f', working_directory); + fmt.register_fmt('f', working_directory.display()); set_title(fmt.do_format( cfg->get_configvalue("dirbrowser-title-format"), width)); } -std::vector<std::string> get_sorted_dirlist() +std::vector<Filepath> get_sorted_dirlist() { - std::vector<std::string> ret; + std::vector<Filepath> ret; - const std::string cwdtmp = utils::getcwd(); + const auto cwdtmp = utils::getcwd(); - DIR* dirp = ::opendir(cwdtmp.c_str()); + DIR* dirp = ::opendir(cwdtmp.to_locale_string().c_str()); if (dirp) { struct dirent* de = ::readdir(dirp); while (de) { if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { struct stat sb; - auto dpath = strprintf::fmt( - "%s/%s", cwdtmp, de->d_name); - if (::lstat(dpath.c_str(), &sb) == 0) { + auto entry = Filepath::from_locale_string(de->d_name); + const auto dpath = cwdtmp.join(entry); + if (::lstat(dpath.to_locale_string().c_str(), &sb) == 0) { const auto ftype = file_system::mode_to_filetype(sb.st_mode); if (ftype == file_system::FileType::Directory) { - ret.push_back(de->d_name); + ret.emplace_back(std::move(entry)); } } } @@ -213,8 +211,8 @@ std::vector<std::string> get_sorted_dirlist() std::sort(ret.begin(), ret.end()); - if (cwdtmp != "/") { - ret.insert(ret.begin(), ".."); + if (cwdtmp != Filepath::from_locale_string("/")) { + ret.emplace(ret.begin(), Filepath::from_locale_string("..")); } return ret; @@ -228,14 +226,11 @@ void DirBrowserFormAction::prepare() * in the current directory. */ if (do_redraw) { - const std::string cwdtmp = utils::getcwd(); - update_title(cwdtmp); - - std::vector<std::string> directories = get_sorted_dirlist(); + update_title(utils::getcwd()); id_at_position.clear(); lines.clear(); - for (std::string directory : directories) { + for (auto directory : get_sorted_dirlist()) { add_directory(id_at_position, directory); } diff --git a/src/filebrowserformaction.cpp b/src/filebrowserformaction.cpp index f55debf7..5968823f 100644 --- a/src/filebrowserformaction.cpp +++ b/src/filebrowserformaction.cpp @@ -1,5 +1,3 @@ -#define ENABLE_IMPLICIT_FILEPATH_CONVERSIONS - #include "filebrowserformaction.h" #include <algorithm> @@ -201,25 +199,25 @@ void FileBrowserFormAction::update_title(const Filepath& working_directory) FmtStrFormatter fmt; fmt.register_fmt('N', PROGRAM_NAME); fmt.register_fmt('V', utils::program_version()); - fmt.register_fmt('f', working_directory); + fmt.register_fmt('f', working_directory.display()); set_title(fmt.do_format( cfg->get_configvalue("filebrowser-title-format"), width)); } -std::vector<std::string> get_sorted_filelist() +std::vector<Filepath> get_sorted_filelist() { - std::vector<std::string> ret; + std::vector<Filepath> ret; - const std::string cwdtmp = utils::getcwd(); + const auto cwdtmp = utils::getcwd(); - DIR* dirp = ::opendir(cwdtmp.c_str()); + DIR* dirp = ::opendir(cwdtmp.to_locale_string().c_str()); if (dirp) { struct dirent* de = ::readdir(dirp); while (de) { if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0) { - ret.push_back(de->d_name); + ret.push_back(Filepath::from_locale_string(de->d_name)); } de = ::readdir(dirp); } @@ -228,8 +226,8 @@ std::vector<std::string> get_sorted_filelist() std::sort(ret.begin(), ret.end()); - if (cwdtmp != "/") { - ret.insert(ret.begin(), ".."); + if (cwdtmp != Filepath::from_locale_string("/")) { + ret.emplace(ret.begin(), Filepath::from_locale_string("..")); } return ret; @@ -243,18 +241,14 @@ void FileBrowserFormAction::prepare() * in the current directory. */ if (do_redraw) { - const std::string cwdtmp = utils::getcwd(); - update_title(cwdtmp); - - std::vector<std::string> files = get_sorted_filelist(); + update_title(utils::getcwd()); id_at_position.clear(); lines.clear(); - for (std::string filename : files) { + for (auto filename : get_sorted_filelist()) { add_file(id_at_position, filename); } - auto render_line = [this](std::uint32_t line, std::uint32_t width) -> StflRichText { (void)width; return lines[line]; @@ -295,7 +289,7 @@ void FileBrowserFormAction::init() const int status = ::chdir(save_path.c_str()); LOG(Level::DEBUG, "view::filebrowser: chdir(%s) = %i", save_path, status); - set_value("filenametext", default_filename); + set_value("filenametext", default_filename.to_locale_string()); // Set position to 0 and back to ensure that the text is visible draw_form(); diff --git a/src/filepath.cpp b/src/filepath.cpp index 6ff48526..caaf7da5 100644 --- a/src/filepath.cpp +++ b/src/filepath.cpp @@ -63,6 +63,26 @@ bool Filepath::operator!=(const Filepath& other) const return !(*this == other); } +bool Filepath::operator<(const Filepath& other) const +{ + return filepath::bridged::less_than(*rs_object, *other.rs_object); +} + +bool Filepath::operator<=(const Filepath& other) const +{ + return !(*this > other); +} + +bool Filepath::operator>(const Filepath& other) const +{ + return !(*this < other) && (*this != other); +} + +bool Filepath::operator>=(const Filepath& other) const +{ + return !(*this < other); +} + void Filepath::push(const Filepath& component) { filepath::bridged::push(*rs_object, *component.rs_object); |