diff options
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 |