2022-09-26 12:01:45 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* 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 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://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef UTILS_H
|
|
|
|
#define UTILS_H
|
|
|
|
#include <type_traits>
|
|
|
|
#include <utility>
|
|
|
|
#include <functional>
|
|
|
|
#include <QString>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <memory>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
#include "SimpleIni.h"
|
|
|
|
#include "qt_utils/utils.h"
|
|
|
|
|
|
|
|
using SimpleIni = CSimpleIniA;
|
|
|
|
using PSimpleIni = std::shared_ptr<SimpleIni>;
|
|
|
|
|
|
|
|
enum class FileType{
|
|
|
|
CSource, // c source file (.c)
|
|
|
|
CppSource, // c++ source file (.cpp)
|
|
|
|
CHeader, // c header (.h)
|
|
|
|
CppHeader, // c++ header (.hpp)
|
|
|
|
WindowsResourceSource, // resource source (.res)
|
|
|
|
Project, //Red Panda C++ Project (.dev)
|
|
|
|
Text, // text file
|
|
|
|
Other // any others
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SearchFileScope {
|
|
|
|
currentFile,
|
|
|
|
wholeProject,
|
|
|
|
openedFiles
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AutoSaveTarget {
|
|
|
|
astCurrentFile,
|
|
|
|
astAllOpennedFiles,
|
|
|
|
astAllProjectFiles
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AutoSaveStrategy {
|
|
|
|
assOverwrite,
|
|
|
|
assAppendUnixTimestamp,
|
|
|
|
assAppendFormatedTimeStamp
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatterBraceStyle {
|
|
|
|
fbsDefault,
|
|
|
|
fbsAllman,
|
|
|
|
fbsJava,
|
|
|
|
fbsKR,
|
|
|
|
fbsStroustrup,
|
|
|
|
fbsWitesmith,
|
|
|
|
fbsVtk,
|
|
|
|
fbsRatliff,
|
|
|
|
fbsGNU,
|
|
|
|
fbsLinux,
|
|
|
|
fbsHorstmann,
|
|
|
|
fbs1TBS,
|
|
|
|
fbsGoogle,
|
|
|
|
fbsMozilla,
|
|
|
|
fbsWebkit,
|
|
|
|
fbsPico,
|
|
|
|
fbsLisp
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatterOperatorAlign {
|
|
|
|
foaNone,
|
|
|
|
foaType,
|
|
|
|
foaMiddle,
|
|
|
|
foaName
|
|
|
|
};
|
|
|
|
|
|
|
|
enum FormatterIndentType {
|
|
|
|
fitSpace,
|
|
|
|
fitTab
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SplitProcessCommandQuoteType {
|
|
|
|
None,
|
|
|
|
Single,
|
|
|
|
Double
|
|
|
|
};
|
|
|
|
|
|
|
|
FileType getFileType(const QString& filename);
|
|
|
|
QStringList splitProcessCommand(const QString& cmd);
|
|
|
|
|
|
|
|
QString genMakePath(const QString& fileName,bool escapeSpaces, bool encloseInQuotes);
|
|
|
|
QString genMakePath1(const QString& fileName);
|
|
|
|
QString genMakePath2(const QString& fileName);
|
|
|
|
QString getCompiledExecutableName(const QString& filename);
|
|
|
|
bool programHasConsole(const QString& filename);
|
|
|
|
|
|
|
|
QString parseMacros(const QString& s);
|
|
|
|
|
|
|
|
class CppParser;
|
|
|
|
void resetCppParser(std::shared_ptr<CppParser> parser, int compilerSetIndex=-1);
|
|
|
|
|
|
|
|
int getNewFileNumber();
|
|
|
|
|
2022-09-26 14:54:28 +08:00
|
|
|
QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,
|
|
|
|
const QByteArray& inputContent = QByteArray(),
|
|
|
|
bool inheritEnvironment = false,
|
|
|
|
const QProcessEnvironment& env = QProcessEnvironment() );
|
|
|
|
|
|
|
|
void executeFile(const QString& fileName,
|
|
|
|
const QString& params,
|
|
|
|
const QString& workingDir,
|
|
|
|
const QString& tempFile);
|
|
|
|
|
|
|
|
bool isGreenEdition();
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
bool readRegistry(HKEY key,const QByteArray& subKey, const QByteArray& name, QString& value);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
qulonglong stringToHex(const QString& str, bool &isOk);
|
|
|
|
|
|
|
|
bool findComplement(const QString& s,
|
|
|
|
const QChar& fromToken,
|
|
|
|
const QChar& toToken,
|
|
|
|
int& curPos,
|
|
|
|
int increment);
|
|
|
|
|
|
|
|
bool haveGoodContrast(const QColor& c1, const QColor &c2);
|
|
|
|
|
|
|
|
QByteArray getHTTPBody(const QByteArray& content);
|
|
|
|
|
|
|
|
QString getSizeString(int size);
|
|
|
|
|
2022-09-26 12:01:45 +08:00
|
|
|
#endif // UTILS_H
|