From 46978a808c7e0309ca4a88f0028669d49eb177a7 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 16 Apr 2025 19:56:48 +0500 Subject: [PATCH 1/6] Disable rich text for `ui_msgbox()`-generated dialogs No strings that gets passed to `ui_msgbox()` use HTML, and it causes newlines to be ignored unless replaced by
`MainWindow::showMessage()` can still accept rich text, but it's now optional and disabled by default --- src/network/network.c | 2 +- src/qt/qt_mainwindow.cpp | 13 +++++++------ src/qt/qt_mainwindow.hpp | 6 +++--- src/qt/qt_openglrenderer.cpp | 10 +++++----- src/qt/qt_ui.cpp | 3 +-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/network/network.c b/src/network/network.c index 047642085..52b686c7e 100644 --- a/src/network/network.c +++ b/src/network/network.c @@ -501,7 +501,7 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin if(net_cards_conf[net_card_current].net_type != NET_TYPE_NONE) { // We're here because of a failure - swprintf(tempmsg, sizeof_w(tempmsg), L"%ls:

%s

%ls", plat_get_string(STRING_NET_ERROR), net_drv_error, plat_get_string(STRING_NET_ERROR_DESC)); + swprintf(tempmsg, sizeof_w(tempmsg), L"%ls:\n\n%s\n\n%ls", plat_get_string(STRING_NET_ERROR), net_drv_error, plat_get_string(STRING_NET_ERROR_DESC)); ui_msgbox(MBX_ERROR, tempmsg); net_cards_conf[net_card_current].net_type = NET_TYPE_NONE; } diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 886f84dcd..760ca7d9b 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -1342,17 +1342,17 @@ MainWindow::refreshMediaMenu() } void -MainWindow::showMessage(int flags, const QString &header, const QString &message) +MainWindow::showMessage(int flags, const QString &header, const QString &message, bool richText) { if (QThread::currentThread() == this->thread()) { if (!cpu_thread_running) { - showMessageForNonQtThread(flags, header, message, nullptr); + showMessageForNonQtThread(flags, header, message, richText, nullptr); } else - showMessage_(flags, header, message); + showMessage_(flags, header, message, richText); } else { std::atomic_bool done = false; - emit showMessageForNonQtThread(flags, header, message, &done); + emit showMessageForNonQtThread(flags, header, message, richText, &done); while (!done) { QThread::msleep(1); } @@ -1360,7 +1360,7 @@ MainWindow::showMessage(int flags, const QString &header, const QString &message } void -MainWindow::showMessage_(int flags, const QString &header, const QString &message, std::atomic_bool *done) +MainWindow::showMessage_(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool *done) { if (done) { *done = false; @@ -1372,7 +1372,8 @@ MainWindow::showMessage_(int flags, const QString &header, const QString &messag } else if (!(flags & (MBX_ERROR | MBX_WARNING))) { box.setIcon(QMessageBox::Warning); } - box.setTextFormat(Qt::TextFormat::RichText); + if (richText) + box.setTextFormat(Qt::TextFormat::RichText); box.exec(); if (done) { *done = true; diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 4b3f9ecae..739d179ff 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -26,7 +26,7 @@ public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); - void showMessage(int flags, const QString &header, const QString &message); + void showMessage(int flags, const QString &header, const QString &message, bool richText); void getTitle(wchar_t *title); void blitToWidget(int x, int y, int w, int h, int monitor_index); QSize getRenderWidgetSize(); @@ -55,7 +55,7 @@ signals: void setFullscreen(bool state); void setMouseCapture(bool state); - void showMessageForNonQtThread(int flags, const QString &header, const QString &message, std::atomic_bool* done); + void showMessageForNonQtThread(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done); void getTitleForNonQtThread(wchar_t *title); public slots: void showSettings(); @@ -123,7 +123,7 @@ private slots: void on_actionRenderer_options_triggered(); void refreshMediaMenu(); - void showMessage_(int flags, const QString &header, const QString &message, std::atomic_bool* done = nullptr); + void showMessage_(int flags, const QString &header, const QString &message, bool richText, std::atomic_bool* done = nullptr); void getTitle_(wchar_t *title); void on_actionMCA_devices_triggered(); diff --git a/src/qt/qt_openglrenderer.cpp b/src/qt/qt_openglrenderer.cpp index 53d29f9a8..45bae6ea7 100644 --- a/src/qt/qt_openglrenderer.cpp +++ b/src/qt/qt_openglrenderer.cpp @@ -200,7 +200,7 @@ OpenGLRenderer::create_program(struct shader_program *program) glw.glGetProgramiv(program->id, GL_INFO_LOG_LENGTH, &maxLength); char *log = (char *) malloc(maxLength); glw.glGetProgramInfoLog(program->id, maxLength, &length, log); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Program not linked:\n\n%1").arg(log).replace("\n", "
")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Program not linked:\n\n%1").arg(log), false); // wx_simple_messagebox("GLSL Error", "Program not linked:\n%s", log); free(log); return 0; @@ -247,7 +247,7 @@ OpenGLRenderer::compile_shader(GLenum shader_type, const char *prepend, const ch glw.glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length); char *log = (char *) malloc(length); glw.glGetShaderInfoLog(shader, length, &length, log); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not compile shader:\n\n%1").arg(log).replace("\n", "
")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not compile shader:\n\n%1").arg(log), false); // wx_simple_messagebox("GLSL Error", "Could not compile shader:\n%s", log); ogl3_log("Could not compile shader: %s\n", log); @@ -651,7 +651,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) if (!load_texture(file, &tex->texture)) { //QMessageBox::critical(main_window, tr("GLSL Error"), tr("Could not load texture: %s").arg(file)); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load texture: %1").arg(file)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load texture: %1").arg(file), false); ogl3_log("Could not load texture %s!\n", file); failed = 1; break; @@ -697,7 +697,7 @@ OpenGLRenderer::load_glslp(glsl_t *glsl, int num_shader, const char *f) ogl3_log("Creating pass %u (%s)\n", (i + 1), pass->alias); ogl3_log("Loading shader %s...\n", shader->shader_fn); if (!shader->shader_program) { - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn)); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("GLSL Error"), tr("Could not load shader: %1").arg(shader->shader_fn), false); // wx_simple_messagebox("GLSL Error", "Could not load shader: %s", shader->shader_fn); ogl3_log("Could not load shader %s\n", shader->shader_fn); failed = 1; @@ -1115,7 +1115,7 @@ OpenGLRenderer::initialize() for (auto &flag : buf_usage) flag.test_and_set(); - main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering.")); + main_window->showMessage(MBX_ERROR | MBX_FATAL, tr("Error initializing OpenGL"), e.what() + tr("\nFalling back to software rendering."), false); context->doneCurrent(); isFinalized = true; diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index b9253663b..57f8001dc 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -142,11 +142,10 @@ ui_msgbox_header(int flags, void *header, void *message) // any error in early init if (main_window == nullptr) { QMessageBox msgBox(QMessageBox::Icon::Critical, hdr, msg); - msgBox.setTextFormat(Qt::TextFormat::RichText); msgBox.exec(); } else { // else scope it to main_window - main_window->showMessage(flags, hdr, msg); + main_window->showMessage(flags, hdr, msg, false); } return 0; } From d5cc259d65c65069fb438ffd1e33116ebe2af610 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 16 Apr 2025 20:47:13 +0500 Subject: [PATCH 2/6] Dev branch: Enable Mitsumi CD-ROM in the UI --- src/cdrom/cdrom.c | 6 ++++++ src/qt/CMakeLists.txt | 4 ++++ src/qt/qt_harddrive_common.cpp | 6 +++--- src/qt/qt_settingsstoragecontrollers.cpp | 9 +++++++++ src/qt/qt_settingsstoragecontrollers.ui | 9 --------- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 0f468bba0..44bf2811c 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -29,6 +29,9 @@ #include <86box/cdrom.h> #include <86box/cdrom_image.h> #include <86box/cdrom_interface.h> +#ifdef USE_CDROM_MITSUMI +#include <86box/cdrom_mitsumi.h> +#endif #include <86box/log.h> #include <86box/plat.h> #include <86box/plat_cdrom_ioctl.h> @@ -117,6 +120,9 @@ static const struct { } controllers[] = { // clang-format off { &cdrom_interface_none_device }, +#ifdef USE_CDROM_MITSUMI + { &mitsumi_cdrom_device }, +#endif { NULL } // clang-format on }; diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index e6e45fc25..f02e3708a 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -207,6 +207,10 @@ if(WACOM) target_compile_definitions(ui PRIVATE USE_WACOM) endif() +if(CDROM_MITSUMI) + target_compile_definitions(ui PRIVATE USE_CDROM_MITSUMI) +endif() + if(WIN32) enable_language(RC) target_sources(86Box PUBLIC 86Box-qt.rc) diff --git a/src/qt/qt_harddrive_common.cpp b/src/qt/qt_harddrive_common.cpp index e0b0233f1..52ae10a98 100644 --- a/src/qt/qt_harddrive_common.cpp +++ b/src/qt/qt_harddrive_common.cpp @@ -51,7 +51,7 @@ void Harddrives::populateRemovableBuses(QAbstractItemModel *model) { model->removeRows(0, model->rowCount()); -#if 0 +#ifdef USE_CDROM_MITSUMI model->insertRows(0, 4); #else model->insertRows(0, 3); @@ -59,14 +59,14 @@ Harddrives::populateRemovableBuses(QAbstractItemModel *model) model->setData(model->index(0, 0), QObject::tr("Disabled")); model->setData(model->index(1, 0), QObject::tr("ATAPI")); model->setData(model->index(2, 0), QObject::tr("SCSI")); -#if 0 +#ifdef USE_CDROM_MITSUMI model->setData(model->index(3, 0), QObject::tr("Mitsumi")); #endif model->setData(model->index(0, 0), HDD_BUS_DISABLED, Qt::UserRole); model->setData(model->index(1, 0), HDD_BUS_ATAPI, Qt::UserRole); model->setData(model->index(2, 0), HDD_BUS_SCSI, Qt::UserRole); -#if 0 +#ifdef USE_CDROM_MITSUMI model->setData(model->index(3, 0), CDROM_BUS_MITSUMI, Qt::UserRole); #endif } diff --git a/src/qt/qt_settingsstoragecontrollers.cpp b/src/qt/qt_settingsstoragecontrollers.cpp index 9bd1bda6f..6fa5906b5 100644 --- a/src/qt/qt_settingsstoragecontrollers.cpp +++ b/src/qt/qt_settingsstoragecontrollers.cpp @@ -142,6 +142,15 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId) ui->comboBoxFD->setCurrentIndex(selectedRow); /*CD interface controller config*/ +#ifdef USE_CDROM_MITSUMI + ui->label_7->setVisible(true); + ui->comboBoxCDInterface->setVisible(true); + ui->pushButtonCDInterface->setVisible(true); +#else + ui->label_7->setVisible(false); + ui->comboBoxCDInterface->setVisible(false); + ui->pushButtonCDInterface->setVisible(false); +#endif c = 0; model = ui->comboBoxCDInterface->model(); removeRows = model->rowCount(); diff --git a/src/qt/qt_settingsstoragecontrollers.ui b/src/qt/qt_settingsstoragecontrollers.ui index 16d6e2494..a167e5bc1 100644 --- a/src/qt/qt_settingsstoragecontrollers.ui +++ b/src/qt/qt_settingsstoragecontrollers.ui @@ -51,9 +51,6 @@ - - false - CD-ROM Controller: @@ -61,9 +58,6 @@ - - false - 30 @@ -71,9 +65,6 @@ - - false - Configure From a4a26f8b56c1f39ef0356032bd2c6657ae3872c9 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 16 Apr 2025 22:04:14 +0500 Subject: [PATCH 3/6] qt: Fix HDD model still being speed in the HDD list --- src/qt/qt_settingsharddisks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/qt_settingsharddisks.cpp b/src/qt/qt_settingsharddisks.cpp index ded50ac34..32b677888 100644 --- a/src/qt/qt_settingsharddisks.cpp +++ b/src/qt/qt_settingsharddisks.cpp @@ -116,7 +116,7 @@ SettingsHarddisks::SettingsHarddisks(QWidget *parent) model->setHeaderData(ColumnHeads, Qt::Horizontal, tr("H")); model->setHeaderData(ColumnSectors, Qt::Horizontal, tr("S")); model->setHeaderData(ColumnSize, Qt::Horizontal, tr("MiB")); - model->setHeaderData(ColumnSpeed, Qt::Horizontal, tr("Speed")); + model->setHeaderData(ColumnSpeed, Qt::Horizontal, tr("Model")); ui->tableView->setModel(model); for (int i = 0; i < HDD_NUM; i++) { From 4160fd6a5a00e649e57d2639ef97fbff757ef8c6 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Wed, 16 Apr 2025 22:23:52 +0500 Subject: [PATCH 4/6] qt: Add colons to dropdown labels on the network settings page For consistency purposes --- src/qt/qt_settingsnetwork.ui | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/qt/qt_settingsnetwork.ui b/src/qt/qt_settingsnetwork.ui index 741b60648..8fb048f71 100644 --- a/src/qt/qt_settingsnetwork.ui +++ b/src/qt/qt_settingsnetwork.ui @@ -58,7 +58,7 @@ - Adapter + Adapter: @@ -84,7 +84,7 @@ - Mode + Mode: @@ -124,14 +124,14 @@ - Interface + Interface: - VDE Socket + VDE Socket: @@ -197,7 +197,7 @@ - Interface + Interface: @@ -217,7 +217,7 @@ - Mode + Mode: @@ -237,7 +237,7 @@ - VDE Socket + VDE Socket: @@ -257,7 +257,7 @@ - Adapter + Adapter: @@ -326,7 +326,7 @@ - VDE Socket + VDE Socket: @@ -362,7 +362,7 @@ - Interface + Interface: @@ -382,7 +382,7 @@ - Mode + Mode: @@ -408,7 +408,7 @@ - Adapter + Adapter: @@ -461,7 +461,7 @@ - Mode + Mode: @@ -481,7 +481,7 @@ - VDE Socket + VDE Socket: @@ -494,7 +494,7 @@ - Adapter + Adapter: @@ -514,7 +514,7 @@ - Interface + Interface: From de35961bb4a14911f64d862448754a245d310d1d Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Thu, 17 Apr 2025 17:20:08 +0500 Subject: [PATCH 5/6] qt: Use Yu Gothic UI as the Japanese font on Windows 10 and later --- src/qt/qt_progsettings.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index 0fce0d705..aa9bbe97b 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -26,6 +26,10 @@ #include #include #include +#ifdef Q_OS_WINDOWS +# include +# include +#endif extern "C" { #include <86box/86box.h> @@ -115,7 +119,11 @@ ProgSettings::getFontName(uint32_t lcid) case 0x0404: /* zh-TW */ return "Microsoft JhengHei"; case 0x0411: /* ja-JP */ - return "Meiryo UI"; + /* Check for Windows 10 or later to choose the appropriate system font */ + if (QVersionNumber::fromString(QSysInfo::kernelVersion()).majorVersion() >= 10) + return "Yu Gothic UI"; + else + return "Meiryo UI"; case 0x0412: /* ko-KR */ return "Malgun Gothic"; case 0x0804: /* zh-CN */ From e1007d2377f572639ac9d847cfca371d2fffac20 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Thu, 17 Apr 2025 21:52:32 +0500 Subject: [PATCH 6/6] Get rid of Windows LCIDs as numeric language IDs --- src/86box.c | 3 +- src/config.c | 6 +-- src/include/86box/86box.h | 8 ++- src/include/86box/plat.h | 4 +- src/qt/qt_platform.cpp | 53 +++--------------- src/qt/qt_progsettings.cpp | 108 ++++++++++++++++++++++++++----------- src/qt/qt_progsettings.hpp | 16 +++--- src/unix/unix.c | 10 ++-- 8 files changed, 106 insertions(+), 102 deletions(-) diff --git a/src/86box.c b/src/86box.c index ad1cfc519..168e8a8dc 100644 --- a/src/86box.c +++ b/src/86box.c @@ -160,6 +160,7 @@ int window_remember; int vid_resize; /* (C) allow resizing */ int invert_display = 0; /* (C) invert the display */ int suppress_overscan = 0; /* (C) suppress overscans */ +int lang_id = 0; /* (C) language id */ int scale = 0; /* (C) screen scale factor */ int dpi_scale = 0; /* (C) DPI scaling of the emulated screen */ @@ -584,7 +585,7 @@ pc_init(int argc, char *argv[]) uint32_t *uid; uint32_t *shwnd; #endif - uint32_t lang_init = 0; + int lang_init = 0; /* Grab the executable's full path. */ plat_get_exe_name(exe_path, sizeof(exe_path) - 1); diff --git a/src/config.c b/src/config.c index 6f023cf67..b3de77d71 100644 --- a/src/config.c +++ b/src/config.c @@ -186,7 +186,7 @@ load_general(void) if (p != NULL) lang_id = plat_language_code(p); else - lang_id = 0xffff; + lang_id = plat_language_code(DEFAULT_LANGUAGE); mouse_sensitivity = ini_section_get_double(cat, "mouse_sensitivity", 1.0); if (mouse_sensitivity < 0.1) @@ -1842,7 +1842,7 @@ config_load(void) cassette_pcm = 0; cassette_ui_writeprot = 0; - lang_id = DEFAULT_LANGUAGE; + lang_id = plat_language_code(DEFAULT_LANGUAGE); config_log("Config file not present or invalid!\n"); } else { @@ -2029,7 +2029,7 @@ save_general(void) else ini_section_delete_var(cat, "mouse_sensitivity"); - if (lang_id == DEFAULT_LANGUAGE) + if (lang_id == plat_language_code(DEFAULT_LANGUAGE)) ini_section_delete_var(cat, "language"); else { plat_language_code_r(lang_id, buffer, 511); diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index ddca937f1..c85311688 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -44,8 +44,8 @@ /* Max UUID Length */ #define MAX_UUID_LEN 64 -/* Default language 0xFFFF = from system, 0x409 = en-US */ -#define DEFAULT_LANGUAGE 0xffff +/* Default language code */ +#define DEFAULT_LANGUAGE "system" #define POSTCARDS_NUM 4 #define POSTCARD_MASK (POSTCARDS_NUM - 1) @@ -84,8 +84,6 @@ extern "C" { #endif /* Global variables. */ -extern uint32_t lang_sys; /* (-) system language code */ - extern int dump_on_exit; /* (O) dump regs on exit*/ extern int start_in_fullscreen; /* (O) start in fullscreen */ #ifdef _WIN32 @@ -117,7 +115,7 @@ extern int window_remember; extern int vid_resize; /* (C) allow resizing */ extern int invert_display; /* (C) invert the display */ extern int suppress_overscan; /* (C) suppress overscans */ -extern uint32_t lang_id; /* (C) language code identifier */ +extern int lang_id; /* (C) language id */ extern int scale; /* (C) screen scale factor */ extern int dpi_scale; /* (C) DPI scaling of the emulated screen */ extern int vid_api; /* (C) video renderer */ diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 7ed6e80d4..bbc673dcf 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -160,8 +160,8 @@ extern int plat_vidapi(const char *name); extern char *plat_vidapi_name(int api); extern void plat_resize(int x, int y, int monitor_index); extern void plat_resize_request(int x, int y, int monitor_index); -extern uint32_t plat_language_code(char *langcode); -extern void plat_language_code_r(uint32_t lcid, char *outbuf, int len); +extern int plat_language_code(char *langcode); +extern void plat_language_code_r(int id, char *outbuf, int len); extern void plat_get_cpu_string(char *outbuf, uint8_t len); extern void plat_set_thread_name(void *thread, const char *name); extern void plat_break(void); diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index e8a02fc3b..0f792feda 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -140,7 +140,6 @@ int update_icons = 1; int kbd_req_capture = 0; int hide_status_bar = 0; int hide_tool_bar = 0; -uint32_t lang_id = 0x0409, lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US int stricmp(const char *s1, const char *s2) @@ -461,58 +460,18 @@ plat_power_off(void) QTimer::singleShot(0, (const QWidget *) main_window, &QMainWindow::close); } -extern "C++" { -QMap> ProgSettings::lcid_langcode = { - { 0x0403, { "ca-ES", "Catalan (Spain)" } }, - { 0x0804, { "zh-CN", "Chinese (Simplified)" } }, - { 0x0404, { "zh-TW", "Chinese (Traditional)" } }, - { 0x041A, { "hr-HR", "Croatian (Croatia)" } }, - { 0x0405, { "cs-CZ", "Czech (Czech Republic)" } }, - { 0x0407, { "de-DE", "German (Germany)" } }, - { 0x0809, { "en-GB", "English (United Kingdom)" }}, - { 0x0409, { "en-US", "English (United States)" } }, - { 0x040B, { "fi-FI", "Finnish (Finland)" } }, - { 0x040C, { "fr-FR", "French (France)" } }, - { 0x040E, { "hu-HU", "Hungarian (Hungary)" } }, - { 0x0410, { "it-IT", "Italian (Italy)" } }, - { 0x0411, { "ja-JP", "Japanese (Japan)" } }, - { 0x0412, { "ko-KR", "Korean (Korea)" } }, - { 0x0413, { "nl-NL", "Dutch (Netherlands)" } }, - { 0x0415, { "pl-PL", "Polish (Poland)" } }, - { 0x0416, { "pt-BR", "Portuguese (Brazil)" } }, - { 0x0816, { "pt-PT", "Portuguese (Portugal)" } }, - { 0x0419, { "ru-RU", "Russian (Russia)" } }, - { 0x041B, { "sk-SK", "Slovak (Slovakia)" } }, - { 0x0424, { "sl-SI", "Slovenian (Slovenia)" } }, - { 0x0C0A, { "es-ES", "Spanish (Spain, Modern Sort)" } }, - { 0x041F, { "tr-TR", "Turkish (Turkey)" } }, - { 0x0422, { "uk-UA", "Ukrainian (Ukraine)" } }, - { 0x042A, { "vi-VN", "Vietnamese (Vietnam)" } }, - { 0xFFFF, { "system", "(System Default)" } }, -}; -} - -/* Sets up the program language before initialization. */ -uint32_t +/* Converts the language code string to a numeric language ID */ +int plat_language_code(char *langcode) { - for (auto &curKey : ProgSettings::lcid_langcode.keys()) { - if (ProgSettings::lcid_langcode[curKey].first == langcode) { - return curKey; - } - } - return 0xFFFF; + return ProgSettings::languageCodeToId(QString(langcode)); } -/* Converts back the language code to LCID */ +/* Converts the numeric language ID to a language code string */ void -plat_language_code_r(uint32_t lcid, char *outbuf, int len) +plat_language_code_r(int id, char *outbuf, int len) { - if (!ProgSettings::lcid_langcode.contains(lcid)) { - qstrncpy(outbuf, "system", len); - return; - } - qstrncpy(outbuf, ProgSettings::lcid_langcode[lcid].first.toUtf8().constData(), len); + qstrncpy(outbuf, ProgSettings::languageIdToCode(id).toUtf8().constData(), len); return; } diff --git a/src/qt/qt_progsettings.cpp b/src/qt/qt_progsettings.cpp index aa9bbe97b..3903c9d9f 100644 --- a/src/qt/qt_progsettings.cpp +++ b/src/qt/qt_progsettings.cpp @@ -45,18 +45,45 @@ extern MainWindow *main_window; ProgSettings::CustomTranslator *ProgSettings::translator = nullptr; QTranslator *ProgSettings::qtTranslator = nullptr; +QVector> ProgSettings::languages = { + { "system", "(System Default)" }, + { "ca-ES", "Catalan (Spain)" }, + { "zh-CN", "Chinese (Simplified)" }, + { "zh-TW", "Chinese (Traditional)" }, + { "hr-HR", "Croatian (Croatia)" }, + { "cs-CZ", "Czech (Czech Republic)" }, + { "de-DE", "German (Germany)" }, + { "en-GB", "English (United Kingdom)" }, + { "en-US", "English (United States)" }, + { "fi-FI", "Finnish (Finland)" }, + { "fr-FR", "French (France)" }, + { "hu-HU", "Hungarian (Hungary)" }, + { "it-IT", "Italian (Italy)" }, + { "ja-JP", "Japanese (Japan)" }, + { "ko-KR", "Korean (Korea)" }, + { "nl-NL", "Dutch (Netherlands)" }, + { "pl-PL", "Polish (Poland)" }, + { "pt-BR", "Portuguese (Brazil)" }, + { "pt-PT", "Portuguese (Portugal)" }, + { "ru-RU", "Russian (Russia)" }, + { "sk-SK", "Slovak (Slovakia)" }, + { "sl-SI", "Slovenian (Slovenia)" }, + { "es-ES", "Spanish (Spain)" }, + { "tr-TR", "Turkish (Turkey)" }, + { "uk-UA", "Ukrainian (Ukraine)" }, + { "vi-VN", "Vietnamese (Vietnam)" }, +}; + ProgSettings::ProgSettings(QWidget *parent) : QDialog(parent) , ui(new Ui::ProgSettings) { ui->setupUi(this); - ui->comboBoxLanguage->setItemData(0, 0xFFFF); - for (auto i = lcid_langcode.begin(); i != lcid_langcode.end(); i++) { - if (i.key() == 0xFFFF) - continue; - ui->comboBoxLanguage->addItem(lcid_langcode[i.key()].second, i.key()); - if (i.key() == lang_id) { - ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i.key())); + ui->comboBoxLanguage->setItemData(0, 0); + for (int i = 1; i < languages.length(); i++) { + ui->comboBoxLanguage->addItem(languages[i].second, i); + if (i == lang_id) { + ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(i)); } } ui->comboBoxLanguage->model()->sort(Qt::AscendingOrder); @@ -78,7 +105,7 @@ ProgSettings::ProgSettings(QWidget *parent) void ProgSettings::accept() { - lang_id = ui->comboBoxLanguage->currentData().toUInt(); + lang_id = ui->comboBoxLanguage->currentData().toInt(); open_dir_usr_path = ui->openDirUsrPath->isChecked() ? 1 : 0; confirm_exit = ui->checkBoxConfirmExit->isChecked() ? 1 : 0; confirm_save = ui->checkBoxConfirmSave->isChecked() ? 1 : 0; @@ -113,27 +140,46 @@ ProgSettings::~ProgSettings() /* Return the standard font name on Windows, which is overridden per-language to prevent CJK fonts with embedded bitmaps being chosen as a fallback. */ QString -ProgSettings::getFontName(uint32_t lcid) +ProgSettings::getFontName(int langId) { - switch (lcid) { - case 0x0404: /* zh-TW */ - return "Microsoft JhengHei"; - case 0x0411: /* ja-JP */ - /* Check for Windows 10 or later to choose the appropriate system font */ - if (QVersionNumber::fromString(QSysInfo::kernelVersion()).majorVersion() >= 10) - return "Yu Gothic UI"; - else - return "Meiryo UI"; - case 0x0412: /* ko-KR */ - return "Malgun Gothic"; - case 0x0804: /* zh-CN */ - return "Microsoft YaHei"; - default: - return "Segoe UI"; - } + QString langCode = languageIdToCode(lang_id); + if (langCode == "ja-JP") { + /* Check for Windows 10 or later to choose the appropriate system font */ + if (QVersionNumber::fromString(QSysInfo::kernelVersion()).majorVersion() >= 10) + return "Yu Gothic UI"; + else + return "Meiryo UI"; + } else if (langCode == "ko-KR") + return "Malgun Gothic"; + else if (langCode == "zh-CN") + return "Microsoft YaHei"; + else if (langCode == "zh-TW") + return "Microsoft JhengHei"; + else + return "Segoe UI"; } #endif +int +ProgSettings::languageCodeToId(QString langCode) +{ + for (int i = 0; i < languages.length(); i++) { + if (languages[i].first == langCode) { + return i; + } + } + return 0; +} + +QString +ProgSettings::languageIdToCode(int id) +{ + if ((id == 0) || (id >= languages.length())) { + return "system"; + } + return languages[id].first; +} + void ProgSettings::loadTranslators(QObject *parent) { @@ -148,7 +194,7 @@ ProgSettings::loadTranslators(QObject *parent) qtTranslator = new QTranslator(parent); translator = new CustomTranslator(parent); QString localetofilename = ""; - if (lang_id == 0xFFFF || lcid_langcode.contains(lang_id) == false) { + if (lang_id == 0 || lang_id >= languages.length()) { for (int i = 0; i < QLocale::system().uiLanguages().size(); i++) { localetofilename = QLocale::system().uiLanguages()[i]; if (translator->load(QLatin1String("86box_") + localetofilename, QLatin1String(":/"))) { @@ -166,12 +212,12 @@ ProgSettings::loadTranslators(QObject *parent) } } } else { - translator->load(QLatin1String("86box_") + lcid_langcode[lang_id].first, QLatin1String(":/")); + translator->load(QLatin1String("86box_") + languages[lang_id].first, QLatin1String(":/")); QCoreApplication::installTranslator(translator); - if (!qtTranslator->load(QLatin1String("qtbase_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - if (!qtTranslator->load(QLatin1String("qtbase_") + QString(lcid_langcode[lang_id].first).left(QString(lcid_langcode[lang_id].first).indexOf('-')), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) - if(!qtTranslator->load(QLatin1String("qt_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QApplication::applicationDirPath() + "/./translations/")) - qtTranslator->load(QLatin1String("qt_") + QString(lcid_langcode[lang_id].first).replace('-', '_'), QLatin1String(":/")); + if (!qtTranslator->load(QLatin1String("qtbase_") + QString(languages[lang_id].first).replace('-', '_'), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + if (!qtTranslator->load(QLatin1String("qtbase_") + QString(languages[lang_id].first).left(QString(languages[lang_id].first).indexOf('-')), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) + if(!qtTranslator->load(QLatin1String("qt_") + QString(languages[lang_id].first).replace('-', '_'), QApplication::applicationDirPath() + "/./translations/")) + qtTranslator->load(QLatin1String("qt_") + QString(languages[lang_id].first).replace('-', '_'), QLatin1String(":/")); QCoreApplication::installTranslator(qtTranslator); } diff --git a/src/qt/qt_progsettings.hpp b/src/qt/qt_progsettings.hpp index 1c7295f56..31600e7f1 100644 --- a/src/qt/qt_progsettings.hpp +++ b/src/qt/qt_progsettings.hpp @@ -15,10 +15,12 @@ public: explicit ProgSettings(QWidget *parent = nullptr); ~ProgSettings(); #ifdef Q_OS_WINDOWS - static QString getFontName(uint32_t lcid); + static QString getFontName(int langId); #endif - static void loadTranslators(QObject *parent = nullptr); - static void reloadStrings(); + static int languageCodeToId(QString langCode); + static QString languageIdToCode(int id); + static void loadTranslators(QObject *parent = nullptr); + static void reloadStrings(); class CustomTranslator : public QTranslator { public: CustomTranslator(QObject *parent = nullptr) @@ -31,10 +33,10 @@ public: return QTranslator::translate("", sourceText, disambiguation, n); } }; - static CustomTranslator *translator; - static QTranslator *qtTranslator; - static QMap> lcid_langcode; - static QMap translatedstrings; + static CustomTranslator *translator; + static QTranslator *qtTranslator; + static QVector> languages; + static QMap translatedstrings; protected slots: void accept() override; diff --git a/src/unix/unix.c b/src/unix/unix.c index c41aee2a4..395e6f540 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -71,8 +71,6 @@ SDL_mutex *blitmtx; SDL_threadID eventthread; static int exit_event = 0; static int fullscreen_pending = 0; -uint32_t lang_id = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US -uint32_t lang_sys = 0x0409; // Multilangual UI variables, for now all set to LCID of en-US static const uint16_t sdl_to_xt[0x200] = { [SDL_SCANCODE_ESCAPE] = 0x01, @@ -1378,8 +1376,8 @@ plat_vidapi_name(UNUSED(int i)) return "default"; } -/* Sets up the program language before initialization. */ -uint32_t +/* Converts the language code string to a numeric language ID */ +int plat_language_code(UNUSED(char *langcode)) { /* or maybe not */ @@ -1419,9 +1417,9 @@ plat_set_thread_name(void *thread, const char *name) #endif } -/* Converts back the language code to LCID */ +/* Converts the numeric language ID to a language code string */ void -plat_language_code_r(UNUSED(uint32_t lcid), UNUSED(char *outbuf), UNUSED(int len)) +plat_language_code_r(UNUSED(int id), UNUSED(char *outbuf), UNUSED(int len)) { /* or maybe not */ return;