mirror of
https://github.com/zhuzichu520/FluentUI.git
synced 2025-07-06 02:15:23 +08:00
update clang-format
This commit is contained in:
@ -4,11 +4,11 @@
|
||||
#include <QGuiApplication>
|
||||
#include "Version.h"
|
||||
|
||||
AppInfo::AppInfo(QObject *parent)
|
||||
: QObject{parent} {
|
||||
AppInfo::AppInfo(QObject *parent) : QObject{parent} {
|
||||
version(APPLICATION_VERSION);
|
||||
}
|
||||
|
||||
|
||||
[[maybe_unused]] void AppInfo::testCrash() {
|
||||
auto *crash = reinterpret_cast<volatile int *>(0);
|
||||
*crash = 0;
|
||||
|
@ -6,13 +6,12 @@
|
||||
#include "singleton.h"
|
||||
|
||||
class AppInfo : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, version)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, version)
|
||||
private:
|
||||
explicit AppInfo(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(AppInfo)
|
||||
|
||||
[[maybe_unused]] Q_INVOKABLE void testCrash();
|
||||
SINGLETON(AppInfo)
|
||||
Q_INVOKABLE [[maybe_unused]] void testCrash();
|
||||
};
|
||||
|
@ -11,21 +11,28 @@
|
||||
|
||||
#pragma comment(lib, "Dbghelp.lib")
|
||||
|
||||
static void
|
||||
miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
|
||||
typedef HRESULT (WINAPI *MiniDumpWriteDumpPtr)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
static void miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile,
|
||||
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam) {
|
||||
typedef HRESULT(WINAPI * MiniDumpWriteDumpPtr)(
|
||||
HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType,
|
||||
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
|
||||
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
HMODULE module = LoadLibraryW(L"Dbghelp.dll");
|
||||
if (module) {
|
||||
MiniDumpWriteDumpPtr mini_dump_write_dump;
|
||||
mini_dump_write_dump = reinterpret_cast<MiniDumpWriteDumpPtr>(GetProcAddress(module, "MiniDumpWriteDump"));
|
||||
mini_dump_write_dump =
|
||||
reinterpret_cast<MiniDumpWriteDumpPtr>(GetProcAddress(module, "MiniDumpWriteDump"));
|
||||
if (mini_dump_write_dump) {
|
||||
mini_dump_write_dump(hProcess, ProcessId, hFile, static_cast<MINIDUMP_TYPE>(80), ExceptionParam, nullptr, CallbackParam);
|
||||
mini_dump_write_dump(hProcess, ProcessId, hFile, static_cast<MINIDUMP_TYPE>(80),
|
||||
ExceptionParam, nullptr, CallbackParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input, PMINIDUMP_CALLBACK_OUTPUT output) {
|
||||
BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input,
|
||||
PMINIDUMP_CALLBACK_OUTPUT output) {
|
||||
if (input == nullptr || output == nullptr)
|
||||
return FALSE;
|
||||
|
||||
@ -42,8 +49,7 @@ BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input, PM
|
||||
output->ModuleWriteFlags &= ~ModuleWriteModule;
|
||||
}
|
||||
ret = TRUE;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -51,7 +57,9 @@ BOOL CALLBACK MyMiniDumpCallback(PVOID, const PMINIDUMP_CALLBACK_INPUT input, PM
|
||||
}
|
||||
|
||||
void WriteDump(EXCEPTION_POINTERS *exp, const std::wstring &path) {
|
||||
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
HANDLE h = ::CreateFileW(path.c_str(), GENERIC_WRITE | GENERIC_READ,
|
||||
FILE_SHARE_WRITE | FILE_SHARE_READ, nullptr, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
MINIDUMP_EXCEPTION_INFORMATION info;
|
||||
info.ThreadId = ::GetCurrentThreadId();
|
||||
info.ExceptionPointers = exp;
|
||||
@ -64,8 +72,10 @@ void WriteDump(EXCEPTION_POINTERS *exp, const std::wstring &path) {
|
||||
}
|
||||
|
||||
LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *exp) {
|
||||
const QString dumpFileName = QString("%1_%2.dmp").arg("crash", QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
|
||||
const QString dumpDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/dmp";
|
||||
const QString dumpFileName =
|
||||
QString("%1_%2.dmp").arg("crash", QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss"));
|
||||
const QString dumpDirPath =
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/dmp";
|
||||
const QDir dumpDir(dumpDirPath);
|
||||
if (!dumpDir.exists()) {
|
||||
dumpDir.mkpath(dumpDirPath);
|
||||
@ -76,4 +86,4 @@ LONG WINAPI MyUnhandledExceptionFilter(EXCEPTION_POINTERS *exp) {
|
||||
arguments << "-crashed=" + dumpFilePath;
|
||||
QProcess::startDetached(QGuiApplication::applicationFilePath(), arguments);
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,7 @@ CircularReveal::CircularReveal(QQuickItem *parent) : QQuickPaintedItem(parent) {
|
||||
setVisible(false);
|
||||
Q_EMIT animationFinished();
|
||||
});
|
||||
connect(this, &CircularReveal::radiusChanged, this, [=]() {
|
||||
update();
|
||||
});
|
||||
connect(this, &CircularReveal::radiusChanged, this, [=]() { update(); });
|
||||
}
|
||||
|
||||
void CircularReveal::paint(QPainter *painter) {
|
||||
@ -36,7 +34,8 @@ void CircularReveal::paint(QPainter *painter) {
|
||||
_anim->setEndValue(radius);
|
||||
_center = center;
|
||||
_grabResult = _target->grabToImage(QSize(w, h));
|
||||
connect(_grabResult.data(), &QQuickItemGrabResult::ready, this, &CircularReveal::handleGrabResult);
|
||||
connect(_grabResult.data(), &QQuickItemGrabResult::ready, this,
|
||||
&CircularReveal::handleGrabResult);
|
||||
}
|
||||
|
||||
void CircularReveal::handleGrabResult() {
|
||||
|
@ -7,20 +7,15 @@
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class CircularReveal : public QQuickPaintedItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO_P(QQuickItem*, target)
|
||||
Q_PROPERTY_AUTO(int, radius)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO_P(QQuickItem *, target)
|
||||
Q_PROPERTY_AUTO(int, radius)
|
||||
public:
|
||||
explicit CircularReveal(QQuickItem *parent = nullptr);
|
||||
|
||||
void paint(QPainter *painter) override;
|
||||
|
||||
[[maybe_unused]] Q_INVOKABLE void start(int w, int h, const QPoint ¢er, int radius);
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void start(int w, int h, const QPoint ¢er, int radius);
|
||||
Q_SIGNAL void imageChanged();
|
||||
|
||||
Q_SIGNAL void animationFinished();
|
||||
|
||||
Q_SLOT void handleGrabResult();
|
||||
|
||||
private:
|
||||
|
@ -6,11 +6,10 @@
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class FileWatcher : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, path);
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, path)
|
||||
public:
|
||||
explicit FileWatcher(QObject *parent = nullptr);
|
||||
|
||||
Q_SIGNAL void fileChanged();
|
||||
|
||||
private:
|
||||
|
@ -12,7 +12,9 @@ FpsItem::FpsItem() {
|
||||
});
|
||||
connect(this, &QQuickItem::windowChanged, this, [this] {
|
||||
if (window()) {
|
||||
connect(window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; }, Qt::DirectConnection);
|
||||
connect(
|
||||
window(), &QQuickWindow::afterRendering, this, [this] { _frameCount++; },
|
||||
Qt::DirectConnection);
|
||||
}
|
||||
});
|
||||
timer->start(1000);
|
||||
|
@ -4,12 +4,11 @@
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class FpsItem : public QQuickItem {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, fps)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, fps)
|
||||
public:
|
||||
FpsItem();
|
||||
|
||||
private:
|
||||
int _frameCount = 0;
|
||||
|
||||
};
|
||||
};
|
||||
|
@ -7,11 +7,8 @@
|
||||
class FBORenderer : public QQuickFramebufferObject::Renderer, protected QOpenGLFunctions {
|
||||
public:
|
||||
explicit FBORenderer(const OpenGLItem *item);
|
||||
|
||||
void render() override;
|
||||
|
||||
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) override;
|
||||
|
||||
QOpenGLShaderProgram program;
|
||||
const OpenGLItem *item = nullptr;
|
||||
};
|
||||
@ -19,22 +16,22 @@ public:
|
||||
FBORenderer::FBORenderer(const OpenGLItem *item) {
|
||||
this->item = item;
|
||||
initializeOpenGLFunctions();
|
||||
program.addCacheableShaderFromSourceCode(QOpenGLShader::Vertex,
|
||||
"attribute highp vec4 vertices;"
|
||||
"varying highp vec2 coords;"
|
||||
"void main() {"
|
||||
" gl_Position = vertices;"
|
||||
" coords = vertices.xy;"
|
||||
"}");
|
||||
program.addCacheableShaderFromSourceCode(QOpenGLShader::Fragment,
|
||||
"uniform lowp float t;"
|
||||
"varying highp vec2 coords;"
|
||||
"void main() {"
|
||||
" lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));"
|
||||
" i = smoothstep(t - 0.8, t + 0.8, i);"
|
||||
" i = floor(i * 20.) / 20.;"
|
||||
" gl_FragColor = vec4(coords * .5 + .5, i, i);"
|
||||
"}");
|
||||
program.addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, "attribute highp vec4 vertices;"
|
||||
"varying highp vec2 coords;"
|
||||
"void main() {"
|
||||
" gl_Position = vertices;"
|
||||
" coords = vertices.xy;"
|
||||
"}");
|
||||
program.addCacheableShaderFromSourceCode(
|
||||
QOpenGLShader::Fragment,
|
||||
"uniform lowp float t;"
|
||||
"varying highp vec2 coords;"
|
||||
"void main() {"
|
||||
" lowp float i = 1. - (pow(abs(coords.x), 4.) + pow(abs(coords.y), 4.));"
|
||||
" i = smoothstep(t - 0.8, t + 0.8, i);"
|
||||
" i = floor(i * 20.) / 20.;"
|
||||
" gl_FragColor = vec4(coords * .5 + .5, i, i);"
|
||||
"}");
|
||||
|
||||
program.bindAttributeLocation("vertices", 0);
|
||||
program.link();
|
||||
@ -54,16 +51,11 @@ void FBORenderer::render() {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
program.bind();
|
||||
program.enableAttributeArray(0);
|
||||
float values[] = {
|
||||
-1, -1,
|
||||
1, -1,
|
||||
-1, 1,
|
||||
1, 1
|
||||
};
|
||||
float values[] = {-1, -1, 1, -1, -1, 1, 1, 1};
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
program.setAttributeArray(0, GL_FLOAT, values, 2);
|
||||
program.setUniformValue("t", (float) item->t());
|
||||
glViewport(0, 0, qRound(item->width()*pixelRatio), qRound(item->height()*pixelRatio));
|
||||
glViewport(0, 0, qRound(item->width() * pixelRatio), qRound(item->height() * pixelRatio));
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
|
@ -7,21 +7,17 @@
|
||||
class FBORenderer;
|
||||
|
||||
class OpenGLItem : public QQuickFramebufferObject, protected QOpenGLFunctions {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
|
||||
public:
|
||||
explicit OpenGLItem(QQuickItem *parent = nullptr);
|
||||
|
||||
[[nodiscard]] QQuickFramebufferObject::Renderer *createRenderer() const override;
|
||||
|
||||
void timerEvent(QTimerEvent *) override;
|
||||
|
||||
[[nodiscard]] qreal t() const { return m_t; }
|
||||
|
||||
[[nodiscard]] qreal t() const {
|
||||
return m_t;
|
||||
}
|
||||
void setT(qreal t);
|
||||
|
||||
signals:
|
||||
|
||||
void tChanged();
|
||||
|
||||
private:
|
||||
|
@ -4,11 +4,11 @@
|
||||
#include <QGuiApplication>
|
||||
|
||||
[[maybe_unused]] InitializrHelper::InitializrHelper(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
InitializrHelper::~InitializrHelper() = default;
|
||||
|
||||
|
||||
bool InitializrHelper::copyDir(const QDir &fromDir, const QDir &toDir, bool coverIfFileExists) {
|
||||
const QDir &_formDir = fromDir;
|
||||
QDir _toDir = toDir;
|
||||
@ -17,25 +17,25 @@ bool InitializrHelper::copyDir(const QDir &fromDir, const QDir &toDir, bool cove
|
||||
return false;
|
||||
}
|
||||
QFileInfoList fileInfoList = _formDir.entryInfoList();
|
||||
foreach(QFileInfo fileInfo, fileInfoList) {
|
||||
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
|
||||
continue;
|
||||
if (fileInfo.isDir()) {
|
||||
if (!copyDir(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()), true))
|
||||
return false;
|
||||
} else {
|
||||
if (coverIfFileExists && _toDir.exists(fileInfo.fileName())) {
|
||||
_toDir.remove(fileInfo.fileName());
|
||||
}
|
||||
if (!QFile::copy(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()))) {
|
||||
return false;
|
||||
}
|
||||
foreach (QFileInfo fileInfo, fileInfoList) {
|
||||
if (fileInfo.fileName() == "." || fileInfo.fileName() == "..")
|
||||
continue;
|
||||
if (fileInfo.isDir()) {
|
||||
if (!copyDir(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()), true))
|
||||
return false;
|
||||
} else {
|
||||
if (coverIfFileExists && _toDir.exists(fileInfo.fileName())) {
|
||||
_toDir.remove(fileInfo.fileName());
|
||||
}
|
||||
if (!QFile::copy(fileInfo.filePath(), _toDir.filePath(fileInfo.fileName()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename...Args>
|
||||
template <typename... Args>
|
||||
void InitializrHelper::templateToFile(const QString &source, const QString &dest, Args &&...args) {
|
||||
QFile file(source);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
@ -61,7 +61,8 @@ void InitializrHelper::templateToFile(const QString &source, const QString &dest
|
||||
|
||||
void InitializrHelper::copyFile(const QString &source, const QString &dest) {
|
||||
QFile::copy(source, dest);
|
||||
QFile::setPermissions(dest, QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther);
|
||||
QFile::setPermissions(dest, QFile::WriteOwner | QFile::WriteUser | QFile::WriteGroup |
|
||||
QFile::WriteOther);
|
||||
}
|
||||
|
||||
[[maybe_unused]] void InitializrHelper::generate(const QString &name, const QString &path) {
|
||||
@ -87,15 +88,21 @@ void InitializrHelper::copyFile(const QString &source, const QString &dest) {
|
||||
projectDir.mkpath(projectPath);
|
||||
QDir fluentDir(projectDir.filePath("FluentUI"));
|
||||
copyDir(QDir(QGuiApplication::applicationDirPath() + "/source"), fluentDir);
|
||||
templateToFile(":/example/res/template/CMakeLists.txt.in", projectDir.filePath("CMakeLists.txt"), name);
|
||||
templateToFile(":/example/res/template/src/CMakeLists.txt.in", projectDir.filePath("src/CMakeLists.txt"), name);
|
||||
templateToFile(":/example/res/template/src/main.cpp.in", projectDir.filePath("src/main.cpp"), name);
|
||||
templateToFile(":/example/res/template/src/main.qml.in", projectDir.filePath("src/main.qml"), name);
|
||||
templateToFile(":/example/res/template/src/en_US.ts.in", projectDir.filePath("src/" + name + "_en_US.ts"), name);
|
||||
templateToFile(":/example/res/template/src/zh_CN.ts.in", projectDir.filePath("src/" + name + "_zh_CN.ts"), name);
|
||||
templateToFile(":/example/res/template/CMakeLists.txt.in",
|
||||
projectDir.filePath("CMakeLists.txt"), name);
|
||||
templateToFile(":/example/res/template/src/CMakeLists.txt.in",
|
||||
projectDir.filePath("src/CMakeLists.txt"), name);
|
||||
templateToFile(":/example/res/template/src/main.cpp.in", projectDir.filePath("src/main.cpp"),
|
||||
name);
|
||||
templateToFile(":/example/res/template/src/main.qml.in", projectDir.filePath("src/main.qml"),
|
||||
name);
|
||||
templateToFile(":/example/res/template/src/en_US.ts.in",
|
||||
projectDir.filePath("src/" + name + "_en_US.ts"), name);
|
||||
templateToFile(":/example/res/template/src/zh_CN.ts.in",
|
||||
projectDir.filePath("src/" + name + "_zh_CN.ts"), name);
|
||||
copyFile(":/example/res/template/src/App.qml.in", projectDir.filePath("src/App.qml"));
|
||||
copyFile(":/example/res/template/src/qml.qrc.in", projectDir.filePath("src/qml.qrc"));
|
||||
copyFile(":/example/res/template/src/logo.ico.in", projectDir.filePath("src/logo.ico"));
|
||||
copyFile(":/example/res/template/src/README.md.in", projectDir.filePath("src/README.md"));
|
||||
return this->success(projectPath+"/CMakeLists.txt");
|
||||
return this->success(projectPath + "/CMakeLists.txt");
|
||||
}
|
||||
|
@ -6,25 +6,18 @@
|
||||
#include "src/singleton.h"
|
||||
|
||||
class InitializrHelper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
[[maybe_unused]] explicit InitializrHelper(QObject *parent = nullptr);
|
||||
|
||||
bool copyDir(const QDir &fromDir, const QDir &toDir, bool coverIfFileExists = true);
|
||||
|
||||
static void copyFile(const QString &source, const QString &dest);
|
||||
|
||||
template<typename...Args>
|
||||
template <typename... Args>
|
||||
void templateToFile(const QString &source, const QString &dest, Args &&...args);
|
||||
|
||||
public:
|
||||
SINGLETON(InitializrHelper)
|
||||
|
||||
SINGLETON(InitializrHelper)
|
||||
~InitializrHelper() override;
|
||||
|
||||
Q_INVOKABLE [[maybe_unused]] void generate(const QString &name, const QString &path);
|
||||
|
||||
Q_SIGNAL void error(const QString &message);
|
||||
|
||||
Q_SIGNAL void success(const QString &path);
|
||||
};
|
||||
|
@ -13,11 +13,9 @@
|
||||
#include "Version.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <process.h>
|
||||
|
||||
# include <process.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef QT_ENDL
|
||||
@ -38,19 +36,20 @@ static std::unique_ptr<QTextStream> g_logStream = nullptr;
|
||||
static int g_logLevel = 4;
|
||||
|
||||
std::map<QtMsgType, int> logLevelMap = {
|
||||
{QtFatalMsg, 0},
|
||||
{QtCriticalMsg, 1},
|
||||
{QtWarningMsg, 2},
|
||||
{QtInfoMsg, 3},
|
||||
{QtDebugMsg, 4}
|
||||
{QtFatalMsg, 0},
|
||||
{QtCriticalMsg, 1},
|
||||
{QtWarningMsg, 2},
|
||||
{QtInfoMsg, 3},
|
||||
{QtDebugMsg, 4}
|
||||
};
|
||||
|
||||
QString Log::prettyProductInfoWrapper() {
|
||||
auto productName = QSysInfo::prettyProductName();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
|
||||
#if defined(Q_OS_MACOS)
|
||||
auto macosVersionFile = QString::fromUtf8("/System/Library/CoreServices/.SystemVersionPlatform.plist");
|
||||
auto fi = QFileInfo (macosVersionFile);
|
||||
# if defined(Q_OS_MACOS)
|
||||
auto macosVersionFile =
|
||||
QString::fromUtf8("/System/Library/CoreServices/.SystemVersionPlatform.plist");
|
||||
auto fi = QFileInfo(macosVersionFile);
|
||||
if (fi.exists() && fi.isReadable()) {
|
||||
auto plistFile = QFile(macosVersionFile);
|
||||
plistFile.open(QIODevice::ReadOnly);
|
||||
@ -69,10 +68,12 @@ QString Log::prettyProductInfoWrapper() {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
#if defined(Q_OS_WIN)
|
||||
QSettings regKey{QString::fromUtf8(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"), QSettings::NativeFormat};
|
||||
QSettings regKey{
|
||||
QString::fromUtf8(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"),
|
||||
QSettings::NativeFormat};
|
||||
if (regKey.contains(QString::fromUtf8("CurrentBuildNumber"))) {
|
||||
auto buildNumber = regKey.value(QString::fromUtf8("CurrentBuildNumber")).toInt();
|
||||
if (buildNumber > 0) {
|
||||
@ -91,7 +92,8 @@ QString Log::prettyProductInfoWrapper() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
static inline void messageHandler(const QtMsgType type, const QMessageLogContext &context, const QString &message) {
|
||||
static inline void messageHandler(const QtMsgType type, const QMessageLogContext &context,
|
||||
const QString &message) {
|
||||
if (message == "Could not get the INetworkConnection instance for the adapter GUID.") {
|
||||
return;
|
||||
}
|
||||
@ -132,14 +134,15 @@ static inline void messageHandler(const QtMsgType type, const QMessageLogContext
|
||||
sprintf(fn, "%s", ptrTmp + 1);
|
||||
strFileTmp = fn;
|
||||
}
|
||||
fileAndLineLogStr = QString::fromStdString("[%1:%2]").arg(QString::fromStdString(strFileTmp), QString::number(context.line));
|
||||
fileAndLineLogStr = QString::fromStdString("[%1:%2]").arg(
|
||||
QString::fromStdString(strFileTmp), QString::number(context.line));
|
||||
}
|
||||
const QString finalMessage = QString::fromStdString("%1[%2]%3[%4]:%5").arg(
|
||||
QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"),
|
||||
levelName,
|
||||
fileAndLineLogStr,
|
||||
QString::number(reinterpret_cast<quintptr>(QThread::currentThreadId())),
|
||||
message);
|
||||
const QString finalMessage =
|
||||
QString::fromStdString("%1[%2]%3[%4]:%5")
|
||||
.arg(QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss.zzz"), levelName,
|
||||
fileAndLineLogStr,
|
||||
QString::number(reinterpret_cast<quintptr>(QThread::currentThreadId())),
|
||||
message);
|
||||
if ((type == QtInfoMsg) || (type == QtDebugMsg)) {
|
||||
std::cout << qPrintable(finalMessage) << std::endl;
|
||||
} else {
|
||||
@ -151,7 +154,8 @@ static inline void messageHandler(const QtMsgType type, const QMessageLogContext
|
||||
if (!g_logFile) {
|
||||
g_logFile = std::make_unique<QFile>(g_file_path);
|
||||
if (!g_logFile->open(QFile::WriteOnly | QFile::Text | QFile::Append)) {
|
||||
std::cerr << "Can't open file to write: " << qPrintable(g_logFile->errorString()) << std::endl;
|
||||
std::cerr << "Can't open file to write: " << qPrintable(g_logFile->errorString())
|
||||
<< std::endl;
|
||||
g_logFile.reset();
|
||||
g_logError = true;
|
||||
return;
|
||||
@ -179,8 +183,10 @@ void Log::setup(char *argv[], const QString &app, int level) {
|
||||
QString applicationPath = QString::fromStdString(argv[0]);
|
||||
once = true;
|
||||
g_app = app;
|
||||
const QString logFileName = QString("%1_%2.log").arg(g_app, QDateTime::currentDateTime().toString("yyyyMMdd"));
|
||||
const QString logDirPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/log";
|
||||
const QString logFileName =
|
||||
QString("%1_%2.log").arg(g_app, QDateTime::currentDateTime().toString("yyyyMMdd"));
|
||||
const QString logDirPath =
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/log";
|
||||
const QDir logDir(logDirPath);
|
||||
if (!logDir.exists()) {
|
||||
logDir.mkpath(logDirPath);
|
||||
@ -195,7 +201,7 @@ void Log::setup(char *argv[], const QString &app, int level) {
|
||||
#ifdef WIN32
|
||||
qInfo() << "[ProcessId]" << QString::number(_getpid());
|
||||
#else
|
||||
qInfo()<<"[ProcessId]"<<QString::number(getpid());
|
||||
qInfo() << "[ProcessId]" << QString::number(getpid());
|
||||
#endif
|
||||
qInfo() << "[GitHashCode]" << COMMIT_HASH;
|
||||
qInfo() << "[DeviceInfo]";
|
||||
|
@ -4,6 +4,5 @@
|
||||
|
||||
namespace Log {
|
||||
QString prettyProductInfoWrapper();
|
||||
|
||||
void setup(char *argv[], const QString &app, int level = 4);
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <utility>
|
||||
|
||||
|
||||
NetworkCallable::NetworkCallable(QObject *parent) : QObject{parent} {
|
||||
|
||||
}
|
||||
|
||||
QString NetworkParams::method2String() const {
|
||||
@ -64,12 +62,11 @@ bool NetworkParams::getOpenLog() const {
|
||||
return Network::getInstance()->openLog();
|
||||
}
|
||||
|
||||
FluDownloadParam::FluDownloadParam(QObject *parent)
|
||||
: QObject{parent} {
|
||||
FluDownloadParam::FluDownloadParam(QObject *parent) : QObject{parent} {
|
||||
}
|
||||
|
||||
FluDownloadParam::FluDownloadParam(QString destPath, bool append, QObject *parent)
|
||||
: QObject{parent} {
|
||||
: QObject{parent} {
|
||||
this->_destPath = std::move(destPath);
|
||||
this->_append = append;
|
||||
}
|
||||
@ -80,7 +77,7 @@ NetworkParams::NetworkParams(QObject *parent) : QObject{parent} {
|
||||
}
|
||||
|
||||
NetworkParams::NetworkParams(QString url, Type type, Method method, QObject *parent)
|
||||
: QObject{parent} {
|
||||
: QObject{parent} {
|
||||
this->_method = method;
|
||||
this->_url = std::move(url);
|
||||
this->_type = type;
|
||||
@ -178,12 +175,14 @@ void Network::handle(NetworkParams *params, NetworkCallable *c) {
|
||||
callable->start();
|
||||
}
|
||||
QString cacheKey = params->buildCacheKey();
|
||||
if (params->_cacheMode == NetworkType::CacheMode::FirstCacheThenRequest && cacheExists(cacheKey)) {
|
||||
if (params->_cacheMode == NetworkType::CacheMode::FirstCacheThenRequest &&
|
||||
cacheExists(cacheKey)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->cache(readCache(cacheKey));
|
||||
}
|
||||
}
|
||||
if (params->_cacheMode == NetworkType::CacheMode::IfNoneCacheRequest && cacheExists(cacheKey)) {
|
||||
if (params->_cacheMode == NetworkType::CacheMode::IfNoneCacheRequest &&
|
||||
cacheExists(cacheKey)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->cache(readCache(cacheKey));
|
||||
callable->finish();
|
||||
@ -194,7 +193,8 @@ void Network::handle(NetworkParams *params, NetworkCallable *c) {
|
||||
QNetworkAccessManager manager;
|
||||
manager.setTransferTimeout(params->getTimeout());
|
||||
QEventLoop loop;
|
||||
connect(&manager, &QNetworkAccessManager::finished, &manager, [&loop](QNetworkReply *reply) { loop.quit(); });
|
||||
connect(&manager, &QNetworkAccessManager::finished, &manager,
|
||||
[&loop](QNetworkReply *reply) { loop.quit(); });
|
||||
for (int i = 0; i <= params->getRetry() - 1; ++i) {
|
||||
QUrl url(params->_url);
|
||||
addQueryParam(&url, params->_queryMap);
|
||||
@ -216,9 +216,11 @@ void Network::handle(NetworkParams *params, NetworkCallable *c) {
|
||||
QMetaObject::Connection conn_destroyed = {};
|
||||
QMetaObject::Connection conn_quit = {};
|
||||
if (params->_target) {
|
||||
conn_destroyed = connect(params->_target, &QObject::destroyed, &manager, abortCallable);
|
||||
conn_destroyed =
|
||||
connect(params->_target, &QObject::destroyed, &manager, abortCallable);
|
||||
}
|
||||
conn_quit = connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager, abortCallable);
|
||||
conn_quit = connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit,
|
||||
&manager, abortCallable);
|
||||
loop.exec();
|
||||
if (conn_destroyed) {
|
||||
disconnect(conn_destroyed);
|
||||
@ -247,7 +249,8 @@ void Network::handle(NetworkParams *params, NetworkCallable *c) {
|
||||
} else {
|
||||
if (i == params->getRetry() - 1) {
|
||||
if (!callable.isNull()) {
|
||||
if (params->_cacheMode == NetworkType::CacheMode::RequestFailedReadCache && cacheExists(cacheKey)) {
|
||||
if (params->_cacheMode == NetworkType::CacheMode::RequestFailedReadCache &&
|
||||
cacheExists(cacheKey)) {
|
||||
if (!callable.isNull()) {
|
||||
callable->cache(readCache(cacheKey));
|
||||
}
|
||||
@ -332,35 +335,41 @@ void Network::handleDownload(NetworkParams *params, NetworkCallable *c) {
|
||||
reply->abort();
|
||||
}
|
||||
};
|
||||
connect(&manager, &QNetworkAccessManager::finished, &manager, [&loop](QNetworkReply *reply) { loop.quit(); });
|
||||
connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager, [&loop, reply]() { reply->abort(), loop.quit(); });
|
||||
connect(&manager, &QNetworkAccessManager::finished, &manager,
|
||||
[&loop](QNetworkReply *reply) { loop.quit(); });
|
||||
connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager,
|
||||
[&loop, reply]() { reply->abort(), loop.quit(); });
|
||||
QMetaObject::Connection conn_destroyed = {};
|
||||
QMetaObject::Connection conn_quit = {};
|
||||
if (params->_target) {
|
||||
conn_destroyed = connect(params->_target, &QObject::destroyed, &manager, abortCallable);
|
||||
}
|
||||
conn_quit = connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager, abortCallable);
|
||||
connect(reply, &QNetworkReply::readyRead, reply, [reply, seek, destFile, cacheFile, callable] {
|
||||
if (!reply || !destFile || reply->error() != QNetworkReply::NoError) {
|
||||
return;
|
||||
}
|
||||
QMap<QString, QVariant> downInfo;
|
||||
qint64 contentLength = reply->header(QNetworkRequest::ContentLengthHeader).toLongLong() + seek;
|
||||
downInfo.insert("contentLength", contentLength);
|
||||
QString eTag = reply->header(QNetworkRequest::ETagHeader).toString();
|
||||
downInfo.insert("eTag", eTag);
|
||||
destFile->write(reply->readAll());
|
||||
destFile->flush();
|
||||
downInfo.insert("fileSize", destFile->size());
|
||||
if (cacheFile->isOpen()) {
|
||||
cacheFile->resize(0);
|
||||
cacheFile->write(QJsonDocument::fromVariant(QVariant(downInfo)).toJson().toBase64());
|
||||
cacheFile->flush();
|
||||
}
|
||||
if (!callable.isNull()) {
|
||||
callable->downloadProgress(destFile->size(), contentLength);
|
||||
}
|
||||
});
|
||||
conn_quit = connect(QGuiApplication::instance(), &QGuiApplication::aboutToQuit, &manager,
|
||||
abortCallable);
|
||||
connect(reply, &QNetworkReply::readyRead, reply,
|
||||
[reply, seek, destFile, cacheFile, callable] {
|
||||
if (!reply || !destFile || reply->error() != QNetworkReply::NoError) {
|
||||
return;
|
||||
}
|
||||
QMap<QString, QVariant> downInfo;
|
||||
qint64 contentLength =
|
||||
reply->header(QNetworkRequest::ContentLengthHeader).toLongLong() + seek;
|
||||
downInfo.insert("contentLength", contentLength);
|
||||
QString eTag = reply->header(QNetworkRequest::ETagHeader).toString();
|
||||
downInfo.insert("eTag", eTag);
|
||||
destFile->write(reply->readAll());
|
||||
destFile->flush();
|
||||
downInfo.insert("fileSize", destFile->size());
|
||||
if (cacheFile->isOpen()) {
|
||||
cacheFile->resize(0);
|
||||
cacheFile->write(
|
||||
QJsonDocument::fromVariant(QVariant(downInfo)).toJson().toBase64());
|
||||
cacheFile->flush();
|
||||
}
|
||||
if (!callable.isNull()) {
|
||||
callable->downloadProgress(destFile->size(), contentLength);
|
||||
}
|
||||
});
|
||||
loop.exec();
|
||||
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (httpStatus == 200) {
|
||||
@ -430,7 +439,9 @@ QString Network::map2String(const QMap<QString, QVariant> &map) {
|
||||
return parameters.join(" ");
|
||||
}
|
||||
|
||||
void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest request, NetworkParams *params, QNetworkReply *&reply, bool isFirst, const QPointer<NetworkCallable> &callable) {
|
||||
void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest request,
|
||||
NetworkParams *params, QNetworkReply *&reply, bool isFirst,
|
||||
const QPointer<NetworkCallable> &callable) {
|
||||
QByteArray verb = params->method2String().toUtf8();
|
||||
switch (params->_type) {
|
||||
case NetworkParams::TYPE_FORM: {
|
||||
@ -438,13 +449,14 @@ void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest reques
|
||||
if (isFormData) {
|
||||
auto *multiPart = new QHttpMultiPart();
|
||||
multiPart->setContentType(QHttpMultiPart::FormDataType);
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
for (const auto &each : params->_paramMap.toStdMap()) {
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, QString("form-data; name=\"%1\"").arg(each.first));
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader,
|
||||
QString("form-data; name=\"%1\"").arg(each.first));
|
||||
part.setBody(each.second.toByteArray());
|
||||
multiPart->append(part);
|
||||
}
|
||||
for (const auto &each: params->_fileMap.toStdMap()) {
|
||||
for (const auto &each : params->_fileMap.toStdMap()) {
|
||||
QString filePath = each.second.toString();
|
||||
QString name = each.first;
|
||||
auto *file = new QFile(filePath);
|
||||
@ -452,21 +464,25 @@ void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest reques
|
||||
file->open(QIODevice::ReadOnly);
|
||||
file->setParent(multiPart);
|
||||
QHttpPart part;
|
||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, QString(R"(form-data; name="%1"; filename="%2")").arg(name, fileName));
|
||||
part.setHeader(
|
||||
QNetworkRequest::ContentDispositionHeader,
|
||||
QString(R"(form-data; name="%1"; filename="%2")").arg(name, fileName));
|
||||
part.setBodyDevice(file);
|
||||
multiPart->append(part);
|
||||
}
|
||||
reply = manager->sendCustomRequest(request, verb, multiPart);
|
||||
multiPart->setParent(reply);
|
||||
connect(reply, &QNetworkReply::uploadProgress, reply, [callable](qint64 bytesSent, qint64 bytesTotal) {
|
||||
if (!callable.isNull() && bytesSent != 0 && bytesTotal != 0) {
|
||||
Q_EMIT callable->uploadProgress(bytesSent, bytesTotal);
|
||||
}
|
||||
});
|
||||
connect(reply, &QNetworkReply::uploadProgress, reply,
|
||||
[callable](qint64 bytesSent, qint64 bytesTotal) {
|
||||
if (!callable.isNull() && bytesSent != 0 && bytesTotal != 0) {
|
||||
Q_EMIT callable->uploadProgress(bytesSent, bytesTotal);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/x-www-form-urlencoded"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
QString("application/x-www-form-urlencoded"));
|
||||
QString value;
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
for (const auto &each : params->_paramMap.toStdMap()) {
|
||||
value += QString("%1=%2").arg(each.first, each.second.toString());
|
||||
value += "&";
|
||||
}
|
||||
@ -479,9 +495,10 @@ void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest reques
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_JSON: {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/json;charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
QString("application/json;charset=utf-8"));
|
||||
QJsonObject json;
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
for (const auto &each : params->_paramMap.toStdMap()) {
|
||||
json.insert(each.first, each.second.toJsonValue());
|
||||
}
|
||||
QByteArray data = QJsonDocument(json).toJson(QJsonDocument::Compact);
|
||||
@ -489,9 +506,10 @@ void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest reques
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_JSONARRAY: {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("application/json;charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
QString("application/json;charset=utf-8"));
|
||||
QJsonArray jsonArray;
|
||||
for (const auto &each: params->_paramMap.toStdMap()) {
|
||||
for (const auto &each : params->_paramMap.toStdMap()) {
|
||||
QJsonObject json;
|
||||
json.insert(each.first, each.second.toJsonValue());
|
||||
jsonArray.append(json);
|
||||
@ -501,7 +519,8 @@ void Network::sendRequest(QNetworkAccessManager *manager, QNetworkRequest reques
|
||||
break;
|
||||
}
|
||||
case NetworkParams::TYPE_BODY: {
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QString("text/plain;charset=utf-8"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,
|
||||
QString("text/plain;charset=utf-8"));
|
||||
QByteArray data = params->_body.toUtf8();
|
||||
reply = manager->sendCustomRequest(request, verb, data);
|
||||
break;
|
||||
@ -519,15 +538,20 @@ void Network::printRequestStartLog(const QNetworkRequest &request, NetworkParams
|
||||
if (!params->getOpenLog()) {
|
||||
return;
|
||||
}
|
||||
qDebug() << "<------" << qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString()) << "Request Start ------>";
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String())) << qUtf8Printable(params->_url);
|
||||
qDebug() << "<------"
|
||||
<< qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())
|
||||
<< "Request Start ------>";
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String()))
|
||||
<< qUtf8Printable(params->_url);
|
||||
auto contentType = request.header(QNetworkRequest::ContentTypeHeader).toString();
|
||||
if (!contentType.isEmpty()) {
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<Header> %1=%2").arg("Content-Type", contentType));
|
||||
qDebug() << qUtf8Printable(
|
||||
QString::fromStdString("<Header> %1=%2").arg("Content-Type", contentType));
|
||||
}
|
||||
QList<QByteArray> headers = request.rawHeaderList();
|
||||
for (const QByteArray &header: headers) {
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<Header> %1=%2").arg(header, request.rawHeader(header)));
|
||||
for (const QByteArray &header : headers) {
|
||||
qDebug() << qUtf8Printable(
|
||||
QString::fromStdString("<Header> %1=%2").arg(header, request.rawHeader(header)));
|
||||
}
|
||||
if (!params->_queryMap.isEmpty()) {
|
||||
qDebug() << "<Query>" << qUtf8Printable(map2String(params->_queryMap));
|
||||
@ -543,12 +567,16 @@ void Network::printRequestStartLog(const QNetworkRequest &request, NetworkParams
|
||||
}
|
||||
}
|
||||
|
||||
void Network::printRequestEndLog(const QNetworkRequest &request, NetworkParams *params, QNetworkReply *&reply, const QString &response) {
|
||||
void Network::printRequestEndLog(const QNetworkRequest &request, NetworkParams *params,
|
||||
QNetworkReply *&reply, const QString &response) {
|
||||
if (!params->getOpenLog()) {
|
||||
return;
|
||||
}
|
||||
qDebug() << "<------" << qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString()) << "Request End ------>";
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String())) << qUtf8Printable(params->_url);
|
||||
qDebug() << "<------"
|
||||
<< qUtf8Printable(request.header(QNetworkRequest::UserAgentHeader).toString())
|
||||
<< "Request End ------>";
|
||||
qDebug() << qUtf8Printable(QString::fromStdString("<%1>").arg(params->method2String()))
|
||||
<< qUtf8Printable(params->_url);
|
||||
qDebug() << "<Result>" << qUtf8Printable(response);
|
||||
}
|
||||
|
||||
@ -562,7 +590,10 @@ void Network::saveResponse(const QString &key, const QString &response) {
|
||||
}
|
||||
|
||||
void Network::addHeaders(QNetworkRequest *request, const QMap<QString, QVariant> &headers) {
|
||||
request->setHeader(QNetworkRequest::UserAgentHeader, QString::fromStdString("Mozilla/5.0 %1/%2").arg(QGuiApplication::applicationName(), QGuiApplication::applicationVersion()));
|
||||
request->setHeader(
|
||||
QNetworkRequest::UserAgentHeader,
|
||||
QString::fromStdString("Mozilla/5.0 %1/%2")
|
||||
.arg(QGuiApplication::applicationName(), QGuiApplication::applicationVersion()));
|
||||
QMapIterator<QString, QVariant> iter(headers);
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
@ -584,7 +615,9 @@ Network::Network(QObject *parent) : QObject{parent} {
|
||||
_timeout = 5000;
|
||||
_retry = 3;
|
||||
_openLog = false;
|
||||
_cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation).append(QDir::separator()).append("network");
|
||||
_cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
|
||||
.append(QDir::separator())
|
||||
.append("network");
|
||||
}
|
||||
|
||||
NetworkParams *Network::get(const QString &url) {
|
||||
@ -656,7 +689,8 @@ NetworkParams *Network::patchJsonArray(const QString &url) {
|
||||
}
|
||||
|
||||
NetworkParams *Network::deleteJsonArray(const QString &url) {
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSONARRAY, NetworkParams::METHOD_DELETE, this);
|
||||
return new NetworkParams(url, NetworkParams::TYPE_JSONARRAY, NetworkParams::METHOD_DELETE,
|
||||
this);
|
||||
}
|
||||
|
||||
void Network::setInterceptor(QJSValue interceptor) {
|
||||
|
@ -28,7 +28,7 @@ namespace NetworkType {
|
||||
* @brief The NetworkCallable class
|
||||
*/
|
||||
class NetworkCallable : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(NetworkCallable)
|
||||
public:
|
||||
explicit NetworkCallable(QObject *parent = nullptr);
|
||||
@ -52,7 +52,7 @@ public:
|
||||
* @brief The FluDownloadParam class
|
||||
*/
|
||||
class FluDownloadParam : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FluDownloadParam(QObject *parent = nullptr);
|
||||
|
||||
@ -67,24 +67,11 @@ public:
|
||||
* @brief The NetworkParams class
|
||||
*/
|
||||
class NetworkParams : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(NetworkParams)
|
||||
public:
|
||||
enum Method {
|
||||
METHOD_GET,
|
||||
METHOD_HEAD,
|
||||
METHOD_POST,
|
||||
METHOD_PUT,
|
||||
METHOD_PATCH,
|
||||
METHOD_DELETE
|
||||
};
|
||||
enum Type {
|
||||
TYPE_NONE,
|
||||
TYPE_FORM,
|
||||
TYPE_JSON,
|
||||
TYPE_JSONARRAY,
|
||||
TYPE_BODY
|
||||
};
|
||||
enum Method { METHOD_GET, METHOD_HEAD, METHOD_POST, METHOD_PUT, METHOD_PATCH, METHOD_DELETE };
|
||||
enum Type { TYPE_NONE, TYPE_FORM, TYPE_JSON, TYPE_JSONARRAY, TYPE_BODY };
|
||||
|
||||
explicit NetworkParams(QObject *parent = nullptr);
|
||||
|
||||
@ -145,11 +132,11 @@ public:
|
||||
* @brief The Network class
|
||||
*/
|
||||
class Network : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, timeout)
|
||||
Q_PROPERTY_AUTO(int, retry)
|
||||
Q_PROPERTY_AUTO(QString, cacheDir)
|
||||
Q_PROPERTY_AUTO(bool, openLog)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(int, timeout)
|
||||
Q_PROPERTY_AUTO(int, retry)
|
||||
Q_PROPERTY_AUTO(QString, cacheDir)
|
||||
Q_PROPERTY_AUTO(bool, openLog)
|
||||
QML_NAMED_ELEMENT(Network)
|
||||
QML_SINGLETON
|
||||
|
||||
@ -157,9 +144,11 @@ private:
|
||||
explicit Network(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(Network)
|
||||
SINGLETON(Network)
|
||||
|
||||
static Network *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) { return getInstance(); }
|
||||
static Network *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) {
|
||||
return getInstance();
|
||||
}
|
||||
|
||||
Q_INVOKABLE NetworkParams *get(const QString &url);
|
||||
|
||||
@ -204,7 +193,9 @@ SINGLETON(Network)
|
||||
void handleDownload(NetworkParams *params, NetworkCallable *result);
|
||||
|
||||
private:
|
||||
static void sendRequest(QNetworkAccessManager *manager, QNetworkRequest request, NetworkParams *params, QNetworkReply *&reply, bool isFirst, const QPointer<NetworkCallable> &callable);
|
||||
static void sendRequest(QNetworkAccessManager *manager, QNetworkRequest request,
|
||||
NetworkParams *params, QNetworkReply *&reply, bool isFirst,
|
||||
const QPointer<NetworkCallable> &callable);
|
||||
|
||||
static void addQueryParam(QUrl *url, const QMap<QString, QVariant> ¶ms);
|
||||
|
||||
@ -222,7 +213,8 @@ private:
|
||||
|
||||
static void printRequestStartLog(const QNetworkRequest &request, NetworkParams *params);
|
||||
|
||||
static void printRequestEndLog(const QNetworkRequest &request, NetworkParams *params, QNetworkReply *&reply, const QString &response);
|
||||
static void printRequestEndLog(const QNetworkRequest &request, NetworkParams *params,
|
||||
QNetworkReply *&reply, const QString &response);
|
||||
|
||||
static QString map2String(const QMap<QString, QVariant> &map);
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <QStandardPaths>
|
||||
|
||||
SettingsHelper::SettingsHelper(QObject *parent) : QObject(parent) {
|
||||
|
||||
}
|
||||
|
||||
SettingsHelper::~SettingsHelper() = default;
|
||||
@ -13,6 +12,7 @@ void SettingsHelper::save(const QString &key, QVariant val) {
|
||||
m_settings->setValue(key, val);
|
||||
}
|
||||
|
||||
|
||||
QVariant SettingsHelper::get(const QString &key, QVariant def) {
|
||||
QVariant data = m_settings->value(key);
|
||||
if (!data.isNull() && data.isValid()) {
|
||||
@ -25,6 +25,7 @@ void SettingsHelper::init(char *argv[]) {
|
||||
QString applicationPath = QString::fromStdString(argv[0]);
|
||||
const QFileInfo fileInfo(applicationPath);
|
||||
const QString iniFileName = fileInfo.completeBaseName() + ".ini";
|
||||
const QString iniFilePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + iniFileName;
|
||||
const QString iniFilePath =
|
||||
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + "/" + iniFileName;
|
||||
m_settings.reset(new QSettings(iniFilePath, QSettings::IniFormat));
|
||||
}
|
||||
|
@ -10,32 +10,35 @@
|
||||
#include "src/singleton.h"
|
||||
|
||||
class SettingsHelper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
private:
|
||||
explicit SettingsHelper(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(SettingsHelper)
|
||||
|
||||
SINGLETON(SettingsHelper)
|
||||
~SettingsHelper() override;
|
||||
|
||||
void init(char *argv[]);
|
||||
|
||||
Q_INVOKABLE void saveDarkMode(int darkModel) { save("darkMode", darkModel); }
|
||||
|
||||
Q_INVOKABLE int getDarkMode() { return get("darkMode", QVariant(0)).toInt(); }
|
||||
|
||||
Q_INVOKABLE void saveUseSystemAppBar(bool useSystemAppBar) { save("useSystemAppBar", useSystemAppBar); }
|
||||
|
||||
Q_INVOKABLE bool getUseSystemAppBar() { return get("useSystemAppBar", QVariant(false)).toBool(); }
|
||||
|
||||
Q_INVOKABLE void saveLanguage(const QString &language) { save("language", language); }
|
||||
|
||||
Q_INVOKABLE QString getLanguage() { return get("language", QVariant("en_US")).toString(); }
|
||||
Q_INVOKABLE void saveDarkMode(int darkModel) {
|
||||
save("darkMode", darkModel);
|
||||
}
|
||||
Q_INVOKABLE int getDarkMode() {
|
||||
return get("darkMode", QVariant(0)).toInt();
|
||||
}
|
||||
Q_INVOKABLE void saveUseSystemAppBar(bool useSystemAppBar) {
|
||||
save("useSystemAppBar", useSystemAppBar);
|
||||
}
|
||||
Q_INVOKABLE bool getUseSystemAppBar() {
|
||||
return get("useSystemAppBar", QVariant(false)).toBool();
|
||||
}
|
||||
Q_INVOKABLE void saveLanguage(const QString &language) {
|
||||
save("language", language);
|
||||
}
|
||||
Q_INVOKABLE QString getLanguage() {
|
||||
return get("language", QVariant("en_US")).toString();
|
||||
}
|
||||
|
||||
private:
|
||||
void save(const QString &key, QVariant val);
|
||||
|
||||
QVariant get(const QString &key, QVariant def = {});
|
||||
|
||||
private:
|
||||
|
@ -18,7 +18,8 @@ void TranslateHelper::init(QQmlEngine *engine) {
|
||||
_translator = new QTranslator(this);
|
||||
QGuiApplication::installTranslator(_translator);
|
||||
QString translatorPath = QGuiApplication::applicationDirPath() + "/i18n";
|
||||
if (_translator->load(QString::fromStdString("%1/example_%2.qm").arg(translatorPath, _current))) {
|
||||
if (_translator->load(
|
||||
QString::fromStdString("%1/example_%2.qm").arg(translatorPath, _current))) {
|
||||
_engine->retranslate();
|
||||
}
|
||||
}
|
||||
|
@ -7,20 +7,18 @@
|
||||
#include "src/stdafx.h"
|
||||
|
||||
class TranslateHelper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, current)
|
||||
Q_PROPERTY_READONLY_AUTO(QStringList, languages)
|
||||
Q_OBJECT
|
||||
Q_PROPERTY_AUTO(QString, current)
|
||||
Q_PROPERTY_READONLY_AUTO(QStringList, languages)
|
||||
private:
|
||||
[[maybe_unused]] explicit TranslateHelper(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
SINGLETON(TranslateHelper)
|
||||
|
||||
SINGLETON(TranslateHelper)
|
||||
~TranslateHelper() override;
|
||||
|
||||
void init(QQmlEngine *engine);
|
||||
|
||||
private:
|
||||
QQmlEngine *_engine = nullptr;
|
||||
QTranslator *_translator = nullptr;
|
||||
};
|
||||
};
|
||||
|
@ -20,36 +20,36 @@
|
||||
#include "src/helper/TranslateHelper.h"
|
||||
#include "src/helper/Network.h"
|
||||
|
||||
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0))
|
||||
# if (QT_VERSION > QT_VERSION_CHECK(6, 2, 0))
|
||||
Q_IMPORT_QML_PLUGIN(FluentUIPlugin)
|
||||
#endif
|
||||
#include <FluentUI.h>
|
||||
# endif
|
||||
# include <FluentUI.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include "app_dmp.h"
|
||||
# include "app_dmp.h"
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
const char *uri = "example";
|
||||
int major = 1;
|
||||
int minor = 0;
|
||||
#ifdef WIN32
|
||||
::SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
|
||||
qputenv("QT_QPA_PLATFORM","windows:darkmode=2");
|
||||
qputenv("QT_QPA_PLATFORM", "windows:darkmode=2");
|
||||
#endif
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE","Basic");
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE", "Basic");
|
||||
#else
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE","Default");
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE", "Default");
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
//fix bug UOSv20 does not print logs
|
||||
qputenv("QT_LOGGING_RULES","");
|
||||
//fix bug UOSv20 v-sync does not work
|
||||
qputenv("QSG_RENDER_LOOP","basic");
|
||||
// fix bug UOSv20 does not print logs
|
||||
qputenv("QT_LOGGING_RULES", "");
|
||||
// fix bug UOSv20 v-sync does not work
|
||||
qputenv("QSG_RENDER_LOOP", "basic");
|
||||
#endif
|
||||
QApplication::setOrganizationName("ZhuZiChu");
|
||||
QApplication::setOrganizationDomain("https://zhuzichu520.github.io");
|
||||
@ -58,43 +58,47 @@ int main(int argc, char *argv[])
|
||||
QApplication::setApplicationVersion(APPLICATION_VERSION);
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
SettingsHelper::getInstance()->init(argv);
|
||||
Log::setup(argv,uri);
|
||||
Log::setup(argv, uri);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
|
||||
#endif
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
#endif
|
||||
# if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
QApplication::setHighDpiScaleFactorRoundingPolicy(
|
||||
Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
||||
# endif
|
||||
#endif
|
||||
QApplication app(argc, argv);
|
||||
//@uri example
|
||||
qmlRegisterType<CircularReveal>(uri, major, minor, "CircularReveal");
|
||||
qmlRegisterType<FileWatcher>(uri, major, minor, "FileWatcher");
|
||||
qmlRegisterType<FpsItem>(uri, major, minor, "FpsItem");
|
||||
qmlRegisterType<NetworkCallable>(uri,major,minor,"NetworkCallable");
|
||||
qmlRegisterType<NetworkParams>(uri,major,minor,"NetworkParams");
|
||||
qmlRegisterType<OpenGLItem>(uri,major,minor,"OpenGLItem");
|
||||
qmlRegisterUncreatableMetaObject(NetworkType::staticMetaObject, uri, major, minor, "NetworkType", "Access to enums & flags only");
|
||||
qmlRegisterType<NetworkCallable>(uri, major, minor, "NetworkCallable");
|
||||
qmlRegisterType<NetworkParams>(uri, major, minor, "NetworkParams");
|
||||
qmlRegisterType<OpenGLItem>(uri, major, minor, "OpenGLItem");
|
||||
qmlRegisterUncreatableMetaObject(NetworkType::staticMetaObject, uri, major, minor,
|
||||
"NetworkType", "Access to enums & flags only");
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
TranslateHelper::getInstance()->init(&engine);
|
||||
engine.rootContext()->setContextProperty("AppInfo",AppInfo::getInstance());
|
||||
engine.rootContext()->setContextProperty("SettingsHelper",SettingsHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("InitializrHelper",InitializrHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("TranslateHelper",TranslateHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("Network",Network::getInstance());
|
||||
engine.rootContext()->setContextProperty("AppInfo", AppInfo::getInstance());
|
||||
engine.rootContext()->setContextProperty("SettingsHelper", SettingsHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("InitializrHelper", InitializrHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("TranslateHelper", TranslateHelper::getInstance());
|
||||
engine.rootContext()->setContextProperty("Network", Network::getInstance());
|
||||
#ifdef FLUENTUI_BUILD_STATIC_LIB
|
||||
FluentUI::getInstance()->registerTypes(&engine);
|
||||
#endif
|
||||
const QUrl url(QStringLiteral("qrc:/example/qml/App.qml"));
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
|
||||
&app, [url](QObject *obj, const QUrl &objUrl) {
|
||||
QObject::connect(
|
||||
&engine, &QQmlApplicationEngine::objectCreated, &app,
|
||||
[url](QObject *obj, const QUrl &objUrl) {
|
||||
if (!obj && url == objUrl)
|
||||
QCoreApplication::exit(-1);
|
||||
}, Qt::QueuedConnection);
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
engine.load(url);
|
||||
const int exec = QApplication::exec();
|
||||
if (exec == 931) {
|
||||
|
@ -3,22 +3,23 @@
|
||||
/**
|
||||
* @brief The Singleton class
|
||||
*/
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T *getInstance();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T *Singleton<T>::getInstance() {
|
||||
static T *instance = new T();
|
||||
return instance;
|
||||
}
|
||||
|
||||
#define SINGLETON(Class) \
|
||||
private: \
|
||||
friend class Singleton<Class>; \
|
||||
public: \
|
||||
static Class* getInstance() { \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
}
|
||||
#define SINGLETON(Class) \
|
||||
private: \
|
||||
friend class Singleton<Class>; \
|
||||
\
|
||||
public: \
|
||||
static Class *getInstance() { \
|
||||
return Singleton<Class>::getInstance(); \
|
||||
}
|
||||
|
@ -1,50 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#define Q_PROPERTY_AUTO_P(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
#define Q_PROPERTY_AUTO_P(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(TYPE in_##M) { \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() { \
|
||||
return _##M; \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
TYPE _##M;
|
||||
|
||||
#define Q_PROPERTY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE& in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
#define Q_PROPERTY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M MEMBER _##M NOTIFY M##Changed) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE &in_##M) { \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() { \
|
||||
return _##M; \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
TYPE _##M;
|
||||
|
||||
|
||||
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M READ M NOTIFY M##Changed FINAL) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE& in_##M) \
|
||||
{ \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() \
|
||||
{ \
|
||||
return _##M; \
|
||||
} \
|
||||
private: \
|
||||
#define Q_PROPERTY_READONLY_AUTO(TYPE, M) \
|
||||
Q_PROPERTY(TYPE M READ M NOTIFY M##Changed FINAL) \
|
||||
public: \
|
||||
Q_SIGNAL void M##Changed(); \
|
||||
void M(const TYPE &in_##M) { \
|
||||
_##M = in_##M; \
|
||||
Q_EMIT M##Changed(); \
|
||||
} \
|
||||
TYPE M() { \
|
||||
return _##M; \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
TYPE _##M;
|
||||
|
Reference in New Issue
Block a user