LibKEduVocDocument

keduvocdocument.h
1/*
2 * Vocabulary Document for KDE Edu
3 * SPDX-FileCopyrightText: 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
4 * SPDX-FileCopyrightText: 2005, 2007 Peter Hedlund <peter.hedlund@kdemail.net>
5 * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8#ifndef KEDUVOCDOCUMENT_H
9#define KEDUVOCDOCUMENT_H
10
11#include "keduvocdocument_export.h"
12
13#include "keduvocarticle.h"
14#include "keduvocconjugation.h"
15#include "keduvocidentifier.h"
16
17#include <QList>
18#include <QMap>
19#include <QObject>
20#include <QUrl>
21
22class KEduVocLesson;
23class KEduVocWordType;
25
26/**
27 * @brief The primary entry point to the hierarchy of objects describing vocabularies.
28 * @details This class contains the expressions of your vocabulary
29 * as well as other information about the vocabulary.
30 */
31class KEDUVOCDOCUMENT_EXPORT KEduVocDocument : public QObject
32{
33 Q_OBJECT
34public:
35 ///@todo in new API change enums to QFlags
36
37 /// known vocabulary file types
38 enum FileType {
39 KvdNone, ///< handles nothing
40 Automatic, ///< try to automatically determine file type
41 Kvtml, ///< Kvtml 2.0
42 Wql, ///< Word Quiz format
43 Pauker, ///< Pauker format
44 Vokabeln, ///< Vokabeln format
45 Xdxf, ///< XDXF format @see https://github.com/soshial/xdxf_makedict/blob/master/format_standard/xdxf_strict.dtd
46 Csv, ///< Command separated values
47 Kvtml1 ///< KVTML 1.0
48 };
49
50 /// the return code when opening/saving
51 enum ErrorCode {
52 NoError = 0, ///< no error
53 Unknown, ///< unspecified error
54 InvalidXml, ///< malformed xml or bad file formatting
55 FileTypeUnknown, ///< unknown file type
56 FileCannotWrite, ///< unwritable file
57 FileWriterFailed, ///< file writer failed
58 FileCannotRead, ///< unreadable file
59 FileReaderFailed, ///< file reader failed
60 FileDoesNotExist, ///< unknown file type
61 FileLocked, ///< An autosave file exists for this document
62 FileCannotLock, ///< Can't create an autosave file for this document
63 FileIsReadOnly, ///< Can't save this file because it was opened read-only
64 };
65
66 /// indicates file open/save status locking or readonly
68 FileDefaultHandling = 0x0, ///< Default status
69 FileIgnoreLock = 0x1, ///< Ignore the file lock
70 FileOpenReadOnly = 0x2, ///< Open without any intention to change and save back later. This also implies FileIgnoreLock.
71 };
72
73 /// used as parameter for pattern
75 Reading,
76 Writing,
77 };
78
79 /// delete only empty lessons or also if they have entries
81 DeleteEmptyLesson,
82 DeleteEntriesAndLesson,
83 };
84
85 /**
86 * Constructor for a KDEEdu vocabulary document
87 *
88 * @param parent calling object
89 */
90 explicit KEduVocDocument(QObject *parent = nullptr);
91
92 /**
93 * Destructor
94 */
95 ~KEduVocDocument() override;
96
97 /** @name Whole Document Methods
98 * Methods related to saving/loading and locating the document
99 * @nosubgrouping
100 */
101 ///@{
102
103 /**
104 * Opens and locks a document file
105 *
106 * Note: This is intended to be preserve binary compatible with int open(const QUrl&)
107 * When the API increments the major version number, then merge them
108 *
109 * @param url url to file to open
110 * @param flags How to handle expected unusual conditions (i.e. locking)
111 * @returns ErrorCode
112 */
113 ErrorCode open(const QUrl &url, FileHandlingFlags flags = FileDefaultHandling);
114
115 /**
116 * Close a document file and release the lock on the file
117 *
118 */
119 void close();
120
121 /**
122 * Saves the data under the given name
123 *
124 * @pre generator is set.
125 *
126 * Note: This is intended to be preserve binary compatible with
127 * int saveAs(const QUrl&, FileType ft, const QString & generator );
128 * When the API increments the major version number, then merge them
129 *
130 * @param url if url is empty (or NULL) actual name is preserved
131 * @param ft the filetype to be used when saving the document
132 * @param flags How to handle expected unusual conditions (i.e. locking)
133 * @returns ErrorCode
134 */
135 ErrorCode saveAs(const QUrl &url, FileType ft, FileHandlingFlags flags = FileDefaultHandling);
136
137 /** @details returns a QByteArray KVTML2 representation of this doc
138 * @param generator name of the application creating the QByteArray
139 * @return KVTML2 XML
140 * @todo in new API if this should be part of save*/
141 QByteArray toByteArray(const QString &generator);
142
143 /**
144 * Merges data from another document (UNIMPLEMENTED)
145 *
146 * @param docToMerge document containing the data to be merged
147 * @param matchIdentifiers if true only entries having identifiers present in the
148 * current document will be mergedurl is empty (or NULL) actual name is preserved
149 */
150 void merge(KEduVocDocument *docToMerge, bool matchIdentifiers);
151
152 /**
153 * Indicates if the document is modified
154 *
155 * @param dirty new state
156 */
157 void setModified(bool dirty = true);
158
159 /** @returns the modification state of the doc */
160 bool isModified() const;
161
162 /**
163 * Sets the URL of the XML file
164 * @param url URL
165 */
166 void setUrl(const QUrl &url);
167
168 /** @returns the URL of the XML file */
169 QUrl url() const;
170
171 ///@}
172
173 /** @name General Document Properties
174 *
175 */
176 ///@{
177
178 /** Set the title of the file
179 * @param title title to set */
180 void setTitle(const QString &title);
181
182 /** @returns the title of the file */
183 QString title() const;
184
185 /** Set the author of the file
186 * @param author author to set */
187 void setAuthor(const QString &author);
188
189 /** @returns the author of the file */
190 QString author() const;
191
192 /** Set the author contact info
193 * @param authorContact contact email/contact info to set */
194 void setAuthorContact(const QString &authorContact);
195
196 /** @returns the author contact information */
197 QString authorContact() const;
198
199 /** Set the license of the file
200 * @param license license to set */
201 void setLicense(const QString &license);
202
203 /** @returns the license of the file */
204 QString license() const;
205
206 /** Set the comment of the file
207 * @param comment comment to set */
208 void setDocumentComment(const QString &comment);
209
210 /** @return the comment of the file */
211 QString documentComment() const;
212
213 /** Set the category of the file
214 * @param category category to set */
215 void setCategory(const QString &category);
216
217 /** @return the category of the file */
218 QString category() const;
219
220 /**
221 * Sets the generator of the file
222 * @param generator name of the application generating the file
223 */
224 void setGenerator(const QString &generator);
225
226 /** @returns the generator of the file */
227 QString generator() const;
228
229 /** Sets version of the loaded file
230 * @param ver the new version */
231 void setVersion(const QString &ver);
232
233 /** @returns the version of the loaded file */
234 QString version() const;
235
236 ///@}
237
238 /** @name Identifier Methods
239 *
240 */
241 ///@{
242
243 /**
244 * @returns the number of different identifiers (usually languages)
245 */
246 int identifierCount() const;
247
248 /**
249 * Appends a new identifier (usually a language)
250 *
251 * @param identifier the identifier to append. If empty default names are used.
252 * @returns the identifier number
253 */
254 int appendIdentifier(const KEduVocIdentifier &identifier = KEduVocIdentifier());
255
256 /**
257 * Sets the identifier of translation
258 *
259 * @param index number of translation 0..x
260 * @param lang the language identifier: en=english, de=german, ...
261 */
262 void setIdentifier(int index, const KEduVocIdentifier &lang);
263
264 /**
265 * Returns the identifier of translation @p index
266 *
267 * @param index number of translation 0..x
268 * @returns the language identifier: en=english, de=german, ...
269 */
270 KEduVocIdentifier &identifier(int index);
271
272 /**
273 * Const overload of identifier(int);
274 * @param index of the identifier
275 * @return reference to the identifier
276 */
277 const KEduVocIdentifier &identifier(int index) const;
278
279 /**
280 * Removes identifier and the according translation in all entries
281 *
282 * @param index number of translation 0..x
283 */
284 void removeIdentifier(int index);
285
286 /**
287 * Determines the index of a given identifier
288 *
289 * @param name identifier of language
290 * @returns index of identifier, 0 = original, 1..n = translation, -1 = not found
291 */
292 int indexOfIdentifier(const QString &name) const;
293
294 ///@}
295
296 /** @name Grade Methods
297 *
298 */
299 ///@{
300
301 /**
302 * Retrieves the identifiers for the current query
303 * not written in the new version!
304 *
305 * @param org identifier for original
306 * @param trans identifier for translation
307 */
308 KEDUVOCDOCUMENT_DEPRECATED void queryIdentifier(QString &org, QString &trans) const;
309
310 /**
311 * Sets the identifiers for the current query
312 * not written in the new version!
313 *
314 * @param org identifier for original
315 * @param trans identifier for translation
316 */
317 KEDUVOCDOCUMENT_DEPRECATED void setQueryIdentifier(const QString &org, const QString &trans);
318
319 ///@}
320
321 /** @name Lesson Methods
322 *
323 */
324 ///@{
325
326 /** @brief Get the lesson root object
327 * @returns a pointer to the lesson object
328 */
329 KEduVocLesson *lesson();
330
331 /** @brief Returns the root word type object
332 @return pointer to the internal word type object */
333 KEduVocWordType *wordTypeContainer();
334
335 /** @brief Returns the root Leitner container
336 @return pointer to the internal Leitner container object
337 @todo in new API determine if this is used */
338 KEduVocLeitnerBox *leitnerContainer();
339
340 ///@}
341
342 /** @name File Format Specific Methods
343 *
344 */
345 ///@{
346
347 /**
348 * Returns the delimiter (separator) used for csv import and export.
349 * The default is a single tab character
350 *
351 * @returns the delimiter used
352 */
353 QString csvDelimiter() const;
354
355 /**
356 * Sets the delimiter (separator) used for csv import and export
357 *
358 * @param delimiter the delimiter to use
359 */
360 void setCsvDelimiter(const QString &delimiter);
361
362 ///@}
363
364 /**
365 * @details Detects the file type
366 * @param fileName filename
367 * @return enum of filetype
368 */
369 static FileType detectFileType(const QString &fileName);
370
371 /**
372 * Create a string with the supported document types, that can be used
373 * as filter in KFileDialog. It includes also an entry to match all the
374 * supported types.
375 *
376 * @param mode the mode for the supported document types
377 * @returns the filter string
378 */
379 static QString pattern(FileDialogMode mode);
380
381 /**
382 * @brief Returns a QString description of the errorCode
383 * @param errorCode the code
384 * @returns a user useful error string.
385 */
386 static QString errorDescription(int errorCode);
387
389 /**
390 * @brief never used
391 * @param curr_percent
392 */
393 void progressChanged(KEduVocDocument *, int curr_percent);
394
395 /**
396 * @brief Emitted when the document becomes modified or saved.
397 * @param mod the current modified/dirty state
398 * @returns state (true=modified)
399 */
400 void docModified(bool mod);
401
402private:
403 // The private data of this - see KEduVocDocument::Private, implemented in keduvocdocument.cpp
404 class KEduVocDocumentPrivate;
405 KEduVocDocumentPrivate *const d; ///< d pointer to private class
406
407 Q_DISABLE_COPY(KEduVocDocument)
408};
409
410#endif // KEDUVOCDOCUMENT_H
The primary entry point to the hierarchy of objects describing vocabularies.
FileHandlingFlags
indicates file open/save status locking or readonly
void progressChanged(KEduVocDocument *, int curr_percent)
never used
LessonDeletion
delete only empty lessons or also if they have entries
void docModified(bool mod)
Emitted when the document becomes modified or saved.
ErrorCode
the return code when opening/saving
@ FileIsReadOnly
Can't save this file because it was opened read-only.
@ FileCannotWrite
unwritable file
@ FileCannotLock
Can't create an autosave file for this document.
@ InvalidXml
malformed xml or bad file formatting
@ Unknown
unspecified error
@ FileWriterFailed
file writer failed
@ FileTypeUnknown
unknown file type
@ FileReaderFailed
file reader failed
@ FileDoesNotExist
unknown file type
@ FileCannotRead
unreadable file
@ FileLocked
An autosave file exists for this document.
FileType
known vocabulary file types
@ KvdNone
handles nothing
@ Wql
Word Quiz format.
@ Xdxf
XDXF format.
@ Vokabeln
Vokabeln format.
@ Kvtml
Kvtml 2.0.
@ Csv
Command separated values.
@ Pauker
Pauker format.
@ Automatic
try to automatically determine file type
FileDialogMode
used as parameter for pattern
Class to store meta information about a language or any other category in the vocabulary.
Leitner Boxes are an alternative grading system.
class to store information about a lesson
class to store translation word types
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.