File indexing completed on 2024-04-14 03:46:37

0001 /*
0002  * read a KEduVocDocument from a KVTML file
0003 
0004  * SPDX-FileCopyrightText: 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
0005  * SPDX-FileCopyrightText: 2005 Eric Pignet <eric at erixpage.com>
0006  * SPDX-FileCopyrightText: 2007 Peter Hedlund <peter.hedlund@kdemail.net>
0007  * SPDX-FileCopyrightText: 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0008  * SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef KEDUVOCKVTMLREADER_H
0012 #define KEDUVOCKVTMLREADER_H
0013 
0014 #include <QDomDocument>
0015 #include <QList>
0016 
0017 #include "keduvocarticle.h"
0018 #include "keduvocdocument.h"
0019 #include "keduvocexpression.h"
0020 #include "keduvockvtmlcompability.h"
0021 #include "keduvocmultiplechoice.h"
0022 #include "keduvocpersonalpronoun.h"
0023 #include "readerbase.h"
0024 
0025 class QIODevice;
0026 class KEduVocDocument;
0027 
0028 /** @brief Reader for KVTML 1.0
0029 @author Eric Pignet
0030 */
0031 class KEduVocKvtmlReader : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     /** constructor
0036         @param file an open device
0037     */
0038     explicit KEduVocKvtmlReader(QIODevice &file);
0039     /**destructor*/
0040     ~KEduVocKvtmlReader() override{};
0041 
0042     /** @brief Can this reader parse this file
0043      *
0044      Read a small portion of the header of the file
0045      and decide if it is a suitable type.
0046      @return true if parsable
0047      */
0048     virtual bool isParsable();
0049 
0050     /**  @brief Parse file and write into doc
0051      @param doc to be written
0052      @return error status of the read.*/
0053     virtual KEduVocDocument::ErrorCode read(KEduVocDocument &doc);
0054 
0055     /** an error message.
0056         @return the error message
0057     */
0058     virtual QString errorMessage() const
0059     {
0060         return m_errorMessage;
0061     }
0062 
0063     /**
0064      * Attempt to add a language/locale. Language/locale are set to the same value.
0065      * No error if already there with the same value.
0066      * @param languageId identifier number
0067      * @param language name
0068      * @return true if successful
0069      */
0070     bool addLanguage(int languageId, const QString &language);
0071 
0072     bool readLesson(QDomElement &domElementParent);
0073     bool readArticle(QDomElement &domElementParent);
0074     bool readPersonalPronouns(QDomElement &domElementParent, KEduVocPersonalPronoun &pronouns);
0075     bool readConjugation(QDomElement &domElementParent, KEduVocConjugation &conjugation);
0076     bool readTranslationConjugations(QDomElement &domElementParent, KEduVocTranslation *translation);
0077     bool readType(QDomElement &domElementParent);
0078     bool readTense(QDomElement &domElementParent);
0079     bool readUsage(QDomElement &domElementParent);
0080     bool readComparison(QDomElement &domElementParent, KEduVocTranslation *translation);
0081     bool readMultipleChoice(QDomElement &domElementParent, KEduVocTranslation *translation);
0082     bool readExpressionChildAttributes(QDomElement &domElementExpressionChild,
0083                                        QString &lang,
0084                                        grade_t &grade,
0085                                        grade_t &rev_grade,
0086                                        int &count,
0087                                        int &rev_count,
0088                                        QDateTime &date,
0089                                        QDateTime &rev_date,
0090                                        QString &remark,
0091                                        int &bcount,
0092                                        int &rev_bcount,
0093                                        QString &query_id,
0094                                        QString &pronunciation,
0095                                        int &width,
0096                                        QString &type,
0097                                        QString &faux_ami_f,
0098                                        QString &faux_ami_t,
0099                                        QString &synonym,
0100                                        QString &example,
0101                                        QString &antonym,
0102                                        QSet<QString> &usage,
0103                                        QString &paraphrase);
0104     bool readExpression(QDomElement &domElementParent);
0105     bool readBody(QDomElement &domElementParent);
0106 
0107 private:
0108     QIODevice *m_inputFile; ///< input device
0109     KEduVocDocument *m_doc; ///< output doc
0110     QString m_errorMessage; ///< error message
0111     int m_cols;
0112     int m_lines;
0113     QStringList m_oldSelfDefinedTypes;
0114 
0115     KEduVocKvtmlCompability m_compability;
0116 };
0117 
0118 #endif