HGGitLab

Commit c15badd2 authored by yangjiaxuan's avatar yangjiaxuan

增加保存设置参数配置项方案的功能

parent 6d963c05
This diff is collapsed.
This diff is collapsed.
/*
Copyright (c) 2009 Dave Gamble
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef cJSON__h
#define cJSON__h
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
/* cJSON Types: */
#define cJSON_False 0
#define cJSON_True 1
#define cJSON_NULL 2
#define cJSON_Number 3
#define cJSON_String 4
#define cJSON_Array 5
#define cJSON_Object 6
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
typedef void *(*malloc_fnxx)(size_t sz);
typedef void (*free_fnxx)(void *ptr);
/* The cJSON structure: */
typedef struct cJSON {
struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
int type; /* The type of the item, as above. */
char *valuestring; /* The item's string, if type==cJSON_String */
int valueint; /* The item's number, if type==cJSON_Number */
double valuedouble; /* The item's number, if type==cJSON_Number */
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} cJSON;
typedef struct cJSON_Hooks {
malloc_fnxx malloc_fn;
free_fnxx free_fn;
} cJSON_Hooks;
/* Supply malloc, realloc and free functions to cJSON */
extern void cJSON_InitHooks(cJSON_Hooks* hooks);
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
extern cJSON *cJSON_Parse(const char *value);
/* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
extern char *cJSON_Print(cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
extern char *cJSON_PrintUnformatted(cJSON *item);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
extern char *cJSON_PrintBuffered(cJSON *item,int prebuffer,int fmt);
/* Delete a cJSON entity and all subentities. */
extern void cJSON_Delete(cJSON *c);
/* Returns the number of items in an array (or object). */
extern int cJSON_GetArraySize(cJSON *array);
/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
extern cJSON *cJSON_GetArrayItem(cJSON *array,int item);
/* Get item "string" from object. Case insensitive. */
extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
extern const char *cJSON_GetErrorPtr(void);
/* These calls create a cJSON item of the appropriate type. */
extern cJSON *cJSON_CreateNull(void);
extern cJSON *cJSON_CreateTrue(void);
extern cJSON *cJSON_CreateFalse(void);
extern cJSON *cJSON_CreateBool(int b);
extern cJSON *cJSON_CreateNumber(double num);
extern cJSON *cJSON_CreateString(const char *string);
extern cJSON *cJSON_CreateArray(void);
extern cJSON *cJSON_CreateObject(void);
/* These utilities create an Array of count items. */
extern cJSON *cJSON_CreateIntArray(const int *numbers,int count);
extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count);
extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count);
extern cJSON *cJSON_CreateStringArray(const char **strings,int count);
/* Append item to the specified array/object. */
extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
extern void cJSON_AddItemToObjectCS(cJSON *object,const char *string,cJSON *item); /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object */
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
/* Remove/Detatch items from Arrays/Objects. */
extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which);
extern void cJSON_DeleteItemFromArray(cJSON *array,int which);
extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
/* Update array items. */
extern void cJSON_InsertItemInArray(cJSON *array,int which,cJSON *newitem); /* Shifts pre-existing items to the right. */
extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem);
extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
/* Duplicate a cJSON item */
extern cJSON *cJSON_Duplicate(cJSON *item,int recurse);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
need to be released. With recurse!=0, it will duplicate any children connected to the item.
The item->next and ->prev pointers are always zero on return from Duplicate. */
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated);
extern void cJSON_Minify(char *json);
/* Macros for creating things quickly. */
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
#define cJSON_SetNumberValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
#ifdef __cplusplus
}
#endif
#endif
#include "config.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <sstream>
#include <iomanip>
#include <QDir>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <QLatin1String>
#include <qtextcodec.h>
config::config() : ini_(NULL), file_(""), schem_jsn_(NULL)
{
}
config::~config()
{
if(ini_)
delete ini_;
if(schem_jsn_)
delete schem_jsn_;
}
QString config::get_scanner_config_file(void)
{
QString file(get_val("scanner", "schemes"));
if(file.length() == 0)
{
file = "scanner.schm";
ini_->setValue("schemes", file);
}
if(file[0] != '/')
{
std::string path(file_.toStdString());
path.erase(path.rfind('/') + 1);
path += file.toStdString();
file = QString::fromStdString(path);
}
return file;
}
void config::reload_schemes(void)
{
if(schem_jsn_)
{
delete schem_jsn_;
schem_jsn_ = NULL;
}
std::string jsntxt(""), org(config::read_mini_file(get_scanner_config_file()));
gb::base64 base64;
if(org.empty())
return;
jsntxt = base64.decode(org.c_str(), org.length());
schem_jsn_ = new gb::json();
if(!schem_jsn_->attach_text(&jsntxt[0]))
{
delete schem_jsn_;
schem_jsn_ = NULL;
}
}
QString config::self_path(void)
{
char path[256];
int len = readlink("/proc/self/exe", path, sizeof(path) - 1);
if (len > 0 && len < sizeof(path))
{
for (--len; len > 0; --len)
{
if (path[len] == '/')
{
path[len] = 0;
break;
}
}
}
return QString::fromStdString(path);
}
std::string config::read_mini_file(QString file)
{
std::string f(file.toStdString()),
ret("");
FILE* src = fopen(f.c_str(), "rb");
if(src)
{
long l = 0;
char *buf = NULL;
fseek(src, 0, SEEK_END);
l = ftell(src);
fseek(src, 0, SEEK_SET);
buf = (char*)malloc(l + 4);
bzero(buf, l + 4);
fread(buf, 1, l, src);
fclose(src);
ret = buf;
free(buf);
}
return ret;
}
std::string config::device_to_config_dev_name(QString& dev_name)
{
std::string name(dev_name.toStdString());
size_t pos = name.find(" - ");
if(pos != std::string::npos)
name.erase(pos);
return name;
}
int config::save_2_file(QString file, const void* buf, size_t l)
{
FILE* dst = fopen(file.toStdString().c_str(), "wb");
if(!dst)
return errno;
fwrite(buf, 1, l, dst);
fclose(dst);
return 0;
}
int config::find_config(QString dev_name, std::vector<DEVCFG>& cfgs)
{
std::string name(config::device_to_config_dev_name(dev_name));
int ind = -1;
for(size_t i = 0; i < cfgs.size(); ++i)
{
if(cfgs[i].name == name)
{
ind = i;
break;
}
}
return ind;
}
bool config::is_accessible_file(const std::string& path_file)
{
size_t pos = path_file.rfind('.');
if(pos++ == std::string::npos)
return false;
std::string ext(path_file.substr(pos));
config::to_lower(ext);
return (ext == "png" ||
ext == "jpg" ||
ext == "jpeg" ||
ext == "bmp" ||
ext == "tif" ||
ext == "pdf" ||
ext == "png");
}
void config::to_lower(std::string& str)
{
for(size_t i = 0; i < str.length(); ++i)
{
if(str[i] >= 'A' && str[i] <= 'Z')
str[i] -= 'A' - 'a';
}
}
int config::load(QString file)
{
if(ini_)
delete ini_;
ini_ = NULL;
if(file.length() == 0)
file = "configs/scanner.conf";
file_ = file;
if(file_[0] != '/')
{
file_ = config::self_path();
file_ += "/" + file;
}
ini_ = new QSettings(file_, QSettings::IniFormat);
ini_->setIniCodec(QTextCodec::codecForName("UTF-8"));
reload_schemes();
return 0;
}
QString config::get_val(QString sec_name, QString key, QString def_val)
{
if(!ini_)
return def_val;
QVariant qv = ini_->value(sec_name + "/" + key);
char buf[128];
if(qv.isNull())
return def_val;
if(qv.type() == QVariant::Type::Int)
{
sprintf(buf, "%d", qv.toInt());
return QString::fromStdString(buf);
}
else if(qv.type() == QVariant::Type::UInt)
{
sprintf(buf, "%u", qv.toInt());
return QString::fromStdString(buf);
}
else if(qv.type() == QVariant::Type::Double)
{
sprintf(buf, "%f", qv.toFloat());
return QString::fromStdString(buf);
}
else
return qv.toString();
}
QString config::get_file(void)
{
return file_;
}
void config::load_all_scanner_configs(std::vector<DEVCFG>& cfgs)
{
#if 0
_opt_scheme opt1;
opt1.name = "aaa";
_opt_scheme opt2;
opt2.name = "bbb";
DEVCFG d1;
d1.name = "d1";
d1.schemes.push_back(opt1);
d1.schemes.push_back(opt2);
cfgs.push_back(d1);
_opt_scheme opt3;
opt3.name = "ccc";
_opt_scheme opt4;
opt4.name = "ddd";
DEVCFG d2;
d2.name = "d2";
d2.schemes.push_back(opt1);
d2.schemes.push_back(opt2);
cfgs.push_back(d2);
#endif
if(!schem_jsn_)
return;
std::vector<std::string> devs;
std::string cont(""), name("");
if(schem_jsn_->first_child(cont, &name))
{
do
{
if(!name.empty())
devs.push_back(name);
}while(schem_jsn_->next_child(cont, &name));
}
for(size_t i = 0; i < devs.size(); ++i)
{
DEVCFG cfg;
load_scanner_configs(QString::fromStdString(devs[i]), &cfg);
cfgs.push_back(cfg);
}
}
void config::load_scanner_configs(QString dev_name, DEVCFG* cfg)
{
std::string name(config::device_to_config_dev_name(dev_name)), cont("");
OPTSCHEME scheme;
OPTVAL val;
cfg->name = name;
cfg->cur_scheme = -1;
if(!schem_jsn_)
return;
gb::json *child = NULL;
schem_jsn_->get_value(name.c_str(), child);
if(!child)
return;
if(child->first_child(cont))
{
gb::json *cur = new gb::json();
if(cur->attach_text(&cont[0]))
{
if(!cur->get_value("cur_sel", cfg->cur_scheme))
cfg->cur_scheme = -1;
}
delete cur;
while(child->next_child(cont))
{
if(cont.empty())
continue;
gb::json jsn, *son = NULL;
if(!jsn.attach_text(&cont[0]))
continue;
jsn.get_value("scheme", scheme.name);
jsn.get_value("opts", son);
if(!son)
continue;
scheme.opts.clear();
if(son->first_child(cont))
{
do
{
if(cont.empty())
continue;
gb::json item;
if(!item.attach_text(&cont[0]))
continue;
if(item.get_value("name", val.name) &&
// item.get_value("type", val.type) &&
item.get_value("value", val.val))
scheme.opts.push_back(val);
}while(son->next_child(cont));
}
delete son;
if(scheme.opts.size())
cfg->schemes.push_back(scheme);
}
}
delete child;
}
int config::save_scanner_configs(const DEVCFG* cfg)
{
if(!schem_jsn_)
schem_jsn_ = new gb::json();
gb::json *child = NULL, *scheme = NULL, *val = NULL;
std::string text("");
schem_jsn_->get_value(cfg->name.c_str(), child);
if(child)
schem_jsn_->remove(cfg->name.c_str());
if(child)
child->clear();
else {
child = new gb::json();
}
child->create_empty(true);
scheme = new gb::json();
scheme->set_value("cur_sel", cfg->cur_scheme);
child->set_value(NULL, scheme);
delete scheme;
for(size_t i = 0; i < cfg->schemes.size(); ++i)
{
if(cfg->schemes[i].opts.empty())
continue;
scheme = new gb::json();
scheme->create_empty();
scheme->set_value("scheme", cfg->schemes[i].name);
gb::json *opt = new gb::json();
opt->create_empty(true);
for(size_t j = 0; j < cfg->schemes[i].opts.size(); ++j)
{
val = new gb::json();
val->set_value("name", cfg->schemes[i].opts[j].name);
// val->set_value("type", cfg->schemes[i].opts[j].type);
val->set_value("value", cfg->schemes[i].opts[j].val);
text = val->to_string(false);
opt->set_value(NULL, val);
text = opt->to_string(false);
delete val;
}
printf("scheme %d: %s\n", i + 1, text.c_str());
scheme->set_value("opts", opt);
text = scheme->to_string(false);
printf("all: %s\n", text.c_str());
delete opt;
child->set_value(NULL, scheme);
text = child->to_string(false);
delete scheme;
}
schem_jsn_->set_value(cfg->name.c_str(), child);
delete child;
text = schem_jsn_->to_string(false);
// save as base64
gb::base64 base64;
std::string ec(base64.encode(text.c_str(), text.length()));
return save_2_file(get_scanner_config_file(), ec.c_str(), ec.length());
}
#pragma once
#include <vector>
#include <string>
#include <qsettings.h>
#include <algorithm>
#include <math.h>
#include "json.h"
#define IS_DOUBLE_EQUAL(a, b) fabs((a) - (b)) < .00001
typedef struct _opt_val
{
std::string name;
std::string type;
std::string val;
bool operator==(const struct _opt_val& r)
{
if(name != r.name)
return false;
if(type == "float")
{
return IS_DOUBLE_EQUAL(atof(val.c_str()), atof(r.val.c_str()));
}
else {
return val == r.val;
}
}
bool operator==(const std::string& n)
{
return name == n;
}
}OPTVAL;
typedef struct _opt_scheme
{
std::string name; // scheme name
std::vector<OPTVAL> opts;
bool operator==(const std::string& n)
{
return name == n;
}
bool operator==(const struct _opt_scheme& r)
{
if(opts.size() != r.opts.size())
return false;
bool equal = true;
for(size_t i = 0; i < r.opts.size(); ++i)
{
std::vector<OPTVAL>::iterator it = std::find(opts.begin(), opts.end(), r.opts[i].name);
if(it == opts.end() ||
r.opts[i].val != it->val)
{
equal = false;
break;
}
}
return equal;
}
}OPTSCHEME;
typedef struct _dev_configs
{
std::string name; // device name
int cur_scheme; // -1 is none user scheme applied, and points to the default setting which at first in 'schemes'
std::vector<OPTSCHEME> schemes; // NOTE: the first is always the default setting, and (cur_scheme + 1) is the user customizing setting, -1 is the default setting
bool operator==(const std::string& n)
{
return name == n;
}
_dev_configs()
{
OPTSCHEME none;
none.name = "默认设置";
schemes.push_back(none);
cur_scheme = -1;
}
OPTSCHEME* get_current(void)
{
if(cur_scheme >= 0 && cur_scheme + 1 < schemes.size())
return &schemes[cur_scheme + 1];
else
return &schemes[0];
}
OPTSCHEME* select(const std::string& name)
{
}
}DEVCFG;
//
// {
// "G100" : [
// {
// "scheme": "color-A4R",
// "opts": [
// {
// "name": "color-mode",
// "type": "string",
// "value": "24-bits",
// "init": "24-bits"
// },
// {
// "name": "paper",
// "type": "string",
// "value": "A4R"
// "init": "A4"
// }],
// }],
//
// "G200" : [ ... ]
//
// }
//
class config
{
QSettings *ini_;
QString file_;
gb::json *schem_jsn_;
QString get_scanner_config_file(void);
void reload_schemes(void);
public:
config();
~config();
static QString self_path(void); // without last '/'
static std::string read_mini_file(QString file);
static std::string device_to_config_dev_name(QString& dev_name);
static int save_2_file(QString file, const void* buf, size_t l);
static int find_config(QString dev_name, std::vector<DEVCFG>& cfgs);
static bool is_accessible_file(const std::string& path_file);
static void to_lower(std::string& str);
public:
int load(QString file = "");
QString get_val(QString sec_name, QString key, QString def_val = "");
QString get_file(void);
void load_all_scanner_configs(std::vector<DEVCFG>& cfgs);
void load_scanner_configs(QString dev_name, DEVCFG* cfg);
int save_scanner_configs(const DEVCFG* cfg);
};
......@@ -8,73 +8,7 @@
#include <QSettings>
#include <algorithm>
#include "sane_ex/sane_ex.h"
#define IS_DOUBLE_EQUAL(a, b) fabs((a) - (b)) < .00001
typedef struct _opt_val
{
std::string name;
std::string type;
std::string val;
bool operator==(const struct _opt_val& r)
{
if(name != r.name)
return false;
if(type == "float")
{
return IS_DOUBLE_EQUAL(atof(val.c_str()), atof(r.val.c_str()));
}
else {
return val == r.val;
}
}
bool operator==(const std::string& n)
{
return name == n;
}
}OPTVAL;
typedef struct _opt_scheme
{
std::string name; // scheme name
std::vector<OPTVAL> opts;
bool operator==(const std::string& n)
{
return name == n;
}
bool operator==(const struct _opt_scheme& r)
{
if(opts.size() != r.opts.size())
return false;
bool equal = true;
for(size_t i = 0; i < r.opts.size(); ++i)
{
std::vector<OPTVAL>::iterator it = std::find(opts.begin(), opts.end(), r.opts[i].name);
if(it == opts.end() ||
r.opts[i].val != it->val)
{
equal = false;
break;
}
}
return equal;
}
}OPTSCHEME;
typedef struct _dev_configs
{
std::string name; // device name
int cur_scheme; // -1 is none user scheme applied, and points to the default setting which at first in 'schemes'
std::vector<OPTSCHEME> schemes; // NOTE: the first is always the default setting, and (cur_scheme + 1) is the user customizing setting, -1 is the default setting
bool operator==(const std::string& n)
{
return name == n;
}
}DEVCFG;
#include "config.h"
class hg_settingdialog : public QDialog
{
......
This diff is collapsed.
#pragma once
#ifdef WIN32
#include <Windows.h>
#endif
#include "cJSON.h"
#include <vector>
#include <string>
namespace gb
{
class json
{
cJSON *obj_;
cJSON* cur_child_;
bool is_array_;
cJSON* find_sibling(cJSON* first, const char* name, cJSON*** addr);
cJSON* find_child(cJSON *parent, std::vector<std::string>& path, bool create, cJSON*** addr = NULL);
cJSON* find(const char* path, bool create = false, cJSON*** addr = NULL);
public:
json(char* json_txt = 0);
~json();
static std::string to_string(cJSON* root, bool formatted);
static std::string get_value_as_string(cJSON* root, bool integer = false);
static void free_node_data(cJSON* node);
static cJSON* create_element_with_name(const char* name);
public:
bool attach_text(char* json_txt);
bool attach_cjson(cJSON* cjson);
bool create_empty(bool array = false);
void clear(void);
std::string to_string(bool formatted);
// can be path: child/value ...
bool get_value(const char* key, bool& val);
bool get_value(const char* key, int& val);
bool get_value(const char* key, double& val);
bool get_value(const char* key, std::string& val);
bool get_value(const char* key, json*& val); // caller shoud call "delete" to free the returned object !!!
bool get_value_as_string(const char* key, std::string& val, bool integer);
bool get_as_array(const char* key, std::vector<std::string>& val);
bool first_child(std::string& val, std::string* name = NULL);
bool next_child(std::string& val, std::string* name = NULL);
bool set_value(const char* key, bool val);
bool set_value(const char* key, int val);
bool set_value(const char* key, double val);
bool set_value(const char* key, std::string val);
bool set_value(const char* key, const char* val);
bool set_value(const char* key, json* obj);
bool remove(const char* key);
};
class base64
{
char base64_ind_[128];
char base64_char_[80];
char padding_char_;
bool is_valid_base64_table(const char* table);
bool initialize_base64_table(const char* table);
public:
base64();
~base64();
public:
bool set_base64_table(const char* table = NULL);
std::string encode(const char* data, size_t bytes, unsigned int line_bytes = -1, bool need_padding = true);
std::string decode(const char* data, size_t bytes);
};
}
......@@ -52,6 +52,8 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
m_config.load();
this->setWindowIcon(QIcon(":images/image_rsc/logo/logo.ico"));
this->setWindowTitle(tr("HuaGoScan"));
this->setAutoFillBackground(true);
......@@ -1916,13 +1918,20 @@ void MainWindow::on_act_scannerSettings_triggered()
if (nullptr != m_saneDeviceHandle)
{
DEVCFG cfg;
std::vector<DEVCFG>::iterator it = std::find(dev_schemes_.begin(), dev_schemes_.end(), m_saneDeviceAction->text().toStdString());
if(it != dev_schemes_.end())
{
cfg = *it;
dev_schemes_.erase(it);
}
cfg.name = m_saneDeviceAction->text().toStdString();
cfg.cur_scheme = -1;
hg_settingdialog dlg(m_saneDeviceHandle, this, &cfg);
if (dlg.exec())
{
int changes = dlg.get_changed_items();
}
dlg.exec();
int changes = dlg.get_changed_items();
dev_schemes_.insert(dev_schemes_.begin(), cfg);
if(changes)
m_config.save_scanner_configs(&cfg);
}
#endif
}
......
......@@ -9,6 +9,7 @@
#include "twain_user/HGTwain.h"
#else
#include "sane_ex/sane_ex.h"
#include "config.h"
#endif
#include "dialog_aquireinto.h"
#include "imgfmt/HGImgFmt.h"
......@@ -211,6 +212,9 @@ private:
QAction *m_saneNoDevAction;
QAction *m_saneDeviceAction;
SANE_Handle m_saneDeviceHandle;
config m_config;
std::vector<DEVCFG> dev_schemes_;
#endif
QString m_currFilePath;
......
......@@ -55,6 +55,9 @@ SOURCES += \
../../../../app/scanner/widget_imgproc_base.cpp \
../../../../app/scanner/widget_statusbar.cpp \
../../../../app/scanner/dialog_admin.cpp \
../../../../app/scanner/config.cpp \
../../../../app/scanner/json.cpp \
../../../../app/scanner/cJSON.c \
../../../../ui/HGImgThumb.cpp \
../../../../ui/HGImgView.cpp \
../../../../ui/HGUIGlobal.cpp
......@@ -82,6 +85,9 @@ HEADERS += \
../../../../app/scanner/widget_imgproc_base.h \
../../../../app/scanner/widget_statusbar.h \
../../../../app/scanner/dialog_admin.h \
../../../../app/scanner/config.h \
../../../../third_party/json/json.h \
../../../../third_party/json/cJSON.h \
../../../../ui/HGImgThumb.h \
../../../../ui/HGImgView.h \
../../../../ui/HGUIGlobal.h
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment