From 876c829512301e3f20161f05d7c193540e6d1710 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sat, 28 Sep 2024 17:39:03 -0500 Subject: Working through file picker. --- src/file_dialog.hpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/file_dialog.hpp (limited to 'src/file_dialog.hpp') 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 +#include +#include + +#include "bookmouse_time.hpp" +#include + +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, + 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 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 -- cgit v1.2.3