Open-Typer
Open source typewriting tutor program
Loading...
Searching...
No Matches
ConfigParser.h
1/*
2 * ConfigParser.h
3 * This file is part of Open-Typer
4 *
5 * Copyright (C) 2021-2023 - adazem009
6 *
7 * Open-Typer is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * Open-Typer is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Open-Typer. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef CONFIGPARSER_H
22#define CONFIGPARSER_H
23
24#include <QObject>
25#include <QFile>
26#include <QBuffer>
27#include <QString>
28#include "IConfigParser.h"
29#include "global/IStringUtils.h"
30
31namespace publicPos {
32 Q_DECL_EXPORT Q_NAMESPACE;
33 extern int Q_DECL_EXPORT currentLesson, currentSublesson, currentExercise;
34}
35
36// TODO: Add a link to pack file format documentation.
50class Q_DECL_EXPORT ConfigParser : public QObject, public IConfigParser
51{
52 Q_OBJECT
53 INJECT(IStringUtils, stringUtils)
54 public:
55 explicit ConfigParser(QObject *parent = nullptr);
56 static std::shared_ptr<ConfigParser> instance();
57 std::shared_ptr<IConfigParser> createInstance() const override;
58 Q_INVOKABLE bool open(const QString fileName) override;
59 Q_INVOKABLE void loadToBuffer(const QByteArray content) override;
60 Q_INVOKABLE QByteArray data(void) override;
61 Q_INVOKABLE bool bufferOpened(void) override;
62 Q_INVOKABLE void close(void) override;
63 QString fileName(void) override;
64 Q_INVOKABLE int lessonCount(void) override;
65 Q_INVOKABLE int sublessonCount(int lesson) override;
66 Q_INVOKABLE int exerciseCount(int lesson, int sublesson) override;
67 Q_INVOKABLE int exerciseLine(int lesson, int sublesson, int exercise) override;
68 Q_INVOKABLE bool exerciseRepeatBool(int lesson, int sublesson, int exercise) override;
69 Q_INVOKABLE QString exerciseRepeatType(int lesson, int sublesson, int exercise) override;
70 Q_INVOKABLE int exerciseRepeatLimit(int lesson, int sublesson, int exercise) override;
71 Q_INVOKABLE int exerciseLineLength(int lesson, int sublesson, int exercise) override;
72 Q_INVOKABLE QString lessonDesc(int lesson) override;
73 Q_INVOKABLE QString parseDesc(QString desc) override;
74 Q_INVOKABLE QString sublessonName(int id) override;
75 Q_INVOKABLE QString lessonTr(int id) override;
76 Q_INVOKABLE QString sublessonTr(int id) override;
77 Q_INVOKABLE QString exerciseTr(int id) override;
78 Q_INVOKABLE QString exerciseRawText(int lesson, int sublesson, int exercise) override;
79 Q_INVOKABLE QString exerciseText(int lesson, int sublesson, int exercise) override;
80 Q_INVOKABLE QString initExercise(QString exercise, int lineLength) override;
81 Q_INVOKABLE QString initExercise(QString exercise, int lineLength, bool lineCountLimit, int currentLine) override;
82 Q_INVOKABLE QString initText(QString rawText) override;
83 Q_INVOKABLE bool addExercise(int lesson, int sublesson, int exercise, bool repeat, QString repeatType, int repeatLimit, int lineLength, QString desc, QString rawText) override;
84 Q_INVOKABLE int defaultRepeatLimit(void) override;
85 Q_INVOKABLE int defaultLineLength(void) override;
86 Q_INVOKABLE void setCurrentLesson(int value) override;
87 Q_INVOKABLE int currentLesson(void) override;
88 Q_INVOKABLE void setCurrentSublesson(int value) override;
89 Q_INVOKABLE int currentSublesson(void) override;
90 Q_INVOKABLE void setCurrentExercise(int value) override;
91 Q_INVOKABLE int currentExercise(void) override;
92
93 private:
94 static std::shared_ptr<ConfigParser> m_instance;
95 QFile configFile;
96 QBuffer configBuffer;
97 QIODevice *currentDevice;
98 static const int m_defaultRepeatLimit = 128;
99 static const int m_defaultLineLength = 100;
100 bool reopen(QIODevice::OpenMode mode);
101 int exerciseID(const QString line, const int part);
102 QString lineOf(int lesson, int sublesson, int exercise);
103 bool exerciseRepeatBool(const QString config);
104 QString exerciseRepeatType(const QString config);
105 QString exerciseRepeatConfig(const QString line);
106 QString exerciseAttribute(const QString config, const int id);
107 QString exerciseAttributes(const QString line);
108 QString exerciseRawText(const QString line);
109 static QString generateText(QString rawText, bool repeat, QString repeatType, int repeatLimit);
110};
111
112#endif // CONFIGPARSER_H
The ConfigParser class provides functions for the pack file format.
Definition ConfigParser.h:51
Definition IConfigParser.h:27
Definition IStringUtils.h:28