From 046d7dd61e08603cc0cc73e9de9454523081508a Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 29 Dec 2003 18:43:11 +0000 Subject: [PATCH] Made the chapter parser for simple/OGM style chapters honour the default values for language and country. --- src/common/chapters.cpp | 16 ++++++++++++++-- src/common/chapters.h | 2 ++ src/mmg/mmg.cpp | 9 +++++---- src/mmg/mmg.h | 2 -- src/mmg/tab_chapters.cpp | 32 ++++++++++++++++---------------- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/common/chapters.cpp b/src/common/chapters.cpp index d94bff948..bcb2491c4 100644 --- a/src/common/chapters.cpp +++ b/src/common/chapters.cpp @@ -32,6 +32,9 @@ using namespace std; using namespace libmatroska; +string default_chapter_language; +string default_chapter_country; + // {{{ defines for chapter line recognition #define isequal(s) (*(s) == '=') @@ -152,8 +155,12 @@ KaxChapters *parse_simple_chapters(mm_text_io_c *in, int64_t min_tc, } else do_convert = false; - if (language == NULL) - language = "eng"; + if (language == NULL) { + if (default_chapter_language.length() > 0) + language = default_chapter_language.c_str(); + else + language = "eng"; + } try { while (in->getline2(line)) { @@ -212,6 +219,11 @@ KaxChapters *parse_simple_chapters(mm_text_io_c *in, int64_t min_tc, *static_cast(&GetChild(*display)) = language; + if (default_chapter_country.length() > 0) + *static_cast + (&GetChild(*display)) = + default_chapter_country; + num++; } } diff --git a/src/common/chapters.h b/src/common/chapters.h index ac10e62b1..baff906c9 100644 --- a/src/common/chapters.h +++ b/src/common/chapters.h @@ -65,5 +65,7 @@ KaxChapters *select_chapters_in_timeframe(KaxChapters *chapters, int64_t min_tc, int64_t max_tc, int64_t offset, bool validate); +extern string default_chapter_language, default_chapter_country; + #endif // __CHAPTERS_H diff --git a/src/mmg/mmg.cpp b/src/mmg/mmg.cpp index 12b9b8060..52a810e39 100644 --- a/src/mmg/mmg.cpp +++ b/src/mmg/mmg.cpp @@ -34,6 +34,7 @@ #include "wx/statline.h" #include "mmg.h" +#include "chapters.h" #include "common.h" #ifdef SYS_UNIX #include "matroskalogo_big.xpm" @@ -1114,9 +1115,9 @@ bool mmg_app::OnInit() { } cfg->SetPath("/chapter_editor"); if (cfg->Read("default_language", &k)) - tab_chapters::default_language = k; + default_chapter_language = k.c_str(); if (cfg->Read("default_country", &k)) - tab_chapters::default_country = k; + default_chapter_country = k.c_str(); app = this; mdlg = new mmg_dialog(); @@ -1133,8 +1134,8 @@ int mmg_app::OnExit() { 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->Write("default_language", default_chapter_language.c_str()); + cfg->Write("default_country", default_chapter_country.c_str()); cfg->Flush(); delete cfg; diff --git a/src/mmg/mmg.h b/src/mmg/mmg.h index 8c3247a13..ee59ee374 100644 --- a/src/mmg/mmg.h +++ b/src/mmg/mmg.h @@ -395,8 +395,6 @@ public: kax_analyzer_c *analyzer; - static wxString default_language, default_country; - public: tab_chapters(wxWindow *parent, wxMenu *nm_chapters); ~tab_chapters(); diff --git a/src/mmg/tab_chapters.cpp b/src/mmg/tab_chapters.cpp index 2e09ff2ca..6d3bc7577 100644 --- a/src/mmg/tab_chapters.cpp +++ b/src/mmg/tab_chapters.cpp @@ -41,9 +41,6 @@ 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; @@ -781,14 +778,15 @@ void tab_chapters::on_add_chapter(wxCommandEvent &evt) { delete (*chapter)[0]; chapter->Remove(0); } - if ((default_language.Length() > 0) || (default_country.Length() > 0)) { + if ((default_chapter_language.length() > 0) || + (default_chapter_country.length() > 0)) { KaxChapterDisplay &display = GetEmptyChild(*chapter); - if (default_language.Length() > 0) + if (default_chapter_language.length() > 0) *static_cast(&GetChild(display)) = - default_language.c_str(); - if (default_country.Length() > 0) + default_chapter_language.c_str(); + if (default_chapter_country.length() > 0) *static_cast(&GetChild(display)) = - default_country.c_str(); + default_chapter_country.c_str(); } s = create_chapter_label(*chapter); @@ -858,14 +856,15 @@ void tab_chapters::on_add_subchapter(wxCommandEvent &evt) { delete (*chapter)[0]; chapter->Remove(0); } - if ((default_language.Length() > 0) || (default_country.Length() > 0)) { + if ((default_chapter_language.length() > 0) || + (default_chapter_country.length() > 0)) { KaxChapterDisplay &display = GetEmptyChild(*chapter); - if (default_language.Length() > 0) + if (default_chapter_language.length() > 0) *static_cast(&GetChild(display)) = - default_language.c_str(); - if (default_country.Length() > 0) + default_chapter_language.c_str(); + if (default_chapter_country.length() > 0) *static_cast(&GetChild(display)) = - default_country.c_str(); + default_chapter_country.c_str(); } m->PushElement(*chapter); s = create_chapter_label(*chapter); @@ -1063,16 +1062,17 @@ void tab_chapters::verify_country_codes(string s, vector &parts) { void tab_chapters::on_set_default_values(wxCommandEvent &evt) { vector parts; - chapter_values_dlg dlg(this, true, default_language, default_country); + chapter_values_dlg dlg(this, true, default_chapter_language.c_str(), + default_chapter_country.c_str()); if (dlg.ShowModal() != wxID_OK) return; verify_language_codes(dlg.tc_language->GetValue().c_str(), parts); - default_language = join(" ", parts).c_str(); + default_chapter_language = join(" ", parts); verify_country_codes(dlg.tc_country->GetValue().c_str(), parts); - default_country = join(" ", parts).c_str(); + default_chapter_country = join(" ", parts); } void tab_chapters::set_values_recursively(wxTreeItemId id, string &s,