2025-06-23 10:41:33 +08:00
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include "SettingDialog.h"
|
|
|
|
#include "Base.h"
|
|
|
|
#include "SystemSettingModule.h"
|
|
|
|
#include "DataManager.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#include "DataManager.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
|
|
|
|
SettingDialog::SettingDialog(MainWindow* parent)
|
|
|
|
: QDialog(parent), _frameless(nullptr), _parent(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
_webView = new WebEngineView(QUrl(BaseUrl + "#/setting"), this);
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout();
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
setLayout(layout);
|
|
|
|
layout->addWidget(_webView);
|
|
|
|
|
|
|
|
DataManager& root = GetDataRoot();
|
|
|
|
_webView->addEventModule(new SystemSettingModule(nullptr, &root));
|
|
|
|
|
|
|
|
_eventModule = new SignalEventModule("SettingDialog");
|
|
|
|
QObject::connect(_eventModule, &SignalEventModule::onmessage, this, &SettingDialog::onMessage);
|
|
|
|
_webView->addEventModule(_eventModule);
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
_frameless = std::move(std::unique_ptr<QFramelessHelper>(new QFramelessHelper(this, _webView, true, (QDialog*)this)));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingDialog::~SettingDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
|
|
|
bool SettingDialog::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
|
|
|
|
#else
|
|
|
|
bool SettingDialog::nativeEvent(const QByteArray& eventType, void* message, long* result)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (_frameless && _frameless->nativeEvent(eventType, message, result))
|
|
|
|
return true;
|
|
|
|
return QDialog::nativeEvent(eventType, message, result);
|
|
|
|
}
|
|
|
|
bool SettingDialog::onMessage(const std::string& eventName, json& parameter)
|
|
|
|
{
|
|
|
|
LOG(INFO) << CommonHelper::utf8ToStdString("SettingDialog receive message.......");
|
|
|
|
LOG(INFO) << eventName;
|
|
|
|
LOG(INFO) << CommonHelper::jsonToString(parameter);
|
|
|
|
TRY{
|
|
|
|
if (eventName == "closed") {
|
|
|
|
close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (eventName == "filedialog")
|
|
|
|
{
|
|
|
|
auto data = parameter["data"];
|
|
|
|
bool bFile = false;
|
|
|
|
if (!data["file"].is_null()) {
|
|
|
|
bFile = data["file"];
|
|
|
|
}
|
|
|
|
if (bFile)
|
|
|
|
{
|
|
|
|
QString curPath = QCoreApplication::applicationDirPath();
|
2025-06-23 18:01:09 +08:00
|
|
|
QString selectDir = QFileDialog::getOpenFileName(this->parentWidget(), "选择文件", "", "*.dbp");
|
2025-06-23 10:41:33 +08:00
|
|
|
if (!selectDir.isEmpty())
|
|
|
|
{
|
|
|
|
parameter["response"] = CommonHelper::qstringToUtf8(selectDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString selectDir = QFileDialog::getExistingDirectory();
|
|
|
|
parameter["response"] = CommonHelper::qstringToUtf8(selectDir);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (eventName == "db-connect")
|
|
|
|
{
|
|
|
|
parent()->DBConnect(parameter);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CATCH(parameter);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow* SettingDialog::parent()
|
|
|
|
{
|
|
|
|
return _parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bool SettingDialog::DBConnect(json& parameter)
|
|
|
|
// {
|
|
|
|
// using namespace DBPlatformSpace;
|
|
|
|
// ResultMsg rm;
|
|
|
|
// auto data = parameter["data"];
|
|
|
|
// // std::string sysDBPath = data["sysDBPath"];
|
|
|
|
// QString sysDBPath = CommonHelper::utf8ToQString(data["sysDBPath"]);
|
|
|
|
// SysManager& sysMgr = GetSysManager();
|
|
|
|
// QString dbFile;
|
|
|
|
// if (sysDBPath == "")
|
|
|
|
// {
|
|
|
|
// dbFile = sysMgr._sysDBPath;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// dbFile = sysDBPath;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// QString msg = "SettingDialog::DBConnect: DBFile:" + dbFile;
|
|
|
|
// LOG(INFO) << CommonHelper::qstringToString(msg);
|
|
|
|
//
|
|
|
|
// QFile file(dbFile);
|
|
|
|
// if (!file.exists())
|
|
|
|
// {
|
2025-06-23 18:01:09 +08:00
|
|
|
// //dbp文件不存在
|
|
|
|
// CommonHelper::message("数据库文件不存在", 2);
|
2025-06-23 10:41:33 +08:00
|
|
|
// LOG(INFO) << CommonHelper::utf8ToStdString("no dbFile");
|
|
|
|
// this->broadcast("connect-status-change", json({ {"status",false} }));
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// if (_pDataManager->pTheDBPlatform)
|
|
|
|
// {
|
|
|
|
// delete _pDataManager->pTheDBPlatform;
|
|
|
|
// _pDataManager->pTheDBPlatform = nullptr;
|
|
|
|
// _pDataManager->clearAllProject();
|
|
|
|
// sysMgr.clearAllDictData();
|
|
|
|
// }
|
|
|
|
// try {
|
|
|
|
// _pDataManager->pTheDBPlatform = new DBPlatformSpace::DBPlatformNew(CommonHelper::qstringToStdString(dbFile));
|
|
|
|
// }
|
|
|
|
// catch (...) {
|
2025-06-23 18:01:09 +08:00
|
|
|
// parameter["error"] = "连接数据库文件失败";
|
2025-06-23 10:41:33 +08:00
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// string st = DBPlatformNew::getCurrPlatformStatus();
|
|
|
|
// if (st == "OK")
|
|
|
|
// {
|
|
|
|
// _pDataManager->_dbConnected = true;
|
|
|
|
// LOG(INFO) << CommonHelper::utf8ToStdString("DBConnect::DBPlatformNew connect success");
|
|
|
|
// this->broadcast("connect-status-change", json({ {"status",true} }));
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// LOG(INFO) << CommonHelper::utf8ToStdString("DBConnect::DBPlatformNew connect failed");
|
|
|
|
// this->broadcast("connect-status-change", json({ {"status",false} }));
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
void SettingDialog::message(const QString& message, int type)
|
|
|
|
{
|
|
|
|
json j;
|
|
|
|
j["value"] = CommonHelper::qstringToUtf8(message);
|
|
|
|
j["type"] = type;
|
|
|
|
|
|
|
|
_eventModule->send("message", j);
|
|
|
|
}
|