From 44b05d450c269de945721fd5b1d6eaf61799c63f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 10 Jun 2022 05:22:00 +0300 Subject: [PATCH 14/14] gtk: Add logging about gtk initialization failure Both gtk clients and modpack installers changed. See osdn #44118 Signed-off-by: Marko Lindqvist --- client/gui-gtk-2.0/gui_main.c | 5 +++- client/gui-gtk-3.0/gui_main.c | 5 +++- client/gui-gtk-3.22/gui_main.c | 5 +++- tools/mpgui_gtk2.c | 51 ++++++++++++++++++---------------- tools/mpgui_gtk3.c | 51 ++++++++++++++++++---------------- 5 files changed, 66 insertions(+), 51 deletions(-) diff --git a/client/gui-gtk-2.0/gui_main.c b/client/gui-gtk-2.0/gui_main.c index 608b84beef..8e2b619dc1 100644 --- a/client/gui-gtk-2.0/gui_main.c +++ b/client/gui-gtk-2.0/gui_main.c @@ -1530,7 +1530,10 @@ void ui_main(int argc, char **argv) gtk_disable_setlocale(); /* GTK withdraw gtk options. Process GTK arguments */ - gtk_init(&argc, &argv); + if (!gtk_init_check(&argc, &argv)) { + log_fatal(_("Failed to open graphical mode.")); + exit(EXIT_FAILURE); + } /* Load resources */ gtk_rc_parse_string(fallback_resources); diff --git a/client/gui-gtk-3.0/gui_main.c b/client/gui-gtk-3.0/gui_main.c index d95a257961..a5f9605a9c 100644 --- a/client/gui-gtk-3.0/gui_main.c +++ b/client/gui-gtk-3.0/gui_main.c @@ -1714,7 +1714,10 @@ void ui_main(int argc, char **argv) gtk_disable_setlocale(); /* GTK withdraw gtk options. Process GTK arguments */ - gtk_init(&argc, &argv); + if (!gtk_init_check(&argc, &argv)) { + log_fatal(_("Failed to open graphical mode.")); + exit(EXIT_FAILURE); + } toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_position(GTK_WINDOW(toplevel), GTK_WIN_POS_CENTER); diff --git a/client/gui-gtk-3.22/gui_main.c b/client/gui-gtk-3.22/gui_main.c index 8495aed360..94887c7369 100644 --- a/client/gui-gtk-3.22/gui_main.c +++ b/client/gui-gtk-3.22/gui_main.c @@ -1794,7 +1794,10 @@ void ui_main(int argc, char **argv) gtk_disable_setlocale(); /* GTK withdraw gtk options. Process GTK arguments */ - gtk_init(&argc, &argv); + if (!gtk_init_check(&argc, &argv)) { + log_fatal(_("Failed to open graphical mode.")); + exit(EXIT_FAILURE); + } dlg_tab_provider_prepare(); diff --git a/tools/mpgui_gtk2.c b/tools/mpgui_gtk2.c index 3e03613613..89473a8bd6 100644 --- a/tools/mpgui_gtk2.c +++ b/tools/mpgui_gtk2.c @@ -582,40 +582,43 @@ int main(int argc, char *argv[]) load_install_info_lists(&fcmp); /* Process GTK arguments */ - gtk_init(&ui_options, &argv); + if (gtk_init_check(&ui_options, &argv)) { + toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); - toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_realize(toplevel); + gtk_widget_set_name(toplevel, "Freeciv-modpack"); + gtk_window_set_title(GTK_WINDOW(toplevel), + _("Freeciv modpack installer (gtk2)")); - gtk_widget_realize(toplevel); - gtk_widget_set_name(toplevel, "Freeciv-modpack"); - gtk_window_set_title(GTK_WINDOW(toplevel), - _("Freeciv modpack installer (gtk2)")); - - /* Keep the icon of the executable on Windows */ + /* Keep the icon of the executable on Windows */ #ifndef FREECIV_MSWINDOWS - { - /* Unlike main client, this only works if installed. Ignore any - * errors loading the icon. */ - GError *err; - (void) gtk_window_set_icon_from_file(GTK_WINDOW(toplevel), MPICON_PATH, - &err); - } + { + /* Unlike main client, this only works if installed. Ignore any + * errors loading the icon. */ + GError *err; + (void) gtk_window_set_icon_from_file(GTK_WINDOW(toplevel), MPICON_PATH, + &err); + } #endif /* FREECIV_MSWINDOWS */ - g_signal_connect(toplevel, "delete_event", - G_CALLBACK(quit_dialog_callback), NULL); + g_signal_connect(toplevel, "delete_event", + G_CALLBACK(quit_dialog_callback), NULL); - modinst_setup_widgets(toplevel); + modinst_setup_widgets(toplevel); - gtk_widget_show_all(toplevel); + gtk_widget_show_all(toplevel); - if (fcmp.autoinstall != NULL) { - gui_download_modpack(fcmp.autoinstall); - } + if (fcmp.autoinstall != NULL) { + gui_download_modpack(fcmp.autoinstall); + } + + gtk_main(); - gtk_main(); + gtk_widget_destroy(toplevel); + } else { + log_fatal(_("Failed to open graphical mode.")); + } - gtk_widget_destroy(toplevel); save_install_info_lists(&fcmp); } diff --git a/tools/mpgui_gtk3.c b/tools/mpgui_gtk3.c index a4c0e88b54..a717560955 100644 --- a/tools/mpgui_gtk3.c +++ b/tools/mpgui_gtk3.c @@ -588,41 +588,44 @@ int main(int argc, char *argv[]) load_install_info_lists(&fcmp); /* Process GTK arguments */ - gtk_init(&ui_options, &argv); + if (gtk_init_check(&ui_options, &argv)) { + toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); - toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_realize(toplevel); + gtk_widget_set_name(toplevel, "Freeciv-modpack"); + gtk_window_set_title(GTK_WINDOW(toplevel), + _("Freeciv modpack installer (gtk3)")); - gtk_widget_realize(toplevel); - gtk_widget_set_name(toplevel, "Freeciv-modpack"); - gtk_window_set_title(GTK_WINDOW(toplevel), - _("Freeciv modpack installer (gtk3)")); - - /* Keep the icon of the executable on Windows */ + /* Keep the icon of the executable on Windows */ #ifndef FREECIV_MSWINDOWS - { - /* Unlike main client, this only works if installed. Ignore any - * errors loading the icon. */ - GError *err; + { + /* Unlike main client, this only works if installed. Ignore any + * errors loading the icon. */ + GError *err; - (void) gtk_window_set_icon_from_file(GTK_WINDOW(toplevel), MPICON_PATH, - &err); - } + (void) gtk_window_set_icon_from_file(GTK_WINDOW(toplevel), MPICON_PATH, + &err); + } #endif /* FREECIV_MSWINDOWS */ - g_signal_connect(toplevel, "delete_event", - G_CALLBACK(quit_dialog_callback), NULL); + g_signal_connect(toplevel, "delete_event", + G_CALLBACK(quit_dialog_callback), NULL); - modinst_setup_widgets(toplevel); + modinst_setup_widgets(toplevel); - gtk_widget_show_all(toplevel); + gtk_widget_show_all(toplevel); - if (fcmp.autoinstall != NULL) { - gui_download_modpack(fcmp.autoinstall); - } + if (fcmp.autoinstall != NULL) { + gui_download_modpack(fcmp.autoinstall); + } + + gtk_main(); - gtk_main(); + gtk_widget_destroy(toplevel); + } else { + log_fatal(_("Failed to open graphical mode.")); + } - gtk_widget_destroy(toplevel); save_install_info_lists(&fcmp); } -- 2.35.1