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-16 11:01:30 +00:00
|
|
|
#include "dialog_inputserialnum.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_top_splitter(nullptr)
|
|
|
|
, m_bot_splitter(nullptr)
|
|
|
|
, 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);
|
|
|
|
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
|
|
|
vLayout->addWidget(m_top_splitter);
|
|
|
|
vLayout->addWidget(m_bot_splitter);
|
2022-12-16 11:01:30 +00:00
|
|
|
vLayout->setStretch(0, 0);
|
2022-12-14 06:39:22 +00:00
|
|
|
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)
|
2022-12-17 05:48:03 +00:00
|
|
|
{
|
2022-12-15 09:27:35 +00:00
|
|
|
ui->act_manage->setVisible(false);
|
2022-12-17 05:48:03 +00:00
|
|
|
ui->act_upload->setVisible(false);
|
|
|
|
}
|
2022-12-15 09:27:35 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2022-12-16 11:01:30 +00:00
|
|
|
//sane_exit();
|
2022-12-15 09:27:35 +00:00
|
|
|
|
2022-12-14 06:39:22 +00:00
|
|
|
HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
|
|
|
|
m_pdtToolDbuserMgr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::isExitApp()
|
|
|
|
{
|
|
|
|
return !m_isLogOut;
|
|
|
|
}
|
|
|
|
|
2022-12-16 11:01:30 +00:00
|
|
|
void MainWindow::updateSplitter()
|
|
|
|
{
|
|
|
|
if (0 != m_top_splitter->count() && 0 == m_bot_splitter->count())
|
|
|
|
{
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 1);
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 0);
|
|
|
|
}
|
|
|
|
else if (0 == m_top_splitter->count() && 0 != m_bot_splitter->count())
|
|
|
|
{
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 0);
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
|
|
|
|
}
|
|
|
|
else if (0 != m_top_splitter->count() && 0 != m_bot_splitter->count())
|
|
|
|
{
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 1);
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(0, 0);
|
|
|
|
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Form_mainInterface* MainWindow::FindInterface(const QString &sn)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_top_splitter->count(); ++i)
|
|
|
|
{
|
|
|
|
Form_mainInterface *interface = (Form_mainInterface *)m_top_splitter->widget(i);
|
|
|
|
if (sn == interface->getSn())
|
|
|
|
{
|
|
|
|
return interface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < m_bot_splitter->count(); ++i)
|
|
|
|
{
|
|
|
|
Form_mainInterface *interface = (Form_mainInterface *)m_bot_splitter->widget(i);
|
|
|
|
if (sn == interface->getSn())
|
|
|
|
{
|
|
|
|
return interface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::AddInterface(Form_mainInterface *interface)
|
|
|
|
{
|
|
|
|
assert(nullptr != interface);
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
if (m_top_splitter->count() < 2)
|
|
|
|
{
|
|
|
|
m_top_splitter->addWidget(interface);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
else if (m_bot_splitter->count() < 2)
|
|
|
|
{
|
|
|
|
m_bot_splitter->addWidget(interface);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSplitter();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::RemoveInterface(Form_mainInterface *interface)
|
|
|
|
{
|
|
|
|
assert(nullptr != interface);
|
|
|
|
delete interface;
|
|
|
|
updateSplitter();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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;
|
2022-12-15 12:16:43 +00:00
|
|
|
MainWindow* p = (MainWindow*)param;
|
2022-12-15 07:00:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-12-15 12:16:43 +00:00
|
|
|
if (!hdev)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p->hg->cb_(hdev, code, data, len, NULL);
|
2022-12-15 07:00:12 +00:00
|
|
|
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-16 11:01:30 +00:00
|
|
|
QString MainWindow::getDevSn(SANE_Handle handle)
|
|
|
|
{
|
|
|
|
std::string serialNum;
|
|
|
|
unsigned int serialNumLen = 0;
|
|
|
|
if(SANE_STATUS_NO_MEM == sane_io_control(handle, IO_CTRL_CODE_GET_SERIAL, nullptr, &serialNumLen) && serialNumLen)
|
|
|
|
{
|
|
|
|
serialNum.resize(serialNumLen);
|
|
|
|
sane_io_control(handle, IO_CTRL_CODE_GET_SERIAL, &serialNum[0], &serialNumLen);
|
|
|
|
}
|
|
|
|
return QString::fromStdString(serialNum.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MainWindow::getDevType(SANE_Handle handle)
|
|
|
|
{
|
|
|
|
std::string firmWareNum;
|
|
|
|
unsigned int firmWareNumLen = 0;
|
|
|
|
if(SANE_STATUS_NO_MEM == sane_io_control(handle, IO_CTRL_CODE_GET_HARDWARE_VERSION, nullptr, &firmWareNumLen) && firmWareNumLen)
|
|
|
|
{
|
|
|
|
firmWareNum.resize(firmWareNumLen);
|
|
|
|
sane_io_control(handle, IO_CTRL_CODE_GET_HARDWARE_VERSION, &firmWareNum[0], &firmWareNumLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString str = QString::fromStdString(firmWareNum.c_str());
|
|
|
|
return str.left(2) + "00";
|
|
|
|
}
|
|
|
|
|
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-16 11:01:30 +00:00
|
|
|
QMessageBox msg(QMessageBox::Question, tr("tips"),
|
|
|
|
tr("Are you sure to connect the new device"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
|
|
|
msg.setButtonText(QMessageBox::Yes, tr("yes"));
|
|
|
|
msg.setButtonText(QMessageBox::No, tr("no"));
|
|
|
|
msg.exec();
|
|
|
|
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
|
|
{
|
|
|
|
SANE_Handle devHandle = nullptr;
|
|
|
|
sane_open(devName.toStdString().c_str(), &devHandle);
|
2022-12-15 03:00:46 +00:00
|
|
|
|
2022-12-16 11:01:30 +00:00
|
|
|
Dialog_InputSerialNum dlg(this, getDevSn(devHandle), getDevType(devHandle));
|
|
|
|
if (dlg.exec())
|
|
|
|
{
|
|
|
|
HGPdtToolDbDevice pdtToolDbDevice = nullptr;
|
|
|
|
HGPdtToolDb_OpenDevice(m_pdtToolDbuserMgr, dlg.GetSn().toStdString().c_str(), &pdtToolDbDevice);
|
|
|
|
|
2022-12-17 05:48:03 +00:00
|
|
|
Form_mainInterface *mainInterface = new Form_mainInterface(this, devHandle, m_pdtToolDbuserMgr, pdtToolDbDevice, dlg.GetSn(), dlg.GetDevType());
|
2022-12-16 11:01:30 +00:00
|
|
|
if (!AddInterface(mainInterface))
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
|
|
|
|
delete mainInterface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// sane_close(devHandle);
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2022-12-16 11:01:30 +00:00
|
|
|
case HGPDTTOOLDB_USEREVENT_CONFLICT:
|
2022-12-15 09:27:35 +00:00
|
|
|
tips = tr("Account login elsewhere");
|
|
|
|
break;
|
2022-12-16 11:01:30 +00:00
|
|
|
case HGPDTTOOLDB_USEREVENT_REFUSE:
|
2022-12-15 09:27:35 +00:00
|
|
|
tips = tr("You have been forced offline by the administrator account");
|
|
|
|
break;
|
2022-12-16 11:01:30 +00:00
|
|
|
case HGPDTTOOLDB_USEREVENT_DBERROR:
|
|
|
|
tips = tr("Data base error");
|
|
|
|
break;
|
2022-12-15 09:27:35 +00:00
|
|
|
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()
|
|
|
|
{
|
2022-12-16 11:01:30 +00:00
|
|
|
Dialog_InputSerialNum dlg(this, "", "");
|
|
|
|
if (dlg.exec())
|
2022-12-14 06:39:22 +00:00
|
|
|
{
|
2022-12-16 11:01:30 +00:00
|
|
|
HGPdtToolDbDevice pdtToolDbDevice = nullptr;
|
|
|
|
HGPdtToolDb_OpenDevice(m_pdtToolDbuserMgr, dlg.GetSn().toStdString().c_str(), &pdtToolDbDevice);
|
2022-12-14 06:39:22 +00:00
|
|
|
|
2022-12-17 05:48:03 +00:00
|
|
|
Form_mainInterface *mainInterface = new Form_mainInterface(this, nullptr, m_pdtToolDbuserMgr, pdtToolDbDevice, dlg.GetSn(), dlg.GetDevType());
|
2022-12-16 11:01:30 +00:00
|
|
|
if (!AddInterface(mainInterface))
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
|
|
|
|
delete mainInterface;
|
|
|
|
}
|
2022-12-14 06:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2022-12-16 11:01:30 +00:00
|
|
|
QString filename = QFileDialog::getSaveFileName(this, tr("save"), "test.xls", tr("xls(*.xls)"));
|
|
|
|
if (!filename.isEmpty())
|
|
|
|
{
|
|
|
|
HGPdtToolDb_Export(m_pdtToolDbuserMgr, getStdString(filename).c_str());
|
|
|
|
}
|
2022-12-14 06:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-12-16 11:01:30 +00:00
|
|
|
void MainWindow::on_act_upload_triggered()
|
|
|
|
{
|
|
|
|
Dialog_uploadCfgFile dlg(m_pdtToolDbuserMgr, this);
|
|
|
|
dlg.exec();
|
|
|
|
}
|