The decdoer info surports mutil-language

This commit is contained in:
dreamsourcelabTAI 2022-10-31 15:38:37 +08:00
parent d04f66d7a4
commit 161f7168d2
12 changed files with 100 additions and 21 deletions

View File

@ -773,5 +773,14 @@ int64_t DecoderStack::get_mark_index()
return _mark_index;
}
const char* DecoderStack::get_root_decoder_id()
{
if (_stack.size() > 0){
decode::Decoder *dec = _stack.front();
return dec->decoder()->id;
}
return NULL;
}
} // namespace data
} // namespace pv

View File

@ -96,6 +96,8 @@ public:
return _stack;
}
const char* get_root_decoder_id();
void add_sub_decoder(decode::Decoder *decoder);
void remove_sub_decoder(decode::Decoder *decoder);
void remove_decoder_by_handel(const srd_decoder *dec);

View File

@ -68,11 +68,23 @@ DecoderOptionsDlg::~DecoderOptionsDlg()
_bindings.clear();
}
void DecoderOptionsDlg::load_options(view::DecodeTrace *trace, bool isNew)
void DecoderOptionsDlg::load_options(view::DecodeTrace *trace)
{
assert(trace);
_trace = trace;
const char *dec_id = trace->decoder()->get_root_decoder_id();
if (LangResource::Instance()->is_new_decoder(dec_id))
LangResource::Instance()->reload_dynamic();
load_options_view();
LangResource::Instance()->release_dynamic();
}
void DecoderOptionsDlg::load_options_view()
{
DSDialog *dlg = this;
QFormLayout *form = new QFormLayout();
@ -349,31 +361,45 @@ void DecoderOptionsDlg::create_decoder_form(
// Add the mandatory channels
for(l = decoder->channels; l; l = l->next) {
const struct srd_channel *const pdch =
(struct srd_channel *)l->data;
const struct srd_channel *const pdch = (struct srd_channel *)l->data;
DsComboBox *const combo = create_probe_selector(parent, dec, pdch);
const char *desc_str = NULL;
if (pdch->idn != NULL){
desc_str = LangResource::Instance()->get_lang_text(STR_PAGE_DECODER, pdch->idn, pdch->desc);
}
else{
desc_str = pdch->desc;
}
//tr
decoder_form->addRow(QString("<b>%1</b> (%2) *")
.arg(QString::fromUtf8(pdch->name))
.arg(QString::fromUtf8(pdch->desc)), combo);
.arg(QString::fromUtf8(desc_str)), combo);
const ProbeSelector s = {combo, dec, pdch};
_probe_selectors.push_back(s);
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int)));
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(on_probe_selected(int)));
}
// Add the optional channels
for(l = decoder->opt_channels; l; l = l->next) {
const struct srd_channel *const pdch =
(struct srd_channel *)l->data;
const struct srd_channel *const pdch = (struct srd_channel *)l->data;
DsComboBox *const combo = create_probe_selector(parent, dec, pdch);
const char *desc_str = NULL;
if (pdch->idn != NULL){
desc_str = LangResource::Instance()->get_lang_text(STR_PAGE_DECODER, pdch->idn, pdch->desc);
}
else{
desc_str = pdch->desc;
}
//tr
decoder_form->addRow(QString("<b>%1</b> (%2)")
.arg(QString::fromUtf8(pdch->name))
.arg(QString::fromUtf8(pdch->desc)), combo);
.arg(QString::fromUtf8(desc_str)), combo);
const ProbeSelector s = {combo, dec, pdch};
_probe_selectors.push_back(s);

View File

@ -84,9 +84,11 @@ public:
cursor2 = _cursor2;
}
void load_options(view::DecodeTrace *trace, bool isNew);
void load_options(view::DecodeTrace *trace);
private:
void load_options_view();
void load_decoder_forms(QWidget *container);
DsComboBox* create_probe_selector(QWidget *parent, const data::decode::Decoder *dec,

View File

@ -1501,7 +1501,11 @@ namespace pv
{
QString ses_name = dir.absolutePath() + "/"
+ _device_agent->driver_name() + QString::number(mode) + ".dsc";
on_load_session(ses_name);
QFile sf(ses_name);
if (sf.exists()){
on_load_session(ses_name);
}
}
}
}

View File

@ -31,6 +31,7 @@
#include "../enum.h"
#include "../int.h"
#include "../string.h"
#include "../../ui/langresource.h"
using namespace boost;
using namespace std;
@ -54,7 +55,15 @@ DecoderOptions::DecoderOptions(pv::data::DecoderStack* decoder_stack, data::deco
const srd_decoder_option *const opt =
(srd_decoder_option*)l->data;
const QString name = QString::fromUtf8(opt->desc);
const char *desc_str = NULL;
if (opt->idn != NULL){
desc_str = LangResource::Instance()->get_lang_text(STR_PAGE_DECODER, opt->idn, opt->desc);
}
else{
desc_str = opt->desc;
}
const QString name = QString::fromUtf8(desc_str);
const Property::Getter getter = bind(
&DecoderOptions::getter, this, opt->id);

View File

@ -161,6 +161,8 @@ void LangResource::load_page(Lang_resource_page &p, QString file)
if (raw_bytes.length() == 0)
return;
dsv_info("Load lang resouce file: %s", file.toLocal8Bit().data());
QJsonParseError error;
QString jsonStr(raw_bytes.data());
QByteArray qbs = jsonStr.toUtf8();
@ -264,7 +266,7 @@ void LangResource::reload_dynamic()
}
}
void LangResource::relase_dynamic()
void LangResource::release_dynamic()
{
for (Lang_resource_page *p : _pages)
{

View File

@ -85,7 +85,7 @@ public:
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();
void release_dynamic();
private:
const char *get_lang_key(int lang);

View File

@ -681,7 +681,7 @@ bool DecodeTrace::create_popup(bool isnew)
QWidget *top = AppControl::Instance()->GetTopWindow();
dialogs::DecoderOptionsDlg dlg(top);
dlg.set_cursor_range(_decode_cursor1, _decode_cursor2);
dlg.load_options(this, isnew);
dlg.load_options(this);
if (QDialog::Accepted == dlg.exec())
{

View File

@ -112,9 +112,10 @@ static void channel_free(void *data)
if (!ch)
return;
g_free(ch->desc);
g_free(ch->name);
g_free(ch->id);
g_safe_free(ch->desc);
g_safe_free(ch->name);
g_safe_free(ch->id);
g_safe_free(ch->idn);
g_free(ch);
}
@ -150,8 +151,9 @@ static void decoder_option_free(void *data)
g_slist_free_full(opt->values, &variant_free);
variant_free(opt->def);
g_free(opt->desc);
g_free(opt->id);
g_safe_free(opt->desc);
g_safe_free(opt->id);
g_safe_free(opt->idn);
g_free(opt);
}
@ -226,6 +228,11 @@ static int get_channels(const struct srd_decoder *d, const char *attr,
goto err_out;
}
pdch = g_malloc(sizeof(struct srd_channel));
pdch->id = NULL;
pdch->name = NULL;
pdch->desc = NULL;
pdch->idn = NULL;
/* Add to list right away so it doesn't get lost. */
pdchl = g_slist_prepend(pdchl, pdch);
@ -236,6 +243,8 @@ static int get_channels(const struct srd_decoder *d, const char *attr,
if (py_dictitem_as_str(py_entry, "desc", &pdch->desc) != SRD_OK)
goto err_out;
py_dictitem_as_str(py_entry, "idn", &pdch->idn);
pdch->type = py_dictitem_to_int(py_entry, "type");
if (pdch->type < 0)
pdch->type = SRD_CHANNEL_COMMON;
@ -303,6 +312,12 @@ static int get_options(struct srd_decoder *d)
}
o = g_malloc0(sizeof(struct srd_decoder_option));
o->id = NULL;
o->idn = NULL;
o->desc = NULL;
o->def = NULL;
o->values = NULL;
/* Add to list right away so it doesn't get lost. */
options = g_slist_prepend(options, o);
@ -321,6 +336,11 @@ static int get_options(struct srd_decoder *d)
goto err_out;
}
py_str = PyDict_GetItemString(py_opt, "idn");
if (py_str){
py_str_as_str(py_str, &o->idn);
}
py_default = PyDict_GetItemString(py_opt, "default");
if (py_default) {
gvar = py_obj_to_variant(py_default);

View File

@ -29,6 +29,8 @@
#include "libsigrokdecode.h"
#include <structmember.h>
#define g_safe_free(p) if((p)){g_free((p)); (p) = NULL;}
enum {
SRD_TERM_HIGH,
SRD_TERM_LOW,

View File

@ -234,10 +234,13 @@ struct srd_channel {
int order;
/** The type of the channel, such us: sclk/sdata/.../others */
int type;
/** The language text soruce id. */
char *idn;
};
struct srd_decoder_option {
char *id;
char *idn;
char *desc;
GVariant *def;
GSList *values;