forked from Ivasoft/DSView
fix: get config api returns an error code
This commit is contained in:
@@ -32,10 +32,19 @@
|
||||
#include <assert.h>
|
||||
|
||||
//---------------Lang_resource_page
|
||||
Lang_resource_page::Lang_resource_page()
|
||||
{
|
||||
_id = -1;
|
||||
_source = NULL;
|
||||
_loaded = false;
|
||||
_released = false;
|
||||
_is_dynamic = false;
|
||||
}
|
||||
|
||||
void Lang_resource_page::Clear()
|
||||
{
|
||||
_res.clear();
|
||||
_res_history.clear();
|
||||
}
|
||||
|
||||
//---------------LangResource
|
||||
@@ -88,7 +97,9 @@ bool LangResource::Load(int lang)
|
||||
|
||||
_cur_lang = lang;
|
||||
|
||||
Release();
|
||||
_query_decoders.clear();
|
||||
|
||||
this->Release();
|
||||
|
||||
num = sizeof(lange_page_keys) / sizeof(lang_page_item);
|
||||
|
||||
@@ -97,7 +108,7 @@ bool LangResource::Load(int lang)
|
||||
Lang_resource_page *p = new Lang_resource_page();
|
||||
p->_id = lange_page_keys[i].id;
|
||||
p->_source = lange_page_keys[i].source;
|
||||
p->_loaded = false;
|
||||
p->_is_dynamic = lange_page_keys[i].is_dynamic;
|
||||
_pages.push_back(p);
|
||||
}
|
||||
|
||||
@@ -139,7 +150,7 @@ void LangResource::load_page(Lang_resource_page &p, QString file)
|
||||
{
|
||||
QFile f(file);
|
||||
if (f.exists() == false){
|
||||
if (_cur_lang != LAN_EN)
|
||||
if (_cur_lang != LAN_EN && p._is_dynamic == false)
|
||||
dsv_warn("Warning:Language source file is not exists: %s", file.toLocal8Bit().data());
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +190,7 @@ void LangResource::load_page(Lang_resource_page &p, QString file)
|
||||
const char* LangResource::get_lang_text(int page_id, const char *str_id, const char *default_str)
|
||||
{
|
||||
assert(str_id);
|
||||
assert(default_str);
|
||||
assert(default_str);
|
||||
|
||||
if (*str_id == '\0' || *default_str == '\0'){
|
||||
dsv_err("%s", "LangResource::get_lang_text(), param is empty.");
|
||||
@@ -198,20 +209,68 @@ const char* LangResource::get_lang_text(int page_id, const char *str_id, const c
|
||||
|
||||
if (_current_page == NULL){
|
||||
if (_cur_lang != LAN_EN)
|
||||
dsv_warn("Warning:Cant find language source page:%d", page_id);
|
||||
dsv_warn("Warning:Can't find language source page:%d", page_id);
|
||||
return default_str;
|
||||
}
|
||||
|
||||
if (_current_page->_loaded == false)
|
||||
load_page(*_current_page);
|
||||
|
||||
auto it = _current_page->_res.find(std::string(str_id));
|
||||
if (it != _current_page->_res.end()){
|
||||
return (*it).second.c_str();
|
||||
std::string key(str_id);
|
||||
|
||||
if (_current_page->_released){
|
||||
auto it = _current_page->_res_history.find(key);
|
||||
if (it != _current_page->_res_history.end()){
|
||||
return (*it).second.c_str();
|
||||
}
|
||||
}
|
||||
else if(_cur_lang != LAN_EN){
|
||||
dsv_warn("Warning:Cant't get language text:%s", str_id);
|
||||
else{
|
||||
auto it = _current_page->_res.find(key);
|
||||
if (it != _current_page->_res.end()){
|
||||
if (_current_page->_is_dynamic){
|
||||
_current_page->_res_history[key] = (*it).second; //Save to history list.
|
||||
}
|
||||
return (*it).second.c_str();
|
||||
}
|
||||
}
|
||||
|
||||
if(_cur_lang != LAN_EN){
|
||||
dsv_warn("Warning:Can't get language text:%s", str_id);
|
||||
}
|
||||
|
||||
return default_str;
|
||||
}
|
||||
|
||||
bool LangResource::is_new_decoder(const char *decoder_id)
|
||||
{
|
||||
std::string key(decoder_id);
|
||||
if (_query_decoders.find(key) == _query_decoders.end()){
|
||||
_query_decoders[key] = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void LangResource::reload_dynamic()
|
||||
{
|
||||
for (Lang_resource_page *p : _pages)
|
||||
{
|
||||
if (p->_is_dynamic){
|
||||
p->_released = false;
|
||||
p->_loaded = false;
|
||||
load_page(*p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LangResource::relase_dynamic()
|
||||
{
|
||||
for (Lang_resource_page *p : _pages)
|
||||
{
|
||||
if (p->_is_dynamic){
|
||||
p->_res.clear();
|
||||
p->_released = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <QString>
|
||||
#include <string>
|
||||
#include "string_ids.h"
|
||||
|
||||
struct lang_key_item
|
||||
@@ -36,19 +37,24 @@ struct lang_key_item
|
||||
class Lang_resource_page
|
||||
{
|
||||
public:
|
||||
Lang_resource_page();
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
int _id;
|
||||
const char *_source;
|
||||
bool _loaded;
|
||||
bool _released;
|
||||
bool _is_dynamic;
|
||||
std::map<std::string, std::string> _res;
|
||||
std::map<std::string, std::string> _res_history;
|
||||
};
|
||||
|
||||
struct lang_page_item
|
||||
{
|
||||
int id;
|
||||
const char *source;
|
||||
bool is_dynamic;
|
||||
};
|
||||
|
||||
static const struct lang_key_item lang_id_keys[] =
|
||||
@@ -59,10 +65,11 @@ static const struct lang_key_item lang_id_keys[] =
|
||||
|
||||
static const struct lang_page_item lange_page_keys[] =
|
||||
{
|
||||
{STR_PAGE_TOOLBAR, "toolbar.json"},
|
||||
{STR_PAGE_MSG, "msg.json"},
|
||||
{STR_PAGE_DLG, "dlg.json"},
|
||||
{STR_PAGE_DSL, "dsl_list.json, dsl_label.json, dsl_channel.json"}
|
||||
{STR_PAGE_TOOLBAR, "toolbar.json", false},
|
||||
{STR_PAGE_MSG, "msg.json", false},
|
||||
{STR_PAGE_DLG, "dlg.json", false},
|
||||
{STR_PAGE_DSL, "dsl_list.json, dsl_label.json, dsl_channel.json", false},
|
||||
{STR_PAGE_DECODER, "dec/0.json,dec/a.json,dec/f.json,dec/k.json,dec/p.json,dec/u.json", true},
|
||||
};
|
||||
|
||||
class LangResource
|
||||
@@ -74,8 +81,12 @@ public:
|
||||
static LangResource* Instance();
|
||||
bool Load(int lang);
|
||||
void Release();
|
||||
|
||||
const char* get_lang_text(int page_id, const char *str_id, const char *default_str);
|
||||
|
||||
bool is_new_decoder(const char *decoder_id);
|
||||
void reload_dynamic();
|
||||
void relase_dynamic();
|
||||
|
||||
private:
|
||||
const char *get_lang_key(int lang);
|
||||
|
||||
@@ -87,6 +98,7 @@ private:
|
||||
std::vector<Lang_resource_page*> _pages;
|
||||
Lang_resource_page *_current_page;
|
||||
int _cur_lang;
|
||||
std::map<std::string, int> _query_decoders;
|
||||
};
|
||||
|
||||
#define S_ID(id) #id
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define STR_PAGE_TOOLBAR 2
|
||||
#define STR_PAGE_DLG 3
|
||||
#define STR_PAGE_DSL 100
|
||||
#define STR_PAGE_DECODER 101
|
||||
|
||||
// xx
|
||||
#define IDS_TOOLBAR_MODE
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
[
|
||||
{
|
||||
"id": "vvv",
|
||||
"text": "xxx"
|
||||
},
|
||||
{
|
||||
"id": "vvv1",
|
||||
"text": "xxx1"
|
||||
}
|
||||
]
|
||||
@@ -726,7 +726,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi,
|
||||
*data = g_variant_new_int16(vdev->version);
|
||||
break;
|
||||
default:
|
||||
return SR_ERR_ARG;
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
@@ -949,7 +949,7 @@ static int config_set(int id, GVariant *data, struct sr_dev_inst *sdi,
|
||||
break;
|
||||
default:
|
||||
sr_err("Unknown capability: %d.", id);
|
||||
return SR_ERR;
|
||||
return SR_ERR_NA;
|
||||
}
|
||||
|
||||
return SR_OK;
|
||||
|
||||
Reference in New Issue
Block a user