File indexing completed on 2022-10-04 13:56:35

0001 /*
0002  * export a KEduVocDocument to a KVTML file
0003  * SPDX-FileCopyrightText: 2007 Jeremy Whiting <jpwhiting@kde.org>
0004  * SPDX-FileCopyrightText: 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #ifndef KEDUVOCKVTML2WRITER_H
0008 #define KEDUVOCKVTML2WRITER_H
0009 
0010 #include <QDomDocument>
0011 #include <QList>
0012 #include <QFile>
0013 
0014 #include "keduvocarticle.h"
0015 #include "keduvocmultiplechoice.h"
0016 #include "keduvoctranslation.h"
0017 #include "keduvocpersonalpronoun.h"
0018 
0019 class KEduVocDocument;
0020 class KEduVocExpression;
0021 class KEduVocLesson;
0022 class KEduVocLeitnerBox;
0023 
0024 /**
0025 * @brief Class to write kvtml2 data files from KEduVocDocument
0026 * @author Jeremy Whiting
0027 */
0028 class KEduVocKvtml2Writer
0029 {
0030 public:
0031     explicit KEduVocKvtml2Writer( QFile *file );
0032 
0033     bool writeDoc( KEduVocDocument *doc, const QString &generator );
0034 
0035     QByteArray toByteArray( KEduVocDocument *doc, const QString &generator );
0036 
0037     /**
0038      * Helper function, appends a new element AND a text child to @p parent
0039      * Only appends if @p text is NOT empty.
0040      * @param parent
0041      * @param elementName
0042      * @param text
0043      */
0044     static void appendTextElement( QDomElement &parent, const QString &elementName, const QString &text );
0045 
0046 private:
0047 
0048     bool createXmlDocument( KEduVocDocument *doc, const QString &generator );
0049 
0050     /** write information entries
0051      * @param informationElement QDomElement information to write to
0052      * @param generator text describing generator
0053      */
0054     bool writeInformation( QDomElement &informationElement, const QString &generator );
0055 
0056     /** write identifiers group
0057      * @param identifiersElement QDomElement identifiers to write to
0058      */
0059     bool writeIdentifiers( QDomElement &identifiersElement );
0060 
0061     /** write article
0062      * @param articleElement QDomElement article to write to
0063      * @param article the article number to write
0064      */
0065     bool writeArticle( QDomElement &articleElement, int article );
0066 
0067     bool writePersonalPronoun( QDomElement &pronounElement, const KEduVocPersonalPronoun &pronoun);
0068     /** write types
0069      * @param typesElement QDomElement types to write to
0070      */
0071     bool writeWordTypes( QDomElement &typesElement, KEduVocWordType* parentContainer );
0072 
0073     /**
0074      * write the leitner boxes @see KEduVocLeitnerBox
0075      * @param leitnerParentElement parent dom element
0076      * @param parentContainer parent of the KEduVocLeitnerBoxes to write
0077      * @return success
0078      */
0079     bool writeLeitnerBoxes( QDomElement &leitnerParentElement, KEduVocLeitnerBox* parentContainer );
0080 
0081     /** write entries
0082      * @param entriesElement QDomElement entries to write to
0083      */
0084     bool writeEntries( QDomElement &entriesElement );
0085 
0086     /** write a translation
0087      * @param translationElement QDomElement translation to write to, with id pre-set
0088      * @param translation object to write
0089      */
0090     bool writeTranslation( QDomElement &translationElement, KEduVocTranslation* translation );
0091 
0092     /**
0093      * Used to write synonym, antonym and false friend lists
0094      * @param typesElement 
0095      * @param parentContainer 
0096      * @return 
0097      */
0098     bool writeRelated( QDomElement &parentElement, QList<KEduVocTranslation*> relatedList );
0099 
0100     /** write the lesson group
0101      * @param parentLesson the parent lesson of the current lesson
0102      * @param lessonsElement QDomElement lessons to write to
0103      */
0104     bool writeLessons( KEduVocLesson *parentLesson, QDomElement &lessonsElement );
0105 
0106     void writeSynonymAntonymFalseFriend(QDomElement & parentElement);
0107 
0108     /** write multiple choice choices
0109      * @param multipleChoiceElement QDomElement multiplechoice to write to
0110      * @returns success
0111      */
0112     bool writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation* translation );
0113 
0114     QDomElement newTextElement( const QString &elementName, const QString &text );
0115 
0116     QFile *m_outputFile;
0117     KEduVocDocument *m_doc;
0118 
0119     QList<KEduVocExpression*>  m_allEntries;
0120     QList<KEduVocTranslation*> m_synonyms;
0121     QList<KEduVocTranslation*> m_antonyms;
0122     QList<KEduVocTranslation*> m_falseFriends;
0123 
0124     QDomDocument m_domDoc;
0125 };
0126 
0127 #endif