File indexing completed on 2024-12-22 04:16:01
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Sharaf Zaman <shzam@sdf.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KISEXIV2IODEVICE_H_ 0008 #define __KISEXIV2IODEVICE_H_ 0009 0010 #include <QFile> 0011 0012 #include <exiv2/exiv2.hpp> 0013 0014 #include <kis_global.h> 0015 0016 #include "kritaexifcommon_export.h" 0017 0018 class KRITAEXIFCOMMON_EXPORT KisExiv2IODevice : public Exiv2::BasicIo 0019 { 0020 public: 0021 #if EXIV2_TEST_VERSION(0,28,0) 0022 using ptr_type = Exiv2::BasicIo::UniquePtr; 0023 #else 0024 using ptr_type = Exiv2::BasicIo::AutoPtr; 0025 #endif 0026 0027 KisExiv2IODevice(QString path); 0028 ~KisExiv2IODevice() override; 0029 0030 int open() override; 0031 int close() override; 0032 #if EXIV2_TEST_VERSION(0,28,0) 0033 size_t write(const Exiv2::byte *data, size_t wcount) override; 0034 size_t write(Exiv2::BasicIo &src) override; 0035 int putb(Exiv2::byte data) override; 0036 Exiv2::DataBuf read(size_t rcount) override; 0037 size_t read(Exiv2::byte *buf, size_t rcount) override; 0038 #else 0039 long write(const Exiv2::byte *data, long wcount) override; 0040 long write(Exiv2::BasicIo &src) override; 0041 int putb(Exiv2::byte data) override; 0042 Exiv2::DataBuf read(long rcount) override; 0043 long read(Exiv2::byte *buf, long rcount) override; 0044 #endif 0045 int getb() override; 0046 void transfer(BasicIo &src) override; 0047 #if defined(_MSC_VER) || EXIV2_TEST_VERSION(0,28,0) 0048 int seek(int64_t offset, Position pos) override; 0049 #else 0050 int seek(long offset, Position pos) override; 0051 #endif 0052 0053 Exiv2::byte *mmap(bool isWriteable = false) override; 0054 #if EXIV2_TEST_VERSION(0,28,0) 0055 void populateFakeData() override; 0056 #endif 0057 int munmap() override; 0058 #if EXIV2_TEST_VERSION(0,28,0) 0059 size_t tell() const override; 0060 #else 0061 long tell() const override; 0062 #endif 0063 size_t size() const override; 0064 bool isopen() const override; 0065 int error() const override; 0066 bool eof() const override; 0067 #if EXIV2_TEST_VERSION(0,28,0) 0068 const std::string& path() const noexcept override; 0069 #else 0070 std::string path() const override; 0071 #endif 0072 0073 private: 0074 bool open(QFile::OpenMode mode); 0075 bool renameToCurrent(const QString srcPath); 0076 QString filePathQString() const; 0077 0078 mutable QFile m_file; 0079 0080 Exiv2::byte *m_mappedArea; 0081 }; 0082 0083 #endif // __KISEXIV2IODEVICE_H_