2022-07-19 14:15:00 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Created by Krad on 2022/7/19.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "DialogManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QWidget>
|
2022-07-20 16:45:33 +08:00
|
|
|
|
#include <QThread>
|
2022-07-28 16:27:51 +08:00
|
|
|
|
#include <QDebug>
|
2022-07-19 14:15:00 +08:00
|
|
|
|
|
|
|
|
|
|
#include "event/EventCenter.h"
|
|
|
|
|
|
#include "dialogs/GUIMessageDialog.h"
|
2022-07-20 16:45:33 +08:00
|
|
|
|
#include "dialogs/ChangePasswordFormDialog.h"
|
|
|
|
|
|
#include "dialogs/AccountFormDialog.h"
|
2022-07-28 16:27:51 +08:00
|
|
|
|
#include "dialogs/MultyMessageDialogManager.h"
|
2022-07-19 14:15:00 +08:00
|
|
|
|
#include "appvals/AppGlobalValues.h"
|
2022-07-20 16:45:33 +08:00
|
|
|
|
#include "windows/LoginDialog.h"
|
2022-07-28 16:27:51 +08:00
|
|
|
|
#include "shimlib/ShimLib.h"
|
2022-07-20 16:45:33 +08:00
|
|
|
|
|
2022-07-28 16:27:51 +08:00
|
|
|
|
void messageCallback(const char* aMessage,unsigned int aMessageLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
DialogManager::Default()->raiseMultyMessageDialog(QString::fromLatin1(aMessage),MessageLevel(aMessageLevel));
|
|
|
|
|
|
}
|
2022-07-20 16:45:33 +08:00
|
|
|
|
|
|
|
|
|
|
DialogManager::DialogManager()
|
|
|
|
|
|
: QObject()
|
|
|
|
|
|
, mFunctionDialog(nullptr)
|
|
|
|
|
|
, mMessageDialog(nullptr)
|
2022-07-28 16:27:51 +08:00
|
|
|
|
, mTopWidget(nullptr)
|
2022-07-20 16:45:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-07-19 14:15:00 +08:00
|
|
|
|
|
2022-07-28 16:27:51 +08:00
|
|
|
|
void DialogManager::init(QWidget* aParent) {
|
2022-07-19 14:15:00 +08:00
|
|
|
|
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise,this,&DialogManager::raiseDeviceError);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationStart,this,&DialogManager::invokeOperationStart);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationProgress,this,&DialogManager::invokeOperationProgress);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationPending,this,&DialogManager::invokeOperationPending);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationEnd,this,&DialogManager::invokeOperationEnd);
|
2022-07-28 16:27:51 +08:00
|
|
|
|
MultyMessageDialogManager::getInstance()->setDialogParent(aParent);
|
|
|
|
|
|
SetMessageCallback(messageCallback);
|
2022-07-19 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-21 10:39:24 +08:00
|
|
|
|
//得考虑多线程的问题
|
|
|
|
|
|
void DialogManager::setTopWidget(QWidget* widget) {
|
2022-07-28 16:27:51 +08:00
|
|
|
|
std::lock_guard<std::mutex> lockGuard(mMutex);
|
|
|
|
|
|
if (nullptr == widget)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!mTopWidget&& QApplication::activeWindow()){
|
|
|
|
|
|
mTopWidget = QApplication::activeWindow();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
}
|
2022-07-28 16:27:51 +08:00
|
|
|
|
qDebug()<<"last top:"<<mTopWidget->objectName()<<", new top:"<<widget->objectName();
|
|
|
|
|
|
widget->setParent(mTopWidget,widget->windowFlags());
|
|
|
|
|
|
mTopWidget = widget;
|
2022-07-21 10:39:24 +08:00
|
|
|
|
++mDialogCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::releaseTopWidget(QWidget* expectedTopWidget) {
|
2022-07-28 16:27:51 +08:00
|
|
|
|
std::lock_guard<std::mutex> lockGuard(mMutex);
|
|
|
|
|
|
if (nullptr == expectedTopWidget)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mTopWidget == expectedTopWidget){
|
|
|
|
|
|
mTopWidget = expectedTopWidget->parentWidget();
|
|
|
|
|
|
--mDialogCount;
|
2022-07-21 10:39:24 +08:00
|
|
|
|
}
|
2022-07-19 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-20 16:45:33 +08:00
|
|
|
|
void DialogManager::requestLogin()
|
|
|
|
|
|
{
|
|
|
|
|
|
//Login 直接最顶层模态
|
|
|
|
|
|
if (!mFunctionDialog){
|
|
|
|
|
|
mFunctionDialog = new LoginDialog;
|
|
|
|
|
|
}
|
2022-07-21 10:39:24 +08:00
|
|
|
|
mFunctionDialog->setWindowModality(Qt::WindowModal);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
mFunctionDialog->exec();
|
|
|
|
|
|
while (QDialog::Accepted != mFunctionDialog->result())
|
|
|
|
|
|
{
|
2022-07-21 10:39:24 +08:00
|
|
|
|
|
2022-07-20 16:45:33 +08:00
|
|
|
|
mFunctionDialog->exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DialogManager::requestAddAccount(QSqlTableModel* model) {
|
2022-07-21 10:39:24 +08:00
|
|
|
|
AccountFormDialog dialog(nullptr, New);
|
|
|
|
|
|
setTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
dialog.setReferenceModel(model);
|
|
|
|
|
|
int ret = dialog.exec();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
releaseTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DialogManager::requestEditSelfAccount() {
|
2022-07-21 10:39:24 +08:00
|
|
|
|
AccountFormDialog dialog(nullptr, Self);
|
|
|
|
|
|
setTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
int ret = dialog.exec();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
releaseTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DialogManager::requestEditAdminAccount(const QMap<QString, QVariant>& values) {
|
2022-07-21 10:39:24 +08:00
|
|
|
|
AccountFormDialog dialog(nullptr, Admin);
|
|
|
|
|
|
setTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
dialog.setAccountInformation(values);
|
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
int ret = dialog.exec();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
releaseTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::requestChangePassword() {
|
2022-07-21 10:39:24 +08:00
|
|
|
|
ChangePasswordFormDialog dialog;
|
|
|
|
|
|
setTopWidget(&dialog);
|
|
|
|
|
|
dialog.setGeometry(dialog.parentWidget()->geometry());
|
2022-07-20 16:45:33 +08:00
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
dialog.exec();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
releaseTopWidget(&dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//考虑以后使用另外的dialog显示错误
|
2022-07-19 14:15:00 +08:00
|
|
|
|
void DialogManager::raiseDeviceError(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
clearMessageDialog();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
auto dialog = new GUIMessageDialog;
|
|
|
|
|
|
|
2022-07-20 16:45:33 +08:00
|
|
|
|
if (msg) {
|
|
|
|
|
|
QString *str = (QString *) msg;
|
2022-07-19 14:15:00 +08:00
|
|
|
|
dialog->showMessage(*str);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
} else {
|
2022-07-19 14:15:00 +08:00
|
|
|
|
dialog->showMessage("Something went error!");
|
|
|
|
|
|
}
|
|
|
|
|
|
dialog->stopLoading();
|
|
|
|
|
|
dialog->showExitButton();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
setTopWidget(dialog);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
dialog->setWindowModality(Qt::NonModal);
|
2022-07-28 16:27:51 +08:00
|
|
|
|
dialog->showFullScreen ();
|
2022-07-20 16:45:33 +08:00
|
|
|
|
dialog->exec();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
releaseTopWidget(dialog);
|
|
|
|
|
|
dialog->deleteLater();
|
2022-07-19 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-20 16:45:33 +08:00
|
|
|
|
// 扫描过程 dialog 只能为最底层,并且会被error dialog 清除!
|
2022-07-19 14:15:00 +08:00
|
|
|
|
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//没有目标parent 撤销操作
|
|
|
|
|
|
if (!QApplication::activeWindow()) return;
|
|
|
|
|
|
//只能在最底层窗口上模态
|
2022-07-21 10:39:24 +08:00
|
|
|
|
if (mDialogCount>0) return;
|
2022-07-20 16:45:33 +08:00
|
|
|
|
clearMessageDialog();
|
2022-07-21 10:39:24 +08:00
|
|
|
|
mMessageDialog = new GUIMessageDialog(QApplication::activeWindow());
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString* str = (QString*)msg;
|
|
|
|
|
|
mMessageDialog->showMessage(*str);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->hideMessage();
|
|
|
|
|
|
}
|
|
|
|
|
|
mMessageDialog->hideExitButton();
|
|
|
|
|
|
mMessageDialog->startLoading();
|
|
|
|
|
|
AppGlobalValues::setInProcessing(true);
|
|
|
|
|
|
if (mMessageDialog->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->open();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//窗口不存在,撤销操作
|
|
|
|
|
|
if (!mMessageDialog) return;
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
QVariant* var = (QVariant*)msg;
|
|
|
|
|
|
if (mMessageDialog->Pending())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->stopPending();
|
|
|
|
|
|
}
|
|
|
|
|
|
mMessageDialog->showMessage(var->toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->hideMessage();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mMessageDialog->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//窗口不存在,撤销操作
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (!mMessageDialog) return;
|
|
|
|
|
|
if (!mMessageDialog->Pending())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->startPending();
|
|
|
|
|
|
QVariant* var = (QVariant*)msg;
|
|
|
|
|
|
mMessageDialog->showMessage(var->toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//窗口不存在,撤销操作
|
|
|
|
|
|
if (!mMessageDialog) return;
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (!mMessageDialog->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (msg && ((QVariant*)msg)->toBool())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->stopLoading();
|
|
|
|
|
|
mMessageDialog->showMessage("Scan completed!");
|
|
|
|
|
|
mMessageDialog->showExitButton();
|
|
|
|
|
|
mMessageDialog->setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
mMessageDialog->exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->accept();
|
|
|
|
|
|
}
|
|
|
|
|
|
delete mMessageDialog;
|
|
|
|
|
|
AppGlobalValues::setInProcessing(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-20 16:45:33 +08:00
|
|
|
|
|
|
|
|
|
|
void DialogManager::clearMessageDialog() {
|
|
|
|
|
|
if (mMessageDialog){
|
|
|
|
|
|
if (!mMessageDialog->isHidden()) mMessageDialog->hide();
|
|
|
|
|
|
delete mMessageDialog;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DialogManager::~DialogManager() {
|
|
|
|
|
|
clearMessageDialog();
|
|
|
|
|
|
}
|
2022-07-28 16:27:51 +08:00
|
|
|
|
|
|
|
|
|
|
void DialogManager::raiseMultyMessageDialog(const QString aMessage, MessageLevel aMessageLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
MultyMessageDialogManager::getInstance()->raiseDialog(aMessage, aMessageLevel);
|
|
|
|
|
|
}
|