2023-03-27 10:02:38 +00:00
|
|
|
|
#include "device_user.h"
|
|
|
|
|
|
2023-03-29 08:16:19 +00:00
|
|
|
|
#if 0
|
2023-03-27 10:02:38 +00:00
|
|
|
|
|
|
|
|
|
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
|
|
|
|
|
{
|
|
|
|
|
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_OpenSelectedDS(m_twainDSM, &ds);
|
|
|
|
|
if (nullptr == ds)
|
|
|
|
|
return nullptr;
|
|
|
|
|
return new DeviceUser(m_wnd, ds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds)
|
|
|
|
|
{
|
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_twainDS = ds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUser::~DeviceUser()
|
|
|
|
|
{
|
|
|
|
|
HGTwain_CloseDS(m_twainDS);
|
|
|
|
|
m_twainDS = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 08:16:19 +00:00
|
|
|
|
QString DeviceUser::GetName()
|
|
|
|
|
{
|
|
|
|
|
HGChar devName[256];
|
|
|
|
|
HGTwain_GetDSName(m_twainDS, devName, 256);
|
|
|
|
|
return QString(devName);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 10:02:38 +00:00
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_EnableDSUIOnly(m_twainDS, (HWND)m_wnd->winId(), DSCloseReqFunc, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
|
|
|
{
|
|
|
|
|
return HGTwain_EnableDS(m_twainDS, HGFALSE, nullptr, DSCloseReqFunc, this, DSImageFunc, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HGAPI DeviceUser::DSCloseReqFunc(HGTwainDS ds, HGPointer param)
|
|
|
|
|
{
|
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
|
|
|
|
HGTwain_DisableDS(p->m_twainDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HGAPI DeviceUser::DSImageFunc(HGTwainDS ds, HGImage image, HGPointer param)
|
|
|
|
|
{
|
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
2023-03-29 08:16:19 +00:00
|
|
|
|
emit p->newImage(image);
|
2023-03-27 10:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
DeviceUserMgr::DeviceUserMgr(QWidget *wnd)
|
|
|
|
|
{
|
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_saneMgr = nullptr;
|
|
|
|
|
HGSane_CreateManager("sane.dll", &m_saneMgr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUserMgr::~DeviceUserMgr()
|
|
|
|
|
{
|
|
|
|
|
HGSane_DestroyManager(m_saneMgr);
|
|
|
|
|
m_saneMgr = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
|
|
|
|
|
{
|
2023-03-29 08:16:19 +00:00
|
|
|
|
HGSaneDevice dev = nullptr;
|
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
|
HGSane_OpenSelectedDevice(m_saneMgr, (HWND)m_wnd->winId(), &dev);
|
|
|
|
|
#else
|
|
|
|
|
HGSane_OpenSelectedDevice(m_saneMgr, m_wnd, &dev);
|
|
|
|
|
#endif
|
|
|
|
|
if (nullptr == dev)
|
2023-03-27 10:02:38 +00:00
|
|
|
|
return nullptr;
|
2023-03-29 08:16:19 +00:00
|
|
|
|
return new DeviceUser(m_wnd, dev);
|
2023-03-27 10:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGSaneDevice dev)
|
|
|
|
|
{
|
|
|
|
|
m_wnd = wnd;
|
|
|
|
|
m_saneDev = dev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeviceUser::~DeviceUser()
|
|
|
|
|
{
|
|
|
|
|
HGSane_CloseDevice(m_saneDev);
|
|
|
|
|
m_saneDev = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 08:16:19 +00:00
|
|
|
|
QString DeviceUser::GetName()
|
|
|
|
|
{
|
|
|
|
|
HGChar devName[256];
|
|
|
|
|
HGSane_GetDeviceName(m_saneDev, devName, 256);
|
|
|
|
|
return QString(devName);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 10:02:38 +00:00
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
|
|
|
{
|
2023-03-28 07:39:10 +00:00
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
|
return HGSane_ShowDeviceSettingDlg(m_saneDev, (HWND)m_wnd->winId());
|
|
|
|
|
#else
|
|
|
|
|
return HGSane_ShowDeviceSettingDlg(m_saneDev, m_wnd);
|
|
|
|
|
#endif
|
2023-03-27 10:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
|
|
|
{
|
2023-03-29 08:16:19 +00:00
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
|
return HGSane_StartDeviceWithUI(m_saneDev, (HWND)m_wnd->winId(), DeviceImageFunc, this);
|
|
|
|
|
#else
|
|
|
|
|
return HGSane_StartDeviceWithUI(m_saneDev, m_wnd, DeviceImageFunc, this);
|
|
|
|
|
#endif
|
2023-03-27 10:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 08:16:19 +00:00
|
|
|
|
void HGAPI DeviceUser::DeviceImageFunc(HGSaneDevice dev, HGImage image, HGPointer param)
|
2023-03-27 10:02:38 +00:00
|
|
|
|
{
|
2023-03-29 08:16:19 +00:00
|
|
|
|
DeviceUser* p = (DeviceUser*)param;
|
|
|
|
|
emit p->newImage(image);
|
2023-03-27 10:02:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|