mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-13 13:32:53 +08:00
The decdoer info surports mutil-language
This commit is contained in:
parent
d04f66d7a4
commit
161f7168d2
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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,14 +361,21 @@ 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);
|
||||
@ -366,14 +385,21 @@ void DecoderOptionsDlg::create_decoder_form(
|
||||
|
||||
// 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);
|
||||
|
@ -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,
|
||||
|
@ -1501,10 +1501,14 @@ namespace pv
|
||||
{
|
||||
QString ses_name = dir.absolutePath() + "/"
|
||||
+ _device_agent->driver_name() + QString::number(mode) + ".dsc";
|
||||
|
||||
QFile sf(ses_name);
|
||||
if (sf.exists()){
|
||||
on_load_session(ses_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QJsonDocument MainWindow::get_session_json_from_file(QString 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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user