code_production/app/HGProductionTool/mainwindow.cpp

231 lines
5.5 KiB
C++
Raw Normal View History

2022-12-14 06:39:22 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QVBoxLayout>
#include "base/HGBase.h"
#include "HGUIGlobal.h"
#include "dialog_login.h"
#include "dialog_changepwd.h"
#include "dialog_accountmanage.h"
2022-12-14 12:28:25 +00:00
#include "dialog_uploadcfgfile.h"
2022-12-14 06:39:22 +00:00
MainWindow::MainWindow(HGPdtToolDbUserMgr userMgr, QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, m_pdtToolDbuserMgr(userMgr)
, m_form_mainInterface(nullptr)
, m_top_splitter(nullptr)
, m_bot_splitter(nullptr)
, m_splitterCount(1)
, m_isLogOut(false)
{
ui->setupUi(this);
setWindowIcon(QIcon(":image/image_rsc/logo/logo.ico"));
HGUInt userType = 0;
HGPdtToolDb_GetUserType(m_pdtToolDbuserMgr, &userType);
if (userType == HGPDTTOOLDB_USERTYPE_NORMAL)
ui->act_manage->setVisible(false);
HGChar userName[128];
HGPdtToolDb_GetUserName(m_pdtToolDbuserMgr, userName, 128);
setWindowTitle(userName);
m_top_splitter = new QSplitter(Qt::Horizontal);
m_bot_splitter = new QSplitter(Qt::Horizontal);
m_form_mainInterface = new Form_mainInterface();
m_top_splitter->addWidget(m_form_mainInterface);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(m_top_splitter);
vLayout->addWidget(m_bot_splitter);
vLayout->setStretch(0, 1);
vLayout->setStretch(1, 0);
this->centralWidget()->setLayout(vLayout);
}
MainWindow::~MainWindow()
{
HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
m_pdtToolDbuserMgr = NULL;
delete ui;
}
bool MainWindow::isExitApp()
{
return !m_isLogOut;
}
2022-12-15 03:00:46 +00:00
std::vector<std::string> MainWindow::get_devices()
{
std::vector<std::string> name;
const SANE_Device** devs_list;
SANE_Status status = SANE_STATUS_GOOD;
if ((status = sane_get_devices(&devs_list, SANE_TRUE)) != SANE_STATUS_GOOD)
{
name.push_back("");
return name;
}
name.clear();
while (*devs_list != NULL)
{
name.push_back((*devs_list)->name);
devs_list++;
}
return name;
}
int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
{
switch (code)
{
case SANE_EVENT_DEVICE_ARRIVED:
(SANE_Device*)data;
break;
case SANE_EVENT_DEVICE_LEFT:
(SANE_Device*)data;
break;
case SANE_EVENT_WORKING:
(char*)data;
break;
case SANE_EVENT_SCAN_FINISHED:
(char*)data;
break;
case SANE_EVENT_STATUS:
(char*)data;
break;
case SANE_EVENT_ERROR:
(char*)data;
break;
case SANE_EVENT_IMAGE_OK:
SANE_Image* sane_img = (SANE_Image*)data;
break;
}
// sane_ex_callback1(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
return 0;
}
void MainWindow::test()
{
SANE_Status status = SANE_STATUS_GOOD;
SANE_Int version_code = 0;
status = sane_init_ex(&version_code, sane_ex_callback, NULL);
Sleep(2000);
const SANE_Device** device_list;
//status = sane_get_devices(&device_list, SANE_TRUE);
std::vector<std::string> name = get_devices();
SANE_Handle devHandle = NULL;
// SANE_String_Const n = name[0].c_str();
int len = name[0].size();
char* buf = new char[len];
strcpy(buf, name[0].c_str());
sane_open(buf, &devHandle);
ui_helper* helper = new ui_helper(devHandle);
// sane_ex_callback1();
func_test_go(L"test-35", L"null", helper);
}
2022-12-14 06:39:22 +00:00
void MainWindow::on_act_newDevice_triggered()
{
m_splitterCount++;
switch (m_splitterCount)
{
case 2:
{
Form_mainInterface *form_mainInterface = new Form_mainInterface();
m_top_splitter->addWidget(form_mainInterface);
break;
}
case 3:
{
Form_mainInterface *form_mainInterface = new Form_mainInterface();
m_bot_splitter->addWidget(form_mainInterface);
reinterpret_cast<QVBoxLayout*>(this->centralWidget()->layout())->setStretch(1, 1);
break;
}
case 4:
{
Form_mainInterface *form_mainInterface = new Form_mainInterface();
m_bot_splitter->addWidget(form_mainInterface);
break;
}
case 5:
QMessageBox::information(this, tr("tips"), tr("cannot create more table"));
return;
break;
default:
break;
}
}
void MainWindow::on_act_manage_triggered()
{
Dialog_accountManage dlg(m_pdtToolDbuserMgr, this);
dlg.exec();
}
void MainWindow::on_act_changePwd_triggered()
{
Dialog_changePwd dlg(m_pdtToolDbuserMgr, this);
dlg.exec();
}
void MainWindow::on_act_export_triggered()
{
HGChar cfgPath[256]= {0};
HGBase_GetConfigPath(cfgPath, 256);
strcat(cfgPath, "1.xls");
HGPdtToolDb_Export(m_pdtToolDbuserMgr, getStdString(cfgPath).c_str());
}
void MainWindow::on_act_logOut_triggered()
{
HGPdtToolDb_DestroyUserMgr(m_pdtToolDbuserMgr);
m_isLogOut = true;
close();
}
void MainWindow::on_act_close_triggered()
{
close();
}
QString MainWindow::getLogInfo(HGResult ret)
{
QString str;
if (HGPDTTOOLDB_ERR_INVALID_USER == ret)
{
str = tr("Illegal user");
}
else if (HGPDTTOOLDB_ERR_WRONG_PASSWORD == ret)
{
str = tr("Wrong password");
}
else if (HGPDTTOOLDB_ERR_DATABASE == ret)
{
str = tr("Database error");
}
else if (HGPDTTOOLDB_ERR_CONNECT == ret)
{
str = tr("connect error");
}
else
{
str = tr("Failed");
}
return str;
}
2022-12-14 12:28:25 +00:00
void MainWindow::on_act_upload_triggered()
{
Dialog_uploadCfgFile dlg(m_pdtToolDbuserMgr, this);
dlg.exec();
}