LibKEduVocDocument

dummyreader.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Andreas Xavier <andxav at zoho dot com>
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6#include "dummyreader.h"
7
8#include <KLocalizedString>
9
10#include <QIODevice>
11#include <QXmlStreamWriter>
12
13//@todo These static functions should be defined here. Find the syntax bug.
14// QString DummyReader::mTag()
15// {
16// return QString( "kvocdocdummyreadertestelement" );
17// }
18
19// QString DummyReader::makeErrorTag(KEduVocDocument::ErrorCode err)
20// {
21// return "errnum-" +QString::number( int( err));
22// }
23
24// QString DummyReader::makeDummyString(KEduVocDocument::ErrorCode error
25// , const QString & msg )
26// {
27// QString out;
28// QXmlStreamWriter stream(&out);
29// stream.setAutoFormatting(true);
30// stream.writeStartDocument();
31// stream.writeStartElement(mTag());
32// stream.writeTextElement( makeErrorTag(error), msg);
33// stream.writeEndElement(); // m_tag
34// stream.writeEndDocument();
35// kDebug() << "The file" <<out;
36// return out;
37// }
38
40 : m_dev(dev)
41{
42}
43
45{
46 bool isparsable = false;
47 setDevice(&m_dev);
48 if (!atEnd()) {
50 if (isStartElement()) {
51 if (name() == mTag()) {
52 isparsable = true;
53 }
54 }
55 }
56 m_dev.seek(0);
57 return isparsable;
58}
59
64
66{
67 setDevice(&m_dev);
68 if (!atEnd()) {
70 if (isStartElement()) {
71 // kDebug() << "Reading Dummy File is start "<< name() <<" text "<<text();
72 if (name() == mTag()) {
73 readNext();
74 readNext();
75 // kDebug() << "Reading Dummy File"<<name() << "text" << text();
76 if (isStartElement()) {
77 m_errorMessage = readElementText();
78 // kDebug() << "Reading Dummy File is " <<name() <<" with "<<m_errorMessage;
79 if (makeErrorTag(KEduVocDocument::NoError) == name())
81 if (makeErrorTag(KEduVocDocument::Unknown) == name())
83 if (makeErrorTag(KEduVocDocument::InvalidXml) == name())
85 if (makeErrorTag(KEduVocDocument::FileTypeUnknown) == name())
87 if (makeErrorTag(KEduVocDocument::FileCannotWrite) == name())
89 if (makeErrorTag(KEduVocDocument::FileWriterFailed) == name())
91 if (makeErrorTag(KEduVocDocument::FileCannotRead) == name())
93 if (makeErrorTag(KEduVocDocument::FileReaderFailed) == name())
95 if (makeErrorTag(KEduVocDocument::FileDoesNotExist) == name())
97 if (makeErrorTag(KEduVocDocument::FileLocked) == name())
99 if (makeErrorTag(KEduVocDocument::FileCannotLock) == name())
101 }
102 }
103 }
104 }
106}
107
109{
110 return m_errorMessage;
111}
KEduVocDocument::FileType fileTypeHandled() override
returns the KEduVocDocument::FileType that this reader handles
KEduVocDocument::ErrorCode read(KEduVocDocument &doc) override
Parse file and write into doc.
DummyReader(QIODevice &dev)
constructor
bool isParsable() override
Can this reader parse this file.
QString errorMessage() const override
an error message.
The primary entry point to the hierarchy of objects describing vocabularies.
ErrorCode
the return code when opening/saving
@ 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
virtual bool seek(qint64 pos)
bool atEnd() const const
bool isStartElement() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
TokenType readNext()
bool readNextStartElement()
void setDevice(QIODevice *device)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.