增加HGLibTest工程,主要功能为基于sane的热拔插事件测试SDK

This commit is contained in:
yangjiaxuan 2024-04-07 18:11:14 +08:00
parent d702c8e2b7
commit 2bf3448df0
6 changed files with 389 additions and 0 deletions

12
app/libtest/main.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

131
app/libtest/mainwindow.cpp Normal file
View File

@ -0,0 +1,131 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDateTime>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_device(nullptr)
{
ui->setupUi(this);
ui->label_devInfo->clear();
ui->pushButton_scan->setEnabled(false);
connect(this, SIGNAL(sane_dev_arrive(QString)), this, SLOT(on_sane_dev_arrive(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(sane_dev_remove(QString)), this, SLOT(on_sane_dev_remove(QString)), Qt::QueuedConnection);
HGLib_InitDevice(DeviceHotPlugEventFunc, this);
}
MainWindow::~MainWindow()
{
HGLib_DeinitDevice();
delete ui;
}
void MainWindow::DeviceHotPlugEventFunc(HGUInt event, const HGChar *deviceName, HGPointer param)
{
MainWindow* p = (MainWindow*)param;
if (HGLIB_DEVHOTPLUG_EVENT_ARRIVE == event)
{
emit p->sane_dev_arrive(deviceName);
}
else if (HGLIB_DEVHOTPLUG_EVENT_REMOVE == event)
{
emit p->sane_dev_remove(deviceName);
}
}
void MainWindow::DeviceScanEventFunc(HGLibDevice device, HGUInt event, HGInt operateCode, const HGChar *info, HGPointer param)
{
MainWindow *p = (MainWindow*)param;
p->addContent(info);
}
void MainWindow::DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param)
{
}
void MainWindow::on_sane_dev_arrive(QString devName)
{
int idx = -1;
int count = ui->comboDevList->count();
for (int i = 0; i < count; ++i)
{
QString name = ui->comboDevList->itemText(i);
if (name == devName)
{
idx = i;
break;
}
}
if (-1 == idx)
{
ui->comboDevList->addItem(devName);
}
}
void MainWindow::on_sane_dev_remove(QString devName)
{
int idx = -1;
int count = ui->comboDevList->count();
for (int i = 0; i < count; ++i)
{
QString name = ui->comboDevList->itemText(i);
if (name == devName)
{
idx = i;
break;
}
}
if (-1 != idx)
{
QString info = tr("The device %1 is disconnected.").arg(devName);
ui->label_devInfo->setText(info);
addContent(info);
ui->comboDevList->removeItem(idx);
}
}
void MainWindow::on_comboDevList_currentIndexChanged(int index)
{
if (-1 != index)
{
if (m_device != nullptr)
{
HGLib_CloseDevice(m_device);
ui->label_devInfo->clear();
ui->pushButton_scan->setEnabled(false);
}
QString name = ui->comboDevList->itemText(index);
m_device = HGLib_OpenDevice(name.toStdString().c_str());
if (m_device != nullptr)
{
QString info = tr("The device %1 is open.").arg(name);
ui->label_devInfo->setText(info);
addContent(info);
ui->pushButton_scan->setEnabled(true);
}
else
{
QString info = tr("The device %1 open failed.").arg(name);
addContent(info);
}
}
}
void MainWindow::on_pushButton_scan_clicked()
{
HGLib_StartDeviceScan(m_device, DeviceScanEventFunc, this, DeviceScanImageFunc, this);
}
void MainWindow::addContent(QString content)
{
ui->textBrowser->insertPlainText(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm] ") + content + "\n");
ui->textBrowser->moveCursor(QTextCursor::End);
ui->textBrowser->setTextColor(Qt::black);
}

45
app/libtest/mainwindow.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "HGScannerLib.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
static void HGAPI DeviceHotPlugEventFunc(HGUInt event, const HGChar *deviceName, HGPointer param);
static void HGAPI DeviceScanEventFunc(HGLibDevice device, HGUInt event, HGInt operateCode, const HGChar *info, HGPointer param);
static void HGAPI DeviceScanImageFunc(HGLibDevice device, HGLibImage image, HGPointer param);
signals:
void sane_dev_arrive(QString devName);
void sane_dev_remove(QString devName);
private slots:
void on_sane_dev_arrive(QString devName);
void on_sane_dev_remove(QString devName);
private slots:
void on_comboDevList_currentIndexChanged(int index);
void on_pushButton_scan_clicked();
private:
void addContent(QString content);
private:
Ui::MainWindow *ui;
HGLibDevice m_device;
};
#endif // MAINWINDOW_H

96
app/libtest/mainwindow.ui Normal file
View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>706</width>
<height>506</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QComboBox" name="comboDevList">
<property name="geometry">
<rect>
<x>150</x>
<y>40</y>
<width>221</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>60</x>
<y>40</y>
<width>81</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Device List:</string>
</property>
</widget>
<widget class="QLabel" name="label_devInfo">
<property name="geometry">
<rect>
<x>60</x>
<y>100</y>
<width>321</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_scan">
<property name="geometry">
<rect>
<x>150</x>
<y>240</y>
<width>111</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>Scan</string>
</property>
</widget>
<widget class="QTextBrowser" name="textBrowser">
<property name="geometry">
<rect>
<x>390</x>
<y>40</y>
<width>256</width>
<height>371</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>706</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="act_selectDevice">
<property name="text">
<string>act_selectDevice</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,104 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
DEFINES += UNTITLED_LIBRARY
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_NO_VERSION_TAGGING
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
include($$PWD/../HGOEM.pri)
CONFIG(debug, debug|release) {
MY_CONFIGURE = Debug
}
CONFIG(release, debug|release) {
MY_CONFIGURE = Release
}
win32 {
MY_OS = windows
TARGET = $${OEM_PREFIX}LibTestApp
contains(QT_ARCH, i386) {
MY_ARCH = x86
}
contains(QT_ARCH, x86_64) {
MY_ARCH = x64
}
CONFIG(release, debug|release) {
QMAKE_LFLAGS_RELEASE += /MAP
QMAKE_CFLAGS_RELEASE += /Zi
QMAKE_LFLAGS_RELEASE += /debug /opt:ref
}
LIBS += -lgdi32 -lgdiplus -ldbghelp -luser32 -ladvapi32
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX}ScannerLib
LIBS += -L$$PWD/../../../../release/win/$${MY_ARCH}/OEM/$${OEM_NAME}
}
INCLUDEPATH += $$PWD/../../../sdk/scannerlib
INCLUDEPATH += $$PWD/../../../modules/base
DESTDIR = $$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}
UI_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET}
MOC_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET}
OBJECTS_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET}
RCC_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET}
message(MY_OS: $$MY_OS)
message(MY_ARCH: $$MY_ARCH)
message(OEM_PREFIX: $$OEM_PREFIX)
message(OEM_PREFIX2: $$OEM_PREFIX2)
message(OEM_NAME: $$OEM_NAME)
message(MY_CONFIGURE: $$MY_CONFIGURE)
message(TARGET: $$TARGET)
message(DESTDIR: $$DESTDIR)
message(UI_DIR: $$UI_DIR)
message(MOC_DIR: $$MOC_DIR)
message(OBJECTS_DIR: $$OBJECTS_DIR)
message(RCC_DIR: $$RCC_DIR)
win32 {
CONFIG(release, debug|release) {
DESTEXE_PATH = $${PWD}/../../../../release/win/$${MY_ARCH}/$${MY_CONFIGURE}/
DESTEXE_PATH = $$replace(DESTEXE_PATH, /, \\)
message(DESTEXE_PATH: $$DESTEXE_PATH)
SRCEXE_FILE = $${DESTDIR}/$${TARGET}.exe
SRCEXE_FILE = $$replace(SRCEXE_FILE, /, \\)
message(SRCEXE_FILE: $$SRCEXE_FILE)
SRCPDB_FILE = $${DESTDIR}/$${TARGET}.pdb
SRCPDB_FILE = $$replace(SRCPDB_FILE, /, \\)
message(SRCPDB_FILE: $$SRCPDB_FILE)
QMAKE_POST_LINK += xcopy /y $$SRCEXE_FILE $$DESTEXE_PATH && xcopy /y $$SRCPDB_FILE $$DESTEXE_PATH
}
}
SOURCES += \
../../../app/libtest/main.cpp \
../../../app/libtest/mainwindow.cpp \
HEADERS += \
../../../app/libtest/mainwindow.h \
FORMS += \
../../../app/libtest/mainwindow.ui

View File

@ -7,6 +7,7 @@ SUBDIRS += \
HGTwainUI \
HGTwainUser \
HGTwainTest \
HGLibTest \
HGVersion \
HGScannerLib \
HGWebService \