sane调用,设备离线时点击设置增加提示

This commit is contained in:
yangjiaxuan 2023-07-14 17:57:17 +08:00
parent 014268db63
commit c3a71fe419
8 changed files with 67 additions and 16 deletions

View File

@ -2901,20 +2901,39 @@ void MainWindow::on_act_about_triggered()
void MainWindow::on_act_scannerSettings_triggered()
{
if (nullptr != m_devUser)
if (nullptr == m_devUser)
{
return;
}
HGResult ret = m_devUser->ShowSettingDlg();
bool deviceIsOnline = true;
bool openSucceed = true;
#if defined(HG_CMP_MSC)
if (HGTWAIN_ERR_DEVICEOFFLINE == ret)
deviceIsOnline = false;
else if (HGTWAIN_ERR_FAIL == ret)
openSucceed = false;
#else
if (HGSANE_ERR_DEVICEOFFLINE == ret)
deviceIsOnline = false;
else if (HGSANE_ERR_FAIL == ret)
openSucceed = false;
if (!deviceIsOnline)
{
QMessageBox::information(this, tr("Prompt"), tr("Device is offline"));
deleteDevUser();
}
else if (ret == HGTWAIN_ERR_FAIL)
else if (!openSucceed)
{
QMessageBox::information(this, tr("Prompt"), tr("Open failed"));
deleteDevUser();
}
}
#endif
}
void MainWindow::on_act_acquire_triggered()

View File

@ -4,4 +4,7 @@
/* 一般错误 */
#define HGSANE_ERR_FAIL 0x00004001L
/* 设备离线 */
#define HGSANE_ERR_DEVICEOFFLINE 0x00004002L
#endif /* __HGSANEERR_H__ */

View File

@ -776,10 +776,19 @@ HGResult HGSaneDeviceImpl::ClearDeviceLog()
HGResult HGSaneDeviceImpl::ShowSettingDlg(HGWindow parent)
{
if (-2 == show_setting_ui(&m_sourceImpl->m_saneApi, m_devHandle, m_devName.c_str(), parent))
int ret = show_setting_ui(&m_sourceImpl->m_saneApi, m_devHandle, m_devName.c_str(), parent);
if (-1 == ret)
{
return HGSANE_ERR_FAIL;
}
else if (-2 == ret)
{
return HGBASE_ERR_NOTSUPPORT;
}
else if (-3 == ret)
{
return HGSANE_ERR_DEVICEOFFLINE;
}
return HGBASE_ERR_OK;
}

View File

@ -145,6 +145,15 @@ int show_setting_ui(const SANEAPI* saneApi, SANE_Handle handle, const char *devN
QCoreApplication::installTranslator(&translator2);
hg_settingdialog dlg(saneApi, handle, devName, qParent);
if (!dlg.IsValid())
{
QCoreApplication::removeTranslator(&translator);
if (20127 != cp)
QCoreApplication::removeTranslator(&translator2);
return -3;
}
dlg.exec();
QCoreApplication::removeTranslator(&translator);

Binary file not shown.

View File

@ -2946,7 +2946,7 @@ No: add new configuration</oldsource>
<location filename="hg_settingdialog.cpp" line="378"/>
<location filename="hg_settingdialog.cpp" line="2358"/>
<source>The current parameter settings are inconsistent with the configuration scheme &apos;%1&apos;. To use the configuration scheme &apos;%1&apos; parameters, please click the restore button</source>
<translation> %1 使 %1 </translation>
<translation> %1 使 %1 </translation>
</message>
<message>
<location filename="hg_settingdialog.cpp" line="383"/>

View File

@ -25,6 +25,7 @@ hg_settingdialog::hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, c
, m_isRefreshUi(false)
, changed_count_(0)
, cur_cfg_(nullptr)
, m_deviceIsValid(true)
{
m_dpiId = -1;
m_dpiValue = 200;
@ -62,7 +63,9 @@ hg_settingdialog::hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, c
dev_que::update_old_cfg(old.toStdString().c_str());
int pid = 0;
m_saneAPI.sane_control_option_api(m_devHandle, (SANE_Int)0x8853, SANE_ACTION_GET_VALUE, &pid, NULL);
SANE_Status ret = m_saneAPI.sane_control_option_api(m_devHandle, (SANE_Int)0x8853, SANE_ACTION_GET_VALUE, &pid, NULL);
if (SANE_STATUS_GOOD != ret)
m_deviceIsValid = false;
char buf[10] = { 0 };
sprintf(buf, "%x", pid);
@ -166,6 +169,11 @@ void hg_settingdialog::apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_con
}
}
bool hg_settingdialog::IsValid()
{
return m_deviceIsValid;
}
void hg_settingdialog::initUi()
{
update_opt_value_from_driver();

View File

@ -54,6 +54,8 @@ public:
static void apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_config_schm* schm);
bool IsValid();
public:
void initUi();
void update_opt_value_from_driver();
@ -157,6 +159,7 @@ private:
QComboBox *comb_;
bool m_isRefreshUi;
bool m_deviceIsValid;
};
#endif // HG_SETTING_DIALOG_H