/
corecliutils.h
189 lines (132 loc) · 6.8 KB
/
corecliutils.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://gnu.org/licenses>.
*******************************************************************************/
//==============================================================================
// Core CLI utilities
//==============================================================================
#pragma once
//==============================================================================
#include "coreglobal.h"
#include "file.h"
#include "filetypeinterface.h"
#include "plugin.h"
#include "plugininfo.h"
//==============================================================================
#include <QAbstractMessageHandler>
#include <QByteArray>
#include <QCoreApplication>
#include <QDomDocument>
#include <QSet>
#include <QSourceLocation>
#include <QSslError>
#include <QUrl>
//==============================================================================
namespace OpenCOR {
namespace Core {
//==============================================================================
#include "cliutils.h.inl"
//==============================================================================
} // namespace Core
} // namespace OpenCOR
//==============================================================================
using QBoolList = QList<bool>;
using QIntList = QList<int>;
using QDoubleList = QList<double>;
//==============================================================================
using QBoolSet = QSet<bool>;
using QIntSet = QSet<int>;
using QDoubleSet = QSet<double>;
//==============================================================================
QBoolList CORE_EXPORT qVariantListToBoolList(const QVariantList &pVariantList);
QVariantList CORE_EXPORT qBoolListToVariantList(const QBoolList &pBoolList);
QIntList CORE_EXPORT qVariantListToIntList(const QVariantList &pVariantList);
QVariantList CORE_EXPORT qIntListToVariantList(const QIntList &pIntList);
//==============================================================================
class QDropEvent;
class QNetworkReply;
//==============================================================================
namespace OpenCOR {
namespace Core {
//==============================================================================
class CORE_EXPORT DummyMessageHandler : public QAbstractMessageHandler
{
Q_OBJECT
protected:
void handleMessage(QtMsgType pType, const QString &pDescription,
const QUrl &pIdentifier,
const QSourceLocation &pSourceLocation) override;
};
//==============================================================================
// Note: both cliutils.h and corecliutils.h must specifically define
// SynchronousFileDownloader. To have it in corecliutils.h.inl is NOT good
// enough since the MOC won't pick it up...
class SynchronousFileDownloader : public QObject
{
Q_OBJECT
public:
bool download(const QString &pUrl, QByteArray &pContents,
QString *pErrorMessage) const;
private slots:
void networkAccessManagerSslErrors(QNetworkReply *pNetworkReply,
const QList<QSslError> &pSslErrors);
};
//==============================================================================
quint64 CORE_EXPORT totalMemory();
quint64 CORE_EXPORT freeMemory();
QString CORE_EXPORT digitGroupNumber(const QString &pNumber);
QString CORE_EXPORT sizeAsString(quint64 pSize, int pPrecision = 1);
QString CORE_EXPORT formatTime(qint64 pTime);
QString CORE_EXPORT sha1(const QByteArray &pByteArray);
QString CORE_EXPORT sha1(const QString &pString);
QString CORE_EXPORT fileSha1(const QString &pFileName);
void CORE_EXPORT stringPositionAsLineColumn(const QString &pString,
const QString &pEol, int pPosition,
int &pLine, int &pColumn);
void CORE_EXPORT stringLineColumnAsPosition(const QString &pString,
const QString &pEol, int pLine,
int pColumn, int &pPosition);
void CORE_EXPORT * globalInstance(const QString &pObjectName,
void *pDefaultGlobalInstance = nullptr);
QString CORE_EXPORT activeDirectory();
void CORE_EXPORT setActiveDirectory(const QString &pDirName);
bool CORE_EXPORT isDirectory(const QString &pDirName);
bool CORE_EXPORT isEmptyDirectory(const QString &pDirName);
void CORE_EXPORT doNothing(quint64 pMax);
void CORE_EXPORT doNothing(const quint64 *pMax, const bool *pStopped = nullptr);
QString CORE_EXPORT cliOpenFile(const QString &pFileName,
File::Type pType = File::Type::Local,
const QString &pUrl = {});
QString CORE_EXPORT cliOpenRemoteFile(const QString &pUrl);
QString CORE_EXPORT formatXml(const QString &pXml);
QString CORE_EXPORT cleanContentMathml(const QString &pContentMathml);
QString CORE_EXPORT cleanPresentationMathml(const QString &pPresentationMathml);
QString CORE_EXPORT newFileName(const QString &pFileName, const QString &pExtra,
bool pBefore, const QString &pFileExtension);
QString CORE_EXPORT newFileName(const QString &pFileName, const QString &pExtra,
bool pBefore);
QString CORE_EXPORT newFileName(const QString &pFileName,
const QString &pFileExtension);
bool CORE_EXPORT validXml(const QByteArray &pXml, const QByteArray &pSchema);
bool CORE_EXPORT validXmlFile(const QString &pXmlFileName,
const QString &pSchemaFileName);
QByteArray CORE_EXPORT serialiseDomDocument(const QDomDocument &pDomDocument);
QStringList CORE_EXPORT filters(const FileTypeInterfaces &pFileTypeInterfaces);
QStringList CORE_EXPORT filters(const FileTypeInterfaces &pFileTypeInterfaces,
const QString &pMimeType);
QStringList CORE_EXPORT droppedFileNames(QDropEvent *pEvent);
//==============================================================================
} // namespace Core
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================