1/*
2 * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#ifndef UTILS_H
18#define UTILS_H
19#include <type_traits>
20#include <utility>
21#include <functional>
22#include <QString>
23#include <QRect>
24#include <QStringList>
25#include <memory>
26#include <QThread>
27#include <QProcessEnvironment>
28#include "SimpleIni.h"
29#include "qt_utils/utils.h"
30
31using SimpleIni = CSimpleIniA;
32using PSimpleIni = std::shared_ptr<SimpleIni>;
33
34enum class FileType{
35 CSource, // c source file (.c)
36 CppSource, // c++ source file (.cpp)
37 CHeader, // c header (.h)
38 CppHeader, // c++ header (.hpp)
39 WindowsResourceSource, // resource source (.res)
40 Project, //Red Panda C++ Project (.dev)
41 Text, // text file
42 Other // any others
43};
44
45enum class SearchFileScope {
46 currentFile,
47 wholeProject,
48 openedFiles
49};
50
51enum AutoSaveTarget {
52 astCurrentFile,
53 astAllOpennedFiles,
54 astAllProjectFiles
55};
56
57enum AutoSaveStrategy {
58 assOverwrite,
59 assAppendUnixTimestamp,
60 assAppendFormatedTimeStamp
61};
62
63enum FormatterBraceStyle {
64 fbsDefault,
65 fbsAllman,
66 fbsJava,
67 fbsKR,
68 fbsStroustrup,
69 fbsWitesmith,
70 fbsVtk,
71 fbsRatliff,
72 fbsGNU,
73 fbsLinux,
74 fbsHorstmann,
75 fbs1TBS,
76 fbsGoogle,
77 fbsMozilla,
78 fbsWebkit,
79 fbsPico,
80 fbsLisp
81};
82
83enum FormatterOperatorAlign {
84 foaNone,
85 foaType,
86 foaMiddle,
87 foaName
88};
89
90enum FormatterIndentType {
91 fitSpace,
92 fitTab
93};
94
95enum class SplitProcessCommandQuoteType {
96 None,
97 Single,
98 Double
99};
100
101FileType getFileType(const QString& filename);
102QStringList splitProcessCommand(const QString& cmd);
103
104QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes);
105QString genMakePath1(const QString& fileName);
106QString genMakePath2(const QString& fileName);
107QString getCompiledExecutableName(const QString& filename);
108bool programHasConsole(const QString& filename);
109
110QString parseMacros(const QString& s);
111
112class CppParser;
113void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
114
115int getNewFileNumber();
116
117QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,
118 const QByteArray& inputContent = QByteArray(),
119 bool inheritEnvironment = false,
120 const QProcessEnvironment& env = QProcessEnvironment() );
121
122void executeFile(const QString& fileName,
123 const QString& params,
124 const QString& workingDir,
125 const QString& tempFile);
126
127bool isGreenEdition();
128
129#ifdef Q_OS_WIN
130bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value);
131#endif
132
133qulonglong stringToHex(const QString& str, bool &isOk);
134
135bool findComplement(const QString& s,
136 const QChar& fromToken,
137 const QChar& toToken,
138 int& curPos,
139 int increment);
140
141bool haveGoodContrast(const QColor& c1, const QColor &c2);
142
143QByteArray getHTTPBody(const QByteArray& content);
144
145QString getSizeString(int size);
146
147#endif // UTILS_H
148