2023-05-06 02:55:17 +00:00
|
|
|
#include "twain_user/twainui.h"
|
2023-05-04 03:13:47 +00:00
|
|
|
#include <QMessageBox>
|
2023-05-19 03:05:59 +00:00
|
|
|
#include <string>
|
2023-04-20 09:49:48 +00:00
|
|
|
#include "dialog_device_select.h"
|
|
|
|
#include "dialog_progress_ui.h"
|
|
|
|
#include "hg_settingdialog.h"
|
2023-05-12 06:39:19 +00:00
|
|
|
#include "dialog_twain_source_select.h"
|
2023-04-27 09:42:50 +00:00
|
|
|
#include "device_menu.h"
|
|
|
|
#include "base/HGBase.h"
|
2023-05-10 12:30:07 +00:00
|
|
|
#include "Manager.h"
|
2023-04-20 09:49:48 +00:00
|
|
|
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
#include "qwinwidget.hpp"
|
|
|
|
extern HINSTANCE g_hInst;
|
2023-05-10 12:30:07 +00:00
|
|
|
extern HGEvent g_event;
|
|
|
|
extern Manager *g_manager;
|
|
|
|
extern HGThread g_hThread;
|
2023-04-20 09:49:48 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
|
|
|
|
static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
|
2023-04-20 09:49:48 +00:00
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
bool ownApplication = false;
|
|
|
|
ownApplication = QMfcApp::pluginInstance(g_hInst);
|
|
|
|
if (ownApplication)
|
|
|
|
{
|
|
|
|
qApp->setQuitOnLastWindowClosed(false);
|
|
|
|
|
|
|
|
g_manager = new Manager;
|
|
|
|
HGBase_SetEvent(g_event);
|
|
|
|
qApp->exec();
|
|
|
|
delete qApp;
|
|
|
|
}
|
|
|
|
}
|
2023-04-21 07:41:13 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
int choose_scanner(const std::vector<DEVQUEUI> &devs)
|
|
|
|
{
|
|
|
|
if (!qApp)
|
|
|
|
{
|
|
|
|
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
|
|
|
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
|
|
|
HGBase_WaitEvent(g_event);
|
|
|
|
}
|
2023-04-21 07:51:55 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
if (NULL == g_manager)
|
|
|
|
{
|
|
|
|
g_manager = new Manager;
|
|
|
|
}
|
2023-04-23 01:25:52 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return g_manager->showDeviceSelect(devs);
|
2023-04-20 09:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *apply_current_config(const char *dev_name, SANE_Handle device, LPSANEAPI api)
|
|
|
|
{
|
2023-04-27 09:42:50 +00:00
|
|
|
dev_que devQue;
|
|
|
|
gb::scanner_cfg *cur_cfg_ = nullptr;
|
|
|
|
gb::sane_config_schm *curScheme = nullptr;
|
|
|
|
|
|
|
|
HGChar cfgpath[512] = {0};
|
|
|
|
HGBase_GetConfigPath(cfgpath, _countof(cfgpath) - 1);
|
|
|
|
HGBase_CreateDir(cfgpath);
|
|
|
|
devQue.set_root_dir(cfgpath);
|
|
|
|
QString old = QString::fromStdString(cfgpath) + PATH_SYMBOL + "scanner.schm";
|
|
|
|
if(QFile::exists(old))
|
|
|
|
dev_que::update_old_cfg(old.toStdString().c_str());
|
|
|
|
|
2023-05-19 03:05:59 +00:00
|
|
|
std::string devName = dev_name;
|
|
|
|
|
|
|
|
int pid = 0;
|
|
|
|
api->sane_control_option_api(device, (SANE_Int)0x8853, SANE_ACTION_GET_VALUE, &pid, NULL);
|
|
|
|
|
|
|
|
devQue.add_scanner(devName.c_str(), pid);
|
2023-05-04 10:14:06 +00:00
|
|
|
devQue.open_scanner(api, device, dev_name, true);
|
2023-04-27 09:42:50 +00:00
|
|
|
|
|
|
|
std::string n(devQue.opened_scanner_name());
|
|
|
|
for(int i = 0; i < devQue.scanners(); ++i)
|
|
|
|
{
|
|
|
|
SCANNER s = devQue.get_at(i);
|
|
|
|
if(s.name == n)
|
|
|
|
{
|
|
|
|
cur_cfg_ = s.cfg;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curScheme = cur_cfg_->get_scheme();
|
|
|
|
if(!curScheme)
|
|
|
|
curScheme = new gb::sane_config_schm();
|
|
|
|
curScheme->begin_setting();
|
|
|
|
|
|
|
|
std::string name = curScheme->get_scheme_name();
|
|
|
|
char *str = const_cast<char*>(name.c_str());
|
|
|
|
return str;
|
2023-04-20 09:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void twain_ui_free(void *buf)
|
|
|
|
{
|
|
|
|
if (buf != nullptr)
|
|
|
|
{
|
|
|
|
delete buf;
|
|
|
|
buf = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-06 02:55:17 +00:00
|
|
|
int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void(ui_result)> callback)
|
2023-04-20 09:49:48 +00:00
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
if (!qApp)
|
|
|
|
{
|
|
|
|
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
|
|
|
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
|
|
|
HGBase_WaitEvent(g_event);
|
|
|
|
}
|
2023-04-20 09:49:48 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
if (NULL == g_manager)
|
2023-04-20 09:49:48 +00:00
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
g_manager = new Manager;
|
2023-04-20 09:49:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return g_manager->showSettingUi(device, parent, api, devName, with_scan, callback);
|
2023-04-20 09:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int show_progress_ui(HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify)
|
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
if (!qApp)
|
2023-04-20 09:49:48 +00:00
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
|
|
|
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
|
|
|
HGBase_WaitEvent(g_event);
|
2023-04-20 09:49:48 +00:00
|
|
|
}
|
2023-05-08 02:10:48 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
if (NULL == g_manager)
|
2023-05-08 02:10:48 +00:00
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
g_manager = new Manager;
|
2023-05-08 02:10:48 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return g_manager->showProgressUi(parent, callback, notify);
|
2023-04-20 09:49:48 +00:00
|
|
|
}
|
2023-05-04 03:13:47 +00:00
|
|
|
|
|
|
|
int show_messagebox_ui(HWND parent, int event, void *msg, int flag)
|
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
if (!qApp)
|
2023-05-04 03:13:47 +00:00
|
|
|
{
|
2023-05-10 12:30:07 +00:00
|
|
|
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
|
|
|
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
|
|
|
HGBase_WaitEvent(g_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == g_manager)
|
|
|
|
{
|
|
|
|
g_manager = new Manager;
|
2023-05-04 03:13:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return g_manager->showMessageBoxUi(parent, event, msg, flag);
|
2023-05-04 03:13:47 +00:00
|
|
|
}
|
2023-05-12 06:39:19 +00:00
|
|
|
|
|
|
|
int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds)
|
|
|
|
{
|
|
|
|
if (!qApp)
|
|
|
|
{
|
|
|
|
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
|
|
|
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
|
|
|
HGBase_WaitEvent(g_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == g_manager)
|
|
|
|
{
|
|
|
|
g_manager = new Manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_manager->showTwainSrcUi(dsmProc, appId, parent, ds);
|
|
|
|
}
|