diff --git a/app/demo/main.cpp b/app/demo/main.cpp index b7110377..7cd517d2 100644 --- a/app/demo/main.cpp +++ b/app/demo/main.cpp @@ -48,6 +48,8 @@ int main(int argc, char *argv[]) lang_set_code_page(cp); MainWindow w; + QScreen *screen = QGuiApplication::primaryScreen(); + w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2); w.show(); return a.exec(); } diff --git a/build2/qt/HGSaneUI/HGSaneUI.pro b/build2/qt/HGSaneUI/HGSaneUI.pro index 6126a658..b200b53e 100644 --- a/build2/qt/HGSaneUI/HGSaneUI.pro +++ b/build2/qt/HGSaneUI/HGSaneUI.pro @@ -217,7 +217,8 @@ SOURCES += \ ../../../modules/saneui/hg_settingdialog.cpp \ ../../../modules/saneui/setpicclrtool.cpp \ ../../../modules/saneui/widget.cpp \ - ../../../utility/HGString.cpp + ../../../utility/HGString.cpp \ + ../../../modules/saneui/dialog_source_select.cpp HEADERS += \ ../../../modules/saneui/HGSaneUI.h \ @@ -226,14 +227,15 @@ HEADERS += \ ../../../modules/saneui/cutdialog.h \ ../../../modules/saneui/cutpapertool.h \ ../../../modules/saneui/device_menu.h \ - ../../../modules/saneui/dialog_device_scan.hpp \ - ../../../modules/saneui/dialog_device_select.hpp \ + ../../../modules/saneui/dialog_device_scan.h \ + ../../../modules/saneui/dialog_device_select.h \ ../../../modules/saneui/dialog_input.h \ ../../../modules/saneui/gaosixy.h \ ../../../modules/saneui/hg_settingdialog.h \ ../../../modules/saneui/setpicclrtool.h \ ../../../modules/saneui/widget.h \ - ../../../utility/HGString.h + ../../../utility/HGString.h \ + ../../../modules/saneui/dialog_source_select.h FORMS += \ ../../../modules/saneui/cutdialog.ui \ @@ -242,7 +244,8 @@ FORMS += \ ../../../modules/saneui/dialog_device_select.ui \ ../../../modules/saneui/dialog_input.ui \ ../../../modules/saneui/setpicclrtool.ui \ - ../../../modules/saneui/widget.ui + ../../../modules/saneui/widget.ui \ + ../../../modules/saneui/dialog_source_select.ui RESOURCES += \ ../../../modules/saneui/SaneUI_resource.qrc diff --git a/modules/sane_user/HGSaneImpl.cpp b/modules/sane_user/HGSaneImpl.cpp index 385d341e..c2f3e3cb 100644 --- a/modules/sane_user/HGSaneImpl.cpp +++ b/modules/sane_user/HGSaneImpl.cpp @@ -13,6 +13,72 @@ HGSaneManagerImpl::~HGSaneManagerImpl() HGResult HGSaneManagerImpl::Create() { + char manuPath[] = "/etc/sane.d/dll.d"; + + DIR* dir = opendir(manuPath); + if (NULL != dir) + { + struct dirent* dire = NULL; + while (dire = readdir(dir)) + { + if (0 == strcmp(dire->d_name, ".") || 0 == strcmp(dire->d_name, "..")) + { + continue; + } + + char fileName[256]; + sprintf(fileName, "%s/%s", manuPath, dire->d_name); + + struct stat filebuf; + lstat(fileName, &filebuf); + if (S_ISDIR(filebuf.st_mode)) + { + continue; + } + + std::string manuName; + FILE *file = fopen(fileName, "r"); + if (NULL != file) + { + char str[256] = {0}; + while (NULL != fgets(str, 256, file)) + { + if ('#' == str[0] || '\n' == str[0]) + { + continue; + } + + char *p = str; + while (0 != *p && '\n' != *p) + { + manuName.push_back(*p); + ++p; + } + + break; + } + + fclose(file); + } + + if (manuName.empty()) + { + continue; + } + + std::pair pr; + pr.first = manuName; + + char sanePath[256]; + sprintf(sanePath, "/usr/lib/x86_64-linux-gnu/sane/libsane-%s.so.1", manuName.c_str()); + pr.second = sanePath; + + m_vSource.push_back(pr); + } + + closedir(dir); + } + return HGBASE_ERR_OK; } @@ -77,23 +143,36 @@ HGResult HGSaneManagerImpl::OpenSelectedSource(HGWindow parent, class HGSaneSour return HGBASE_ERR_INVALIDARG; } + const char **manuNames = new const char *[m_vSource.size() + 1]; + const char **sanePaths = new const char *[m_vSource.size() + 1]; + for (int i = 0; i < (int)m_vSource.size(); ++i) + { + manuNames[i] = m_vSource[i].first.c_str(); + sanePaths[i] = m_vSource[i].second.c_str(); + } + manuNames[m_vSource.size()] = NULL; + sanePaths[m_vSource.size()] = NULL; + HGDll dll = NULL; - f_sane_init fInit = NULL; - f_sane_exit fExit = NULL; SANEAPI saneAPI; char manuName[256]; - if (-2 == show_srclist_ui(parent, &dll, &fInit, &fExit, &saneAPI, manuName, 256)) + if (-2 == show_srclist_ui(manuNames, sanePaths, parent, &dll, &saneAPI, manuName, 256)) { + delete [] sanePaths; + delete [] manuNames; return HGBASE_ERR_NOTSUPPORT; } + delete [] sanePaths; + delete [] manuNames; + if (NULL == dll) { return HGSANE_ERR_FAIL; } HGSaneSourceImpl* newSourceImpl = new HGSaneSourceImpl(this); - HGResult ret = newSourceImpl->Init(manuName, dll, fInit, fExit, &saneAPI); + HGResult ret = newSourceImpl->Init(manuName, dll, &saneAPI); if (HGBASE_ERR_OK != ret) { delete newSourceImpl; @@ -126,8 +205,6 @@ HGSaneSourceImpl::HGSaneSourceImpl(HGSaneManagerImpl *managerImpl) m_managerImpl = managerImpl; m_manuName.clear(); m_dll = NULL; - m_f_sane_init = NULL; - m_f_sane_exit = NULL; memset(&m_saneApi, 0, sizeof(SANEAPI)); } @@ -136,11 +213,11 @@ HGSaneSourceImpl::~HGSaneSourceImpl() } -HGResult HGSaneSourceImpl::Init(const HGChar* saneManu, HGDll dll, f_sane_init fInit, f_sane_exit fExit, const SANEAPI *saneAPI) +HGResult HGSaneSourceImpl::Init(const HGChar* saneManu, HGDll dll, const SANEAPI *saneAPI) { assert(NULL == m_dll); - if (NULL == dll || NULL == fInit || NULL == fExit || NULL == saneAPI) + if (NULL == saneManu || 0 == *saneManu || NULL == dll || NULL == saneAPI) { return HGBASE_ERR_INVALIDARG; } @@ -149,21 +226,20 @@ HGResult HGSaneSourceImpl::Init(const HGChar* saneManu, HGDll dll, f_sane_init f || NULL == saneAPI->sane_start_api || NULL == saneAPI->sane_read_api || NULL == saneAPI->sane_cancel_api || NULL == saneAPI->sane_get_devices_api || NULL == saneAPI->sane_get_option_descriptor_api || NULL == saneAPI->sane_control_option_api - || NULL == saneAPI->sane_get_parameters_api || saneAPI->sane_set_io_mode_api - || NULL == saneAPI->sane_strstatus_api || NULL == saneAPI->sane_io_control_api) + || NULL == saneAPI->sane_get_parameters_api || NULL == saneAPI->sane_set_io_mode_api + || NULL == saneAPI->sane_strstatus_api || NULL == saneAPI->sane_io_control_api + || NULL == saneAPI->sane_init_api || NULL == saneAPI->sane_exit_api) { return HGBASE_ERR_INVALIDARG; } - if (SANE_STATUS_GOOD != fInit(NULL, NULL)) + if (SANE_STATUS_GOOD != saneAPI->sane_init_api(NULL, NULL)) { return HGSANE_ERR_FAIL; } m_manuName = saneManu; m_dll = dll; - m_f_sane_init = fInit; - m_f_sane_exit = fExit; memcpy(&m_saneApi, saneAPI, sizeof(SANEAPI)); return HGBASE_ERR_OK; } @@ -172,27 +248,28 @@ HGResult HGSaneSourceImpl::Open(const HGChar* saneManu, const HGChar* sanePath) { assert(NULL == m_dll); - if (NULL == saneManu || 0 == *saneManu - || NULL == sanePath || 0 == *sanePath) + if (NULL == saneManu || 0 == *saneManu || NULL == sanePath || 0 == *sanePath) { return HGBASE_ERR_INVALIDARG; } - HGResult ret = HGBase_CreateDll(sanePath, &m_dll); + HGDll dll = NULL; + HGResult ret = HGBase_CreateDll(sanePath, &dll); if (HGBASE_ERR_OK != ret) { return ret; } - ret = FindFunctions(saneManu); + SANEAPI saneAPI; + ret = FindFunctions(dll, saneManu, &saneAPI); if (HGBASE_ERR_OK != ret) { - HGBase_DestroyDll(m_dll); - m_dll = NULL; + HGBase_DestroyDll(dll); + dll = NULL; return ret; } - if (SANE_STATUS_GOOD != m_f_sane_init(NULL, NULL)) + if (SANE_STATUS_GOOD != saneAPI.sane_init_api(NULL, NULL)) { HGBase_DestroyDll(m_dll); m_dll = NULL; @@ -200,6 +277,8 @@ HGResult HGSaneSourceImpl::Open(const HGChar* saneManu, const HGChar* sanePath) } m_manuName = saneManu; + m_dll = dll; + memcpy(&m_saneApi, &saneAPI, sizeof(SANEAPI)); return HGBASE_ERR_OK; } @@ -212,7 +291,7 @@ HGResult HGSaneSourceImpl::Close() return HGBASE_ERR_FAIL; } - m_f_sane_exit(); + m_saneApi.sane_exit_api(); HGBase_DestroyDll(m_dll); m_dll = NULL; m_managerImpl->RemoveSource(this); @@ -349,7 +428,7 @@ HGResult HGSaneSourceImpl::OpenSelectedDevice(HGWindow parent, class HGSaneDevic return HGBASE_ERR_OK; } -HGResult HGSaneSourceImpl::FindFunctions(const HGChar* saneManu) +HGResult HGSaneSourceImpl::FindFunctions(HGDll dll, const HGChar* saneManu, SANEAPI *saneAPI) { HGResult ret = HGBASE_ERR_OK; @@ -358,72 +437,72 @@ HGResult HGSaneSourceImpl::FindFunctions(const HGChar* saneManu) HGChar funcName[256]; sprintf(funcName, "sane_%s_init", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_f_sane_init); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_init_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_exit", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_f_sane_exit); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_exit_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_get_devices", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_get_devices_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_devices_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_open", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_open_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_open_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_close", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_close_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_close_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_start", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_start_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_start_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_read", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_read_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_read_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_cancel", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_cancel_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_cancel_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_set_io_mode", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_set_io_mode_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_set_io_mode_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_strstatus", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_strstatus_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_strstatus_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_get_parameters", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_get_parameters_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_parameters_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_get_option_descriptor", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_get_option_descriptor_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_option_descriptor_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_control_option", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_control_option_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_control_option_api); if (HGBASE_ERR_OK != ret) break; sprintf(funcName, "sane_%s_io_control", saneManu); - ret = HGBase_GetDllProcAddress(m_dll, funcName, (HGPointer*)&m_saneApi.sane_io_control_api); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_io_control_api); if (HGBASE_ERR_OK != ret) break; diff --git a/modules/sane_user/HGSaneImpl.hpp b/modules/sane_user/HGSaneImpl.hpp index b705b10d..bb261c70 100644 --- a/modules/sane_user/HGSaneImpl.hpp +++ b/modules/sane_user/HGSaneImpl.hpp @@ -41,7 +41,7 @@ public: HGSaneSourceImpl(HGSaneManagerImpl *managerImpl); ~HGSaneSourceImpl(); - HGResult Init(const HGChar* saneManu, HGDll dll, f_sane_init fInit, f_sane_exit fExit, const SANEAPI *saneAPI); + HGResult Init(const HGChar* saneManu, HGDll dll, const SANEAPI *saneAPI); HGResult Open(const HGChar* saneManu, const HGChar* sanePath); HGResult Close(); HGResult GetName(HGChar* name, HGUInt maxLen); @@ -51,15 +51,13 @@ public: HGResult OpenSelectedDevice(HGWindow parent, class HGSaneDeviceImpl** deviceImpl); private: - HGResult FindFunctions(const HGChar* saneManu); + static HGResult FindFunctions(HGDll dll, const HGChar* saneManu, SANEAPI *saneAPI); void RemoveDevice(class HGSaneDeviceImpl* deviceImpl); private: HGSaneManagerImpl *m_managerImpl; std::string m_manuName; HGDll m_dll; - f_sane_init m_f_sane_init; - f_sane_exit m_f_sane_exit; SANEAPI m_saneApi; std::list m_listDeviceImpl; }; diff --git a/modules/saneui/HGSaneUI.cpp b/modules/saneui/HGSaneUI.cpp index e491c839..ede2cd68 100644 --- a/modules/saneui/HGSaneUI.cpp +++ b/modules/saneui/HGSaneUI.cpp @@ -1,6 +1,7 @@ #include "HGSaneUI.h" -#include "dialog_device_select.hpp" -#include "dialog_device_scan.hpp" +#include "dialog_source_select.h" +#include "dialog_device_select.h" +#include "dialog_device_scan.h" #include "hg_settingdialog.h" #include "lang/app_language.h" #include @@ -13,9 +14,48 @@ extern HINSTANCE g_hInst; extern bool g_ownApplication; #endif -int show_srclist_ui(HGWindow parent, HGDll *dll, f_sane_init *fInit, f_sane_exit *fExit, +int show_srclist_ui(const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll, SANEAPI* saneApi, char *manuName, unsigned int maxLen) { + if (nullptr == manuNames || nullptr == sanePaths || nullptr == dll || nullptr == saneApi) + return -1; + + QWidget *qParent = nullptr; +#ifdef HG_CMP_MSC + if (!g_ownApplication) + g_ownApplication = QMfcApp::pluginInstance(g_hInst); + QWinWidget win(parent); + win.showCentered(); + qParent = &win; +#else + qParent = parent; +#endif + + QTranslator translator; + int cp = lang_get_cur_code_page(); + if (20127 == cp) + translator.load(":translation/SaneUI_zh_EN.qm"); + else + translator.load(":translation/SaneUI_zh_CN.qm"); + QCoreApplication::installTranslator(&translator); + + *dll = nullptr; + memset(saneApi, 0, sizeof(SANEAPI)); + Dialog_Source_Select dlg(manuNames, sanePaths, qParent); + if (dlg.exec()) + { + if (nullptr != manuName) + { + std::string strManuName = dlg.GetManuName(); + if (maxLen >= strManuName.size() + 1) + strcpy(manuName, strManuName.c_str()); + } + + *dll = dlg.GetDll(); + dlg.GetSaneAPI(saneApi); + } + + QCoreApplication::removeTranslator(&translator); return 0; } diff --git a/modules/saneui/HGSaneUI.h b/modules/saneui/HGSaneUI.h index 5eef66bd..415424ac 100644 --- a/modules/saneui/HGSaneUI.h +++ b/modules/saneui/HGSaneUI.h @@ -5,11 +5,9 @@ #include "../base/HGDll.h" #include "sane/sane_ex.h" -typedef SANE_Status (*f_sane_init)(SANE_Int* version_code, SANE_Auth_Callback authorize); -typedef void (*f_sane_exit)(void); typedef void (*show_scan_ui_image_callback)(const SANE_Parameters *imageFormat, const SANE_Byte *imageData, void * callbackParam); -HGEXPORT int show_srclist_ui(HGWindow parent, HGDll *dll, f_sane_init *fInit, f_sane_exit *fExit, +HGEXPORT int show_srclist_ui(const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll, SANEAPI* saneApi, char *manuName, unsigned int maxLen); HGEXPORT int show_devlist_ui(const SANEAPI* saneApi, HGWindow parent, SANE_Handle *handle, char *devName, unsigned int maxLen); HGEXPORT int show_setting_ui(const SANEAPI* saneApi, SANE_Handle handle, const char *devName, HGWindow parent); diff --git a/modules/saneui/dialog_device_scan.cpp b/modules/saneui/dialog_device_scan.cpp index 643bfc2d..480bdf20 100644 --- a/modules/saneui/dialog_device_scan.cpp +++ b/modules/saneui/dialog_device_scan.cpp @@ -1,4 +1,4 @@ -#include "dialog_device_scan.hpp" +#include "dialog_device_scan.h" #include "ui_dialog_device_scan.h" #include "base/HGInc.h" #include diff --git a/modules/saneui/dialog_device_scan.hpp b/modules/saneui/dialog_device_scan.h similarity index 100% rename from modules/saneui/dialog_device_scan.hpp rename to modules/saneui/dialog_device_scan.h diff --git a/modules/saneui/dialog_device_select.cpp b/modules/saneui/dialog_device_select.cpp index 5b75ea0d..deb067b6 100644 --- a/modules/saneui/dialog_device_select.cpp +++ b/modules/saneui/dialog_device_select.cpp @@ -1,4 +1,4 @@ -#include "dialog_device_select.hpp" +#include "dialog_device_select.h" #include "ui_dialog_device_select.h" #include diff --git a/modules/saneui/dialog_device_select.hpp b/modules/saneui/dialog_device_select.h similarity index 100% rename from modules/saneui/dialog_device_select.hpp rename to modules/saneui/dialog_device_select.h diff --git a/modules/saneui/dialog_source_select.cpp b/modules/saneui/dialog_source_select.cpp new file mode 100644 index 00000000..cfed9edd --- /dev/null +++ b/modules/saneui/dialog_source_select.cpp @@ -0,0 +1,175 @@ +#include "dialog_source_select.h" +#include "ui_dialog_source_select.h" +#include + +Dialog_Source_Select::Dialog_Source_Select(const char **manuNames, const char **sanePaths, QWidget *parent) : + QDialog(parent), + ui(new Ui::Dialog_Source_Select) +{ + ui->setupUi(this); + + m_vSource.clear(); + m_strManuName.clear(); + m_dll = nullptr; + memset(&m_saneApi, 0, sizeof(SANEAPI)); + + setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + + const char **p1 = manuNames; + const char **p2 = sanePaths; + while (*p1 != NULL && *p2 != NULL) + { + std::pair pr; + pr.first = *p1; + pr.second = *p2; + m_vSource.push_back(pr); + ui->listWidget->addItem(*p1); + ++p1; + ++p2; + } + + if (!m_vSource.empty()) + { + ui->listWidget->setCurrentRow(0); + } +} + +Dialog_Source_Select::~Dialog_Source_Select() +{ + delete ui; +} + +std::string Dialog_Source_Select::GetManuName() +{ + return m_strManuName; +} + +HGDll Dialog_Source_Select::GetDll() +{ + return m_dll; +} + +void Dialog_Source_Select::GetSaneAPI(SANEAPI *saneAPI) +{ + memcpy(saneAPI, &m_saneApi, sizeof(SANEAPI)); +} + +void Dialog_Source_Select::on_pushButton_OK_clicked() +{ + int index = ui->listWidget->currentRow(); + if (index < 0) + { + return; + } + + HGDll dll = nullptr; + HGResult ret = HGBase_CreateDll(m_vSource[index].second.c_str(), &dll); + if (HGBASE_ERR_OK != ret) + { + QMessageBox::information(this, tr("tips"), tr("Load library failed")); + return; + } + + SANEAPI saneAPI; + ret = FindFunctions(dll, m_vSource[index].first.c_str(), &saneAPI); + if (HGBASE_ERR_OK != ret) + { + HGBase_DestroyDll(dll); + dll = NULL; + QMessageBox::information(this, tr("tips"), tr("Find function failed")); + return; + } + + m_strManuName = m_vSource[index].first; + m_dll = dll; + memcpy(&m_saneApi, &saneAPI, sizeof(SANEAPI)); + accept(); +} + +void Dialog_Source_Select::on_pushButton_Cancel_clicked() +{ + reject(); +} + +HGResult Dialog_Source_Select::FindFunctions(HGDll dll, const HGChar* saneManu, SANEAPI *saneAPI) +{ + HGResult ret = HGBASE_ERR_OK; + + do + { + HGChar funcName[256]; + + sprintf(funcName, "sane_%s_init", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_init_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_exit", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_exit_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_get_devices", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_devices_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_open", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_open_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_close", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_close_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_start", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_start_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_read", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_read_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_cancel", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_cancel_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_set_io_mode", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_set_io_mode_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_strstatus", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_strstatus_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_get_parameters", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_parameters_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_get_option_descriptor", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_get_option_descriptor_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_control_option", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_control_option_api); + if (HGBASE_ERR_OK != ret) + break; + + sprintf(funcName, "sane_%s_io_control", saneManu); + ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_io_control_api); + if (HGBASE_ERR_OK != ret) + break; + + } while (0); + + return ret; +} diff --git a/modules/saneui/dialog_source_select.h b/modules/saneui/dialog_source_select.h new file mode 100644 index 00000000..ce58b77a --- /dev/null +++ b/modules/saneui/dialog_source_select.h @@ -0,0 +1,41 @@ +#ifndef DIALOG_SOURCE_SELECT_H +#define DIALOG_SOURCE_SELECT_H + +#include +#include +#include +#include "HGSaneUI.h" + +namespace Ui { +class Dialog_Source_Select; +} + +class Dialog_Source_Select : public QDialog +{ + Q_OBJECT + +public: + explicit Dialog_Source_Select(const char **manuNames, const char **sanePaths, QWidget *parent = 0); + ~Dialog_Source_Select(); + + std::string GetManuName(); + HGDll GetDll(); + void GetSaneAPI(SANEAPI *saneAPI); + +private slots: + void on_pushButton_OK_clicked(); + + void on_pushButton_Cancel_clicked(); + +private: + HGResult FindFunctions(HGDll dll, const HGChar* saneManu, SANEAPI *saneAPI); + +private: + Ui::Dialog_Source_Select *ui; + std::vector > m_vSource; + std::string m_strManuName; + HGDll m_dll; + SANEAPI m_saneApi; +}; + +#endif // DIALOG_SOURCE_SELECT_H diff --git a/modules/saneui/dialog_source_select.ui b/modules/saneui/dialog_source_select.ui new file mode 100644 index 00000000..892d8366 --- /dev/null +++ b/modules/saneui/dialog_source_select.ui @@ -0,0 +1,59 @@ + + + Dialog_Source_Select + + + + 0 + 0 + 346 + 207 + + + + Select source + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + +