2023-01-04 06:28:44 +00:00
|
|
|
#include "form_burnmode.h"
|
|
|
|
#include "ui_form_burnmode.h"
|
|
|
|
#include "dialog_setburnsn.h"
|
|
|
|
#include "hgscanner.h"
|
|
|
|
#include "mainwindow.h"
|
2023-01-04 12:48:53 +00:00
|
|
|
#include "analysisjson.h"
|
|
|
|
#include "base/HGBase.h"
|
2023-01-04 06:28:44 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
|
|
|
Form_BurnMode::Form_BurnMode(class MainWindow *mainwnd, QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
m_curIndex(0),
|
|
|
|
m_mainwnd(mainwnd),
|
|
|
|
ui(new Ui::Form_BurnMode)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2023-01-04 14:24:41 +00:00
|
|
|
connect(this, SIGNAL(testResult(bool)), this, SLOT(on_testResult(bool)), Qt::QueuedConnection);
|
2023-01-04 06:28:44 +00:00
|
|
|
|
|
|
|
initTableWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
Form_BurnMode::~Form_BurnMode()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Form_BurnMode::addDevice(DeviceManager *devManager)
|
|
|
|
{
|
|
|
|
ui->tableWidget->setRowCount(m_curIndex + 1);
|
|
|
|
ui->tableWidget->setItem(m_curIndex, 0, new QTableWidgetItem(QString::number(m_curIndex + 1)));
|
|
|
|
ui->tableWidget->item(m_curIndex, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
QTableWidgetItem *check = new QTableWidgetItem();
|
|
|
|
check->setCheckState(Qt::Unchecked);
|
|
|
|
ui->tableWidget->setItem(m_curIndex, 1, check);
|
|
|
|
ui->tableWidget->item(m_curIndex, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui->tableWidget->setItem(m_curIndex, 2, new QTableWidgetItem(devManager->getDevName()));
|
|
|
|
ui->tableWidget->item(m_curIndex, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
ui->tableWidget->setItem(m_curIndex, 3, new QTableWidgetItem(devManager->getSn()));
|
|
|
|
ui->tableWidget->item(m_curIndex, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(m_curIndex, 1);
|
|
|
|
QVariant var = QVariant::fromValue((void*)devManager);
|
|
|
|
item->setData(Qt::UserRole, var);
|
|
|
|
|
2023-01-05 07:18:55 +00:00
|
|
|
updatetablewidget();
|
2023-01-04 06:28:44 +00:00
|
|
|
// for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
|
|
|
// {
|
|
|
|
// QTableWidgetItem *item = ui->tableWidget->item(i, 3);
|
|
|
|
// if (item != nullptr)
|
|
|
|
// item->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled);
|
|
|
|
// }
|
|
|
|
|
|
|
|
m_curIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Form_BurnMode::deleteDevice(QString devName)
|
|
|
|
{
|
2023-01-05 07:18:55 +00:00
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
2023-01-04 06:28:44 +00:00
|
|
|
{
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
QTableWidgetItem *item2 = ui->tableWidget->item(i, 2);
|
|
|
|
if (devName!= nullptr && item != nullptr)
|
|
|
|
{
|
|
|
|
if (devName == item2->text())
|
|
|
|
{
|
|
|
|
DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
|
|
|
|
delete devManager;
|
|
|
|
|
|
|
|
ui->tableWidget->removeRow(i);
|
|
|
|
m_curIndex--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-05 07:18:55 +00:00
|
|
|
updatetablewidget();
|
2023-01-04 06:28:44 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 14:24:41 +00:00
|
|
|
void Form_BurnMode::on_testResult(bool setStatus)
|
2023-01-04 06:28:44 +00:00
|
|
|
{
|
|
|
|
m_mainwnd->releaseTesting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Form_BurnMode::initTableWidget()
|
|
|
|
{
|
|
|
|
ui->tableWidget->resizeRowsToContents();
|
|
|
|
ui->tableWidget->setColumnCount(4);
|
|
|
|
ui->tableWidget->horizontalHeader()->setDefaultSectionSize(200);
|
|
|
|
// ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
|
|
|
|
QStringList header;
|
|
|
|
header<< tr("ID") << tr("selected") << tr("device") << tr("serialNum");
|
|
|
|
ui->tableWidget->setHorizontalHeaderLabels(header);
|
|
|
|
|
|
|
|
QFont font = ui->tableWidget->horizontalHeader()->font();
|
|
|
|
font.setBold(true);
|
|
|
|
ui->tableWidget->horizontalHeader()->setFont(font);
|
|
|
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
ui->tableWidget->verticalHeader()->setDefaultSectionSize(10);
|
|
|
|
ui->tableWidget->setFrameShape(QFrame::NoFrame);
|
|
|
|
ui->tableWidget->setShowGrid(true);
|
|
|
|
ui->tableWidget->verticalHeader()->setVisible(false);
|
|
|
|
// ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
ui->tableWidget->horizontalHeader()->setFixedHeight(30);
|
|
|
|
ui->tableWidget->clearContents();
|
|
|
|
}
|
|
|
|
|
2023-01-05 07:18:55 +00:00
|
|
|
void Form_BurnMode::updatetablewidget()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
|
|
|
{
|
|
|
|
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(QString::number(i + 1)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-04 06:28:44 +00:00
|
|
|
void Form_BurnMode::on_cbox_selectAll_stateChanged(int arg1)
|
|
|
|
{
|
|
|
|
(void)arg1;
|
|
|
|
bool check = ui->cbox_selectAll->isChecked();
|
|
|
|
|
2023-01-05 07:18:55 +00:00
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
2023-01-04 06:28:44 +00:00
|
|
|
{
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
if (item != nullptr)
|
|
|
|
{
|
|
|
|
if (check)
|
|
|
|
item->setCheckState(Qt::Checked);
|
|
|
|
else
|
|
|
|
item->setCheckState(Qt::Unchecked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Form_BurnMode::on_pbtn_burn_clicked()
|
|
|
|
{
|
2023-01-04 14:24:41 +00:00
|
|
|
int select = 0;
|
2023-01-05 07:18:55 +00:00
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
2023-01-04 14:24:41 +00:00
|
|
|
{
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
if (item != nullptr && Qt::Checked == item->checkState())
|
|
|
|
{
|
|
|
|
select++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (select == 0)
|
|
|
|
{
|
2023-01-05 07:18:55 +00:00
|
|
|
QMessageBox::information(this, tr("tips"), tr("Please check a devices at least"));
|
2023-01-04 14:24:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-05 07:18:55 +00:00
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
2023-01-04 06:28:44 +00:00
|
|
|
{
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
if (item != nullptr && Qt::Checked == item->checkState())
|
|
|
|
{
|
|
|
|
DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
|
|
|
|
devManager->setBurnMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-06 05:39:49 +00:00
|
|
|
//void Form_BurnMode::on_pbtn_setSn_clicked()
|
|
|
|
//{
|
|
|
|
// int select = 0;
|
|
|
|
// for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
|
|
|
// {
|
|
|
|
// QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
// if (item != nullptr && Qt::Checked == item->checkState())
|
|
|
|
// {
|
|
|
|
// select++;
|
|
|
|
// }
|
|
|
|
// }
|
2023-01-04 06:28:44 +00:00
|
|
|
|
2023-01-06 05:39:49 +00:00
|
|
|
// if (select == 0)
|
|
|
|
// {
|
|
|
|
// QMessageBox::information(this, tr("tips"), tr("Please check a devices to set sn at least"));
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// else if (select > 1)
|
|
|
|
// {
|
|
|
|
// QMessageBox::information(this, tr("tips"), tr("Please check single devices to set sn"));
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
// else if (select == 1)
|
|
|
|
// {
|
|
|
|
// for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
|
|
|
// {
|
|
|
|
// QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
// QTableWidgetItem *item2 = ui->tableWidget->item(i, 3);
|
|
|
|
// if (item != nullptr && Qt::Checked == item->checkState())
|
|
|
|
// {
|
|
|
|
// Dialog_SetBurnSn dlg(item2->text(), this);
|
|
|
|
// if (dlg.exec())
|
|
|
|
// {
|
|
|
|
// DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
|
|
|
|
// devManager->setSn(dlg.getSn());
|
|
|
|
|
|
|
|
// item2->setText(devManager->getUpdatedSn());
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
2023-01-04 06:28:44 +00:00
|
|
|
|
2023-01-04 12:48:53 +00:00
|
|
|
DeviceManager::DeviceManager(class MainWindow *mainwnd, HGPdtToolDbUserMgr pdtToolDbuserMgr, class Form_BurnMode *burnMode,
|
|
|
|
SANE_Handle handle, const QString & devName, const QString & sn, const QString &devType)
|
2023-01-04 06:28:44 +00:00
|
|
|
{
|
2023-01-04 12:48:53 +00:00
|
|
|
m_mainwnd = mainwnd;
|
|
|
|
m_pdtToolDbuserMgr = pdtToolDbuserMgr;
|
|
|
|
m_burnMode = burnMode;
|
2023-01-04 06:28:44 +00:00
|
|
|
m_handle = handle;
|
|
|
|
m_devName = devName;
|
|
|
|
m_sn = sn;
|
2023-01-04 12:48:53 +00:00
|
|
|
m_devType = devType;
|
2023-01-04 06:28:44 +00:00
|
|
|
|
2023-01-06 07:17:48 +00:00
|
|
|
m_hg = new hgscanner(nullptr, m_burnMode, nullptr, m_handle);
|
2023-01-04 06:28:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManager::~DeviceManager()
|
|
|
|
{
|
|
|
|
delete m_hg;
|
|
|
|
m_hg = nullptr;
|
|
|
|
|
|
|
|
sane_close(m_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DeviceManager::getDevName()
|
|
|
|
{
|
|
|
|
return m_devName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DeviceManager::getSn()
|
|
|
|
{
|
|
|
|
return m_sn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceManager::setBurnMode()
|
|
|
|
{
|
|
|
|
const wchar_t *p = L"1";
|
|
|
|
func_test_go(HGPDTTOOLDB_NAME_REBOOT_DEVICE, p, m_hg);
|
|
|
|
m_mainwnd->addTestingRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceManager::setSn(QString sn)
|
|
|
|
{
|
|
|
|
LPWRITECFG p = new WRITECFG;
|
|
|
|
|
2023-01-04 09:27:24 +00:00
|
|
|
std::wstring sn2 = sn.toStdWString();
|
2023-01-04 06:28:44 +00:00
|
|
|
p->cat = WRITE_CAT_SERIALNUM;
|
2023-01-04 09:27:24 +00:00
|
|
|
p->val = (void*)sn2.c_str();
|
2023-01-04 06:28:44 +00:00
|
|
|
func_test_go(WRITE_CFG_NAME, (const wchar_t*)p, m_hg);
|
|
|
|
m_mainwnd->addTestingRef();
|
|
|
|
|
2023-01-04 12:48:53 +00:00
|
|
|
setGlobalCfg();
|
|
|
|
|
2023-01-04 06:28:44 +00:00
|
|
|
delete p;
|
|
|
|
}
|
2023-01-04 09:27:24 +00:00
|
|
|
|
2023-01-04 12:48:53 +00:00
|
|
|
QString DeviceManager::getUpdatedSn()
|
|
|
|
{
|
|
|
|
return m_mainwnd->getDevSn(m_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceManager::setGlobalCfg()
|
|
|
|
{
|
|
|
|
HGChar cfgPath[512] = {0};
|
|
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
|
|
HGBase_CreateDir(cfgPath);
|
|
|
|
strcat(cfgPath, m_devType.toStdString().c_str());
|
|
|
|
strcat(cfgPath, ".json");
|
|
|
|
|
|
|
|
HGPdtToolDb_DownloadFile(m_pdtToolDbuserMgr, m_devType.toStdString().c_str(), cfgPath);
|
|
|
|
|
|
|
|
AnalysisJson analysisJson(QString::fromStdString(cfgPath));
|
|
|
|
|
|
|
|
assert(nullptr != m_hg);
|
|
|
|
AnalysisJson::json_global jsonGlobal = analysisJson.GetGlobal();
|
|
|
|
LPWRITECFG lp = new WRITECFG;
|
|
|
|
|
|
|
|
VIDPID vidpid;
|
|
|
|
vidpid.VID = jsonGlobal.vid_to;
|
|
|
|
vidpid.PID = jsonGlobal.pid_to;
|
|
|
|
int vidpidValue = vidpid.Value;
|
|
|
|
lp->cat = WRITE_CAT_VID_PID;
|
|
|
|
lp->val = (void*)&vidpidValue;
|
|
|
|
func_test_go(WRITE_CFG_NAME, (const wchar_t*)lp, m_hg);
|
|
|
|
m_mainwnd->addTestingRef();
|
|
|
|
|
|
|
|
int speedMode = jsonGlobal.speed_mode ;
|
|
|
|
lp->cat = WRITE_CAT_SPEED;
|
|
|
|
lp->val = (void*)&speedMode;
|
|
|
|
func_test_go(WRITE_CFG_NAME, (const wchar_t*)lp, m_hg);
|
|
|
|
m_mainwnd->addTestingRef();
|
|
|
|
|
|
|
|
int sleepTime = jsonGlobal.sleep_time;
|
|
|
|
lp->cat = WRITE_CAT_SLEEP;
|
|
|
|
lp->val = (void*)&sleepTime;
|
|
|
|
func_test_go(WRITE_CFG_NAME, (const wchar_t*)lp, m_hg);
|
|
|
|
m_mainwnd->addTestingRef();
|
|
|
|
|
|
|
|
delete lp;
|
|
|
|
}
|
|
|
|
|
2023-01-04 09:27:24 +00:00
|
|
|
void Form_BurnMode::on_tableWidget_itemDoubleClicked(QTableWidgetItem *item)
|
|
|
|
{
|
|
|
|
int row = item->row();
|
|
|
|
QTableWidgetItem *item2 = ui->tableWidget->item(row, 1);
|
|
|
|
if (item2->checkState() == Qt::Checked)
|
|
|
|
{
|
|
|
|
item2->setCheckState(Qt::Unchecked);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item2->setCheckState(Qt::Checked);
|
|
|
|
}
|
|
|
|
}
|
2023-01-04 12:48:53 +00:00
|
|
|
|
2023-01-05 07:18:55 +00:00
|
|
|
void Form_BurnMode::on_pbtn_close_clicked()
|
|
|
|
{
|
|
|
|
int select = 0;
|
|
|
|
for(int i = 0; i < ui->tableWidget->rowCount(); i++)
|
|
|
|
{
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
if (item != nullptr && Qt::Checked == item->checkState())
|
|
|
|
{
|
|
|
|
select++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (select == 0)
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("tips"), tr("Please check a devices at least"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:16:17 +00:00
|
|
|
int rowCount = ui->tableWidget->rowCount();
|
|
|
|
for (int i = rowCount - 1; i >= 0; --i)
|
2023-01-05 07:18:55 +00:00
|
|
|
{
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(i, 1);
|
|
|
|
if (item != nullptr && Qt::Checked == item->checkState())
|
|
|
|
{
|
|
|
|
DeviceManager *devManager = (DeviceManager*)item->data(Qt::UserRole).value<void*>();
|
|
|
|
delete devManager;
|
2023-01-04 12:48:53 +00:00
|
|
|
|
2023-01-05 07:18:55 +00:00
|
|
|
ui->tableWidget->removeRow(i);
|
|
|
|
m_curIndex--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updatetablewidget();
|
|
|
|
}
|