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

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Andreas Xavier <andxav at zoho dot com>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #ifndef FAILEDREADER_H
0007 #define FAILEDREADER_H
0008 
0009 #include "readerbase.h"
0010 
0011 #include <QDebug>
0012 
0013 /**
0014  * @brief A fallback reader when the device can't be read or no other reader can parse.
0015  @details FailedReader always returns the error message that it was initialized with
0016  , unless the error code was NoError.  In which case it returns Unknown.
0017  *
0018  * */
0019 class FailedReader : public ReaderBase
0020 {
0021 public:
0022     /** @brief When constructed with error code FailedReader will return this error code
0023      @param error the error code or defaults to Unknown
0024      @param msg a custom message or defaults to \"Error while reading file\"*/
0025     explicit FailedReader(KEduVocDocument::ErrorCode error = KEduVocDocument::Unknown, const QString &msg = QString());
0026 
0027     /**destructor*/
0028     ~FailedReader() override{};
0029 
0030     /** @brief Can this reader parse this file
0031      *
0032      Read a small portion of the header of the file
0033      and decide if it is a suitable type.
0034      @return true if parsable
0035      */
0036     bool isParsable() Q_DECL_OVERRIDE;
0037 
0038     /** @brief returns the KEduVocDocument::FileType that this reader handles
0039         @return KEduVocDocument::FileType handled
0040      */
0041     KEduVocDocument::FileType fileTypeHandled() Q_DECL_OVERRIDE;
0042 
0043     /**  @brief Parse file and write into doc
0044      @param doc to be written
0045      @return error status of the read.*/
0046     KEduVocDocument::ErrorCode read(KEduVocDocument &doc) Q_DECL_OVERRIDE;
0047 
0048     /** an error message.
0049         @return the error message
0050     */
0051     QString errorMessage() const Q_DECL_OVERRIDE;
0052 
0053 private:
0054     KEduVocDocument::ErrorCode m_error; ///< The error code to always return;
0055     QString m_errorMessage; ///< The error message
0056 };
0057 
0058 #endif // FAILEDREADER_H