diff --git a/modules/base/HGIni.cpp b/modules/base/HGIni.cpp index 23206eb3..5cc8875e 100644 --- a/modules/base/HGIni.cpp +++ b/modules/base/HGIni.cpp @@ -1,4 +1,4 @@ -#include "HGIni.h" +#include "HGIni.h" #include "HGInc.h" #include "HGInfo.h" #include @@ -21,8 +21,8 @@ static HGResult LoadIni(const char* file, SectionList& sectList) while (feof(fp) == 0) { - char lineContent[256] = { 0 }; - if (NULL == fgets(lineContent, 256, fp)) + char lineContent[2048] = { 0 }; + if (NULL == fgets(lineContent, 2048, fp)) { continue; } diff --git a/modules/twainui/TwainUI_zh_CN.qm b/modules/twainui/TwainUI_zh_CN.qm index 10d1ed9f..25be1357 100644 Binary files a/modules/twainui/TwainUI_zh_CN.qm and b/modules/twainui/TwainUI_zh_CN.qm differ diff --git a/modules/twainui/TwainUI_zh_CN.ts b/modules/twainui/TwainUI_zh_CN.ts index 987867bd..d5f0e9fa 100644 --- a/modules/twainui/TwainUI_zh_CN.ts +++ b/modules/twainui/TwainUI_zh_CN.ts @@ -2821,7 +2821,7 @@ Are you sure to close? 删除配置 - + existing configuration scheme 现有配置方案: @@ -2842,143 +2842,144 @@ Are you sure to close? 删除所有配置 - confgiuration information: - 配置信息: + 配置信息: - + about... 关于... - + scan 扫描 - - + + ok 确定 - + cancel 取消 - + configuration scheme management 配置方案管理 - + regional crop 区域裁剪 - + custom tone curve 自定义色调曲线 - - - - - - - - + + + + + + + + + Prompt 提示 - - - - - - - + + + + + + + The funtion is unsupported 此版本不支持该功能 - + + This function may cause a decrease in the speed of drawing. 此功能可能会导致出图速度降低. - + about 关于 - - - - - - + + + + + + Not supported 不支持 - + <p>Device model: %1</p> <p>设备型号: %1</p> - + <p>Driver version: %1</p> <p>驱动版本号: %1</p> - + <p>Firmware number: %1</p> <p>设备固件版本号: %1</p> - + <p>Serial number: %1</p> <p>设备序列号: %1</p> - - - + + + <p>Roller count: %1</p> <p>设备滚轴计数: %1</p> - + <p>History count: %1</p> <p>设备历史扫描张数: %1</p> - + Please select to overwrite the original configuration: 请选择覆盖原来的配置: - + ,or add a new configuration ,或者新增配置 - + save the configuration 保存配置 - + Add new scheme 新增配置 - + The configuration scheme already exists 配置方案已存在 @@ -3012,80 +3013,85 @@ No: add new configuration - + <h6><b> <h6><b> - + cover original configuration: 覆盖原来配置: - - + + Default scheme 默认配置 - + Add new - 新增 + 新增方案 - + + Save + 保存 + + + Delete - 删除 + 删除当前方案 - + Delete all 全部删除 - + add new configuration 新增配置 - + rename: 更名: - - - + + + tips 提示 - + scheme name cannot be empty 配置名不能为空 - + scheme name: 配置名: - + already exists 已存在 - + :</b></h6> :</b></h6> - + <p> <p> - + </p> </p> @@ -3094,18 +3100,18 @@ No: add new configuration 配置改名 - - + + be sure to delete the configuration 确认删除配置 - + Are you sure you want to delete the configuration " 您确认要删除配置 - + " ? @@ -3118,7 +3124,7 @@ No: add new configuration ’ 吗? - + Are you sure you want to delete the configuration? 您确认要删除所有配置吗? diff --git a/modules/twainui/TwainUI_zh_EN.qm b/modules/twainui/TwainUI_zh_EN.qm index 652cd26a..348df823 100644 Binary files a/modules/twainui/TwainUI_zh_EN.qm and b/modules/twainui/TwainUI_zh_EN.qm differ diff --git a/modules/twainui/TwainUI_zh_EN.ts b/modules/twainui/TwainUI_zh_EN.ts index 3ec3954b..53f51381 100644 --- a/modules/twainui/TwainUI_zh_EN.ts +++ b/modules/twainui/TwainUI_zh_EN.ts @@ -2480,7 +2480,7 @@ Please go to “Scan to” and change the accessible scan folder and then perfor hg_settingdialog - + existing configuration scheme Existing configuration plan: @@ -2501,221 +2501,227 @@ Please go to “Scan to” and change the accessible scan folder and then perfor Delete all configurations - - + + Default scheme Default scheme - + Add new Add new - + + Save + Save + + + Delete Delete - + Delete all Delete all - confgiuration information: - Configuration information: + Configuration information: - + about... About... - + scan Scan - - + + ok OK - + cancel Cancel - + configuration scheme management Configuration plan management - + regional crop Regional crop - + custom tone curve Custom tone curve - - - - - - - - + + + + + + + + + Prompt Prompt - - - - - - - + + + + + + + The funtion is unsupported This version does not support this feature. - + + This function may cause a decrease in the speed of drawing. This function may cause a decrease in the speed of drawing. - + about About - - - - - - + + + + + + Not supported Not supported - + <p>Device model: %1</p> <p>Device model: %1</p> - + <p>Driver version: %1</p> <p>Driver version: %1</p> - + <p>Firmware number: %1</p> <p>Firmware number: %1</p> - + <p>Serial number: %1</p> <p>Serial number: %1</p> - - - + + + <p>Roller count: %1</p> <p>Roller count: %1</p> - + <p>History count: %1</p> <p>History count: %1</p> - + Please select to overwrite the original configuration: Please select overwrite original configuration: - + ,or add a new configuration , or add new configuration - + save the configuration Save configuration - + cover original configuration: Overwrite original configuration: - + add new configuration Add new configuration - + rename: Rename: - - - + + + tips Prompt - + scheme name cannot be empty Configuration name cannot be blank - + scheme name: Configuration name: - + already exists already exists - + <h6><b> <h6><b> - + :</b></h6> :</b></h6> - + <p> <p> - + </p> </p> - + Add new scheme Add new scheme - + The configuration scheme already exists The configuration scheme already exists @@ -2724,18 +2730,18 @@ Please go to “Scan to” and change the accessible scan folder and then perfor Rename configuration - - + + be sure to delete the configuration Delete configuration - + Are you sure you want to delete the configuration " Are you sure you want to delete configuration - + " ? ? @@ -2748,7 +2754,7 @@ Please go to “Scan to” and change the accessible scan folder and then perfor No - + Are you sure you want to delete the configuration? Are you sure you want to delete all configurations? diff --git a/modules/twainui/app_cfg.cpp b/modules/twainui/app_cfg.cpp index 46935a42..6e97a280 100644 --- a/modules/twainui/app_cfg.cpp +++ b/modules/twainui/app_cfg.cpp @@ -1,11 +1,71 @@ #include "app_cfg.h" -#include "base/HGDef.h" #include "base/HGInc.h" #include "base/HGUtility.h" #include "base/HGIni.h" #include "HGUIGlobal.h" #include "HGString.h" +#include + +bool removeSection(const HGChar* appName) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + strcat(cfgPath, "default.ini"); + HGResult ret = HGBase_RemoveProfileSection(cfgPath, appName); + + if (ret == HGBASE_ERR_OK) + return true; + + return false; +} + +bool searchKeyName(const HGChar* appName, const HGChar* key) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + strcat(cfgPath, "default.ini"); + + HGResult ret = HGBase_SearchProfileConfig(cfgPath, appName, key); + if (ret == HGBASE_ERR_OK) + return true; + + return false; +} + +QString getDefaultCfgValue(const char* appName, const char* key, const QString& def) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + strcat(cfgPath, "default.ini"); + + HGChar value[2048] = { 0 }; + HGBase_GetProfileString(cfgPath, appName, key, getStdString(def).c_str(), value, 2048); + return StdStringToUtf8(value).c_str(); +} + +int getDefaultCfgValue(const char* appName, const char* key, int def) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + strcat(cfgPath, "default.ini"); + + HGInt value = 0; + HGBase_GetProfileInt(cfgPath, appName, key, def, &value); + return value; +} + +bool getDefaultCfgValue(const char* appName, const char* key, bool def) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + strcat(cfgPath, "default.ini"); + + HGInt value = 0; + HGBase_GetProfileInt(cfgPath, appName, key, (HGInt)def, &value); + return (bool)value; +} + QString getCfgValue(const char *appName, const char *key, const QString &def) { HGChar cfgPath[512]; @@ -39,6 +99,46 @@ bool getCfgValue(const char *appName, const char *key, bool def) return (bool)value; } +void saveDefaultCfgValue(const char* appName, const char* key, const QString& value) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "default.ini"); + + HGBase_SetProfileString(cfgPath, appName, key, getStdString(value).c_str()); +} + +void saveDefaultCfgValue(const char* appName, const char* key, int value) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "default.ini"); + + HGBase_SetProfileInt(cfgPath, appName, key, value); +} + +void saveDefaultCfgValue(const char* appName, const char* key, float value) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "default.ini"); + + HGBase_SetProfileInt(cfgPath, appName, key, value); +} + +void saveDefaultCfgValue(const char* appName, const char* key, bool value) +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "default.ini"); + + HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value); +} + void saveCfgValue(const char *appName, const char *key, const QString &value) { HGChar cfgPath[512]; @@ -68,3 +168,51 @@ void saveCfgValue(const char *appName, const char *key, bool value) HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value); } + +HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen) +{ + if (NULL == configPath || 0 == maxLen) + { + return HGBASE_ERR_INVALIDARG; + } + + const char* appName = "HuaGoScan"; +#if defined(OEM_HANWANG) + appName = "HanvonScan"; +#elif defined(OEM_LISICHENG) + appName = "LanxumScan"; +#elif defined(OEM_CANGTIAN) + appName = "CumtennScan"; +#elif defined(OEM_ZHONGJING) + appName = "MicrotekScan"; +#elif defined(OEM_ZIGUANG) + appName = "UniScan"; +#endif + +#if defined(HG_CMP_MSC) + CHAR cfgPath[MAX_PATH] = { 0 }; + BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE); + if (!ret) + return HGBASE_ERR_FAIL; + if (cfgPath[strlen(cfgPath) - 1] != '\\') + strcat(cfgPath, "\\"); + + strcat(cfgPath, appName); + strcat(cfgPath, "\\Cfg\\"); +#else + char cfgPath[512] = { 0 }; + struct passwd* pw = getpwuid(getuid()); + strcpy(cfgPath, pw->pw_dir); + if (cfgPath[strlen(cfgPath) - 1] != '/') + strcat(cfgPath, "/"); + + strcat(cfgPath, "."); + strcat(cfgPath, appName); + strcat(cfgPath, "/Cfg/"); +#endif + + if (maxLen < strlen(cfgPath) + 1) + return HGBASE_ERR_FAIL; + strcpy(configPath, cfgPath); + return HGBASE_ERR_OK; +} diff --git a/modules/twainui/app_cfg.h b/modules/twainui/app_cfg.h index 0b5d1228..df377c33 100644 --- a/modules/twainui/app_cfg.h +++ b/modules/twainui/app_cfg.h @@ -1,14 +1,27 @@ -#ifndef __APP_CFG_H__ +#ifndef __APP_CFG_H__ #define __APP_CFG_H__ #include +#include "base/HGDef.h" + +bool removeSection(const HGChar* appName); +bool searchKeyName(const HGChar* appName, const HGChar* key); + +QString getDefaultCfgValue(const char* appName, const char* key, const QString& def); +int getDefaultCfgValue(const char* appName, const char* key, int def); +bool getDefaultCfgValue(const char* appName, const char* key, bool def); QString getCfgValue(const char *appName, const char *key, const QString &def); int getCfgValue(const char *appName, const char *key, int def); bool getCfgValue(const char *appName, const char *key, bool def); +void saveDefaultCfgValue(const char* appName, const char* key, const QString& value); +void saveDefaultCfgValue(const char* appName, const char* key, int value); +void saveDefaultCfgValue(const char* appName, const char* key, bool value); + void saveCfgValue(const char *appName, const char *key, const QString &value); void saveCfgValue(const char *appName, const char *key, int value); void saveCfgValue(const char *appName, const char *key, bool value); +HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen); #endif /* __APP_CFG_H__ */ diff --git a/modules/twainui/hg_settingdialog.cpp b/modules/twainui/hg_settingdialog.cpp index cf445948..f48b1f8a 100644 --- a/modules/twainui/hg_settingdialog.cpp +++ b/modules/twainui/hg_settingdialog.cpp @@ -13,6 +13,8 @@ #include #include "device_menu.h" #include "dialog_device_scan.h" +#include "app_cfg.h" +#include "base/HGBase64.h" hg_settingdialog * hg_settingdialog::hg_setting_ui_ =NULL; std::string hg_settingdialog::property_combox_data_type_ = "combox_value_type"; @@ -46,6 +48,7 @@ hg_settingdialog::hg_settingdialog(SANE_Handle handle, const SANEAPI* saneApi, b setAttribute(Qt::WA_DeleteOnClose, true); setIcon(); + m_scheme = new gb::sane_config_schm(); HGChar cfgpath[512] = {0}; GetConfigPath(cfgpath, 512); @@ -111,7 +114,16 @@ hg_settingdialog::hg_settingdialog(SANE_Handle handle, const SANEAPI* saneApi, b initUi(); on_current_scheme_changed(); - //getAppVersion(); + + saveDefaultCfgValue("deviceName", "name", QString::fromStdString(m_devName)); + + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + QString oldFile = QString::fromStdString(cfgPath) + "default.ini"; + QString newFile = QString::fromStdString(cfgPath) + "olddefault.ini"; + QFile::copy(oldFile, newFile); + + comb_->setCurrentIndex(getDefaultCfgValue("current", "index", 0)); } hg_settingdialog::~hg_settingdialog() @@ -297,32 +309,41 @@ void hg_settingdialog::create_scheme_management_ui(QVBoxLayout* layout) layout->addSpacing(10); - del_this_ = new QPushButton(this); - del_this_->setText(tr("Delete")); - del_this_->setEnabled(enabled); - del_this_->setFixedWidth(width / 2); - layout->addWidget(del_this_); - connect(del_this_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management())); + m_pbtn_Save = new QPushButton(this); + m_pbtn_Save->setText(tr("Save")); + m_pbtn_Save->setFixedWidth(width / 2); + layout->addWidget(m_pbtn_Save); + connect(m_pbtn_Save, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management())); layout->addSpacing(10); - del_all_ = new QPushButton(this); - del_all_->setText(tr("Delete all")); - del_all_->setEnabled(enabled); - del_all_->setFixedWidth(width / 2); - layout->addWidget(del_all_); - connect(del_all_, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management())); + m_deleteCur = new QPushButton(this); + m_deleteCur->setText(tr("Delete")); + m_deleteCur->setEnabled(enabled); + m_deleteCur->setFixedWidth(width / 2); + layout->addWidget(m_deleteCur); + connect(m_deleteCur, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management())); + + layout->addSpacing(10); + + m_deleteAll = new QPushButton(this); + m_deleteAll->setText(tr("Delete all")); + m_deleteAll->setEnabled(enabled); + m_deleteAll->setFixedWidth(width / 2); + layout->addWidget(m_deleteAll); + connect(m_deleteAll, SIGNAL(clicked(bool)), this, SLOT(slot_pushButton_scheme_management())); layout->addStretch(); - title = new QLabel(this); - title->setText(tr("confgiuration information:")); - layout->addWidget(title); + //title = new QLabel(this); + //title->setText(tr("confgiuration information:")); + //layout->addWidget(title); - sketch_ = new QTextEdit(this); - sketch_->setReadOnly(true); - sketch_->setFixedSize(width, 200); - layout->addWidget(sketch_); +// sketch_ = new QTextEdit(this); +// sketch_->setReadOnly(true); +// sketch_->setFixedSize(width, 200); +// sketch_->setVisible(false); + //layout->addWidget(sketch_); connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed())); //on_current_scheme_changed(); @@ -859,18 +880,19 @@ void hg_settingdialog::refresh_control_value(int op_id) else if(!slider) { slider = qobject_cast(ctrls[i]); - if(slider) - disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); +// if(slider) +// disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); } else if(!spin) { spin = qobject_cast(ctrls[i]); - if(spin) - disconnect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); +// if(spin) +// disconnect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); } } if (slider) { + disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); if (opt->constraint_type == SANE_CONSTRAINT_RANGE) slider->setRange(SANE_UNFIX(opt->constraint.range->min) * 100, SANE_UNFIX(opt->constraint.range->max) * 100); slider->setValue(val * 100); @@ -879,6 +901,7 @@ void hg_settingdialog::refresh_control_value(int op_id) if (spin) { + disconnect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); if (opt->constraint_type == SANE_CONSTRAINT_RANGE) spin->setRange(SANE_UNFIX(opt->constraint.range->min), SANE_UNFIX(opt->constraint.range->max)); spin->setValue(val); @@ -1034,10 +1057,16 @@ void hg_settingdialog::slot_checkedClicked() btn_gamma_->setEnabled(checkBoxcurrentState); cur_scheme_->config_changed(id, (char*)&checkBoxcurrentState, sizeof(checkBoxcurrentState)); - if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_RID_MORR) || 0 == strcmp(opt->name, SANE_STD_OPT_NAME_RID_GRID)) + if (checkBoxcurrentState && (0 == strcmp(opt->name, SANE_STD_OPT_NAME_RID_MORR) || 0 == strcmp(opt->name, SANE_STD_OPT_NAME_RID_GRID))) { QMessageBox::information(this, tr("Prompt"), tr("This function may cause a decrease in the speed of drawing.")); } + + if (0 == comb_->currentIndex()) + { + bool value = checkBoxcurrentState; + saveDefaultCfgValue("default", opt->name, value); + } } void hg_settingdialog::slot_string_list_comboBoxClicked() @@ -1117,6 +1146,12 @@ void hg_settingdialog::slot_string_list_comboBoxClicked() if (comboBox->currentText() == OPTION_VALUE_WGFX_ZDWBFXSB) QMessageBox::information(this, tr("Prompt"), tr("This function may cause a decrease in the speed of drawing.")); } + + if (0 == comb_->currentIndex()) + { + QString value = QString::fromStdString(comboBoxcurrentItem); + saveDefaultCfgValue("default", opt->name, value); + } } void hg_settingdialog::slot_pushButtonClicked() @@ -1178,6 +1213,11 @@ void hg_settingdialog::slot_cutButtonClicked() value = SANE_FIX(m_cutBottomValue); m_saneAPI.sane_control_option_api(m_devHandle, m_cutBottomId, SANE_ACTION_SET_VALUE, &value, &info); cur_scheme_->config_changed(m_cutBottomId, (char*)&value, sizeof(value)); + + saveDefaultCfgValue("default", "cutLeftvalue", QString::number(m_cutLeftValue)); + saveDefaultCfgValue("default", "cutTopValue", QString::number(m_cutTopValue)); + saveDefaultCfgValue("default", "cutRightvalue", QString::number(m_cutRightValue)); + saveDefaultCfgValue("default", "cutBottomvalue", QString::number(m_cutBottomValue)); } } @@ -1339,6 +1379,16 @@ void hg_settingdialog::slot_gammaButtonClicked() dev_que::set_custom_gamma(&m_saneAPI, m_devHandle, &m_gammaData); cur_scheme_->config_changed(SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA, (char*)&m_gammaData, sizeof(m_gammaData), true); + + HGSize length = 0; + HGBase_Base64Encode((const HGByte*)&m_gammaData, sizeof(m_gammaData), NULL, &length); + HGByte* base64Str = new HGByte[length + 1]; + HGBase_Base64Encode((const HGByte*)&m_gammaData, sizeof(m_gammaData), base64Str, &length); + base64Str[length] = 0; + + QString value = QString::fromStdString((char*)base64Str); + saveDefaultCfgValue("default", "gamma", value); + delete[] base64Str; } } @@ -1383,6 +1433,9 @@ void hg_settingdialog::slot_word_list_comboBoxClicked(int value) comboBox->setCurrentText(QString::fromStdString(buf)); } cur_scheme_->config_changed(id, (char*)&temp, sizeof(temp)); + + if (0 == comb_->currentIndex()) + saveDefaultCfgValue("default", opt->name, comboBox->currentText()); } void hg_settingdialog::slot_sliderClicked(int value) @@ -1392,11 +1445,21 @@ void hg_settingdialog::slot_sliderClicked(int value) QAbstractSpinBox* spin = nullptr; for(int i = 0; i < m_list_sliderSpinbox.size(); i++) - if (m_list_sliderSpinbox.at(i).first == slider) + if (m_list_sliderSpinbox.at(i).first == slider) + { + spin = reinterpret_cast(m_list_sliderSpinbox.at(i).second); + break; + } + + const SANE_Option_Descriptor* opt = nullptr; + for (int i = 0; i < m_list_getOpt.size(); i++) + { + if (m_list_getOpt.at(i).first == id) { - spin = reinterpret_cast(m_list_sliderSpinbox.at(i).second); + opt = reinterpret_cast(m_list_getOpt.at(i).second); break; } + } if (spin != nullptr) { @@ -1407,7 +1470,8 @@ void hg_settingdialog::slot_sliderClicked(int value) QSpinBox* spin_ = reinterpret_cast(spin); spin_->setValue(value); -// //m_list_IdValueTitle.append(QPair, QString>(QPair(id, val), md5(opt->title))); + if (0 == comb_->currentIndex()) + saveDefaultCfgValue("default", opt->name, value); } else { @@ -1419,8 +1483,13 @@ void hg_settingdialog::slot_sliderClicked(int value) val = SANE_FIX(temp); db_val = true; - ////m_list_IdValueTitle.append(QPair, QString>(QPair(id, temp), md5(opt->title))); + if (0 == comb_->currentIndex()) + { + QString value2 = QString::number(temp); + saveDefaultCfgValue("default", opt->name, value2); + } } + SANE_Status ret = m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_SET_VALUE, &val, &method); if (ret == SANE_STATUS_UNSUPPORTED) { @@ -1451,11 +1520,22 @@ void hg_settingdialog::slot_sliderClicked(int value) double v = SANE_UNFIX(val); spin_->setValue(v); slider->setValue(spin_->value() / spin_->singleStep()); + if (0 == comb_->currentIndex()) + { + QString value2 = QString::number(v); + saveDefaultCfgValue("default", opt->name, value2); + } } - else { + else + { QSpinBox* spin_ = reinterpret_cast(spin); spin_->setValue(val); - slider->setValue(spin_->value() / spin_->singleStep()); + slider->setValue(spin_->value() / spin_->singleStep()); + if (0 == comb_->currentIndex()) + { + int value2 = val; + saveDefaultCfgValue("default", opt->name, value2); + } } } cur_scheme_->config_changed(id, (char*)&val, sizeof(val)); @@ -1491,6 +1571,14 @@ void hg_settingdialog::slot_spinBoxClicked(int value) int id = spinBox->property("controls_id").toInt(); const SANE_Option_Descriptor* opt = nullptr; + for (int i = 0; i < m_list_getOpt.size(); i++) + { + if (m_list_getOpt.at(i).first == id) + { + opt = reinterpret_cast(m_list_getOpt.at(i).second); + break; + } + } QAbstractSlider* slider = nullptr; for (int i = 0; i < m_list_sliderSpinbox.size(); i++) @@ -1524,7 +1612,14 @@ void hg_settingdialog::slot_spinBoxClicked(int value) connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); } cur_scheme_->config_changed(id, (char*)&temp, sizeof(temp)); - }else + + if (0 == comb_->currentIndex()) + { + int value2 = value; + saveDefaultCfgValue("default", opt->name, value2); + } + } + else { QSlider* slider_ = reinterpret_cast(slider); slider_->setValue(spinBox->value()); @@ -1683,15 +1778,14 @@ void hg_settingdialog::slot_buttonAboutClicked() void hg_settingdialog::slot_buttonScanClicked() { - save_scheme(); + //save_scheme(); m_closeButton = closeButtonScan; if (!quit_) m_callback(UI_RESULT_START_SCAN); } void hg_settingdialog::slot_buttonOkClicked() -{ - save_ = true; +{ m_closeButton = closeButtonOk; close(); } @@ -1727,54 +1821,6 @@ gb::sane_config_schm *hg_settingdialog::getCurScheme() return cur_scheme_; } -HGResult hg_settingdialog::GetConfigPath(HGChar* configPath, HGUInt maxLen) -{ - if (NULL == configPath || 0 == maxLen) - { - return HGBASE_ERR_INVALIDARG; - } - - const char *appName = "HuaGoScan"; -#if defined(OEM_HANWANG) - appName = "HanvonScan"; -#elif defined(OEM_LISICHENG) - appName = "LanxumScan"; -#elif defined(OEM_CANGTIAN) - appName = "CumtennScan"; -#elif defined(OEM_ZHONGJING) - appName = "MicrotekScan"; -#elif defined(OEM_ZIGUANG) - appName = "UniScan"; -#endif - -#if defined(HG_CMP_MSC) - CHAR cfgPath[MAX_PATH] = { 0 }; - BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE); - if (!ret) - return HGBASE_ERR_FAIL; - if (cfgPath[strlen(cfgPath) - 1] != '\\') - strcat(cfgPath, "\\"); - - strcat(cfgPath, appName); - strcat(cfgPath, "\\Cfg\\"); -#else - char cfgPath[512] = { 0 }; - struct passwd* pw = getpwuid(getuid()); - strcpy(cfgPath, pw->pw_dir); - if (cfgPath[strlen(cfgPath) - 1] != '/') - strcat(cfgPath, "/"); - - strcat(cfgPath, "."); - strcat(cfgPath, appName); - strcat(cfgPath, "/Cfg/"); -#endif - - if (maxLen < strlen(cfgPath) + 1) - return HGBASE_ERR_FAIL; - strcpy(configPath, cfgPath); - return HGBASE_ERR_OK; -} - //生成UTF-8编码的MD5值 QString hg_settingdialog::md5(QString key) { @@ -1815,12 +1861,25 @@ void hg_settingdialog::closeEvent(QCloseEvent* e) { if(e->type() == QEvent::Close) // consider as cancel ... { - if(save_) - save_scheme(); - else - cancel_setting(); + //if(save_) + // save_scheme(); + //else + // cancel_setting(); } + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + QString oldFile = QString::fromStdString(cfgPath) + "olddefault.ini"; + QString newFile = QString::fromStdString(cfgPath) + "default.ini"; + + QFile::remove(newFile); + QFile file(oldFile); + file.rename(newFile); + + int index = comb_->currentIndex(); + if (m_closeButton == closeButtonOk) + saveDefaultCfgValue("current", "index", index); + e->accept(); } @@ -1992,6 +2051,9 @@ std::string hg_settingdialog::getCurUiShemeName(std::string name) void hg_settingdialog::save_scheme(void) { + if (comb_->currentIndex() == 0) + return; + std::string name(cur_scheme_->get_scheme_name()); bool add = name.empty(); @@ -2041,13 +2103,14 @@ void hg_settingdialog::save_scheme(void) if(ind > 0) { name.erase(pos); - sprintf(append, "-%d", ++ind); +// sprintf(append, "-%d", ++ind); } } - while (!cur_cfg_->add_scheme(cur_scheme_, (name + append).c_str())) - { - sprintf(append, "-%d", ++ind); - } + cur_cfg_->add_scheme(cur_scheme_, (name + append).c_str()); +// while (!cur_cfg_->add_scheme(cur_scheme_, (name + append).c_str())) +// { +// sprintf(append, "-%d", ++ind); +// } } else { @@ -2091,6 +2154,226 @@ void hg_settingdialog::setIcon() this->setWindowIcon(QIcon(":logo/image_rsc/logo/uniscan.ico")); #endif } + +void hg_settingdialog::updateDefaultScheme() +{ + updateOpt(); + + SANE_Int dev_options = 0; + m_saneAPI.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); + for(int id = 1, optons = dev_options; id < optons; id++) + { + QVector ctrls = find_control(id); + + if(ctrls.empty()) + continue; + + const SANE_Option_Descriptor* opt = (const SANE_Option_Descriptor*)m_list_defaultOptions.at(id - 1).first; + if(opt->type == SANE_TYPE_BOOL) + { + for(size_t i = 0; i < (size_t)ctrls.size(); ++i) + { + QCheckBox* cb = qobject_cast(ctrls[i]); + if(cb) + { + //disconnect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked())); + + if (comb_->currentIndex() == 0) + { + if (searchKeyName("default", opt->name)) + { + cb->setCheckState(getDefaultCfgValue("default", opt->name, false) ? Qt::Checked : Qt::Unchecked); + } + } + //connect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked())); + break; + } + } + } + else if(opt->type == SANE_TYPE_INT) + { + for(size_t i = 0; i < (size_t)ctrls.size(); ++i) + { + QSlider* slider = qobject_cast(ctrls[i]); + if(slider) + { + //disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); + + if (comb_->currentIndex() == 0) + { + if (searchKeyName("default", opt->name)) + { + int value = getDefaultCfgValue("default", opt->name, 0); + slider->setValue(value); + } + } + //connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); + } + else + { + QSpinBox* spin = qobject_cast(ctrls[i]); + if(spin) + { + //disconnect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); + + if (comb_->currentIndex() == 0) + { + if (searchKeyName("default", opt->name)) + { + int value = getDefaultCfgValue("default", opt->name, 0); + spin->setValue(value); + } + } + //connect(spin, SIGNAL(valueChanged(int)), this, SLOT(slot_spinBoxClicked(int))); + } + } + } + } + else if(opt->type == SANE_TYPE_FIXED) + { + QSlider *slider = NULL; + QDoubleSpinBox* spin = NULL; + for(size_t i = 0; i < (size_t)ctrls.size(); ++i) + { + if (!slider) + { + slider = qobject_cast(ctrls[i]); + //if (slider) + //disconnect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); + } + else if (!spin) + { + spin = qobject_cast(ctrls[i]); + //if (spin) + //disconnect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); + } + } + if (slider) + { + if (comb_->currentIndex() == 0) + { + if (searchKeyName("default", opt->name)) + { + float value = getDefaultCfgValue("default", opt->name, QString("")).toFloat(); + slider->setValue(value * 100); + } + //connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slot_sliderClicked(int))); + } + + if (spin) + { + if (comb_->currentIndex() == 0) + { + if (searchKeyName("default", opt->name)) + { + float value = getDefaultCfgValue("default", opt->name, QString("")).toFloat(); + spin->setValue(value); + } + //connect(spin, SIGNAL(valueChanged(double)), this, SLOT(slot_spinBoxClicked(double))); + } + } + } + } + else if(opt->type == SANE_TYPE_STRING) + { + for(size_t i = 0; i < (size_t)ctrls.size(); ++i) + { + QComboBox* comb = qobject_cast(ctrls[i]); + if(comb) + { + //disconnect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked())); + + if (comb_->currentIndex() == 0) + { + if (searchKeyName("default", opt->name)) + { + QString value = getDefaultCfgValue("default", opt->name, QString("")); + comb->setCurrentText(value); + } + //connect(comb, SIGNAL(currentTextChanged(const QString)), this, SLOT(slot_string_list_comboBoxClicked())); + } + else + { + QLineEdit* edit = qobject_cast(ctrls[i]); + if(edit) + { + //disconnect(edit, SIGNAL(textChanged(const QString&)), this, SLOT(slot_lineEditInput())); + edit->setText(m_list_defaultOptions.at(id - 1).second.toString()); + //connect(edit, SIGNAL(textChanged(const QString&)), this, SLOT(slot_lineEditInput())); + } + } + } + } + } + if (comb_->currentIndex() == 0) + { + if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) && searchKeyName("default", "cutLeftvalue")) + { + double value = getDefaultCfgValue("default", "cutLeftvalue", QString("")).toDouble(); + m_cutLeftValue = value; + } + if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) && searchKeyName("default", "cutLeftvalue")) + { + double value = getDefaultCfgValue("default", "cutTopValue", QString("")).toDouble(); + m_cutTopValue = value; + } + if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT) && searchKeyName("default", "cutLeftvalue")) + { + double value = getDefaultCfgValue("default", "cutRightvalue", QString("")).toDouble(); + m_cutRightValue = value; + } + if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT) && searchKeyName("default", "cutLeftvalue")) + { + double value = getDefaultCfgValue("default", "cutBottomvalue", QString("")).toDouble(); + m_cutBottomValue = value; + } + if (0 == strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) && searchKeyName("default", "gamma")) + { + QString value = getDefaultCfgValue("default", "gamma", QString("")); + if (!value.isEmpty()) + { + HGSize length = 0; + std::string base64Data = value.toStdString(); + HGBase_Base64Decode((const HGByte*)base64Data.c_str(), base64Data.size(), NULL, &length); + + if (length == sizeof(SANE_Gamma)) + { + HGBase_Base64Decode((const HGByte*)base64Data.c_str(), base64Data.size(), (HGByte*)&m_gammaData, &length); + } + } + } + } + } +} + +void hg_settingdialog::processIniFile() +{ + HGChar cfgPath[512]; + GetConfigPath(cfgPath, 512); + QString oldFile = QString::fromStdString(cfgPath) + "olddefault.ini"; + QString newFile = QString::fromStdString(cfgPath) + "default.ini"; + + QFile::remove(oldFile); + QFile::copy(newFile, oldFile); +} + +void hg_settingdialog::setDefault() +{ + SANE_Int dev_options = 0; + m_saneAPI.sane_control_option_api(m_devHandle, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); + for (int i = 1; i < dev_options; ++i) + { + const SANE_Option_Descriptor* opt = m_saneAPI.sane_get_option_descriptor_api(m_devHandle, i); + if (!opt) + continue; + + if (opt->type == SANE_TYPE_BUTTON || opt->type == SANE_TYPE_GROUP) + continue; + + m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_SET_AUTO, NULL, NULL); + } +} + std::string sane_val_to_string(const char* val, SANE_Value_Type type) { char buf[128] = {0}; @@ -2118,16 +2401,15 @@ std::string sane_val_to_string(const char* val, SANE_Value_Type type) } void hg_settingdialog::on_current_scheme_changed() { - del_this_->setEnabled(true); - del_all_->setEnabled(false); - + m_deleteCur->setEnabled(true); + m_deleteAll->setEnabled(true); if (comb_->currentIndex() == 0) { - del_this_->setEnabled(false); + m_deleteCur->setEnabled(false); } - if (comb_->count() > 1) + if (comb_->count() == 1) { - del_all_->setEnabled(true); + m_deleteAll->setEnabled(false); } QString text(find_current_scheme_menu()); @@ -2193,7 +2475,12 @@ void hg_settingdialog::on_current_scheme_changed() if(schm) schm->release(); - sketch_->setHtml(info); + if (comb_->currentIndex() == 0) + { + updateDefaultScheme(); + } + +// sketch_->setHtml(info); } void hg_settingdialog::slot_pushButton_scheme_management(void) { @@ -2222,7 +2509,7 @@ void hg_settingdialog::slot_pushButton_scheme_management(void) } disconnect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed())); - comb_->insertItem(id, newCfgName); + comb_->insertItem(id + 1, newCfgName); connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed())); gb::sane_config_schm *scheme = cur_scheme_->copy(); @@ -2232,12 +2519,19 @@ void hg_settingdialog::slot_pushButton_scheme_management(void) cur_cfg_->add_scheme(cur_scheme_, newCfgName.toStdString().c_str()); cur_cfg_->select_scheme(cur_scheme_->get_scheme_name().c_str()); cur_cfg_->save(); - comb_->setCurrentIndex(id); + comb_->setCurrentIndex(id + 1); changed_count_++; } } } - else if(btn == del_this_) + else if (btn == m_pbtn_Save) + { + if (comb_->currentIndex() == 0) + processIniFile(); + else + save_scheme(); + } + else if(btn == m_deleteCur) { int id = -1; QString text(find_current_scheme_menu(&id)); @@ -2265,7 +2559,7 @@ void hg_settingdialog::slot_pushButton_scheme_management(void) changed_count_++; cur_cfg_->save(); } - else if(btn == del_all_) + else if(btn == m_deleteAll) { QMessageBox msg(QMessageBox::Question, tr("be sure to delete the configuration"), tr("Are you sure you want to delete the configuration?"), QMessageBox::Yes | QMessageBox::No, this); @@ -2284,17 +2578,21 @@ void hg_settingdialog::slot_pushButton_scheme_management(void) } void hg_settingdialog::restore_2_default_settings(void) { - cur_scheme_->end_setting(true); - cur_cfg_->select_scheme(nullptr); - dev_que_.apply_scheme(&m_saneAPI, nullptr); - cur_cfg_->save(); + if (comb_->currentIndex() == 0) + { + removeSection("default"); + } + else + { + cur_scheme_->end_setting(true); + cur_cfg_->select_scheme(nullptr); + dev_que_.apply_scheme(&m_saneAPI, nullptr); + cur_cfg_->save(); - gb::sane_config_schm *s = new gb::sane_config_schm(); - s->copy_default_value(cur_scheme_); - cur_scheme_->release(); - cur_scheme_ = s; - cur_scheme_->begin_setting(); - - // on_current_scheme_changed(); - comb_->setCurrentIndex(0); + gb::sane_config_schm *s = new gb::sane_config_schm(); + s->copy_default_value(cur_scheme_); + cur_scheme_->release(); + cur_scheme_ = s; + cur_scheme_->begin_setting(); + } } diff --git a/modules/twainui/hg_settingdialog.h b/modules/twainui/hg_settingdialog.h index ef85ff43..6c81975e 100644 --- a/modules/twainui/hg_settingdialog.h +++ b/modules/twainui/hg_settingdialog.h @@ -27,8 +27,9 @@ class hg_settingdialog : public QDialog QMenu *top_menu_; QLineEdit *edit_name_; QPushButton *m_pbtn_addNew; - QPushButton *del_this_; - QPushButton *del_all_; + QPushButton* m_pbtn_Save; + QPushButton *m_deleteCur; + QPushButton *m_deleteAll; QLabel *custom_area_lable_; QPushButton *btn_cut_area_; QPushButton *btn_gamma_; @@ -79,6 +80,8 @@ public: int m_closeButton; private: + gb::sane_config_schm* m_scheme; + static hg_settingdialog *hg_setting_ui_; SANEAPI m_saneAPI; SANE_Handle m_devHandle; @@ -94,7 +97,6 @@ private: QSettings *m_configIniRead; private: - HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen); QString md5(QString key); const void* find_option_description(int id); // return const SANE_Option_Descriptor* pointer const void* find_option_description(const std::string& title, int* id); // return const SANE_Option_Descriptor* pointer @@ -108,6 +110,9 @@ private: std::string getAppVersion(); void apply_current_scheme(void); void setIcon(); + void updateDefaultScheme(); + void processIniFile(); + void setDefault(); private: QVector, QString>> m_list_IdValueTitle; diff --git a/modules/twainui/twainui.cpp b/modules/twainui/twainui.cpp index 1f5c0b1b..0e1eefe0 100644 --- a/modules/twainui/twainui.cpp +++ b/modules/twainui/twainui.cpp @@ -1,7 +1,6 @@ #include "twain_user/twainui.h" #include #include -#include #include "dialog_device_select.h" #include "dialog_progress_ui.h" #include "hg_settingdialog.h" @@ -51,54 +50,6 @@ int choose_scanner(const std::vector &devs) return g_manager->showDeviceSelect(nullptr == g_hThread, devs); } -static HGResult GetConfigPath(HGChar* configPath, HGUInt maxLen) -{ - if (NULL == configPath || 0 == maxLen) - { - return HGBASE_ERR_INVALIDARG; - } - - const char *appName = "HuaGoScan"; -#if defined(OEM_HANWANG) - appName = "HanvonScan"; -#elif defined(OEM_LISICHENG) - appName = "LanxumScan"; -#elif defined(OEM_CANGTIAN) - appName = "CumtennScan"; -#elif defined(OEM_ZHONGJING) - appName = "MicrotekScan"; -#elif defined(OEM_ZIGUANG) - appName = "UniScan"; -#endif - -#if defined(HG_CMP_MSC) - CHAR cfgPath[MAX_PATH] = { 0 }; - BOOL ret = SHGetSpecialFolderPathA(NULL, cfgPath, CSIDL_APPDATA, FALSE); - if (!ret) - return HGBASE_ERR_FAIL; - if (cfgPath[strlen(cfgPath) - 1] != '\\') - strcat(cfgPath, "\\"); - - strcat(cfgPath, appName); - strcat(cfgPath, "\\Cfg\\"); -#else - char cfgPath[512] = { 0 }; - struct passwd* pw = getpwuid(getuid()); - strcpy(cfgPath, pw->pw_dir); - if (cfgPath[strlen(cfgPath) - 1] != '/') - strcat(cfgPath, "/"); - - strcat(cfgPath, "."); - strcat(cfgPath, appName); - strcat(cfgPath, "/Cfg/"); -#endif - - if (maxLen < strlen(cfgPath) + 1) - return HGBASE_ERR_FAIL; - strcpy(configPath, cfgPath); - return HGBASE_ERR_OK; -} - char *apply_current_config(const char *dev_name, SANE_Handle device, LPSANEAPI api) { dev_que devQue;