Changeset View
Changeset View
Standalone View
Standalone View
src/qtquick/ArchiveBookModel.h
Show All 17 Lines | |||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | * | 19 | * | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #ifndef ARCHIVEBOOKMODEL_H | 22 | #ifndef ARCHIVEBOOKMODEL_H | ||
23 | #define ARCHIVEBOOKMODEL_H | 23 | #define ARCHIVEBOOKMODEL_H | ||
24 | 24 | | |||
25 | #include "BookModel.h" | 25 | #include "BookModel.h" | ||
26 | 26 | /** | |||
27 | * \brief Class to hold pages and metadata for archive based books. | ||||
28 | * | ||||
29 | * In particular, ArchiveBookModel handles CBZ and CBR files, reads | ||||
30 | * potential metadata and holds that into the acbfdata object. | ||||
31 | * | ||||
32 | * ArchiveBookModel extends BookModel, which handles the functions for | ||||
33 | * setting the current page, and returning basic metadata. | ||||
34 | */ | ||||
27 | class KArchiveFile; | 35 | class KArchiveFile; | ||
28 | class ArchiveBookModel : public BookModel | 36 | class ArchiveBookModel : public BookModel | ||
29 | { | 37 | { | ||
30 | Q_OBJECT | 38 | Q_OBJECT | ||
31 | Q_PROPERTY(QObject* qmlEngine READ qmlEngine WRITE setQmlEngine NOTIFY qmlEngineChanged) | 39 | Q_PROPERTY(QObject* qmlEngine READ qmlEngine WRITE setQmlEngine NOTIFY qmlEngineChanged) | ||
32 | Q_PROPERTY(bool readWrite READ readWrite WRITE setReadWrite NOTIFY readWriteChanged) | 40 | Q_PROPERTY(bool readWrite READ readWrite WRITE setReadWrite NOTIFY readWriteChanged) | ||
33 | Q_PROPERTY(bool hasUnsavedChanges READ hasUnsavedChanges NOTIFY hasUnsavedChangesChanged) | 41 | Q_PROPERTY(bool hasUnsavedChanges READ hasUnsavedChanges NOTIFY hasUnsavedChangesChanged) | ||
34 | public: | 42 | public: | ||
35 | explicit ArchiveBookModel(QObject* parent = nullptr); | 43 | explicit ArchiveBookModel(QObject* parent = nullptr); | ||
36 | ~ArchiveBookModel() override; | 44 | ~ArchiveBookModel() override; | ||
37 | 45 | | |||
46 | /** | ||||
47 | * \brief Set the filename that points to the archive that describes this book. | ||||
48 | */ | ||||
38 | void setFilename(QString newFilename) override; | 49 | void setFilename(QString newFilename) override; | ||
39 | 50 | | |||
51 | /** | ||||
52 | * The author name will be either the default bookmodel author name, or | ||||
53 | * if ACBF data is available, the first authorname in the list of ACBF authors. | ||||
54 | * | ||||
55 | * @return the author name as a QString. | ||||
56 | */ | ||||
40 | QString author() const override; | 57 | QString author() const override; | ||
58 | /** | ||||
59 | * \brief Set the main author's nickname. | ||||
60 | * | ||||
61 | * If there is no ACBF data, this will set the author to BookModel's author. | ||||
62 | * If there is ACBF data, this will set the nickname entry on the name of the | ||||
63 | * first possible author. | ||||
64 | * | ||||
65 | * Preferably authors should be added by editing the author list in the bookinfo | ||||
66 | * of the ACBF metadata this book holds. | ||||
67 | * | ||||
68 | * @param newAuthor The main author's nickname. | ||||
69 | */ | ||||
41 | void setAuthor(QString newAuthor) override; | 70 | void setAuthor(QString newAuthor) override; | ||
71 | /** | ||||
72 | * @return the name of the publisher as a QString. | ||||
73 | */ | ||||
42 | QString publisher() const override; | 74 | QString publisher() const override; | ||
75 | /** | ||||
76 | * \brief Set the name of the publisher. | ||||
77 | * @param newPublisher QString with the name of the publisher. | ||||
78 | */ | ||||
43 | void setPublisher(QString newPublisher) override; | 79 | void setPublisher(QString newPublisher) override; | ||
80 | /** | ||||
81 | * @return The proper title of this book as a QString. | ||||
82 | */ | ||||
44 | QString title() const override; | 83 | QString title() const override; | ||
84 | /** | ||||
85 | * \brief Set the default title of this book. | ||||
86 | * @param newTitle The default title of this book as a QString. | ||||
87 | */ | ||||
45 | void setTitle(QString newTitle) override; | 88 | void setTitle(QString newTitle) override; | ||
46 | 89 | | |||
90 | /** | ||||
91 | * @return a QQmlEngine associated with this book. | ||||
92 | * TODO: What is the QML engine and what is its purpose? | ||||
93 | * Used in the cbr.qml | ||||
94 | */ | ||||
47 | QObject* qmlEngine() const; | 95 | QObject* qmlEngine() const; | ||
96 | /** | ||||
97 | * \brief Set the QML engine on this book. | ||||
98 | * @param newEngine A QQmlEngine object. | ||||
99 | */ | ||||
48 | void setQmlEngine(QObject* newEngine); | 100 | void setQmlEngine(QObject* newEngine); | ||
101 | /** | ||||
102 | * \brief Fires when a new QQmlEngine is set on this book. | ||||
103 | */ | ||||
49 | Q_SIGNAL void qmlEngineChanged(); | 104 | Q_SIGNAL void qmlEngineChanged(); | ||
50 | 105 | | |||
106 | /** | ||||
107 | * TODO: What is this? Only used in book.qml once? | ||||
108 | */ | ||||
51 | bool readWrite() const; | 109 | bool readWrite() const; | ||
52 | void setReadWrite(bool newReadWrite); | 110 | void setReadWrite(bool newReadWrite); | ||
53 | Q_SIGNAL void readWriteChanged(); | 111 | Q_SIGNAL void readWriteChanged(); | ||
54 | 112 | | |||
113 | /** | ||||
114 | * @return whether the book has been modified and has unsaved changes. | ||||
115 | * | ||||
116 | * Used in PeruseCreator to determine whether to enable the save dialog. | ||||
117 | */ | ||||
55 | bool hasUnsavedChanges() const; | 118 | bool hasUnsavedChanges() const; | ||
119 | /** | ||||
120 | * \brief Set that the book has been modified. | ||||
121 | * @param isDirty whether the book has been modified. | ||||
122 | */ | ||||
56 | Q_INVOKABLE void setDirty(bool isDirty = true); | 123 | Q_INVOKABLE void setDirty(bool isDirty = true); | ||
124 | /** | ||||
125 | * \brief Fires when there are unsaved changes. | ||||
126 | */ | ||||
57 | Q_SIGNAL void hasUnsavedChangesChanged(); | 127 | Q_SIGNAL void hasUnsavedChangesChanged(); | ||
58 | 128 | | |||
59 | /** | 129 | /** | ||
60 | * Saves the archive back to disk | 130 | * \brief Saves the archive back to disk | ||
61 | * @return True if the save was successful | 131 | * @return True if the save was successful | ||
62 | */ | 132 | */ | ||
63 | Q_INVOKABLE bool saveBook(); | 133 | Q_INVOKABLE bool saveBook(); | ||
64 | 134 | | |||
135 | /** | ||||
136 | * \brief add a page to this book. | ||||
137 | * | ||||
138 | * This adds it to the ACBF metadata too. | ||||
139 | * | ||||
140 | * @param url The resource location of the page as an url. | ||||
141 | * @param title The title of the page. This is shown in a table of contents. | ||||
142 | */ | ||||
65 | void addPage(QString url, QString title) override; | 143 | void addPage(QString url, QString title) override; | ||
66 | /** | 144 | /** | ||
67 | * Adds a new page to the book archive on disk, by copying in the file | 145 | * Adds a new page to the book archive on disk, by copying in the file | ||
68 | * passed to the function. Optionally this can be done at a specific | 146 | * passed to the function. Optionally this can be done at a specific | ||
69 | * position in the book. | 147 | * position in the book. | ||
70 | * | 148 | * | ||
71 | * @param fileUrl The URL of the file to copy into the archive | 149 | * @param fileUrl The URL of the file to copy into the archive | ||
72 | * @param insertAfter The index to insert the new page after. If invalid, insertion will be at the end | 150 | * @param insertAfter The index to insert the new page after. If invalid, insertion will be at the end | ||
Show All 9 Lines | |||||
82 | * @param withThisIndex The index of the page you want the first to be swapped with | 160 | * @param withThisIndex The index of the page you want the first to be swapped with | ||
83 | */ | 161 | */ | ||
84 | Q_INVOKABLE void swapPages(int swapThisIndex, int withThisIndex) override; | 162 | Q_INVOKABLE void swapPages(int swapThisIndex, int withThisIndex) override; | ||
85 | 163 | | |||
86 | /** | 164 | /** | ||
87 | * Creates a new book in the folder, with the given title and cover. | 165 | * Creates a new book in the folder, with the given title and cover. | ||
88 | * A filename will be constructed to fit the title, and which does not already exist in the | 166 | * A filename will be constructed to fit the title, and which does not already exist in the | ||
89 | * directory. | 167 | * directory. | ||
168 | * | ||||
169 | * @param folder the path to the folder to create this book in. | ||||
170 | * @param title The title of the book. | ||||
171 | * @param coverUrl A resource location pointing at the image that will be the coverpage. | ||||
90 | */ | 172 | */ | ||
91 | Q_INVOKABLE QString createBook(QString folder, QString title, QString coverUrl); | 173 | Q_INVOKABLE QString createBook(QString folder, QString title, QString coverUrl); | ||
92 | 174 | | |||
93 | friend class ArchiveImageProvider; | 175 | friend class ArchiveImageProvider; | ||
94 | protected: | 176 | protected: | ||
95 | const KArchiveFile* archiveFile(const QString& filePath); | 177 | const KArchiveFile* archiveFile(const QString& filePath); | ||
96 | 178 | | |||
97 | private: | 179 | private: | ||
98 | class Private; | 180 | class Private; | ||
99 | Private* d; | 181 | Private* d; | ||
100 | }; | 182 | }; | ||
101 | 183 | | |||
102 | #endif//ARCHIVEBOOKMODEL_H | 184 | #endif//ARCHIVEBOOKMODEL_H |