#include "dialog_upgradefirmware.h" #include "ui_dialog_upgradefirmware.h" #include #include #include #include "base/HGBase.h" Dialog_upgradeFirmware::Dialog_upgradeFirmware(SANE_Handle handle, const std::string &filePath, QWidget *parent) : QDialog(parent) , m_handle(handle) , m_filePath(filePath) , m_result(1) , ui(new Ui::Dialog_upgradeFirmware) { ui->setupUi(this); setWindowTitle(tr("upgrade")); setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint); ui->label_text->setText(tr("firmware upgrade in progress, please wait...")); QMovie *movie = new QMovie(":images/image_rsc/logo/waiting.gif"); ui->label_gif->setMovie(movie); movie->setCacheMode(QMovie::CacheAll); movie->setScaledSize(QSize(ui->label_gif->width(), ui->label_gif->height())); movie->start(); ui->label_gif->show(); connect(this, SIGNAL(finish()), this, SLOT(on_finish()), Qt::QueuedConnection); HGBase_OpenThread(ThreadFunc, this, &m_thread); } Dialog_upgradeFirmware::~Dialog_upgradeFirmware() { if (nullptr != m_thread) { HGBase_CloseThread(m_thread); m_thread = nullptr; } delete ui; } void HGAPI Dialog_upgradeFirmware::ThreadFunc(HGThread thread, HGPointer param) { (void)thread; Dialog_upgradeFirmware *p = (Dialog_upgradeFirmware *)param; SANE_Status ret = sane_io_control(p->m_handle, IO_CTRL_CODE_SET_FIRMWARE_UPGRADE, (void*)p->m_filePath.c_str(), nullptr); if (SANE_STATUS_GOOD == ret) { p->m_result = 0; } else { p->m_result = ret; } emit p->finish(); } int Dialog_upgradeFirmware::getUpgradeStatus() { return m_result; } void Dialog_upgradeFirmware::on_finish() { accept(); }