diff options
Diffstat (limited to 'src/archive.hpp')
-rw-r--r-- | src/archive.hpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/archive.hpp b/src/archive.hpp new file mode 100644 index 0000000..d8464e5 --- /dev/null +++ b/src/archive.hpp @@ -0,0 +1,52 @@ +#ifndef ARCHIVE_HPP +#define ARCHIVE_HPP + +#include "result.hpp" + +#include <QtWidgets> +#include <cstdlib> +#include <string> +#include <vector> +#include <zip.h> + +namespace getsuyomi { + +enum class ArchiveError +{ + BadIndex, + ZipError, + BadData, + Unimplemented +}; + +using ArchiveResult = Result<std::reference_wrapper<const QImage>, ArchiveError>; + +class Archive { + public: + virtual ~Archive() = default; + virtual ArchiveResult getPage(size_t page) = 0; + virtual size_t numPages() const = 0; +}; + +class ZipArchive : public Archive { + public: + explicit ZipArchive(const QString& filename); + virtual ~ZipArchive() override; + virtual ArchiveResult getPage(size_t page) override; + virtual size_t numPages() const override; + + private: + void populate(); + + zip_t* m_archive{nullptr}; + + std::vector<size_t> m_sortedIndices{}; + std::vector<std::string> m_filenames{}; + std::vector<size_t> m_fileSizes{}; + + std::vector<std::optional<QImage>> m_pages{}; +}; + +} // namespace getsuyomi + +#endif |