File indexing completed on 2025-02-02 04:36:18
0001 /* 0002 * Copyright (C) 2017 Jesse Pullinen <jesse12p@gmail.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 * 0020 */ 0021 0022 #ifndef ACBFBINARY_H 0023 #define ACBFBINARY_H 0024 0025 #include <memory> 0026 0027 #include "AcbfInternalReferenceObject.h" 0028 0029 0030 class QXmlStreamReader; 0031 class QXmlStreamWriter; 0032 0033 /** 0034 * \brief Class for handling the embedded data in ACBF 0035 * 0036 * ACBF allows for embedding images and fonts as Base64 bytearrays. 0037 * 0038 * The images are used to allow ACBF to be standalone. 0039 * 0040 * The fonts are used to indicate the appropriate style 0041 * for text areas. 0042 * 0043 * This class holds the bytearray and mimetype, 0044 * handling reading and loading from the xml. 0045 * 0046 * It does not convert the bytearrays 0047 * to the appropriate object. 0048 */ 0049 0050 namespace AdvancedComicBookFormat 0051 { 0052 class Data; 0053 class Binary : public InternalReferenceObject 0054 { 0055 Q_OBJECT 0056 Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged) 0057 Q_PROPERTY(QString contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged) 0058 Q_PROPERTY(int size READ size NOTIFY dataChanged) 0059 public: 0060 explicit Binary(Data* parent = nullptr); 0061 ~Binary() override; 0062 0063 /** 0064 *\brief Load binary data into xml. 0065 */ 0066 void toXml(QXmlStreamWriter *writer); 0067 0068 /** 0069 * \brief Load binary data from xml. 0070 * @return True if the xmlReader encountered no errors. 0071 */ 0072 bool fromXml(QXmlStreamReader *xmlReader); 0073 0074 /** 0075 * @return The ID of this binary data element as a QString. 0076 * Used to identify it from other parts of the 0077 * ACBF document. 0078 */ 0079 QString id() const; 0080 0081 /** 0082 * \brief Set the ID for this binary element. 0083 * This is used to reference this element from 0084 * other parts of the ACBF document. 0085 * @param newId - The new ID as a string. 0086 */ 0087 void setId(const QString& newId); 0088 Q_SIGNAL void idChanged(); 0089 0090 /** 0091 * @return the mimetype of the binary data as a QString. If one was not defined, the default is application/octet-stream 0092 */ 0093 QString contentType() const; 0094 0095 /** 0096 * \brief Indicate the mimetype of the binary data. 0097 * @param newContentType - the mimetype in string format. 0098 */ 0099 void setContentType(const QString& newContentType); 0100 Q_SIGNAL void contentTypeChanged(); 0101 0102 /** 0103 * @return The binary data as a QByteArray. 0104 */ 0105 QByteArray data() const; 0106 /** 0107 * @return The size of the binary data 0108 */ 0109 int size() const; 0110 0111 /** 0112 * \brief Set the binary data to store in this element. 0113 * 0114 * @param newData - This should be a QByteArray. 0115 */ 0116 void setData(const QByteArray& newData); 0117 /** 0118 * \brief Set the binary data to store in this element from a file. 0119 * Note: This will be read immediately and added with no further checks. 0120 * @param fileName The filename of a file on disk. If the file does not exist, the data will be set to empty. 0121 */ 0122 Q_INVOKABLE void setDataFromFile(const QString& fileName); 0123 /** 0124 * Fired whenever the data contents of the binary changes 0125 */ 0126 Q_SIGNAL void dataChanged(); 0127 0128 /** 0129 * The position of this binary in the list of Binary instances in the 0130 * parent Data instance. 0131 * @return The instance's position 0132 */ 0133 int localIndex() override; 0134 private: 0135 class Private; 0136 std::unique_ptr<Private> d; 0137 }; 0138 } 0139 Q_DECLARE_METATYPE(AdvancedComicBookFormat::Binary*) 0140 0141 #endif // ACBFBINARY_H