OfficeAssistant_Win10/OfficeAssistant_msvc/mainwindow.cpp

125 lines
4.1 KiB
C++
Raw Normal View History

//
// Created by HW on 2023/07/26.
//
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved
#include "mainwindow.h"
#include "ui_MainWindow.h"
2023-08-13 12:16:22 +08:00
#include "netio.h"
#include "config.h"
ExitManager exit_manager;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
2023-08-13 12:16:22 +08:00
agree = false;
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect deskRect = desktopWidget->availableGeometry();
resize(deskRect.width()*0.8, deskRect.height()*0.8);
setWindowState(Qt::WindowMaximized);
mainWindowLayout=new MainWindowLayout(this);
setCentralWidget(mainWindowLayout);
2023-08-13 12:16:22 +08:00
setWindowTitle(QString::fromLocal8Bit(TITLE));
QString path = QApplication::applicationDirPath();
path += LOGO_TITLEBAR;
icon = new QIcon(path);
setWindowIcon(*icon);
2023-08-13 12:16:22 +08:00
setStyleSheet("*{font-family:SimHei;}");
QFile file(QApplication::applicationDirPath() + DEFAULT_FILE);
if(!file.open(QIODevice::Text|QIODevice::ReadOnly))
{
QMessageBox::warning(nullptr, QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), QString::fromLocal8Bit("<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>"));
exit_manager.exit(1);
}
QByteArray buffer;
buffer = file.readAll();
file.close();
QJsonDocument document = QJsonDocument::fromJson(buffer);
if(document.isObject())
{
if(document.object().value("agree").isUndefined())
{
QMessageBox msg;
msg.setWindowTitle(QString::fromLocal8Bit("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƽƻ<EFBFBD>"));
msg.setText(QString::fromLocal8Bit("Ϊ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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ⲻӰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
msg.addButton(QString::fromLocal8Bit("ͬ<EFBFBD><EFBFBD>"), QMessageBox::AcceptRole);
msg.addButton(QString::fromLocal8Bit("<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>"), QMessageBox::RejectRole);
int ret = msg.exec();
if(ret==QMessageBox::AcceptRole)
{
QJsonObject obj_root = document.object();
obj_root.insert("agree", true);
document.setObject(obj_root);
agree = true;
DeviceRequest* device_request = new DeviceRequest;//<2F><><EFBFBD><EFBFBD><ECBAAF>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delete device_request;
}else
{
QJsonObject obj_root = document.object();
obj_root.insert("agree", false);
document.setObject(obj_root);
agree = false;
}
if(file.open(QIODevice::WriteOnly|QIODevice::Text))
{
file.write(document.toJson());
file.close();
}
}
else if(document.object().value("agree").toBool())
{
agree = true;
DeviceRequest* device_request = new DeviceRequest;
delete device_request;
}
}
else
{
QMessageBox msg;
msg.setWindowTitle(QString::fromLocal8Bit("<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƽƻ<EFBFBD>"));
msg.setText(QString::fromLocal8Bit("Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵķ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n"
"1.<2E><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>\n"
"2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD>б<EFBFBD><D0B1><EFBFBD>\n"
"3.<2E><><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>Dz<EFBFBD><C7B2><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n"
"<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD>ⲻӰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
msg.addButton(QString::fromLocal8Bit("ͬ<EFBFBD><EFBFBD>"), QMessageBox::AcceptRole);
msg.addButton(QString::fromLocal8Bit("<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>"), QMessageBox::RejectRole);
int ret = msg.exec();
if (ret == QMessageBox::AcceptRole)
{
QJsonObject obj_root;
obj_root.insert("agree", true);
document.setObject(obj_root);
agree = true;
DeviceRequest* device_request = new DeviceRequest;//<2F><><EFBFBD><EFBFBD><ECBAAF>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>ȥ<EFBFBD><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delete device_request;
}
else
{
QJsonObject obj_root;
obj_root.insert("agree", false);
document.setObject(obj_root);
agree = false;
}
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
file.write(document.toJson());
file.close();
}
}
}
MainWindow::~MainWindow() {
2023-08-13 12:16:22 +08:00
SQLiteHelper sqlite_helper;
sqlite_helper.db.close();
QSqlDatabase::removeDatabase("mydb");
delete icon;
this->setCentralWidget(nullptr);
delete mainWindowLayout;
delete ui;
}