9#include "keduvocvokabelnreader.h"
11#include <KLocalizedString>
16#include "keduvocexpression.h"
53 for (
int x = 0; x < 10; x++) {
76 qDebug() <<
"Reading vokabeln.de document...";
79 m_doc->
setAuthor(QStringLiteral(
"http://www.vokabeln.de"));
82 qWarning() <<
" Need to fix inputStream.setCodec( ISO-8859-1 );";
97 int maxLessonNumber = -1;
115 if (inputStream.
atEnd()) {
116 m_errorMessage =
i18n(
"Error while reading file: Truncated header");
123 m_errorMessage =
i18n(
"Error while reading file: No title");
129 titles = title.
split(QStringLiteral(
"\","));
130 m_doc->setTitle(titles[0].mid(1));
131 qDebug() <<
"TitleA " << m_doc->title();
135 titles = comment.
split(QStringLiteral(
"\","));
136 m_doc->setDocumentComment(titles[0]);
137 m_doc->setTitle(title.
mid(1));
138 qDebug() <<
"TitleB " << m_doc->title();
141 wordCount = titles[1].section(
',', 0, 0).toInt();
142 qDebug() <<
"WordCount " << wordCount;
147 languages = lang1.
split(QStringLiteral(
"\","));
149 if (languages.
size() < 2) {
150 m_errorMessage =
i18n(
"Error while reading file: Didn't find two languages in %1", lang1);
154 m_doc->appendIdentifier();
156 m_doc->identifier(0).setLocale(language);
157 m_doc->identifier(0).setName(language);
158 qDebug() <<
"First language: " << language;
160 m_doc->appendIdentifier();
161 language = languages[1].
mid(1);
162 m_doc->identifier(1).setLocale(language);
163 m_doc->identifier(1).setName(language);
164 qDebug() <<
"Second language: " << language;
166 QString section8Header(QStringLiteral(
"8. Lernhilfe"));
167 while (!temp.
contains(section8Header)) {
168 if (inputStream.
atEnd()) {
169 m_errorMessage =
i18n(
"Error while reading file: Missing \"%1\"", section8Header);
175 for (i = 0; i <= 14; ++i) {
179 for (i = 0; i < wordCount - 1; ++i) {
184 if (inputStream.
atEnd()) {
185 m_errorMessage =
i18n(
"Error while reading file: Expecting something like \"dog\",\"Hund\",1");
196 words = expression.
split(QStringLiteral(
"\","));
197 original = words[0].
mid(1);
198 translation = words[1].
mid(1);
199 lessonNumber = words[2].toInt() - 1;
200 maxLessonNumber = qMax(lessonNumber, maxLessonNumber);
202 qDebug() <<
"Reading entry: " << original <<
" - " << translation <<
" Lesson: " << lessonNumber;
205 if (lessonNumber < 0) {
206 qDebug() <<
"Warning, invalid lesson found!";
210 while (m_doc->lesson()->childContainerCount() <= lessonNumber) {
212 m_doc->lesson()->appendChildContainer(lesson);
213 qDebug() <<
"Created lesson " << lessonNumber;
231 while (!inputStream.
atEnd() && ii < lines && ii <= maxLessonNumber) {
233 qDebug() <<
"Found lesson description " << lessonDescr;
234 lessonDescr = lessonDescr.
mid(1, lessonDescr.
length() - 2);
235 m_doc->lesson()->childContainer(ii)->setName(lessonDescr);
The primary entry point to the hierarchy of objects describing vocabularies.
void setAuthor(const QString &author)
Set the author of the file.
ErrorCode
the return code when opening/saving
@ FileReaderFailed
file reader failed
FileType
known vocabulary file types
@ Vokabeln
Vokabeln format.
This class contains one vocabulary expression as an original with one or more translations.
void setTranslation(int index, const QString &expression)
Add a translation to this expression.
class to store information about a lesson
void appendEntry(KEduVocExpression *entry)
append an entry to the lesson
KEduVocDocument::ErrorCode read(KEduVocDocument &doc) override
Parse file and write into doc.
KEduVocDocument::FileType fileTypeHandled() override
returns the KEduVocDocument::FileType that this reader handles
KEduVocVokabelnReader(QIODevice &file)
constructor
bool isParsable() override
Can this reader parse this file.
QString i18n(const char *text, const TYPE &arg...)
QList< T > mid(qsizetype pos, qsizetype length) const const
qsizetype size() const const
qsizetype count() const const
QString & append(QChar ch)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString readLine(qint64 maxlen)
void setAutoDetectUnicode(bool enabled)