-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmdOrGuiApp.h
106 lines (88 loc) · 3.15 KB
/
CmdOrGuiApp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//========================================================================
//
// Copyright (C) 2020 Matthieu Bruel <Matthieu.Bruel@gmail.com>
//
// This file is a part of ngPost : https://github.com/mbruel/ngPost
//
// ngPost is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; version 3.0 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
// USA.
//
//========================================================================
#ifndef CMDORGUIAPP_H
#define CMDORGUIAPP_H
#include <QString>
class MainWindow;
class QCoreApplication;
class CmdOrGuiApp
{
protected:
enum class AppMode : bool {CMD = 0, HMI = 1}; //!< supposed to be CMD but a simple HMI has been added
QCoreApplication *_app; //!< Application instance (either a QCoreApplication or a QApplication in HMI mode)
const AppMode _mode; //!< CMD or HMI (for Windowser...)
MainWindow *_hmi; //!< potential HMI
public:
explicit CmdOrGuiApp(int &argc, char *argv[]);
virtual ~CmdOrGuiApp();
virtual const char *appName() = 0;
virtual bool parseCommandLine(int argc, char *argv[]) = 0;
virtual void checkForNewVersion();
virtual int startHMI();
inline bool useHMI() const;
int startEventLoop(); //!< to start in CMD
inline static QString escapeXML(const char *str);
inline static QString escapeXML(const QString &str);
inline static QString xml2txt(const char *str);
inline static QString xml2txt(const QString &str);
};
bool CmdOrGuiApp::useHMI() const { return _mode == AppMode::HMI; }
QString CmdOrGuiApp::escapeXML(const char *str)
{
QString escaped(str);
escaped.replace('&', "&");
escaped.replace('<', "<");
escaped.replace('>', ">");
escaped.replace('"', """);
escaped.replace('\'', "'");
return escaped;
}
QString CmdOrGuiApp::escapeXML(const QString &str)
{
QString escaped(str);
escaped.replace('&', "&");
escaped.replace('<', "<");
escaped.replace('>', ">");
escaped.replace('"', """);
escaped.replace('\'', "'");
return escaped;
}
QString CmdOrGuiApp::xml2txt(const char *str)
{
QString escaped(str);
escaped.replace("&", "&");
escaped.replace("<", "<");
escaped.replace(">", ">");
escaped.replace(""", "\"");
escaped.replace("'", "'");
return escaped;
}
QString CmdOrGuiApp::xml2txt(const QString &str)
{
QString escaped(str);
escaped.replace("&", "&");
escaped.replace("<", "<");
escaped.replace(">", ">");
escaped.replace(""", "\"");
escaped.replace("'", "'");
return escaped;
}
#endif // CMDORGUIAPP_H