129 lines
2.6 KiB
C++
129 lines
2.6 KiB
C++
#include "device_user.h"
|
|
#include "dialog_device_select.h"
|
|
#include "dialog_device_scan.h"
|
|
#include <QMessageBox>
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
HGImage image2 = nullptr;
|
|
HGBase_CloneImage(image, 0, 0, &image2);
|
|
if (nullptr != image2)
|
|
{
|
|
emit p->newImage(image2);
|
|
}
|
|
}
|
|
|
|
#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()
|
|
{
|
|
Dialog_Device_Select dlg(m_saneMgr, m_wnd);
|
|
if (!dlg.exec())
|
|
return nullptr;
|
|
|
|
return new DeviceUser(m_wnd, dlg.getSaneDevice());
|
|
}
|
|
|
|
DeviceUser::DeviceUser(QWidget *wnd, HGSaneDevice dev)
|
|
{
|
|
m_wnd = wnd;
|
|
m_saneDev = dev;
|
|
}
|
|
|
|
DeviceUser::~DeviceUser()
|
|
{
|
|
HGSane_CloseDevice(m_saneDev);
|
|
m_saneDev = nullptr;
|
|
}
|
|
|
|
HGResult DeviceUser::ShowSettingDlg()
|
|
{
|
|
#ifdef HG_CMP_MSC
|
|
return HGSane_ShowDeviceSettingDlg(m_saneDev, (HWND)m_wnd->winId());
|
|
#else
|
|
return HGSane_ShowDeviceSettingDlg(m_saneDev, m_wnd);
|
|
#endif
|
|
}
|
|
|
|
HGResult DeviceUser::StartScan()
|
|
{
|
|
Dialog_Device_Scan dlg(m_saneDev, m_wnd);
|
|
connect(&dlg, SIGNAL(newImage(void *)), this, SLOT(on_newImage(void *)), Qt::QueuedConnection);
|
|
dlg.exec();
|
|
disconnect(&dlg, SIGNAL(newImage(void *)), this, SLOT(on_newImage(void *)));
|
|
return HGBASE_ERR_OK;
|
|
}
|
|
|
|
void DeviceUser::on_newImage(void *image)
|
|
{
|
|
emit newImage(image);
|
|
}
|
|
|
|
#endif
|