164 lines
4.5 KiB
C++
164 lines
4.5 KiB
C++
#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();
|
||
QString selectDir = QFileDialog::getOpenFileName(this->parentWidget(), "ѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>", "", "*.dbp");
|
||
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())
|
||
// {
|
||
// //dbp<62>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// CommonHelper::message("<22><><EFBFBD>ݿ<EFBFBD><DDBF>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 2);
|
||
// 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 (...) {
|
||
// parameter["error"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF>ļ<EFBFBD>ʧ<EFBFBD><CAA7>";
|
||
// 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);
|
||
} |