2023-05-20 08:08:55 +00:00
|
|
|
#include "device_user.h"
|
2023-05-04 06:55:26 +00:00
|
|
|
#include <QMessageBox>
|
2023-05-20 08:08:55 +00:00
|
|
|
#include <QFileDialog>
|
2023-05-16 10:31:32 +00:00
|
|
|
#include "HGUIGlobal.h"
|
|
|
|
#include <thread>
|
2023-05-04 06:55:26 +00:00
|
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
DeviceUserMgr::DeviceUserMgr(QString password, QWidget *wnd)
|
2023-05-04 06:55:26 +00:00
|
|
|
{
|
2023-05-16 10:31:32 +00:00
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
m_wnd = wnd;
|
|
|
|
m_twainDSM = nullptr;
|
|
|
|
HGTwain_CreateDSM((HWND)m_wnd->winId(), &m_twainDSM);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceUserMgr::~DeviceUserMgr()
|
|
|
|
{
|
|
|
|
HGTwain_DestroyDSM(m_twainDSM);
|
|
|
|
m_twainDSM = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
|
|
|
|
{
|
|
|
|
HGTwainDS ds = nullptr;
|
|
|
|
HGTwain_OpenSelectedDSEx(m_twainDSM, &ds);
|
|
|
|
if (nullptr == ds)
|
|
|
|
return nullptr;
|
2023-05-16 10:31:32 +00:00
|
|
|
return new DeviceUser(m_wnd, ds, m_password);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds, QString password)
|
2023-05-04 06:55:26 +00:00
|
|
|
{
|
|
|
|
m_wnd = wnd;
|
|
|
|
m_twainDS = ds;
|
2023-05-16 10:31:32 +00:00
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DeviceUser::~DeviceUser()
|
|
|
|
{
|
|
|
|
HGTwain_CloseDS(m_twainDS);
|
|
|
|
m_twainDS = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DeviceUser::GetName()
|
|
|
|
{
|
|
|
|
HGChar devName[256];
|
|
|
|
HGTwain_GetDSName(m_twainDS, devName, 256);
|
|
|
|
return QString(devName);
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
|
|
{
|
2023-05-20 08:08:55 +00:00
|
|
|
return HGTwain_EnableDSUIOnly(m_twainDS, (HWND)m_wnd->winId(), DSEventFunc, this);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
|
|
{
|
2023-05-20 08:08:55 +00:00
|
|
|
return HGTwain_EnableDS(m_twainDS, HGFALSE, (HWND)m_wnd->winId(), DSEventFunc, this, DSImageFunc, this);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
HGResult DeviceUser::StartSingleScan()
|
|
|
|
{
|
2023-05-20 08:27:48 +00:00
|
|
|
return HGTwain_EnableDSWithSingleScan(m_twainDS, (HWND)m_wnd->winId(), DSEventFunc, this, DSImageFunc, this);
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
HGResult DeviceUser::GetDeviceCustomInfo(HGTwainDeviceCustomInfo *info)
|
|
|
|
{
|
|
|
|
return HGTwain_GetDSDeviceCustomInfo(m_twainDS, info);
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
HGResult DeviceUser::Login()
|
|
|
|
{
|
|
|
|
return HGTwain_LoginDS(m_twainDS, "user", getStdString(m_password).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::Logout()
|
|
|
|
{
|
|
|
|
return HGTwain_LogoutDS(m_twainDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearRollerCount()
|
|
|
|
{
|
|
|
|
return HGTwain_ClearDSRollerCount(m_twainDS);
|
|
|
|
}
|
|
|
|
|
2023-05-17 10:29:08 +00:00
|
|
|
QString DeviceUser::GetDriverLog()
|
2023-05-16 10:31:32 +00:00
|
|
|
{
|
2023-05-20 08:08:55 +00:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(m_wnd, tr("Select log file path"), ".", tr("text(*.txt)"));
|
|
|
|
HGResult ret = HGTwain_GetDSDriverLog(m_twainDS, fileName.toStdString().c_str());
|
2023-05-17 10:29:08 +00:00
|
|
|
if (ret == HGBASE_ERR_OK)
|
2023-05-20 08:08:55 +00:00
|
|
|
return fileName;
|
2023-05-17 10:29:08 +00:00
|
|
|
|
2023-05-20 08:08:55 +00:00
|
|
|
return "Fail";
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearDriverLog()
|
|
|
|
{
|
|
|
|
return HGTwain_ClearDSDriverLog(m_twainDS);
|
|
|
|
}
|
|
|
|
|
2023-05-17 10:29:08 +00:00
|
|
|
QString DeviceUser::GetDeviceLog()
|
2023-05-16 10:31:32 +00:00
|
|
|
{
|
2023-05-20 08:08:55 +00:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(m_wnd, tr("Select log file path"), ".", tr("text(*.txt)"));
|
|
|
|
HGResult ret = HGTwain_GetDSDeviceLog(m_twainDS, fileName.toStdString().c_str());
|
2023-05-17 10:29:08 +00:00
|
|
|
if (ret == HGBASE_ERR_OK)
|
2023-05-20 08:08:55 +00:00
|
|
|
return fileName;
|
2023-05-17 10:29:08 +00:00
|
|
|
|
2023-05-20 08:08:55 +00:00
|
|
|
return "Fail";
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearDeviceLog()
|
|
|
|
{
|
|
|
|
return HGTwain_ClearDSDeviceLog(m_twainDS);
|
|
|
|
}
|
|
|
|
|
2023-05-20 08:08:55 +00:00
|
|
|
void HGAPI DeviceUser::DSEventFunc(HGTwainDS ds, HGUInt event, HGPointer param)
|
2023-05-04 06:55:26 +00:00
|
|
|
{
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
2023-05-20 08:08:55 +00:00
|
|
|
emit p->scanEvent(event);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
|
|
|
|
{
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
2023-05-20 03:47:19 +00:00
|
|
|
emit p->newImage(image);
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
#else
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
DeviceUserMgr::DeviceUserMgr(QString password, QWidget *wnd)
|
2023-05-04 06:55:26 +00:00
|
|
|
{
|
|
|
|
m_wnd = wnd;
|
|
|
|
m_saneMgr = nullptr;
|
2023-05-16 10:31:32 +00:00
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
HGSane_CreateManager(&m_saneMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceUserMgr::~DeviceUserMgr()
|
|
|
|
{
|
|
|
|
HGSane_DestroyManager(m_saneMgr);
|
|
|
|
m_saneMgr = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
|
|
|
|
{
|
|
|
|
HGSaneSource source = nullptr;
|
|
|
|
HGSane_OpenSelectedSource(m_saneMgr, m_wnd, &source);
|
|
|
|
if (nullptr == source)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
HGUInt devCount = 0;
|
|
|
|
HGSane_GetDeviceCount(source, &devCount);
|
|
|
|
if (0 == devCount)
|
|
|
|
{
|
|
|
|
HGSane_CloseSource(source);
|
2023-05-29 07:19:07 +00:00
|
|
|
QMessageBox::information(m_wnd, tr("tips"), tr("no device"));
|
2023-05-04 06:55:26 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else if (1 == devCount)
|
|
|
|
{
|
|
|
|
HGChar errInfo[256];
|
|
|
|
HGSaneDevice dev = nullptr;
|
|
|
|
HGSane_OpenDevice(source, 0, &dev, errInfo, 256);
|
|
|
|
if (nullptr == dev)
|
|
|
|
{
|
|
|
|
HGSane_CloseSource(source);
|
|
|
|
QMessageBox::information(m_wnd, tr("tips"), QString::fromUtf8(errInfo));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
return new DeviceUser(m_wnd, source, dev, m_password);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HGSaneDevice dev = nullptr;
|
|
|
|
HGSane_OpenSelectedDevice(source, m_wnd, &dev);
|
|
|
|
if (nullptr == dev)
|
|
|
|
{
|
|
|
|
HGSane_CloseSource(source);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
return new DeviceUser(m_wnd, source, dev, m_password);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGSaneSource source, HGSaneDevice dev, QString password)
|
2023-05-04 06:55:26 +00:00
|
|
|
{
|
|
|
|
m_wnd = wnd;
|
|
|
|
m_source = source;
|
|
|
|
m_saneDev = dev;
|
2023-05-16 10:31:32 +00:00
|
|
|
m_password = password;
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DeviceUser::~DeviceUser()
|
|
|
|
{
|
|
|
|
HGSane_CloseDevice(m_saneDev);
|
|
|
|
m_saneDev = nullptr;
|
|
|
|
HGSane_CloseSource(m_source);
|
|
|
|
m_source = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DeviceUser::GetName()
|
|
|
|
{
|
|
|
|
HGChar devName[256];
|
|
|
|
HGSane_GetSourceName(m_source, devName, 256);
|
|
|
|
return QString(devName);
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
|
|
{
|
|
|
|
return HGSane_ShowDeviceSettingDlg(m_saneDev, m_wnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
|
|
{
|
2023-05-23 06:52:45 +00:00
|
|
|
return HGSane_StartDevice(m_saneDev, m_wnd, DeviceEventFunc, this, DeviceImageFunc, this);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 10:06:05 +00:00
|
|
|
HGResult DeviceUser::StartSingleScan()
|
2023-05-16 10:31:32 +00:00
|
|
|
{
|
2023-05-23 06:52:45 +00:00
|
|
|
return HGSane_StartDeviceWithSingleScan(m_saneDev, m_wnd, DeviceEventFunc, this, DeviceImageFunc, this);
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 10:06:05 +00:00
|
|
|
HGResult DeviceUser::GetDeviceCustomInfo(HGSaneDeviceCustomInfo *info)
|
2023-05-04 06:55:26 +00:00
|
|
|
{
|
|
|
|
return HGSane_GetDeviceCustomInfo(m_saneDev, info);
|
|
|
|
}
|
|
|
|
|
2023-05-16 10:31:32 +00:00
|
|
|
HGResult DeviceUser::Login()
|
|
|
|
{
|
|
|
|
return HGSane_Login(m_saneDev, "user", getStdString(m_password).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::Logout()
|
|
|
|
{
|
|
|
|
return HGSane_Logout(m_saneDev);
|
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearRollerCount()
|
|
|
|
{
|
|
|
|
return HGSane_ClearRollerCount(m_saneDev);
|
|
|
|
}
|
|
|
|
|
2023-05-20 10:06:05 +00:00
|
|
|
QString DeviceUser::GetDriverLog()
|
2023-05-16 10:31:32 +00:00
|
|
|
{
|
2023-05-20 10:06:05 +00:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(m_wnd, tr("Select log file path"), ".", tr("text(*.txt)"));
|
|
|
|
HGResult ret = HGSane_GetDriverLog(m_saneDev, fileName.toStdString().c_str());
|
|
|
|
if (ret == HGBASE_ERR_OK)
|
|
|
|
return fileName;
|
|
|
|
|
|
|
|
return "Fail";
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearDriverLog()
|
|
|
|
{
|
|
|
|
return HGSane_ClearDriverLog(m_saneDev);
|
|
|
|
}
|
|
|
|
|
2023-05-20 10:06:05 +00:00
|
|
|
QString DeviceUser::GetDeviceLog()
|
2023-05-16 10:31:32 +00:00
|
|
|
{
|
2023-05-20 10:06:05 +00:00
|
|
|
QString fileName = QFileDialog::getSaveFileName(m_wnd, tr("Select log file path"), ".", tr("text(*.txt)"));
|
|
|
|
HGResult ret = HGSane_GetDeviceLog(m_saneDev, fileName.toStdString().c_str());
|
|
|
|
if (ret == HGBASE_ERR_OK)
|
|
|
|
return fileName;
|
|
|
|
|
|
|
|
return "Fail";
|
2023-05-16 10:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HGResult DeviceUser::ClearDeviceLog()
|
|
|
|
{
|
|
|
|
return HGSane_ClearDeviceLog(m_saneDev);
|
|
|
|
}
|
|
|
|
|
2023-05-23 06:52:45 +00:00
|
|
|
void HGAPI DeviceUser::DeviceEventFunc(HGSaneDevice dev, HGUInt event, HGPointer param)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-04 06:55:26 +00:00
|
|
|
void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param)
|
|
|
|
{
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
2023-05-20 03:47:19 +00:00
|
|
|
emit p->newImage(image);
|
2023-05-04 06:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|