#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include #include #include #include #include "widget_statusbar.h" #include "dialog_log.h" #include "dialog_openimageindex.h" #include "dialog_saveas.h" #include "dialog_export.h" #include "dialog_exportimagefile.h" #include "dialog_imageinfo.h" #include "dialog_fullscreen.h" #include "dialog_imgproc_adjust.h" #include "dialog_multirotate.h" #include "dialog_multirotateimagefile.h" #include "dialog_imgproc_autocrop.h" #include "dialog_admin.h" #include "dialog_passwordchange.h" #include "dialog_insertindex.h" #include "dialog_aquireinto.h" #include "dialog_logmanager.h" #include "dialog_clrcache.h" #include "dialog_moveto.h" #include "dialog_imageeditor.h" #include "dialog_updateprogress.h" #include "dialog_upgrade.h" #include "dialog_feedback.h" #include "dialog_upgradefirmware.h" #include "hg_settingdialog.h" #include "base/HGInfo.h" #include "huagao/hgscanner_error.h" #include "imgfmt/HGPdf.h" #include "imgfmt/HGTiff.h" #include "imgfmt/HGImgFmt.h" #include "imgproc/HGImgProc.h" #include "imgproc/HGOCR.h" #include "base/HGUtility.h" #include "base/HGCrash.h" #include "HGUIGlobal.h" #include "HGString.h" #include "app_cfg.h" #include #include "dialog_wrong_img.h" #define PASSWORD_KEY 4 #define MY_URL_SCHEME "inscanner" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_versionDll(NULL) , m_admin_loggedIn(false) , m_dpi(200) , m_currFilePath("") , m_currIndex(-1) , m_multiPageCount(0) , m_multiIndex(-1) , m_modify(false) , m_singleScan(false) , m_scanType(0) , m_scanInsertPos(-1) , m_scanFileName("") , m_scanImgFmtWriter(nullptr) , m_isScanning(false) , auto_save_changes_(false) , save_from_changed_(false) , m_closeTip(true) , m_currScanCount(0) , m_devSerialNum("") , m_devVersionNum("") , m_currDeviceName("") { ui->setupUi(this); m_versionDll = new VersionDll; HGBase_RegisterCrashFunc(CrashFunc, this); // HGChar logFilePath[512]; // HGBase_GetLogFilePath(logFilePath, 512); // deleteFile(QString::fromStdString(getStdString(logFilePath))); // HGChar cfgFilePath[512]; // HGBase_GetConfigPath(cfgFilePath, 512); // deleteFile(QString::fromStdString(getStdString(cfgFilePath))); #if defined(OEM_HANWANG) this->setWindowIcon(QIcon(":images/image_rsc/logo/Hanvon_logo1.ico")); this->setWindowTitle(tr("HanvonScan")); #elif defined(OEM_LISICHENG) this->setWindowIcon(QIcon(":images/image_rsc/logo/Lanxum_logo.ico")); this->setWindowTitle(tr("LanxumScan")); auto_save_changes_ = true; #elif defined(OEM_CANGTIAN) this->setWindowIcon(QIcon(":images/image_rsc/logo/Cumtenn_logo.ico")); this->setWindowTitle(tr("CumtennScan")); #else this->setWindowIcon(QIcon(":images/image_rsc/logo/logo.ico")); this->setWindowTitle(tr("HuaGoScan")); #endif this->setAutoFillBackground(true); this->setPalette(QPalette(QColor(230, 230, 230))); QDesktopWidget *desktopWidget = QApplication::desktop(); QRect screenRect = desktopWidget->screenGeometry(this); if(screenRect.width() > 950 && screenRect.height() > 720) { resize(950, 720); } if (!m_versionDll->IsValid()) { ui->actionact_update->setVisible(false); ui->act_feedback->setVisible(false); } else { m_versionDll->PostUserOpenInfo(HGVERSION_APPNAME_SCANNER); } HGChar cfgpath[512] = {0}; QString old; HGBase_GetConfigPath(cfgpath, _countof(cfgpath) - 1); dev_que_.set_root_dir(cfgpath); old = QString::fromStdString(cfgpath) + PATH_SYMBOL + "scanner.schm"; if(QFile::exists(old)) dev_que::update_old_cfg(old.toStdString().c_str()); ui->toolBar->addAction(ui->act_scannerSettings); ui->toolBar->addAction(ui->act_acquire); ui->toolBar->addSeparator(); ui->toolBar->addAction(ui->act_fitWindowWidth); ui->toolBar->addAction(ui->act_fitWindowSize); ui->toolBar->addAction(ui->act_zoomIn); ui->toolBar->addAction(ui->act_zoomOut); ui->toolBar->addAction(ui->act_realSize); ui->toolBar->addSeparator(); ui->toolBar->addAction(ui->act_90Left); ui->toolBar->addAction(ui->act_90Right); ui->toolBar->addAction(ui->act_imageEdit); ui->toolBar->addSeparator(); ui->toolBar->addAction(ui->act_previous); ui->toolBar->addAction(ui->act_next); ui->toolBar->addAction(ui->act_previousPage); ui->toolBar->addAction(ui->act_nextPage); ui->toolBar->addAction(ui->act_sortPages); ui->toolBar->addSeparator(); ui->toolBar->addAction(ui->act_help); m_view = new HGImgView(ui->centralwidget); ui->verticalLayout->addWidget(m_view); ui->centralwidget->setMinimumWidth(160); m_thumb = new HGImgThumb(ui->dockWidget); ui->dockWidget->setMinimumWidth(200); resizeDocks({ui->dockWidget}, {200}, Qt::Horizontal); ui->dockWidget->setWidget(m_thumb); ui->dockWidget->setTitleBarWidget(new QWidget()); ui->dockWidget->titleBarWidget()->setVisible(false); QRegExp rx("[0-9,-]+$"); m_multiPageLineEdit = new HGLineEdit(this); m_multiPageLineEdit->setValidator(new QRegExpValidator(rx, this)); m_multiPageLineEdit->setFixedWidth(100); m_multiPageLineEdit->setAlignment(Qt::AlignHCenter); ui->toolBar->insertWidget(ui->act_nextPage, m_multiPageLineEdit); ui->toolBar->setStyleSheet("QToolBar::item{border: 0px}"); m_wndStatusBar = new Widget_StatusBar(ui->act_zoomIn, ui->act_zoomOut, ui->statusBar); ui->statusBar->addWidget(m_wndStatusBar, 1); m_wndStatusBar->setStyleSheet("QStatusBar::item{border: 0px}"); ui->statusBar->setSizeGripEnabled(false); m_dialogLog = new dialog_log(this); connect(m_view, SIGNAL(scaleChanged(double)), this, SLOT(on_viewerScale(double))); connect(m_view, SIGNAL(mousePos(int, int)), this, SLOT(on_viewerMousePos(int, int))); connect(m_view, SIGNAL(drop(const QObject*, const QStringList &)), this, SLOT(on_viewerDrop(const QObject*, const QStringList &))); connect(m_view, SIGNAL(doubleClicked()), this, SLOT(on_viewerDblClick())); connect(m_thumb, SIGNAL(itemCountChanged(int)), this, SLOT(on_itemCountChanged(int))); connect(m_thumb, SIGNAL(itemSelectingChanged()), this, SLOT(on_itemSelectingChanged())); connect(m_thumb, SIGNAL(currItemChanged(int)), this, SLOT(on_currItemChanged(int))); connect(m_thumb, SIGNAL(itemDoubleClicked(int)), this, SLOT(on_itemDoubleClicked(int))); connect(m_thumb, SIGNAL(contextMenuEvent(int)), this, SLOT(on_thumbContextMenu(int))); connect(m_thumb, SIGNAL(drop(const QObject*, const QStringList &, int)), this, SLOT(on_thumbDrop(const QObject*, const QStringList &, int))); connect(m_multiPageLineEdit, SIGNAL(editingFinished()), this, SLOT(on_multiPageLineEditFinished())); m_view->enableScroll(true); m_view->setScrollSize(16); m_view->setMinScrollSliderSize(20); QImage defItemImage(":images/image_rsc/scroll/defItemImage.png"); m_thumb->setDefItemImage(&defItemImage); m_thumb->setType(HGImgThumb::ThumbType_Vert); m_thumb->setItemSize(120); m_thumb->setScrollSize(16); m_thumb->setMinScrollSliderSize(20); m_thumb->setItemTextHeight(0); QImage nullScrollImage(":images/image_rsc/scroll/nullScrollImage.png"); m_view->setNullScrollImage(&nullScrollImage); m_thumb->setNullScrollImage(&nullScrollImage); QImage hScrollImage(":images/image_rsc/scroll/hScrollImage.png"); m_thumb->setHScrollImage(&hScrollImage, nullptr); m_view->setHScrollImage(&hScrollImage, nullptr); QImage vScrollImage(":images/image_rsc/scroll/vScrollImage.png"); m_thumb->setVScrollImage(&vScrollImage, nullptr); m_view->setVScrollImage(&vScrollImage, nullptr); QImage leftNormalImg(":images/image_rsc/scroll/left_Normal.png"); QImage leftHotImg(":images/image_rsc/scroll/left_Hot.png"); QImage leftPushImg(":images/image_rsc/scroll/left_Push.png"); m_thumb->setHScrollLeftImage(&leftNormalImg, &leftHotImg, &leftPushImg); m_view->setHScrollLeftImage(&leftNormalImg, &leftHotImg, &leftPushImg); QImage rightNormalImg(":images/image_rsc/scroll/right_Normal.png"); QImage rightHotImg(":images/image_rsc/scroll/right_Hot.png"); QImage rightPushImg(":images/image_rsc/scroll/right_Push.png"); m_thumb->setHScrollRightImage(&rightNormalImg, &rightHotImg, &rightPushImg); m_view->setHScrollRightImage(&rightNormalImg, &rightHotImg, &rightPushImg); QImage topNormalImg(":images/image_rsc/scroll/top_Normal.png"); QImage topHotImg(":images/image_rsc/scroll/top_Hot.png"); QImage topPushImg(":images/image_rsc/scroll/top_Push.png"); m_thumb->setVScrollTopImage(&topNormalImg, &topHotImg, &topPushImg); m_view->setVScrollTopImage(&topNormalImg, &topHotImg, &topPushImg); QImage bottomNormalImg(":images/image_rsc/scroll/bottom_Normal.png"); QImage bottomHotImg(":images/image_rsc/scroll/bottom_Hot.png"); QImage bottomPushImg(":images/image_rsc/scroll/bottom_Push.png"); m_thumb->setVScrollBottomImage(&bottomNormalImg, &bottomHotImg, &bottomPushImg); m_view->setVScrollBottomImage(&bottomNormalImg, &bottomHotImg, &bottomPushImg); HGRect hSliderStretchRect = { 4, 0, 196, 16 }; QImage hScrollSliderNormalImage(":images/image_rsc/scroll/hScrollSlider_Normal.png"); QImage hScrollSliderHotImage(":images/image_rsc/scroll/hScrollSlider_Hot.png"); QImage hScrollSliderPushImage(":images/image_rsc/scroll/hScrollSlider_Push.png"); m_thumb->setHScrollSliderImage(&hScrollSliderNormalImage, &hSliderStretchRect, &hScrollSliderHotImage, &hSliderStretchRect, &hScrollSliderPushImage, &hSliderStretchRect); m_view->setHScrollSliderImage(&hScrollSliderNormalImage, &hSliderStretchRect, &hScrollSliderHotImage, &hSliderStretchRect, &hScrollSliderPushImage, &hSliderStretchRect); HGRect vSliderStretchRect = { 0, 4, 16, 196 }; QImage vScrollSliderNormalImage(":images/image_rsc/scroll/vScrollSlider_Normal.png"); QImage vScrollSliderHotImage(":images/image_rsc/scroll/vScrollSlider_Hot.png"); QImage vScrollSliderPushImage(":images/image_rsc/scroll/vScrollSlider_Push.png"); m_thumb->setVScrollSliderImage(&vScrollSliderNormalImage, &vSliderStretchRect, &vScrollSliderHotImage, &vSliderStretchRect, &vScrollSliderPushImage, &vSliderStretchRect); m_view->setVScrollSliderImage(&vScrollSliderNormalImage, &vSliderStretchRect, &vScrollSliderHotImage, &vSliderStretchRect, &vScrollSliderPushImage, &vSliderStretchRect); QAction* act_thumbGrid = new QAction(tr("Grid"), this); act_thumbGrid->setCheckable(true); act_thumbGrid->setChecked(false); connect(act_thumbGrid, SIGNAL(triggered(bool)), this, SLOT(on_act_thumbGrid_triggered(bool))); m_moveToAction = new QAction(tr("Move To..."), this); connect(m_moveToAction, SIGNAL(triggered()), this, SLOT(on_act_moveTo_triggered())); m_thumbMenu = new QMenu(this); QMenu* menu_imageInsert = new QMenu(tr("Insert files"), m_thumbMenu); m_thumbMenu->addAction(ui->act_closeFile); m_thumbMenu->addAction(ui->act_closeAll); m_thumbMenu->addAction(ui->act_Export); m_thumbMenu->addSeparator(); m_thumbMenu->addAction(m_moveToAction); m_thumbMenu->addAction(menu_imageInsert->menuAction()); m_thumbMenu->addSeparator(); m_thumbMenu->addAction(act_thumbGrid); menu_imageInsert->addAction(ui->act_insert); menu_imageInsert->addAction(ui->act_insertFromScanner); ui->act_consume->setVisible(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(new_image(void*, int)), this, SLOT(on_new_image(void*, int)), Qt::QueuedConnection); connect(this, SIGNAL(scan_working(QString)), this, SLOT(on_scan_working(QString)), Qt::QueuedConnection); connect(this, SIGNAL(scan_finish(QString, int)), this, SLOT(on_scan_finish(QString, int)), Qt::QueuedConnection); connect(this, SIGNAL(fwUpgradeAndDevLock_Finish()), this, SLOT(on_fwUpgradeAndDevLock_Finish()), Qt::QueuedConnection); connect(this, SIGNAL(sane_dev_error(QString)), this, SLOT(on_sane_dev_error(QString)), Qt::QueuedConnection); connect(m_dialogLog, SIGNAL(continueScan()), this, SLOT(on_continueScan())); connect(m_dialogLog, SIGNAL(stopScan()), this, SLOT(on_stopScan())); connect(m_dialogLog, SIGNAL(exportScanned()), this, SLOT(on_export_scanned_image())); connect(m_wndStatusBar, SIGNAL(statusInfoDblClick()), this, SLOT(on_statusInfoDblClick())); m_wndStatusBar->setDeviceStatusInfo(tr("nodevice"), false); m_dialogLog->addLog(tr("nodevice"), false); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(tr("nodevice")).c_str()); connect(ui->menu_device, SIGNAL(scanOptionsChanged(const QString&, const QString&, bool)), this, SLOT(on_scanOptions_changed(const QString&, const QString&, bool))); QString password = getCfgValue("login", "password", QString("")); if (password.isEmpty()) #if defined(OEM_HANWANG) m_password = "hanvonscan"; #elif defined(OEM_LISICHENG) m_password = "lanxum"; #elif defined(OEM_CANGTIAN) m_password = "cumtenn"; #else m_password = "huagoscan"; #endif else m_password = passwordDecrypt(password); m_dlgFullScreen = nullptr; m_dialogLog->updateStatus(!dev_que_.opened_scanner_name().empty() && 0 != m_scanType, m_isScanning); updateActionStatus(); ui->act_autoSave->setChecked(getCfgValue("save", "autoSave", false)); auto_save_changes_ = ui->act_autoSave->isChecked(); ui->act_autoSave->setText(tr("auto save")); ui->act_autoSave->setToolTip(tr("when switching pictures, save the edited pictures directly without reminding")); auto_save_info_.index = 0; ui->act_device_log->setEnabled(false); ui->act_driver_log->setEnabled(false); m_vFwUpgradeAndDevLock.clear(); m_threadFwUpgradeAndDevLock = NULL; SANE_Int v = 0; sane_init_ex(&v, sane_ex_callback, this); } MainWindow::~MainWindow() { if (nullptr != m_dlgFullScreen) { delete m_dlgFullScreen; m_dlgFullScreen = nullptr; } if (NULL != m_threadFwUpgradeAndDevLock) { HGBase_CloseThread(m_threadFwUpgradeAndDevLock); m_threadFwUpgradeAndDevLock = NULL; } sane_exit(); m_versionDll->PostDeviceCloseInfo(m_currDeviceName.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str()); delete m_versionDll; m_versionDll = NULL; for(auto& v : wrong_imgs_) { v->hide(); delete v; } delete ui; } void MainWindow::exitFullScreen() { assert(nullptr != m_dlgFullScreen); this->show(); delete m_dlgFullScreen; m_dlgFullScreen = nullptr; } HGResult MainWindow::saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool ocr, const HGChar *fileName) { if (!ocr) { return HGImgFmt_SaveImage(image, 0, info, fileName); } HGResult ret = HGBASE_ERR_FAIL; // 韫囩晫鏆恑nfo HGOCRMgr ocrMgr = nullptr; HGImgProc_CreateOCRMgr(0, &ocrMgr); if (nullptr != ocrMgr) { ret = HGImgProc_ImageOCRToFile(ocrMgr, image, 0, fileName); if (ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "HGImgProc_ImageOCRToFile:%u", ret); } HGImgProc_DestroyOCRMgr(ocrMgr); } return ret; } void MainWindow::on_act_90Left_triggered() { if (HGBASE_ERR_OK == m_view->rotateLeft()) { m_modify = true; updateStatusBarPixelInfo(); updateActionStatus(); if (auto_save_changes_) { on_act_save_triggered(); } } } void MainWindow::on_act_90Right_triggered() { if (HGBASE_ERR_OK == m_view->rotateRight()) { m_modify = true; updateStatusBarPixelInfo(); updateActionStatus(); if (auto_save_changes_) { on_act_save_triggered(); } } } void MainWindow::on_act_180_triggered() { if (HGBASE_ERR_OK == m_view->rotate180()) { m_modify = true; updateStatusBarPixelInfo(); updateActionStatus(); if (auto_save_changes_) { on_act_save_triggered(); } } } void MainWindow::on_act_fitWindowSize_triggered() { m_view->fitWndSize(); } void MainWindow::on_act_fitWindowWidth_triggered() { m_view->fitWndWidth(); } void MainWindow::on_act_realSize_triggered() { m_view->realSize(); } void MainWindow::on_act_zoomIn_triggered() { m_view->zoomIn(nullptr); } void MainWindow::on_act_zoomOut_triggered() { m_view->zoomOut(nullptr); } void MainWindow::on_act_statusBar_triggered(bool checked) { ui->statusBar->setVisible(checked); if(checked) { m_wndStatusBar->setDeviceStatusInfo(tr("statusBar displayed"), false); } else { m_wndStatusBar->setDeviceStatusInfo(tr("statusBar hidden"), false); } } void MainWindow::on_act_toolBar_triggered(bool checked) { ui->toolBar->setVisible(checked); if(checked) { m_wndStatusBar->setDeviceStatusInfo(tr("toolBar displayed"), false); } else { m_wndStatusBar->setDeviceStatusInfo(tr("toolBar hidden"), false); } } void MainWindow::on_act_colorInfo_triggered(bool checked) { m_view->showColorInfo(checked); if(checked) { m_wndStatusBar->setDeviceStatusInfo(tr("colorInfo enabled"), false); } else { m_wndStatusBar->setDeviceStatusInfo(tr("colorInfo disenabled"), false); } } void MainWindow::on_act_fullscreen_triggered() { assert(nullptr == m_dlgFullScreen); int count = 0; m_thumb->getItemCount(&count); if (0 == count || -1 == m_currIndex || -1 == m_multiIndex) { return; } QStringList fileNames; for (int i = 0; i < count; ++i) { QString fileName; m_thumb->getItemFileName(i, fileName); fileNames.append(fileName); } m_dlgFullScreen = new Dialog_FullScreen(this, fileNames, m_currIndex, m_multiIndex); m_dlgFullScreen->show(); this->hide(); } void MainWindow::on_act_autoSave_triggered() { auto_save_changes_ = ui->act_autoSave->isChecked(); if(auto_save_changes_) { m_wndStatusBar->setDeviceStatusInfo(tr("enabling automatic saving"), false); } else { m_wndStatusBar->setDeviceStatusInfo(tr("cancel auto save"), false); } saveCfgValue("save", "autoSave", auto_save_changes_); } void MainWindow::on_itemCountChanged(int count) { m_wndStatusBar->setPageInfo(count, m_currIndex); updateActionStatus(); } void MainWindow::on_itemSelectingChanged() { updateActionStatus(); } void MainWindow::on_currItemChanged(int index) { HGImage img = nullptr; m_view->getImage(&img); if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1) { assert(!m_currFilePath.isEmpty()); QString newCurrFilePath; if (-1 != index) m_thumb->getItemFileName(index, newCurrFilePath); if (m_currFilePath != newCurrFilePath) { bool save = false; if(auto_save_changes_) { // 閸掑洦宕查崶鍓у閺冭绱濋懛顏勫З娣囨繂鐡ㄧ紓鏍帆鏉╁洨娈戦崶鎯у剼閵嗗倽瀚㈤幆鍐插絿濞戝牞绱濈拠宄板絿濞戝牆瀣€闁褰嶉崡鏇€嶉敍姘禈閸?>閼奉亜濮╂穱婵嗙摠 QString info(tr("Automatically save the edited the edited iamge when switching pictures. To cancel, uncheck the menu item: image-> automatically save")); m_wndStatusBar->setDeviceStatusInfo(info, false); save = true; } else { QMessageBox msg(QMessageBox::Question, tr("Question"), tr("modified, save it?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::YesToAll, tr("save, do not remind again")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if (msg.clickedButton() == msg.button(QMessageBox::No)) { m_modify = false; } else { save = true; auto_save_changes_ = msg.clickedButton() == msg.button(QMessageBox::YesToAll); if(auto_save_changes_) ui->act_autoSave->setChecked(true); } } if(save) { save_from_changed_ = true; on_act_save_triggered(); save_from_changed_ = false; } } } if (-1 != index) { QString oldCurrFilePath = m_currFilePath; m_currIndex = index; m_thumb->getItemFileName(m_currIndex, m_currFilePath); assert(!m_currFilePath.isEmpty()); if (oldCurrFilePath != m_currFilePath) { m_multiPageCount = getMultiPageCount(); m_multiIndex = 0; HGImage img2 = createImage(); if (nullptr != img2) { m_view->addImage(img2); HGBase_DestroyImage(img2); m_modify = false; } else { m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; QFileInfo info(m_currFilePath); if (!info.isFile()) { QMessageBox msg(QMessageBox::Question, tr("Question"), tr("file lost, remove it?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if (msg.clickedButton() == msg.button(QMessageBox::Yes)) { m_thumb->removeItem(index, HGImgThumb::ThumbRemoveFlag_NULL); } } } } } else { m_currFilePath.clear(); m_currIndex = -1; m_multiPageCount = 0; m_multiIndex = -1; m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; } int count = 0; m_thumb->getItemCount(&count); m_wndStatusBar->setPageInfo(count, m_currIndex); updateStatusBarPixelInfo(); updateActionStatus(); } void MainWindow::on_itemDoubleClicked(int index) { (void)index; } void MainWindow::on_thumbContextMenu(int index) { qDebug("thumbnail menu index=%d", index); m_thumbMenu->show(); m_thumbMenu->popup(QCursor::pos()); qDebug("show menu"); } void MainWindow::on_viewerScale(double scale) { m_wndStatusBar->setScale(scale); } void MainWindow::on_viewerMousePos(int x, int y) { m_wndStatusBar->setMousePosInfo(x, y); } void MainWindow::on_thumbDrop(const QObject *source, const QStringList &fileNames, int pos) { if (source != m_thumb) m_thumb->insertItems(fileNames, pos); else m_thumb->moveItems(fileNames, pos); } void MainWindow::on_viewerDrop(const QObject *source, const QStringList &fileNames) { if (source != m_thumb) m_thumb->addItems(fileNames); } void MainWindow::on_viewerDblClick() { on_act_open_triggered(); } void MainWindow::on_act_moveTo_triggered() { int count = 0; m_thumb->getItemCount(&count); Dialog_MoveTo dlg(count, (-1 != m_currIndex) ? m_currIndex : 0, this); if (dlg.exec()) { QStringList fileNames; for (int i = 0; i < count; ++i) { bool selected = false; m_thumb->itemIsSelect(i, &selected); if (selected) { QString fileName; m_thumb->getItemFileName(i, fileName); fileNames.append(fileName); } } int index = dlg.getMoveToIndex(); m_thumb->moveItemsTo(fileNames, index); } } void MainWindow::on_act_thumbGrid_triggered(bool checked) { if (checked) { m_thumb->setType(HGImgThumb::ThumbType_Grid); resizeDocks({ui->dockWidget}, {300}, Qt::Horizontal); } else { m_thumb->setType(HGImgThumb::ThumbType_Vert); resizeDocks({ui->dockWidget}, {200}, Qt::Horizontal); } } void MainWindow::on_dialog_adjust_applyToImage(HGImage img) { m_view->addImage(img); updateStatusBarPixelInfo(); } void MainWindow::on_dialog_multirotate_refreshImgFile(const QString &fileName) { m_thumb->refreshItem(fileName); } void MainWindow::on_multiPageLineEditFinished() { if (-1 != m_currIndex && m_multiPageCount > 0) { int multiIndex = m_multiPageLineEdit->text().toInt() - 1; if (multiIndex >= 0 && multiIndex < m_multiPageCount) { m_multiIndex = multiIndex; HGImage img = createImage(); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); m_modify = false; } else { m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; } updateStatusBarPixelInfo(); } updateActionStatus(); } } void MainWindow::on_clearCache() { std::vector removeItems; int count = 0; m_thumb->getItemCount(&count); for (int i = 0; i < count; ++i) { QString fileName; m_thumb->getItemFileName(i, fileName); if (0 == fileName.indexOf(Dialog_ClrCache::getCachePath())) { removeItems.push_back(i); } } m_thumb->removeItems(removeItems, HGImgThumb::ThumbRemoveFlag_NULL); } void MainWindow::on_sane_dev_arrive(QString devName, bool opened) { bool reconnected = false; std::vector now; std::string stdn(devName.toStdString()); dev_que_.get_scanners(now); if(std::find(now.begin(), now.end(), stdn) == now.end()) { // initializing the device configuration ... dev_que_.add_scanner(stdn.c_str()); // statu info ... QString info(tr("found device ") +": " + devName); m_wndStatusBar->setDeviceStatusInfo(info, false); m_dialogLog->addLog(info, false); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(info).c_str()); } else { // re-connected statu ... QString info(devName); if(!opened && devName.toStdString() != dev_que_.opened_scanner_name()) opened = true; if(opened) info += tr(" reconnected"); else info += tr("already connected, but open faild"); m_wndStatusBar->setDeviceStatusInfo(info, !opened); m_dialogLog->addLog(info, !opened); HGBase_WriteInfo(!opened ? HGBASE_INFOTYPE_ERROR : HGBASE_INFOTYPE_DESC, "%s", getStdString(info).c_str()); reconnected = true; dev_que_.set_online(true, stdn.c_str()); } // enable the device menu item ... ui->menu_device->connectedDevice(devName); // open it if no device has been opened ... if (dev_que_.opened_scanner_name().empty()) { //dev_que_.open_scanner(stdn.c_str()); open_scanner(devName, ""); } else { upgradeFwAndLockDevice(); } ui->menu_device->deviceMenuUpdate(&dev_que_); m_dialogLog->updateStatus(!dev_que_.opened_scanner_name().empty() && 0 != m_scanType, m_isScanning); updateActionStatus(); } void MainWindow::on_sane_dev_remove(QString devName) { // statu info ... QString info(devName + tr(" disconnected")); m_wndStatusBar->setDeviceStatusInfo(info, true); m_dialogLog->addLog(info, true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(info).c_str()); // enable the device menu item ... ui->menu_device->disconnectedDevice(devName); // set openning device offline ... dev_que_.set_online(false, devName.toStdString().c_str()); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); } void MainWindow::on_sane_dev_error(QString errorInfo) { //Error codes operate in slot function: on_scan_finish(QString finishInfo, int err). m_wndStatusBar->setDeviceStatusInfo(errorInfo, true); m_dialogLog->addLog(errorInfo, true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(errorInfo).c_str()); } void MainWindow::on_new_image(void *img, int statu) { HGImage image = (HGImage)img; HGBase_SetImageDpi(image, m_dpi, m_dpi); if (1 == m_scanType) { QString fileName = getCacheFileName(image); HGResult ret = HGImgFmt_SaveImage(image, 0, nullptr, getStdString(fileName).c_str()); if(ret == HGBASE_ERR_OK) { if(statu != SANE_Image_Statu_OK) { int ind = 0; if(m_scanInsertPos == -1) m_thumb->getItemCount(&ind); else ind = m_scanInsertPos; dialog_wrong_img *wi = new dialog_wrong_img(this, fileName, ind, statu); connect(wi, SIGNAL(handle_wrong_img(dialog_wrong_img*, bool)), this, SLOT(on_wrong_image_decide(dialog_wrong_img*, bool))); wrong_imgs_.push_back(wi); wi->show(); } else if (-1 == m_scanInsertPos) { m_thumb->addItem(fileName); } else { m_thumb->insertItem(fileName, m_scanInsertPos); ++m_scanInsertPos; } } else { m_dialogLog->addLog(tr("save failed"), true); m_wndStatusBar->setDeviceStatusInfo(tr("save failed"), true); } } else if (2 == m_scanType) { ++m_aquireIntoPageIndex; if ((1 == m_aquireIntoSaveParam.m_fileNameOddEventType && 1 != m_aquireIntoPageIndex % 2) || (2 == m_aquireIntoSaveParam.m_fileNameOddEventType && 0 != m_aquireIntoPageIndex % 2)) { HGBase_DestroyImage(image); return; } if (m_aquireIntoSaveParam.m_isSaveAsMultiPage) { if (1 == m_aquireIntoSaveParam.m_multiPagesType && m_aquireIntoMultiPageCount == m_aquireIntoSaveParam.m_customMultiPages) { if (nullptr != m_scanImgFmtWriter) { HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); m_scanImgFmtWriter = nullptr; m_thumb->addItem(m_scanFileName); m_scanFileName.clear(); ++m_aquireIntoSaveParam.m_fileNameStartIndex; m_aquireIntoMultiPageCount = 0; } } if (nullptr == m_scanImgFmtWriter) { assert(m_scanFileName.isEmpty()); HGResult ret = HGBase_CreateDir(getStdString(m_aquireIntoSaveParam.m_savePath).c_str()); if (ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "create aquireInto path failed, %s", getStdString(m_aquireIntoSaveParam.m_savePath).c_str()); } QString scanFileName; while (1) { scanFileName = QString(tr("%1%2%3.%4")).arg(m_aquireIntoSaveParam.m_savePath) .arg(m_aquireIntoSaveParam.m_fileNamePrefix) .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) .arg(m_aquireIntoSaveParam.m_fileNameExt); QFileInfo fileInfo(scanFileName); if (fileInfo.isFile()) { ++m_aquireIntoSaveParam.m_fileNameStartIndex; } else { break; } } HGImgFmt_OpenImageWriter(getStdString(getStdFileName(scanFileName)).c_str(), 0, &m_scanImgFmtWriter); if (nullptr != m_scanImgFmtWriter) m_scanFileName = scanFileName; } if (nullptr != m_scanImgFmtWriter) { HGImgFmtSaveInfo saveInfo; saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality; saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality; HGImageInfo imgInfo; HGBase_GetImageInfo(image, &imgInfo); if (HGBASE_IMGTYPE_BINARY == imgInfo.type) { if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; } else { if (1 == m_aquireIntoSaveParam.m_tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == m_aquireIntoSaveParam.m_tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; } HGImgFmt_SaveImageToWriter(m_scanImgFmtWriter, image, &saveInfo); ++m_aquireIntoMultiPageCount; } } else { assert(m_scanFileName.isEmpty()); assert(nullptr == m_scanImgFmtWriter); QString savePath = m_aquireIntoSaveParam.m_savePath; if (m_aquireIntoSaveParam.m_isUseSubfolderByBlankPages) { HGBool isBlank = HGFALSE; HGImgProc_ImageBlankCheck(image, nullptr, &isBlank); if (isBlank) { m_aquireIntoInBlank = true; HGBase_DestroyImage(image); return; } else { if (m_aquireIntoInBlank) { ++m_aquireIntoBatchStartIndex; } m_aquireIntoInBlank = false; } char batchDir[20]; sprintf(batchDir, "batch%d", m_aquireIntoBatchStartIndex); savePath = getStdFileName(savePath + batchDir + "/"); } if (m_aquireIntoSaveParam.m_isUseSubfolderByColor) { QString colorModeName; HGImageInfo imgInfo; HGBase_GetImageInfo(image, &imgInfo); if (HGBASE_IMGTYPE_BINARY == imgInfo.type) colorModeName = tr("binary"); else if (HGBASE_IMGTYPE_GRAY == imgInfo.type) colorModeName = tr("gray"); else colorModeName = tr("rgb"); savePath = getStdFileName(savePath + colorModeName + "/"); } HGResult result = HGBase_CreateDir(getStdString(savePath).c_str()); if (result != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "HGBase_CreateDir:%u file:%s line:%d", result, __FILE__, __LINE__); } QString scanFileName; while (1) { scanFileName = QString(tr("%1%2%3.%4")).arg(savePath) .arg(m_aquireIntoSaveParam.m_fileNamePrefix) .arg(m_aquireIntoSaveParam.m_fileNameStartIndex, m_aquireIntoSaveParam.m_fileNameDigits, 10, QLatin1Char('0')) .arg(m_aquireIntoSaveParam.m_fileNameExt); QFileInfo fileInfo(scanFileName); if (fileInfo.isFile()) { ++m_aquireIntoSaveParam.m_fileNameStartIndex; } else { break; } } HGImgFmtSaveInfo saveInfo; saveInfo.jpegQuality = (HGUInt)m_aquireIntoSaveParam.m_jpegQuality; saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; saveInfo.tiffJpegQuality = (HGUInt)m_aquireIntoSaveParam.m_tiffQuality; HGImageInfo imgInfo; HGBase_GetImageInfo(image, &imgInfo); if (HGBASE_IMGTYPE_BINARY == imgInfo.type) { if (1 == m_aquireIntoSaveParam.m_tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == m_aquireIntoSaveParam.m_tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; } else { if (1 == m_aquireIntoSaveParam.m_tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == m_aquireIntoSaveParam.m_tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; } HGResult ret = saveImage(image, &saveInfo, m_aquireIntoSaveParam.m_isOcr, getStdString(scanFileName).c_str()); if(ret == HGBASE_ERR_OK) { m_thumb->addItem(scanFileName); ++m_aquireIntoSaveParam.m_fileNameStartIndex; } } } m_currScanCount++; HGBase_DestroyImage(image); if(statu == SANE_Image_Statu_OK) m_dialogLog->image_received_from_scanner(); } void MainWindow::on_scan_working(QString workingInfo) { m_wndStatusBar->setDeviceStatusInfo(workingInfo, false); m_dialogLog->addLog(workingInfo, false, LOG_EVENT_SCAN_BEGINNING); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(workingInfo).c_str()); } void MainWindow::on_scan_finish(QString finishInfo, int err) { if (0 == m_scanType) { if (nullptr != m_scanImgFmtWriter) { HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); m_scanImgFmtWriter = nullptr; m_thumb->addItem(m_scanFileName); m_scanFileName.clear(); ++m_aquireIntoSaveParam.m_fileNameStartIndex; } } if(err == SCANNER_ERR_DEVICE_PAPER_JAMMED) { m_versionDll->PostDevicePaperJamInfo(m_currDeviceName.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str()); } m_versionDll->PostDeviceScanCountInfo(m_currDeviceName.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str(), m_currScanCount); m_currScanCount = 0; m_isScanning = false; m_thumb->setAcceptDrops(true); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); m_wndStatusBar->setDeviceStatusInfo(finishInfo, (err != SANE_STATUS_GOOD)); m_dialogLog->addLog(finishInfo, (err != SANE_STATUS_GOOD), LOG_EVENT_SCAN_STOPPED); HGBase_WriteInfo((err != SANE_STATUS_GOOD) ? HGBASE_INFOTYPE_ERROR : HGBASE_INFOTYPE_DESC, "%s", getStdString(finishInfo).c_str()); } void MainWindow::on_fwUpgradeAndDevLock_Finish() { if (NULL != m_threadFwUpgradeAndDevLock) { HGBase_CloseThread(m_threadFwUpgradeAndDevLock); m_threadFwUpgradeAndDevLock = NULL; } upgradeFwAndLockDevice(); } void MainWindow::on_export_scanned_image(void) { m_dialogLog->hide(); on_act_Export_triggered(); } void MainWindow::on_continueScan() { if(!isLimitAccessFolder("")) { return; } if (!dev_que_.is_online() || m_isScanning || 0 == m_scanType) { return; } if (!startSpaceCheck(m_dialogLog)) { return; } startSaveMessageBox(m_dialogLog); SANE_Status ret; m_dpi = getDpi(); if (m_singleScan) ret = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_TEST_SINGLE, nullptr, nullptr); else ret = sane_start(dev_que_.handle()); if (ret != SANE_STATUS_GOOD) { m_wndStatusBar->setDeviceStatusInfo(tr("start failed"), true); m_dialogLog->addLog(tr("start failed") + "(" + QString(sane_err_desc(ret)) + ")", true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(tr("start failed")).c_str()); if(ret == SCANNER_ERR_DEVICE_SLEEPING) { ui->menu_scan->setEnabled(false); ui->act_acquire->setEnabled(false); ui->act_scannerSettings->setEnabled(false); m_dialogLog->updateStatus(false, false); m_dialogLog->show(); QTime curTimer = QTime::currentTime().addMSecs(10000); while (QTime::currentTime() < curTimer) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } ui->menu_scan->setEnabled(true); ui->act_acquire->setEnabled(true); ui->act_scannerSettings->setEnabled(true); m_dialogLog->addLog(tr("already waked up device"), false); m_wndStatusBar->setDeviceStatusInfo(tr("already waked up device"), false); m_dialogLog->updateStatus(true, false); } } else { m_isScanning = true; m_thumb->setAcceptDrops(false); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); } m_dialogLog->show(); } void MainWindow::on_stopScan() { m_dialogLog->updateStatus(dev_que_.is_online(), m_isScanning); if (!m_isScanning) { if (nullptr != m_scanImgFmtWriter) { HGImgFmt_CloseImageWriter(m_scanImgFmtWriter); m_scanImgFmtWriter = nullptr; m_thumb->addItem(m_scanFileName); m_scanFileName.clear(); ++m_aquireIntoSaveParam.m_fileNameStartIndex; } } else { if (dev_que_.is_online()) { sane_cancel(dev_que_.handle()); } } } void MainWindow::on_statusInfoDblClick() { m_dialogLog->show(); } void MainWindow::on_wrong_image_decide(dialog_wrong_img* dlg, bool save) { int i = 0; for(; i < wrong_imgs_.size(); ++i) { if(wrong_imgs_[i] == dlg) { wrong_imgs_.erase(wrong_imgs_.begin() + i); break; } } if(save) { // save the image ... for(; i < wrong_imgs_.size(); ++i) wrong_imgs_[i]->increase_index(); m_thumb->insertItem(dlg->image_file(), dlg->index()); if (-1 != m_scanInsertPos) { ++m_scanInsertPos; } m_dialogLog->image_received_from_scanner(); } else { remove(dlg->image_file().toStdString().c_str()); } delete dlg; } void MainWindow::on_act_thumbnailBar_triggered(bool checked) { ui->dockWidget->setVisible(checked); if(checked) { m_wndStatusBar->setDeviceStatusInfo(tr("thumbnailBar enabled"), false); } else { m_wndStatusBar->setDeviceStatusInfo(tr("thumbnailBar hidden"), false); } } void MainWindow::on_act_previous_triggered() { int count = 0; m_thumb->getItemCount(&count); if (count > 0 && (-1 == m_currIndex || m_currIndex > 0)) { if (-1 == m_currIndex) m_thumb->setCurrItem(0); else m_thumb->setCurrItem(m_currIndex - 1); } } void MainWindow::on_act_next_triggered() { int count = 0; m_thumb->getItemCount(&count); if (count > 0 && (-1 == m_currIndex || m_currIndex < count - 1)) { if (-1 == m_currIndex) m_thumb->setCurrItem(0); else m_thumb->setCurrItem(m_currIndex + 1); } } void MainWindow::on_act_first_triggered() { int count = 0; m_thumb->getItemCount(&count); if (count > 0 && 0 != m_currIndex) { m_thumb->setCurrItem(0); } } void MainWindow::on_act_last_triggered() { int count = 0; m_thumb->getItemCount(&count); if (count > 0 && count - 1 != m_currIndex) { m_thumb->setCurrItem(count - 1); } } HGUInt MainWindow::getDpi() { HGUInt dpi = 200; SANE_Int num_dev_options = 0; sane_control_option(dev_que_.handle(), 0, SANE_ACTION_GET_VALUE, &num_dev_options, nullptr); for (int i = 1; i < num_dev_options; ++i) { const SANE_Option_Descriptor* desp = sane_get_option_descriptor(dev_que_.handle(), i); if (nullptr == desp) continue; if (SANE_TYPE_INT == desp->type) { SANE_Int value = 0; sane_control_option(dev_que_.handle(), i, SANE_ACTION_GET_VALUE, &value, nullptr); if (0 == strcmp(desp->name, SANE_STD_OPT_NAME_RESOLUTION)) { dpi = (HGUInt)value; } } } return dpi; } QString MainWindow::getCacheFileName(HGImage img) { assert(nullptr != img); HGImageInfo imgInfo; HGBase_GetImageInfo(img, &imgInfo); QString cachePath = Dialog_ClrCache::getCachePath(); HGResult ret = HGBase_CreateDir(getStdString(cachePath).c_str()); if(ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "create cache file failed, %s", getStdString(cachePath).c_str()); } char uuid[256] = {0}; HGBase_GetUuid(uuid, 256); QString suffix = (HGBASE_IMGTYPE_BINARY == imgInfo.type) ? ".bmp" : ".jpg"; QString fileName = getStdFileName(cachePath + uuid + suffix); return fileName; } HGImage MainWindow::createImage() { qDebug("createImage"); assert(-1 != m_currIndex && -1 != m_multiIndex); assert(!m_currFilePath.isEmpty()); HGImage img = nullptr; HGPdfReader pdfReader = nullptr; HGImgFmt_OpenPdfReader(getStdString(m_currFilePath).c_str(), &pdfReader); if (nullptr != pdfReader) { float scale = 200.0f / 72.0f; HGImgFmt_LoadImageFromPdfReader(pdfReader, (HGUInt)m_multiIndex, scale, scale, 0, HGBASE_IMGORIGIN_TOP, &img); HGBase_SetImageDpi(img, 200, 200); HGImgFmt_ClosePdfReader(pdfReader); } else { HGImgFmtReader imgFmtReader = nullptr; HGImgFmt_OpenImageReader(getStdString(m_currFilePath).c_str(), 0, &imgFmtReader); if (nullptr != imgFmtReader) { HGImgFmt_LoadImageFromReader(imgFmtReader, (HGUInt)m_multiIndex, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img); HGImgFmt_CloseImageReader(imgFmtReader); } } return img; } int MainWindow::getMultiPageCount() { assert(-1 != m_currIndex); assert(!m_currFilePath.isEmpty()); int count = 0; HGImgFmtReader imgFmtReader = nullptr; HGImgFmt_OpenImageReader(getStdString(m_currFilePath).c_str(), 0, &imgFmtReader); if (nullptr != imgFmtReader) { HGImgFmt_GetImagePageCount(imgFmtReader, (HGUInt *)&count); HGImgFmt_CloseImageReader(imgFmtReader); } qDebug("pageCount=%d", count); return count; } void MainWindow::updateStatusBarPixelInfo() { HGImage img = nullptr; m_view->getImage(&img); if (nullptr == img) { m_wndStatusBar->setPixelInfo(0, 0, 0); } else { HGImageInfo imgInfo; HGBase_GetImageInfo(img, &imgInfo); int bpp = 0; if (HGBASE_IMGTYPE_BINARY == imgInfo.type) bpp = 1; else if (HGBASE_IMGTYPE_GRAY == imgInfo.type) bpp = 8; else if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_RGB == imgInfo.type) bpp = 24; else bpp = 32; m_wndStatusBar->setPixelInfo((int)imgInfo.width, (int)imgInfo.height, bpp); } } void MainWindow::updateActionStatus() { HGImage img = nullptr; m_view->getImage(&img); int count = 0; m_thumb->getItemCount(&count); std::vector selectIndexs; for (int i = 0; i < count; ++i) { bool select = false; m_thumb->itemIsSelect(i, &select); if (select) selectIndexs.push_back(i); } ui->act_open->setEnabled(!dev_que_.is_online() || !m_isScanning); ui->act_insert->setEnabled(!dev_que_.is_online() || !m_isScanning); ui->act_save->setEnabled(nullptr != img && -1 != m_currIndex && m_multiPageCount == 1 && (!dev_que_.is_online() || !m_isScanning)); ui->act_saveAs->setEnabled(nullptr != img); ui->act_Export->setEnabled(0 != count && (!dev_que_.is_online() || !m_isScanning)); ui->act_closeFile->setEnabled(!selectIndexs.empty() && (!dev_que_.is_online() || !m_isScanning)); ui->act_closeAll->setEnabled(0 != count && (!dev_que_.is_online() || !m_isScanning)); ui->act_imageInfo->setEnabled(-1 != m_currIndex && (!dev_que_.is_online() || !m_isScanning)); ui->menu_multiPages->setEnabled(m_multiPageCount > 1 && (!dev_que_.is_online() || !m_isScanning)); ui->act_previous->setEnabled(count > 0 && (-1 == m_currIndex || m_currIndex > 0) && (!dev_que_.is_online() || !m_isScanning)); ui->act_next->setEnabled(count > 0 && (-1 == m_currIndex || m_currIndex < count - 1) && (!dev_que_.is_online() || !m_isScanning)); ui->act_first->setEnabled(count > 0 && 0 != m_currIndex && (!dev_que_.is_online() || !m_isScanning)); ui->act_last->setEnabled(count > 0 && count - 1 != m_currIndex && (!dev_que_.is_online() || !m_isScanning)); ui->act_openPageNum->setEnabled(count > 0 && (!dev_que_.is_online() || !m_isScanning)); ui->act_previousPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex > 0 && (!dev_que_.is_online() || !m_isScanning)); ui->act_nextPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && -1 != m_multiIndex && m_multiIndex < m_multiPageCount - 1 && (!dev_que_.is_online() || !m_isScanning)); ui->act_firstPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && 0 != m_multiIndex && (!dev_que_.is_online() || !m_isScanning)); ui->act_lastPage->setEnabled(-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex != m_multiPageCount - 1 && (!dev_que_.is_online() || !m_isScanning)); m_multiPageLineEdit->setText(QString("%1/%2").arg(m_multiIndex + 1).arg(m_multiPageCount)); ui->toolBar->actions().at(16)->setVisible(-1 != m_currIndex && m_multiPageCount > 1 && -1 != m_multiIndex && (!dev_que_.is_online() || !m_isScanning)); ui->act_sortPages->setEnabled(0 != count && (!dev_que_.is_online() || !m_isScanning)); ui->act_imageEdit->setEnabled(nullptr != img); ui->act_zoomIn->setEnabled(nullptr != img); ui->act_zoomOut->setEnabled(nullptr != img); ui->act_fullscreen->setEnabled(count > 0 && -1 != m_currIndex && -1 != m_multiIndex && (!dev_que_.is_online() || !m_isScanning)); ui->act_fitWindowSize->setEnabled(nullptr != img); ui->act_fitWindowWidth->setEnabled(nullptr != img); ui->act_realSize->setEnabled(nullptr != img); ui->act_90Left->setEnabled(nullptr != img); ui->act_90Right->setEnabled(nullptr != img); ui->act_180->setEnabled(nullptr != img); ui->menu_Auto_Image_Size->setEnabled(nullptr != img); ui->act_adjust->setEnabled(nullptr != img); ui->act_multiRotate->setEnabled(0 != count && (!dev_que_.is_online() || !m_isScanning)); ui->menu_Rotate->setEnabled((0 != count || nullptr != img) && (!dev_que_.is_online() || !m_isScanning)); ui->act_autoCrop->setEnabled(nullptr != img); ui->act_signIn->setEnabled(!m_admin_loggedIn); ui->act_passwordChange->setEnabled(m_admin_loggedIn); ui->act_signOut->setEnabled(m_admin_loggedIn); ui->act_log->setEnabled(m_admin_loggedIn); ui->act_clrCache->setEnabled(m_admin_loggedIn); ui->act_consume->setEnabled(m_admin_loggedIn); ui->act_clearRoller->setEnabled(m_admin_loggedIn); ui->act_acquireInto->setEnabled(dev_que_.is_online() && !m_isScanning); ui->act_acquireSingle->setEnabled(dev_que_.is_online() && !m_isScanning); ui->act_acquire->setEnabled(dev_que_.is_online() && !m_isScanning); ui->act_scannerSettings->setEnabled(dev_que_.is_online() && !m_isScanning); ui->act_insertFromScanner->setEnabled(dev_que_.is_online() && !m_isScanning); ui->menu_scan->setEnabled(dev_que_.is_online() && !m_isScanning); ui->menu_device->setEnabled(!dev_que_.is_online() || !m_isScanning); ui->act_device_log->setEnabled(m_admin_loggedIn && !m_isScanning && dev_que_.is_online()); ui->act_driver_log->setEnabled(m_admin_loggedIn); m_moveToAction->setEnabled(!selectIndexs.empty() && (!dev_que_.is_online() || !m_isScanning)); } void MainWindow::startSaveMessageBox(QWidget* parent) { HGImage img = nullptr; m_view->getImage(&img); if (nullptr != img && m_modify && -1 != m_currIndex && m_multiPageCount == 1) { QMessageBox msg(QMessageBox::Question, tr("Question"), tr("modified, save it?"), QMessageBox::Yes | QMessageBox::No, parent); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if (msg.clickedButton() != msg.button(QMessageBox::Yes)) { m_modify = false; updateActionStatus(); } else { on_act_save_triggered(); } } } askIfClear MainWindow::startScanMessageBox(QWidget *parent) { QMessageBox box(parent); QPushButton* clearBtn = box.addButton(tr("Clear, then start scan"), QMessageBox::ActionRole); box.addButton(tr("Do NOT clear, then start scan"), QMessageBox::ActionRole); QPushButton* cancelBtn = box.addButton(QMessageBox::Cancel); box.setWindowTitle(tr("Question")); box.setText(tr("Already exist images in image list.\nDo you want to clear?")); box.exec(); if (box.clickedButton() == cancelBtn) return cancelScan; else if (box.clickedButton() == clearBtn) { on_act_closeAll_triggered(); return clearAndScan; } return notClearAndScan; } bool MainWindow::startSpaceCheck(QWidget* parent) { qint64 space = 0; QList storageInfoList = QStorageInfo::mountedVolumes(); foreach(QStorageInfo storage, storageInfoList) { QString savePath; if (1 == m_scanType) savePath = Dialog_ClrCache::getCachePath(); else if (2 == m_scanType) savePath = m_aquireIntoSaveParam.m_savePath; if (0 == savePath.indexOf(getStdFileName(storage.rootPath()))) { space = storage.bytesAvailable() / 1024 / 1024; break; } } assert(0 != space); if (space < 64) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "disk space is unsufficient!"); QMessageBox msg(QMessageBox::Information, tr("Information"), tr("Insufficient disk space"), QMessageBox::Yes, parent); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.exec(); return false; } return true; } 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; } void MainWindow::on_act_openPageNum_triggered() { int count = 0; m_thumb->getItemCount(&count); if (0 == count) { return; } Dialog_OpenImageIndex dlg(count, (-1 == m_currIndex) ? 0 : m_currIndex, this); if (dlg.exec()) { int index = dlg.getIndex(); m_thumb->setCurrItem(index); } } void MainWindow::on_act_previousPage_triggered() { if (-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex > 0) { --m_multiIndex; HGImage img = createImage(); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); m_modify = false; } else { m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; } updateStatusBarPixelInfo(); updateActionStatus(); } } void MainWindow::on_act_nextPage_triggered() { if (-1 != m_currIndex && m_multiPageCount > 0 && -1 != m_multiIndex && m_multiIndex < m_multiPageCount - 1) { ++m_multiIndex; HGImage img = createImage(); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); m_modify = false; } else { m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; } updateStatusBarPixelInfo(); updateActionStatus(); } } void MainWindow::on_act_firstPage_triggered() { if (-1 != m_currIndex && m_multiPageCount > 0 && 0 != m_multiIndex) { m_multiIndex = 0; HGImage img = createImage(); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); m_modify = false; } else { m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; } updateStatusBarPixelInfo(); updateActionStatus(); } } void MainWindow::on_act_lastPage_triggered() { if (-1 != m_currIndex && m_multiPageCount > 0 && m_multiIndex != m_multiPageCount - 1) { m_multiIndex = m_multiPageCount - 1; HGImage img = createImage(); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); m_modify = false; } else { m_view->clearImage(); m_wndStatusBar->setMousePosInfo(0, 0); m_modify = false; } updateStatusBarPixelInfo(); updateActionStatus(); } } void MainWindow::on_act_adjust_triggered() { HGImage img = nullptr; m_view->getImage(&img); if (nullptr == img) { return; } Dialog_ImgProc_Adjust dlg(img, this); connect(&dlg, SIGNAL(applyToImage(HGImage)), this, SLOT(on_dialog_adjust_applyToImage(HGImage))); if (dlg.exec()) { m_view->addImage(dlg.getAfterImage()); m_modify = true; } else { m_view->addImage(dlg.getBeforeImage()); } updateStatusBarPixelInfo(); updateActionStatus(); if (auto_save_changes_) { on_act_save_triggered(); } disconnect(&dlg, SIGNAL(applyToImage(HGImage)), this, SLOT(on_dialog_adjust_applyToImage(HGImage))); } void MainWindow::on_act_open_triggered() { if (m_isScanning) { return; } QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, tr("Open images"), "", "(*.jpg *.jpeg *.png *.bmp *.ppm *.pgm *.pbm *.pdf *.tif *.tiff *.ofd *.gif)"); m_thumb->addItems(fileNames); } void MainWindow::on_act_insert_triggered() { if (m_isScanning) { return; } QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, tr("Insert images"), "", "(*.jpg *.jpeg *.png *.bmp *.ppm *.pgm *.pbm *.pdf *.tif *.tiff *.ofd *.gif)"); if (-1 != m_currIndex) m_thumb->insertItems(fileNames, m_currIndex); else m_thumb->addItems(fileNames); } void MainWindow::on_act_closeFile_triggered() { if (m_isScanning) { return; } std::vector selectIndexs; int count = 0; m_thumb->getItemCount(&count); for (int i = 0; i < count; ++i) { bool select = false; m_thumb->itemIsSelect(i, &select); if (select) selectIndexs.push_back(i); } if (selectIndexs.empty()) { return; } if (-1 != m_currIndex) { bool select = false; m_thumb->itemIsSelect(m_currIndex, &select); if (select) { startSaveMessageBox(this); } } m_thumb->removeItems(selectIndexs, HGImgThumb::ThumbRemoveFlag_NULL); } void MainWindow::on_act_closeAll_triggered() { if (m_isScanning) { return; } int count = 0; auto_save_info_.index = 0; auto_save_info_.path = ""; m_thumb->getItemCount(&count); if (0 == count) { return; } for(auto& v : wrong_imgs_) { v->hide(); remove(v->image_file().toStdString().c_str()); delete v; } wrong_imgs_.clear(); startSaveMessageBox(this); m_thumb->removeAllItems(HGImgThumb::ThumbRemoveFlag_NULL); } void MainWindow::on_act_exit_triggered() { close(); } void MainWindow::on_act_save_triggered() { HGImage img = nullptr; m_view->getImage(&img); if (nullptr == img || -1 == m_currIndex || 1 != m_multiPageCount) { return; } assert(!m_currFilePath.isEmpty()); if (0 == m_currFilePath.indexOf(Dialog_ClrCache::getCachePath())) { QString savePath; if (!auto_save_changes_) savePath = auto_save_info_.path; else savePath = m_currFilePath; int jpegQuality = auto_save_info_.jpegQuality; int tiffCompressionBW = auto_save_info_.tiffCompressionBW; int tiffCompression = auto_save_info_.tiffCompression; int tiffQuality = auto_save_info_.tiffQuality; bool isOcr = auto_save_info_.isOcr; bool find = false; int count = 0; if(!auto_save_changes_ || auto_save_info_.path.isEmpty() || !judgeDiskSpace(savePath)) { Dialog_SaveAs dlg(this); if(savePath.length()) { int pos = savePath.lastIndexOf('/'); if(pos > 0) dlg.set_current_directory(savePath.left(pos)); } if (!auto_save_changes_) { if (!dlg.exec()) { return; } } else savePath = m_currFilePath; if (!judgeDiskSpace(savePath)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } if (!auto_save_changes_) { savePath = auto_save_info_.path = dlg.getSavePath(); } isOcr = auto_save_info_.isOcr = dlg.isOcr(); jpegQuality = auto_save_info_.jpegQuality = dlg.getJpegQuality(); tiffQuality = auto_save_info_.tiffQuality = dlg.getTiffQuality(); tiffCompression = auto_save_info_.tiffCompression = dlg.getTiffCompression(); tiffCompressionBW = auto_save_info_.tiffCompressionBW = dlg.getTiffCompressionBW(); } if(auto_save_changes_ && save_from_changed_) { // appendix ... int pos = savePath.lastIndexOf('.'); char index[20] = {0}; if (!auto_save_changes_) { sprintf(index, "_%03u", ++auto_save_info_.index); } savePath.insert(pos, QString::fromStdString(index)); m_thumb->notify_mouse_leave(); } m_thumb->getItemCount(&count); for (int i = 0; i < count; ++i) { QString fileName; m_thumb->getItemFileName(i, fileName); assert(!fileName.isEmpty()); if (!auto_save_changes_) { if (fileName == savePath) { find = true; break; } } } if (!find) { HGImgFmtSaveInfo saveInfo; saveInfo.jpegQuality = (HGUInt)jpegQuality; saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; saveInfo.tiffJpegQuality = (HGUInt)tiffQuality; HGImageInfo imgInfo; HGBase_GetImageInfo(img, &imgInfo); if (HGBASE_IMGTYPE_BINARY == imgInfo.type) { if (1 == tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; } else { if (1 == tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; } if (HGBASE_ERR_OK == saveImage(img, &saveInfo, isOcr, getStdString(savePath).c_str())) { if (auto_save_changes_) { m_thumb->refreshItem(m_currIndex); } else m_thumb->updateItem(m_currIndex, savePath); m_currFilePath = savePath; m_modify = false; if(!auto_save_changes_) { QMessageBox::information(this, tr("tips"), tr("save succeed")); } } else { QMessageBox::critical(this, tr("tips"), tr("save failed")); m_dialogLog->addLog(tr("save failed"), true); m_wndStatusBar->setDeviceStatusInfo(tr("save failed"), true); } } else { QMessageBox::information(this, tr("tips"), tr("find savePath in thumbnail")); } return; } HGResult saveRet = HGBASE_ERR_FAIL; HGUInt fmtType = 0; HGImgFmt_GetImgFmtTypeFromFileName(getStdString(m_currFilePath).c_str(), &fmtType); if (HGIMGFMT_TYPE_TIFF == fmtType) { HGUInt compression = HGIMGFMT_TIFFCOMP_LZW; HGTiffReader tiffReader = nullptr; HGImgFmt_OpenTiffReader(getStdString(m_currFilePath).c_str(), &tiffReader); if (nullptr != tiffReader) { HGTiffLoadInfo tiffInfo; HGImgFmt_LoadImageFromTiffReader(tiffReader, 0, &tiffInfo, 0, 0, nullptr); compression = tiffInfo.compression; HGImgFmt_CloseTiffReader(tiffReader); } HGUInt xDpi, yDpi; HGBase_GetImageDpi(img, &xDpi, &yDpi); HGTiffSaveInfo tiffInfo; tiffInfo.compression = compression; tiffInfo.jpegQuality = 80; tiffInfo.resolutionUnit = HGIMGFMT_TIFFRESUNIT_INCH; tiffInfo.xResolution = xDpi; tiffInfo.yResolution = yDpi; HGTiffWriter tiffWriter = nullptr; HGImgFmt_OpenTiffWriter(getStdString(m_currFilePath).c_str(), &tiffWriter); if (nullptr != tiffWriter) { saveRet = HGImgFmt_SaveImageToTiffWriter(tiffWriter, img, &tiffInfo); HGImgFmt_CloseTiffWriter(tiffWriter); } } else { saveRet = HGImgFmt_SaveImage(img, 0, nullptr, getStdString(m_currFilePath).c_str()); } if (HGBASE_ERR_OK == saveRet) { if(auto_save_changes_ && save_from_changed_) m_thumb->notify_mouse_leave(); m_thumb->refreshItem(m_currFilePath); m_modify = false; updateActionStatus(); if(!auto_save_changes_) { QMessageBox::information(this, tr("tips"), tr("save succeed")); } } else { QMessageBox::critical(this, tr("tips"), tr("save failed")); } } void MainWindow::on_act_saveAs_triggered() { HGImage img = nullptr; m_view->getImage(&img); if (nullptr == img) { return; } Dialog_SaveAs dlg(this); if (dlg.exec()) { QString savePath = dlg.getSavePath(); if(!judgeDiskSpace(savePath)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } bool find = false; int count = 0; m_thumb->getItemCount(&count); for (int i = 0; i < count; ++i) { QString fileName; m_thumb->getItemFileName(i, fileName); assert(!fileName.isEmpty()); if (fileName == savePath) { find = true; break; } } if (!find) { int jpegQuality = dlg.getJpegQuality(); int tiffCompressionBW = dlg.getTiffCompressionBW(); int tiffCompression = dlg.getTiffCompression(); int tiffQuality = dlg.getTiffQuality(); bool isOcr = dlg.isOcr(); HGImgFmtSaveInfo saveInfo; saveInfo.jpegQuality = (HGUInt)jpegQuality; saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE; saveInfo.tiffJpegQuality = (HGUInt)tiffQuality; HGImageInfo imgInfo; HGBase_GetImageInfo(img, &imgInfo); if (HGBASE_IMGTYPE_BINARY == imgInfo.type) { if (1 == tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == tiffCompressionBW) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4; } else { if (1 == tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW; else if (2 == tiffCompression) saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG; } if (HGBASE_ERR_OK == saveImage(img, &saveInfo, isOcr, getStdString(savePath).c_str())) { if(!auto_save_changes_) { QMessageBox::information(this, tr("tips"), tr("save succeed")); } } else { QMessageBox::critical(this, tr("tips"), tr("save failed")); m_dialogLog->addLog(tr("save failed"), true); m_wndStatusBar->setDeviceStatusInfo(tr("save failed"), true); } } else { QMessageBox::information(this, tr("tips"), tr("find savePath in thumbnail")); } } } void MainWindow::on_act_Export_triggered() { int count = 0; m_thumb->getItemCount(&count); if (0 == count) { return; } std::vector selectIndexs; for (int i = 0; i < count; ++i) { bool select = false; m_thumb->itemIsSelect(i, &select); if (select) selectIndexs.push_back(i); } Dialog_Export dlg(count, selectIndexs, this); if (dlg.exec()) { QStringList srcFiles; std::vector saveIndexs; dlg.getSaveIndexs(saveIndexs); for (size_t i = 0; i < saveIndexs.size(); ++i) { QString fileName; m_thumb->getItemFileName(saveIndexs[i], fileName); srcFiles.append(fileName); if(!judgeDiskSpace(fileName)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } } if (!srcFiles.isEmpty()) { QString savePath = dlg.getSavePath(); QString saveName = dlg.getSaveName(); QString saveExt = dlg.getSaveExt(); bool isSaveAsMulti = dlg.isSaveAsMultiPage(); int jpegQuality = dlg.getJpegQuality(); int tiffCompressionBW = dlg.getTiffCompressionBW(); int tiffCompression = dlg.getTiffCompression(); int tiffQuality = dlg.getTiffQuality(); bool isOcr = dlg.isOcr(); Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality, tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this); dlgExport.exec(); } } } void MainWindow::on_act_imageInfo_triggered() { if (-1 == m_currIndex) { return; } assert(!m_currFilePath.isEmpty()); QFileInfo info(m_currFilePath); HGImage image = NULL; m_view->getImage(&image); if (nullptr == image) { return; } HGImageInfo imgInfo; HGBase_GetImageInfo(image, &imgInfo); HGUInt xDpi, yDpi; HGBase_GetImageDpi(image, &xDpi, &yDpi); QStringList fileKeys; fileKeys << tr("File name") << tr("File path") << tr("File size") << tr("Creation date/time") << tr("Modified date/time") << tr("Accessed date/time"); QStringList fileValues; fileValues.append(info.completeBaseName());//add Filename fileValues.append(info.absoluteFilePath());//add Filepath qint64 size_B = info.size(); QDateTime c_date = info.created(); QString createTime = c_date.toString("yyyy-MM-dd hh:mm:ss"); fileValues.append(createTime);//add File created time QDateTime m_date = info.lastModified(); QString modifiedTime = m_date.toString("yyyy-MM-dd hh:mm:ss"); fileValues.append(modifiedTime);//add File modified time QDateTime r_date = info.lastRead(); QString accessTime = r_date.toString("yyyy-MM-dd hh:mm:ss"); fileValues.append(accessTime);//add File access time double s = size_B; int unit = 0; while (true) { if (s > 1024.0) { s /= 1024.0; unit += 1; } else break; } QString unitstring = unit == 3 ? "GB" : (unit == 2 ? "MB" : (unit == 1 ? "KB" : "B")); QString sstring = QString::number(s, 'f', 2); QString Bstring = QString::number(size_B); int commaNum = Bstring.size() / 3; if (Bstring.size() % 3 == 0) commaNum -= 1; int offset = 0; for (int i = 0; i < commaNum; i++) { Bstring.insert(Bstring.size() - 3 - offset * 4, ","); offset += 1; } fileValues.insert(2, sstring + " " + unitstring + " (" + Bstring + ")");//add Filesize QStringList imageKeys; imageKeys << tr("Format") << tr("Width") << tr("Height") << tr("depth") << tr("Color model") << tr("DPI") << tr("Print size") << tr("Frame"); QStringList imageValues; imageValues.append(info.suffix());//add image format imageValues.append(QString::number(imgInfo.width));//add image width imageValues.append(QString::number(imgInfo.height));//add image height int depth = 1; if (HGBASE_IMGTYPE_GRAY == imgInfo.type) depth = 8; else if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_RGB == imgInfo.type) depth = 24; else if (HGBASE_IMGTYPE_BGRA == imgInfo.type || HGBASE_IMGTYPE_RGBA == imgInfo.type) depth = 32; imageValues.append(QString::number(depth));//add image depth imageValues.append(depth == 0 ? tr("None") : (depth == 1 ? tr("Mono") : (depth == 8 ? tr("Gray") : tr("Color"))));//add image color QString dpi = QString::number(xDpi) + " x " + QString::number(yDpi); imageValues.append(dpi);//add image dpi double cm_x = (0 == xDpi) ? 0 : 2.54 * imgInfo.width / xDpi; double cm_y = (0 == yDpi) ? 0 : 2.54 * imgInfo.height / yDpi; QString cm_printsize = QString::number(cm_x, 'f', 2) + " x " + QString::number(cm_y, 'f', 2) + " cm"; double inch_x = cm_x / 2.54; double inch_y = cm_y / 2.54; QString inch_printsize = QString::number(inch_x, 'f', 2) + " x " + QString::number(inch_y, 'f', 2) + " inches"; imageValues.append(cm_printsize + ", " + inch_printsize);//add image print size imageValues.append(QString::number(m_multiIndex)); Dialog_ImageInfo d(fileKeys, fileValues, imageKeys, imageValues, this); d.exec(); } void MainWindow::closeEvent(QCloseEvent *e) { if (m_isScanning) { QMessageBox::warning(this, tr("Warning"), tr("Device is Running!\nPlease finish scanning first.")); e->ignore(); return; } bool cache_saved = true; int count = 0; m_thumb->getItemCount(&count); for (int i = 0; i < count; ++i) { QString fileName; m_thumb->getItemFileName(i, fileName); if (0 == fileName.indexOf(Dialog_ClrCache::getCachePath())) { cache_saved = false; break; } } if(m_closeTip) { if (!cache_saved || m_modify) { QMessageBox msg(QMessageBox::Question, tr("Question"), tr("There are pictures that have not been saved.\nAre you sure to close?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if (msg.clickedButton() != msg.button(QMessageBox::Yes)) { e->ignore(); return; } } else { QMessageBox msg(QMessageBox::Question, tr("tips"), tr("Are you sure to close?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if (msg.clickedButton() != msg.button(QMessageBox::Yes)) { e->ignore(); return; } } } QDir dir = QDir(Dialog_ClrCache::getCachePath()); dir.removeRecursively(); QMainWindow::closeEvent(e); m_versionDll->PostUserCloseInfo(HGVERSION_APPNAME_SCANNER); } 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: { } break; case SANE_EVENT_ERROR: { QString errorInfo((char*)data); emit p->sane_dev_error(errorInfo); } break; case SANE_EVENT_WORKING: { QString workingInfo((char*)data); emit p->scan_working(workingInfo); } break; case SANE_EVENT_IMAGE_OK: { SANE_Image *sane_img = (SANE_Image *)data; HGUInt imgType = 0; if (sane_img->header.format == SANE_FRAME_GRAY) { if (1 == sane_img->header.depth) imgType = HGBASE_IMGTYPE_BINARY; else if (8 == sane_img->header.depth) imgType = HGBASE_IMGTYPE_GRAY; } else if (sane_img->header.format == SANE_FRAME_RGB) { imgType = HGBASE_IMGTYPE_RGB; } HGByte *imgData = sane_img->data; HGImageInfo imgInfo = {(HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines, imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP}; HGImage img = nullptr; HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, imgType, HGBASE_IMGORIGIN_TOP, &img); if (nullptr != img) { emit p->new_image(img, sane_img->flag.statu); } } break; case SANE_EVENT_SCAN_FINISHED: { int err = len ? (int)(*len) : 0; QString finishInfo((char*)data); emit p->scan_finish(finishInfo, err); } break; } return 0; } void HGAPI MainWindow::CrashFunc(HGPointer crashAddr, HGPointer param) { MainWindow *p = (MainWindow *)param; HGChar tmpName[256]; HGBase_GetTmpFileName("dmp", tmpName, 256); if (HGBASE_ERR_OK == HGBase_MakeCrashFile(tmpName)) { HGChar excpStr[64]; #ifdef HG_64BIT sprintf(excpStr, "0x%016p", crashAddr); #else sprintf(excpStr, "0x%08p", crashAddr); #endif p->m_versionDll->PostCrashInfo(HGVERSION_APPNAME_SCANNER, "crash", tmpName, excpStr); HGBase_DeleteFile(tmpName); } } void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer param) { MainWindow* p = (MainWindow*)param; int index = -1; for (int i = 0; i < (int)p->m_vFwUpgradeAndDevLock.size(); ++i) { if (p->m_currDeviceName.toStdString() == p->m_vFwUpgradeAndDevLock[i].m_devName) { index = i; break; } } if (-1 != index) { if (p->m_vFwUpgradeAndDevLock[index].m_checkFlag & FwUpgradeAndDevLock::FwUpgrade) { QString devType = GetDevType(p->m_devVersionNum); assert(!devType.isEmpty()); // 检查升级 HGVersionInfo* versionInfo = nullptr; HGUInt versionCount = 0; p->m_versionDll->GetDriverVersionList(devType.toStdString().c_str(), &versionInfo, &versionCount); if (versionCount > 0) { if ((std::string)(versionInfo[0].version) > p->m_devVersionNum.toStdString()) // 比较版本号 { HGChar suffix[64]; HGBase_GetFileSuffix(versionInfo[0].url, suffix, 64); HGChar savePath[512]; HGBase_GetConfigPath(savePath, 512); HGResult ret = HGBase_CreateDir(savePath); if(ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "create fwUpgrade file failed, %s", savePath); } HGChar fileName[128]; sprintf(fileName, "%s.%s", versionInfo[0].version, 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() || versionInfo[0].md5 != md5_2) { HGResult ret = p->m_versionDll->HttpDownload(versionInfo[0].url, savePath, NULL, NULL); if (HGBASE_ERR_OK == ret) { QFile saveFile(savePath); saveFile.open(QFile::ReadOnly); QByteArray fileMsg = saveFile.readAll(); saveFile.close(); QString md5_2 = QCryptographicHash::hash(fileMsg, QCryptographicHash::Md5).toHex(); if (versionInfo[0].md5 == md5_2) { p->m_vFwUpgradeAndDevLock[index].m_upgradeFilePath = savePath; p->m_vFwUpgradeAndDevLock[index].m_handleFlag |= FwUpgradeAndDevLock::FwUpgrade; } } } else { p->m_vFwUpgradeAndDevLock[index].m_upgradeFilePath = savePath; p->m_vFwUpgradeAndDevLock[index].m_handleFlag |= FwUpgradeAndDevLock::FwUpgrade; } } } p->m_versionDll->ReleaseVersionList(versionInfo, versionCount); p->m_vFwUpgradeAndDevLock[index].m_checkFlag &= ~FwUpgradeAndDevLock::FwUpgrade; } if (p->m_vFwUpgradeAndDevLock[index].m_checkFlag & FwUpgradeAndDevLock::DevLock) { // 检查锁定 HGBool inList = HGFALSE; HGResult ret = p->m_versionDll->BlackListCheck(p->m_devSerialNum.toStdString().c_str(), &inList); if (HGBASE_ERR_OK == ret) { p->m_vFwUpgradeAndDevLock[index].m_lock = inList; p->m_vFwUpgradeAndDevLock[index].m_handleFlag |= FwUpgradeAndDevLock::DevLock; } p->m_vFwUpgradeAndDevLock[index].m_checkFlag &= ~FwUpgradeAndDevLock::DevLock; } } // 发送信号 emit p->fwUpgradeAndDevLock_Finish(); } void MainWindow::on_act_multiRotate_triggered() { int count = 0; m_thumb->getItemCount(&count); if (0 == count) { return; } Dialog_MultiRotate dlg(this); if (dlg.exec()) { int rotateType = dlg.getRotateType(); int rotatePageType = dlg.getRotatePageType(); QStringList fileList; switch (rotatePageType) { case 0: { if (-1 != m_currIndex) { assert(!m_currFilePath.isEmpty()); fileList.append(m_currFilePath); } } break; case 1: { for (int i = 0; i < count; ++i) { bool selected = false; m_thumb->itemIsSelect(i, &selected); if (selected) { QString fileName; m_thumb->getItemFileName(i, fileName); fileList.append(fileName); } } } break; case 2: { for (int i = 0; i < count; ++i) { if ((i + 1) % 2 != 0) { QString fileName; m_thumb->getItemFileName(i, fileName); fileList.append(fileName); } } } break; case 3: { for (int i = 0; i < count; ++i) { if ((i + 1) % 2 == 0) { QString fileName; m_thumb->getItemFileName(i, fileName); fileList.append(fileName); } } } break; case 4: { for (int i = 0; i < count; ++i) { QString fileName; m_thumb->getItemFileName(i, fileName); fileList.append(fileName); } } break; } if (!fileList.isEmpty()) { Dialog_MultiRotateImageFile processDlg(fileList, rotateType, this); connect(&processDlg, SIGNAL(refreshImageFile(const QString &)), this, SLOT(on_dialog_multirotate_refreshImgFile(const QString &))); processDlg.exec(); disconnect(&processDlg, SIGNAL(refreshImageFile(const QString &)), this, SLOT(on_dialog_multirotate_refreshImgFile(const QString &))); } } } void MainWindow::on_act_autoCrop_triggered() { HGImage img = nullptr; m_view->getImage(&img); if (nullptr == img) { return; } Dialog_ImgProc_AutoCrop dlg(this); if (dlg.exec()) { bool isCrop = dlg.isCrop(); bool isDeskew = dlg.isDeskew(); bool isFillBlank = dlg.isFillBlank(); bool isConvex = dlg.isConvex(); bool isAutoColor = dlg.isAutoColor(); bool isUseAdvParam = dlg.isUseAdvancedParam(); int threshold = dlg.getThreshold(); int noise = dlg.getNoise(); int indent = dlg.getIndent(); HGImgAutoCropParam autoCropParam; autoCropParam.normalCrop = HGFALSE; autoCropParam.dispersion = HGTRUE; if (isFillBlank) { autoCropParam.convex = (HGBool)isConvex; autoCropParam.fillColor = (HGBool)isAutoColor; } else { autoCropParam.convex = HGTRUE; autoCropParam.fillColor = HGFALSE; } if (isUseAdvParam) { autoCropParam.threshold = threshold; autoCropParam.noise = noise; autoCropParam.indent = indent; } else { autoCropParam.threshold = 40.0; autoCropParam.noise = 8; autoCropParam.indent = 5; } if (isCrop || isDeskew || isFillBlank) { HGImageInfo imgInfo; HGBase_GetImageInfo(img, &imgInfo); HGImage destImage = nullptr; HGUInt destWidth = imgInfo.width; HGUInt destHeight = imgInfo.height; HGImgProc_ImageAutoCrop(img, (HGBool)isCrop, (HGBool)isDeskew, (HGBool)isFillBlank, &autoCropParam, destWidth, destHeight, imgInfo.type, HGBASE_IMGORIGIN_TOP, &destImage); if (nullptr != destImage) { m_view->addImage(destImage); HGBase_DestroyImage(destImage); m_modify = true; updateStatusBarPixelInfo(); updateActionStatus(); if (auto_save_changes_) { on_act_save_triggered(); } } } } } void MainWindow::on_act_signIn_triggered() { if (m_admin_loggedIn) { return; } Dialog_Admin dlg(m_password, this); m_admin_loggedIn = dlg.exec(); updateActionStatus(); if (m_admin_loggedIn) m_versionDll->PostUserLoginInfo(HGVERSION_APPNAME_SCANNER); } void MainWindow::on_act_passwordChange_triggered() { if (!m_admin_loggedIn) { return; } Dialog_PasswordChange dlg(m_password, this); if (dlg.exec()) { m_password = dlg.getNewPassword(); saveCfgValue("login", "password", passwordEncrypt(m_password)); } } void MainWindow::on_act_signOut_triggered() { if (!m_admin_loggedIn) { return; } QMessageBox msg(QMessageBox::Question, tr("Question"), tr("Sure to sign out administrator account?"), QMessageBox::Yes | QMessageBox::No); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if(msg.clickedButton() == msg.button(QMessageBox::Yes)) { m_admin_loggedIn = false; updateActionStatus(); m_versionDll->PostUserLogoutInfo(HGVERSION_APPNAME_SCANNER); } } void MainWindow::on_act_log_triggered() { if (!m_admin_loggedIn) { return; } Dialog_LogManager d(this); d.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); d.exec(); } void MainWindow::on_act_clrCache_triggered() { if (!m_admin_loggedIn) { return; } Dialog_ClrCache dlg(this); dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); connect(&dlg, SIGNAL(clearCache()), this, SLOT(on_clearCache())); dlg.exec(); disconnect(&dlg, SIGNAL(clearCache()), this, SLOT(on_clearCache())); } void MainWindow::on_act_consume_triggered() { if (!m_admin_loggedIn) { return; } } void MainWindow::on_act_clearRoller_triggered() { if (!m_admin_loggedIn) { return; } QMessageBox msg(QMessageBox::Question, tr("confirm operation"), tr("are you sure to clear the roller count?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if(msg.clickedButton() != msg.button(QMessageBox::Yes)) return; unsigned int count = 0; int ret = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_CLEAR_ROLLER_COUNT, nullptr, &count); if(ret == SANE_STATUS_GOOD) { QMessageBox::information(this, tr("hint"), tr("Roller scanned count has been set to 0.")); m_versionDll->PostDeviceClearRollerInfo(m_currDeviceName.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str()); } else QMessageBox::information(this, tr("hint"), tr("Roller scanned count reset failed.")); } void MainWindow::on_act_help_triggered() { #if defined(HG_CMP_MSC) #if defined(OEM_HANWANG) QString filename = QApplication::applicationDirPath() + "/HanvonScan_App_Help_manual.pdf"; #elif defined(OEM_LISICHENG) QString filename = QApplication::applicationDirPath() + "/LanxumScan_App_Help_manual.pdf"; #elif defined(OEM_CANGTIAN) QString filename = QApplication::applicationDirPath() + "/CumtennScan_App_Help_manual.pdf"; #else QString filename = QApplication::applicationDirPath() + "/HuaGoScan_App_Help_manual.pdf"; #endif #else #if defined (UOS) #if defined(OEM_HANWANG) QString filename = "/opt/apps/com.hanvonchina.hanvonscan/entries/help/HanvonScan_App_Help_manual.pdf"; #elif defined(OEM_LISICHENG) QString filename = "/opt/apps/com.lanxumchina.lanxumscan/entries/help/LanxumScan_App_Help_manual.pdf"; #elif defined(OEM_CANGTIAN) QString filename = "/opt/apps/com.cumtennchina.cumtennscan/entries/help/CumtennScan_App_Help_manual.pdf"; #else QString filename = "/opt/apps/com.huagaochina.huagoscan/entries/help/HuaGoScan_App_Help_manual.pdf"; #endif #elif defined(KYLIN) #if defined(OEM_HANWANG) QString filename = "/opt/apps/scanner-driver-hanvon/doc/HanvonScan_App_Help_manual.pdf"; #elif defined(OEM_LISICHENG) QString filename = "/opt/apps/scanner-driver-lanxum/doc/LanxumScan_App_Help_manual.pdf"; #elif defined(OEM_CANGTIAN) QString filename = "/opt/apps/scanner-driver-cumtenn/doc/CumtennScan_App_Help_manual.pdf"; #else QString filename = "/opt/apps/scanner-driver-huagao/doc/HuaGoScan_App_Help_manual.pdf"; #endif #else #if defined(OEM_HANWANG) QString filename = "/opt/apps/scanner-driver-hanvon/doc/HanvonScan_App_Help_manual.pdf"; #elif defined(OEM_LISICHENG) QString filename = "/opt/apps/scanner-driver-lanxum/doc/LanxumScan_App_Help_manual.pdf"; #elif defined(OEM_CANGTIAN) QString filename = "/opt/apps/scanner-driver-cumtenn/doc/CumtennScan_App_Help_manual.pdf"; #else QString filename = "/opt/apps/scanner-driver-huagao/doc/HuaGoScan_App_Help_manual.pdf"; #endif #endif #endif QFileInfo info(filename); if (!info.exists()) QMessageBox::warning(this, tr("Error"), tr("Document missing! It would be deleted or renamed.")); else QDesktopServices::openUrl(QUrl::fromLocalFile(filename)); } void MainWindow::my_url_handler(const QUrl& url) { std::string to(url.url().toStdString()); if(to.find("://clear-roller") != std::string::npos) { QMessageBox msg(QMessageBox::Question, tr("confirm the operation"), tr("Are you sure to clear the rollor acount?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if(msg.clickedButton() == msg.button(QMessageBox::Yes)) { unsigned int count = 0; int ret = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_CLEAR_ROLLER_COUNT, nullptr, &count); QString info; if(ret == SANE_STATUS_GOOD) { info = tr("Roller scanned count has been set to 0."); // +鐠囩兘鍣搁弬鎷岀箻閸忋儱鍙ф禍搴f櫕闂堫澀浜掗懢宄板絿閺堚偓閺傛澘鈧? info += tr("Please re-enter the Abount screen to obtain the latest value"); } else info = tr("Roller scanned count reset failed."); QMessageBox::information(this, tr("hint"), info); } } } void MainWindow::on_act_about_triggered() { QString company; QString appName; QString copyRight; QString developer; QString website; QString contact; QString afterSelesContact; QString address; QString navigation; SANE_About *about = nullptr; unsigned int len = 0; QString title(tr("About %1").arg(company)), content(tr("

%1

" "

Version: %2" "
CopyRight: © %3

" "

%4%5%6%7%8%9

") .arg(appName).arg("v2.0.9.061").arg(copyRight).arg(developer).arg(website).arg(contact).arg(afterSelesContact).arg(address).arg(navigation)); QDesktopServices::setUrlHandler(MY_URL_SCHEME, this, "my_url_handler"); if (sane_io_control(dev_que_.handle(), IO_CTRL_CODE_ABOUT_INFO, about, &len) == SANE_STATUS_NO_MEM) { about = (SANE_About*)malloc(len + 128); if (about) { memset(about, 0, len + 128); if (sane_io_control(dev_que_.handle(), IO_CTRL_CODE_ABOUT_INFO, about, &len) == SANE_STATUS_GOOD) { title = tr("about %1").arg(QString::fromStdString(about->title)); content = tr("

Version: %1

").arg(QString::fromStdString(about->version)); content += tr("

CopyRight: © %1

").arg(QString::fromStdString(about->copyright)); for (int i = 0; about->appendix[i].key; ++i) { if(about->appendix[i].url) content += tr("

%1: %3").arg(about->appendix[i].key).arg(about->appendix[i].url).arg(about->appendix[i].content); else content += tr("

%1: %2").arg(about->appendix[i].key).arg(about->appendix[i].content); if(m_admin_loggedIn && strcmp(about->appendix[i].key, tr("roller number").toLatin1().data()) == 0 && atoi(about->appendix[i].content) > 0) { char url[128] = {0}; sprintf(url, "        \346\270\205\351\231\244", MY_URL_SCHEME); content += QString::fromStdString(url); } content += "

"; } } free(about); } } QMessageBox::about(this, title, content); QDesktopServices::unsetUrlHandler(MY_URL_SCHEME); } void MainWindow::on_act_scannerSettings_triggered() { if (!dev_que_.is_online() || m_isScanning) { return; } hg_settingdialog dlg(dev_que_.handle(), this, &dev_que_); dlg.exec(); ui->menu_device->deviceMenuUpdate(&dev_que_); } void MainWindow::on_act_acquire_triggered() { if(!isLimitAccessFolder("")) { return; } if (!dev_que_.is_online() || m_isScanning) { return; } int count = 0; m_thumb->getItemCount(&count); if (count != 0) { int result = startScanMessageBox(this); if (cancelScan == result) return; } m_singleScan = false; m_scanType = 1; m_scanInsertPos = -1; if (!startSpaceCheck(this)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } startSaveMessageBox(this); m_dpi = getDpi(); SANE_Status ret = sane_start(dev_que_.handle()); if (ret != SANE_STATUS_GOOD) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); m_wndStatusBar->setDeviceStatusInfo(tr("start failed"), true); m_dialogLog->addLog(tr("start failed") + "(" + QString(sane_err_desc(ret)) + ")", true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(tr("start failed")).c_str()); if(ret == SCANNER_ERR_DEVICE_SLEEPING) { ui->menu_scan->setEnabled(false); ui->act_acquire->setEnabled(false); ui->act_scannerSettings->setEnabled(false); m_dialogLog->updateStatus(false, false); m_dialogLog->show(); QTime curTimer = QTime::currentTime().addMSecs(10000); while (QTime::currentTime() < curTimer) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } ui->menu_scan->setEnabled(true); ui->act_acquire->setEnabled(true); ui->act_scannerSettings->setEnabled(true); m_dialogLog->addLog(tr("already waked up device"), false); m_wndStatusBar->setDeviceStatusInfo(tr("already waked up device"), false); m_dialogLog->updateStatus(true, false); } } else { m_isScanning = true; m_thumb->setAcceptDrops(false); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); } m_dialogLog->show(); } void MainWindow::on_act_acquireSingle_triggered() { if(!isLimitAccessFolder("")) { return; } if (!dev_que_.is_online() || m_isScanning) { return; } int count = 0; m_thumb->getItemCount(&count); if (count != 0) { int result = startScanMessageBox(this); if (cancelScan == result) return; } m_singleScan = true; m_scanType = 1; m_scanInsertPos = -1; if (!startSpaceCheck(this)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } startSaveMessageBox(this); m_dpi = getDpi(); SANE_Status ret = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_TEST_SINGLE, nullptr, nullptr); if (ret != SANE_STATUS_GOOD) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); m_wndStatusBar->setDeviceStatusInfo(tr("start failed"), true); m_dialogLog->addLog(tr("start failed") + "(" + QString(sane_err_desc(ret)) + ")", true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(tr("start failed")).c_str()); if(ret == SCANNER_ERR_DEVICE_SLEEPING) { ui->menu_scan->setEnabled(false); ui->act_acquire->setEnabled(false); ui->act_scannerSettings->setEnabled(false); m_dialogLog->updateStatus(false, false); m_dialogLog->show(); QTime curTimer = QTime::currentTime().addMSecs(10000); while (QTime::currentTime() < curTimer) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } ui->menu_scan->setEnabled(true); ui->act_acquire->setEnabled(true); ui->act_scannerSettings->setEnabled(true); m_dialogLog->addLog(tr("already waked up device"), false); m_wndStatusBar->setDeviceStatusInfo(tr("already waked up device"), false); m_dialogLog->updateStatus(true, false); } } else { m_isScanning = true; m_thumb->setAcceptDrops(false); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); } m_dialogLog->show(); } void MainWindow::on_act_acquireInto_triggered() { if (!dev_que_.is_online() || m_isScanning) { return; } int count = 0; m_thumb->getItemCount(&count); if (count != 0) { int result = startScanMessageBox(this); if (cancelScan == result) return; } Dialog_AquireInto dlg(this); if (dlg.exec()) { m_singleScan = false; m_scanType = 2; m_aquireIntoSaveParam = dlg.getSaveParam(); m_aquireIntoInBlank = true; m_aquireIntoBatchStartIndex = 0; m_aquireIntoPageIndex = 0; m_aquireIntoMultiPageCount = 0; QDateTime dateTime = QDateTime::currentDateTime(); if (m_aquireIntoSaveParam.m_isUseSubfolderByTime) { m_aquireIntoSaveParam.m_savePath = getStdFileName(m_aquireIntoSaveParam.m_savePath + dateTime.toString("yyyy-MM-dd") + "/"); } // m_aquireIntoSaveParam.m_savePath = getStdFileName(m_aquireIntoSaveParam.m_savePath + dateTime.toString("yyyyMMddhhmmss") + "/"); if(!isLimitAccessFolder(m_aquireIntoSaveParam.m_savePath)) { return; } if (!startSpaceCheck(this)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } startSaveMessageBox(this); m_dpi = getDpi(); SANE_Status ret = sane_start(dev_que_.handle()); if (ret != SANE_STATUS_GOOD) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); m_wndStatusBar->setDeviceStatusInfo(tr("start failed"), true); m_dialogLog->addLog(tr("start failed") + "(" + QString(sane_err_desc(ret)) + ")", true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(tr("start failed")).c_str()); if(ret == SCANNER_ERR_DEVICE_SLEEPING) { ui->menu_scan->setEnabled(false); ui->act_acquire->setEnabled(false); ui->act_scannerSettings->setEnabled(false); m_dialogLog->updateStatus(false, false); m_dialogLog->show(); QTime curTimer = QTime::currentTime().addMSecs(10000); while (QTime::currentTime() < curTimer) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } ui->menu_scan->setEnabled(true); ui->act_acquire->setEnabled(true); ui->act_scannerSettings->setEnabled(true); m_dialogLog->addLog(tr("already waked up device"), false); m_wndStatusBar->setDeviceStatusInfo(tr("already waked up device"), false); m_dialogLog->updateStatus(true, false); } } else { m_isScanning = true; m_thumb->setAcceptDrops(false); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); } m_dialogLog->show(); } } void MainWindow::on_act_insertFromScanner_triggered() { if(!isLimitAccessFolder("")) { return; } if (!dev_que_.is_online() || m_isScanning) { return; } Dialog_InsertIndex dlg(this); if (dlg.exec()) { m_singleScan = false; m_scanType = 1; m_scanInsertPos = -1; int count = 0; m_thumb->getItemCount(&count); switch (dlg.selectedLocation()) { case 0: m_scanInsertPos = 0; break; case 1: if (-1 != m_currIndex) m_scanInsertPos = m_currIndex; break; case 2: if (-1 != m_currIndex) m_scanInsertPos = m_currIndex + 1; break; case 3: m_scanInsertPos = count; break; } if (!startSpaceCheck(this)) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); return; } startSaveMessageBox(this); m_dpi = getDpi(); SANE_Status ret = sane_start(dev_que_.handle()); if (ret != SANE_STATUS_GOOD) { m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); m_wndStatusBar->setDeviceStatusInfo(tr("start failed"), true); m_dialogLog->addLog(tr("start failed") + "(" + QString(sane_err_desc(ret)) + ")", true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(tr("start failed")).c_str()); if(ret == SCANNER_ERR_DEVICE_SLEEPING) { ui->menu_scan->setEnabled(false); ui->act_acquire->setEnabled(false); ui->act_scannerSettings->setEnabled(false); m_dialogLog->updateStatus(false, false); m_dialogLog->show(); QTime curTimer = QTime::currentTime().addMSecs(10000); while (QTime::currentTime() < curTimer) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } ui->menu_scan->setEnabled(true); ui->act_acquire->setEnabled(true); ui->act_scannerSettings->setEnabled(true); m_dialogLog->addLog(tr("already waked up device"), false); m_wndStatusBar->setDeviceStatusInfo(tr("already waked up device"), false); m_dialogLog->updateStatus(true, false); } } else { m_isScanning = true; m_thumb->setAcceptDrops(false); m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); } m_dialogLog->show(); } } void MainWindow::on_act_imageEdit_triggered() { HGImage img = nullptr; m_view->getImage(&img); if (nullptr == img) { return; } HGImageInfo info; HGBase_GetImageInfo(img, &info); QImage::Format fmt = QImage::Format_Invalid; if (info.type == HGBASE_IMGTYPE_BINARY) fmt = QImage::Format_Mono; else if (info.type == HGBASE_IMGTYPE_GRAY) fmt = QImage::Format_Grayscale8; else if (info.type == HGBASE_IMGTYPE_RGB) fmt = QImage::Format_RGB888; else if (info.type == HGBASE_IMGTYPE_RGBA) fmt = QImage::Format_RGBA8888; if (QImage::Format_Invalid == fmt) { return; } HGByte *data = nullptr; HGBase_GetImageData(img, &data); QImage image(data, (int)info.width, (int)info.height, (int)info.widthStep, fmt); if (image.isNull()) { return; } Dialog_ImageEditor dlg(this); dlg.setImage(image); if (dlg.exec()) { QImage image = dlg.exportImage(); if (!image.isNull()) { info.width = (HGUInt)image.width(); info.height = (HGUInt)image.height(); info.type = 0; if (QImage::Format_Mono == image.format()) info.type = HGBASE_IMGTYPE_BINARY; else if (QImage::Format_Grayscale8 == image.format()) info.type = HGBASE_IMGTYPE_GRAY; else if (QImage::Format_RGB888 == image.format()) info.type = HGBASE_IMGTYPE_RGB; else if (QImage::Format_RGBA8888 == image.format()) info.type = HGBASE_IMGTYPE_RGBA; info.widthStep = (HGUInt)image.bytesPerLine(); info.origin = HGBASE_IMGORIGIN_TOP; HGImage img = nullptr; HGBase_CreateImageWithData((HGByte *)image.bits(), &info, &img); if (nullptr != img) { m_view->addImage(img); HGBase_DestroyImage(img); m_modify = true; updateStatusBarPixelInfo(); updateActionStatus(); if (auto_save_changes_) { on_act_save_triggered(); } } } } } bool MainWindow::open_scanner(const QString& name, const QString& scheme) { bool ret = dev_que_.open_scanner(name.toStdString().c_str(), scheme.toStdString().c_str()) == SANE_STATUS_GOOD; QString info(tr("open scanner ") + " " + name + " "); QString title(tr("app name")); if(ret) { std::string serialNum; unsigned int serialNumLen = 0; if(SANE_STATUS_NO_MEM == sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_SERIAL, nullptr, &serialNumLen) && serialNumLen) { serialNum.resize(serialNumLen); sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_SERIAL, &serialNum[0], &serialNumLen); } m_devSerialNum = QString::fromStdString(serialNum.c_str()); std::string versionNum; unsigned int versionNumLen = 0; if(SANE_STATUS_NO_MEM == sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_HARDWARE_VERSION, nullptr, &versionNumLen) && versionNumLen) { versionNum.resize(versionNumLen); sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_HARDWARE_VERSION, &versionNum[0], &versionNumLen); } m_devVersionNum = QString::fromStdString(versionNum.c_str()); m_versionDll->PostDeviceOpenInfo(name.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str()); m_currDeviceName = name; upgradeFwAndLockDevice(); title = name; info += tr("success"); m_wndStatusBar->setDeviceStatusInfo(info, false); m_dialogLog->addLog(info, false); HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "%s", getStdString(info).c_str()); m_wndStatusBar->setDeviceStatusInfo(tr("be ready"), false); } else { info += tr("failed"); m_wndStatusBar->setDeviceStatusInfo(info, true); m_dialogLog->addLog(info, true); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "%s", getStdString(info).c_str()); } m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); // setWindowTitle(title); return ret; } bool MainWindow::judgeDiskSpace(QString currentPath) { QStorageInfo storage = QStorageInfo::root(); storage.refresh(); storage.device(); storage.setPath(currentPath); qint64 available_size = 0; available_size = storage.bytesAvailable()/1024/1024; if(available_size < 64) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "disk space is unsufficient!"); QMessageBox::warning(this, tr("warning"), tr("the disk space in the current path is unsufficient, please select a new path or clear the disk space in time.")); return false; } return true; } void MainWindow::upgradeApp(QString pkgPath) { HGChar moduleName[256]; HGBase_GetModuleName(nullptr, moduleName, 256); HGChar curPath2[256]; HGBase_GetFilePath(moduleName, curPath2, 256); QString curPath(curPath2); HGChar tmpPath2[256]; HGBase_GetTmpPath(tmpPath2, 256); QString tmpPath(tmpPath2); #if defined(HG_CMP_MSC) #if defined(OEM_HANWANG) QFile::remove(tmpPath + "HwUpgradeApp.exe"); QFile::copy(curPath + "HwUpgradeApp.exe", tmpPath + "HwUpgradeApp.exe"); QFile::remove(tmpPath + "HwBase.dll"); QFile::copy(curPath + "HwBase.dll", tmpPath + "HwBase.dll"); QFile::remove(tmpPath + "HwVersion.dll"); QFile::copy(curPath + "HwVersion.dll", tmpPath + "HwVersion.dll"); #elif defined(OEM_LISICHENG) QFile::remove(tmpPath + "LscUpgradeApp.exe"); QFile::copy(curPath + "LscUpgradeApp.exe", tmpPath + "LscUpgradeApp.exe"); QFile::remove(tmpPath + "LscBase.dll"); QFile::copy(curPath + "LscBase.dll", tmpPath + "LscBase.dll"); QFile::remove(tmpPath + "LscVersion.dll"); QFile::copy(curPath + "LscVersion.dll", tmpPath + "LscVersion.dll"); #elif defined(OEM_CANGTIAN) QFile::remove(tmpPath + "CtsUpgradeApp.exe"); QFile::copy(curPath + "CtsUpgradeApp.exe", tmpPath + "CtsUpgradeApp.exe"); QFile::remove(tmpPath + "CtsBase.dll"); QFile::copy(curPath + "CtsBase.dll", tmpPath + "CtsBase.dll"); QFile::remove(tmpPath + "CtsVersion.dll"); QFile::copy(curPath + "CtsVersion.dll", tmpPath + "CtsVersion.dll"); #else QFile::remove(tmpPath + "HGUpgradeApp.exe"); QFile::copy(curPath + "HGUpgradeApp.exe", tmpPath + "HGUpgradeApp.exe"); QFile::remove(tmpPath + "HGBase.dll"); QFile::copy(curPath + "HGBase.dll", tmpPath + "HGBase.dll"); QFile::remove(tmpPath + "HGVersion.dll"); QFile::copy(curPath + "HGVersion.dll", tmpPath + "HGVersion.dll"); #endif QFile::remove(tmpPath + "msvcp140.dll"); QFile::copy(curPath + "msvcp140.dll", tmpPath + "msvcp140.dll"); QFile::remove(tmpPath + "Qt5Core.dll"); QFile::copy(curPath + "Qt5Core.dll", tmpPath + "Qt5Core.dll"); QFile::remove(tmpPath + "Qt5Gui.dll"); QFile::copy(curPath + "Qt5Gui.dll", tmpPath + "Qt5Gui.dll"); QFile::remove(tmpPath + "Qt5Widgets.dll"); QFile::copy(curPath + "Qt5Widgets.dll", tmpPath + "Qt5Widgets.dll"); QFile::remove(tmpPath + "vcruntime140.dll"); QFile::copy(curPath + "vcruntime140.dll", tmpPath + "vcruntime140.dll"); QDir dir; dir.mkdir(tmpPath + "platforms"); QFile::remove(tmpPath + "platforms/qwindows.dll"); QFile::copy(curPath + "platforms/qwindows.dll", tmpPath + "platforms/qwindows.dll"); dir.mkdir(tmpPath + "imageformats"); QFile::remove(tmpPath + "imageformats/qgif.dll"); QFile::copy(curPath + "imageformats/qgif.dll", tmpPath + "imageformats/qgif.dll"); #else #if defined(OEM_HANWANG) QFile::remove(tmpPath + "HwUpgradeApp"); QFile::copy(curPath + "HwUpgradeApp", tmpPath + "HwUpgradeApp"); //QFile::remove(tmpPath + "libHwBase.so"); //QFile::copy(curPath + "libHwBase.so", tmpPath + "libHwBase.so"); //QFile::remove(tmpPath + "libHwVersion.so"); //QFile::copy(curPath + "libHwVersion.so", tmpPath + "libHwVersion.so"); #elif defined(OEM_LISICHENG) QFile::remove(tmpPath + "LscUpgradeApp"); QFile::copy(curPath + "LscUpgradeApp", tmpPath + "LscUpgradeApp"); //QFile::remove(tmpPath + "libLscBase.so"); //QFile::copy(curPath + "libLscBase.so", tmpPath + "libLscBase.so"); //QFile::remove(tmpPath + "libLscVersion.so"); //QFile::copy(curPath + "libLscVersion.so", tmpPath + "libLscVersion.so"); #elif defined(OEM_CANGTIAN) QFile::remove(tmpPath + "CtsUpgradeApp"); QFile::copy(curPath + "CtsUpgradeApp", tmpPath + "CtsUpgradeApp"); //QFile::remove(tmpPath + "libCtsBase.so"); //QFile::copy(curPath + "libCtsBase.so", tmpPath + "libCtsBase.so"); //QFile::remove(tmpPath + "libCtsVersion.so"); //QFile::copy(curPath + "libCtsVersion.so", tmpPath + "libCtsVersion.so"); #else QFile::remove(tmpPath + "HGUpgradeApp"); QFile::copy(curPath + "HGUpgradeApp", tmpPath + "HGUpgradeApp"); //QFile::remove(tmpPath + "libHGBase.so"); //QFile::copy(curPath + "libHGBase.so", tmpPath + "libHGBase.so"); //QFile::remove(tmpPath + "libHGVersion.so"); //QFile::copy(curPath + "libHGVersion.so", tmpPath + "libHGVersion.so"); #endif #endif QProcess proc; bool isSuccessdStart = false; QStringList argList; argList.push_back(QString("-appName=%1").arg(HGVERSION_APPNAME_SCANNER)); argList.push_back(QString("-pkgpath=%1").arg(pkgPath.toStdString().c_str())); argList.push_back(QString("-type=%1").arg("upgrade")); #if defined(HG_CMP_MSC) #if defined(OEM_HANWANG) isSuccessdStart = proc.startDetached(tmpPath + "HwUpgradeApp.exe", argList); #elif defined(OEM_LISICHENG) isSuccessdStart = proc.startDetached(tmpPath + "LscUpgradeApp.exe", argList); #elif defined(OEM_CANGTIAN) isSuccessdStart = proc.startDetached(tmpPath + "CtsUpgradeApp.exe", argList); #else isSuccessdStart = proc.startDetached(tmpPath + "HGUpgradeApp.exe", argList); #endif #else #if defined(OEM_HANWANG) isSuccessdStart = proc.startDetached(tmpPath + "HwUpgradeApp", argList); #elif defined(OEM_LISICHENG) isSuccessdStart = proc.startDetached(tmpPath + "LscUpgradeApp", argList); #elif defined(OEM_CANGTIAN) isSuccessdStart = proc.startDetached(tmpPath + "CtsUpgradeApp", argList); #else isSuccessdStart = proc.startDetached(tmpPath + "HGUpgradeApp", argList); #endif #endif if (isSuccessdStart) { m_closeTip = false; close(); } else { QMessageBox msg(QMessageBox::Critical, tr("error"), tr("start failed!"), QMessageBox::Ok, this); msg.setButtonText(QMessageBox::Ok, tr("yes")); msg.exec(); } } bool MainWindow::isLimitAccessFolder(QString filePath) { HGChar documentsPath[512]; HGBase_GetDocumentsPath(documentsPath, 512); HGChar procName[512]; HGBase_GetProcessName(procName, 512); strcat(documentsPath, procName); HGResult ret = HGBase_CreateDir(getStdString(documentsPath).c_str()); if (ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "Mainwindow::isLimitAccessFolder(), create documentsPath1 file failed, %s", getStdString(documentsPath).c_str()); } HGChar uuid[512]; HGBase_GetUuid(uuid, 512); strcat(documentsPath, "/"); strcat(documentsPath, uuid); HGResult result = HGBase_CreateDir(getStdString(documentsPath).c_str()); if(result != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "Mainwindow::isLimitAccessFolder(), create documentsPath2 file failed, %s", getStdString(documentsPath).c_str()); if(!filePath.isEmpty()) { HGChar uuid2[512]; HGBase_GetUuid(uuid2, 512); filePath += uuid2; HGResult result2 = HGBase_CreateDir(getStdString(filePath).c_str()); if (result2 != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "Mainwindow::isLimitAccessFolder(), create scanPath3 file failed, %s", getStdString(filePath).c_str()); QMessageBox::critical(this, tr("error"), tr("folder limit")); m_dialogLog->addLog(tr("folder limit"), true); m_wndStatusBar->setDeviceStatusInfo(tr("folder limit"), true); return false; } else { HGBase_DeleteDir(getStdString(filePath).c_str()); } return true; } QMessageBox::critical(this, tr("error"), tr("folder limit")); m_dialogLog->addLog(tr("folder limit"), true); m_wndStatusBar->setDeviceStatusInfo(tr("folder limit"), true); return false; } else { HGBase_DeleteDir(getStdString(documentsPath).c_str()); } return true; } QString MainWindow::GetDevType(const QString& fwVersion) { 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 <= "A1225") devType = dev + ver + "/" + "A1220-A1225"; else if (date >= "B0326" && date <= "B0331") devType = dev + ver + "/" + "B0326-B0331"; else if (date >= "B0429") devType = dev + ver + "/" + "B0429-"; } else if (dev == "G4" && ver == "393") { devType = dev + ver + "/"; } } } return devType; } void MainWindow::upgradeFwAndLockDevice() { if (NULL == m_threadFwUpgradeAndDevLock) { int index = -1; for (int i = 0; i < (int)m_vFwUpgradeAndDevLock.size(); ++i) { if (m_currDeviceName.toStdString() == m_vFwUpgradeAndDevLock[i].m_devName) { index = i; break; } } if (-1 == index) { FwUpgradeAndDevLock o(m_currDeviceName.toStdString()); //QString devType = GetDevType(m_devVersionNum); //if (!devType.isEmpty()) // o.m_checkFlag |= FwUpgradeAndDevLock::FwUpgrade; m_vFwUpgradeAndDevLock.push_back(o); index = m_vFwUpgradeAndDevLock.size() - 1; } assert(index != -1); if (0 != m_vFwUpgradeAndDevLock[index].m_checkFlag) { assert(0 == m_vFwUpgradeAndDevLock[index].m_handleFlag); HGBase_OpenThread(FwUpgradeAndDevLockThread, this, &m_threadFwUpgradeAndDevLock); assert(NULL != m_threadFwUpgradeAndDevLock); } else if (0 != m_vFwUpgradeAndDevLock[index].m_handleFlag) { assert(0 == m_vFwUpgradeAndDevLock[index].m_checkFlag); if (m_vFwUpgradeAndDevLock[index].m_handleFlag & FwUpgradeAndDevLock::FwUpgrade) { const char* path = m_vFwUpgradeAndDevLock[index].m_upgradeFilePath.c_str(); Dialog_upgradeFirmware dlg(dev_que_.handle(), path, this); if(dlg.exec()) { if (SANE_STATUS_GOOD == dlg.getUpgradeStatus()) { m_vFwUpgradeAndDevLock[index].m_handleFlag &= ~FwUpgradeAndDevLock::FwUpgrade; } } } else if (m_vFwUpgradeAndDevLock[index].m_handleFlag & FwUpgradeAndDevLock::DevLock) { SANE_Bool b = m_vFwUpgradeAndDevLock[index].m_lock; SANE_Bool b2 = SANE_FALSE; unsigned int len = sizeof(SANE_Bool); sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_SCAN_ISLOCK, &b2, &len); if (b2 == b) { m_vFwUpgradeAndDevLock[index].m_handleFlag &= ~FwUpgradeAndDevLock::DevLock; } else { if (SANE_STATUS_GOOD == sane_io_control(dev_que_.handle(), IO_CTRL_CODE_SET_SCAN_LOCK, &b, NULL)) { m_versionDll->PostDeviceLockInfo(m_currDeviceName.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str(), b); } } } } } } //void MainWindow::deleteFile(QString filePath) //{ // QDir dir(filePath); // if(!dir.exists()) // { // return; // } // dir.setFilter(QDir::Files | QDir::NoSymLinks); // QFileInfoList list = dir.entryInfoList(); // int count = list.count(); // if(count <= 0) // { // return; // } // for(int i=0; i < count; i++) // { // QFileInfo info = list.at(i); // QString suffix = info.suffix(); // if(QString::compare(suffix, QString("exe"), Qt::CaseInsensitive) == 0) // { // QDateTime nowTime = QDateTime::currentDateTime(); // QDateTime createTime = info.created(); // int days = createTime.daysTo(nowTime); // if (days > 14) // { // HGBase_DeleteFile(info.absoluteFilePath().c_str()); // } // } // } //} void MainWindow::on_scanOptions_changed(const QString &device, const QString &option, bool checked_now) { QString title(tr("app name")); if(checked_now) { std::string curdev(dev_que_.opened_scanner_name()); int ret = 0; if(curdev != device.toStdString()) { //ret = dev_que_.open_scanner(device.toStdString().c_str(), option.toStdString().c_str()); open_scanner(device, option); return; } else { ret = dev_que_.apply_scheme(option.toStdString().c_str()); } QString info(tr("apply setting") + " '" + option + "' "); if(ret == 0) { info += tr("success"); } else { ui->menu_device->setOptionChecked(device, option, false); info += tr("failed"); } m_wndStatusBar->setDeviceStatusInfo(info, ret != 0); m_dialogLog->addLog(info, ret != 0); HGBase_WriteInfo(ret != 0 ? HGBASE_INFOTYPE_ERROR : HGBASE_INFOTYPE_DESC, "%s", getStdString(info).c_str()); title = device + "(" + option + ")"; } else { QMessageBox msg(QMessageBox::Question, title, tr("Are you sure to close ") + device + tr(" ?"), QMessageBox::Yes | QMessageBox::No, this); msg.setButtonText(QMessageBox::Yes, tr("yes")); msg.setButtonText(QMessageBox::No, tr("no")); msg.exec(); if(msg.clickedButton() == msg.button(QMessageBox::Yes)) { dev_que_.close_scanner(); m_versionDll->PostDeviceCloseInfo(device.toStdString().c_str(), m_devSerialNum.toStdString().c_str(), "", m_devVersionNum.toStdString().c_str()); m_dialogLog->addLog(tr("close ") + device, false); m_wndStatusBar->setDeviceStatusInfo(tr("close ") + device, false); } else { ui->menu_device->setOptionChecked(device, option, true); return; } } m_dialogLog->updateStatus(dev_que_.is_online() && 0 != m_scanType, m_isScanning); updateActionStatus(); // setWindowTitle(title); } void MainWindow::on_act_sortPages_triggered() { if (dev_que_.is_online() && m_isScanning) { return; } m_thumb->bookSort(); } void MainWindow::on_actionact_update_triggered() { HGVersionInfo *versionInfo = NULL; HGUInt versionCount = 0; HGResult ret = m_versionDll->GetVersionList(HGVERSION_APPNAME_SCANNER, &versionInfo, &versionCount); if (ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "GetVersionList:%u", ret); } if(versionCount > 0) { Dialog_upgrade dlg(m_versionDll, versionInfo, versionCount, this); if (dlg.exec()) { QString url, md5; QString versionNum = dlg.getVersionNum(); for (HGUInt i = 0; i < versionCount; ++i) { if (versionNum == versionInfo[i].version) { url = versionInfo[i].url; md5 = versionInfo[i].md5; break; } } assert(!url.isEmpty() && !md5.isEmpty()); HGChar suffix[64]; HGBase_GetFileSuffix(url.toStdString().c_str(), suffix, 64); HGChar savePath[512]; HGBase_GetConfigPath(savePath, 512); HGResult ret = HGBase_CreateDir(savePath); if(ret != HGBASE_ERR_OK) { HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "create upgrade app savefile failed, %s", savePath); } HGChar fileName[128]; sprintf(fileName, "%s.%s", versionNum.toStdString().c_str(), 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_versionDll, 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) { upgradeApp(savePath); } } } else { upgradeApp(savePath); } } } else { QMessageBox::information(this, tr("tip"), tr("Other versions not available")); } m_versionDll->ReleaseVersionList(versionInfo, versionCount); } void MainWindow::on_act_feedback_triggered() { Dialog_Feedback dlg(m_versionDll, this); dlg.exec(); } void MainWindow::on_act_driver_log_triggered() { char log_file_path[260] = {0}; unsigned int type = SANE_LogFileType::LOG_FILE_DRIVER; SANE_Status statu = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_LOG_FILE, log_file_path, &type); if(statu == SANE_STATUS_GOOD) { if(log_file_path[0]) QDesktopServices::openUrl(QUrl::fromLocalFile(log_file_path)); } else { if(statu == SANE_STATUS_UNSUPPORTED) // 鐠佹儳顦稉宥嗘暜閹镐浇顕氶幙宥勭稊 QMessageBox::information(this, windowTitle(), tr("The device does not support this operation")); else QMessageBox::information(this, windowTitle(), tr("IO error")); // IO闁挎瑨顕? } } void MainWindow::on_act_device_log_triggered() { char log_file_path[260] = {0}; unsigned int type = SANE_LogFileType::LOG_FILE_DEVICE; SANE_Status statu = sane_io_control(dev_que_.handle(), IO_CTRL_CODE_GET_LOG_FILE, log_file_path, &type); if(statu == SANE_STATUS_GOOD) { if(log_file_path[0]) QDesktopServices::openUrl(QUrl::fromLocalFile(log_file_path)); } else { if(statu == SANE_STATUS_UNSUPPORTED) QMessageBox::information(this, windowTitle(), tr("The device does not support this operation")); else QMessageBox::information(this, windowTitle(), tr("IO error")); } }