2022-11-23 10:39:06 +00:00
# include "mainwindow.h"
2022-05-03 10:25:52 +00:00
# include "ui_mainwindow.h"
# include <QDockWidget>
# include <QFileDialog>
# include <QMessageBox>
# include <QDateTime>
# include <QLineEdit>
# include <QRegExpValidator>
# include <QStandardPaths>
# include <QDesktopServices>
# 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"
2022-07-07 08:16:41 +00:00
# include "dialog_updateprogress.h"
2022-07-18 08:59:12 +00:00
# include "dialog_upgrade.h"
2022-07-20 09:30:27 +00:00
# include "dialog_feedback.h"
2022-11-06 08:00:48 +00:00
# include "dialog_upgradefirmware.h"
2023-02-16 07:17:41 +00:00
# include "dialog_savemessagebox.h"
2022-05-03 10:25:52 +00:00
# include "hg_settingdialog.h"
# include "base/HGInfo.h"
2022-08-22 07:25:37 +00:00
# include "huagao/hgscanner_error.h"
2022-05-03 10:25:52 +00:00
# include "imgfmt/HGPdf.h"
2022-05-13 12:38:58 +00:00
# include "imgfmt/HGTiff.h"
2022-05-03 10:25:52 +00:00
# include "imgfmt/HGImgFmt.h"
# include "imgproc/HGImgProc.h"
2022-05-16 09:00:08 +00:00
# include "imgproc/HGOCR.h"
2022-05-03 10:25:52 +00:00
# include "base/HGUtility.h"
2022-07-14 10:45:35 +00:00
# include "base/HGCrash.h"
2022-05-03 10:25:52 +00:00
# include "HGUIGlobal.h"
2022-05-19 10:11:56 +00:00
# include "HGString.h"
2022-05-03 10:25:52 +00:00
# include "app_cfg.h"
2022-05-24 05:45:07 +00:00
# include <assert.h>
2022-07-23 08:54:56 +00:00
# include "dialog_wrong_img.h"
2023-02-03 09:38:13 +00:00
# include "../../code_device/hgdriver/hgdev/char_const.h"
# include "lang/app_language.h"
2023-02-17 01:20:12 +00:00
# include "ocrPdf.h"
2022-05-03 10:25:52 +00:00
# define PASSWORD_KEY 4
2022-05-10 10:15:37 +00:00
# define MY_URL_SCHEME "inscanner"
2022-05-03 10:25:52 +00:00
2023-01-29 03:18:42 +00:00
MainWindow : : MainWindow ( const QString & appLang , QWidget * parent )
2022-05-03 10:25:52 +00:00
: QMainWindow ( parent )
, ui ( new Ui : : MainWindow )
2023-01-28 07:32:08 +00:00
, m_currLang ( appLang )
, m_versionDll ( nullptr )
2022-05-03 10:25:52 +00:00
, m_admin_loggedIn ( false )
2022-05-20 10:44:24 +00:00
, m_dpi ( 200 )
2022-05-03 10:25:52 +00:00
, m_currFilePath ( " " )
, m_currIndex ( - 1 )
, m_multiPageCount ( 0 )
, m_multiIndex ( - 1 )
, m_modify ( false )
, m_singleScan ( false )
, m_scanType ( 0 )
, m_scanInsertPos ( - 1 )
2023-04-13 01:43:57 +00:00
, m_saveType ( 0 )
2022-05-03 10:25:52 +00:00
, m_scanFileName ( " " )
, m_scanImgFmtWriter ( nullptr )
, m_isScanning ( false )
2022-06-02 10:27:14 +00:00
, auto_save_changes_ ( false )
, save_from_changed_ ( false )
2022-07-14 11:13:00 +00:00
, m_closeTip ( true )
2022-07-30 01:27:43 +00:00
, m_currScanCount ( 0 )
2022-07-27 10:41:21 +00:00
, m_devSerialNum ( " " )
, m_devVersionNum ( " " )
2022-07-28 09:22:27 +00:00
, m_currDeviceName ( " " )
2022-11-24 15:48:08 +00:00
, m_cacheDirNotify ( false )
, m_AquirePathNotify ( false )
2023-04-08 08:33:36 +00:00
, m_bSideflag ( false )
2023-04-08 10:43:46 +00:00
, m_bSideEditing ( false )
2022-05-03 10:25:52 +00:00
{
ui - > setupUi ( this ) ;
2023-02-22 07:33:25 +00:00
m_versionDll = new VersionDll ;
2022-07-14 10:45:35 +00:00
HGBase_RegisterCrashFunc ( CrashFunc , this ) ;
2022-11-29 06:00:50 +00:00
HGChar logFilePath [ 512 ] ;
HGBase_GetLogFilePath ( logFilePath , 512 ) ;
2022-11-29 07:42:18 +00:00
deleteOverdueLogFile ( QString : : fromStdString ( getStdString ( logFilePath ) ) ) ;
2022-11-23 10:39:06 +00:00
2022-11-29 06:00:50 +00:00
HGChar cfgFilePath [ 512 ] ;
HGBase_GetConfigPath ( cfgFilePath , 512 ) ;
2022-11-29 07:42:18 +00:00
deleteUpgradePkg ( QString : : fromStdString ( getStdString ( cfgFilePath ) ) ) ;
2022-11-23 10:39:06 +00:00
2022-05-17 03:59:09 +00:00
# if defined(OEM_HANWANG)
this - > setWindowIcon ( QIcon ( " :images/image_rsc/logo/Hanvon_logo1.ico " ) ) ;
this - > setWindowTitle ( tr ( " HanvonScan " ) ) ;
2023-01-13 05:56:24 +00:00
m_oemName = HGVERSION_OEMNAME_HANVON ;
2022-05-17 10:09:21 +00:00
# elif defined(OEM_LISICHENG)
2022-05-17 03:59:09 +00:00
this - > setWindowIcon ( QIcon ( " :images/image_rsc/logo/Lanxum_logo.ico " ) ) ;
this - > setWindowTitle ( tr ( " LanxumScan " ) ) ;
2023-01-13 05:56:24 +00:00
m_oemName = HGVERSION_OEMNAME_LANXUM ;
2022-11-10 01:11:57 +00:00
# elif defined(OEM_CANGTIAN)
this - > setWindowIcon ( QIcon ( " :images/image_rsc/logo/Cumtenn_logo.ico " ) ) ;
this - > setWindowTitle ( tr ( " CumtennScan " ) ) ;
2023-01-13 05:56:24 +00:00
m_oemName = HGVERSION_OEMNAME_CUMTENN ;
2023-01-29 09:02:57 +00:00
# elif defined(OEM_ZHONGJING)
this - > setWindowIcon ( QIcon ( " :images/image_rsc/logo/Microtek_logo.ico " ) ) ;
this - > setWindowTitle ( tr ( " MicrotekScan " ) ) ;
m_oemName = HGVERSION_OEMNAME_MICROTEK ;
2023-03-10 05:39:50 +00:00
# elif defined(OEM_ZIGUANG)
this - > setWindowIcon ( QIcon ( " :images/image_rsc/logo/uniscan.ico " ) ) ;
this - > setWindowTitle ( tr ( " UniScan " ) ) ;
2023-03-10 10:31:39 +00:00
m_oemName = HGVERSION_OEMNAME_UNIS ;
2022-05-17 03:59:09 +00:00
# else
2022-05-03 10:25:52 +00:00
this - > setWindowIcon ( QIcon ( " :images/image_rsc/logo/logo.ico " ) ) ;
this - > setWindowTitle ( tr ( " HuaGoScan " ) ) ;
2023-01-13 05:56:24 +00:00
m_oemName = HGVERSION_OEMNAME_HUAGO ;
2022-05-17 03:59:09 +00:00
# endif
2022-07-13 11:01:42 +00:00
2022-05-03 10:25:52 +00:00
this - > setAutoFillBackground ( true ) ;
2022-05-18 10:05:10 +00:00
this - > setPalette ( QPalette ( QColor ( 230 , 230 , 230 ) ) ) ;
2022-06-15 03:04:47 +00:00
QDesktopWidget * desktopWidget = QApplication : : desktop ( ) ;
QRect screenRect = desktopWidget - > screenGeometry ( this ) ;
2022-06-15 09:37:41 +00:00
if ( screenRect . width ( ) > 950 & & screenRect . height ( ) > 720 )
2022-06-15 03:04:47 +00:00
{
resize ( 950 , 720 ) ;
}
2022-05-03 10:25:52 +00:00
2023-02-22 07:18:06 +00:00
ui - > actionact_update - > setVisible ( false ) ;
ui - > act_feedback - > setVisible ( false ) ;
# if defined(OEM_HUAGAO)
if ( m_versionDll - > IsValid ( ) )
2022-07-27 03:32:46 +00:00
{
2023-02-22 07:18:06 +00:00
ui - > actionact_update - > setVisible ( true ) ;
ui - > act_feedback - > setVisible ( true ) ;
2023-01-13 05:56:24 +00:00
m_versionDll - > PostUserOpenInfo ( HGVERSION_APPNAME_SCANNER , m_oemName ) ;
2022-07-27 03:32:46 +00:00
}
2023-02-22 07:18:06 +00:00
# endif
2022-07-07 08:16:41 +00:00
2022-10-28 01:03:22 +00:00
HGChar cfgpath [ 512 ] = { 0 } ;
QString old ;
HGBase_GetConfigPath ( cfgpath , _countof ( cfgpath ) - 1 ) ;
2023-01-28 02:57:18 +00:00
HGBase_CreateDir ( cfgpath ) ;
2022-10-28 01:03:22 +00:00
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 ( ) ) ;
2022-05-03 10:25:52 +00:00
ui - > toolBar - > addAction ( ui - > act_scannerSettings ) ;
ui - > toolBar - > addAction ( ui - > act_acquire ) ;
2023-03-10 09:26:03 +00:00
m_act_acquireInto2 = new QAction ( QIcon ( " :/images/image_rsc/actions/scanInto.png " ) , tr ( " act_acquireInto " ) , this ) ;
2023-03-06 09:01:57 +00:00
connect ( m_act_acquireInto2 , SIGNAL ( triggered ( ) ) , this , SLOT ( on_AcquireInto2 ( ) ) ) ;
ui - > toolBar - > addAction ( m_act_acquireInto2 ) ;
2022-05-03 10:25:52 +00:00
ui - > toolBar - > addSeparator ( ) ;
2023-03-31 07:22:07 +00:00
initAcquireIntoComboBox ( ) ;
2022-05-03 10:25:52 +00:00
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 ) ;
2022-05-16 06:38:22 +00:00
ui - > toolBar - > addAction ( ui - > act_sortPages ) ;
2022-05-03 10:25:52 +00:00
ui - > toolBar - > addSeparator ( ) ;
ui - > toolBar - > addAction ( ui - > act_help ) ;
2023-01-30 07:03:30 +00:00
# if defined (OEM_ZHONGJING)
2023-01-28 07:32:08 +00:00
m_menu_language = new QMenu ( tr ( " menu_language " ) ) ;
2023-01-29 07:24:02 +00:00
m_act_simpCN = new QAction ( tr ( " act_simpCN " ) , nullptr ) ;
m_act_English = new QAction ( tr ( " act_English " ) , nullptr ) ;
2023-01-28 02:57:18 +00:00
m_act_simpCN - > setCheckable ( true ) ;
m_act_English - > setCheckable ( true ) ;
2023-01-28 07:32:08 +00:00
ui - > menu_info - > addMenu ( m_menu_language ) ;
m_menu_language - > addAction ( m_act_simpCN ) ;
m_menu_language - > addAction ( m_act_English ) ;
2023-01-28 09:45:13 +00:00
if ( m_currLang = = " english " )
2023-01-28 07:32:08 +00:00
{
m_act_simpCN - > setChecked ( false ) ;
m_act_English - > setChecked ( true ) ;
}
else
{
m_act_simpCN - > setChecked ( true ) ;
m_act_English - > setChecked ( false ) ;
}
2023-01-28 02:57:18 +00:00
2023-01-30 07:03:30 +00:00
connect ( m_act_simpCN , SIGNAL ( triggered ( ) ) , this , SLOT ( on_act_simpCN_triggered ( ) ) ) ;
connect ( m_act_English , SIGNAL ( triggered ( ) ) , this , SLOT ( on_act_English_triggered ( ) ) ) ;
# endif
2022-05-03 10:25:52 +00:00
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 ) ) ;
2022-05-14 08:38:09 +00:00
m_multiPageLineEdit - > setFixedWidth ( 100 ) ;
2022-05-03 10:25:52 +00:00
m_multiPageLineEdit - > setAlignment ( Qt : : AlignHCenter ) ;
ui - > toolBar - > insertWidget ( ui - > act_nextPage , m_multiPageLineEdit ) ;
2022-05-18 08:24:41 +00:00
ui - > toolBar - > setStyleSheet ( " QToolBar::item{border: 0px} " ) ;
2022-05-03 10:25:52 +00:00
m_wndStatusBar = new Widget_StatusBar ( ui - > act_zoomIn , ui - > act_zoomOut , ui - > statusBar ) ;
ui - > statusBar - > addWidget ( m_wndStatusBar , 1 ) ;
2022-05-18 08:24:41 +00:00
m_wndStatusBar - > setStyleSheet ( " QStatusBar::item{border: 0px} " ) ;
ui - > statusBar - > setSizeGripEnabled ( false ) ;
2022-05-03 10:25:52 +00:00
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 ) ) ) ;
2022-05-14 05:22:20 +00:00
connect ( m_view , SIGNAL ( drop ( const QObject * , const QStringList & ) ) , this , SLOT ( on_viewerDrop ( const QObject * , const QStringList & ) ) ) ;
2022-05-03 10:25:52 +00:00
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 ) ) ) ;
2022-05-14 05:22:20 +00:00
connect ( m_thumb , SIGNAL ( drop ( const QObject * , const QStringList & , int ) ) , this , SLOT ( on_thumbDrop ( const QObject * , const QStringList & , int ) ) ) ;
2022-05-03 10:25:52 +00:00
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 ) ;
2022-07-19 10:06:08 +00:00
m_thumb - > setItemTextHeight ( 0 ) ;
2022-05-03 10:25:52 +00:00
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 " ) ;
2022-11-09 03:39:53 +00:00
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 ) ;
2023-01-28 07:32:08 +00:00
m_act_thumbGrid = new QAction ( tr ( " Grid " ) , this ) ;
m_act_thumbGrid - > setCheckable ( true ) ;
m_act_thumbGrid - > setChecked ( false ) ;
connect ( m_act_thumbGrid , SIGNAL ( triggered ( bool ) ) , this , SLOT ( on_act_thumbGrid_triggered ( bool ) ) ) ;
2022-11-09 03:39:53 +00:00
m_moveToAction = new QAction ( tr ( " Move To... " ) , this ) ;
connect ( m_moveToAction , SIGNAL ( triggered ( ) ) , this , SLOT ( on_act_moveTo_triggered ( ) ) ) ;
m_thumbMenu = new QMenu ( this ) ;
2023-01-28 07:32:08 +00:00
m_menu_imageInsert = new QMenu ( tr ( " Insert files " ) , m_thumbMenu ) ;
2022-11-09 03:39:53 +00:00
2023-02-03 02:21:33 +00:00
m_thumbMenu - > addAction ( ui - > act_deleteFile ) ;
2022-11-09 03:39:53 +00:00
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 ) ;
2023-01-28 07:32:08 +00:00
m_thumbMenu - > addAction ( m_menu_imageInsert - > menuAction ( ) ) ;
2022-11-09 03:39:53 +00:00
m_thumbMenu - > addSeparator ( ) ;
2023-01-28 07:32:08 +00:00
m_thumbMenu - > addAction ( m_act_thumbGrid ) ;
m_menu_imageInsert - > addAction ( ui - > act_insert ) ;
m_menu_imageInsert - > addAction ( ui - > act_insertFromScanner ) ;
2022-11-09 03:39:53 +00:00
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 ) ;
2023-04-13 01:43:57 +00:00
connect ( this , SIGNAL ( pre_new_image ( void * ) ) , this , SLOT ( on_pre_new_image ( void * ) ) , Qt : : BlockingQueuedConnection ) ;
connect ( this , SIGNAL ( post_new_image ( unsigned int , int ) ) , this , SLOT ( on_post_new_image ( unsigned int , int ) ) , Qt : : BlockingQueuedConnection ) ;
2022-11-09 03:39:53 +00:00
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 ( 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)
2023-03-11 08:55:26 +00:00
m_password = " hanvonscan " ;
2022-11-09 03:39:53 +00:00
# elif defined(OEM_LISICHENG)
m_password = " lanxum " ;
2023-01-29 09:02:57 +00:00
# elif defined(OEM_CANGTIAN)
2022-11-10 01:11:57 +00:00
m_password = " cumtenn " ;
2023-01-29 09:02:57 +00:00
# elif defined(OEM_ZHONGJING)
m_password = " microtek " ;
2023-03-10 05:39:50 +00:00
# elif defined(OEM_ZIGUANG)
m_password = " uniscan " ;
2022-11-09 03:39:53 +00:00
# else
m_password = " huagoscan " ;
# endif
else
m_password = passwordDecrypt ( password ) ;
2022-07-26 09:35:01 +00:00
2022-11-09 03:39:53 +00:00
m_dlgFullScreen = nullptr ;
m_dialogLog - > updateStatus ( ! dev_que_ . opened_scanner_name ( ) . empty ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-11-23 14:24:06 +00:00
ui - > act_autoSave - > setChecked ( getCfgValue ( " save " , " autoSave " , false ) ) ;
2022-12-05 10:08:46 +00:00
# if defined(OEM_LISICHENG)
ui - > act_autoSave - > setChecked ( true ) ;
# endif
2022-11-23 14:56:43 +00:00
auto_save_changes_ = ui - > act_autoSave - > isChecked ( ) ;
2022-11-09 03:39:53 +00:00
ui - > act_autoSave - > setText ( tr ( " auto save " ) ) ;
2022-11-23 14:24:06 +00:00
ui - > act_autoSave - > setToolTip ( tr ( " when switching pictures, save the edited pictures directly without reminding " ) ) ;
2022-07-26 09:35:01 +00:00
2022-11-09 03:39:53 +00:00
auto_save_info_ . index = 0 ;
ui - > act_device_log - > setEnabled ( false ) ;
ui - > act_driver_log - > setEnabled ( false ) ;
2022-11-03 09:18:30 +00:00
2023-04-08 08:33:36 +00:00
m_pbtn_push = new QPushButton ( this ) ;
m_pbtn_push - > setText ( " << " ) ;
m_pbtn_push - > setGeometry ( 0 , 0 , 25 , 50 ) ;
m_widget_sideBar = new Widget_Imgproc_SideBar ( this ) ;
connect ( m_pbtn_push , SIGNAL ( clicked ( ) ) , this , SLOT ( on_m_pbtn_push_clicked ( ) ) ) ;
2023-04-08 10:43:46 +00:00
connect ( m_widget_sideBar , SIGNAL ( applyToImage ( HGImage , int , int , double , bool ) ) , this , SLOT ( on_dialog_sideBar_applyToImage ( HGImage , int , int , double , bool ) ) ) ;
connect ( m_widget_sideBar , SIGNAL ( finish ( bool ) ) , this , SLOT ( on_dialog_sideBar_finish ( bool ) ) ) ;
2023-04-08 08:33:36 +00:00
updateSideBar ( ) ;
updateActionStatus ( ) ;
2022-11-09 03:39:53 +00:00
SANE_Int v = 0 ;
sane_init_ex ( & v , sane_ex_callback , this ) ;
2022-05-03 10:25:52 +00:00
}
MainWindow : : ~ MainWindow ( )
{
if ( nullptr ! = m_dlgFullScreen )
{
delete m_dlgFullScreen ;
m_dlgFullScreen = nullptr ;
}
2023-01-28 07:32:08 +00:00
if ( nullptr ! = dev_que_ . handle ( ) )
{
dev_que_ . close_scanner ( ) ;
m_versionDll - > PostDeviceCloseInfo ( m_currDeviceName . toStdString ( ) . c_str ( ) , m_devSerialNum . toStdString ( ) . c_str ( ) , " " , m_devVersionNum . toStdString ( ) . c_str ( ) ) ;
2022-11-03 09:18:30 +00:00
}
2022-05-03 10:25:52 +00:00
sane_exit ( ) ;
2022-07-14 07:44:53 +00:00
delete m_versionDll ;
2023-01-28 07:32:08 +00:00
m_versionDll = nullptr ;
2022-07-13 11:01:42 +00:00
2022-07-23 08:54:56 +00:00
for ( auto & v : wrong_imgs_ )
{
v - > hide ( ) ;
delete v ;
}
2022-05-03 10:25:52 +00:00
delete ui ;
}
void MainWindow : : exitFullScreen ( )
{
assert ( nullptr ! = m_dlgFullScreen ) ;
this - > show ( ) ;
delete m_dlgFullScreen ;
m_dlgFullScreen = nullptr ;
}
2023-03-02 07:43:58 +00:00
HGResult MainWindow : : saveImage ( HGImage image , const HGImgFmtSaveInfo * info , bool ocr , int ocrLanguageType , const HGChar * fileName )
2022-05-16 09:00:08 +00:00
{
if ( ! ocr )
{
return HGImgFmt_SaveImage ( image , 0 , info , fileName ) ;
}
HGResult ret = HGBASE_ERR_FAIL ;
2023-02-17 01:20:12 +00:00
2023-03-03 04:00:14 +00:00
#if 0
2023-02-17 01:20:12 +00:00
HGChar tmpFileName [ 256 ] ;
HGBase_GetTmpFileName ( " bmp " , tmpFileName , 256 ) ;
ret = HGImgFmt_SaveImage ( image , 0 , info , tmpFileName ) ;
2023-03-02 07:43:58 +00:00
bool result = createOcrPdf ( tmpFileName , fileName , ocrLanguageType ) ;
2023-02-17 01:20:12 +00:00
QFile : : remove ( tmpFileName ) ;
2023-02-17 03:05:49 +00:00
return ( result ) ? HGBASE_ERR_OK : HGIMGPROC_ERR_OCR ;
2023-02-17 01:20:12 +00:00
# else
2022-11-06 08:00:48 +00:00
// 韫囩晫鏆恑nfo
2022-05-16 09:00:08 +00:00
HGOCRMgr ocrMgr = nullptr ;
2022-11-24 09:02:26 +00:00
ret = HGImgProc_CreateOCRMgr ( 0 , & ocrMgr ) ;
if ( HGBASE_ERR_OK = = ret )
2022-05-16 09:00:08 +00:00
{
ret = HGImgProc_ImageOCRToFile ( ocrMgr , image , 0 , fileName ) ;
HGImgProc_DestroyOCRMgr ( ocrMgr ) ;
}
return ret ;
2023-02-17 01:20:12 +00:00
# endif
2022-05-16 09:00:08 +00:00
}
2022-05-03 10:25:52 +00:00
void MainWindow : : on_act_90Left_triggered ( )
{
if ( HGBASE_ERR_OK = = m_view - > rotateLeft ( ) )
{
m_modify = true ;
updateStatusBarPixelInfo ( ) ;
updateActionStatus ( ) ;
2022-10-26 10:24:25 +00:00
if ( auto_save_changes_ )
{
on_act_save_triggered ( ) ;
}
2022-05-03 10:25:52 +00:00
}
}
void MainWindow : : on_act_90Right_triggered ( )
{
if ( HGBASE_ERR_OK = = m_view - > rotateRight ( ) )
{
m_modify = true ;
updateStatusBarPixelInfo ( ) ;
updateActionStatus ( ) ;
2022-10-26 10:24:25 +00:00
if ( auto_save_changes_ )
{
on_act_save_triggered ( ) ;
}
2022-05-03 10:25:52 +00:00
}
}
void MainWindow : : on_act_180_triggered ( )
{
if ( HGBASE_ERR_OK = = m_view - > rotate180 ( ) )
{
m_modify = true ;
updateStatusBarPixelInfo ( ) ;
updateActionStatus ( ) ;
2022-10-26 10:24:25 +00:00
if ( auto_save_changes_ )
{
on_act_save_triggered ( ) ;
}
2022-05-03 10:25:52 +00:00
}
}
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 ) ;
2022-08-22 04:47:25 +00:00
if ( checked )
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " statusBar displayed " ) , false ) ;
}
else
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " statusBar hidden " ) , false ) ;
}
2022-05-03 10:25:52 +00:00
}
void MainWindow : : on_act_toolBar_triggered ( bool checked )
{
ui - > toolBar - > setVisible ( checked ) ;
2022-08-22 04:47:25 +00:00
if ( checked )
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " toolBar displayed " ) , false ) ;
}
else
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " toolBar hidden " ) , false ) ;
}
2022-05-03 10:25:52 +00:00
}
void MainWindow : : on_act_colorInfo_triggered ( bool checked )
{
m_view - > showColorInfo ( checked ) ;
2022-08-22 04:47:25 +00:00
if ( checked )
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " colorInfo enabled " ) , false ) ;
}
else
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " colorInfo disenabled " ) , false ) ;
}
2022-05-03 10:25:52 +00:00
}
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 ( ) ;
}
2022-06-02 10:27:14 +00:00
void MainWindow : : on_act_autoSave_triggered ( )
{
auto_save_changes_ = ui - > act_autoSave - > isChecked ( ) ;
if ( auto_save_changes_ )
{
2022-06-06 02:28:27 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " enabling automatic saving " ) , false ) ;
2022-06-02 10:27:14 +00:00
}
else
{
2022-06-06 02:28:27 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " cancel auto save " ) , false ) ;
2022-06-02 10:27:14 +00:00
}
2022-11-23 14:24:06 +00:00
saveCfgValue ( " save " , " autoSave " , auto_save_changes_ ) ;
2022-06-02 10:27:14 +00:00
}
2023-03-06 09:01:57 +00:00
void MainWindow : : on_AcquireInto2 ( )
{
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 ( 1 )
{
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 ( 2 ) )
{
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 ( ) ;
2023-04-12 10:44:20 +00:00
if ( m_devVersionNum < " G4393B1001 "
& & ( " 439 " = = getDevPid ( ) | | " 9220 " = = getDevPid ( ) | | " 8529 " = = getDevPid ( ) ) )
2023-03-06 09:01:57 +00:00
{
m_dialogLog - > addLog ( tr ( " Please wake up the device manually " ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " Please wake up the device manually " ) , true ) ;
}
else
{
QTime curTimer = QTime : : currentTime ( ) . addMSecs ( 10000 ) ;
while ( QTime : : currentTime ( ) < curTimer )
{
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
}
m_dialogLog - > addLog ( tr ( " already waked up device " ) , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " already waked up device " ) , false ) ;
}
ui - > menu_scan - > setEnabled ( true ) ;
ui - > act_acquire - > setEnabled ( true ) ;
ui - > act_scannerSettings - > setEnabled ( true ) ;
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 ( ) ;
}
}
2023-03-31 07:22:07 +00:00
void MainWindow : : on_reloadAcquireIntoCfg ( )
{
disconnect ( m_cbtn_acquireIntoCfg , SIGNAL ( currentTextChanged ( QString ) ) , this , SLOT ( on_m_acquireIntoCfg_changed ( QString ) ) ) ;
m_cbtn_acquireIntoCfg - > clear ( ) ;
m_cbtn_acquireIntoCfg - > addItem ( tr ( " default scheme " ) ) ;
connect ( m_cbtn_acquireIntoCfg , SIGNAL ( currentTextChanged ( QString ) ) , this , SLOT ( on_m_acquireIntoCfg_changed ( QString ) ) ) ;
QString allCfgName = getCfgValue ( " aquire " , " cfgNameList " , QString ( " " ) ) ;
QStringList allCfgNameList = allCfgName . split ( " , " ) ;
if ( ! allCfgNameList . contains ( QString ( " " ) ) )
{
m_cbtn_acquireIntoCfg - > addItems ( allCfgNameList ) ;
m_cbtn_acquireIntoCfg - > setCurrentText ( getCfgValue ( " aquire " , " currentKeyName " , QString ( " aquire " ) ) ) ;
}
else
{
allCfgNameList . removeOne ( QString ( " " ) ) ;
m_cbtn_acquireIntoCfg - > setCurrentIndex ( 0 ) ;
}
}
void MainWindow : : on_m_acquireIntoCfg_changed ( QString schemeName )
{
QString selectedCfgName = m_cbtn_acquireIntoCfg - > currentText ( ) ;
Dialog_AquireInto dlg ;
dlg . setConfig ( selectedCfgName ) ;
}
2022-05-03 10:25:52 +00:00
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 ) ;
2022-05-12 11:21:43 +00:00
if ( nullptr ! = img & & m_modify & & - 1 ! = m_currIndex & & m_multiPageCount = = 1 )
2022-05-03 10:25:52 +00:00
{
assert ( ! m_currFilePath . isEmpty ( ) ) ;
QString newCurrFilePath ;
if ( - 1 ! = index )
m_thumb - > getItemFileName ( index , newCurrFilePath ) ;
if ( m_currFilePath ! = newCurrFilePath )
{
2022-06-02 10:27:14 +00:00
bool save = false ;
if ( auto_save_changes_ )
2022-05-03 10:25:52 +00:00
{
2022-06-06 02:28:27 +00:00
QString info ( tr ( " Automatically save the edited the edited iamge when switching pictures. To cancel, uncheck the menu item: image-> automatically save " ) ) ;
2022-06-02 10:27:14 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( info , false ) ;
save = true ;
2022-05-03 10:25:52 +00:00
}
2023-02-16 07:17:41 +00:00
else
{
Dialog_SaveMessageBox dlg ( this ) ;
if ( dlg . exec ( ) )
2022-06-02 10:27:14 +00:00
{
2023-02-16 07:17:41 +00:00
if ( dlg . m_result = = dlg . result_Yes )
{
save = true ;
}
else if ( dlg . m_result = = dlg . result_YesToAll )
{
save = true ;
auto_save_changes_ = true ;
2022-06-02 10:27:14 +00:00
ui - > act_autoSave - > setChecked ( true ) ;
2023-02-16 07:17:41 +00:00
}
else if ( dlg . m_result = = dlg . result_No )
{
m_modify = false ;
}
2022-06-02 10:27:14 +00:00
}
}
2023-02-16 07:17:41 +00:00
2022-06-02 10:27:14 +00:00
if ( save )
2022-05-03 10:25:52 +00:00
{
2022-06-02 10:27:14 +00:00
save_from_changed_ = true ;
2022-05-03 10:25:52 +00:00
on_act_save_triggered ( ) ;
2022-06-02 10:27:14 +00:00
save_from_changed_ = false ;
2022-05-03 10:25:52 +00:00
}
}
}
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 ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img2 ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
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 . 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 ) ;
}
2022-05-14 05:22:20 +00:00
void MainWindow : : on_thumbDrop ( const QObject * source , const QStringList & fileNames , int pos )
2022-05-03 10:25:52 +00:00
{
2022-05-14 05:22:20 +00:00
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 ) ;
2022-05-03 10:25:52 +00:00
}
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 ) ;
}
}
2022-05-17 07:54:32 +00:00
int index = dlg . getMoveToIndex ( ) ;
m_thumb - > moveItemsTo ( fileNames , index ) ;
2022-05-03 10:25:52 +00:00
}
}
void MainWindow : : on_act_thumbGrid_triggered ( bool checked )
{
if ( checked )
2022-08-16 06:00:16 +00:00
{
2022-05-03 10:25:52 +00:00
m_thumb - > setType ( HGImgThumb : : ThumbType_Grid ) ;
2022-08-16 06:00:16 +00:00
resizeDocks ( { ui - > dockWidget } , { 300 } , Qt : : Horizontal ) ;
}
2022-05-03 10:25:52 +00:00
else
2022-08-16 06:00:16 +00:00
{
2022-05-03 10:25:52 +00:00
m_thumb - > setType ( HGImgThumb : : ThumbType_Vert ) ;
2022-08-16 06:00:16 +00:00
resizeDocks ( { ui - > dockWidget } , { 200 } , Qt : : Horizontal ) ;
}
2022-05-03 10:25:52 +00:00
}
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 ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
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 < int > 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 ;
2022-10-28 01:03:22 +00:00
std : : vector < std : : string > now ;
std : : string stdn ( devName . toStdString ( ) ) ;
dev_que_ . get_scanners ( now ) ;
if ( std : : find ( now . begin ( ) , now . end ( ) , stdn ) = = now . end ( ) )
2022-05-03 10:25:52 +00:00
{
// initializing the device configuration ...
2022-10-28 01:03:22 +00:00
dev_que_ . add_scanner ( stdn . c_str ( ) ) ;
2022-05-03 10:25:52 +00:00
// statu info ...
2023-01-28 02:57:18 +00:00
QString info = tr ( " found device : %1 " ) . arg ( devName ) ;
2022-05-03 10:25:52 +00:00
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 ) ;
2022-10-28 08:58:38 +00:00
if ( ! opened & & devName . toStdString ( ) ! = dev_que_ . opened_scanner_name ( ) )
opened = true ;
2022-05-03 10:25:52 +00:00
if ( opened )
info + = tr ( " reconnected " ) ;
else
2022-05-27 10:45:51 +00:00
info + = tr ( " already connected, but open faild " ) ;
2022-05-03 10:25:52 +00:00
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 ;
2022-10-28 01:03:22 +00:00
dev_que_ . set_online ( true , stdn . c_str ( ) ) ;
2022-05-03 10:25:52 +00:00
}
// enable the device menu item ...
ui - > menu_device - > connectedDevice ( devName ) ;
// open it if no device has been opened ...
2022-10-28 01:03:22 +00:00
if ( dev_que_ . opened_scanner_name ( ) . empty ( ) )
2022-05-03 10:25:52 +00:00
{
2022-10-28 08:53:43 +00:00
//dev_que_.open_scanner(stdn.c_str());
open_scanner ( devName , " " ) ;
2022-05-03 10:25:52 +00:00
}
2022-11-07 02:10:21 +00:00
2022-10-28 01:03:22 +00:00
ui - > menu_device - > deviceMenuUpdate ( & dev_que_ ) ;
2022-05-03 10:25:52 +00:00
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( ! dev_que_ . opened_scanner_name ( ) . empty ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
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 ) ;
2022-10-28 01:03:22 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( info ) . c_str ( ) ) ;
2022-05-03 10:25:52 +00:00
// enable the device menu item ...
ui - > menu_device - > disconnectedDevice ( devName ) ;
// set openning device offline ...
2022-10-28 01:03:22 +00:00
dev_que_ . set_online ( false , devName . toStdString ( ) . c_str ( ) ) ;
2022-05-03 10:25:52 +00:00
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
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 ( ) ) ;
}
2023-04-13 01:43:57 +00:00
void MainWindow : : on_pre_new_image ( void * img )
2022-05-03 10:25:52 +00:00
{
2023-04-13 01:43:57 +00:00
m_saveType = 0 ;
2022-05-03 10:25:52 +00:00
HGImage image = ( HGImage ) img ;
2022-05-20 10:44:24 +00:00
HGBase_SetImageDpi ( image , m_dpi , m_dpi ) ;
2022-05-03 10:25:52 +00:00
if ( 1 = = m_scanType )
{
2022-11-24 16:39:37 +00:00
if ( m_cacheDirNotify )
2022-11-24 15:48:08 +00:00
{
2022-11-24 09:40:18 +00:00
return ;
2022-11-24 15:48:08 +00:00
}
2022-11-24 16:39:37 +00:00
else
{
if ( ! judgeDiskSpace ( Dialog_ClrCache : : getCachePath ( ) , false ) )
{
m_cacheDirNotify = true ;
2022-11-24 16:44:13 +00:00
on_stopScan ( ) ;
2022-11-24 16:39:37 +00:00
QString info = tr ( " the disk space in the current path is unsufficient, please select a new path or clear the disk space in time. " ) ;
m_wndStatusBar - > setDeviceStatusInfo ( info , true ) ;
m_dialogLog - > addLog ( info , true ) ;
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " disk space is unsufficient! " ) ;
QMessageBox : : warning ( this , tr ( " warning " ) , info ) ;
return ;
}
}
2022-11-24 09:40:18 +00:00
2023-04-13 01:43:57 +00:00
m_scanFileName = getCacheFileName ( image ) ;
m_saveType = 1 ;
return ;
2022-05-03 10:25:52 +00:00
}
else if ( 2 = = m_scanType )
{
2022-11-24 16:39:37 +00:00
if ( m_AquirePathNotify )
2022-11-24 15:48:08 +00:00
{
2022-11-24 10:14:56 +00:00
return ;
2022-11-24 15:48:08 +00:00
}
2022-11-24 16:39:37 +00:00
else
{
if ( ! judgeDiskSpace ( m_aquireIntoSaveParam . m_savePath , false ) )
{
m_AquirePathNotify = true ;
2022-11-24 16:44:13 +00:00
on_stopScan ( ) ;
2022-11-24 16:39:37 +00:00
QString info = tr ( " the disk space in the current path is unsufficient, please select a new path or clear the disk space in time. " ) ;
m_wndStatusBar - > setDeviceStatusInfo ( info , true ) ;
m_dialogLog - > addLog ( info , true ) ;
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " disk space is unsufficient! " ) ;
QMessageBox : : warning ( this , tr ( " warning " ) , info ) ;
return ;
}
}
2022-11-24 10:14:56 +00:00
2022-05-16 02:43:51 +00:00
+ + m_aquireIntoPageIndex ;
if ( ( 1 = = m_aquireIntoSaveParam . m_fileNameOddEventType & & 1 ! = m_aquireIntoPageIndex % 2 )
| | ( 2 = = m_aquireIntoSaveParam . m_fileNameOddEventType & & 0 ! = m_aquireIntoPageIndex % 2 ) )
{
return ;
}
2022-05-03 10:25:52 +00:00
if ( m_aquireIntoSaveParam . m_isSaveAsMultiPage )
{
2022-05-16 02:43:51 +00:00
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 ;
2022-11-24 06:14:08 +00:00
m_aquireIntoMultiPageCount = 0 ;
2022-05-16 02:43:51 +00:00
}
}
2022-05-03 10:25:52 +00:00
if ( nullptr = = m_scanImgFmtWriter )
{
assert ( m_scanFileName . isEmpty ( ) ) ;
2022-10-28 02:45:32 +00:00
HGResult ret = HGBase_CreateDir ( getStdString ( m_aquireIntoSaveParam . m_savePath ) . c_str ( ) ) ;
if ( ret ! = HGBASE_ERR_OK )
{
2022-11-24 09:40:18 +00:00
m_dialogLog - > addLog ( tr ( " create savepath failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " create savepath failed: " ) + getLogInfo ( ret ) , true ) ;
2022-10-28 02:45:32 +00:00
}
2022-05-03 10:25:52 +00:00
QString scanFileName ;
while ( 1 )
{
2022-11-26 10:38:26 +00:00
scanFileName = m_aquireIntoSaveParam . m_savePath + m_aquireIntoSaveParam . m_fileNamePrefix + QString ( " %1.%2 " )
2022-05-03 10:25:52 +00:00
. 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 ;
}
}
2022-11-24 09:02:26 +00:00
ret = HGImgFmt_OpenImageWriter ( getStdString ( getStdFileName ( scanFileName ) ) . c_str ( ) , 0 , & m_scanImgFmtWriter ) ;
if ( ret ! = HGBASE_ERR_OK )
{
2022-11-24 09:40:18 +00:00
m_dialogLog - > addLog ( tr ( " create image doc failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " create image doc failed: " ) + getLogInfo ( ret ) , true ) ;
2022-11-24 09:02:26 +00:00
}
2022-05-03 10:25:52 +00:00
if ( nullptr ! = m_scanImgFmtWriter )
m_scanFileName = scanFileName ;
}
if ( nullptr ! = m_scanImgFmtWriter )
2022-05-13 12:38:58 +00:00
{
2023-04-13 01:43:57 +00:00
m_saveType = 2 ;
2022-05-13 12:38:58 +00:00
}
2022-05-03 10:25:52 +00:00
}
else
{
assert ( nullptr = = m_scanImgFmtWriter ) ;
2022-05-14 05:57:49 +00:00
QString savePath = m_aquireIntoSaveParam . m_savePath ;
2022-05-16 02:43:51 +00:00
if ( m_aquireIntoSaveParam . m_isUseSubfolderByBlankPages )
{
HGBool isBlank = HGFALSE ;
HGImgProc_ImageBlankCheck ( image , nullptr , & isBlank ) ;
if ( isBlank )
{
m_aquireIntoInBlank = true ;
}
else
{
if ( m_aquireIntoInBlank )
{
+ + m_aquireIntoBatchStartIndex ;
}
m_aquireIntoInBlank = false ;
}
char batchDir [ 20 ] ;
sprintf ( batchDir , " batch%d " , m_aquireIntoBatchStartIndex ) ;
savePath = getStdFileName ( savePath + batchDir + " / " ) ;
}
2022-05-14 05:57:49 +00:00
if ( m_aquireIntoSaveParam . m_isUseSubfolderByColor )
{
2022-05-27 01:23:06 +00:00
QString colorModeName ;
2022-05-16 02:43:51 +00:00
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( image , & imgInfo ) ;
2022-05-27 01:23:06 +00:00
if ( HGBASE_IMGTYPE_BINARY = = imgInfo . type )
2022-10-28 02:45:32 +00:00
colorModeName = tr ( " binary " ) ;
2022-05-16 02:43:51 +00:00
else if ( HGBASE_IMGTYPE_GRAY = = imgInfo . type )
2022-10-28 02:45:32 +00:00
colorModeName = tr ( " gray " ) ;
2022-05-27 01:23:06 +00:00
else
2022-10-28 02:45:32 +00:00
colorModeName = tr ( " rgb " ) ;
2022-05-16 02:43:51 +00:00
savePath = getStdFileName ( savePath + colorModeName + " / " ) ;
2022-05-14 05:57:49 +00:00
}
2022-11-24 09:02:26 +00:00
HGResult ret = HGBase_CreateDir ( getStdString ( savePath ) . c_str ( ) ) ;
if ( ret ! = HGBASE_ERR_OK )
2022-10-28 02:45:32 +00:00
{
2022-11-24 09:40:18 +00:00
m_dialogLog - > addLog ( tr ( " create savepath failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " create savepath failed: " ) + getLogInfo ( ret ) , true ) ;
2022-10-28 02:45:32 +00:00
}
2022-05-03 10:25:52 +00:00
while ( 1 )
{
2023-04-13 01:43:57 +00:00
m_scanFileName = savePath + m_aquireIntoSaveParam . m_fileNamePrefix + QString ( " %1.%2 " )
2022-05-03 10:25:52 +00:00
. arg ( m_aquireIntoSaveParam . m_fileNameStartIndex , m_aquireIntoSaveParam . m_fileNameDigits , 10 , QLatin1Char ( ' 0 ' ) )
. arg ( m_aquireIntoSaveParam . m_fileNameExt ) ;
2023-04-13 01:43:57 +00:00
QFileInfo fileInfo ( m_scanFileName ) ;
2022-05-03 10:25:52 +00:00
if ( fileInfo . isFile ( ) )
{
+ + m_aquireIntoSaveParam . m_fileNameStartIndex ;
}
else
{
break ;
}
}
2023-04-13 01:43:57 +00:00
m_saveType = 3 ;
}
}
}
2022-05-27 04:14:39 +00:00
2023-04-13 01:43:57 +00:00
void MainWindow : : on_post_new_image ( unsigned int ret , int statu )
{
if ( 1 = = m_scanType & & 1 = = m_saveType )
{
if ( ret = = HGBASE_ERR_OK )
{
if ( statu ! = SANE_Image_Statu_OK )
2022-05-27 04:14:39 +00:00
{
2023-04-13 01:43:57 +00:00
int ind = 0 ;
if ( m_scanInsertPos = = - 1 )
m_thumb - > getItemCount ( & ind ) ;
else
ind = m_scanInsertPos ;
dialog_wrong_img * wi = new dialog_wrong_img ( this , m_scanFileName , 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 ( m_scanFileName ) ;
2022-05-27 04:14:39 +00:00
}
else
{
2023-04-13 01:43:57 +00:00
m_thumb - > insertItem ( m_scanFileName , m_scanInsertPos ) ;
+ + m_scanInsertPos ;
}
}
else
{
m_dialogLog - > addLog ( tr ( " save image failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " save image failed: " ) + getLogInfo ( ret ) , true ) ;
}
}
else if ( 2 = = m_scanType )
{
if ( m_aquireIntoSaveParam . m_isSaveAsMultiPage & & 2 = = m_saveType )
{
if ( ret ! = HGBASE_ERR_OK )
{
m_dialogLog - > addLog ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
2022-05-27 04:14:39 +00:00
}
2023-04-13 01:43:57 +00:00
+ + m_aquireIntoMultiPageCount ;
}
else if ( 3 = = m_saveType )
{
if ( ret = = HGBASE_ERR_OK )
2022-08-12 06:54:47 +00:00
{
2023-04-13 01:43:57 +00:00
m_thumb - > addItem ( m_scanFileName ) ;
2022-08-12 06:54:47 +00:00
+ + m_aquireIntoSaveParam . m_fileNameStartIndex ;
}
2022-11-24 09:02:26 +00:00
else
{
2022-11-24 09:40:18 +00:00
m_dialogLog - > addLog ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
2022-11-24 09:02:26 +00:00
}
2022-05-03 10:25:52 +00:00
}
}
2022-07-30 01:27:43 +00:00
m_currScanCount + + ;
2022-07-23 08:54:56 +00:00
if ( statu = = SANE_Image_Statu_OK )
m_dialogLog - > image_received_from_scanner ( ) ;
2022-05-03 10:25:52 +00:00
}
void MainWindow : : on_scan_working ( QString workingInfo )
{
m_wndStatusBar - > setDeviceStatusInfo ( workingInfo , false ) ;
2022-05-16 10:01:42 +00:00
m_dialogLog - > addLog ( workingInfo , false , LOG_EVENT_SCAN_BEGINNING ) ;
2022-05-03 10:25:52 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " %s " , getStdString ( workingInfo ) . c_str ( ) ) ;
}
void MainWindow : : on_scan_finish ( QString finishInfo , int err )
{
2022-05-05 02:03:14 +00:00
if ( 0 = = m_scanType )
2022-05-03 10:25:52 +00:00
{
2022-05-05 02:03:14 +00:00
if ( nullptr ! = m_scanImgFmtWriter )
{
HGImgFmt_CloseImageWriter ( m_scanImgFmtWriter ) ;
m_scanImgFmtWriter = nullptr ;
m_thumb - > addItem ( m_scanFileName ) ;
m_scanFileName . clear ( ) ;
+ + m_aquireIntoSaveParam . m_fileNameStartIndex ;
}
2022-05-03 10:25:52 +00:00
}
2022-09-23 07:24:32 +00:00
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 ( ) ) ;
}
2022-07-30 01:27:43 +00:00
m_versionDll - > PostDeviceScanCountInfo ( m_currDeviceName . toStdString ( ) . c_str ( ) , m_devSerialNum . toStdString ( ) . c_str ( ) , " " , m_devVersionNum . toStdString ( ) . c_str ( ) , m_currScanCount ) ;
m_currScanCount = 0 ;
2022-05-03 10:25:52 +00:00
m_isScanning = false ;
m_thumb - > setAcceptDrops ( true ) ;
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
m_wndStatusBar - > setDeviceStatusInfo ( finishInfo , ( err ! = SANE_STATUS_GOOD ) ) ;
2022-05-16 10:01:42 +00:00
m_dialogLog - > addLog ( finishInfo , ( err ! = SANE_STATUS_GOOD ) , LOG_EVENT_SCAN_STOPPED ) ;
2022-07-19 10:06:08 +00:00
HGBase_WriteInfo ( ( err ! = SANE_STATUS_GOOD ) ? HGBASE_INFOTYPE_ERROR : HGBASE_INFOTYPE_DESC ,
2022-05-03 10:25:52 +00:00
" %s " , getStdString ( finishInfo ) . c_str ( ) ) ;
2022-11-24 15:48:08 +00:00
m_cacheDirNotify = false ;
m_AquirePathNotify = false ;
2022-05-03 10:25:52 +00:00
}
2022-05-26 09:20:12 +00:00
void MainWindow : : on_export_scanned_image ( void )
{
m_dialogLog - > hide ( ) ;
on_act_Export_triggered ( ) ;
}
2022-05-03 10:25:52 +00:00
void MainWindow : : on_continueScan ( )
{
2023-02-22 07:18:06 +00:00
if ( 1 = = m_scanType )
2022-08-13 09:47:29 +00:00
{
2023-02-22 07:18:06 +00:00
if ( ! isLimitAccessFolder ( 1 ) )
{
return ;
}
}
else if ( 2 = = m_scanType )
{
if ( ! isLimitAccessFolder ( 2 ) )
{
return ;
}
2022-08-13 09:47:29 +00:00
}
2022-10-28 01:03:22 +00:00
if ( ! dev_que_ . is_online ( ) | | m_isScanning | | 0 = = m_scanType )
2022-05-03 10:25:52 +00:00
{
return ;
}
startSaveMessageBox ( m_dialogLog ) ;
SANE_Status ret ;
2022-05-20 10:44:24 +00:00
m_dpi = getDpi ( ) ;
2022-05-03 10:25:52 +00:00
if ( m_singleScan )
2022-10-28 01:03:22 +00:00
ret = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_TEST_SINGLE , nullptr , nullptr ) ;
2022-05-03 10:25:52 +00:00
else
2022-10-28 01:03:22 +00:00
ret = sane_start ( dev_que_ . handle ( ) ) ;
2022-05-03 10:25:52 +00:00
if ( ret ! = SANE_STATUS_GOOD )
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " start failed " ) , true ) ;
2022-08-02 10:09:02 +00:00
m_dialogLog - > addLog ( tr ( " start failed " ) + " ( " + QString ( sane_err_desc ( ret ) ) + " ) " , true ) ;
2022-05-03 10:25:52 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( tr ( " start failed " ) ) . c_str ( ) ) ;
2022-08-22 07:25:37 +00:00
if ( ret = = SCANNER_ERR_DEVICE_SLEEPING )
{
ui - > menu_scan - > setEnabled ( false ) ;
ui - > act_acquire - > setEnabled ( false ) ;
ui - > act_scannerSettings - > setEnabled ( false ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( false , false ) ;
2022-08-26 08:20:59 +00:00
m_dialogLog - > show ( ) ;
2023-02-06 08:18:47 +00:00
2023-04-12 10:44:20 +00:00
if ( m_devVersionNum < " G4393B1001 "
& & ( " 439 " = = getDevPid ( ) | | " 9220 " = = getDevPid ( ) | | " 8529 " = = getDevPid ( ) ) )
2022-08-22 07:25:37 +00:00
{
2023-02-06 08:18:47 +00:00
m_dialogLog - > addLog ( tr ( " Please wake up the device manually " ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " Please wake up the device manually " ) , true ) ;
2022-08-22 07:25:37 +00:00
}
2023-02-06 08:18:47 +00:00
else
{
QTime curTimer = QTime : : currentTime ( ) . addMSecs ( 10000 ) ;
while ( QTime : : currentTime ( ) < curTimer )
{
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
}
m_dialogLog - > addLog ( tr ( " already waked up device " ) , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " already waked up device " ) , false ) ;
}
2022-08-22 07:25:37 +00:00
ui - > menu_scan - > setEnabled ( true ) ;
ui - > act_acquire - > setEnabled ( true ) ;
ui - > act_scannerSettings - > setEnabled ( true ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( true , false ) ;
2022-08-22 07:25:37 +00:00
}
2022-05-03 10:25:52 +00:00
}
else
{
m_isScanning = true ;
m_thumb - > setAcceptDrops ( false ) ;
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
}
m_dialogLog - > show ( ) ;
}
void MainWindow : : on_stopScan ( )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) , m_isScanning ) ;
2022-05-05 02:03:14 +00:00
if ( ! m_isScanning )
2022-05-03 10:25:52 +00:00
{
2022-05-05 02:03:14 +00:00
if ( nullptr ! = m_scanImgFmtWriter )
{
HGImgFmt_CloseImageWriter ( m_scanImgFmtWriter ) ;
m_scanImgFmtWriter = nullptr ;
m_thumb - > addItem ( m_scanFileName ) ;
m_scanFileName . clear ( ) ;
+ + m_aquireIntoSaveParam . m_fileNameStartIndex ;
}
}
else
{
2022-10-28 01:03:22 +00:00
if ( dev_que_ . is_online ( ) )
2022-05-05 02:03:14 +00:00
{
2022-10-28 01:03:22 +00:00
sane_cancel ( dev_que_ . handle ( ) ) ;
2022-05-05 02:03:14 +00:00
}
2022-05-03 10:25:52 +00:00
}
}
void MainWindow : : on_statusInfoDblClick ( )
{
m_dialogLog - > show ( ) ;
}
2022-07-23 08:54:56 +00:00
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 ;
}
2022-05-03 10:25:52 +00:00
2023-04-08 08:33:36 +00:00
void MainWindow : : on_m_pbtn_push_clicked ( )
{
int mainWndWidth = this - > rect ( ) . width ( ) ;
int mainWndHeight = this - > rect ( ) . height ( ) ;
2023-04-08 10:43:46 +00:00
int sideBarWidth = m_widget_sideBar - > width ( ) ;
int sideBarHeight = m_widget_sideBar - > height ( ) ;
2023-04-08 08:33:36 +00:00
if ( ! m_bSideflag )
{
m_propertyAnimation - > setStartValue ( QRect ( mainWndWidth , mainWndHeight / 2 - sideBarHeight / 2 , sideBarWidth , sideBarHeight ) ) ;
m_propertyAnimation - > setEndValue ( QRect ( mainWndWidth - sideBarWidth , mainWndHeight / 2 - sideBarHeight / 2 , sideBarWidth , sideBarHeight ) ) ;
m_propertyAnimation - > start ( ) ;
m_propertyAnimation2 - > setStartValue ( QRect ( mainWndWidth - m_pbtn_push - > width ( ) , mainWndHeight / 2 - m_pbtn_push - > height ( ) / 2 , m_pbtn_push - > width ( ) , m_pbtn_push - > height ( ) ) ) ;
m_propertyAnimation2 - > setEndValue ( QRect ( mainWndWidth - m_pbtn_push - > width ( ) - sideBarWidth , mainWndHeight / 2 - m_pbtn_push - > height ( ) / 2 , m_pbtn_push - > width ( ) , m_pbtn_push - > height ( ) ) ) ;
m_propertyAnimation2 - > start ( ) ;
m_pbtn_push - > setText ( " >> " ) ;
m_bSideflag = ! m_bSideflag ;
}
else
{
m_propertyAnimation - > setStartValue ( QRect ( mainWndWidth - sideBarWidth , mainWndHeight / 2 - sideBarHeight / 2 , sideBarWidth , sideBarHeight ) ) ;
m_propertyAnimation - > setEndValue ( QRect ( mainWndWidth , mainWndHeight / 2 - sideBarHeight / 2 , sideBarWidth , sideBarHeight ) ) ;
m_propertyAnimation - > start ( ) ;
m_propertyAnimation2 - > setStartValue ( QRect ( mainWndWidth - m_pbtn_push - > width ( ) - sideBarWidth , mainWndHeight / 2 - m_pbtn_push - > height ( ) / 2 , m_pbtn_push - > width ( ) , m_pbtn_push - > height ( ) ) ) ;
m_propertyAnimation2 - > setEndValue ( QRect ( mainWndWidth - m_pbtn_push - > width ( ) , mainWndHeight / 2 - m_pbtn_push - > height ( ) / 2 , m_pbtn_push - > width ( ) , m_pbtn_push - > height ( ) ) ) ;
m_propertyAnimation2 - > start ( ) ;
m_pbtn_push - > setText ( " << " ) ;
m_bSideflag = ! m_bSideflag ;
}
2023-04-08 10:43:46 +00:00
updateActionStatus ( ) ;
2023-04-08 08:33:36 +00:00
}
2023-04-08 10:43:46 +00:00
void MainWindow : : on_dialog_sideBar_applyToImage ( HGImage img , int brightness , int contrast , double gamma , bool enhanceText )
2023-04-08 08:33:36 +00:00
{
assert ( nullptr ! = img ) ;
HGImage destImg = nullptr ;
2023-04-08 10:43:46 +00:00
HGBase_CloneImage ( img , 0 , 0 , & destImg ) ;
2023-04-08 08:33:36 +00:00
if ( nullptr ! = destImg )
{
2023-04-08 10:43:46 +00:00
HGImgProc_ImageAdjustColors ( destImg , destImg , brightness , contrast , ( HGFloat ) gamma ) ;
if ( enhanceText )
HGImgProc_ImageBinarization ( destImg , destImg , HGIMGPROC_THRESHTYPE_ADAPTIVE_GAUSSIAN , 120 , 51 , 41 ) ;
2023-04-08 08:33:36 +00:00
m_view - > addImage ( destImg ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > enableUI ( m_multiPageCount = = 1 ) ;
m_bSideEditing = true ;
2023-04-08 08:33:36 +00:00
HGBase_DestroyImage ( destImg ) ;
2023-04-08 10:43:46 +00:00
updateActionStatus ( ) ;
2023-04-08 08:33:36 +00:00
updateStatusBarPixelInfo ( ) ;
}
}
2023-04-08 10:43:46 +00:00
void MainWindow : : on_dialog_sideBar_finish ( bool ok )
2023-04-08 08:33:36 +00:00
{
2023-04-08 10:43:46 +00:00
m_modify = ok ;
m_bSideEditing = false ;
updateActionStatus ( ) ;
2023-04-08 08:33:36 +00:00
emit m_pbtn_push - > clicked ( ) ;
}
2022-05-03 10:25:52 +00:00
void MainWindow : : on_act_thumbnailBar_triggered ( bool checked )
{
ui - > dockWidget - > setVisible ( checked ) ;
2022-08-22 04:47:25 +00:00
if ( checked )
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " thumbnailBar enabled " ) , false ) ;
}
else
{
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " thumbnailBar hidden " ) , false ) ;
}
2022-05-03 10:25:52 +00:00
}
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 ) ;
}
}
2022-05-20 10:44:24 +00:00
HGUInt MainWindow : : getDpi ( )
{
HGUInt dpi = 200 ;
SANE_Int num_dev_options = 0 ;
2022-10-28 01:03:22 +00:00
sane_control_option ( dev_que_ . handle ( ) , 0 , SANE_ACTION_GET_VALUE , & num_dev_options , nullptr ) ;
2022-05-20 10:44:24 +00:00
for ( int i = 1 ; i < num_dev_options ; + + i )
{
2022-10-28 01:03:22 +00:00
const SANE_Option_Descriptor * desp = sane_get_option_descriptor ( dev_que_ . handle ( ) , i ) ;
2022-05-20 10:44:24 +00:00
if ( nullptr = = desp )
continue ;
if ( SANE_TYPE_INT = = desp - > type )
{
SANE_Int value = 0 ;
2022-10-28 01:03:22 +00:00
sane_control_option ( dev_que_ . handle ( ) , i , SANE_ACTION_GET_VALUE , & value , nullptr ) ;
2022-10-13 07:14:20 +00:00
if ( 0 = = strcmp ( desp - > name , SANE_STD_OPT_NAME_RESOLUTION ) )
2022-05-20 10:44:24 +00:00
{
dpi = ( HGUInt ) value ;
}
}
}
return dpi ;
}
2022-06-01 10:47:58 +00:00
QString MainWindow : : getCacheFileName ( HGImage img )
2022-05-03 10:25:52 +00:00
{
2022-06-01 10:47:58 +00:00
assert ( nullptr ! = img ) ;
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( img , & imgInfo ) ;
2022-05-03 10:25:52 +00:00
QString cachePath = Dialog_ClrCache : : getCachePath ( ) ;
2022-11-24 09:02:26 +00:00
HGBase_CreateDir ( getStdString ( cachePath ) . c_str ( ) ) ;
2022-05-03 10:25:52 +00:00
char uuid [ 256 ] = { 0 } ;
HGBase_GetUuid ( uuid , 256 ) ;
2022-06-01 10:47:58 +00:00
QString suffix = ( HGBASE_IMGTYPE_BINARY = = imgInfo . type ) ? " .bmp " : " .jpg " ;
QString fileName = getStdFileName ( cachePath + uuid + suffix ) ;
2022-05-03 10:25:52 +00:00
return fileName ;
}
HGImage MainWindow : : createImage ( )
{
qDebug ( " createImage " ) ;
assert ( - 1 ! = m_currIndex & & - 1 ! = m_multiIndex ) ;
assert ( ! m_currFilePath . isEmpty ( ) ) ;
HGImage img = nullptr ;
2022-08-23 04:42:01 +00:00
HGPdfReader pdfReader = nullptr ;
HGImgFmt_OpenPdfReader ( getStdString ( m_currFilePath ) . c_str ( ) , & pdfReader ) ;
if ( nullptr ! = pdfReader )
{
2022-08-31 03:30:18 +00:00
2022-08-31 03:10:58 +00:00
float scale = 200.0f / 72.0f ;
HGImgFmt_LoadImageFromPdfReader ( pdfReader , ( HGUInt ) m_multiIndex , scale , scale , 0 , HGBASE_IMGORIGIN_TOP , & img ) ;
2023-02-27 07:26:39 +00:00
//HGBase_SetImageDpi(img, 200, 200);
2022-08-23 04:42:01 +00:00
HGImgFmt_ClosePdfReader ( pdfReader ) ;
}
else
{
2022-05-03 10:25:52 +00:00
HGImgFmtReader imgFmtReader = nullptr ;
HGImgFmt_OpenImageReader ( getStdString ( m_currFilePath ) . c_str ( ) , 0 , & imgFmtReader ) ;
if ( nullptr ! = imgFmtReader )
{
2022-05-27 01:23:06 +00:00
HGImgFmt_LoadImageFromReader ( imgFmtReader , ( HGUInt ) m_multiIndex , nullptr , 0 , HGBASE_IMGORIGIN_TOP , & img ) ;
2022-05-03 10:25:52 +00:00
HGImgFmt_CloseImageReader ( imgFmtReader ) ;
}
2022-08-23 04:42:01 +00:00
}
2022-05-03 10:25:52 +00:00
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 ;
2022-05-27 01:23:06 +00:00
if ( HGBASE_IMGTYPE_BINARY = = imgInfo . type )
bpp = 1 ;
else if ( HGBASE_IMGTYPE_GRAY = = imgInfo . type )
2022-05-03 10:25:52 +00:00
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 < int > selectIndexs ;
for ( int i = 0 ; i < count ; + + i )
{
bool select = false ;
m_thumb - > itemIsSelect ( i , & select ) ;
if ( select )
selectIndexs . push_back ( i ) ;
}
2022-10-28 01:03:22 +00:00
ui - > act_open - > setEnabled ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ;
ui - > act_insert - > setEnabled ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ;
2022-05-13 07:40:05 +00:00
ui - > act_save - > setEnabled ( nullptr ! = img & & - 1 ! = m_currIndex & & m_multiPageCount = = 1
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
ui - > act_saveAs - > setEnabled ( nullptr ! = img ) ;
2022-10-28 01:03:22 +00:00
ui - > act_Export - > setEnabled ( 0 ! = count & & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2023-02-03 02:21:33 +00:00
ui - > act_deleteFile - > setEnabled ( ! selectIndexs . empty ( ) & & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-10-28 01:03:22 +00:00
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 ) ) ;
2022-07-19 10:06:08 +00:00
ui - > act_previous - > setEnabled ( count > 0 & & ( - 1 = = m_currIndex | | m_currIndex > 0 )
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-07-19 10:06:08 +00:00
ui - > act_next - > setEnabled ( count > 0 & & ( - 1 = = m_currIndex | | m_currIndex < count - 1 )
2022-10-28 01:03:22 +00:00
& & ( ! 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 ) ) ;
2022-05-03 10:25:52 +00:00
ui - > act_previousPage - > setEnabled ( - 1 ! = m_currIndex & & m_multiPageCount > 0 & & m_multiIndex > 0
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
ui - > act_nextPage - > setEnabled ( - 1 ! = m_currIndex & & m_multiPageCount > 0 & & - 1 ! = m_multiIndex & & m_multiIndex < m_multiPageCount - 1
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
ui - > act_firstPage - > setEnabled ( - 1 ! = m_currIndex & & m_multiPageCount > 0 & & 0 ! = m_multiIndex
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
ui - > act_lastPage - > setEnabled ( - 1 ! = m_currIndex & & m_multiPageCount > 0 & & m_multiIndex ! = m_multiPageCount - 1
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
m_multiPageLineEdit - > setText ( QString ( " %1/%2 " ) . arg ( m_multiIndex + 1 ) . arg ( m_multiPageCount ) ) ;
2023-03-31 08:53:25 +00:00
ui - > toolBar - > actions ( ) . at ( 18 ) - > setVisible ( - 1 ! = m_currIndex & & m_multiPageCount > 1 & & - 1 ! = m_multiIndex
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
ui - > act_sortPages - > setEnabled ( 0 ! = count & & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
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
2022-10-28 01:03:22 +00:00
& & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2022-05-03 10:25:52 +00:00
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 ) ;
2022-10-28 01:03:22 +00:00
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 ) ) ;
2022-05-03 10:25:52 +00:00
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 ) ;
2022-10-28 01:03:22 +00:00
ui - > act_acquireInto - > setEnabled ( dev_que_ . is_online ( ) & & ! m_isScanning ) ;
2023-03-06 09:01:57 +00:00
m_act_acquireInto2 - > setEnabled ( dev_que_ . is_online ( ) & & ! m_isScanning ) ;
2022-10-28 01:03:22 +00:00
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 ( ) ) ;
2022-07-26 05:44:44 +00:00
ui - > act_driver_log - > setEnabled ( m_admin_loggedIn ) ;
2022-11-25 03:42:27 +00:00
if ( m_dialogLog ! = nullptr )
m_dialogLog - > pbtn_export - > setEnabled ( ui - > act_Export - > isEnabled ( ) ) ;
2022-05-03 10:25:52 +00:00
2022-10-28 01:03:22 +00:00
m_moveToAction - > setEnabled ( ! selectIndexs . empty ( ) & & ( ! dev_que_ . is_online ( ) | | ! m_isScanning ) ) ;
2023-04-08 08:33:36 +00:00
if ( m_pbtn_push ! = nullptr & & m_widget_sideBar ! = nullptr )
{
m_pbtn_push - > setVisible ( nullptr ! = img ) ;
m_widget_sideBar - > setVisible ( nullptr ! = img ) ;
}
2023-04-13 02:51:38 +00:00
m_cbtn_acquireIntoCfg - > setEnabled ( dev_que_ . is_online ( ) & & ! m_isScanning ) ;
2023-04-08 10:43:46 +00:00
ui - > act_adjust - > setEnabled ( ! m_bSideEditing & & nullptr ! = img ) ;
2022-05-03 10:25:52 +00:00
}
void MainWindow : : startSaveMessageBox ( QWidget * parent )
{
HGImage img = nullptr ;
m_view - > getImage ( & img ) ;
2022-05-12 11:21:43 +00:00
if ( nullptr ! = img & & m_modify & & - 1 ! = m_currIndex & & m_multiPageCount = = 1 )
2022-05-03 10:25:52 +00:00
{
QMessageBox msg ( QMessageBox : : Question , tr ( " Question " ) ,
tr ( " modified, save it? " ) ,
QMessageBox : : Yes | QMessageBox : : No , parent ) ;
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 ) ;
2023-01-13 08:21:03 +00:00
cancelBtn - > setText ( tr ( " cancel " ) ) ;
2022-05-03 10:25:52 +00:00
box . setWindowTitle ( tr ( " Question " ) ) ;
box . setText ( tr ( " Already exist images in image list. \n Do 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 ;
}
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 ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
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 ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
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 ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
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 ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
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 ;
}
2023-03-01 09:27:13 +00:00
HGUInt xDpi = 0 ;
HGUInt yDpi = 0 ;
HGBase_GetImageDpi ( img , & xDpi , & yDpi ) ;
2022-05-03 10:25:52 +00:00
Dialog_ImgProc_Adjust dlg ( img , this ) ;
connect ( & dlg , SIGNAL ( applyToImage ( HGImage ) ) , this , SLOT ( on_dialog_adjust_applyToImage ( HGImage ) ) ) ;
2023-03-01 09:27:13 +00:00
HGImage image = NULL ;
2022-05-03 10:25:52 +00:00
if ( dlg . exec ( ) )
{
2023-03-01 09:27:13 +00:00
image = dlg . getAfterImage ( ) ;
HGBase_SetImageDpi ( image , xDpi , yDpi ) ;
m_view - > addImage ( image ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( image ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
m_modify = true ;
}
else
{
2023-03-01 09:27:13 +00:00
image = dlg . getBeforeImage ( ) ;
HGBase_SetImageDpi ( image , xDpi , yDpi ) ;
m_view - > addImage ( image ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( image ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
}
updateStatusBarPixelInfo ( ) ;
updateActionStatus ( ) ;
2022-10-26 10:24:25 +00:00
if ( auto_save_changes_ )
{
on_act_save_triggered ( ) ;
}
2022-05-03 10:25:52 +00:00
disconnect ( & dlg , SIGNAL ( applyToImage ( HGImage ) ) , this , SLOT ( on_dialog_adjust_applyToImage ( HGImage ) ) ) ;
}
void MainWindow : : on_act_open_triggered ( )
{
if ( m_isScanning )
{
return ;
}
2022-11-06 10:13:08 +00:00
QStringList fileNames = QFileDialog : : getOpenFileNames ( nullptr , tr ( " Open images " ) , " " , " (*.jpg *.jpeg *.png *.bmp *.ppm *.pgm *.pbm *.pdf *.tif *.tiff *.ofd *.gif) " ) ;
2022-05-03 10:25:52 +00:00
m_thumb - > addItems ( fileNames ) ;
}
void MainWindow : : on_act_insert_triggered ( )
{
if ( m_isScanning )
{
return ;
}
2022-11-06 10:13:08 +00:00
QStringList fileNames = QFileDialog : : getOpenFileNames ( nullptr , tr ( " Insert images " ) , " " , " (*.jpg *.jpeg *.png *.bmp *.ppm *.pgm *.pbm *.pdf *.tif *.tiff *.ofd *.gif) " ) ;
2022-05-03 10:25:52 +00:00
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 < int > 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 ;
2022-06-02 10:27:14 +00:00
auto_save_info_ . index = 0 ;
auto_save_info_ . path = " " ;
2022-05-03 10:25:52 +00:00
m_thumb - > getItemCount ( & count ) ;
if ( 0 = = count )
{
return ;
}
2022-07-23 08:54:56 +00:00
for ( auto & v : wrong_imgs_ )
{
v - > hide ( ) ;
remove ( v - > image_file ( ) . toStdString ( ) . c_str ( ) ) ;
delete v ;
}
wrong_imgs_ . clear ( ) ;
2022-05-03 10:25:52 +00:00
startSaveMessageBox ( this ) ;
m_thumb - > removeAllItems ( HGImgThumb : : ThumbRemoveFlag_NULL ) ;
}
void MainWindow : : on_act_exit_triggered ( )
{
close ( ) ;
}
void MainWindow : : on_act_save_triggered ( )
{
2022-11-24 09:02:26 +00:00
HGResult ret = HGBASE_ERR_FAIL ;
2022-05-03 10:25:52 +00:00
HGImage img = nullptr ;
m_view - > getImage ( & img ) ;
2022-05-13 07:40:05 +00:00
if ( nullptr = = img | | - 1 = = m_currIndex | | 1 ! = m_multiPageCount )
2022-05-03 10:25:52 +00:00
{
return ;
}
assert ( ! m_currFilePath . isEmpty ( ) ) ;
2022-05-13 07:40:05 +00:00
if ( 0 = = m_currFilePath . indexOf ( Dialog_ClrCache : : getCachePath ( ) ) )
{
2022-10-26 07:10:33 +00:00
QString savePath ;
if ( ! auto_save_changes_ )
savePath = auto_save_info_ . path ;
else
savePath = m_currFilePath ;
2022-06-02 10:27:14 +00:00
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 ;
2023-03-02 07:43:58 +00:00
int ocrLanguageType = 0 ;
2022-06-02 10:27:14 +00:00
bool find = false ;
int count = 0 ;
if ( ! auto_save_changes_ | | auto_save_info_ . path . isEmpty ( ) | | ! judgeDiskSpace ( savePath ) )
2022-11-06 08:00:48 +00:00
{
2022-06-02 10:27:14 +00:00
Dialog_SaveAs dlg ( this ) ;
if ( savePath . length ( ) )
2022-05-27 10:45:51 +00:00
{
2022-06-02 10:27:14 +00:00
int pos = savePath . lastIndexOf ( ' / ' ) ;
if ( pos > 0 )
dlg . set_current_directory ( savePath . left ( pos ) ) ;
2022-05-27 10:45:51 +00:00
}
2022-10-26 06:20:41 +00:00
if ( ! auto_save_changes_ )
2022-05-13 07:40:05 +00:00
{
2022-10-26 06:20:41 +00:00
if ( ! dlg . exec ( ) )
2022-05-13 07:40:05 +00:00
{
2022-06-02 10:27:14 +00:00
return ;
2022-05-13 07:40:05 +00:00
}
2022-06-02 10:27:14 +00:00
}
2022-10-26 06:20:41 +00:00
else
savePath = m_currFilePath ;
if ( ! judgeDiskSpace ( savePath ) )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-06-02 10:27:14 +00:00
return ;
2022-05-13 07:40:05 +00:00
}
2022-10-26 06:20:41 +00:00
if ( ! auto_save_changes_ )
{
savePath = auto_save_info_ . path = dlg . getSavePath ( ) ;
}
2022-11-06 08:00:48 +00:00
2022-10-26 06:20:41 +00:00
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 ( ) ;
2023-03-02 07:43:58 +00:00
ocrLanguageType = dlg . getOcrLanguageType ( ) ;
2022-06-02 10:27:14 +00:00
}
if ( auto_save_changes_ & & save_from_changed_ )
{
// appendix ...
int pos = savePath . lastIndexOf ( ' . ' ) ;
char index [ 20 ] = { 0 } ;
2022-10-26 06:20:41 +00:00
if ( ! auto_save_changes_ )
{
sprintf ( index , " _%03u " , + + auto_save_info_ . index ) ;
}
2022-11-06 08:00:48 +00:00
2022-06-02 10:27:14 +00:00
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 ( ) ) ;
2022-05-13 07:40:05 +00:00
2022-10-26 06:20:41 +00:00
if ( ! auto_save_changes_ )
2022-05-13 07:40:05 +00:00
{
2022-10-26 06:20:41 +00:00
if ( fileName = = savePath )
{
find = true ;
break ;
}
2022-06-02 10:27:14 +00:00
}
2022-10-26 06:20:41 +00:00
2022-06-02 10:27:14 +00:00
}
2022-05-13 12:38:58 +00:00
2022-06-02 10:27:14 +00:00
if ( ! find )
{
HGImgFmtSaveInfo saveInfo ;
saveInfo . jpegQuality = ( HGUInt ) jpegQuality ;
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_NONE ;
saveInfo . tiffJpegQuality = ( HGUInt ) tiffQuality ;
2022-05-27 04:14:39 +00:00
2022-06-02 10:27:14 +00:00
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 ;
}
2023-03-02 07:43:58 +00:00
ret = saveImage ( img , & saveInfo , isOcr , ocrLanguageType , getStdString ( savePath ) . c_str ( ) ) ;
2022-11-24 09:02:26 +00:00
if ( HGBASE_ERR_OK = = ret )
2022-06-02 10:27:14 +00:00
{
2022-10-26 06:20:41 +00:00
if ( auto_save_changes_ )
{
m_thumb - > refreshItem ( m_currIndex ) ;
}
else
m_thumb - > updateItem ( m_currIndex , savePath ) ;
2022-11-06 08:00:48 +00:00
2022-06-02 10:27:14 +00:00
m_currFilePath = savePath ;
m_modify = false ;
2022-10-07 01:56:30 +00:00
if ( ! auto_save_changes_ )
{
QMessageBox : : information ( this , tr ( " tips " ) , tr ( " save succeed " ) ) ;
}
2022-05-13 07:40:05 +00:00
}
else
{
2022-11-24 09:40:18 +00:00
QMessageBox : : critical ( this , tr ( " tips " ) , tr ( " save image doc failed: " ) + getLogInfo ( ret ) ) ;
m_dialogLog - > addLog ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
2022-05-13 07:40:05 +00:00
}
}
2022-06-02 10:27:14 +00:00
else
{
2022-08-20 07:33:44 +00:00
QMessageBox : : information ( this , tr ( " tips " ) , tr ( " find savePath in thumbnail " ) ) ;
2022-06-02 10:27:14 +00:00
}
2022-05-13 07:40:05 +00:00
return ;
}
2022-05-13 12:38:58 +00:00
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 )
{
2022-07-11 03:42:49 +00:00
HGTiffLoadInfo tiffInfo ;
2022-05-13 12:38:58 +00:00
HGImgFmt_LoadImageFromTiffReader ( tiffReader , 0 , & tiffInfo , 0 , 0 , nullptr ) ;
compression = tiffInfo . compression ;
HGImgFmt_CloseTiffReader ( tiffReader ) ;
}
HGUInt xDpi , yDpi ;
HGBase_GetImageDpi ( img , & xDpi , & yDpi ) ;
2022-07-11 03:42:49 +00:00
HGTiffSaveInfo tiffInfo ;
2022-05-13 12:38:58 +00:00
tiffInfo . compression = compression ;
tiffInfo . jpegQuality = 80 ;
tiffInfo . resolutionUnit = HGIMGFMT_TIFFRESUNIT_INCH ;
tiffInfo . xResolution = xDpi ;
tiffInfo . yResolution = yDpi ;
HGTiffWriter tiffWriter = nullptr ;
2022-11-26 03:06:18 +00:00
ret = HGImgFmt_OpenTiffWriter ( getStdString ( m_currFilePath ) . c_str ( ) , & tiffWriter ) ;
if ( HGBASE_ERR_OK = = ret )
2022-05-13 12:38:58 +00:00
{
2022-11-26 03:06:18 +00:00
ret = HGImgFmt_SaveImageToTiffWriter ( tiffWriter , img , & tiffInfo ) ;
2022-05-13 12:38:58 +00:00
HGImgFmt_CloseTiffWriter ( tiffWriter ) ;
}
}
else
{
2022-11-26 03:06:18 +00:00
ret = HGImgFmt_SaveImage ( img , 0 , nullptr , getStdString ( m_currFilePath ) . c_str ( ) ) ;
2022-05-13 12:38:58 +00:00
}
2022-11-26 03:06:18 +00:00
if ( HGBASE_ERR_OK = = ret )
2022-05-03 10:25:52 +00:00
{
2022-06-10 07:28:12 +00:00
if ( auto_save_changes_ & & save_from_changed_ )
m_thumb - > notify_mouse_leave ( ) ;
2022-05-03 10:25:52 +00:00
m_thumb - > refreshItem ( m_currFilePath ) ;
m_modify = false ;
updateActionStatus ( ) ;
2022-10-07 01:56:30 +00:00
if ( ! auto_save_changes_ )
{
QMessageBox : : information ( this , tr ( " tips " ) , tr ( " save succeed " ) ) ;
}
2022-05-03 10:25:52 +00:00
}
else
{
2022-11-24 09:40:18 +00:00
QMessageBox : : critical ( this , tr ( " tips " ) , tr ( " save image doc failed: " ) + getLogInfo ( ret ) ) ;
m_dialogLog - > addLog ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
2022-05-03 10:25:52 +00:00
}
}
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 ( ) ;
2022-05-27 10:45:51 +00:00
if ( ! judgeDiskSpace ( savePath ) )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-27 10:45:51 +00:00
return ;
}
2022-05-03 10:25:52 +00:00
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 )
{
2022-05-13 12:38:58 +00:00
int jpegQuality = dlg . getJpegQuality ( ) ;
2022-05-18 08:40:52 +00:00
int tiffCompressionBW = dlg . getTiffCompressionBW ( ) ;
2022-05-13 12:38:58 +00:00
int tiffCompression = dlg . getTiffCompression ( ) ;
int tiffQuality = dlg . getTiffQuality ( ) ;
2022-05-16 09:00:08 +00:00
bool isOcr = dlg . isOcr ( ) ;
2023-03-02 07:43:58 +00:00
int ocrLanguageType = dlg . getOcrLanguageType ( ) ;
2022-05-13 12:38:58 +00:00
HGImgFmtSaveInfo saveInfo ;
saveInfo . jpegQuality = ( HGUInt ) jpegQuality ;
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_NONE ;
saveInfo . tiffJpegQuality = ( HGUInt ) tiffQuality ;
2022-05-27 04:14:39 +00:00
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 ;
}
2023-03-02 07:43:58 +00:00
HGResult ret = saveImage ( img , & saveInfo , isOcr , ocrLanguageType , getStdString ( savePath ) . c_str ( ) ) ;
2022-11-24 09:02:26 +00:00
if ( HGBASE_ERR_OK = = ret )
2022-05-03 10:25:52 +00:00
{
2022-10-07 01:56:30 +00:00
if ( ! auto_save_changes_ )
{
QMessageBox : : information ( this , tr ( " tips " ) , tr ( " save succeed " ) ) ;
}
2022-05-03 10:25:52 +00:00
}
else
{
2022-11-24 09:40:18 +00:00
QMessageBox : : critical ( this , tr ( " tips " ) , tr ( " save image doc failed: " ) + getLogInfo ( ret ) ) ;
m_dialogLog - > addLog ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " save image doc failed: " ) + getLogInfo ( ret ) , true ) ;
2022-05-03 10:25:52 +00:00
}
}
else
{
2022-08-20 07:33:44 +00:00
QMessageBox : : information ( this , tr ( " tips " ) , tr ( " find savePath in thumbnail " ) ) ;
2022-05-03 10:25:52 +00:00
}
}
}
void MainWindow : : on_act_Export_triggered ( )
{
int count = 0 ;
m_thumb - > getItemCount ( & count ) ;
if ( 0 = = count )
{
return ;
}
std : : vector < int > selectIndexs ;
for ( int i = 0 ; i < count ; + + i )
{
bool select = false ;
m_thumb - > itemIsSelect ( i , & select ) ;
if ( select )
selectIndexs . push_back ( i ) ;
}
2022-11-24 12:00:36 +00:00
if ( selectIndexs . size ( ) = = 0 )
{
QMessageBox : : information ( this , tr ( " tips " ) , tr ( " Please select at least one picture before export " ) ) ;
return ;
}
2022-05-03 10:25:52 +00:00
Dialog_Export dlg ( count , selectIndexs , this ) ;
if ( dlg . exec ( ) )
{
QStringList srcFiles ;
std : : vector < int > saveIndexs ;
dlg . getSaveIndexs ( saveIndexs ) ;
for ( size_t i = 0 ; i < saveIndexs . size ( ) ; + + i )
{
QString fileName ;
2022-10-22 01:32:42 +00:00
m_thumb - > getItemFileName ( saveIndexs [ i ] , fileName ) ;
2022-05-03 10:25:52 +00:00
srcFiles . append ( fileName ) ;
2022-05-27 10:45:51 +00:00
if ( ! judgeDiskSpace ( fileName ) )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-27 10:45:51 +00:00
return ;
}
2022-05-03 10:25:52 +00:00
}
if ( ! srcFiles . isEmpty ( ) )
{
QString savePath = dlg . getSavePath ( ) ;
QString saveName = dlg . getSaveName ( ) ;
QString saveExt = dlg . getSaveExt ( ) ;
bool isSaveAsMulti = dlg . isSaveAsMultiPage ( ) ;
2022-05-13 12:38:58 +00:00
int jpegQuality = dlg . getJpegQuality ( ) ;
int tiffCompressionBW = dlg . getTiffCompressionBW ( ) ;
int tiffCompression = dlg . getTiffCompression ( ) ;
int tiffQuality = dlg . getTiffQuality ( ) ;
2022-05-16 09:00:08 +00:00
bool isOcr = dlg . isOcr ( ) ;
2023-03-02 07:43:58 +00:00
int ocrLanguageType = dlg . getOcrLanguageType ( ) ;
2022-05-03 10:25:52 +00:00
2022-05-13 12:38:58 +00:00
Dialog_ExportImageFile dlgExport ( savePath , saveName , saveExt , isSaveAsMulti , jpegQuality ,
2023-03-02 07:43:58 +00:00
tiffCompressionBW , tiffCompression , tiffQuality , isOcr , ocrLanguageType , srcFiles , this ) ;
2022-05-03 10:25:52 +00:00
dlgExport . exec ( ) ;
}
}
}
void MainWindow : : on_act_imageInfo_triggered ( )
{
if ( - 1 = = m_currIndex )
{
return ;
}
assert ( ! m_currFilePath . isEmpty ( ) ) ;
QFileInfo info ( m_currFilePath ) ;
2022-08-29 03:11:17 +00:00
HGImage image = NULL ;
m_view - > getImage ( & image ) ;
if ( nullptr = = image )
2022-05-03 10:25:52 +00:00
{
2022-08-29 03:11:17 +00:00
return ;
}
2022-08-23 04:42:01 +00:00
2022-08-29 03:11:17 +00:00
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( image , & imgInfo ) ;
2022-08-23 04:42:01 +00:00
2022-08-29 03:11:17 +00:00
HGUInt xDpi , yDpi ;
HGBase_GetImageDpi ( image , & xDpi , & yDpi ) ;
2022-05-03 10:25:52 +00:00
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 ( ) ;
2022-05-24 05:45:07 +00:00
QDateTime c_date = info . created ( ) ;
2022-05-03 10:25:52 +00:00
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
2022-08-29 03:11:17 +00:00
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 ;
2022-05-03 10:25:52 +00:00
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
2023-02-27 07:26:39 +00:00
if ( 0 = = xDpi | | 0 = = yDpi )
{
QString info = tr ( " Not supported " ) ;
imageValues . append ( info ) ;
imageValues . append ( info ) ;
}
else
{
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
}
2022-05-03 10:25:52 +00:00
imageValues . append ( QString : : number ( m_multiIndex ) ) ;
Dialog_ImageInfo d ( fileKeys , fileValues , imageKeys , imageValues , this ) ;
d . exec ( ) ;
}
void MainWindow : : closeEvent ( QCloseEvent * e )
{
if ( m_isScanning )
{
2023-01-28 07:32:08 +00:00
m_closeTip = true ;
2022-05-03 10:25:52 +00:00
QMessageBox : : warning ( this , tr ( " Warning " ) , tr ( " Device is Running! \n Please finish scanning first. " ) ) ;
e - > ignore ( ) ;
return ;
}
2022-05-13 07:40:05 +00:00
bool cache_saved = true ;
2022-05-03 10:25:52 +00:00
int count = 0 ;
m_thumb - > getItemCount ( & count ) ;
2022-05-13 07:40:05 +00:00
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 ;
}
}
2022-07-14 11:13:00 +00:00
if ( m_closeTip )
2022-05-03 10:25:52 +00:00
{
2022-07-14 11:13:00 +00:00
if ( ! cache_saved | | m_modify )
2022-05-13 07:40:05 +00:00
{
2022-07-14 11:13:00 +00:00
QMessageBox msg ( QMessageBox : : Question , tr ( " Question " ) ,
tr ( " There are pictures that have not been saved. \n Are you sure to close? " ) ,
QMessageBox : : Yes | QMessageBox : : No , this ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) ! = msg . button ( QMessageBox : : Yes ) )
{
e - > ignore ( ) ;
return ;
}
2022-05-13 07:40:05 +00:00
}
2022-07-14 11:13:00 +00:00
else
2022-05-03 10:25:52 +00:00
{
2022-07-14 11:13:00 +00:00
QMessageBox msg ( QMessageBox : : Question , tr ( " tips " ) ,
tr ( " Are you sure to close? " ) ,
QMessageBox : : Yes | QMessageBox : : No , this ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) ! = msg . button ( QMessageBox : : Yes ) )
{
e - > ignore ( ) ;
return ;
}
2022-05-03 10:25:52 +00:00
}
}
2023-01-11 11:03:54 +00:00
QString cachePath = Dialog_ClrCache : : getCachePath ( ) ;
QDir dir = QDir ( cachePath ) ;
2023-02-15 13:43:18 +00:00
if ( dir . exists ( ) & & ( cachePath . endsWith ( " Cache/ " ) | | cachePath . endsWith ( " Cache \\ " ) ) )
2023-01-10 04:03:02 +00:00
dir . removeRecursively ( ) ;
2022-07-28 09:22:27 +00:00
2023-01-13 05:56:24 +00:00
m_versionDll - > PostUserCloseInfo ( HGVERSION_APPNAME_SCANNER , m_oemName ) ;
2022-05-03 10:25:52 +00:00
}
2023-04-08 08:33:36 +00:00
void MainWindow : : resizeEvent ( QResizeEvent * e )
{
( void ) e ;
if ( m_bSideflag )
{
int mainWndWidth = this - > rect ( ) . width ( ) ;
int mainWndHeight = this - > rect ( ) . height ( ) ;
2023-04-08 10:43:46 +00:00
int sideBarWidth = m_widget_sideBar - > width ( ) ;
int sideBarHeight = m_widget_sideBar - > height ( ) ;
2023-04-08 08:33:36 +00:00
m_widget_sideBar - > move ( mainWndWidth - sideBarWidth , mainWndHeight / 2 - sideBarHeight / 2 ) ;
m_pbtn_push - > move ( mainWndWidth - m_pbtn_push - > width ( ) - sideBarWidth , mainWndHeight / 2 - m_pbtn_push - > height ( ) / 2 ) ;
}
else
{
updateSideBar ( ) ;
}
}
2022-05-03 10:25:52 +00:00
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 )
2022-05-27 01:40:25 +00:00
{
if ( 1 = = sane_img - > header . depth )
imgType = HGBASE_IMGTYPE_BINARY ;
else if ( 8 = = sane_img - > header . depth )
imgType = HGBASE_IMGTYPE_GRAY ;
}
2022-05-27 03:05:17 +00:00
else if ( sane_img - > header . format = = SANE_FRAME_RGB )
2022-05-27 01:40:25 +00:00
{
2022-05-03 10:25:52 +00:00
imgType = HGBASE_IMGTYPE_RGB ;
2022-05-27 01:40:25 +00:00
}
2022-05-03 10:25:52 +00:00
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 ;
2023-04-13 01:43:57 +00:00
HGBase_CreateImageWithData ( imgData , & imgInfo , & img ) ;
2022-05-03 10:25:52 +00:00
if ( nullptr ! = img )
{
2023-04-13 01:43:57 +00:00
emit p - > pre_new_image ( img ) ;
2023-04-12 10:36:38 +00:00
2023-04-13 01:43:57 +00:00
HGResult ret = HGBASE_ERR_FAIL ;
if ( 1 = = p - > m_saveType )
{
2023-04-12 10:36:38 +00:00
HGImgFmtSaveInfo info ;
info . jpegQuality = 100 ;
info . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
info . tiffJpegQuality = 0 ;
2023-04-13 01:43:57 +00:00
ret = HGImgFmt_SaveImage ( img , 0 , & info , getStdString ( p - > m_scanFileName ) . c_str ( ) ) ;
2023-04-12 10:36:38 +00:00
}
2023-04-13 01:43:57 +00:00
else if ( 2 = = p - > m_saveType )
2023-04-12 10:36:38 +00:00
{
2023-04-13 01:43:57 +00:00
HGImgFmtSaveInfo saveInfo ;
saveInfo . jpegQuality = ( HGUInt ) p - > m_aquireIntoSaveParam . m_jpegQuality ;
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_NONE ;
saveInfo . tiffJpegQuality = ( HGUInt ) p - > m_aquireIntoSaveParam . m_tiffQuality ;
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( img , & imgInfo ) ;
if ( HGBASE_IMGTYPE_BINARY = = imgInfo . type )
2023-04-12 10:36:38 +00:00
{
2023-04-13 01:43:57 +00:00
if ( 1 = = p - > m_aquireIntoSaveParam . m_tiffCompressionBW )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
else if ( 2 = = p - > m_aquireIntoSaveParam . m_tiffCompressionBW )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4 ;
2023-04-12 10:36:38 +00:00
}
2023-04-13 01:43:57 +00:00
else
2023-04-12 10:36:38 +00:00
{
2023-04-13 01:43:57 +00:00
if ( 1 = = p - > m_aquireIntoSaveParam . m_tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
else if ( 2 = = p - > m_aquireIntoSaveParam . m_tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_JPEG ;
2023-04-12 10:36:38 +00:00
}
2023-04-13 01:43:57 +00:00
ret = HGImgFmt_SaveImageToWriter ( p - > m_scanImgFmtWriter , img , & saveInfo ) ;
}
else if ( 3 = = p - > m_saveType )
{
HGImgFmtSaveInfo saveInfo ;
saveInfo . jpegQuality = ( HGUInt ) p - > m_aquireIntoSaveParam . m_jpegQuality ;
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_NONE ;
saveInfo . tiffJpegQuality = ( HGUInt ) p - > m_aquireIntoSaveParam . m_tiffQuality ;
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( img , & imgInfo ) ;
if ( HGBASE_IMGTYPE_BINARY = = imgInfo . type )
2023-04-12 10:36:38 +00:00
{
2023-04-13 01:43:57 +00:00
if ( 1 = = p - > m_aquireIntoSaveParam . m_tiffCompressionBW )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
else if ( 2 = = p - > m_aquireIntoSaveParam . m_tiffCompressionBW )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4 ;
2023-04-12 10:36:38 +00:00
}
else
{
2023-04-13 01:43:57 +00:00
if ( 1 = = p - > m_aquireIntoSaveParam . m_tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
else if ( 2 = = p - > m_aquireIntoSaveParam . m_tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_JPEG ;
2023-04-12 10:36:38 +00:00
}
2023-04-13 01:43:57 +00:00
ret = saveImage ( img , & saveInfo , p - > m_aquireIntoSaveParam . m_isOcr , 0 , getStdString ( p - > m_scanFileName ) . c_str ( ) ) ;
2023-04-12 10:36:38 +00:00
}
2023-04-13 01:43:57 +00:00
emit p - > post_new_image ( ret , sane_img - > flag . statu ) ;
2023-04-12 10:36:38 +00:00
HGBase_DestroyImage ( img ) ;
2022-05-03 10:25:52 +00:00
}
}
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 ;
}
2022-10-12 03:51:41 +00:00
void HGAPI MainWindow : : CrashFunc ( HGPointer crashAddr , HGPointer param )
2022-07-14 10:45:35 +00:00
{
MainWindow * p = ( MainWindow * ) param ;
2023-02-01 03:25:11 +00:00
HGChar crashName [ 256 ] ;
HGBase_GetLogFilePath ( crashName , 256 ) ;
strcat ( crashName , " crash.dmp " ) ;
if ( HGBASE_ERR_OK = = HGBase_MakeCrashFile ( crashName ) )
2022-07-14 10:45:35 +00:00
{
HGChar excpStr [ 64 ] ;
# ifdef HG_64BIT
sprintf ( excpStr , " 0x%016p " , crashAddr ) ;
# else
sprintf ( excpStr , " 0x%08p " , crashAddr ) ;
# endif
2023-02-01 03:25:11 +00:00
p - > m_versionDll - > PostCrashInfo ( HGVERSION_APPNAME_SCANNER , p - > m_oemName , " crash " , crashName , excpStr ) ;
2022-07-14 10:45:35 +00:00
}
}
2022-05-03 10:25:52 +00:00
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 ;
}
2023-03-01 09:17:36 +00:00
HGUInt xDpi = 0 ;
HGUInt yDpi = 0 ;
HGBase_GetImageDpi ( img , & xDpi , & yDpi ) ;
2022-05-03 10:25:52 +00:00
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 ( ) ;
2022-05-12 03:26:09 +00:00
bool isUseAdvParam = dlg . isUseAdvancedParam ( ) ;
2022-05-03 10:25:52 +00:00
int threshold = dlg . getThreshold ( ) ;
int noise = dlg . getNoise ( ) ;
int indent = dlg . getIndent ( ) ;
2022-05-12 03:26:09 +00:00
HGImgAutoCropParam autoCropParam ;
2022-10-19 03:14:07 +00:00
autoCropParam . normalCrop = HGFALSE ;
autoCropParam . dispersion = HGTRUE ;
2022-05-12 03:26:09 +00:00
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 ;
}
2022-05-03 10:25:52 +00:00
2022-10-19 03:14:07 +00:00
if ( isCrop | | isDeskew | | isFillBlank )
2022-05-03 10:25:52 +00:00
{
2022-10-19 03:14:07 +00:00
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( img , & imgInfo ) ;
2022-05-03 10:25:52 +00:00
2022-10-19 03:14:07 +00:00
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 )
{
2023-03-01 09:17:36 +00:00
HGBase_SetImageDpi ( destImage , xDpi , yDpi ) ;
2022-10-19 03:14:07 +00:00
m_view - > addImage ( destImage ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( destImage ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-10-19 03:14:07 +00:00
HGBase_DestroyImage ( destImage ) ;
m_modify = true ;
updateStatusBarPixelInfo ( ) ;
updateActionStatus ( ) ;
2022-10-26 10:24:25 +00:00
if ( auto_save_changes_ )
{
on_act_save_triggered ( ) ;
}
2022-10-19 03:14:07 +00:00
}
2022-05-03 10:25:52 +00:00
}
}
}
void MainWindow : : on_act_signIn_triggered ( )
{
if ( m_admin_loggedIn )
{
return ;
}
Dialog_Admin dlg ( m_password , this ) ;
m_admin_loggedIn = dlg . exec ( ) ;
updateActionStatus ( ) ;
2022-07-28 09:22:27 +00:00
if ( m_admin_loggedIn )
2023-01-13 05:56:24 +00:00
m_versionDll - > PostUserLoginInfo ( HGVERSION_APPNAME_SCANNER , m_oemName ) ;
2022-05-03 10:25:52 +00:00
}
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 . exec ( ) ;
if ( msg . clickedButton ( ) = = msg . button ( QMessageBox : : Yes ) )
{
m_admin_loggedIn = false ;
updateActionStatus ( ) ;
2023-01-13 05:56:24 +00:00
m_versionDll - > PostUserLogoutInfo ( HGVERSION_APPNAME_SCANNER , m_oemName ) ;
2022-07-27 03:32:46 +00:00
}
2022-05-03 10:25:52 +00:00
}
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 ;
}
2022-05-26 10:49:22 +00:00
QMessageBox msg ( QMessageBox : : Question , tr ( " confirm operation " ) ,
tr ( " are you sure to clear the roller count? " ) ,
QMessageBox : : Yes | QMessageBox : : No , this ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) ! = msg . button ( QMessageBox : : Yes ) )
2022-05-12 07:34:40 +00:00
return ;
2022-05-03 10:25:52 +00:00
unsigned int count = 0 ;
2022-12-14 01:25:16 +00:00
int ret = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT , nullptr , & count ) ;
2022-05-03 10:25:52 +00:00
if ( ret = = SANE_STATUS_GOOD )
2022-07-27 10:41:21 +00:00
{
2022-05-03 10:25:52 +00:00
QMessageBox : : information ( this , tr ( " hint " ) , tr ( " Roller scanned count has been set to 0. " ) ) ;
2022-07-28 09:22:27 +00:00
m_versionDll - > PostDeviceClearRollerInfo ( m_currDeviceName . toStdString ( ) . c_str ( ) , m_devSerialNum . toStdString ( ) . c_str ( ) , " " , m_devVersionNum . toStdString ( ) . c_str ( ) ) ;
2022-07-27 10:41:21 +00:00
}
2022-05-03 10:25:52 +00:00
else
QMessageBox : : information ( this , tr ( " hint " ) , tr ( " Roller scanned count reset failed. " ) ) ;
}
void MainWindow : : on_act_help_triggered ( )
{
# if defined(HG_CMP_MSC)
2022-05-26 09:26:07 +00:00
# if defined(OEM_HANWANG)
QString filename = QApplication : : applicationDirPath ( ) + " /HanvonScan_App_Help_manual.pdf " ;
# elif defined(OEM_LISICHENG)
2022-05-31 08:46:50 +00:00
QString filename = QApplication : : applicationDirPath ( ) + " /LanxumScan_App_Help_manual.pdf " ;
2022-11-10 01:11:57 +00:00
# elif defined(OEM_CANGTIAN)
QString filename = QApplication : : applicationDirPath ( ) + " /CumtennScan_App_Help_manual.pdf " ;
2023-01-29 09:02:57 +00:00
# elif defined(OEM_ZHONGJING)
QString filename = QApplication : : applicationDirPath ( ) + " /MicrotekScan_App_Help_manual.pdf " ;
2023-03-10 05:39:50 +00:00
# elif defined(OEM_ZIGUANG)
QString filename = QApplication : : applicationDirPath ( ) + " /UniScan_App_Help_manual.pdf " ;
2022-05-26 09:26:07 +00:00
# else
QString filename = QApplication : : applicationDirPath ( ) + " /HuaGoScan_App_Help_manual.pdf " ;
# endif
2022-05-17 03:59:09 +00:00
# else
2023-03-07 08:03:37 +00:00
QString filename ;
std : : string osName ;
FILE * file = popen ( " cat /etc/issue | cut -d \' \' -f1 " , " r " ) ;
if ( NULL ! = file )
{
char data [ 1024 ] = { 0 } ;
if ( NULL ! = fgets ( data , 1024 , file ) )
osName = data ;
pclose ( file ) ;
}
printf ( " osName=%s \n " , osName . c_str ( ) ) ;
if ( osName . find ( " UnionTech " ) ! = std : : string : : npos )
{
# if defined(OEM_HANWANG)
filename = " /opt/apps/com.hanvonchina.hanvonscan/entries/help/HanvonScan_App_Help_manual.pdf " ;
# elif defined(OEM_LISICHENG)
filename = " /opt/apps/com.lanxumchina.lanxumscan/entries/help/LanxumScan_App_Help_manual.pdf " ;
# elif defined(OEM_CANGTIAN)
filename = " /opt/apps/com.cumtennchina.cumtennscan/entries/help/CumtennScan_App_Help_manual.pdf " ;
# elif defined(OEM_ZHONGJING)
2023-03-16 11:06:20 +00:00
filename = " /opt/apps/com.microtekchina.microtekscan-ex/entries/help/MicrotekScan_App_Help_manual.pdf " ;
2023-03-10 05:39:50 +00:00
# elif defined(OEM_ZIGUANG)
2023-03-10 10:31:39 +00:00
filename = " /opt/apps/com.unischina.uniscan/entries/help/UniScan_App_Help_manual.pdf " ;
2023-03-07 08:03:37 +00:00
# else
filename = " /opt/apps/com.huagaochina.huagoscan/entries/help/HuaGoScan_App_Help_manual.pdf " ;
# endif
}
else
{
# if defined(OEM_HANWANG)
filename = " /opt/apps/scanner-driver-hanvon/doc/HanvonScan_App_Help_manual.pdf " ;
# elif defined(OEM_LISICHENG)
filename = " /opt/apps/scanner-driver-lanxum/doc/LanxumScan_App_Help_manual.pdf " ;
# elif defined(OEM_CANGTIAN)
filename = " /opt/apps/scanner-driver-cumtenn/doc/CumtennScan_App_Help_manual.pdf " ;
# elif defined(OEM_ZHONGJING)
2023-03-16 11:06:20 +00:00
filename = " /opt/apps/scanner-driver-microtek-ex/doc/MicrotekScan_App_Help_manual.pdf " ;
2023-03-10 05:39:50 +00:00
# elif defined(OEM_ZIGUANG)
2023-03-15 08:07:23 +00:00
filename = " /opt/apps/scanner-driver-unis/doc/UniScan_App_Help_manual.pdf " ;
2023-03-07 08:03:37 +00:00
# else
filename = " /opt/apps/scanner-driver-huagao/doc/HuaGoScan_App_Help_manual.pdf " ;
# endif
}
2022-05-03 10:25:52 +00:00
# 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 ) ) ;
}
2022-05-10 10:15:37 +00:00
void MainWindow : : my_url_handler ( const QUrl & url )
{
std : : string to ( url . url ( ) . toStdString ( ) ) ;
if ( to . find ( " ://clear-roller " ) ! = std : : string : : npos )
{
2022-05-27 10:45:51 +00:00
QMessageBox msg ( QMessageBox : : Question , tr ( " confirm the operation " ) ,
tr ( " Are you sure to clear the rollor acount? " ) ,
2022-05-26 10:49:22 +00:00
QMessageBox : : Yes | QMessageBox : : No , this ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) = = msg . button ( QMessageBox : : Yes ) )
2022-05-10 10:15:37 +00:00
{
2022-05-12 07:34:40 +00:00
unsigned int count = 0 ;
2022-12-14 01:25:16 +00:00
int ret = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT , nullptr , & count ) ;
2022-05-10 10:15:37 +00:00
2022-05-12 07:34:40 +00:00
QString info ;
if ( ret = = SANE_STATUS_GOOD )
{
info = tr ( " Roller scanned count has been set to 0. " ) ;
2022-05-10 10:15:37 +00:00
2022-11-06 08:00:48 +00:00
// +鐠囩兘鍣搁弬鎷岀箻閸忋儱鍙ф禍搴f櫕闂堫澀浜掗懢宄板絿閺堚偓閺傛澘鈧? info += tr("Please re-enter the Abount screen to obtain the latest value");
2022-05-12 07:34:40 +00:00
}
else
info = tr ( " Roller scanned count reset failed. " ) ;
QMessageBox : : information ( this , tr ( " hint " ) , info ) ;
}
2022-05-10 10:15:37 +00:00
}
}
2022-05-03 10:25:52 +00:00
void MainWindow : : on_act_about_triggered ( )
{
SANE_About * about = nullptr ;
unsigned int len = 0 ;
2023-02-03 09:38:13 +00:00
QString title ;
QString content ;
std : : list < QString > info ;
2022-05-10 10:15:37 +00:00
QDesktopServices : : setUrlHandler ( MY_URL_SCHEME , this , " my_url_handler " ) ;
2022-10-28 01:03:22 +00:00
if ( sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_ABOUT_INFO , about , & len ) = = SANE_STATUS_NO_MEM )
2022-05-03 10:25:52 +00:00
{
about = ( SANE_About * ) malloc ( len + 128 ) ;
if ( about )
{
memset ( about , 0 , len + 128 ) ;
2022-10-28 01:03:22 +00:00
if ( sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_ABOUT_INFO , about , & len ) = = SANE_STATUS_GOOD )
2022-05-03 10:25:52 +00:00
{
2023-02-03 09:38:13 +00:00
# if defined(OEM_ZHONGJING)
title = tr ( " about %1 " ) . arg ( QString : : fromStdString ( about - > title ) ) ;
info . push_back ( tr ( " <p>Version: %1</p> " ) . arg ( QString : : fromStdString ( about - > version ) ) ) ;
for ( int i = 0 ; about - > appendix [ i ] . key ; + + i )
{
if ( about - > appendix [ i ] . url )
info . push_back ( tr ( " <p>%1: <a href='%2'>%3</a> " ) . arg ( about - > appendix [ i ] . key ) . arg ( about - > appendix [ i ] . url ) . arg ( about - > appendix [ i ] . content ) + " </p> " ) ;
else
info . push_back ( tr ( " <p>%1: %2 " ) . arg ( about - > appendix [ i ] . key ) . arg ( about - > appendix [ i ] . content ) + " </p> " ) ;
}
info . push_back ( tr ( " <p>CopyRight: © %1</p> " ) . arg ( QString : : fromStdString ( about - > copyright ) ) ) ;
const char * cmp [ ] = {
2023-02-16 07:17:41 +00:00
BRAND_TITLE_DEVICE_MODEL ,
2023-02-03 09:38:13 +00:00
about - > version ,
BRAND_TITLE_FIRM_VERSION ,
BRAND_TITLE_SERIAL_NUM ,
BRAND_TITLE_ROLLER_COUNT ,
BRAND_TITLE_HISTORY_COUNT ,
BRAND_TITLE_IP ,
BRAND_TITE_MANUFACTOR ,
BRAND_COMPANY_ADDRESS ,
BRAND_TITLE_TEL ,
BRAND_TITLE_URL ,
BRAND_TITLE_GPS ,
about - > copyright
} ;
for ( int i = 0 ; i < sizeof ( cmp ) / sizeof ( const char * ) ; + + i )
{
std : : list < QString > : : iterator iter = info . begin ( ) ;
while ( iter ! = info . end ( ) )
{
if ( iter - > contains ( from_default_language ( cmp [ i ] , nullptr ) ) )
{
content + = * iter ;
info . erase ( iter ) ;
break ;
}
else
{
+ + iter ;
}
}
}
std : : list < QString > : : iterator iter = info . begin ( ) ;
while ( iter ! = info . end ( ) )
{
content + = * iter ;
+ + iter ;
}
# else
2022-05-03 10:25:52 +00:00
title = tr ( " about %1 " ) . arg ( QString : : fromStdString ( about - > title ) ) ;
content = tr ( " <p>Version: %1</p> " ) . arg ( QString : : fromStdString ( about - > version ) ) ;
content + = tr ( " <p>CopyRight: © %1</p> " ) . arg ( QString : : fromStdString ( about - > copyright ) ) ;
for ( int i = 0 ; about - > appendix [ i ] . key ; + + i )
{
if ( about - > appendix [ i ] . url )
2022-05-10 10:15:37 +00:00
content + = tr ( " <p>%1: <a href='%2'>%3</a> " ) . arg ( about - > appendix [ i ] . key ) . arg ( about - > appendix [ i ] . url ) . arg ( about - > appendix [ i ] . content ) ;
2022-05-03 10:25:52 +00:00
else
2022-05-10 10:15:37 +00:00
content + = tr ( " <p>%1: %2 " ) . arg ( about - > appendix [ i ] . key ) . arg ( about - > appendix [ i ] . content ) ;
2022-05-11 01:35:05 +00:00
if ( m_admin_loggedIn
2022-05-27 10:45:51 +00:00
& & strcmp ( about - > appendix [ i ] . key , tr ( " roller number " ) . toLatin1 ( ) . data ( ) ) = = 0
2022-05-11 01:35:05 +00:00
& & atoi ( about - > appendix [ i ] . content ) > 0 )
2022-05-10 10:15:37 +00:00
{
char url [ 128 ] = { 0 } ;
sprintf ( url , " <a href=%s://clear-roller> \346 \270 \205 \351 \231 \244 </a> " , MY_URL_SCHEME ) ;
content + = QString : : fromStdString ( url ) ;
}
content + = " </p> " ;
2022-05-03 10:25:52 +00:00
}
2023-02-03 09:38:13 +00:00
# endif
2022-05-03 10:25:52 +00:00
}
free ( about ) ;
}
}
2023-02-03 09:38:13 +00:00
2022-05-03 10:25:52 +00:00
QMessageBox : : about ( this , title , content ) ;
2022-05-10 10:15:37 +00:00
QDesktopServices : : unsetUrlHandler ( MY_URL_SCHEME ) ;
2022-05-03 10:25:52 +00:00
}
void MainWindow : : on_act_scannerSettings_triggered ( )
{
2022-10-28 01:03:22 +00:00
if ( ! dev_que_ . is_online ( ) | | m_isScanning )
2022-05-03 10:25:52 +00:00
{
return ;
}
2022-10-28 01:03:22 +00:00
hg_settingdialog dlg ( dev_que_ . handle ( ) , this , & dev_que_ ) ;
2022-05-03 10:25:52 +00:00
dlg . exec ( ) ;
2022-10-28 01:03:22 +00:00
ui - > menu_device - > deviceMenuUpdate ( & dev_que_ ) ;
2022-05-03 10:25:52 +00:00
}
void MainWindow : : on_act_acquire_triggered ( )
{
2023-02-22 07:18:06 +00:00
if ( ! isLimitAccessFolder ( 1 ) )
2022-08-13 09:47:29 +00:00
{
return ;
}
2022-10-28 01:03:22 +00:00
if ( ! dev_que_ . is_online ( ) | | m_isScanning )
2022-05-03 10:25:52 +00:00
{
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 ;
startSaveMessageBox ( this ) ;
2022-05-20 10:44:24 +00:00
m_dpi = getDpi ( ) ;
2022-10-28 01:03:22 +00:00
SANE_Status ret = sane_start ( dev_que_ . handle ( ) ) ;
2022-05-03 10:25:52 +00:00
if ( ret ! = SANE_STATUS_GOOD )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " start failed " ) , true ) ;
2022-08-02 10:09:02 +00:00
m_dialogLog - > addLog ( tr ( " start failed " ) + " ( " + QString ( sane_err_desc ( ret ) ) + " ) " , true ) ;
2022-05-03 10:25:52 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( tr ( " start failed " ) ) . c_str ( ) ) ;
2022-08-22 07:25:37 +00:00
if ( ret = = SCANNER_ERR_DEVICE_SLEEPING )
{
ui - > menu_scan - > setEnabled ( false ) ;
ui - > act_acquire - > setEnabled ( false ) ;
ui - > act_scannerSettings - > setEnabled ( false ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( false , false ) ;
2022-08-26 08:20:59 +00:00
m_dialogLog - > show ( ) ;
2023-02-06 08:18:47 +00:00
2023-04-12 10:44:20 +00:00
if ( m_devVersionNum < " G4393B1001 "
& & ( " 439 " = = getDevPid ( ) | | " 9220 " = = getDevPid ( ) | | " 8529 " = = getDevPid ( ) | | " 7039 " = = getDevPid ( ) ) ) //Previous versions of this firmware number and 439 device can only be manually awakened.
2023-02-06 08:18:47 +00:00
{
m_dialogLog - > addLog ( tr ( " Please wake up the device manually " ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " Please wake up the device manually " ) , true ) ;
}
else
2022-08-22 07:25:37 +00:00
{
2023-02-06 08:18:47 +00:00
QTime curTimer = QTime : : currentTime ( ) . addMSecs ( 10000 ) ;
while ( QTime : : currentTime ( ) < curTimer )
{
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
}
m_dialogLog - > addLog ( tr ( " already waked up device " ) , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " already waked up device " ) , false ) ;
2022-08-22 07:25:37 +00:00
}
2023-02-06 08:18:47 +00:00
2022-08-22 07:25:37 +00:00
ui - > menu_scan - > setEnabled ( true ) ;
ui - > act_acquire - > setEnabled ( true ) ;
ui - > act_scannerSettings - > setEnabled ( true ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( true , false ) ;
2022-08-22 07:25:37 +00:00
}
2022-05-03 10:25:52 +00:00
}
else
{
m_isScanning = true ;
m_thumb - > setAcceptDrops ( false ) ;
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
}
m_dialogLog - > show ( ) ;
}
void MainWindow : : on_act_acquireSingle_triggered ( )
{
2023-02-22 07:18:06 +00:00
if ( ! isLimitAccessFolder ( 1 ) )
2022-08-15 01:27:15 +00:00
{
return ;
}
2022-10-28 01:03:22 +00:00
if ( ! dev_que_ . is_online ( ) | | m_isScanning )
2022-05-03 10:25:52 +00:00
{
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 ;
startSaveMessageBox ( this ) ;
2022-05-20 10:44:24 +00:00
m_dpi = getDpi ( ) ;
2022-10-28 01:03:22 +00:00
SANE_Status ret = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_TEST_SINGLE , nullptr , nullptr ) ;
2022-05-03 10:25:52 +00:00
if ( ret ! = SANE_STATUS_GOOD )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " start failed " ) , true ) ;
2022-08-02 10:21:32 +00:00
m_dialogLog - > addLog ( tr ( " start failed " ) + " ( " + QString ( sane_err_desc ( ret ) ) + " ) " , true ) ;
2022-05-03 10:25:52 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( tr ( " start failed " ) ) . c_str ( ) ) ;
2022-08-22 07:25:37 +00:00
if ( ret = = SCANNER_ERR_DEVICE_SLEEPING )
{
ui - > menu_scan - > setEnabled ( false ) ;
ui - > act_acquire - > setEnabled ( false ) ;
ui - > act_scannerSettings - > setEnabled ( false ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( false , false ) ;
2022-08-26 08:20:59 +00:00
m_dialogLog - > show ( ) ;
2023-02-06 08:18:47 +00:00
2023-04-12 10:44:20 +00:00
if ( m_devVersionNum < " G4393B1001 "
& & ( " 439 " = = getDevPid ( ) | | " 9220 " = = getDevPid ( ) | | " 8529 " = = getDevPid ( ) ) )
2023-02-06 08:18:47 +00:00
{
m_dialogLog - > addLog ( tr ( " Please wake up the device manually " ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " Please wake up the device manually " ) , true ) ;
}
else
2022-08-22 07:25:37 +00:00
{
2023-02-06 08:18:47 +00:00
QTime curTimer = QTime : : currentTime ( ) . addMSecs ( 10000 ) ;
while ( QTime : : currentTime ( ) < curTimer )
{
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
}
m_dialogLog - > addLog ( tr ( " already waked up device " ) , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " already waked up device " ) , false ) ;
2022-08-22 07:25:37 +00:00
}
2023-02-06 08:18:47 +00:00
2022-08-22 07:25:37 +00:00
ui - > menu_scan - > setEnabled ( true ) ;
ui - > act_acquire - > setEnabled ( true ) ;
ui - > act_scannerSettings - > setEnabled ( true ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( true , false ) ;
2022-08-22 07:25:37 +00:00
}
2022-05-03 10:25:52 +00:00
}
else
{
m_isScanning = true ;
m_thumb - > setAcceptDrops ( false ) ;
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
}
m_dialogLog - > show ( ) ;
}
void MainWindow : : on_act_acquireInto_triggered ( )
{
2022-10-28 01:03:22 +00:00
if ( ! dev_que_ . is_online ( ) | | m_isScanning )
2022-05-03 10:25:52 +00:00
{
return ;
}
int count = 0 ;
m_thumb - > getItemCount ( & count ) ;
if ( count ! = 0 )
{
int result = startScanMessageBox ( this ) ;
if ( cancelScan = = result )
return ;
}
Dialog_AquireInto dlg ( this ) ;
2023-03-31 07:22:07 +00:00
connect ( & dlg , SIGNAL ( reloadAcquireIntoCfg ( ) ) , this , SLOT ( on_reloadAcquireIntoCfg ( ) ) ) ;
2022-05-03 10:25:52 +00:00
if ( dlg . exec ( ) )
{
m_singleScan = false ;
m_scanType = 2 ;
m_aquireIntoSaveParam = dlg . getSaveParam ( ) ;
2022-05-16 02:43:51 +00:00
m_aquireIntoInBlank = true ;
m_aquireIntoBatchStartIndex = 0 ;
m_aquireIntoPageIndex = 0 ;
m_aquireIntoMultiPageCount = 0 ;
2022-05-03 10:25:52 +00:00
2022-05-16 02:43:51 +00:00
QDateTime dateTime = QDateTime : : currentDateTime ( ) ;
2022-05-03 10:25:52 +00:00
if ( m_aquireIntoSaveParam . m_isUseSubfolderByTime )
{
2022-05-16 02:43:51 +00:00
m_aquireIntoSaveParam . m_savePath = getStdFileName ( m_aquireIntoSaveParam . m_savePath + dateTime . toString ( " yyyy-MM-dd " ) + " / " ) ;
2022-05-03 10:25:52 +00:00
}
2022-08-16 04:25:48 +00:00
// m_aquireIntoSaveParam.m_savePath = getStdFileName(m_aquireIntoSaveParam.m_savePath + dateTime.toString("yyyyMMddhhmmss") + "/");
2022-05-16 02:43:51 +00:00
2022-10-25 11:17:33 +00:00
2023-02-22 07:18:06 +00:00
if ( ! isLimitAccessFolder ( 2 ) )
2022-10-25 11:17:33 +00:00
{
return ;
}
2022-05-03 10:25:52 +00:00
startSaveMessageBox ( this ) ;
2022-05-20 10:44:24 +00:00
m_dpi = getDpi ( ) ;
2022-10-28 01:03:22 +00:00
SANE_Status ret = sane_start ( dev_que_ . handle ( ) ) ;
2022-05-03 10:25:52 +00:00
if ( ret ! = SANE_STATUS_GOOD )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " start failed " ) , true ) ;
2022-08-02 10:09:02 +00:00
m_dialogLog - > addLog ( tr ( " start failed " ) + " ( " + QString ( sane_err_desc ( ret ) ) + " ) " , true ) ;
2022-05-03 10:25:52 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( tr ( " start failed " ) ) . c_str ( ) ) ;
2022-08-22 07:25:37 +00:00
if ( ret = = SCANNER_ERR_DEVICE_SLEEPING )
{
ui - > menu_scan - > setEnabled ( false ) ;
ui - > act_acquire - > setEnabled ( false ) ;
ui - > act_scannerSettings - > setEnabled ( false ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( false , false ) ;
2022-08-26 08:20:59 +00:00
m_dialogLog - > show ( ) ;
2023-02-06 08:18:47 +00:00
2023-04-12 10:44:20 +00:00
if ( m_devVersionNum < " G4393B1001 "
& & ( " 439 " = = getDevPid ( ) | | " 9220 " = = getDevPid ( ) | | " 8529 " = = getDevPid ( ) ) )
2022-08-22 07:25:37 +00:00
{
2023-02-06 08:18:47 +00:00
m_dialogLog - > addLog ( tr ( " Please wake up the device manually " ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " Please wake up the device manually " ) , true ) ;
2022-08-22 07:25:37 +00:00
}
2023-02-06 08:18:47 +00:00
else
{
QTime curTimer = QTime : : currentTime ( ) . addMSecs ( 10000 ) ;
while ( QTime : : currentTime ( ) < curTimer )
{
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
}
m_dialogLog - > addLog ( tr ( " already waked up device " ) , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " already waked up device " ) , false ) ;
}
2022-08-22 07:25:37 +00:00
ui - > menu_scan - > setEnabled ( true ) ;
ui - > act_acquire - > setEnabled ( true ) ;
ui - > act_scannerSettings - > setEnabled ( true ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( true , false ) ;
2022-08-22 07:25:37 +00:00
}
2022-05-03 10:25:52 +00:00
}
else
{
m_isScanning = true ;
m_thumb - > setAcceptDrops ( false ) ;
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
}
m_dialogLog - > show ( ) ;
}
}
void MainWindow : : on_act_insertFromScanner_triggered ( )
{
2023-02-22 07:18:06 +00:00
if ( ! isLimitAccessFolder ( 1 ) )
2022-08-13 09:47:29 +00:00
{
return ;
}
2022-10-28 01:03:22 +00:00
if ( ! dev_que_ . is_online ( ) | | m_isScanning )
2022-05-03 10:25:52 +00:00
{
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 ;
}
startSaveMessageBox ( this ) ;
2022-05-20 10:44:24 +00:00
m_dpi = getDpi ( ) ;
2022-10-28 01:03:22 +00:00
SANE_Status ret = sane_start ( dev_que_ . handle ( ) ) ;
2022-05-03 10:25:52 +00:00
if ( ret ! = SANE_STATUS_GOOD )
{
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " start failed " ) , true ) ;
2022-08-02 10:09:02 +00:00
m_dialogLog - > addLog ( tr ( " start failed " ) + " ( " + QString ( sane_err_desc ( ret ) ) + " ) " , true ) ;
2022-05-03 10:25:52 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( tr ( " start failed " ) ) . c_str ( ) ) ;
2022-08-22 07:25:37 +00:00
if ( ret = = SCANNER_ERR_DEVICE_SLEEPING )
{
ui - > menu_scan - > setEnabled ( false ) ;
ui - > act_acquire - > setEnabled ( false ) ;
ui - > act_scannerSettings - > setEnabled ( false ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( false , false ) ;
2022-08-26 08:20:59 +00:00
m_dialogLog - > show ( ) ;
2023-02-06 08:18:47 +00:00
2023-04-12 10:44:20 +00:00
if ( m_devVersionNum < " G4393B1001 "
& & ( " 439 " = = getDevPid ( ) | | " 9220 " = = getDevPid ( ) | | " 8529 " = = getDevPid ( ) ) )
2022-08-22 07:25:37 +00:00
{
2023-02-06 08:18:47 +00:00
m_dialogLog - > addLog ( tr ( " Please wake up the device manually " ) , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " Please wake up the device manually " ) , true ) ;
2022-08-22 07:25:37 +00:00
}
2023-02-06 08:18:47 +00:00
else
{
QTime curTimer = QTime : : currentTime ( ) . addMSecs ( 10000 ) ;
while ( QTime : : currentTime ( ) < curTimer )
{
QCoreApplication : : processEvents ( QEventLoop : : AllEvents , 100 ) ;
}
m_dialogLog - > addLog ( tr ( " already waked up device " ) , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " already waked up device " ) , false ) ;
}
2022-08-22 07:25:37 +00:00
ui - > menu_scan - > setEnabled ( true ) ;
ui - > act_acquire - > setEnabled ( true ) ;
ui - > act_scannerSettings - > setEnabled ( true ) ;
2022-08-26 07:41:56 +00:00
m_dialogLog - > updateStatus ( true , false ) ;
2022-08-22 07:25:37 +00:00
}
2022-05-03 10:25:52 +00:00
}
else
{
m_isScanning = true ;
m_thumb - > setAcceptDrops ( false ) ;
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
}
m_dialogLog - > show ( ) ;
}
}
void MainWindow : : on_act_imageEdit_triggered ( )
{
HGImage img = nullptr ;
m_view - > getImage ( & img ) ;
if ( nullptr = = img )
{
return ;
}
2023-01-14 02:55:34 +00:00
HGUInt xDpi = 0 ;
HGUInt yDpi = 0 ;
HGBase_GetImageDpi ( img , & xDpi , & yDpi ) ;
2022-05-03 10:25:52 +00:00
HGImageInfo info ;
HGBase_GetImageInfo ( img , & info ) ;
QImage : : Format fmt = QImage : : Format_Invalid ;
2022-05-27 01:23:06 +00:00
if ( info . type = = HGBASE_IMGTYPE_BINARY )
fmt = QImage : : Format_Mono ;
else if ( info . type = = HGBASE_IMGTYPE_GRAY )
2022-05-03 10:25:52 +00:00
fmt = QImage : : Format_Grayscale8 ;
else if ( info . type = = HGBASE_IMGTYPE_RGB )
fmt = QImage : : Format_RGB888 ;
2022-05-27 01:23:06 +00:00
else if ( info . type = = HGBASE_IMGTYPE_RGBA )
fmt = QImage : : Format_RGBA8888 ;
2022-05-03 10:25:52 +00:00
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 ;
2022-05-27 01:23:06 +00:00
if ( QImage : : Format_Mono = = image . format ( ) )
info . type = HGBASE_IMGTYPE_BINARY ;
else if ( QImage : : Format_Grayscale8 = = image . format ( ) )
2022-05-03 10:25:52 +00:00
info . type = HGBASE_IMGTYPE_GRAY ;
else if ( QImage : : Format_RGB888 = = image . format ( ) )
info . type = HGBASE_IMGTYPE_RGB ;
2022-05-27 01:23:06 +00:00
else if ( QImage : : Format_RGBA8888 = = image . format ( ) )
info . type = HGBASE_IMGTYPE_RGBA ;
2022-05-03 10:25:52 +00:00
info . widthStep = ( HGUInt ) image . bytesPerLine ( ) ;
info . origin = HGBASE_IMGORIGIN_TOP ;
HGImage img = nullptr ;
2022-05-26 03:23:27 +00:00
HGBase_CreateImageWithData ( ( HGByte * ) image . bits ( ) , & info , & img ) ;
2022-05-03 10:25:52 +00:00
if ( nullptr ! = img )
{
2023-01-14 02:55:34 +00:00
HGBase_SetImageDpi ( img , xDpi , yDpi ) ;
2022-05-03 10:25:52 +00:00
m_view - > addImage ( img ) ;
2023-04-08 10:43:46 +00:00
m_widget_sideBar - > setImage ( img ) ;
m_widget_sideBar - > enableUI ( false ) ;
m_bSideEditing = false ;
2022-05-03 10:25:52 +00:00
HGBase_DestroyImage ( img ) ;
2022-05-26 05:34:35 +00:00
m_modify = true ;
updateStatusBarPixelInfo ( ) ;
updateActionStatus ( ) ;
2022-10-26 10:24:25 +00:00
if ( auto_save_changes_ )
{
on_act_save_triggered ( ) ;
}
2022-05-03 10:25:52 +00:00
}
}
}
}
2022-10-28 01:03:22 +00:00
bool MainWindow : : open_scanner ( const QString & name , const QString & scheme )
2022-05-03 10:25:52 +00:00
{
2022-10-28 01:03:22 +00:00
bool ret = dev_que_ . open_scanner ( name . toStdString ( ) . c_str ( ) , scheme . toStdString ( ) . c_str ( ) ) = = SANE_STATUS_GOOD ;
2022-05-03 10:25:52 +00:00
QString info ( tr ( " open scanner " ) + " " + name + " " ) ;
QString title ( tr ( " app name " ) ) ;
if ( ret )
{
2022-07-27 10:41:21 +00:00
std : : string serialNum ;
unsigned int serialNumLen = 0 ;
2022-10-28 01:03:22 +00:00
if ( SANE_STATUS_NO_MEM = = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_SERIAL , nullptr , & serialNumLen )
2022-08-19 06:25:04 +00:00
& & serialNumLen )
{
serialNum . resize ( serialNumLen ) ;
2022-10-28 01:03:22 +00:00
sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_SERIAL , & serialNum [ 0 ] , & serialNumLen ) ;
2022-08-19 06:25:04 +00:00
}
2022-11-04 06:22:38 +00:00
m_devSerialNum = QString : : fromStdString ( serialNum . c_str ( ) ) ;
2022-07-27 10:41:21 +00:00
std : : string versionNum ;
unsigned int versionNumLen = 0 ;
2022-10-28 01:03:22 +00:00
if ( SANE_STATUS_NO_MEM = = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_HARDWARE_VERSION , nullptr , & versionNumLen )
2022-08-19 06:25:04 +00:00
& & versionNumLen )
{
versionNum . resize ( versionNumLen ) ;
2022-10-28 01:03:22 +00:00
sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_HARDWARE_VERSION , & versionNum [ 0 ] , & versionNumLen ) ;
2022-08-19 06:25:04 +00:00
}
2022-11-04 06:22:38 +00:00
m_devVersionNum = QString : : fromStdString ( versionNum . c_str ( ) ) ;
2022-07-27 10:41:21 +00:00
2022-07-28 09:22:27 +00:00
m_versionDll - > PostDeviceOpenInfo ( name . toStdString ( ) . c_str ( ) , m_devSerialNum . toStdString ( ) . c_str ( ) , " " , m_devVersionNum . toStdString ( ) . c_str ( ) ) ;
m_currDeviceName = name ;
2022-07-27 10:41:21 +00:00
2022-05-03 10:25:52 +00:00
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 ( ) ) ;
2022-08-22 04:47:25 +00:00
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " be ready " ) , false ) ;
2022-05-03 10:25:52 +00:00
}
else
{
info + = tr ( " failed " ) ;
m_wndStatusBar - > setDeviceStatusInfo ( info , true ) ;
m_dialogLog - > addLog ( info , true ) ;
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " %s " , getStdString ( info ) . c_str ( ) ) ;
}
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
2022-05-18 08:40:52 +00:00
// setWindowTitle(title);
2022-05-03 10:25:52 +00:00
return ret ;
}
2022-11-24 16:39:37 +00:00
bool MainWindow : : judgeDiskSpace ( QString currentPath , bool showDlg )
2022-05-27 10:45:51 +00:00
{
QStorageInfo storage = QStorageInfo : : root ( ) ;
storage . refresh ( ) ;
storage . device ( ) ;
storage . setPath ( currentPath ) ;
qint64 available_size = 0 ;
available_size = storage . bytesAvailable ( ) / 1024 / 1024 ;
2022-11-24 16:44:13 +00:00
if ( available_size < 64 )
2022-05-27 10:45:51 +00:00
{
2022-11-24 16:39:37 +00:00
if ( showDlg )
{
QString info = tr ( " the disk space in the current path is unsufficient, please select a new path or clear the disk space in time. " ) ;
m_wndStatusBar - > setDeviceStatusInfo ( info , true ) ;
m_dialogLog - > addLog ( info , true ) ;
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " disk space is unsufficient! " ) ;
QMessageBox : : warning ( this , tr ( " warning " ) , info ) ;
}
2022-05-27 10:45:51 +00:00
return false ;
}
return true ;
}
2022-07-22 06:25:24 +00:00
void MainWindow : : upgradeApp ( QString pkgPath )
{
2022-09-26 03:03:07 +00:00
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 ) ;
2022-07-22 06:25:24 +00:00
# if defined(HG_CMP_MSC)
2023-02-22 07:18:06 +00:00
// #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");
// #elif defined(OEM_ZHONGJING)
// QFile::remove(tmpPath + "ZJUpgradeApp.exe");
// QFile::copy(curPath + "ZJUpgradeApp.exe", tmpPath + "ZJUpgradeApp.exe");
// QFile::remove(tmpPath + "ZJBase.dll");
// QFile::copy(curPath + "ZJBase.dll", tmpPath + "ZJBase.dll");
// QFile::remove(tmpPath + "ZJVersion.dll");
// QFile::copy(curPath + "ZJVersion.dll", tmpPath + "ZJVersion.dll");
2023-03-10 05:39:50 +00:00
// #elif defined(OEM_ZIGUANG)
// QFile::remove(tmpPath + "ZGUpgradeApp.exe");
// QFile::copy(curPath + "ZGUpgradeApp.exe", tmpPath + "ZGUpgradeApp.exe");
// QFile::remove(tmpPath + "ZGBase.dll");
// QFile::copy(curPath + "ZGBase.dll", tmpPath + "ZGBase.dll");
// QFile::remove(tmpPath + "ZGVersion.dll");
// QFile::copy(curPath + "ZGVersion.dll", tmpPath + "ZGVersion.dll");
2023-02-22 07:18:06 +00:00
// #else
2022-09-26 03:03:07 +00:00
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 " ) ;
2023-02-22 07:18:06 +00:00
// #endif
2022-07-22 06:25:24 +00:00
2022-09-26 03:03:07 +00:00
QFile : : remove ( tmpPath + " msvcp140.dll " ) ;
2023-01-11 10:56:48 +00:00
QFile : : copy ( curPath + " msvcp140.dll " , tmpPath + " msvcp140.dll " ) ;
2022-09-26 03:03:07 +00:00
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 " ) ;
2023-01-11 10:56:48 +00:00
QFile : : remove ( tmpPath + " concrt140.dll " ) ;
QFile : : copy ( curPath + " concrt140.dll " , tmpPath + " concrt140.dll " ) ;
QFile : : remove ( tmpPath + " vcruntime140_1.dll " ) ;
QFile : : copy ( curPath + " vcruntime140_1.dll " , tmpPath + " vcruntime140_1.dll " ) ;
2022-07-22 06:25:24 +00:00
QDir dir ;
2022-09-26 03:03:07 +00:00
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 " ) ;
2022-07-22 06:25:24 +00:00
# else
2023-02-22 07:18:06 +00:00
// #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");
// #elif defined(OEM_ZHONGJING)
// QFile::remove(tmpPath + "ZjUpgradeApp");
// QFile::copy(curPath + "ZjUpgradeApp", tmpPath + "ZjUpgradeApp");
// //QFile::remove(tmpPath + "libZjBase.so");
// //QFile::copy(curPath + "libZjBase.so", tmpPath + "libZjBase.so");
// //QFile::remove(tmpPath + "libZjVersion.so");
// //QFile::copy(curPath + "libZjVersion.so", tmpPath + "libZjVersion.so");
2023-03-10 05:39:50 +00:00
// #elif defined(OEM_ZIGUANG)
// QFile::remove(tmpPath + "ZgUpgradeApp");
// QFile::copy(curPath + "ZgUpgradeApp", tmpPath + "ZgUpgradeApp");
// //QFile::remove(tmpPath + "libZgBase.so");
// //QFile::copy(curPath + "libZgBase.so", tmpPath + "libZgBase.so");
// //QFile::remove(tmpPath + "libZgVersion.so");
// //QFile::copy(curPath + "libZgVersion.so", tmpPath + "libZgVersion.so");
2023-02-22 07:18:06 +00:00
// #else
2022-09-26 03:03:07 +00:00
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");
2023-02-22 07:18:06 +00:00
// #endif
2022-07-22 06:25:24 +00:00
# endif
QProcess proc ;
bool isSuccessdStart = false ;
QStringList argList ;
argList . push_back ( QString ( " -appName=%1 " ) . arg ( HGVERSION_APPNAME_SCANNER ) ) ;
2023-04-13 09:31:39 +00:00
argList . push_back ( QString ( " -oemName=%1 " ) . arg ( m_oemName ) ) ;
2022-07-22 06:25:24 +00:00
argList . push_back ( QString ( " -pkgpath=%1 " ) . arg ( pkgPath . toStdString ( ) . c_str ( ) ) ) ;
argList . push_back ( QString ( " -type=%1 " ) . arg ( " upgrade " ) ) ;
2023-01-28 09:45:13 +00:00
argList . push_back ( QString ( " -language=%1 " ) . arg ( m_currLang . toStdString ( ) . c_str ( ) ) ) ;
2022-07-22 06:25:24 +00:00
# if defined(HG_CMP_MSC)
2023-02-22 07:18:06 +00:00
// #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);
// #elif defined(OEM_ZHONGJING)
// isSuccessdStart = proc.startDetached(tmpPath + "ZJUpgradeApp.exe", argList);
2023-03-10 05:39:50 +00:00
// #elif defined(OEM_ZIGUANG)
// isSuccessdStart = proc.startDetached(tmpPath + "ZGUpgradeApp.exe", argList);
2023-02-22 07:18:06 +00:00
// #else
2022-09-26 03:03:07 +00:00
isSuccessdStart = proc . startDetached ( tmpPath + " HGUpgradeApp.exe " , argList ) ;
2023-02-22 07:18:06 +00:00
// #endif
2022-07-22 06:25:24 +00:00
# else
2023-02-22 07:18:06 +00:00
// #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);
// #elif defined(OEM_ZHONGJING)
// isSuccessdStart = proc.startDetached(tmpPath + "ZjUpgradeApp", argList);
2023-03-10 05:39:50 +00:00
// #elif defined(OEM_ZIGUANG)
// isSuccessdStart = proc.startDetached(tmpPath + "ZgUpgradeApp", argList);
2023-02-22 07:18:06 +00:00
// #else
2022-09-26 03:03:07 +00:00
isSuccessdStart = proc . startDetached ( tmpPath + " HGUpgradeApp " , argList ) ;
2023-02-22 07:18:06 +00:00
// #endif
2022-07-22 06:25:24 +00:00
# endif
if ( isSuccessdStart )
{
m_closeTip = false ;
close ( ) ;
}
else
{
QMessageBox msg ( QMessageBox : : Critical , tr ( " error " ) ,
tr ( " start failed! " ) ,
QMessageBox : : Ok , this ) ;
msg . exec ( ) ;
}
}
2023-02-22 07:18:06 +00:00
bool MainWindow : : isLimitAccessFolder ( int type )
2022-08-13 09:47:29 +00:00
{
2023-02-22 07:18:06 +00:00
QString cachePath = Dialog_ClrCache : : getCachePath ( ) ;
QString aquireIntoPath = m_aquireIntoSaveParam . m_savePath ;
QString filePath ;
2022-08-13 09:47:29 +00:00
HGChar uuid [ 512 ] ;
HGBase_GetUuid ( uuid , 512 ) ;
2023-02-22 07:18:06 +00:00
if ( 1 = = type )
2022-08-13 09:47:29 +00:00
{
2023-02-22 07:18:06 +00:00
filePath = cachePath + uuid ;
}
else if ( 2 = = type )
{
filePath = aquireIntoPath + uuid ;
}
HGResult ret = HGBase_CreateDir ( getStdString ( filePath ) . c_str ( ) ) ;
if ( ret ! = HGBASE_ERR_OK )
{
QString info ;
if ( 1 = = type )
2022-10-25 11:17:33 +00:00
{
2023-02-22 07:18:06 +00:00
info = tr ( " cache path folder limit:%1 " ) . arg ( cachePath ) ;
}
else if ( 2 = = type )
{
info = tr ( " aquireinto folder limit:%1 " ) . arg ( aquireIntoPath ) ;
2022-10-25 11:17:33 +00:00
}
2023-02-22 07:18:06 +00:00
QMessageBox : : critical ( this , tr ( " error " ) , info ) ;
m_dialogLog - > addLog ( info , true ) ;
m_wndStatusBar - > setDeviceStatusInfo ( info , true ) ;
2022-08-13 09:47:29 +00:00
return false ;
}
else
{
2023-02-22 07:18:06 +00:00
HGBase_DeleteDir ( getStdString ( filePath ) . c_str ( ) ) ;
2022-08-13 09:47:29 +00:00
}
return true ;
}
2022-12-03 08:58:16 +00:00
QString MainWindow : : GetDevType ( const QString & fwVersion , bool & canLock )
2022-11-11 08:39:46 +00:00
{
2022-12-03 08:58:16 +00:00
canLock = false ;
2022-11-11 08:39:46 +00:00
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 " )
{
2022-12-03 08:58:16 +00:00
if ( date > = " A1220 " & & date < = " A1230 " )
{
devType = dev + ver + " / " + " A1220-A1230 " ;
if ( date > = " A1224 " )
{
canLock = true ;
}
}
else if ( date > = " B0326 " & & date < = " B0334 " )
{
devType = dev + ver + " / " + " B0326-B0334 " ;
if ( date > = " B0333 " )
{
canLock = true ;
}
}
2022-11-11 08:39:46 +00:00
else if ( date > = " B0429 " )
2022-12-03 08:58:16 +00:00
{
2022-11-11 08:39:46 +00:00
devType = dev + ver + " / " + " B0429- " ;
2022-12-05 06:38:25 +00:00
if ( date > = " B1031 " | | date = = " B0500 " )
2022-12-03 08:58:16 +00:00
{
canLock = true ;
}
}
2022-11-11 08:39:46 +00:00
}
else if ( dev = = " G4 " & & ver = = " 393 " )
{
devType = dev + ver + " / " ;
2022-12-03 08:58:16 +00:00
if ( date > = " B1108 " )
{
canLock = true ;
}
2022-11-11 08:39:46 +00:00
}
}
}
return devType ;
}
2022-11-24 09:02:26 +00:00
QString MainWindow : : getLogInfo ( HGResult ret )
{
QString str ;
if ( HGBASE_ERR_ACCESSDENIED = = ret )
{
str = tr ( " Insufficient access rights " ) ;
}
else if ( HGIMGPROC_ERR_FAIL = = ret )
{
str = tr ( " Image processing failed " ) ;
}
2022-11-24 10:14:56 +00:00
else if ( HGIMGPROC_ERR_OCRINIT = = ret )
{
str = tr ( " Ocr init failed " ) ;
}
else if ( HGIMGPROC_ERR_OCR = = ret )
{
str = tr ( " Ocr failed " ) ;
}
2022-11-25 10:35:22 +00:00
else if ( HGBASE_ERR_FILENOTEXIST = = ret )
{
str = tr ( " File does not exist " ) ;
}
else if ( HGBASE_ERR_LOADLIBRARY = = ret )
{
str = tr ( " Failed to load dynamic library " ) ;
}
else if ( HGBASE_ERR_FILEERROR = = ret )
{
str = tr ( " File data error " ) ;
}
2022-11-26 09:40:28 +00:00
else if ( HGIMGFMT_ERR_FAIL = = ret )
{
str = tr ( " Image format processing error " ) ;
}
else if ( HGBASE_ERR_OUTOFMEMORY = = ret )
{
str = tr ( " Out of memory " ) ;
}
2022-11-24 10:14:56 +00:00
else
{
str = tr ( " Failed " ) ;
}
2022-11-24 09:02:26 +00:00
return str ;
}
2022-11-29 07:42:18 +00:00
void MainWindow : : deleteOverdueLogFile ( const QString & logFilePath )
2022-11-29 06:00:50 +00:00
{
2022-11-29 07:42:18 +00:00
QDir dir ( logFilePath ) ;
2022-11-29 06:00:50 +00:00
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 ( suffix = = " log " )
{
QDateTime nowTime = QDateTime : : currentDateTime ( ) ;
QDateTime createTime = info . created ( ) ;
int days = createTime . daysTo ( nowTime ) ;
if ( days > 14 )
{
HGBase_DeleteFile ( info . absoluteFilePath ( ) . toStdString ( ) . c_str ( ) ) ;
}
}
2022-11-29 07:42:18 +00:00
}
}
void MainWindow : : deleteUpgradePkg ( const QString & cfgFilePath )
{
QDir dir ( cfgFilePath ) ;
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 ( suffix = = " exe " )
2022-11-29 06:00:50 +00:00
{
HGBase_DeleteFile ( info . absoluteFilePath ( ) . toStdString ( ) . c_str ( ) ) ;
}
}
}
2022-11-23 10:39:06 +00:00
2023-02-06 08:18:47 +00:00
QString MainWindow : : getDevPid ( )
{
VIDPID vidpid ;
int vidpid_val ;
unsigned int len = sizeof ( int ) ;
sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_VIDPID , & vidpid_val , & len ) ;
vidpid . Value = vidpid_val ;
int vid = vidpid . VID ;
int pid = vidpid . PID ;
char buf [ 10 ] ;
char buf2 [ 10 ] ;
sprintf ( buf , " %x " , vid ) ;
sprintf ( buf2 , " %x " , pid ) ;
return QString : : fromStdString ( buf2 ) ;
}
2023-03-31 07:22:07 +00:00
void MainWindow : : initAcquireIntoComboBox ( )
{
m_cbtn_acquireIntoCfg = new QComboBox ;
m_cbtn_acquireIntoCfg - > setFixedWidth ( 150 ) ;
ui - > toolBar - > addWidget ( m_cbtn_acquireIntoCfg ) ;
m_cbtn_acquireIntoCfg - > addItem ( tr ( " default scheme " ) ) ;
QString allCfgName = getCfgValue ( " aquire " , " cfgNameList " , QString ( " " ) ) ;
QStringList allCfgNameList = allCfgName . split ( " , " ) ;
if ( ! allCfgNameList . contains ( QString ( " " ) ) )
{
m_cbtn_acquireIntoCfg - > addItems ( allCfgNameList ) ;
m_cbtn_acquireIntoCfg - > setCurrentText ( getCfgValue ( " aquire " , " currentKeyName " , QString ( " aquire " ) ) ) ;
}
else
{
allCfgNameList . removeOne ( QString ( " " ) ) ;
m_cbtn_acquireIntoCfg - > setCurrentIndex ( 0 ) ;
}
connect ( m_cbtn_acquireIntoCfg , SIGNAL ( currentTextChanged ( QString ) ) , this , SLOT ( on_m_acquireIntoCfg_changed ( QString ) ) ) ;
}
2023-04-08 08:33:36 +00:00
void MainWindow : : updateSideBar ( )
{
int mainWndWidth = this - > rect ( ) . width ( ) ;
int mainWndHeight = this - > rect ( ) . height ( ) ;
2023-04-08 10:43:46 +00:00
int sideBarHeight = m_widget_sideBar - > height ( ) ;
2023-04-08 08:33:36 +00:00
m_widget_sideBar - > move ( mainWndWidth , mainWndHeight / 2 - sideBarHeight / 2 ) ;
m_pbtn_push - > move ( mainWndWidth - m_pbtn_push - > width ( ) , mainWndHeight / 2 - m_pbtn_push - > height ( ) / 2 ) ;
m_propertyAnimation = new QPropertyAnimation ( m_widget_sideBar , " geometry " ) ;
m_propertyAnimation - > setEasingCurve ( QEasingCurve : : InOutSine ) ;
m_propertyAnimation - > setDuration ( 600 ) ;
m_propertyAnimation2 = new QPropertyAnimation ( m_pbtn_push , " geometry " ) ;
m_propertyAnimation2 - > setEasingCurve ( QEasingCurve : : InOutSine ) ;
m_propertyAnimation2 - > setDuration ( 600 ) ;
}
2022-05-03 10:25:52 +00:00
void MainWindow : : on_scanOptions_changed ( const QString & device , const QString & option , bool checked_now )
{
QString title ( tr ( " app name " ) ) ;
if ( checked_now )
{
2022-10-28 01:03:22 +00:00
std : : string curdev ( dev_que_ . opened_scanner_name ( ) ) ;
int ret = 0 ;
if ( curdev ! = device . toStdString ( ) )
2022-10-18 10:51:24 +00:00
{
2022-10-28 08:53:43 +00:00
//ret = dev_que_.open_scanner(device.toStdString().c_str(), option.toStdString().c_str());
open_scanner ( device , option ) ;
return ;
2022-05-18 09:36:13 +00:00
}
2022-10-28 01:03:22 +00:00
else {
ret = dev_que_ . apply_scheme ( option . toStdString ( ) . c_str ( ) ) ;
2022-05-03 10:25:52 +00:00
}
QString info ( tr ( " apply setting " ) + " ' " + option + " ' " ) ;
2022-10-28 01:03:22 +00:00
if ( ret = = 0 )
2022-05-07 10:43:43 +00:00
{
2022-05-03 10:25:52 +00:00
info + = tr ( " success " ) ;
2022-05-07 10:43:43 +00:00
}
2022-05-03 10:25:52 +00:00
else
2022-05-07 10:43:43 +00:00
{
ui - > menu_device - > setOptionChecked ( device , option , false ) ;
2022-05-03 10:25:52 +00:00
info + = tr ( " failed " ) ;
2022-05-07 10:43:43 +00:00
}
2022-05-03 10:25:52 +00:00
2022-10-28 01:03:22 +00:00
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 ( ) ) ;
2022-05-03 10:25:52 +00:00
title = device + " ( " + option + " ) " ;
}
else
{
2022-05-26 10:49:22 +00:00
QMessageBox msg ( QMessageBox : : Question , title ,
2022-05-27 10:45:51 +00:00
tr ( " Are you sure to close " ) + device + tr ( " ? " ) ,
2022-05-26 10:49:22 +00:00
QMessageBox : : Yes | QMessageBox : : No , this ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) = = msg . button ( QMessageBox : : Yes ) )
2022-05-20 05:40:08 +00:00
{
2022-10-28 01:03:22 +00:00
dev_que_ . close_scanner ( ) ;
2022-07-28 09:22:27 +00:00
m_versionDll - > PostDeviceCloseInfo ( device . toStdString ( ) . c_str ( ) , m_devSerialNum . toStdString ( ) . c_str ( ) , " " , m_devVersionNum . toStdString ( ) . c_str ( ) ) ;
2022-05-20 05:40:08 +00:00
2022-05-27 10:45:51 +00:00
m_dialogLog - > addLog ( tr ( " close " ) + device , false ) ;
m_wndStatusBar - > setDeviceStatusInfo ( tr ( " close " ) + device , false ) ;
2022-05-20 05:40:08 +00:00
}
else {
ui - > menu_device - > setOptionChecked ( device , option , true ) ;
return ;
}
2022-05-03 10:25:52 +00:00
}
2022-10-28 01:03:22 +00:00
m_dialogLog - > updateStatus ( dev_que_ . is_online ( ) & & 0 ! = m_scanType , m_isScanning ) ;
2022-05-03 10:25:52 +00:00
updateActionStatus ( ) ;
2022-05-18 08:40:52 +00:00
// setWindowTitle(title);
2022-05-03 10:25:52 +00:00
}
2022-05-16 06:38:22 +00:00
void MainWindow : : on_act_sortPages_triggered ( )
{
2022-10-28 01:03:22 +00:00
if ( dev_que_ . is_online ( ) & & m_isScanning )
2022-05-16 06:38:22 +00:00
{
return ;
}
m_thumb - > bookSort ( ) ;
}
2022-07-07 08:16:41 +00:00
void MainWindow : : on_actionact_update_triggered ( )
{
2022-07-14 07:44:53 +00:00
HGVersionInfo * versionInfo = NULL ;
HGUInt versionCount = 0 ;
2023-01-13 05:56:24 +00:00
HGResult ret = m_versionDll - > GetVersionList ( HGVERSION_APPNAME_SCANNER , m_oemName , & versionInfo , & versionCount ) ;
2022-10-28 02:45:32 +00:00
if ( ret ! = HGBASE_ERR_OK )
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " GetVersionList:%u " , ret ) ;
}
2022-07-14 07:44:53 +00:00
if ( versionCount > 0 )
2022-07-13 11:01:42 +00:00
{
2022-11-26 03:29:31 +00:00
Dialog_upgrade dlg ( m_versionDll , versionInfo , this ) ;
2022-07-21 07:41:16 +00:00
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 ( ) ) ;
2022-07-22 01:46:34 +00:00
HGChar suffix [ 64 ] ;
HGBase_GetFileSuffix ( url . toStdString ( ) . c_str ( ) , suffix , 64 ) ;
2022-07-21 07:41:16 +00:00
HGChar savePath [ 512 ] ;
2022-11-29 07:42:18 +00:00
HGBase_GetConfigPath ( savePath , 512 ) ;
2022-11-24 09:02:26 +00:00
HGBase_CreateDir ( savePath ) ;
2022-11-23 10:39:06 +00:00
2022-07-22 01:46:34 +00:00
HGChar fileName [ 128 ] ;
sprintf ( fileName , " %s.%s " , versionNum . toStdString ( ) . c_str ( ) , suffix ) ;
strcat ( savePath , fileName ) ;
2022-07-21 07:41:16 +00:00
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 )
{
2022-07-22 06:25:24 +00:00
upgradeApp ( savePath ) ;
2022-07-21 07:41:16 +00:00
}
}
}
else
{
2022-07-22 06:25:24 +00:00
upgradeApp ( savePath ) ;
2022-07-21 07:41:16 +00:00
}
}
2022-07-07 08:16:41 +00:00
}
else
{
2022-07-28 02:44:16 +00:00
QMessageBox : : information ( this , tr ( " tip " ) , tr ( " Other versions not available " ) ) ;
2022-07-07 08:16:41 +00:00
}
2022-07-21 02:56:47 +00:00
m_versionDll - > ReleaseVersionList ( versionInfo , versionCount ) ;
2022-07-07 08:16:41 +00:00
}
2022-07-20 09:30:27 +00:00
void MainWindow : : on_act_feedback_triggered ( )
{
Dialog_Feedback dlg ( m_versionDll , this ) ;
dlg . exec ( ) ;
}
2022-07-26 05:44:44 +00:00
void MainWindow : : on_act_driver_log_triggered ( )
{
char log_file_path [ 260 ] = { 0 } ;
unsigned int type = SANE_LogFileType : : LOG_FILE_DRIVER ;
2022-10-28 01:03:22 +00:00
SANE_Status statu = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_LOG_FILE , log_file_path , & type ) ;
2022-07-26 05:44:44 +00:00
if ( statu = = SANE_STATUS_GOOD )
{
if ( log_file_path [ 0 ] )
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( log_file_path ) ) ;
}
else {
2022-11-06 08:00:48 +00:00
if ( statu = = SANE_STATUS_UNSUPPORTED ) // 鐠佹儳顦稉宥嗘暜閹镐浇顕氶幙宥勭稊
2022-07-28 02:44:16 +00:00
QMessageBox : : information ( this , windowTitle ( ) , tr ( " The device does not support this operation " ) ) ;
2022-07-26 05:44:44 +00:00
else
2022-11-06 08:00:48 +00:00
QMessageBox : : information ( this , windowTitle ( ) , tr ( " IO error " ) ) ; // IO闁挎瑨顕?
2022-07-26 05:44:44 +00:00
}
}
void MainWindow : : on_act_device_log_triggered ( )
{
char log_file_path [ 260 ] = { 0 } ;
unsigned int type = SANE_LogFileType : : LOG_FILE_DEVICE ;
2022-10-28 01:03:22 +00:00
SANE_Status statu = sane_io_control ( dev_que_ . handle ( ) , IO_CTRL_CODE_GET_LOG_FILE , log_file_path , & type ) ;
2022-07-26 05:44:44 +00:00
if ( statu = = SANE_STATUS_GOOD )
{
if ( log_file_path [ 0 ] )
QDesktopServices : : openUrl ( QUrl : : fromLocalFile ( log_file_path ) ) ;
}
else {
2022-07-28 09:22:27 +00:00
if ( statu = = SANE_STATUS_UNSUPPORTED )
2022-07-28 02:44:16 +00:00
QMessageBox : : information ( this , windowTitle ( ) , tr ( " The device does not support this operation " ) ) ;
2022-07-26 05:44:44 +00:00
else
2022-07-28 09:22:27 +00:00
QMessageBox : : information ( this , windowTitle ( ) , tr ( " IO error " ) ) ;
2022-07-26 05:44:44 +00:00
}
}
2023-01-28 02:57:18 +00:00
void MainWindow : : on_act_simpCN_triggered ( )
{
2023-01-29 03:18:42 +00:00
m_act_simpCN - > setChecked ( true ) ;
m_act_English - > setChecked ( false ) ;
2023-01-28 02:57:18 +00:00
2023-01-28 09:45:13 +00:00
if ( m_currLang = = " chinese " )
2023-01-28 07:32:08 +00:00
{
return ;
2023-01-28 02:57:18 +00:00
}
2023-01-29 03:18:42 +00:00
m_currLang = " chinese " ;
saveCfgValue ( " global " , " language " , m_currLang ) ;
2023-02-01 08:02:58 +00:00
QMessageBox msg ( QMessageBox : : Information , tr ( " tips " ) ,
2023-01-29 03:18:42 +00:00
tr ( " The language switch is successful and takes effect the next time the software is started! " ) ,
QMessageBox : : Ok , this ) ;
msg . exec ( ) ;
2023-01-28 02:57:18 +00:00
}
void MainWindow : : on_act_English_triggered ( )
{
2023-01-29 03:18:42 +00:00
m_act_simpCN - > setChecked ( false ) ;
m_act_English - > setChecked ( true ) ;
2023-01-28 02:57:18 +00:00
2023-01-28 09:45:13 +00:00
if ( m_currLang = = " english " )
2023-01-28 07:32:08 +00:00
{
return ;
2023-01-28 02:57:18 +00:00
}
2023-01-28 07:32:08 +00:00
2023-01-29 03:18:42 +00:00
m_currLang = " english " ;
saveCfgValue ( " global " , " language " , m_currLang ) ;
2023-02-01 08:02:58 +00:00
QMessageBox msg ( QMessageBox : : Information , tr ( " tips " ) ,
2023-01-29 03:18:42 +00:00
tr ( " The language switch is successful and takes effect the next time the software is started! " ) ,
QMessageBox : : Ok , this ) ;
msg . exec ( ) ;
2023-01-28 02:57:18 +00:00
}
2023-02-03 02:21:33 +00:00
void MainWindow : : on_act_deleteFile_triggered ( )
{
if ( m_isScanning )
{
return ;
}
std : : vector < int > 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 ) ;
}
}
QMessageBox msg ( QMessageBox : : Question , tr ( " tips " ) , tr ( " Are you sure to delete selected file? " ) ,
QMessageBox : : Yes | QMessageBox : : No , this ) ;
msg . exec ( ) ;
if ( msg . clickedButton ( ) = = msg . button ( QMessageBox : : Yes ) )
{
m_thumb - > removeItems ( selectIndexs , HGImgThumb : : ThumbRemoveFlag_Delete ) ;
}
}