调整设置参数配置方案管理
This commit is contained in:
parent
7e8ec0b0bf
commit
5dd83874d7
|
@ -498,7 +498,7 @@ public:
|
|||
if(!handle_)
|
||||
return SCANNER_ERR_NOT_OPEN;
|
||||
|
||||
if (0 == getDefaultCfgValue("default", "index", 0))
|
||||
if (0 == getDefaultCfgValue("current", "index", 0))
|
||||
{
|
||||
SANE_Int none = 0;
|
||||
none = restore_settings(saneApi, handle_);
|
||||
|
|
|
@ -32,6 +32,7 @@ hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const
|
|||
, m_devName(devName)
|
||||
, m_callback(callback)
|
||||
, m_isRefreshUi(false)
|
||||
, changed_count_(0)
|
||||
{
|
||||
m_mgr = mgr;
|
||||
m_langCode = lang_get_cur_code_page();
|
||||
|
@ -126,13 +127,18 @@ hg_settingdialog::hg_settingdialog(class Manager *mgr, SANE_Handle handle, const
|
|||
QFile::copy(oldFile, newFile);
|
||||
|
||||
int index = getDefaultCfgValue("current", "index", 0);
|
||||
if (comb_->count() == 1)
|
||||
if (comb_->count() < index + 1)
|
||||
index = 0;
|
||||
|
||||
comb_->setCurrentIndex(index < 0 ? 0 : index);
|
||||
|
||||
saveOriginDeviceScheme();
|
||||
applyDeviceScheme();
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
initGammaData();
|
||||
applyDeviceScheme();
|
||||
}
|
||||
connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
|
||||
}
|
||||
|
||||
|
@ -295,7 +301,6 @@ void hg_settingdialog::create_scheme_management_ui(QVBoxLayout* layout)
|
|||
|
||||
cur_cfg_->get_all_schemes(schemes);
|
||||
comb_ = new QComboBox(this);
|
||||
//disconnect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
|
||||
comb_->addItem(tr("Default scheme"));
|
||||
layout->addSpacing(30);
|
||||
for(int i = 1; i < (int)schemes.size(); ++i)
|
||||
|
@ -357,13 +362,15 @@ void hg_settingdialog::create_scheme_management_ui(QVBoxLayout* layout)
|
|||
m_deleteCur->setEnabled(true);
|
||||
m_deleteAll->setEnabled(true);
|
||||
m_pbtn_Save->setEnabled(true);
|
||||
int index = getDefaultCfgValue("default", "index", 0);
|
||||
int index = getDefaultCfgValue("current", "index", 0);
|
||||
int count = comb_->count();
|
||||
if (index == 0)
|
||||
{
|
||||
m_deleteCur->setEnabled(false);
|
||||
m_pbtn_Save->setEnabled(false);
|
||||
}
|
||||
if (index == 1)
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
m_deleteAll->setEnabled(false);
|
||||
}
|
||||
|
@ -499,6 +506,10 @@ void hg_settingdialog::createUI()
|
|||
bool enable = *(bool*)&cur_val[0];
|
||||
checkBoxCreation->setProperty("controls_id", id);
|
||||
checkBoxCreation->setChecked(enable);
|
||||
if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0 && btn_gamma_ != nullptr)
|
||||
{
|
||||
btn_gamma_->setEnabled(enable);
|
||||
}
|
||||
if (strcmp(opt->name, SANE_STD_OPT_NAME_CUSTOM_AREA) == 0)
|
||||
btn_cut_area_->setEnabled(enable);
|
||||
else if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0)
|
||||
|
@ -843,6 +854,11 @@ void hg_settingdialog::refresh_control_value(int op_id)
|
|||
{
|
||||
disconnect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked()));
|
||||
cb->setChecked(m_list_defaultOptions.at(op_id - 1).second.toBool());
|
||||
if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0 && btn_gamma_ != nullptr)
|
||||
{
|
||||
btn_gamma_->setEnabled(m_list_defaultOptions.at(op_id - 1).second.toBool());
|
||||
}
|
||||
|
||||
connect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked()));
|
||||
break;
|
||||
}
|
||||
|
@ -1937,13 +1953,14 @@ void hg_settingdialog::closeEvent(QCloseEvent* e)
|
|||
QFile::remove(newFile);
|
||||
QFile file(oldFile);
|
||||
file.rename(newFile);
|
||||
if (0 == index)
|
||||
|
||||
if (0 != index)
|
||||
{
|
||||
cancel_setting();
|
||||
cancelScheme();
|
||||
}
|
||||
|
||||
else
|
||||
cancel_setting();
|
||||
cancelScheme();
|
||||
}
|
||||
|
||||
e->accept();
|
||||
|
@ -2198,7 +2215,7 @@ void hg_settingdialog::cancel_setting(void)
|
|||
{
|
||||
// restore changed value ...
|
||||
cur_scheme_->end_setting(true);
|
||||
dev_que::apply_scheme(&m_saneAPI, m_devHandle, cur_scheme_);
|
||||
//dev_que::apply_scheme(&m_saneAPI, m_devHandle, cur_scheme_);
|
||||
}
|
||||
|
||||
std::string hg_settingdialog::getAppVersion()
|
||||
|
@ -2255,6 +2272,10 @@ void hg_settingdialog::applyDeviceScheme()
|
|||
m_saneAPI.sane_control_option_api(m_devHandle, id, SANE_ACTION_GET_VALUE, &value, &method);
|
||||
disconnect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked()));
|
||||
cb->setCheckState(value ? Qt::Checked : Qt::Unchecked);
|
||||
if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0 && btn_gamma_ != nullptr)
|
||||
{
|
||||
btn_gamma_->setEnabled(value);
|
||||
}
|
||||
connect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked()));
|
||||
break;
|
||||
}
|
||||
|
@ -2385,10 +2406,16 @@ void hg_settingdialog::updateDefaultScheme()
|
|||
|
||||
if (comb_->currentIndex() == 0)
|
||||
{
|
||||
bool check = false;
|
||||
if (searchKeyName("default", opt->name))
|
||||
{
|
||||
cb->setCheckState(getDefaultCfgValue("default", opt->name, false) ? Qt::Checked : Qt::Unchecked);
|
||||
check = getDefaultCfgValue("default", opt->name, false);
|
||||
}
|
||||
cb->setCheckState(check ? Qt::Checked : Qt::Unchecked);
|
||||
if (strcmp(opt->name, SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA) == 0 && btn_gamma_ != nullptr)
|
||||
{
|
||||
btn_gamma_->setEnabled(check);
|
||||
}
|
||||
}
|
||||
//connect(cb, SIGNAL(stateChanged(int)), this, SLOT(slot_checkedClicked()));
|
||||
break;
|
||||
|
@ -2593,6 +2620,8 @@ void hg_settingdialog::saveOriginDeviceScheme()
|
|||
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, init, &method);
|
||||
m_list_originDeviceScheme.append(QPair<const void*, QVariant>(opt, QVariant(QString::fromStdString(init))));
|
||||
|
||||
free(init);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2623,10 +2652,10 @@ void hg_settingdialog::cancelScheme()
|
|||
}
|
||||
else if (opt->type == SANE_TYPE_FIXED)
|
||||
{
|
||||
double f_ratio = m_list_originDeviceScheme.at(i).second.toDouble();
|
||||
auto ff = SANE_FIX(f_ratio);
|
||||
double v = SANE_UNFIX(m_list_originDeviceScheme.at(i).second.toDouble());
|
||||
SANE_Int v2 = SANE_FIX(v);
|
||||
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i + 1, SANE_ACTION_SET_VALUE, &ff, &none);
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i + 1, SANE_ACTION_SET_VALUE, &v2, &none);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2638,6 +2667,23 @@ void hg_settingdialog::cancelScheme()
|
|||
}
|
||||
}
|
||||
|
||||
void hg_settingdialog::restoreDeviceScheme()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void hg_settingdialog::processIniFile()
|
||||
{
|
||||
HGChar cfgPath[512];
|
||||
|
@ -2649,6 +2695,85 @@ void hg_settingdialog::processIniFile()
|
|||
QFile::copy(newFile, oldFile);
|
||||
}
|
||||
|
||||
void hg_settingdialog::initGammaData()
|
||||
{
|
||||
QString value = getDefaultCfgValue("default", "curves", 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::updateSchemeFromUi()
|
||||
{
|
||||
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, j = dev_options; i < j; i++)
|
||||
{
|
||||
const SANE_Option_Descriptor* opt = m_saneAPI.sane_get_option_descriptor_api(m_devHandle, i);
|
||||
SANE_Int method = 0;
|
||||
if (opt == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (opt->type == SANE_TYPE_INT)
|
||||
{
|
||||
SANE_Int init = 0;
|
||||
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method);
|
||||
cur_scheme_->config_changed(i, (char*)&init, sizeof(init));
|
||||
}
|
||||
else if (opt->type == SANE_TYPE_FIXED)
|
||||
{
|
||||
SANE_Fixed init = 0;
|
||||
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method);
|
||||
cur_scheme_->config_changed(i, (char*)&init, sizeof(init));
|
||||
}
|
||||
else if (opt->type == SANE_TYPE_BOOL)
|
||||
{
|
||||
SANE_Bool init = 0;
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, &init, &method);
|
||||
cur_scheme_->config_changed(i, (char*)&init, sizeof(init));
|
||||
}
|
||||
else if (opt->type == SANE_TYPE_STRING)
|
||||
{
|
||||
char* init = (char*)malloc(opt->size * 2 + 4);
|
||||
|
||||
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_GET_VALUE, init, &method);
|
||||
std::string value = QString(init).toStdString();
|
||||
cur_scheme_->config_changed(i, value.c_str(), value.size());
|
||||
free(init);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hg_settingdialog::updateSchemeManagerUi()
|
||||
{
|
||||
m_deleteCur->setEnabled(true);
|
||||
m_deleteAll->setEnabled(true);
|
||||
m_pbtn_Save->setEnabled(true);
|
||||
if (comb_->currentIndex() == 0)
|
||||
{
|
||||
m_deleteCur->setEnabled(false);
|
||||
m_pbtn_Save->setEnabled(false);
|
||||
}
|
||||
if (comb_->count() == 1)
|
||||
{
|
||||
m_deleteAll->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
std::string sane_val_to_string(const char* val, SANE_Value_Type type)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
|
@ -2676,22 +2801,24 @@ std::string sane_val_to_string(const char* val, SANE_Value_Type type)
|
|||
}
|
||||
void hg_settingdialog::on_current_scheme_changed()
|
||||
{
|
||||
m_deleteCur->setEnabled(true);
|
||||
m_deleteAll->setEnabled(true);
|
||||
m_pbtn_Save->setEnabled(true);
|
||||
if (comb_->currentIndex() == 0)
|
||||
{
|
||||
m_deleteCur->setEnabled(false);
|
||||
m_pbtn_Save->setEnabled(false);
|
||||
}
|
||||
if (comb_->count() == 1)
|
||||
{
|
||||
m_deleteAll->setEnabled(false);
|
||||
}
|
||||
updateSchemeManagerUi();
|
||||
|
||||
if (comb_->currentIndex() == 0)
|
||||
{
|
||||
restoreDeviceScheme();
|
||||
applyDeviceScheme();
|
||||
|
||||
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);
|
||||
QFile::copy(newFile, oldFile);
|
||||
|
||||
updateDefaultScheme();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2794,10 +2921,16 @@ void hg_settingdialog::slot_pushButton_scheme_management(void)
|
|||
cur_scheme_->end_setting(true);
|
||||
cur_scheme_->release();
|
||||
cur_scheme_ = scheme;
|
||||
|
||||
updateSchemeFromUi();
|
||||
|
||||
cur_cfg_->add_scheme(cur_scheme_, newCfgName.toStdString().c_str());
|
||||
cur_cfg_->select_scheme(cur_scheme_->get_scheme_name().c_str());
|
||||
cur_cfg_->save();
|
||||
disconnect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
|
||||
comb_->setCurrentIndex(id + 1);
|
||||
connect(comb_, SIGNAL(currentTextChanged(const QString)), this, SLOT(on_current_scheme_changed()));
|
||||
|
||||
changed_count_++;
|
||||
}
|
||||
}
|
||||
|
@ -2853,6 +2986,7 @@ void hg_settingdialog::slot_pushButton_scheme_management(void)
|
|||
cur_cfg_->remove_all_schemes();
|
||||
cur_cfg_->save();
|
||||
}
|
||||
updateSchemeManagerUi();
|
||||
}
|
||||
void hg_settingdialog::restore_2_default_settings(void)
|
||||
{
|
||||
|
|
|
@ -113,7 +113,11 @@ private:
|
|||
void updateDefaultScheme();
|
||||
void saveOriginDeviceScheme();
|
||||
void cancelScheme();
|
||||
void restoreDeviceScheme();
|
||||
void processIniFile();
|
||||
void initGammaData();
|
||||
void updateSchemeFromUi();
|
||||
void updateSchemeManagerUi();
|
||||
|
||||
private:
|
||||
QVector<QPair<QPair<int, QVariant>, QString>> m_list_IdValueTitle;
|
||||
|
|
Loading…
Reference in New Issue