#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include #include "dialog_upgradefirmware.h" #include "dialog_updateprogress.h" #include "base/HGBase.h" #include "base/HGInc.h" #include "huagao/hgscanner_error.h" #include "sane/sane_option_definitions.h" #include "HGString.h" #include #if defined(HG_CMP_MSC) #include #else #include #include #include #include #endif #define PASSWORD_KEY 4 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_isFlatCorrecting(false) , m_isDisCorrecting(false) { ui->setupUi(this); m_curDevName.clear(); m_curDevHandle = nullptr; m_curFwVersion.clear(); m_curSerialNum.clear(); 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); 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); connect(this, SIGNAL(scan_finish(void*)), this, SLOT(on_scan_finish(void*)), Qt::QueuedConnection); m_versionMgr = nullptr; HGVersion_CreateMgr(&m_versionMgr); SANE_Int v = 0; sane_init_ex(&v, sane_ex_callback, this); } MainWindow::~MainWindow() { if (nullptr != m_curDevHandle) { sane_close(m_curDevHandle); m_curDevHandle = nullptr; } m_curFwVersion.clear(); m_curDevName.clear(); sane_exit(); m_vVersion.clear(); HGVersion_DestroyMgr(m_versionMgr); m_versionMgr = nullptr; delete ui; } 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; } 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; } 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; } } 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); ui->comboDevList->addItem(devName); } else if (opened) { ui->comboDevList->setCurrentIndex(-1); ui->comboDevList->setCurrentIndex(idx); } } 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); } void MainWindow::on_scan_finish(void *data) { 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); if (ret != SANE_STATUS_GOOD || (dis.w < 0 && dis.w > 9999) || (dis.h < 0 && dis.h > 9999) || dis.scaleXY < 0) { 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)); 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)); } m_isDisCorrecting = false; m_isFlatCorrecting = false; ui->pushButton_correct->setEnabled(true); } 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) { emit p->scan_finish(data); } break; } 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() { QString devType = m_curFwVersion.left(2) + "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) { textBrowser->moveCursor(QTextCursor::End); if (isNormal) textBrowser->insertPlainText(content); else { textBrowser->setTextColor(Qt::red); textBrowser->insertPlainText(content); } textBrowser->setTextColor(Qt::black); textBrowser->insertPlainText("\n"); } 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; } void MainWindow::on_comboDevList_currentIndexChanged(int index) { m_vVersion.clear(); ui->comboVersionList->clear(); ui->editFilePath->clear(); 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(); ui->label_correct->setText(tr("Have not corrected")); if (nullptr != m_curDevHandle) { sane_close(m_curDevHandle); m_curDevHandle = nullptr; } m_curFwVersion.clear(); m_curSerialNum.clear(); 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); ui->lineEdit_getDistortion->setEnabled(false); ui->pushButton_correct->setEnabled(false); ui->pushButton_countDistortion->setEnabled(false); ui->lineEdit_countDistortion->setEnabled(false); 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) { 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) { fwVersionNum.resize(fwVersionNumLen); sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_HARDWARE_VERSION, &fwVersionNum[0], &fwVersionNumLen); } 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"))); 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()))); 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) { ui->label_rollerCout->setText(QString(tr("roll count: %1")).arg(rollCount)); } else { 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) { ui->label_scanCount->setText(QString(tr("scan count: %1")).arg(scanCount)); } else { ui->label_scanCount->setText(tr("do not support")); } 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); } ui->btnClearRollCount->setEnabled(true); 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); ui->pushButton_countDistortion->setEnabled(!isAndroid); ui->lineEdit_countDistortion->setEnabled(!isAndroid); } else if (SCANNER_ERR_OPENED_BY_OTHER_PROCESS == ret) { ui->label_deviceError->setText(QString(tr("Device is opened by other process"))); } else { ui->label_deviceError->setText(QString(tr("open device error"))); } } else { ui->label_deviceError->setText(tr("no device opened")); } } static bool Greater(const VersionInfo &info1, const VersionInfo &info2) { return info1.version > info2.version; } void MainWindow::on_btnGetVersionList_clicked() { m_vVersion.clear(); 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) { for (HGUInt i = 0; i < versionCount; ++i) { 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); } } } 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()) { QMessageBox msg(QMessageBox::Information, tr("tips"), tr("no version available"), QMessageBox::Ok, this); 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)")); 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); } } } } 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) { QMessageBox msg(QMessageBox::Information, tr("tips"), tr("the selected firmware is not newer than the current version"), QMessageBox::Ok, this); msg.exec(); return; } 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); 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) { 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(); } } } else { 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)); } } HGBase_DeleteFile(savePath); } } void MainWindow::on_btnUpgrade_clicked() { std::string filePath = Utf8ToStdString(ui->editFilePath->text().toStdString()); if (!filePath.empty()) { Dialog_upgradeFirmware dlg(m_curDevHandle, filePath, 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)); } } } void MainWindow::on_comboDevList2_currentIndexChanged(int index) { ui->comboDevList->setCurrentIndex(index); } void MainWindow::on_btnClearRollCount_clicked() { unsigned int count = 0; int ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT, nullptr, &count); QString info; if (ret == SANE_STATUS_GOOD) { ui->label_rollerCout->setText(QString(tr("roll count: %1")).arg(QString::number(0))); info = tr("Roller scanned count has been set to 0."); } else if (ret == SANE_STATUS_UNSUPPORTED) { info = tr("Do not supported"); } else info = tr("Roller scanned count reset failed."); QMessageBox msg(QMessageBox::Information, tr("tips"), info, QMessageBox::Ok, this); msg.exec(); } void MainWindow::on_btnModifyPassword_clicked() { HGChar cfgPath[256]= {0}; GetConfigPath(cfgPath, 256); HGBase_CreateDir(cfgPath); strcat(cfgPath, "config.ini"); HGChar str[256] = {0}; HGBase_GetProfileString(cfgPath, "login", "password", "", str, 256); QString password = (0 == *str) ? "huagoscan" : MainWindow::passwordDecrypt(str); if (password != ui->editOldPassword->text()) { QMessageBox msg(QMessageBox::Information, tr("tips"), tr("old password is wrong"), QMessageBox::Ok, this); msg.exec(); return; } if (ui->editNewPassword->text().isEmpty()) { QMessageBox msg(QMessageBox::Information, tr("tips"), tr("new password can not be empty"), QMessageBox::Ok, this); 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); 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); 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); msg.exec(); } void MainWindow::on_pushButton_getDistortion_clicked() { ui->lineEdit_getDistortion->clear(); initColorAndDpi(); float distortion = 1.0; unsigned int len = sizeof(SANE_Bool); SANE_Status ret = sane_io_control(m_curDevHandle, IO_CTRL_CODE_GET_DISTORTION_DEVS_CHECK_VAL, &distortion, &len); 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 { addContent(ui->textBrowser_disCorrect, tr("Get distortion failed"), false); QMessageBox::information(this, tr("Prompt"), tr("Get failed")); return; } 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() { 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); if (ret == SANE_STATUS_GOOD) { 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 { 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(); 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); if (ret == SANE_STATUS_GOOD) { 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")); m_isFlatCorrecting = false; return; } else { QMessageBox::information(this, tr("Prompt"), tr("Correct failed")); m_isFlatCorrecting = false; return; } } 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); } 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; float distortion = 1.0; unsigned int len = sizeof(SANE_Bool); 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); }