828 lines
24 KiB
C++
828 lines
24 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QVBoxLayout>
|
|
#include <QTimer>
|
|
#include "base/HGBase.h"
|
|
#include "huagao/brand.h"
|
|
#include "huagao/hgscanner_error.h"
|
|
#include "HGUIGlobal.h"
|
|
#include "app_cfg.h"
|
|
#include "dialog_login.h"
|
|
#include "dialog_changepwd.h"
|
|
#include "dialog_accountmanage.h"
|
|
#include "dialog_uploadcfgfile.h"
|
|
#include "dialog_inputserialnum.h"
|
|
#include "dialog_hgmessagebox.h"
|
|
|
|
MainWindow::MainWindow(Dialog_logIn::LogInType loginType, const QString &profileName, const QString &accountName, const QString &ftpHost, unsigned short ftpPort, QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, m_ftpHost(ftpHost)
|
|
, m_ftpPort(ftpPort)
|
|
, m_lock(nullptr)
|
|
, m_testingRef(0)
|
|
, m_loginType(loginType)
|
|
, m_accountName(accountName)
|
|
, m_profileName(profileName)
|
|
, m_formBurnMode(nullptr)
|
|
, m_top_splitter(nullptr)
|
|
, m_bot_splitter(nullptr)
|
|
, m_isLogOut(false)
|
|
, m_inputSnDlg(nullptr)
|
|
, m_tmpDevType("")
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
ui->act_newDevice->setVisible(false);
|
|
ui->act_close->setVisible(false);
|
|
ui->act_manage->setVisible(false);
|
|
ui->act_export->setVisible(false);
|
|
ui->act_upload->setVisible(false);
|
|
ui->act_openLog->setVisible(false);
|
|
|
|
if (m_accountName == "admin")
|
|
ui->act_openLog->setVisible(true);
|
|
|
|
ui->act_refreshDevice->setShortcut(QKeySequence("F5"));
|
|
|
|
QFont ft;
|
|
ft.setPointSize(15);
|
|
this->setFont(ft);
|
|
|
|
setWindowIcon(QIcon(":image/image_rsc/logo/logo.ico"));
|
|
|
|
HGBase_CreateLock(&m_lock);
|
|
|
|
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);
|
|
connect(this, &MainWindow::sane_create_interface, this, &MainWindow::on_sane_create_interface, Qt::QueuedConnection);
|
|
|
|
if (m_loginType == Dialog_logIn::LogInType_Burn)
|
|
{
|
|
setWindowTitle(tr("production tool-burn station"));
|
|
// ui->act_newDevice->setVisible(false);
|
|
|
|
m_formBurnMode = new Form_BurnMode(this, this);
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
|
vLayout->addWidget(m_formBurnMode);
|
|
this->centralWidget()->setLayout(vLayout);
|
|
show();
|
|
}
|
|
else
|
|
{
|
|
// ui->act_refreshDevice->setVisible(true);
|
|
|
|
m_top_splitter = new QSplitter(Qt::Horizontal);
|
|
m_bot_splitter = new QSplitter(Qt::Horizontal);
|
|
m_top_splitter->setMinimumWidth(600);
|
|
m_bot_splitter->setMinimumWidth(600);
|
|
m_top_splitter->setChildrenCollapsible(false);
|
|
m_bot_splitter->setChildrenCollapsible(false);
|
|
|
|
QVBoxLayout *vLayout = new QVBoxLayout;
|
|
vLayout->addWidget(m_top_splitter);
|
|
vLayout->addWidget(m_bot_splitter);
|
|
vLayout->setStretch(0, 0);
|
|
vLayout->setStretch(1, 0);
|
|
this->centralWidget()->setLayout(vLayout);
|
|
|
|
showMaximized();
|
|
}
|
|
|
|
QTimer *timer = new QTimer(this);
|
|
timer->start(1000);
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(on_update_userStatus()));
|
|
|
|
HGUInt userType = 0;
|
|
//HGPdtToolDb_GetUserType(m_pdtToolDbuserMgr, &userType);
|
|
// if (userType == HGPDTTOOLDB_USERTYPE_NORMAL)
|
|
// {
|
|
// ui->act_manage->setVisible(false);
|
|
// ui->act_upload->setVisible(false);
|
|
// }
|
|
|
|
if (m_loginType == Dialog_logIn::LogInType_InitTest)
|
|
setWindowTitle(tr("production tool-init test station"));
|
|
else if (m_loginType == Dialog_logIn::LogInType_ImageTest)
|
|
setWindowTitle(tr("production tool-image test station"));
|
|
if (m_loginType == Dialog_logIn::LogInType_PressureTest)
|
|
setWindowTitle(tr("production tool-pressure test station"));
|
|
|
|
SANE_Int v = 0;
|
|
sane_init_ex(&v, sane_ex_callback, this);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
//HGBase_EnterLock(m_lock);
|
|
if (m_top_splitter != nullptr)
|
|
{
|
|
while (0 != m_top_splitter->count())
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(0);
|
|
delete mainInterface;
|
|
}
|
|
}
|
|
|
|
if (m_top_splitter != nullptr)
|
|
{
|
|
while (0 != m_bot_splitter->count())
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(0);
|
|
delete mainInterface;
|
|
}
|
|
}
|
|
|
|
//HGBase_LeaveLock(m_lock);
|
|
|
|
sane_exit();
|
|
|
|
//HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
|
|
//m_pdtToolDbuserMgr = nullptr;
|
|
|
|
delete m_formBurnMode;
|
|
m_formBurnMode = nullptr;
|
|
|
|
HGBase_DestroyLock(m_lock);
|
|
m_lock = nullptr;
|
|
delete ui;
|
|
}
|
|
|
|
bool MainWindow::isExitApp()
|
|
{
|
|
return !m_isLogOut;
|
|
}
|
|
|
|
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 * mainInterface = (Form_mainInterface *)m_top_splitter->widget(i);
|
|
if (sn == mainInterface->getSn())
|
|
{
|
|
return mainInterface;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < m_bot_splitter->count(); ++i)
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(i);
|
|
if (sn == mainInterface->getSn())
|
|
{
|
|
return mainInterface;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
Form_mainInterface *MainWindow::FindInterfaceByDevName(const QString &devName)
|
|
{
|
|
for (int i = 0; i < m_top_splitter->count(); ++i)
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(i);
|
|
if (devName == mainInterface->getDevName())
|
|
{
|
|
return mainInterface;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < m_bot_splitter->count(); ++i)
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(i);
|
|
if (devName == mainInterface->getDevName())
|
|
{
|
|
return mainInterface;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
Form_mainInterface* MainWindow::FindInterface(SANE_Handle handle)
|
|
{
|
|
Form_mainInterface *form = nullptr;
|
|
for (int i = 0; i < m_top_splitter->count(); ++i)
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_top_splitter->widget(i);
|
|
if (handle == mainInterface->getDevHandle())
|
|
{
|
|
form = mainInterface;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (nullptr == form)
|
|
{
|
|
for (int i = 0; i < m_bot_splitter->count(); ++i)
|
|
{
|
|
Form_mainInterface * mainInterface = (Form_mainInterface *)m_bot_splitter->widget(i);
|
|
if (handle == mainInterface->getDevHandle())
|
|
{
|
|
form = mainInterface;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return form;
|
|
}
|
|
|
|
bool MainWindow::AddInterface(Form_mainInterface * mainInterface)
|
|
{
|
|
assert(nullptr != mainInterface);
|
|
|
|
//HGBase_EnterLock(m_lock);
|
|
bool ret = false;
|
|
if (m_top_splitter->count() < 2)
|
|
{
|
|
m_top_splitter->addWidget(mainInterface);
|
|
ret = true;
|
|
}
|
|
else if (m_bot_splitter->count() < 2)
|
|
{
|
|
m_bot_splitter->addWidget(mainInterface);
|
|
ret = true;
|
|
}
|
|
//HGBase_LeaveLock(m_lock);
|
|
|
|
updateSplitter();
|
|
return ret;
|
|
}
|
|
|
|
bool MainWindow::RemoveInterface(Form_mainInterface * mainInterface)
|
|
{
|
|
assert(nullptr != mainInterface);
|
|
//HGBase_EnterLock(m_lock);
|
|
delete mainInterface;
|
|
mainInterface = nullptr;
|
|
m_testingRef = 0;
|
|
updateActionStatus(true);
|
|
//HGBase_LeaveLock(m_lock);
|
|
updateSplitter();
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::updateActionStatus(bool enable)
|
|
{
|
|
ui->act_refreshDevice->setEnabled(enable);
|
|
ui->act_close->setEnabled(enable);
|
|
ui->act_manage->setEnabled(enable);
|
|
ui->act_logOut->setEnabled(enable);
|
|
ui->act_changePwd->setEnabled(enable);
|
|
ui->act_export->setEnabled(enable);
|
|
ui->act_upload->setEnabled(enable);
|
|
}
|
|
|
|
void MainWindow::addTestingRef()
|
|
{
|
|
++m_testingRef;
|
|
updateActionStatus(false);
|
|
}
|
|
|
|
void MainWindow::releaseTesting()
|
|
{
|
|
--m_testingRef;
|
|
|
|
if (0 == m_testingRef)
|
|
{
|
|
updateActionStatus(true);
|
|
}
|
|
}
|
|
|
|
bool MainWindow::isTesting()
|
|
{
|
|
return (m_testingRef != 0);
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
{
|
|
if (isTesting())
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("Is testing, do not close!"));
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigned int *len, void *param)
|
|
{
|
|
MainWindow* p = (MainWindow*)param;
|
|
|
|
if (SANE_EVENT_DEVICE_ARRIVED == code)
|
|
{
|
|
SANE_Device_Ex* sane_dev = (SANE_Device_Ex*)data;
|
|
|
|
emit p->sane_dev_arrive(sane_dev->name);
|
|
}
|
|
else if (SANE_EVENT_DEVICE_LEFT == code)
|
|
{
|
|
SANE_Device* sane_dev = (SANE_Device*)data;
|
|
emit p->sane_dev_remove(sane_dev->name);
|
|
}
|
|
else if (SANE_EVENT_IMAGE_OK == code)
|
|
{
|
|
if (p->m_loginType != Dialog_logIn::LogInType_Burn)
|
|
{
|
|
Form_mainInterface* mainInterface = p->FindInterface(hdev);
|
|
if (nullptr != mainInterface)
|
|
{
|
|
if (nullptr != mainInterface->getScanner() && nullptr != mainInterface->getScanner()->cb_)
|
|
mainInterface->getScanner()->cb_(hdev, code, data, len, mainInterface->getScanner());
|
|
}
|
|
}
|
|
}
|
|
else if (code == SANE_EVENT_SCAN_FINISHED || code == SANE_EVENT_ERROR || code == SANE_EVENT_STATUS)
|
|
{
|
|
SaneParams *saneParams = new SaneParams;
|
|
saneParams->hdev = hdev;
|
|
saneParams->code = code;
|
|
|
|
char *content = new char[strlen((char*)data) + 1];
|
|
memcpy(content, data, strlen((char*)data) + 1);
|
|
saneParams->data = content;
|
|
saneParams->len = *len;
|
|
|
|
emit p->sane_create_interface(saneParams);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
std::vector<std::string> MainWindow::getDevices()
|
|
{
|
|
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;
|
|
}
|
|
|
|
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";
|
|
}
|
|
|
|
QString MainWindow::getDevFwNum(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);
|
|
}
|
|
|
|
return QString::fromStdString(firmWareNum.c_str());
|
|
}
|
|
|
|
void MainWindow::on_sane_dev_arrive(QString devName)
|
|
{
|
|
//// QTime curTimer = QTime::currentTime().addMSecs(5000);
|
|
//// while (QTime::currentTime() < curTimer)
|
|
//// {
|
|
//// QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
|
//// }
|
|
|
|
// if (m_loginType == Dialog_logIn::LogInType_Burn)
|
|
// {
|
|
// SANE_Handle devHandle = nullptr;
|
|
// sane_open(devName.toStdString().c_str(), &devHandle);
|
|
// if (nullptr != devHandle)
|
|
// {
|
|
// DeviceManager *devManager = new DeviceManager(this, m_formBurnMode, devHandle, devName);
|
|
// m_formBurnMode->addDevice(devManager);
|
|
// }
|
|
|
|
// return;
|
|
// }
|
|
|
|
// // QString str = tr("Confirm whether the device is reset");
|
|
// // Dialog_HGMessageBox dlg(str, this);
|
|
// // if (!dlg.exec())
|
|
// // {
|
|
// // return;
|
|
// // }
|
|
|
|
// SANE_Handle devHandle = nullptr;
|
|
// sane_open(devName.toStdString().c_str(), &devHandle);
|
|
|
|
// if (nullptr == devHandle)
|
|
// {
|
|
// QMessageBox::information(this, tr("tips"), tr("Open device failed"));
|
|
// return;
|
|
// }
|
|
|
|
// m_inputSnDlg = new Dialog_InputSerialNum(this, devName, m_pdtToolDbuserMgr, devHandle, getDevSn(devHandle), getDevType(devHandle));
|
|
// if (!m_inputSnDlg->exec())
|
|
// {
|
|
// sane_close(devHandle);
|
|
// return ;
|
|
// }
|
|
|
|
// HGPdtToolDbDevice pdtToolDbDevice = nullptr;
|
|
// HGPdtToolDb_OpenDevice(m_pdtToolDbuserMgr, m_inputSnDlg->GetSn().toStdString().c_str(), &pdtToolDbDevice);
|
|
|
|
// Form_mainInterface *mainInterface = new Form_mainInterface(this, m_loginType, devHandle, m_pdtToolDbuserMgr, pdtToolDbDevice,
|
|
// m_inputSnDlg->GetSn(), m_inputSnDlg->GetDevType(), devName, getDevFwNum(devHandle));
|
|
// if (!AddInterface(mainInterface))
|
|
// {
|
|
// QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
|
|
// delete mainInterface;
|
|
// }
|
|
|
|
// if (m_inputSnDlg != nullptr)
|
|
// {
|
|
// delete m_inputSnDlg;
|
|
// m_inputSnDlg = nullptr;
|
|
// }
|
|
}
|
|
|
|
void MainWindow::on_sane_dev_remove(QString devName)
|
|
{
|
|
if (m_loginType == Dialog_logIn::LogInType_Burn)
|
|
{
|
|
m_formBurnMode->deleteDevice(devName);
|
|
}
|
|
else
|
|
{
|
|
if (nullptr != m_inputSnDlg)
|
|
{
|
|
m_inputSnDlg->Invalid(devName);
|
|
}
|
|
|
|
Form_mainInterface * mainInterface = FindInterfaceByDevName(devName);
|
|
if (mainInterface != nullptr)
|
|
{
|
|
mainInterface->setDevDisconnect();
|
|
//if (!mainInterface->isTesting())
|
|
{
|
|
RemoveInterface(mainInterface);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_sane_create_interface(SaneParams *saneParams)
|
|
{
|
|
if (m_loginType != Dialog_logIn::LogInType_Burn)
|
|
{
|
|
Form_mainInterface* mainInterface = FindInterface(saneParams->hdev);
|
|
if (nullptr != mainInterface)
|
|
{
|
|
if (nullptr != mainInterface->getScanner() && nullptr != mainInterface->getScanner()->cb_)
|
|
{
|
|
QString info = QString::fromStdString((char*)saneParams->data);
|
|
if (info == QString(STATU_DESC_SCANNER_ERR_IMAGE_CORRECTION_FINISHED))
|
|
{
|
|
int type = 0;
|
|
func_test_correct(true, &type);
|
|
}
|
|
else if (info == QString(STATU_DESC_SCANNER_ERR_IMAGE_CORRECTION_FAIL))
|
|
{
|
|
int type = 0;
|
|
func_test_correct(false, &type);
|
|
if (type > 0)
|
|
{
|
|
mainInterface->checkWrongCorrectItem(type);
|
|
}
|
|
}
|
|
|
|
func_test_distortion();
|
|
|
|
mainInterface->getScanner()->cb_(saneParams->hdev, saneParams->code, saneParams->data, &saneParams->len, mainInterface->getScanner());
|
|
}
|
|
}
|
|
}
|
|
|
|
delete[] (char*)saneParams->data;
|
|
delete saneParams;
|
|
saneParams = nullptr;
|
|
}
|
|
|
|
void MainWindow::on_update_userStatus()
|
|
{
|
|
QString tips;
|
|
HGUInt userStatus = 0;
|
|
//HGPdtToolDb_GetUserStatus(m_pdtToolDbuserMgr, &userStatus);
|
|
|
|
// switch (userStatus)
|
|
// {
|
|
// case HGPDTTOOLDB_USERSTATUS_CONFLICT:
|
|
// tips = tr("Account login elsewhere");
|
|
// break;
|
|
// case HGPDTTOOLDB_USERSTATUS_REFUSE:
|
|
// tips = tr("You have been forced offline by the administrator account");
|
|
// break;
|
|
// case HGPDTTOOLDB_USERSTATUS_DBERROR:
|
|
// tips = tr("Data base error");
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
|
|
// if (!tips.isEmpty())
|
|
// {
|
|
// if (!isTesting())
|
|
// {
|
|
// QMessageBox::information(this, (tr("tips")), tips);
|
|
// m_isLogOut = true;
|
|
// close();
|
|
// }
|
|
// }
|
|
}
|
|
|
|
void MainWindow::on_act_newDevice_triggered()
|
|
{
|
|
m_inputSnDlg = new Dialog_InputSerialNum(this, m_loginType, "", m_profileName, m_accountName, nullptr, "", "");
|
|
if (m_inputSnDlg->exec())
|
|
{
|
|
//HGPdtToolDbDevice pdtToolDbDevice = nullptr;
|
|
//HGPdtToolDb_OpenDevice(m_pdtToolDbuserMgr, m_inputSnDlg->GetSn().toStdString().c_str(), &pdtToolDbDevice);
|
|
|
|
Form_mainInterface *mainInterface = new Form_mainInterface(this, m_loginType, m_profileName, m_accountName, nullptr,
|
|
m_inputSnDlg->GetSn(), m_inputSnDlg->GetDevType(), nullptr, nullptr);
|
|
if (!AddInterface(mainInterface))
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
|
|
delete mainInterface;
|
|
}
|
|
}
|
|
|
|
delete m_inputSnDlg;
|
|
m_inputSnDlg = nullptr;
|
|
}
|
|
void MainWindow::on_act_manage_triggered()
|
|
{
|
|
Dialog_accountManage dlg(this);
|
|
dlg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_changePwd_triggered()
|
|
{
|
|
Dialog_changePwd dlg(m_accountName, this);
|
|
dlg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_export_triggered()
|
|
{
|
|
// QString filename = QFileDialog::getSaveFileName(this, tr("save"), "test.xls", tr("xls(*.xls)"));
|
|
// if (!filename.isEmpty())
|
|
// {
|
|
// if (HGBASE_ERR_OK == HGPdtToolDb_Export(m_pdtToolDbuserMgr, getStdString(filename).c_str()))
|
|
// {
|
|
// QMessageBox::information(this, tr("tips"), tr("export succeed"));
|
|
// }
|
|
// else
|
|
// {
|
|
// QMessageBox::information(this, tr("tips"), tr("export failed"));
|
|
// }
|
|
// }
|
|
}
|
|
|
|
void MainWindow::on_act_logOut_triggered()
|
|
{
|
|
if (isTesting())
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("Is testing, do not close!"));
|
|
return;
|
|
}
|
|
m_isLogOut = true;
|
|
close();
|
|
}
|
|
|
|
|
|
void MainWindow::on_act_close_triggered()
|
|
{
|
|
if (isTesting())
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("Is testing, do not close!"));
|
|
return;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
void MainWindow::on_act_upload_triggered()
|
|
{
|
|
Dialog_uploadCfgFile dlg(this);
|
|
dlg.exec();
|
|
}
|
|
|
|
void MainWindow::on_act_refreshDevice_triggered()
|
|
{
|
|
std::vector<std::string> name;
|
|
name = getDevices();
|
|
|
|
if (m_loginType == Dialog_logIn::LogInType_Burn)
|
|
{
|
|
for (int i = 0; i < name.size(); ++i)
|
|
{
|
|
SANE_Handle devHandle = nullptr;
|
|
sane_open(name[i].c_str(), &devHandle);
|
|
if (nullptr != devHandle)
|
|
{
|
|
DeviceManager *devManager = new DeviceManager(this, m_formBurnMode, devHandle, m_profileName, name[i].c_str(), getDevSn(devHandle));
|
|
m_formBurnMode->addDevice(devManager);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < name.size(); ++i)
|
|
{
|
|
SANE_Handle devHandle = nullptr;
|
|
sane_open(name[i].c_str(), &devHandle);
|
|
if (nullptr != devHandle)
|
|
{
|
|
m_inputSnDlg = new Dialog_InputSerialNum(this, m_loginType, name[i].c_str(), m_profileName, m_accountName, devHandle, getDevSn(devHandle), getDevType(devHandle));
|
|
|
|
if (m_inputSnDlg->exec())
|
|
{
|
|
//HGPdtToolDbDevice pdtToolDbDevice = nullptr;
|
|
//HGPdtToolDb_OpenDevice(m_pdtToolDbuserMgr, m_inputSnDlg->GetSn().toStdString().c_str(), &pdtToolDbDevice);
|
|
|
|
Form_mainInterface *mainInterface = new Form_mainInterface(this, m_loginType, m_profileName, m_accountName, devHandle,
|
|
m_inputSnDlg->GetSn(), m_inputSnDlg->GetDevType(), name[i].c_str(), getDevFwNum(devHandle));
|
|
if (!AddInterface(mainInterface))
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
|
|
delete mainInterface;
|
|
}
|
|
m_tmpDevType = getDevType(devHandle);
|
|
}
|
|
else
|
|
{
|
|
sane_close(devHandle);
|
|
}
|
|
|
|
delete m_inputSnDlg;
|
|
m_inputSnDlg = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_act_openLog_triggered()
|
|
{
|
|
HGChar logPath[512];
|
|
HGBase_GetDocumentsPath(logPath, 512);
|
|
HGChar procName[512];
|
|
HGBase_GetProcessName(procName, 512);
|
|
strcat(logPath, procName);
|
|
strcat(logPath, "/Test_Log/");
|
|
|
|
QString defaultFileName = logPath + m_accountName + ".log";
|
|
|
|
QString fileName = getCfgValue(m_tmpDevType.toStdString().c_str(), "logPath", defaultFileName);
|
|
QFileInfo fileInfo(getStdFileName(fileName));
|
|
auto pathDir = fileInfo.path();
|
|
QString strFilePath = "file:///" + pathDir;
|
|
QDesktopServices::openUrl(QUrl(strFilePath));
|
|
}
|
|
|
|
static bool isLeap(int year)
|
|
{
|
|
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
static int getDays(int year, int month)
|
|
{
|
|
if (2 == month)
|
|
{
|
|
if (isLeap(year))
|
|
return 29;
|
|
else
|
|
return 28;
|
|
}
|
|
|
|
if (4 == month || 6 == month || 9 == month || 11 == month)
|
|
{
|
|
return 30;
|
|
}
|
|
|
|
return 31;
|
|
}
|
|
|
|
static int getPatchVersion()
|
|
{
|
|
const char *buildDate = __DATE__;
|
|
QDate date = QLocale(QLocale::English).toDate(QString(buildDate).replace(" ", " 0"), "MMM dd yyyy");
|
|
int year = date.year();
|
|
int day = date.day();
|
|
int month = date.month();
|
|
|
|
int ret = year % 100;
|
|
ret *= 1000;
|
|
|
|
for (int i = 1; i < month; ++i)
|
|
{
|
|
ret += getDays(year, i);
|
|
}
|
|
|
|
ret += day;
|
|
return ret;
|
|
}
|
|
|
|
void MainWindow::on_act_about_triggered()
|
|
{
|
|
int mainVersion = VERSION_MAIN;
|
|
int subVersion = VERSION_SUB;
|
|
int buildVersion = 10000;
|
|
int patchVersion = 0;
|
|
|
|
patchVersion = getPatchVersion();
|
|
|
|
HGChar version[32] = { 0 };
|
|
sprintf(version, "%d.%d.%d.%d", mainVersion, subVersion, buildVersion, patchVersion);
|
|
|
|
QString title = tr("about %1").arg(tr("Production tool"));
|
|
QString content;
|
|
content += tr("<p>DriverVer: %1</p>").arg(QString::fromLocal8Bit(version));
|
|
|
|
QMessageBox::about(this, title, content);
|
|
}
|