diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-28 17:39:03 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-28 17:39:03 -0500 |
commit | 876c829512301e3f20161f05d7c193540e6d1710 (patch) | |
tree | 17cb3f1956d88ce87e1bcd980ea67f0592b0bed4 /src/file_dialog.hpp | |
parent | dac2e7507d0172e2a87ed5b2df9c320bc9717da6 (diff) |
Working through file picker.
Diffstat (limited to 'src/file_dialog.hpp')
-rw-r--r-- | src/file_dialog.hpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/file_dialog.hpp b/src/file_dialog.hpp new file mode 100644 index 0000000..9709ec0 --- /dev/null +++ b/src/file_dialog.hpp @@ -0,0 +1,97 @@ +#ifndef FILE_DIALOG_HPP +#define FILE_DIALOG_HPP + +#include <fud_status.hpp> +#include <fud_string.hpp> +#include <fud_directory.hpp> + +#include "bookmouse_time.hpp" +#include <vector> + +namespace bookmouse { + +using DirEntryType = fud::DirectoryEntryType; +struct DialogEntry : public fud::DirectoryEntry { + TimeInfo timeInfo; + fud::String niceTime; + bool selected; + bool valid; + bool gotTime; + + DialogEntry() = default; + DialogEntry(fud::DirectoryEntry&& entry); + + fud::FudStatus formatTime(TimeFormat& format); +}; + +constexpr char DirEntryTypeToChar(DirEntryType entryType) +{ + char entryLetter = 'D'; + switch (entryType) { + case DirEntryType::Directory: + entryLetter = 'D'; + break; + case DirEntryType::RegularFile: + entryLetter = 'F'; + break; + case DirEntryType::Character: + entryLetter = 'F'; + break; + case DirEntryType::UnixSocket: + entryLetter = 'S'; + break; + case DirEntryType::NamedPipe: + entryLetter = 'P'; + break; + case DirEntryType::SymbolicLink: + entryLetter = 'L'; + break; + case DirEntryType::Block: + entryLetter = 'B'; + break; + case DirEntryType::Unknown: + default: + entryLetter = '?'; + break; + } + return entryLetter; +} + +using FilePickerResult = fud::Result< + std::vector<DialogEntry>, + fud::FudStatus>; + +class FileDialog { + +public: + FileDialog( + const fud::String& directoryName, + TimeFormat& timeFormat); + + FilePickerResult pickFiles(); + + constexpr bool valid() const { + return m_valid; + } + +private: + fud::FudStatus getDirectoryContents(); + + fud::String m_directoryName; + fud::Directory m_directory; + TimeFormat& m_timeFormat; + + std::vector<DialogEntry> m_directoryContents{}; + + bool m_valid{false}; + + bool m_typeSelected{false}; + bool m_nameSelectede{false}; + bool m_sizeSelected{false}; + bool m_dateSelected{false}; + +}; + +} // namespace bookmouse + +#endif |