Added "default values" for chapter language and country codes.

This commit is contained in:
Moritz Bunkus 2003-12-02 14:56:16 +00:00
parent 67c6c6c5fd
commit 7d21ef1d6d
3 changed files with 134 additions and 8 deletions

View File

@ -1075,6 +1075,11 @@ bool mmg_app::OnInit() {
if (cfg->Read(k, &v))
last_chapters.push_back(v);
}
cfg->SetPath("/chapter_editor");
if (cfg->Read("default_language", &k))
tab_chapters::default_language = k;
if (cfg->Read("default_country", &k))
tab_chapters::default_country = k;
app = this;
mdlg = new mmg_dialog();
@ -1090,6 +1095,9 @@ int mmg_app::OnExit() {
cfg = wxConfigBase::Get();
cfg->SetPath("/GUI");
cfg->Write("last_directory", last_open_dir);
cfg->SetPath("/chapter_editor");
cfg->Write("default_language", tab_chapters::default_language);
cfg->Write("default_country", tab_chapters::default_country);
cfg->Flush();
delete cfg;

View File

@ -382,6 +382,8 @@ public:
kax_analyzer_c *analyzer;
static wxString default_language, default_country;
public:
tab_chapters(wxWindow *parent, wxMenu *nm_chapters);
~tab_chapters();
@ -405,6 +407,8 @@ public:
bool verify_atom_recursively(EbmlElement *e, int64_t p_start = -1,
int64_t p_end = -1);
bool verify();
void verify_language_codes(string s, vector<string> &parts);
void verify_country_codes(string s, vector<string> &parts);
void add_recursively(wxTreeItemId &parent, EbmlMaster &master);
wxString create_chapter_label(KaxChapterAtom &chapter);
void fix_missing_languages(EbmlMaster &master);

View File

@ -41,6 +41,9 @@ using namespace std;
using namespace libebml;
using namespace libmatroska;
wxString tab_chapters::default_language = "";
wxString tab_chapters::default_country = "";
class chapter_node_data_c: public wxTreeItemData {
public:
bool is_atom;
@ -60,21 +63,61 @@ public:
class chapter_values_dlg: public wxDialog {
public:
wxTextCtrl tc_language, tc_country;
wxTextCtrl *tc_language, *tc_country;
public:
chapter_values_dlg(wxWindow *parent, bool set_defaults);
chapter_values_dlg(wxWindow *parent, bool set_defaults,
wxString old_def_language = "",
wxString old_def_country = "");
};
chapter_values_dlg::chapter_values_dlg(wxWindow *parent, bool set_defaults):
chapter_values_dlg::chapter_values_dlg(wxWindow *parent, bool set_defaults,
wxString old_def_language,
wxString old_def_country):
wxDialog(parent, 0, "") {
SetSize(400, 200);
wxButton *b_ok, *b_cancel;
wxPanel *panel;
SetSize(350, 200);
panel = new wxPanel(this, -1);
if (set_defaults) {
new wxStaticText(this, wxID_STATIC,
"Chapters:",
wxPoint(10, 5),
wxDefaultSize, 0);
SetTitle("Change the default values");
new wxStaticText(panel, wxID_STATIC,
"Here you can set the default values that mmg will use\n"
"for each chapter that you create. These values can\n"
"then be changed if needed. The default values will be\n"
"saved when you exit mmg.",
wxPoint(10, 10), wxSize(380, 100), 0);
} else {
SetTitle("Select values to be applied");
new wxStaticText(panel, wxID_STATIC,
"Please enter the values for the language and the\n"
"country that you want to apply to all the chapters\n"
"below and including the currently selected entry.",
wxPoint(10, 10), wxSize(380, 100), 0);
}
new wxStaticText(panel, wxID_STATIC, "Language:", wxPoint(10, 90));
tc_language =
new wxTextCtrl(panel, wxID_STATIC, old_def_language, wxPoint(90, 90),
wxSize(220, -1));
new wxStaticText(panel, wxID_STATIC, "Country:", wxPoint(10, 125));
tc_country =
new wxTextCtrl(panel, wxID_STATIC, old_def_country, wxPoint(90, 125),
wxSize(220, -1));
b_ok = new wxButton(panel, wxID_OK, "Ok", wxPoint(0, 0));
b_ok->SetDefault();
b_cancel = new wxButton(panel, wxID_CANCEL, "Cancel", wxPoint(0, 0));
b_ok->SetSize(b_cancel->GetSize());
b_ok->Move(wxPoint(GetSize().GetWidth() / 2 - b_ok->GetSize().GetWidth() -
b_cancel->GetSize().GetWidth() / 2,
GetSize().GetHeight() -
b_ok->GetSize().GetHeight() * 3 / 2));
b_cancel->Move(wxPoint(GetSize().GetWidth() / 2 +
b_cancel->GetSize().GetWidth() / 2,
GetSize().GetHeight() -
b_ok->GetSize().GetHeight() * 3 / 2));
}
void expand_subtree(wxTreeCtrl &tree, wxTreeItemId &root, bool expand = true) {
@ -687,6 +730,15 @@ void tab_chapters::on_add_chapter(wxCommandEvent &evt) {
delete (*chapter)[0];
chapter->Remove(0);
}
if ((default_language.Length() > 0) || (default_country.Length() > 0)) {
KaxChapterDisplay &display = GetEmptyChild<KaxChapterDisplay>(*chapter);
if (default_language.Length() > 0)
*static_cast<EbmlString *>(&GetChild<KaxChapterLanguage>(display)) =
default_language.c_str();
if (default_country.Length() > 0)
*static_cast<EbmlString *>(&GetChild<KaxChapterCountry>(display)) =
default_country.c_str();
}
s = create_chapter_label(*chapter);
if (d->is_atom) {
@ -755,6 +807,15 @@ void tab_chapters::on_add_subchapter(wxCommandEvent &evt) {
delete (*chapter)[0];
chapter->Remove(0);
}
if ((default_language.Length() > 0) || (default_country.Length() > 0)) {
KaxChapterDisplay &display = GetEmptyChild<KaxChapterDisplay>(*chapter);
if (default_language.Length() > 0)
*static_cast<EbmlString *>(&GetChild<KaxChapterLanguage>(display)) =
default_language.c_str();
if (default_country.Length() > 0)
*static_cast<EbmlString *>(&GetChild<KaxChapterCountry>(display)) =
default_country.c_str();
}
m->PushElement(*chapter);
s = create_chapter_label(*chapter);
tc_chapters->AppendItem(id, s, -1, -1,
@ -905,7 +966,60 @@ void tab_chapters::on_country_code_selected(wxCommandEvent &evt) {
tc_country_codes->AppendText(cob_add_country_code->GetStringSelection());
}
void tab_chapters::verify_language_codes(string s, vector<string> &parts) {
uint32_t i;
vector<string>::iterator eit;
strip(s);
parts = split(s.c_str(), " ");
i = 0;
while (i < parts.size())
if (!is_valid_iso639_2_code(parts[i].c_str())) {
wxMessageBox(wxString("'") + parts[i].c_str() +
wxString("' is not a valid ISO639-2 language code. "
"Removing this entry."),
_("Input data error"), wxOK | wxCENTER | wxICON_ERROR);
eit = parts.begin();
eit += i;
parts.erase(eit);
} else
i++;
}
void tab_chapters::verify_country_codes(string s, vector<string> &parts) {
uint32_t i;
vector<string>::iterator eit;
strip(s);
parts = split(s.c_str(), " ");
i = 0;
while (i < parts.size())
if ((parts[i].length() != 2) ||
(parts[i][0] < 'a') || (parts[i][0] > 'z') ||
(parts[i][1] < 'a') || (parts[i][1] > 'z')) {
wxMessageBox(wxString("'") + parts[i].c_str() +
wxString("' is not a valid two-letter country "
"code. Removing this entry."),
_("Input data error"), wxOK | wxCENTER | wxICON_ERROR);
eit = parts.begin();
eit += i;
parts.erase(eit);
} else
i++;
}
void tab_chapters::on_set_default_values(wxCommandEvent &evt) {
vector<string> parts;
chapter_values_dlg dlg(this, true, default_language, default_country);
if (dlg.ShowModal() != wxID_OK)
return;
verify_language_codes(dlg.tc_language->GetValue().c_str(), parts);
default_language = join(" ", parts).c_str();
verify_country_codes(dlg.tc_country->GetValue().c_str(), parts);
default_country = join(" ", parts).c_str();
}
bool tab_chapters::copy_values(wxTreeItemId id) {