| 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 | |
| 31 | using SimpleIni = CSimpleIniA; |
| 32 | using PSimpleIni = std::shared_ptr<SimpleIni>; |
| 33 | |
| 34 | enum class FileType{ |
| 35 | CSource, // c source file (.c) |
| 36 | CppSource, // c++ source file (.cpp) |
| 37 | , // c header (.h) |
| 38 | , // 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 | |
| 45 | enum class SearchFileScope { |
| 46 | currentFile, |
| 47 | wholeProject, |
| 48 | openedFiles |
| 49 | }; |
| 50 | |
| 51 | enum AutoSaveTarget { |
| 52 | astCurrentFile, |
| 53 | astAllOpennedFiles, |
| 54 | astAllProjectFiles |
| 55 | }; |
| 56 | |
| 57 | enum AutoSaveStrategy { |
| 58 | assOverwrite, |
| 59 | assAppendUnixTimestamp, |
| 60 | assAppendFormatedTimeStamp |
| 61 | }; |
| 62 | |
| 63 | enum 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 | |
| 83 | enum FormatterOperatorAlign { |
| 84 | foaNone, |
| 85 | foaType, |
| 86 | foaMiddle, |
| 87 | foaName |
| 88 | }; |
| 89 | |
| 90 | enum FormatterIndentType { |
| 91 | fitSpace, |
| 92 | fitTab |
| 93 | }; |
| 94 | |
| 95 | enum class SplitProcessCommandQuoteType { |
| 96 | None, |
| 97 | Single, |
| 98 | Double |
| 99 | }; |
| 100 | |
| 101 | FileType getFileType(const QString& filename); |
| 102 | QStringList splitProcessCommand(const QString& cmd); |
| 103 | |
| 104 | QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes); |
| 105 | QString genMakePath1(const QString& fileName); |
| 106 | QString genMakePath2(const QString& fileName); |
| 107 | QString getCompiledExecutableName(const QString& filename); |
| 108 | bool programHasConsole(const QString& filename); |
| 109 | |
| 110 | QString parseMacros(const QString& s); |
| 111 | |
| 112 | class CppParser; |
| 113 | void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1); |
| 114 | |
| 115 | int getNewFileNumber(); |
| 116 | |
| 117 | QByteArray 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 | |
| 122 | void executeFile(const QString& fileName, |
| 123 | const QString& params, |
| 124 | const QString& workingDir, |
| 125 | const QString& tempFile); |
| 126 | |
| 127 | bool isGreenEdition(); |
| 128 | |
| 129 | #ifdef Q_OS_WIN |
| 130 | bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value); |
| 131 | #endif |
| 132 | |
| 133 | qulonglong stringToHex(const QString& str, bool &isOk); |
| 134 | |
| 135 | bool findComplement(const QString& s, |
| 136 | const QChar& fromToken, |
| 137 | const QChar& toToken, |
| 138 | int& curPos, |
| 139 | int increment); |
| 140 | |
| 141 | bool haveGoodContrast(const QColor& c1, const QColor &c2); |
| 142 | |
| 143 | QByteArray getHTTPBody(const QByteArray& content); |
| 144 | |
| 145 | QString getSizeString(int size); |
| 146 | |
| 147 | #endif // UTILS_H |
| 148 | |