code_production/app/HGProductionTool/mainwindow.cpp

277 lines
6.3 KiB
C++
Raw Normal View History

2022-12-14 06:39:22 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QVBoxLayout>
#include "base/HGBase.h"
#include "HGUIGlobal.h"
#include "dialog_login.h"
#include "dialog_changepwd.h"
#include "dialog_accountmanage.h"
2022-12-14 12:28:25 +00:00
#include "dialog_uploadcfgfile.h"
2022-12-15 06:05:53 +00:00
#include "hgscanner.h"
2022-12-14 06:39:22 +00:00
2022-12-15 09:27:35 +00:00
MainWindow::MainWindow(QWidget *parent)
2022-12-14 06:39:22 +00:00
: QMainWindow(parent)
, ui(new Ui::MainWindow)
2022-12-15 09:27:35 +00:00
, m_pdtToolDbuserMgr(nullptr)
2022-12-14 06:39:22 +00:00
, m_form_mainInterface(nullptr)
, m_top_splitter(nullptr)
, m_bot_splitter(nullptr)
, m_splitterCount(1)
2022-12-15 07:00:12 +00:00
, m_handle(nullptr)
2022-12-14 06:39:22 +00:00
, m_isLogOut(false)
{
ui->setupUi(this);
setWindowIcon(QIcon(":image/image_rsc/logo/logo.ico"));
2022-12-15 07:00:12 +00:00
connect(this, SIGNAL(sane_dev_arrive(QString)), this, SLOT(on_sane_dev_arrive(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(sane_dev_remove(QString)), this, SLOT(on_sane_dev_remove(QString)), Qt::QueuedConnection);
2022-12-15 09:27:35 +00:00
connect(this, SIGNAL(user_event(int)), this, SLOT(on_user_event(int)), Qt::QueuedConnection);
2022-12-14 06:39:22 +00:00
m_top_splitter = new QSplitter(Qt::Horizontal);
m_bot_splitter = new QSplitter(Qt::Horizontal);
m_form_mainInterface = new Form_mainInterface();
m_top_splitter->addWidget(m_form_mainInterface);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(m_top_splitter);
vLayout->addWidget(m_bot_splitter);
vLayout->setStretch(0, 1);
vLayout->setStretch(1, 0);
this->centralWidget()->setLayout(vLayout);
}
MainWindow::~MainWindow()
{
2022-12-15 09:27:35 +00:00
delete ui;
}
void MainWindow::Init()
{
assert(nullptr != m_pdtToolDbuserMgr);
HGUInt userType = 0;
HGPdtToolDb_GetUserType(m_pdtToolDbuserMgr, &userType);
if (userType == HGPDTTOOLDB_USERTYPE_NORMAL)
ui->act_manage->setVisible(false);
HGChar userName[128];
HGPdtToolDb_GetUserName(m_pdtToolDbuserMgr, userName, 128);
setWindowTitle(userName);
SANE_Int v = 0;
sane_init_ex(&v, sane_ex_callback, this);
}
void MainWindow::Deinit()
{
// if (nullptr != m_handle)
// {
// sane_close(m_handle);
// m_handle = nullptr;
// }
// sane_exit();
2022-12-14 06:39:22 +00:00
HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
m_pdtToolDbuserMgr = NULL;
}
bool MainWindow::isExitApp()
{
return !m_isLogOut;
}
2022-12-15 09:27:35 +00:00
void HGAPI MainWindow::PdtToolDbUserEventFunc(HGPdtToolDbUserMgr userMgr, HGUInt event, HGPointer param)
{
MainWindow *p = (MainWindow *)param;
if (0 != event)
{
emit p->user_event(event);
}
}
2022-12-15 07:00:12 +00:00
int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigned int *len, void *param)
{
(void)hdev;
(void)len;
MainWindow *p = (MainWindow *)param;
switch (code)
{
case SANE_EVENT_DEVICE_ARRIVED:
{
SANE_Device_Ex* sane_dev = (SANE_Device_Ex*)data;
emit p->sane_dev_arrive(sane_dev->name);
}
break;
case SANE_EVENT_DEVICE_LEFT:
{
SANE_Device* sane_dev = (SANE_Device*)data;
emit p->sane_dev_remove(sane_dev->name);
}
break;
}
return 0;
}
std::vector<std::string> MainWindow::getDevices()
2022-12-15 03:00:46 +00:00
{
std::vector<std::string> name;
const SANE_Device** devs_list;
SANE_Status status = SANE_STATUS_GOOD;
if ((status = sane_get_devices(&devs_list, SANE_TRUE)) != SANE_STATUS_GOOD)
{
name.push_back("");
return name;
}
name.clear();
while (*devs_list != NULL)
{
name.push_back((*devs_list)->name);
devs_list++;
}
return name;
}
2022-12-15 07:00:12 +00:00
void MainWindow::on_sane_dev_arrive(QString devName)
2022-12-15 03:00:46 +00:00
{
2022-12-15 09:27:35 +00:00
// SANE_Status ret = sane_open(devName.toStdString().c_str(), &m_handle);
2022-12-15 03:00:46 +00:00
2022-12-15 09:27:35 +00:00
// ui_helper* helper;
// hgscanner* hg = new hgscanner(m_handle);
// helper = dynamic_cast<hgscanner*>(hg);
// func_test_go(L"test-31", L"null", helper);
2022-12-15 07:00:12 +00:00
}
void MainWindow::on_sane_dev_remove(QString devName)
{
2022-12-15 03:00:46 +00:00
}
2022-12-15 07:00:12 +00:00
2022-12-15 09:27:35 +00:00
void MainWindow::on_user_event(int event)
{
QString tips;
switch (event)
{
case 1:
tips = tr("Account login elsewhere");
break;
case 2:
tips = tr("Network connection lost");
break;
case 3:
tips = tr("You have been forced offline by the administrator account");
break;
default:
break;
}
QMessageBox::information(this, (tr("tips")), tips);
m_isLogOut = true;
close();
}
2022-12-14 06:39:22 +00:00
void MainWindow::on_act_newDevice_triggered()
{
m_splitterCount++;
switch (m_splitterCount)
{
case 2:
{
Form_mainInterface *form_mainInterface = new Form_mainInterface();
m_top_splitter->addWidget(form_mainInterface);
break;
}
case 3:
{
Form_mainInterface *form_mainInterface = new Form_mainInterface();
m_bot_splitter->addWidget(form_mainInterface);
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
break;
}
case 4:
{
Form_mainInterface *form_mainInterface = new Form_mainInterface();
m_bot_splitter->addWidget(form_mainInterface);
break;
}
case 5:
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
return;
break;
default:
break;
}
}
void MainWindow::on_act_manage_triggered()
{
Dialog_accountManage dlg(m_pdtToolDbuserMgr, this);
dlg.exec();
}
void MainWindow::on_act_changePwd_triggered()
{
Dialog_changePwd dlg(m_pdtToolDbuserMgr, this);
dlg.exec();
}
void MainWindow::on_act_export_triggered()
{
HGChar cfgPath[256]= {0};
HGBase_GetConfigPath(cfgPath, 256);
strcat(cfgPath, "1.xls");
HGPdtToolDb_Export(m_pdtToolDbuserMgr, getStdString(cfgPath).c_str());
}
void MainWindow::on_act_logOut_triggered()
{
m_isLogOut = true;
close();
}
void MainWindow::on_act_close_triggered()
{
close();
}
QString MainWindow::getLogInfo(HGResult ret)
{
QString str;
if (HGPDTTOOLDB_ERR_INVALID_USER == ret)
{
str = tr("Illegal user");
}
else if (HGPDTTOOLDB_ERR_WRONG_PASSWORD == ret)
{
str = tr("Wrong password");
}
else if (HGPDTTOOLDB_ERR_DATABASE == ret)
{
str = tr("Database error");
}
else if (HGPDTTOOLDB_ERR_CONNECT == ret)
{
str = tr("connect error");
}
else
{
str = tr("Failed");
}
return str;
}
2022-12-14 12:28:25 +00:00
void MainWindow::on_act_upload_triggered()
{
2022-12-15 09:27:35 +00:00
Dialog_uploadCfgFile dlg(m_pdtToolDbuserMgr, this);
dlg.exec();
2022-12-14 12:28:25 +00:00
}