Convert the track name and title from Matroska files to the local charset instead of displaying UTF-8.

This commit is contained in:
Moritz Bunkus 2004-02-21 18:16:25 +00:00
parent 161d3ebaa7
commit e976802eb1
6 changed files with 93 additions and 32 deletions

View File

@ -1,5 +1,12 @@
2004-02-21 Moritz Bunkus <moritz@bunkus.org>
* mmg: bug fix: When adding a Matroska file that contains a track
name or a title with non-ASCII characters those would be displayed
as UTF-8 in the appropriate input boxes. This has been changed,
but obviously it won't work if you add files with Japanese
characters on a system with a different locale. For full Unicode
support you'll have to wait quite a bit longer.
* mmg: bug fix: For some 'browse file' buttons the default
directory was not set to the last directory a file was selected
from.

View File

@ -1266,7 +1266,7 @@ static void identify(const char *filename) {
static void parse_args(int argc, char **argv) {
track_info_c *ti;
int i, j, cc_command_line;
int i, j;
filelist_t *file;
char *s, *this_arg, *next_arg;
audio_sync_t async;
@ -1282,8 +1282,6 @@ static void parse_args(int argc, char **argv) {
memset(attachment, 0, sizeof(attachment_t));
memset(&tags, 0, sizeof(tags_t));
cc_command_line = cc_local_utf8;
// Check if only information about the file is wanted. In this mode only
// two parameters are allowed: the --identify switch and the file.
if (((argc == 2) || (argc == 3)) &&
@ -1351,11 +1349,6 @@ static void parse_args(int argc, char **argv) {
outfile = safestrdup(next_arg);
i++;
} else if (!strcmp(this_arg, "--command-line-charset")) {
if (next_arg == NULL)
mxerror("'--command-line-charset' lacks the charset.\n");
cc_command_line = utf8_init(next_arg);
}
}
@ -1393,14 +1386,11 @@ static void parse_args(int argc, char **argv) {
verbose++;
else if (!strcmp(this_arg, "--title")) {
char *tmp;
if (next_arg == NULL)
mxerror("'--title' lacks the title.\n");
tmp = to_utf8(cc_command_line, next_arg);
segment_title = tmp;
segment_title = next_arg;
segment_title_set = true;
safefree(tmp);
i++;
} else if (!strcmp(this_arg, "--split")) {
@ -1509,7 +1499,7 @@ static void parse_args(int argc, char **argv) {
if (attachment->description != NULL)
mxwarn("More than one description given for a single attachment.\n");
safefree(attachment->description);
attachment->description = to_utf8(cc_command_line, next_arg);
attachment->description = next_arg;
i++;
} else if (!strcmp(this_arg, "--attachment-mime-type")) {
@ -1770,14 +1760,10 @@ static void parse_args(int argc, char **argv) {
i++;
} else if (!strcmp(this_arg, "--track-name")) {
char *utf8;
if (next_arg == NULL)
mxerror("'--track-name' lacks its argument.\n");
parse_language(next_arg, lang, "track-name", "track name", false);
utf8 = to_utf8(cc_command_line, lang.language);
safefree(lang.language);
lang.language = utf8;
ti->track_names->push_back(lang);
i++;
@ -1875,6 +1861,7 @@ static char **add_string(int &num, char **values, const char *new_string) {
static char **read_args_from_file(int &num_args, char **args, char *filename) {
mm_text_io_c *mm_io;
string buffer, opt1, opt2;
bool skip_next;
mm_io = NULL;
try {
@ -1884,7 +1871,12 @@ static char **read_args_from_file(int &num_args, char **args, char *filename) {
"arguments from.", filename);
}
skip_next = false;
while (!mm_io->eof() && mm_io->getline2(buffer)) {
if (skip_next) {
skip_next = false;
continue;
}
strip(buffer);
if (buffer == "#EMPTY#") {
@ -1895,6 +1887,10 @@ static char **read_args_from_file(int &num_args, char **args, char *filename) {
if ((buffer[0] == '#') || (buffer[0] == 0))
continue;
if (buffer == "--command-line-charset") {
skip_next = true;
continue;
}
args = add_string(num_args, args, buffer.c_str());
}
@ -1904,17 +1900,28 @@ static char **read_args_from_file(int &num_args, char **args, char *filename) {
}
static void handle_args(int argc, char **argv) {
int i, num_args;
char **args;
int i, num_args, cc_command_line;
char **args, *utf8;
args = NULL;
num_args = 0;
cc_command_line = cc_local_utf8;
for (i = 1; i < argc; i++)
if (argv[i][0] == '@')
args = read_args_from_file(num_args, args, &argv[i][1]);
else
args = add_string(num_args, args, argv[i]);
else {
if (!strcmp(argv[i], "--command-line-charset")) {
if ((i + 1) == argc)
mxerror("'--command-line-charset' is missing its argument.\n");
cc_command_line = utf8_init(argv[i + 1]);
i++;
} else {
utf8 = to_utf8(cc_command_line, argv[i]);
args = add_string(num_args, args, utf8);
safefree(utf8);
}
}
parse_args(num_args, args);

View File

@ -230,6 +230,18 @@ strip(vector<wxString> &v,
return v;
}
wxString
to_utf8_wx(wxString &src) {
char *utf8;
wxString retval;
utf8 = to_utf8(cc_local_utf8, src.c_str());
retval = utf8;
safefree(utf8);
return retval;
}
mmg_dialog::mmg_dialog(): wxFrame(NULL, -1, "mkvmerge GUI v" VERSION,
wxPoint(0, 0),
#ifdef SYS_WINDOWS
@ -648,16 +660,32 @@ void mmg_dialog::on_save_cmdline(wxCommandEvent &evt) {
}
void mmg_dialog::on_create_optionfile(wxCommandEvent &evt) {
wxFile *file;
uint32_t i;
char *arg_utf8;
mm_io_c *file;
wxFileDialog dlg(NULL, "Choose an output file", last_open_dir, "",
_T(ALLFILES), wxSAVE | wxOVERWRITE_PROMPT);
if(dlg.ShowModal() == wxID_OK) {
last_open_dir = dlg.GetDirectory();
file = new wxFile(dlg.GetPath(), wxFile::write);
try {
file = new mm_io_c(dlg.GetPath().c_str(), MODE_CREATE);
file->write_bom("UTF-8");
} catch (...) {
wxMessageBox("Could not create the specified file.",
"File creation failed", wxOK | wxCENTER |
wxICON_ERROR);
return;
}
for (i = 1; i < clargs.Count(); i++) {
file->Write(clargs[i]);
file->Write("\n");
if (clargs[i].length() == 0)
file->puts_unl("#EMPTY#");
else {
arg_utf8 = to_utf8(cc_local_utf8, clargs[i].c_str());
file->puts_unl(arg_utf8);
safefree(arg_utf8);
}
file->puts_unl("\n");
}
delete file;
@ -697,7 +725,8 @@ void mmg_dialog::update_command_line() {
wxString sid, old_cmdline, arg, aids, sids, dids, track_order;
old_cmdline = cmdline;
cmdline = "\"" + mkvmerge_path + "\" -o \"" + tc_output->GetValue() + "\" ";
cmdline = "\"" + mkvmerge_path + "\" -o \"" + tc_output->GetValue() + "\" " +
"--command-line-charset UTF-8 ";
clargs.Clear();
clargs.Add(mkvmerge_path);
@ -966,6 +995,7 @@ void mmg_dialog::update_command_line() {
cmdline += " " + shell_escape(clargs[i]);
}
cmdline = to_utf8_wx(cmdline);
if (old_cmdline != cmdline)
tc_cmdline->SetValue(cmdline);
}
@ -1121,6 +1151,8 @@ bool mmg_app::OnInit() {
uint32_t i;
wxString k, v;
cc_local_utf8 = utf8_init(NULL);
cfg = new wxConfig("mkvmergeGUI");
wxConfigBase::Set(cfg);
cfg->SetPath("/GUI");
@ -1161,6 +1193,8 @@ int mmg_app::OnExit() {
delete cfg;
utf8_done();
return 0;
}

View File

@ -56,7 +56,7 @@ mux_dialog::mux_dialog(wxWindow *parent):
wxSize(500, 520),
#endif
wxCAPTION) {
char c;
char c, *arg_utf8;
long value;
wxString line, tmp;
wxInputStream *out;
@ -112,6 +112,7 @@ mux_dialog::mux_dialog(wxWindow *parent):
#endif
try {
opt_file = new mm_io_c(opt_file_name.c_str(), MODE_CREATE);
opt_file->write_bom("UTF-8");
} catch (...) {
wxString error;
error.Printf("Could not create a temporary file for mkvmerge's command "
@ -125,8 +126,11 @@ mux_dialog::mux_dialog(wxWindow *parent):
for (i = 1; i < arg_list->Count(); i++) {
if ((*arg_list)[i].Length() == 0)
opt_file->puts_unl("#EMPTY#");
else
opt_file->puts_unl((*arg_list)[i].c_str());
else {
arg_utf8 = to_utf8(cc_local_utf8, (*arg_list)[i].c_str());
opt_file->puts_unl(arg_utf8);
safefree(arg_utf8);
}
opt_file->puts_unl("\n");
}
delete opt_file;

View File

@ -38,7 +38,7 @@ tab_advanced::tab_advanced(wxWindow *parent):
new wxStaticBox(this, -1, _("Other options"),
wxPoint(10, 5), wxSize(475, 50));
new wxStaticText(this, -1, _("Command line charset:"), wxPoint(15, 25));
// new wxStaticText(this, -1, _("Command line charset:"), wxPoint(15, 25));
cob_cl_charset =
new wxComboBox(this, ID_CB_CLCHARSET, "", wxPoint(155, 25),
wxSize(130, -1), 0, NULL, wxCB_DROPDOWN |
@ -52,6 +52,7 @@ tab_advanced::tab_advanced(wxWindow *parent):
"system's current locale. The options that "
"this setting affects are: segment title, "
"track name and attachment description."));
cob_cl_charset->Show(false);
new wxStaticBox(this, -1, _("Advanced options (DO NOT CHANGE!)"),
wxPoint(10, 400), wxSize(475, 62));

View File

@ -531,7 +531,11 @@ void tab_input::on_add_file(wxCommandEvent &evt) {
if (pair.size() != 2)
continue;
if (pair[0] == "track_name") {
*track.track_name = unescape(pair[1].c_str()).c_str();
char *name_local;
name_local =
from_utf8(cc_local_utf8, unescape(pair[1].c_str()).c_str());
*track.track_name = name_local;
safefree(name_local);
track.track_name_was_present = true;
} else if (pair[0] == "language")
*track.language = unescape(pair[1].c_str()).c_str();
@ -579,7 +583,11 @@ void tab_input::on_add_file(wxCommandEvent &evt) {
for (k = 0; k < args.size(); k++) {
pair = split(args[k].c_str(), ":", 2);
if ((pair.size() == 2) && (pair[0] == "title")) {
*file.title = unescape(pair[1].c_str()).c_str();
char *title_local;
title_local =
from_utf8(cc_local_utf8, unescape(pair[1].c_str()).c_str());
*file.title = title_local;
safefree(title_local);
title_was_present = true;
}
}