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>
|
2023-06-16 06:00:50 +00:00
|
|
|
#include <QMessageBox>
|
2022-11-11 06:55:30 +00:00
|
|
|
#include <QCryptographicHash>
|
2022-11-10 09:23:16 +00:00
|
|
|
#include "dialog_upgradefirmware.h"
|
2022-11-11 06:55:30 +00:00
|
|
|
#include "dialog_updateprogress.h"
|
2022-11-10 09:23:16 +00:00
|
|
|
#include "base/HGBase.h"
|
2023-02-17 04:03:40 +00:00
|
|
|
#include "base/HGInc.h"
|
2023-06-15 02:58:30 +00:00
|
|
|
#include "huagao/hgscanner_error.h"
|
2023-06-12 09:11:25 +00:00
|
|
|
#include "sane/sane_option_definitions.h"
|
2022-11-29 10:24:01 +00:00
|
|
|
#include "HGString.h"
|
2022-12-02 10:32:48 +00:00
|
|
|
#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
|
|
|
|
2024-04-07 09:44:48 +00:00
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Hanvon_logo1.ico"));
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Lanxum_logo.ico"));
|
|
|
|
#elif defined(OEM_CANGTIAN)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Cumtenn_logo.ico"));
|
|
|
|
#elif defined(OEM_ZHONGJING)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/Microtek_logo.ico"));
|
|
|
|
#elif defined(OEM_ZIGUANG)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/uniscan.ico"));
|
|
|
|
#elif defined(OEM_NEUTRAL)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/NoBrand_logo.ico"));
|
|
|
|
#elif defined(OEM_DELI)
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/deli.ico"));
|
|
|
|
#else
|
|
|
|
this->setWindowIcon(QIcon(":images/image_rsc/logo/logo.ico"));
|
|
|
|
#endif
|
|
|
|
|
2022-11-10 09:23:16 +00:00
|
|
|
m_curDevName.clear();
|
|
|
|
m_curDevHandle = nullptr;
|
|
|
|
m_curFwVersion.clear();
|
2023-06-12 09:11:25 +00:00
|
|
|
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);
|
|
|
|
|
2023-06-29 08:54:47 +00:00
|
|
|
ui->comboBox_colorMode->setEnabled(false);
|
|
|
|
ui->comboBox_dpi->setEnabled(false);
|
|
|
|
ui->pushButton_getDistortion->setEnabled(false);
|
|
|
|
ui->pushButton_setDistortion->setEnabled(false);
|
|
|
|
ui->lineEdit_getDistortion->setEnabled(false);
|
|
|
|
ui->pushButton_countDistortion->setEnabled(false);
|
|
|
|
ui->lineEdit_countDistortion->setEnabled(false);
|
|
|
|
ui->pushButton_correct->setEnabled(false);
|
|
|
|
ui->checkBox_colorCorrect->setEnabled(false);
|
|
|
|
|
2023-06-16 06:00:50 +00:00
|
|
|
addContent(ui->textBrowser_flatcorrect, tr("Please confirm that the device has correctly placed the calibration paper!"), false);
|
2023-06-29 08:54:47 +00:00
|
|
|
addContent(ui->textBrowser_flatcorrect, tr("Prompt of Hualing device"), false);
|
2023-06-16 06:00:50 +00:00
|
|
|
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);
|
2023-06-12 09:11:25 +00:00
|
|
|
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();
|
|
|
|
|
2022-11-11 07:52:54 +00:00
|
|
|
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";
|
2024-04-07 09:44:48 +00:00
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
appName = "HanvonScan";
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
appName = "LanxumScan";
|
|
|
|
#elif defined(OEM_CANGTIAN)
|
|
|
|
appName = "CumtennScan";
|
|
|
|
#elif defined(OEM_ZHONGJING)
|
|
|
|
appName = "MicrotekScan";
|
|
|
|
#elif defined(OEM_ZIGUANG)
|
|
|
|
appName = "UniScan";
|
|
|
|
#elif defined(OEM_DELI)
|
|
|
|
appName = "DeliScan";
|
|
|
|
#elif defined(OEM_NEUTRAL)
|
|
|
|
appName = "NeuScan";
|
|
|
|
#endif
|
|
|
|
|
2023-06-15 07:29:35 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2022-12-03 08:58:16 +00:00
|
|
|
QString MainWindow::GetDevType(const QString& fwVersion, bool *canLock)
|
2022-11-11 06:55:30 +00:00
|
|
|
{
|
2022-12-03 08:58:16 +00:00
|
|
|
if (NULL != canLock)
|
|
|
|
*canLock = false;
|
|
|
|
|
2022-11-11 06:55:30 +00:00
|
|
|
QString devType;
|
|
|
|
if (fwVersion.length() == 10)
|
|
|
|
{
|
|
|
|
QString dev = fwVersion.left(2);
|
|
|
|
if (fwVersion.mid(2, 2) == "40" || fwVersion.mid(2, 2) == "50"
|
2023-09-06 10:20:09 +00:00
|
|
|
|| fwVersion.mid(2, 2) == "60" || fwVersion.mid(2, 2) == "70"
|
|
|
|
|| fwVersion.mid(2, 2) == "80" || fwVersion.mid(2, 2) == "90")
|
2022-11-11 06:55:30 +00:00
|
|
|
{
|
|
|
|
// 3288
|
2023-09-06 10:20:09 +00:00
|
|
|
QString ppm = fwVersion.mid(2, 2);
|
2022-11-11 06:55:30 +00:00
|
|
|
QString date = fwVersion.mid(4, 6);
|
2023-09-06 10:20:09 +00:00
|
|
|
|
|
|
|
if (dev == "G3")
|
|
|
|
{
|
|
|
|
if (date >= "220424" && date <= "230105")
|
|
|
|
{
|
|
|
|
devType = dev + "x0" + "/" + "220424-230105";
|
|
|
|
}
|
|
|
|
else if (date >= "230106" && date <= "230305")
|
|
|
|
{
|
|
|
|
devType = dev + "x0" + "/" + "230106-230305";
|
|
|
|
}
|
|
|
|
else if (date >= "230306")
|
|
|
|
{
|
|
|
|
devType = dev + "x0" + "/" + "230306-";
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 3399
|
|
|
|
QString ver = fwVersion.mid(2, 3);
|
|
|
|
QString date = fwVersion.mid(5, 5);
|
|
|
|
if ((dev == "G1" || dev == "G2") && ver == "393")
|
|
|
|
{
|
2022-12-03 08:58:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
else if (date >= "B0429")
|
2022-12-03 08:58:16 +00:00
|
|
|
{
|
2022-11-11 06:55:30 +00:00
|
|
|
devType = dev + ver + "/" + "B0429-";
|
2022-12-05 06:38:25 +00:00
|
|
|
if (date >= "B1031" || date == "B0500")
|
2022-12-03 08:58:16 +00:00
|
|
|
{
|
|
|
|
if (NULL != canLock)
|
|
|
|
*canLock = true;
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
}
|
|
|
|
else if (dev == "G4" && ver == "393")
|
|
|
|
{
|
|
|
|
devType = dev + ver + "/";
|
2022-12-03 08:58:16 +00:00
|
|
|
if (date >= "B1108")
|
|
|
|
{
|
|
|
|
if (NULL != canLock)
|
|
|
|
*canLock = true;
|
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2022-11-11 06:55:30 +00:00
|
|
|
assert(!opened);
|
2022-11-10 09:23:16 +00:00
|
|
|
ui->comboDevList->addItem(devName);
|
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-12 09:11:25 +00:00
|
|
|
void MainWindow::on_correctInfo(QString info)
|
|
|
|
{
|
2023-06-16 06:00:50 +00:00
|
|
|
addContent(ui->textBrowser_flatcorrect, info, true);
|
|
|
|
}
|
|
|
|
|
2023-06-16 09:37:44 +00:00
|
|
|
void MainWindow::on_scan_finish(void *data)
|
2023-06-16 06:00:50 +00:00
|
|
|
{
|
2023-06-16 09:37:44 +00:00
|
|
|
if (0 == strcmp((char*)data, STATU_DESC_SCAN_STOPPED))
|
2023-06-16 06:00:50 +00:00
|
|
|
{
|
|
|
|
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 06:00:50 +00:00
|
|
|
{
|
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;
|
2023-06-16 06:00:50 +00:00
|
|
|
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 06:00:50 +00:00
|
|
|
}
|
2023-06-16 09:37:44 +00:00
|
|
|
|
|
|
|
m_isDisCorrecting = false;
|
|
|
|
m_isFlatCorrecting = false;
|
|
|
|
ui->pushButton_correct->setEnabled(true);
|
2023-06-29 08:54:47 +00:00
|
|
|
ui->checkBox_colorCorrect->setEnabled(true);
|
2023-06-12 09:11:25 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2023-06-12 09:11:25 +00:00
|
|
|
case SANE_EVENT_STATUS:
|
|
|
|
{
|
|
|
|
QString info;
|
|
|
|
if (data != nullptr)
|
|
|
|
{
|
|
|
|
info = QString::fromStdString((const char*)data);
|
|
|
|
emit p->correctInfo(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2023-06-16 06:00:50 +00:00
|
|
|
case SANE_EVENT_SCAN_FINISHED:
|
|
|
|
QString info;
|
|
|
|
if (data != nullptr)
|
|
|
|
{
|
2023-06-16 09:37:44 +00:00
|
|
|
emit p->scan_finish(data);
|
2023-06-16 06:00:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-12 09:11:25 +00:00
|
|
|
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
|
|
|
{
|
2023-06-12 09:11:25 +00:00
|
|
|
QString devType = m_curFwVersion.left(2) + "00";
|
2022-11-10 09:23:16 +00:00
|
|
|
|
2023-06-12 09:11:25 +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];
|
|
|
|
}
|
|
|
|
|
2023-06-16 06:00:50 +00:00
|
|
|
if (0 == speed)
|
|
|
|
return(QString(tr("do not support")));
|
|
|
|
|
2023-06-12 09:11:25 +00:00
|
|
|
return QString::number(speed) + "PPM";
|
|
|
|
}
|
|
|
|
|
2023-06-16 06:00:50 +00:00
|
|
|
void MainWindow::addContent(QTextBrowser *textBrowser, QString content, bool isNormal)
|
|
|
|
{
|
2023-06-16 09:37:44 +00:00
|
|
|
textBrowser->moveCursor(QTextCursor::End);
|
|
|
|
|
2023-06-16 06:00:50 +00:00
|
|
|
if (isNormal)
|
|
|
|
textBrowser->insertPlainText(content);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textBrowser->setTextColor(Qt::red);
|
|
|
|
textBrowser->insertPlainText(content);
|
2023-06-29 08:54:47 +00:00
|
|
|
textBrowser->insertPlainText("\n");
|
2023-06-16 06:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
textBrowser->setTextColor(Qt::black);
|
|
|
|
textBrowser->insertPlainText("\n");
|
|
|
|
}
|
|
|
|
|
2023-06-29 01:47:19 +00:00
|
|
|
bool MainWindow::isAndroidDevice()
|
|
|
|
{
|
|
|
|
VIDPID vidpid;
|
|
|
|
int vidpid_val;
|
|
|
|
unsigned int len = sizeof(int);
|
|
|
|
sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_VIDPID, &vidpid_val, &len);
|
|
|
|
vidpid.Value = vidpid_val;
|
|
|
|
int pid = vidpid.PID;
|
|
|
|
|
|
|
|
if (pid != 0)
|
|
|
|
{
|
|
|
|
char buf[10];
|
|
|
|
sprintf(buf, "%x", pid);
|
|
|
|
if (strcmp(buf,"302") == 0 || strcmp(buf, "402") == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-12 09:11:25 +00:00
|
|
|
void MainWindow::on_comboDevList_currentIndexChanged(int index)
|
|
|
|
{
|
2022-11-11 07:52:54 +00:00
|
|
|
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)));
|
2023-06-15 02:58:30 +00:00
|
|
|
ui->label_deviceError->clear();
|
|
|
|
ui->labelDevInfo->clear();
|
2023-06-28 11:11:22 +00:00
|
|
|
ui->label_correct->setText(tr("Have not corrected"));
|
2022-11-10 09:23:16 +00:00
|
|
|
|
|
|
|
if (nullptr != m_curDevHandle)
|
|
|
|
{
|
|
|
|
sane_close(m_curDevHandle);
|
|
|
|
m_curDevHandle = nullptr;
|
|
|
|
}
|
|
|
|
m_curFwVersion.clear();
|
2023-06-12 09:11:25 +00:00
|
|
|
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);
|
|
|
|
|
2023-06-15 02:58:30 +00:00
|
|
|
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);
|
2023-06-15 02:58:30 +00:00
|
|
|
ui->pushButton_correct->setEnabled(false);
|
2023-06-29 08:54:47 +00:00
|
|
|
ui->checkBox_colorCorrect->setEnabled(false);
|
2023-06-29 01:47:19 +00:00
|
|
|
ui->pushButton_countDistortion->setEnabled(false);
|
|
|
|
ui->lineEdit_countDistortion->setEnabled(false);
|
2023-06-15 02:58:30 +00:00
|
|
|
|
2022-11-10 09:23:16 +00:00
|
|
|
if (-1 != index)
|
|
|
|
{
|
|
|
|
QString name = ui->comboDevList->itemText(index);
|
2023-06-15 02:58:30 +00:00
|
|
|
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;
|
|
|
|
|
2023-06-12 09:11:25 +00:00
|
|
|
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
|
|
|
{
|
2023-06-12 09:11:25 +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
|
|
|
}
|
|
|
|
|
2023-06-12 09:11:25 +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());
|
2022-12-03 08:58:16 +00:00
|
|
|
QString devType = GetDevType(m_curFwVersion, NULL);
|
2022-11-11 06:55:30 +00:00
|
|
|
|
2023-06-15 02:58:30 +00:00
|
|
|
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"))));
|
2023-06-12 09:11:25 +00:00
|
|
|
ui->label_speedMode->setText(QString(tr("speed mode: %1").arg(getSpeedMode())));
|
2022-11-10 09:23:16 +00:00
|
|
|
|
2022-11-11 10:21:02 +00:00
|
|
|
SANE_Int rollCount = 0;
|
|
|
|
unsigned int rollCountSize = sizeof(SANE_Int);
|
2022-12-29 13:27:24 +00:00
|
|
|
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_ROLLER_NUM, &rollCount, &rollCountSize);
|
2022-11-11 10:21:02 +00:00
|
|
|
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-10-27 01:16:40 +00:00
|
|
|
ui->label_rollerCout->setText(QString(tr("roll count: %1")).arg(tr("do not support")));
|
2022-11-11 10:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SANE_Int scanCount = 0;
|
|
|
|
unsigned int scanCountSize = sizeof(SANE_Int);
|
2022-12-29 13:27:24 +00:00
|
|
|
ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_HISTORY_SCAN_NUM, &scanCount, &scanCountSize);
|
2022-11-11 10:21:02 +00:00
|
|
|
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));
|
2022-11-11 10:21:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-27 01:16:40 +00:00
|
|
|
ui->label_scanCount->setText(QString(tr("scan count: %1")).arg(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")));
|
|
|
|
|
2022-11-11 06:55:30 +00:00
|
|
|
if (!devType.isEmpty())
|
|
|
|
{
|
|
|
|
ui->btnGetVersionList->setEnabled(true);
|
|
|
|
}
|
2023-09-07 01:15:08 +00:00
|
|
|
ui->btnOpenFilePath->setEnabled(true);
|
2022-11-10 09:23:16 +00:00
|
|
|
ui->btnClearRollCount->setEnabled(true);
|
2023-06-15 02:58:30 +00:00
|
|
|
|
2023-06-29 01:47:19 +00:00
|
|
|
bool isAndroid = isAndroidDevice();
|
|
|
|
ui->comboBox_colorMode->setEnabled(!isAndroid);
|
|
|
|
ui->comboBox_dpi->setEnabled(!isAndroid);
|
|
|
|
ui->pushButton_getDistortion->setEnabled(!isAndroid);
|
|
|
|
ui->pushButton_setDistortion->setEnabled(!isAndroid);
|
|
|
|
ui->lineEdit_getDistortion->setEnabled(!isAndroid);
|
|
|
|
ui->pushButton_correct->setEnabled(!isAndroid);
|
2023-06-29 08:54:47 +00:00
|
|
|
ui->checkBox_colorCorrect->setEnabled(!isAndroid);
|
2023-06-29 01:47:19 +00:00
|
|
|
ui->pushButton_countDistortion->setEnabled(!isAndroid);
|
|
|
|
ui->lineEdit_countDistortion->setEnabled(!isAndroid);
|
2023-06-15 02:58:30 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2023-06-15 02:58:30 +00:00
|
|
|
ui->label_deviceError->setText(QString(tr("open device error")));
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-15 02:58:30 +00:00
|
|
|
ui->label_deviceError->setText(tr("no device opened"));
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 10:32:48 +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()
|
|
|
|
{
|
2022-11-11 07:52:54 +00:00
|
|
|
m_vVersion.clear();
|
2022-11-10 09:23:16 +00:00
|
|
|
ui->comboVersionList->clear();
|
|
|
|
|
2022-12-03 08:58:16 +00:00
|
|
|
QString devType = GetDevType(m_curFwVersion, NULL);
|
2022-11-11 06:55:30 +00:00
|
|
|
assert(!devType.isEmpty());
|
|
|
|
|
2022-11-11 07:52:54 +00:00
|
|
|
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
|
|
|
{
|
2022-11-11 07:52:54 +00:00
|
|
|
for (HGUInt i = 0; i < versionCount; ++i)
|
2022-11-10 09:23:16 +00:00
|
|
|
{
|
2022-11-11 07:52:54 +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
|
|
|
}
|
|
|
|
}
|
2022-11-11 08:39:46 +00:00
|
|
|
|
|
|
|
HGVersion_ReleaseVersionList(versionInfo, versionCount);
|
|
|
|
|
2022-12-02 10:32:48 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2022-11-11 08:39:46 +00:00
|
|
|
if (m_vVersion.empty())
|
2022-11-10 09:23:16 +00:00
|
|
|
{
|
2023-02-16 07:17:41 +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()
|
|
|
|
{
|
2022-11-11 06:55:30 +00:00
|
|
|
QString filePath = QFileDialog::getOpenFileName(this, tr("Open File"), ".", tr("ZIP Files(*.zip *.zip)"));
|
2022-11-10 09:23:16 +00:00
|
|
|
if (!filePath.isEmpty())
|
|
|
|
{
|
2022-12-03 08:58:16 +00:00
|
|
|
QString devType = GetDevType(m_curFwVersion, NULL);
|
2022-11-11 06:55:30 +00:00
|
|
|
assert(!devType.isEmpty());
|
|
|
|
|
|
|
|
HGChar fileName[256] = {0};
|
|
|
|
HGBase_GetFileName(filePath.toStdString().c_str(), fileName, 256);
|
|
|
|
HGChar fileVersion[256] = {0};
|
|
|
|
HGBase_GetFilePrefix(fileName, fileVersion, 256);
|
2023-11-08 08:36:26 +00:00
|
|
|
//if (devType == GetDevType(fileVersion, NULL))
|
|
|
|
if (1)
|
2022-11-11 06:55:30 +00:00
|
|
|
{
|
2023-11-08 08:36:26 +00:00
|
|
|
//if (m_curFwVersion >= fileVersion)
|
2023-11-08 10:02:53 +00:00
|
|
|
if (0)
|
2022-11-11 06:55:30 +00:00
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("the selected firmware is not newer than the current version"), QMessageBox::Ok, this);
|
2022-11-11 06:55:30 +00:00
|
|
|
msg.exec();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->editFilePath->setText(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-29 10:42:43 +00:00
|
|
|
QMessageBox msg(QMessageBox::Question, tr("tips"),
|
|
|
|
tr("firmware file mismatch, continue?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No, this);
|
2022-11-11 06:55:30 +00:00
|
|
|
msg.exec();
|
2022-11-29 10:42:43 +00:00
|
|
|
if (msg.clickedButton() == msg.button(QMessageBox::Yes))
|
|
|
|
{
|
|
|
|
ui->editFilePath->setText(filePath);
|
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
}
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_btnDownloadUpgrade_clicked()
|
|
|
|
{
|
|
|
|
int idx = ui->comboVersionList->currentIndex();
|
|
|
|
if (-1 != idx)
|
|
|
|
{
|
2022-11-11 07:52:54 +00:00
|
|
|
QString url = m_vVersion[idx].url.c_str();
|
|
|
|
QString md5 = m_vVersion[idx].md5.c_str();
|
|
|
|
QString versionNum = m_vVersion[idx].version.c_str();
|
2022-11-11 06:55:30 +00:00
|
|
|
|
|
|
|
if (m_curFwVersion >= versionNum)
|
2022-11-10 09:23:16 +00:00
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("the selected firmware is not newer than the current version"), QMessageBox::Ok, this);
|
2022-11-11 06:55:30 +00:00
|
|
|
msg.exec();
|
|
|
|
return;
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
|
|
|
|
assert(!url.isEmpty() && !md5.isEmpty() && !versionNum.isEmpty());
|
|
|
|
|
|
|
|
HGChar suffix[64];
|
|
|
|
HGBase_GetFileSuffix(url.toStdString().c_str(), suffix, 64);
|
|
|
|
|
|
|
|
HGChar savePath[512];
|
2022-11-29 07:09:06 +00:00
|
|
|
HGBase_GetTmpPath(savePath, 512);
|
2022-11-24 09:02:26 +00:00
|
|
|
HGBase_CreateDir(savePath);
|
2022-11-11 06:55:30 +00:00
|
|
|
HGChar fileName[128];
|
2022-11-29 07:09:06 +00:00
|
|
|
sprintf(fileName, "%s.%s", "{644759d6-7e4e-47c7-b42e-5105bb2de4a3}", suffix);
|
2022-11-11 06:55:30 +00:00
|
|
|
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
|
|
|
{
|
2022-11-11 06:55:30 +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();
|
2023-09-07 03:53:06 +00:00
|
|
|
int status = dlg.getUpgradeStatus();
|
|
|
|
if (0 == status)
|
2022-11-11 06:55:30 +00:00
|
|
|
{
|
2023-09-07 03:53:06 +00:00
|
|
|
QMessageBox::information(this, tr("Prompt"), QString(tr("device: %1 upgrade firmware success")).arg(m_curDevName));
|
2022-11-11 06:55:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-07 03:53:06 +00:00
|
|
|
QMessageBox::information(this, tr("Prompt"),
|
|
|
|
QString(tr("device: %1 upgrade firmware failed: %2")).arg(m_curDevName).arg(sane_strstatus((SANE_Status)status)));
|
2022-11-11 06:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("download firmware fail"), QMessageBox::Ok, this);
|
2022-11-11 06:55:30 +00:00
|
|
|
msg.exec();
|
|
|
|
}
|
|
|
|
}
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
else
|
2022-11-10 09:23:16 +00:00
|
|
|
{
|
2022-11-11 06:55:30 +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
|
|
|
}
|
2022-11-29 07:09:06 +00:00
|
|
|
|
|
|
|
HGBase_DeleteFile(savePath);
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_btnUpgrade_clicked()
|
|
|
|
{
|
2022-11-29 10:24:01 +00:00
|
|
|
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();
|
2023-09-07 03:53:06 +00:00
|
|
|
int status = dlg.getUpgradeStatus();
|
|
|
|
if (0 == status)
|
2022-11-10 09:23:16 +00:00
|
|
|
{
|
2023-09-07 03:53:06 +00:00
|
|
|
QMessageBox::information(this, tr("Prompt"), QString(tr("device: %1 upgrade firmware success")).arg(m_curDevName));
|
2022-11-10 09:23:16 +00:00
|
|
|
}
|
2022-11-11 06:55:30 +00:00
|
|
|
else
|
2022-11-10 09:23:16 +00:00
|
|
|
{
|
2023-09-07 03:53:06 +00:00
|
|
|
QMessageBox::information(this, tr("Prompt"),
|
|
|
|
QString(tr("device: %1 upgrade firmware failed: %2")).arg(m_curDevName).arg(sane_strstatus((SANE_Status)status)));
|
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;
|
2022-11-11 10:21:02 +00:00
|
|
|
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.");
|
2022-11-11 10:21:02 +00:00
|
|
|
}
|
2023-06-12 09:11:25 +00:00
|
|
|
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.");
|
|
|
|
|
2023-02-16 07:17:41 +00:00
|
|
|
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())
|
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
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())
|
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
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())
|
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
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()))
|
|
|
|
{
|
2023-02-16 07:17:41 +00:00
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("modify password fail"), QMessageBox::Ok, this);
|
2022-11-10 09:23:16 +00:00
|
|
|
msg.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-11 06:55:30 +00:00
|
|
|
ui->editOldPassword->setText("");
|
|
|
|
ui->editNewPassword->setText("");
|
|
|
|
ui->editNewPassword_2->setText("");
|
|
|
|
|
2023-02-16 07:17:41 +00:00
|
|
|
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("modify password success"), QMessageBox::Ok, this);
|
2022-11-10 09:23:16 +00:00
|
|
|
msg.exec();
|
|
|
|
}
|
2023-06-12 09:11:25 +00:00
|
|
|
|
|
|
|
void MainWindow::on_pushButton_getDistortion_clicked()
|
|
|
|
{
|
2023-06-16 09:37:44 +00:00
|
|
|
ui->lineEdit_getDistortion->clear();
|
2023-06-12 09:11:25 +00:00
|
|
|
initColorAndDpi();
|
|
|
|
|
2023-06-16 06:00:50 +00:00
|
|
|
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);
|
2023-06-12 09:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_setDistortion_clicked()
|
|
|
|
{
|
2023-06-16 09:37:44 +00:00
|
|
|
QString value = ui->lineEdit_getDistortion->text();
|
|
|
|
if (value.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2023-06-12 09:11:25 +00:00
|
|
|
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-12 09:11:25 +00:00
|
|
|
{
|
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"));
|
2023-06-12 09:11:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-06-16 06:00:50 +00:00
|
|
|
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;
|
2023-06-16 06:00:50 +00:00
|
|
|
}
|
2023-06-12 09:11:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_correct_clicked()
|
|
|
|
{
|
2023-06-16 06:00:50 +00:00
|
|
|
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);
|
2023-06-29 08:54:47 +00:00
|
|
|
ui->checkBox_colorCorrect->setEnabled(false);
|
2023-06-12 09:11:25 +00:00
|
|
|
|
2023-06-29 08:54:47 +00:00
|
|
|
int type = ui->checkBox_colorCorrect->isChecked() ? 1 : 0;
|
2023-06-12 09:11:25 +00:00
|
|
|
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-12 09:11:25 +00:00
|
|
|
{
|
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"));
|
2023-06-28 11:11:22 +00:00
|
|
|
m_isFlatCorrecting = false;
|
2023-06-12 09:11:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-27 13:04:39 +00:00
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("Correct failed"));
|
2023-06-28 11:11:22 +00:00
|
|
|
m_isFlatCorrecting = false;
|
2023-06-27 13:04:39 +00:00
|
|
|
return;
|
2023-06-12 09:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-16 06:00:50 +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;
|
2023-06-28 11:11:22 +00:00
|
|
|
float distortion = 1.0;
|
2023-06-16 09:37:44 +00:00
|
|
|
unsigned int len = sizeof(SANE_Bool);
|
2023-06-28 11:11:22 +00:00
|
|
|
|
|
|
|
initColorAndDpi();
|
|
|
|
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_DISTORTION_DEVS_CHECK_VAL, &distortion, &len);
|
|
|
|
ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_DISTORTION_IMAGE, &type, &len);
|
2023-06-16 09:37:44 +00:00
|
|
|
}
|
2023-10-27 01:16:40 +00:00
|
|
|
|
|
|
|
void MainWindow::on_pushButton_restoreSettings_clicked()
|
|
|
|
{
|
|
|
|
int data = 0;
|
|
|
|
unsigned int len = 0;
|
|
|
|
SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_RESTORE, &data, &len);
|
|
|
|
if (SANE_STATUS_GOOD == ret)
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("Restore succeed"));
|
|
|
|
}
|
|
|
|
else if (ret == SANE_STATUS_UNSUPPORTED)
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("do not support"));
|
|
|
|
}
|
|
|
|
else if (ret == SANE_STATUS_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("Restore failed"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("Prompt"), tr("Other error:%1").arg(QString::number(ret)));
|
|
|
|
}
|
|
|
|
}
|