summaryrefslogtreecommitdiff
path: root/src/archive.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-09-18 21:59:54 -0500
committerDominick Allen <djallen@librehumanitas.org>2024-09-18 21:59:54 -0500
commitfa4b4097d3283e1d6e6376c70910e245f0b1f6ec (patch)
tree74dff4ded82d3f4854b3f10d5dd2e5be1f69b95e /src/archive.hpp
parent04dbfdc97e94e6f477675b9d3135164752a7cfef (diff)
Save progress of qt6 implementation.
Diffstat (limited to 'src/archive.hpp')
-rw-r--r--src/archive.hpp52
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