code_app/app/fwupgrade/mainwindow.cpp

951 lines
30 KiB
C++
Raw Normal View History

2022-11-10 02:22:58 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QMovie>
#include <QMessageBox>
2022-11-10 09:23:16 +00:00
#include <QFileDialog>
#include <QMessageBox>
#include <QCryptographicHash>
2022-11-10 09:23:16 +00:00
#include "dialog_upgradefirmware.h"
#include "dialog_updateprogress.h"
2022-11-10 09:23:16 +00:00
#include "base/HGBase.h"
#include "base/HGInc.h"
#include "huagao/hgscanner_error.h"
#include "sane/sane_option_definitions.h"
#include "HGString.h"
#include <algorithm>
2022-11-10 09:23:16 +00:00
2023-06-15 07:29:35 +00:00
#if defined(HG_CMP_MSC)
#include <shlobj.h>
#else
#include <grp.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#endif
2022-11-10 09:23:16 +00:00
#define PASSWORD_KEY 4
2022-11-10 02:22:58 +00:00
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
2023-06-16 09:37:44 +00:00
, m_isFlatCorrecting(false)
, m_isDisCorrecting(false)
2022-11-10 02:22:58 +00:00
{
ui->setupUi(this);
2022-11-10 09:23:16 +00:00
m_curDevName.clear();
m_curDevHandle = nullptr;
m_curFwVersion.clear();
m_curSerialNum.clear();
2022-11-10 09:23:16 +00:00
ui->editFilePath->setEnabled(false);
ui->editOldPassword->setEchoMode(QLineEdit::EchoMode::Password);
ui->editNewPassword->setEchoMode(QLineEdit::EchoMode::Password);
ui->editNewPassword_2->setEchoMode(QLineEdit::EchoMode::Password);
ui->btnGetVersionList->setEnabled(false);
ui->btnDownloadUpgrade->setEnabled(false);
ui->btnOpenFilePath->setEnabled(false);
ui->btnUpgrade->setEnabled(false);
ui->btnClearRollCount->setEnabled(false);
addContent(ui->textBrowser_flatcorrect, tr("Please confirm that the device has correctly placed the calibration paper!"), false);
addContent(ui->textBrowser_disCorrect, tr("Please confirm that the device has placed a special scanning test paper for distortion correction!"), false);
2022-11-10 09:23:16 +00:00
connect(this, SIGNAL(sane_dev_arrive(QString, bool)), this, SLOT(on_sane_dev_arrive(QString, bool)), Qt::QueuedConnection);
connect(this, SIGNAL(sane_dev_remove(QString)), this, SLOT(on_sane_dev_remove(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(correctInfo(QString)), this, SLOT(on_correctInfo(QString)), Qt::QueuedConnection);
2023-06-16 09:37:44 +00:00
connect(this, SIGNAL(scan_finish(void*)), this, SLOT(on_scan_finish(void*)), Qt::QueuedConnection);
2022-11-10 09:23:16 +00:00
m_versionMgr = nullptr;
HGVersion_CreateMgr(&m_versionMgr);
SANE_Int v = 0;
sane_init_ex(&v, sane_ex_callback, this);
2022-11-10 02:22:58 +00:00
}
MainWindow::~MainWindow()
{
2022-11-10 09:23:16 +00:00
if (nullptr != m_curDevHandle)
{
sane_close(m_curDevHandle);
m_curDevHandle = nullptr;
}
m_curFwVersion.clear();
m_curDevName.clear();
sane_exit();
m_vVersion.clear();
2022-11-10 09:23:16 +00:00
HGVersion_DestroyMgr(m_versionMgr);
m_versionMgr = nullptr;
2022-11-10 02:22:58 +00:00
delete ui;
}
2023-06-15 07:29:35 +00:00
static HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen)
{
if (NULL == configPath || 0 == maxLen)
{
return HGBASE_ERR_INVALIDARG;
}
const char *appName = "HuaGoScan";
#if defined(HG_CMP_MSC)
CHAR cfgPath[MAX_PATH] = { 0 };
BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE);
if (!ret)
return HGBASE_ERR_FAIL;
if (cfgPath[strlen(cfgPath) - 1] != '\\')
strcat(cfgPath, "\\");
strcat(cfgPath, appName);
strcat(cfgPath, "\\Cfg\\");
#else
char cfgPath[512] = { 0 };
struct passwd* pw = getpwuid(getuid());
strcpy(cfgPath, pw->pw_dir);
if (cfgPath[strlen(cfgPath) - 1] != '/')
strcat(cfgPath, "/");
strcat(cfgPath, ".");
strcat(cfgPath, appName);
strcat(cfgPath, "/Cfg/");
#endif
if (maxLen < strlen(cfgPath) + 1)
return HGBASE_ERR_FAIL;
strcpy(configPath, cfgPath);
return HGBASE_ERR_OK;
}
2022-11-10 09:23:16 +00:00
QString MainWindow::passwordEncrypt(const QString& password)
{
QString p = password;
int num = PASSWORD_KEY - p.length() % PASSWORD_KEY;
for (int i = 0; i < num; i++)
p.append("+");
int rows = p.length() / 4;
QString transcode;
for (int i = 0; i < PASSWORD_KEY; i++)
for (int j = 0; j < rows; j++)
transcode.append(p[i + j * PASSWORD_KEY]);
return transcode;
}
QString MainWindow::passwordDecrypt(const QString& transcode)
{
QString t = transcode;
int cols = t.length() / 4;
QString password;
for (int i = 0; i < cols; i++)
for (int j = 0; j < PASSWORD_KEY; j++)
password.append(t[i + j * cols]);
password.remove("+");
return password;
}
QString MainWindow::GetDevType(const QString& fwVersion, bool *canLock)
{
if (NULL != canLock)
*canLock = false;
QString devType;
if (fwVersion.length() == 10)
{
QString dev = fwVersion.left(2);
if (fwVersion.mid(2, 2) == "40" || fwVersion.mid(2, 2) == "50"
|| fwVersion.mid(2, 2) == "60" || fwVersion.mid(2, 2) == "70")
{
// 3288
QString ver = fwVersion.mid(2, 2);
QString date = fwVersion.mid(4, 6);
}
else
{
// 3399
QString ver = fwVersion.mid(2, 3);
QString date = fwVersion.mid(5, 5);
if ((dev == "G1" || dev == "G2") && ver == "393")
{
if (date >= "A1220" && date <= "A1230")
{
devType = dev + ver + "/" + "A1220-A1230";
if (date >= "A1224")
{
if (NULL != canLock)
*canLock = true;
}
}
else if (date >= "B0326" && date <= "B0334")
{
devType = dev + ver + "/" + "B0326-B0334";
if (date >= "B0333")
{
if (NULL != canLock)
*canLock = true;
}
}
else if (date >= "B0429")
{
devType = dev + ver + "/" + "B0429-";
if (date >= "B1031" || date == "B0500")
{
if (NULL != canLock)
*canLock = true;
}
}
}
else if (dev == "G4" && ver == "393")
{
devType = dev + ver + "/";
if (date >= "B1108")
{
if (NULL != canLock)
*canLock = true;
}
}
}
}
return devType;
}
2023-06-16 09:37:44 +00:00
void MainWindow::closeEvent(QCloseEvent *event)
{
if (m_isDisCorrecting || m_isFlatCorrecting)
{
QMessageBox::warning(this, tr("Warning"), tr("Device is Running! please wait for the process to end."));
event->ignore();
return;
}
}
2022-11-10 09:23:16 +00:00
void MainWindow::on_sane_dev_arrive(QString devName, bool opened)
{
int idx = -1;
int count = ui->comboDevList->count();
for (int i = 0; i < count; ++i)
{
QString name = ui->comboDevList->itemText(i);
if (name == devName)
{
idx = i;
break;
}
}
if (-1 == idx)
{
assert(!opened);
2022-11-10 09:23:16 +00:00
ui->comboDevList->addItem(devName);
}
else if (opened)
{
ui->comboDevList->setCurrentIndex(-1);
ui->comboDevList->setCurrentIndex(idx);
}
2022-11-10 09:23:16 +00:00
}
void MainWindow::on_sane_dev_remove(QString devName)
{
int idx = -1;
int count = ui->comboDevList->count();
for (int i = 0; i < count; ++i)
{
QString name = ui->comboDevList->itemText(i);
if (name == devName)
{
idx = i;
break;
}
}
if (-1 != idx)
{
ui->comboDevList->removeItem(idx);
}
}
void MainWindow::on_correctInfo(QString info)
{
addContent(ui->textBrowser_flatcorrect, info, true);
}
2023-06-16 09:37:44 +00:00
void MainWindow::on_scan_finish(void *data)
{
2023-06-16 09:37:44 +00:00
if (0 == strcmp((char*)data, STATU_DESC_SCAN_STOPPED))
{
unsigned int len = sizeof(int);
SANE_DISTORTION_VAL dis = { 0 };
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_PC_DISTORTION_CHECK_VAL, &dis, &len);
2023-06-16 09:37:44 +00:00
if (ret != SANE_STATUS_GOOD || (dis.w < 0 && dis.w > 9999) || (dis.h < 0 && dis.h > 9999) || dis.scaleXY < 0)
{
2023-06-16 09:37:44 +00:00
addContent(ui->textBrowser_disCorrect, tr("Count distortion failed"), false);
QMessageBox::information(this, tr("Prompt"), tr("Count distortion failed"));
m_isDisCorrecting = false;
return;
}
QString value(QString::number(dis.scaleXY, 'f', 4));
2023-06-16 09:37:44 +00:00
addContent(ui->textBrowser_disCorrect, tr("Count distortion succeed: %1").arg(value), true);
ui->lineEdit_countDistortion->setText(value);
}
else if (0 == strcmp((char*)data, STATU_DESC_SCANNER_ERR_DEVICE_AUTO_FAIL_OVER))
{
ui->label_correct->setText(tr("Have already corrected"));
}
else
{
QMessageBox::information(this, tr("Prompt"), QString::fromStdString((char*)data));
if (m_isFlatCorrecting)
ui->label_correct->setText(QString::fromStdString((char*)data));
}
2023-06-16 09:37:44 +00:00
m_isDisCorrecting = false;
m_isFlatCorrecting = false;
ui->pushButton_correct->setEnabled(true);
}
2022-11-10 09:23:16 +00:00
void MainWindow::on_btnExit_clicked()
{
close();
}
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, sane_dev->openned == SANE_TRUE);
}
break;
case SANE_EVENT_DEVICE_LEFT:
{
SANE_Device* sane_dev = (SANE_Device*)data;
emit p->sane_dev_remove(sane_dev->name);
}
break;
case SANE_EVENT_STATUS:
{
QString info;
if (data != nullptr)
{
info = QString::fromStdString((const char*)data);
emit p->correctInfo(info);
}
}
break;
case SANE_EVENT_SCAN_FINISHED:
QString info;
if (data != nullptr)
{
2023-06-16 09:37:44 +00:00
emit p->scan_finish(data);
}
break;
2022-11-10 09:23:16 +00:00
}
return 0;
}
void MainWindow::initColorAndDpi()
{
const char *color = nullptr;
if (0 == ui->comboBox_colorMode->currentIndex())
{
color = OPTION_VALUE_YSMS_24WCS;
}
else
{
color = OPTION_VALUE_YSMS_256JHD;
}
int dpi = ui->comboBox_dpi->currentText().toInt();
unsigned int colorLen = strlen(color);
unsigned int len = sizeof(int);
sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_COLOR, (void*)color, &colorLen);
sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_DPI, (void*)&dpi, &len);
}
QString MainWindow::getSpeedMode()
2022-11-10 09:23:16 +00:00
{
QString devType = m_curFwVersion.left(2) + "00";
2022-11-10 09:23:16 +00:00
SANE_Int speedMode = 0;
unsigned int len = sizeof(SANE_Int);
sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_SPEED_MODE, &speedMode, &len);
const wchar_t G100[6] = { 70,80,90,110 };
const wchar_t G200[6] = { 100,110,120,130 };
const wchar_t G300[6] = { 40,50,60,70 };
const wchar_t G400[6] = { 40,50,60,70,80 };
int speed = 0;
if ((int)speedMode >= 40)
speed = (int)speedMode;
else
{
if (devType == "G100")
speed = G100[(int)speedMode - 1];
else if (devType == "G200")
speed = G200[(int)speedMode - 1];
else if (devType == "G300")
speed = G300[(int)speedMode - 1];
else if (devType == "G400")
speed = G400[(int)speedMode - 1];
}
if (0 == speed)
return(QString(tr("do not support")));
return QString::number(speed) + "PPM";
}
void MainWindow::addContent(QTextBrowser *textBrowser, QString content, bool isNormal)
{
2023-06-16 09:37:44 +00:00
textBrowser->moveCursor(QTextCursor::End);
if (isNormal)
textBrowser->insertPlainText(content);
else
{
textBrowser->setTextColor(Qt::red);
textBrowser->insertPlainText(content);
}
textBrowser->setTextColor(Qt::black);
textBrowser->insertPlainText("\n");
}
void MainWindow::on_comboDevList_currentIndexChanged(int index)
{
m_vVersion.clear();
2022-11-10 09:23:16 +00:00
ui->comboVersionList->clear();
ui->editFilePath->clear();
2023-06-27 13:04:39 +00:00
ui->label_rollerCout->setText(QString(tr("roll count: %1")).arg(QString::number(0)));
ui->label_scanCount->setText(QString(tr("scan count: %1")).arg(QString::number(0)));
ui->label_deviceError->clear();
ui->labelDevInfo->clear();
2022-11-10 09:23:16 +00:00
if (nullptr != m_curDevHandle)
{
sane_close(m_curDevHandle);
m_curDevHandle = nullptr;
}
m_curFwVersion.clear();
m_curSerialNum.clear();
2022-11-10 09:23:16 +00:00
m_curDevName.clear();
ui->btnGetVersionList->setEnabled(false);
ui->btnDownloadUpgrade->setEnabled(false);
ui->btnOpenFilePath->setEnabled(false);
ui->btnUpgrade->setEnabled(false);
ui->btnClearRollCount->setEnabled(false);
ui->comboBox_colorMode->setEnabled(false);
ui->comboBox_dpi->setEnabled(false);
ui->pushButton_getDistortion->setEnabled(false);
ui->pushButton_setDistortion->setEnabled(false);
2023-06-16 09:37:44 +00:00
ui->lineEdit_getDistortion->setEnabled(false);
ui->pushButton_correct->setEnabled(false);
2022-11-10 09:23:16 +00:00
if (-1 != index)
{
QString name = ui->comboDevList->itemText(index);
SANE_Status ret = sane_open(name.toStdString().c_str(), &m_curDevHandle);
if (SANE_STATUS_GOOD == ret)
2022-11-10 09:23:16 +00:00
{
m_curDevName = name;
std::string fwVersionNum;
unsigned int fwVersionNumLen = 0;
if(SANE_STATUS_NO_MEM == sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_HARDWARE_VERSION, nullptr, &fwVersionNumLen)
&& fwVersionNumLen)
2022-11-10 09:23:16 +00:00
{
fwVersionNum.resize(fwVersionNumLen);
sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_HARDWARE_VERSION, &fwVersionNum[0], &fwVersionNumLen);
2022-11-10 09:23:16 +00:00
}
std::string serialNum;
unsigned int serialNumLen = 0;
if(SANE_STATUS_NO_MEM == sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_SERIAL, nullptr, &serialNumLen)
&& serialNumLen)
{
serialNum.resize(serialNumLen);
sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_SERIAL, &serialNum[0], &serialNumLen);
}
m_curSerialNum =QString::fromStdString(serialNum.c_str());
m_curFwVersion = QString::fromStdString(fwVersionNum.c_str());
QString devType = GetDevType(m_curFwVersion, NULL);
ui->labelDevInfo->setText(QString(tr("upgrade: %1")).arg(!devType.isEmpty() ? tr("support") : tr("do not support")));
2023-06-17 07:27:49 +00:00
ui->label_fwNum->setText(QString(tr("FirmWare number: %1").arg(!m_curFwVersion.isEmpty() ? m_curFwVersion : tr("do not support"))));
ui->label_sn->setText(QString(tr("Serial number: %1").arg(!m_curSerialNum.isEmpty() ? m_curSerialNum : tr("do not support"))));
ui->label_speedMode->setText(QString(tr("speed mode: %1").arg(getSpeedMode())));
2022-11-10 09:23:16 +00:00
SANE_Int rollCount = 0;
unsigned int rollCountSize = sizeof(SANE_Int);
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_ROLLER_NUM, &rollCount, &rollCountSize);
if(ret == SANE_STATUS_GOOD && rollCount >= 0)
2022-11-11 03:56:19 +00:00
{
2023-06-27 13:04:39 +00:00
ui->label_rollerCout->setText(QString(tr("roll count: %1")).arg(rollCount));
2022-11-11 03:56:19 +00:00
}
else
{
2023-06-27 13:04:39 +00:00
ui->label_rollerCout->setText(tr("do not support"));
}
SANE_Int scanCount = 0;
unsigned int scanCountSize = sizeof(SANE_Int);
ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_HISTORY_SCAN_NUM, &scanCount, &scanCountSize);
if (ret == SANE_STATUS_GOOD && scanCount >= 0)
{
2023-06-27 13:04:39 +00:00
ui->label_scanCount->setText(QString(tr("scan count: %1")).arg(scanCount));
}
else
{
2023-06-27 13:04:39 +00:00
ui->label_scanCount->setText(tr("do not support"));
2022-11-11 03:56:19 +00:00
}
2022-11-10 09:23:16 +00:00
2023-06-17 07:27:49 +00:00
char motorVersion[256] = {0};
SANE_Int motorVersionLen = 0;
ret = sane_control_option(m_curDevHandle, (SANE_Int)0x885D, SANE_ACTION_GET_VALUE, motorVersion, &motorVersionLen);
ui->label_motorVersion->setText(QString(tr("Motor Version: %1")).arg(*motorVersion != 0 ? QString::fromStdString(motorVersion) : tr("do not support")));
if (!devType.isEmpty())
{
ui->btnGetVersionList->setEnabled(true);
ui->btnOpenFilePath->setEnabled(true);
}
2022-11-10 09:23:16 +00:00
ui->btnClearRollCount->setEnabled(true);
ui->comboBox_colorMode->setEnabled(true);
ui->comboBox_dpi->setEnabled(true);
ui->pushButton_getDistortion->setEnabled(true);
ui->pushButton_setDistortion->setEnabled(true);
2023-06-16 09:37:44 +00:00
ui->lineEdit_getDistortion->setEnabled(true);
ui->pushButton_correct->setEnabled(true);
}
else if (SCANNER_ERR_OPENED_BY_OTHER_PROCESS == ret)
{
ui->label_deviceError->setText(QString(tr("Device is opened by other process")));
2022-11-10 09:23:16 +00:00
}
else
{
ui->label_deviceError->setText(QString(tr("open device error")));
2022-11-10 09:23:16 +00:00
}
}
else
{
ui->label_deviceError->setText(tr("no device opened"));
2022-11-10 09:23:16 +00:00
}
}
static bool Greater(const VersionInfo &info1, const VersionInfo &info2)
{
return info1.version > info2.version;
}
2022-11-10 09:23:16 +00:00
void MainWindow::on_btnGetVersionList_clicked()
{
m_vVersion.clear();
2022-11-10 09:23:16 +00:00
ui->comboVersionList->clear();
QString devType = GetDevType(m_curFwVersion, NULL);
assert(!devType.isEmpty());
HGVersionInfo *versionInfo = nullptr;
HGUInt versionCount = 0;
HGVersion_GetDriverVersionList(m_versionMgr, devType.toStdString().c_str(), &versionInfo, &versionCount);
if (0 != versionCount)
2022-11-10 09:23:16 +00:00
{
for (HGUInt i = 0; i < versionCount; ++i)
2022-11-10 09:23:16 +00:00
{
if (QString(versionInfo[i].version) > m_curFwVersion)
{
VersionInfo inf;
inf.version = versionInfo[i].version;
inf.url = versionInfo[i].url;
inf.md5 = versionInfo[i].md5;
m_vVersion.push_back(inf);
}
2022-11-10 09:23:16 +00:00
}
}
HGVersion_ReleaseVersionList(versionInfo, versionCount);
std::sort(m_vVersion.begin(), m_vVersion.end(), Greater);
for (int i = 0; i < m_vVersion.size(); ++i)
{
ui->comboVersionList->addItem(m_vVersion[i].version.c_str());
}
if (m_vVersion.empty())
2022-11-10 09:23:16 +00:00
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("no version available"), QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
}
}
void MainWindow::on_comboVersionList_currentIndexChanged(int index)
{
if (-1 != index)
{
ui->btnDownloadUpgrade->setEnabled(true);
}
else
{
ui->btnDownloadUpgrade->setEnabled(false);
}
}
void MainWindow::on_editFilePath_textChanged(const QString &arg1)
{
if (arg1.isEmpty())
{
ui->btnUpgrade->setEnabled(false);
}
else
{
ui->btnUpgrade->setEnabled(true);
}
}
void MainWindow::on_btnOpenFilePath_clicked()
{
QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), ".", tr("ZIP Files(*.zip *.zip)"));
2022-11-10 09:23:16 +00:00
if (!filePath.isEmpty())
{
QString devType = GetDevType(m_curFwVersion, NULL);
assert(!devType.isEmpty());
HGChar fileName[256] = {0};
HGBase_GetFileName(filePath.toStdString().c_str(), fileName, 256);
HGChar fileVersion[256] = {0};
HGBase_GetFilePrefix(fileName, fileVersion, 256);
if (devType == GetDevType(fileVersion, NULL))
{
if (m_curFwVersion >= fileVersion)
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("the selected firmware is not newer than the current version"), QMessageBox::Ok, this);
msg.exec();
}
else
{
ui->editFilePath->setText(filePath);
}
}
else
{
QMessageBox msg(QMessageBox::Question, tr("tips"),
tr("firmware file mismatch, continue?"),
QMessageBox::Yes | QMessageBox::No, this);
msg.exec();
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
{
ui->editFilePath->setText(filePath);
}
}
2022-11-10 09:23:16 +00:00
}
}
void MainWindow::on_btnDownloadUpgrade_clicked()
{
int idx = ui->comboVersionList->currentIndex();
if (-1 != idx)
{
QString url = m_vVersion[idx].url.c_str();
QString md5 = m_vVersion[idx].md5.c_str();
QString versionNum = m_vVersion[idx].version.c_str();
if (m_curFwVersion >= versionNum)
2022-11-10 09:23:16 +00:00
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("the selected firmware is not newer than the current version"), QMessageBox::Ok, this);
msg.exec();
return;
2022-11-10 09:23:16 +00:00
}
assert(!url.isEmpty() && !md5.isEmpty() && !versionNum.isEmpty());
HGChar suffix[64];
HGBase_GetFileSuffix(url.toStdString().c_str(), suffix, 64);
HGChar savePath[512];
HGBase_GetTmpPath(savePath, 512);
2022-11-24 09:02:26 +00:00
HGBase_CreateDir(savePath);
HGChar fileName[128];
sprintf(fileName, "%s.%s", "{644759d6-7e4e-47c7-b42e-5105bb2de4a3}", suffix);
strcat(savePath, fileName);
QFile saveFile(savePath);
saveFile.open(QFile::ReadOnly);
QByteArray fileMsg = saveFile.readAll();
saveFile.close();
QString md5_2 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
QFile f(savePath);
if(!f.exists() || md5 != md5_2)
2022-11-10 09:23:16 +00:00
{
Dialog_updateProgress dlg(m_versionMgr, url, savePath, this);
if (dlg.exec())
{
QFile saveFile(savePath);
saveFile.open(QFile::ReadOnly);
QByteArray fileMsg = saveFile.readAll();
saveFile.close();
QString md5_2 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
if (md5 == md5_2)
{
Dialog_upgradeFirmware dlg(m_curDevHandle, savePath, this);
dlg.exec();
if (0 == dlg.getUpgradeStatus())
{
ui->labelDevInfo->setText(QString(tr("device: %1 upgrade firmware success")).arg(m_curDevName));
}
else
{
ui->labelDevInfo->setText(QString(tr("device: %1 upgrade firmware failed, io error")).arg(m_curDevName));
}
}
else
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("download firmware fail"), QMessageBox::Ok, this);
msg.exec();
}
}
2022-11-10 09:23:16 +00:00
}
else
2022-11-10 09:23:16 +00:00
{
Dialog_upgradeFirmware dlg(m_curDevHandle, savePath, this);
dlg.exec();
if (0 == dlg.getUpgradeStatus())
{
ui->labelDevInfo->setText(QString(tr("device: %1 upgrade firmware success")).arg(m_curDevName));
}
else
{
ui->labelDevInfo->setText(QString(tr("device: %1 upgrade firmware failed, io error")).arg(m_curDevName));
}
2022-11-10 09:23:16 +00:00
}
HGBase_DeleteFile(savePath);
2022-11-10 09:23:16 +00:00
}
}
void MainWindow::on_btnUpgrade_clicked()
{
std::string filePath = Utf8ToStdString(ui->editFilePath->text().toStdString());
2022-11-10 09:23:16 +00:00
if (!filePath.empty())
{
Dialog_upgradeFirmware dlg(m_curDevHandle, filePath, this);
dlg.exec();
if (0 == dlg.getUpgradeStatus())
{
2022-11-11 03:56:19 +00:00
ui->labelDevInfo->setText(QString(tr("device: %1 upgrade firmware success")).arg(m_curDevName));
2022-11-10 09:23:16 +00:00
}
else
2022-11-10 09:23:16 +00:00
{
2022-11-11 03:56:19 +00:00
ui->labelDevInfo->setText(QString(tr("device: %1 upgrade firmware failed, io error")).arg(m_curDevName));
2022-11-10 09:23:16 +00:00
}
}
}
void MainWindow::on_comboDevList2_currentIndexChanged(int index)
{
ui->comboDevList->setCurrentIndex(index);
}
void MainWindow::on_btnClearRollCount_clicked()
{
unsigned int count = 0;
2022-12-14 01:25:16 +00:00
int ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT, nullptr, &count);
2022-11-10 09:23:16 +00:00
QString info;
if (ret == SANE_STATUS_GOOD)
{
2023-06-27 13:04:39 +00:00
ui->label_rollerCout->setText(QString(tr("roll count: %1")).arg(QString::number(0)));
2022-11-10 09:23:16 +00:00
info = tr("Roller scanned count has been set to 0.");
}
else if (ret == SANE_STATUS_UNSUPPORTED)
{
info = tr("Do not supported");
}
2022-11-10 09:23:16 +00:00
else
info = tr("Roller scanned count reset failed.");
QMessageBox msg(QMessageBox::Information, tr("tips"), info, QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
}
void MainWindow::on_btnModifyPassword_clicked()
{
HGChar cfgPath[256]= {0};
2023-06-15 07:29:35 +00:00
GetConfigPath(cfgPath, 256);
2022-11-24 09:02:26 +00:00
HGBase_CreateDir(cfgPath);
2022-11-10 09:23:16 +00:00
strcat(cfgPath, "config.ini");
HGChar str[256] = {0};
HGBase_GetProfileString(cfgPath, "login", "password", "", str, 256);
2023-06-15 07:29:35 +00:00
QString password = (0 == *str) ? "huagoscan" : MainWindow::passwordDecrypt(str);
2022-11-10 09:23:16 +00:00
if (password != ui->editOldPassword->text())
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("old password is wrong"), QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
return;
}
if (ui->editNewPassword->text().isEmpty())
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("new password can not be empty"), QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
return;
}
if (ui->editNewPassword->text() != ui->editNewPassword_2->text())
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("new password is inconsistent"), QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
return;
}
if (HGBASE_ERR_OK != HGBase_SetProfileString(cfgPath, "login", "password", passwordEncrypt(ui->editNewPassword->text()).toStdString().c_str()))
{
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("modify password fail"), QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
return;
}
ui->editOldPassword->setText("");
ui->editNewPassword->setText("");
ui->editNewPassword_2->setText("");
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("modify password success"), QMessageBox::Ok, this);
2022-11-10 09:23:16 +00:00
msg.exec();
}
void MainWindow::on_pushButton_getDistortion_clicked()
{
2023-06-16 09:37:44 +00:00
ui->lineEdit_getDistortion->clear();
initColorAndDpi();
float distortion = 1.0;
unsigned int len = sizeof(SANE_Bool);
2023-06-16 09:37:44 +00:00
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_DISTORTION_DEVS_CHECK_VAL, &distortion, &len);
2023-06-27 13:04:39 +00:00
if (ret == SANE_STATUS_GOOD)
{
}
else if (ret == SANE_STATUS_UNSUPPORTED)
{
addContent(ui->textBrowser_disCorrect, tr("do not support"), false);
QMessageBox::information(this, tr("Prompt"), tr("do not support"));
return;
}
else
2023-06-16 09:37:44 +00:00
{
addContent(ui->textBrowser_disCorrect, tr("Get distortion failed"), false);
QMessageBox::information(this, tr("Prompt"), tr("Get failed"));
return;
}
2023-06-27 13:04:39 +00:00
2023-06-16 09:37:44 +00:00
QString value(QString::number(distortion, 'f', 4));
addContent(ui->textBrowser_disCorrect, tr("Get distortion succeed: %1").arg(value), true);
ui->lineEdit_getDistortion->setText(value);
}
void MainWindow::on_pushButton_setDistortion_clicked()
{
2023-06-16 09:37:44 +00:00
QString value = ui->lineEdit_getDistortion->text();
if (value.isEmpty())
return;
initColorAndDpi();
float distortion = value.toFloat();
unsigned int len = sizeof(int);
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_DISTORTION_DEVS_CHECK_VAL, &distortion, &len);
2023-06-27 13:04:39 +00:00
if (ret == SANE_STATUS_GOOD)
{
2023-06-27 13:04:39 +00:00
addContent(ui->textBrowser_disCorrect, tr("Set succeed"), true);
}
else if (ret == SANE_STATUS_UNSUPPORTED)
{
addContent(ui->textBrowser_disCorrect, tr("do not support"), false);
QMessageBox::information(this, tr("Prompt"), tr("do not support"));
return;
}
else
{
2023-06-27 13:04:39 +00:00
addContent(ui->textBrowser_disCorrect, tr("Set failed").arg(value), true);
QMessageBox::information(this, tr("Prompt"), tr("Set failed"));
return;
}
}
void MainWindow::on_pushButton_correct_clicked()
{
QMessageBox msg(QMessageBox::Information, tr("Prompt"), tr("Please confirm that the device has correctly placed the calibration paper!"),
QMessageBox::Yes | QMessageBox::No, this);
msg.exec();
if (msg.clickedButton() != msg.button(QMessageBox::Yes))
{
return;
}
ui->textBrowser_flatcorrect->clear();
2023-06-16 09:37:44 +00:00
m_isFlatCorrecting = true;
ui->pushButton_correct->setEnabled(false);
int type = 0;
unsigned int len = sizeof(int);;
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_AUTO_FALT, (void*)&type, &len);
2023-06-27 13:04:39 +00:00
if (ret == SANE_STATUS_GOOD)
{
2023-06-27 13:04:39 +00:00
ui->label_correct->setText(tr("correcting..."));
}
else if (ret == SANE_STATUS_UNSUPPORTED)
{
QMessageBox::information(this, tr("Prompt"), tr("do not support"));
ui->label_correct->setText(tr("do not support"));
return;
}
else
{
2023-06-27 13:04:39 +00:00
QMessageBox::information(this, tr("Prompt"), tr("Correct failed"));
return;
}
2023-06-27 13:04:39 +00:00
}
void MainWindow::on_pushButton_exportTestPaper_clicked()
{
QString srcFileName = QString(":images/image_rsc/distortion/testPaper.jpg");
QString fileName = QFileDialog::getSaveFileName(this, tr("Export special test paper"), ".", tr("jpg(*.jpg)"));
QFile::copy(srcFileName, fileName);
}
2023-06-16 09:37:44 +00:00
void MainWindow::on_pushButton_countDistortion_clicked()
{
m_isDisCorrecting = true;
addContent(ui->textBrowser_disCorrect, tr("Color mode: %1, Dpi: %2").arg(ui->comboBox_colorMode->currentText())
.arg(ui->comboBox_dpi->currentText()), true);
ui->lineEdit_countDistortion->clear();
SANE_Bool type = true;
unsigned int len = sizeof(SANE_Bool);
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_DISTORTION_IMAGE, &type, &len);
}