From 011783da148ce9c81d042feecd202f6935f7ef71 Mon Sep 17 00:00:00 2001 From: Logan Rathbone Date: Thu, 19 Jan 2023 14:07:34 -0500 Subject: Initial port to libadwaita --- src/about.c | 6 +- src/calendar.c | 37 +- src/color.c | 21 +- src/entry.c | 34 +- src/fileselection.c | 25 +- src/forms.c | 37 +- src/main.c | 13 +- src/meson.build | 21 +- src/msg.c | 74 +--- src/notification.c | 2 +- src/option.h | 2 +- src/password.c | 38 +- src/progress.c | 86 ++-- src/scale.c | 38 +- src/text.c | 54 +-- src/tree.c | 36 +- src/util.c | 67 ++- src/util.h | 25 +- src/zenity.gresource.xml | 28 -- src/zenity.gresource.xml.in | 28 ++ src/zenity.h | 28 +- src/zenity.ui | 967 ++++++++++++++++---------------------------- 22 files changed, 668 insertions(+), 999 deletions(-) delete mode 100644 src/zenity.gresource.xml create mode 100644 src/zenity.gresource.xml.in (limited to 'src') diff --git a/src/about.c b/src/about.c index cac56c8..b71ea13 100644 --- a/src/about.c +++ b/src/about.c @@ -6,7 +6,7 @@ * Copyright © 2002 Sun Microsystems, Inc. * Copyright © 2001 CodeFactory AB * Copyright © 2001, 2002 Anders Carlsson - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -83,7 +83,7 @@ zenity_about (ZenityData *data) VERSION, "copyright", "Copyright \xc2\xa9 2003 Sun Microsystems\n" - "Copyright \xc2\xa9 2021 Logan Rathbone\n", + "Copyright \xc2\xa9 2021-2023 Logan Rathbone\n", "comments", _("Display dialog boxes from shell scripts"), "authors", @@ -117,5 +117,5 @@ zenity_about_close_cb (GtkWindow *window, gpointer data) ZenityData *zen_data = data; zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - zenity_util_gapp_quit (window); + zenity_util_gapp_quit (window, zen_data); } diff --git a/src/calendar.c b/src/calendar.c index be8c8af..f5237d1 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -4,7 +4,7 @@ * calendar.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,20 +35,18 @@ static GtkWidget *calendar; static ZenityCalendarData *zen_cal_data; -static void zenity_calendar_dialog_response (GtkWidget *widget, - int response, gpointer data); +static void zenity_calendar_dialog_response (GtkWidget *widget, char *rstr, gpointer data); void zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data) { g_autoptr(GtkBuilder) builder = NULL; GtkWidget *dialog; - GtkWidget *button; GObject *text; zen_cal_data = cal_data; - builder = zenity_util_load_ui_file ("zenity_calendar_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_calendar_dialog", "zenity_calendar_box", NULL); if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -108,22 +106,17 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) { - gtk_dialog_add_button (GTK_DIALOG(dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } - if (data->ok_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_calendar_ok_button")); - gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + if (data->ok_label) + { + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } - if (data->cancel_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_calendar_cancel_button")); - gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + if (data->cancel_label) + { + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } zenity_util_gapp_main (GTK_WINDOW(dialog)); @@ -150,19 +143,19 @@ zenity_calendar_dialog_output (void) } static void -zenity_calendar_dialog_response (GtkWidget *widget, int response, - gpointer data) +zenity_calendar_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityData *zen_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_calendar_dialog_output (); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -178,5 +171,5 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(gtk_widget_get_native (widget))); + zenity_util_gapp_quit (GTK_WINDOW(gtk_widget_get_native (widget)), zen_data); } diff --git a/src/color.c b/src/color.c index 4289407..667c1ad 100644 --- a/src/color.c +++ b/src/color.c @@ -4,7 +4,7 @@ * color.c * * Copyright © 2010 Berislav Kovacki - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -32,8 +32,7 @@ static ZenityData *zen_data; -static void zenity_colorselection_dialog_response (GtkWidget *widget, - int response, gpointer data); +static void zenity_colorselection_dialog_response (GtkWidget *widget, char *rstr, gpointer data); void zenity_colorselection (ZenityData *data, ZenityColorData *color_data) @@ -58,11 +57,7 @@ zenity_colorselection (ZenityData *data, ZenityColorData *color_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG (dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } if (data->modal) @@ -81,20 +76,20 @@ zenity_colorselection (ZenityData *data, ZenityColorData *color_data) } static void -zenity_colorselection_dialog_response (GtkWidget *widget, - int response, gpointer data) +zenity_colorselection_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { GdkRGBA color; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_util_exit_code_with_data (ZENITY_OK, zen_data); gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (widget), &color); g_print ("%s\n", gdk_rgba_to_string (&color)); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -105,5 +100,5 @@ zenity_colorselection_dialog_response (GtkWidget *widget, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/entry.c b/src/entry.c index a6d67a4..bf94cd4 100644 --- a/src/entry.c +++ b/src/entry.c @@ -4,7 +4,7 @@ * entry.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,8 +29,7 @@ #include -static void zenity_entry_dialog_response (GtkWidget *widget, - int response, gpointer data); +static void zenity_entry_dialog_response (GtkWidget *widget, char *rstr, gpointer data); static GtkWidget *entry; static int n_entries = 0; @@ -55,13 +54,12 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) { g_autoptr(GtkBuilder) builder = NULL; GtkWidget *dialog; - GtkWidget *button; GObject *text; GSList *entries = NULL; GSList *tmp; GObject *vbox; - builder = zenity_util_load_ui_file ("zenity_entry_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_entry_dialog", "zenity_entry_box", NULL); if (builder == NULL) { @@ -72,8 +70,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) dialog = GTK_WIDGET(gtk_builder_get_object (builder, "zenity_entry_dialog")); - g_signal_connect (dialog, "response", - G_CALLBACK(zenity_entry_dialog_response), data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_entry_dialog_response), data); if (data->dialog_title) gtk_window_set_title (GTK_WINDOW(dialog), data->dialog_title); @@ -90,25 +87,17 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG (dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } if (data->ok_label) { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_entry_ok_button")); - gtk_button_set_label (GTK_BUTTON(button), data->ok_label); + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } if (data->cancel_label) { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_entry_cancel_button")); - gtk_button_set_label (GTK_BUTTON(button), data->cancel_label); + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } text = gtk_builder_get_object (builder, "zenity_entry_text"); @@ -202,18 +191,19 @@ zenity_entry_dialog_output (void) } static void -zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data) +zenity_entry_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityData *zen_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_entry_dialog_output (); zenity_util_exit_code_with_data (ZENITY_OK, zen_data); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -229,5 +219,5 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/fileselection.c b/src/fileselection.c index e495f76..4cf544d 100644 --- a/src/fileselection.c +++ b/src/fileselection.c @@ -4,7 +4,7 @@ * fileselection.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -31,10 +31,14 @@ #include +/* GtkFileChooser deprecated in 4.10, but we want to maintain backwards + * compatibility with GTK 4.0. + */ +G_GNUC_BEGIN_IGNORE_DEPRECATIONS + static ZenityData *zen_data; -static void zenity_fileselection_dialog_response (GtkDialog *dialog, - int response, gpointer data); +static void zenity_fileselection_dialog_response (GtkWidget *widget, char *rstr, gpointer data); void zenity_fileselection (ZenityData *data, ZenityFileData *file_data) @@ -63,8 +67,7 @@ zenity_fileselection (ZenityData *data, ZenityFileData *file_data) if (data->extra_label) g_warning ("Cannot add extra labels to GtkFileChooserNative"); - g_signal_connect (dialog, "response", - G_CALLBACK(zenity_fileselection_dialog_response), file_data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_fileselection_dialog_response), file_data); if (file_data->uri) { @@ -179,11 +182,11 @@ zenity_fileselection_dialog_output (GtkFileChooser *chooser, } static void -zenity_fileselection_dialog_response (GtkDialog *dialog, - int response, gpointer data) +zenity_fileselection_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityFileData *file_data = data; - GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); + GtkFileChooser *chooser = GTK_FILE_CHOOSER (widget); + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { @@ -192,7 +195,7 @@ zenity_fileselection_dialog_response (GtkDialog *dialog, zenity_util_exit_code_with_data (ZENITY_OK, zen_data); break; - case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_REJECT: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -209,5 +212,7 @@ zenity_fileselection_dialog_response (GtkDialog *dialog, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (NULL); + zenity_util_gapp_quit (NULL, zen_data); } + +G_GNUC_END_IGNORE_DEPRECATIONS diff --git a/src/forms.c b/src/forms.c index ea50349..f3ce547 100644 --- a/src/forms.c +++ b/src/forms.c @@ -4,7 +4,7 @@ * forms.c * * Copyright © 2010 Arx Cruz - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,8 +33,7 @@ static ZenityData *zen_data; static GSList *selected; -static void zenity_forms_dialog_response (GtkWidget *widget, - int response, gpointer data); +static void zenity_forms_dialog_response (GtkWidget *widget, char *rstr, gpointer data); static void zenity_forms_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, @@ -228,7 +227,6 @@ zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data) GtkWidget *dialog; GtkWidget *grid; GtkWidget *text; - GtkWidget *button; int list_count = 0; int combo_count = 0; @@ -236,7 +234,7 @@ zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data) zen_data = data; - builder = zenity_util_load_ui_file ("zenity_forms_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_forms_dialog", "zenity_forms_box", NULL); if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -259,23 +257,17 @@ zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data) if (data->extra_label) { - for (i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG(dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } - if (data->ok_label) { - button = GTK_WIDGET ( - gtk_builder_get_object (builder, "zenity_forms_ok_button")); - gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + if (data->ok_label) + { + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } - if (data->cancel_label) { - button = GTK_WIDGET ( - gtk_builder_get_object (builder, "zenity_forms_cancel_button")); - gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + if (data->cancel_label) + { + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } text = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_text")); @@ -441,18 +433,19 @@ zenity_forms_dialog_output (ZenityFormsData *forms_data) } static void -zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data) +zenity_forms_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityFormsData *forms_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_forms_dialog_output (forms_data); zenity_util_exit_code_with_data (ZENITY_OK, zen_data); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -468,5 +461,5 @@ zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data) zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/main.c b/src/main.c index a4531fd..b224bf1 100644 --- a/src/main.c +++ b/src/main.c @@ -4,7 +4,7 @@ * main.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,7 @@ #include "option.h" #include "zenity.h" -#include +#include #include #include @@ -39,7 +39,7 @@ typedef struct { } ZenityArgs; static void -command_line_cb (GtkApplication *app, +command_line_cb (GApplication *app, GApplicationCommandLine *command_line, gpointer user_data) { @@ -125,9 +125,6 @@ command_line_cb (GtkApplication *app, exit (-1); } - g_application_command_line_set_exit_status (command_line, - results->data->exit_code); - g_free (args); } @@ -135,7 +132,7 @@ int main (int argc, char *argv[]) { ZenityArgs *args; - g_autoptr(GtkApplication) app = NULL; + g_autoptr(AdwApplication) app = NULL; int status; /* */ @@ -150,7 +147,7 @@ main (int argc, char *argv[]) args->argc = argc; args->argv = argv; - app = gtk_application_new (APP_ID, G_APPLICATION_HANDLES_COMMAND_LINE); + app = adw_application_new (APP_ID, G_APPLICATION_HANDLES_COMMAND_LINE); g_signal_connect (app, "command-line", G_CALLBACK(command_line_cb), args); status = g_application_run (G_APPLICATION(app), 0, NULL); diff --git a/src/meson.build b/src/meson.build index 9034cb2..0c03b31 100644 --- a/src/meson.build +++ b/src/meson.build @@ -15,12 +15,25 @@ zenity_sources = [ 'scale.c', 'text.c', 'tree.c', - 'util.c' + 'util.c', ] +zenity_enums = gnome.mkenums_simple('zenity-enums', + sources: 'zenity.h', +) + +zenity_res_conf = configuration_data() +zenity_res_conf.set('resource_base_path', resource_base_path) + +zenity_res_in = configure_file( + input: 'zenity.gresource.xml.in', + output: 'zenity.gresource.xml', + configuration: zenity_res_conf +) + zenity_res = gnome.compile_resources( 'zenity-resources', - 'zenity.gresource.xml', + zenity_res_in, c_name: 'zenity' ) @@ -30,9 +43,9 @@ zenity_c_args = [ zenity = executable( meson.project_name(), - zenity_sources + zenity_res, + zenity_sources + zenity_enums + zenity_res, include_directories: zenity_root_dir, c_args: zenity_c_args, - dependencies: gtk_dep, + dependencies: adw_dep, install: true ) diff --git a/src/msg.c b/src/msg.c index 985a733..87a5beb 100644 --- a/src/msg.c +++ b/src/msg.c @@ -4,7 +4,7 @@ * msg.c * * Copyright (C) 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,31 +29,7 @@ #include "util.h" #include "zenity.h" -static void zenity_msg_dialog_response (GtkWidget *widget, - int response, gpointer data); - -static void -zenity_msg_construct_question_dialog (GtkWidget *dialog, - ZenityMsgData *msg_data, ZenityData *data) -{ - GtkWidget *cancel_button, *ok_button; - - cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_No"), GTK_RESPONSE_CANCEL); - ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("_Yes"), GTK_RESPONSE_OK); - - gtk_widget_grab_focus - (msg_data->default_cancel ? cancel_button : ok_button); - - if (data->cancel_label) { - gtk_button_set_label (GTK_BUTTON (cancel_button), data->cancel_label); - } - - if (data->ok_label) { - gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label); - } -} +static void zenity_msg_dialog_response (GtkWidget *widget, char *rstr, gpointer data); /* FIXME - Is this still necessary with gtk4? */ static void @@ -86,50 +62,42 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) { g_autoptr(GtkBuilder) builder; GtkWidget *dialog; - GtkWidget *ok_button; GObject *text; GObject *image; switch (msg_data->mode) { case ZENITY_MSG_WARNING: - builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_warning_dialog", "zenity_warning_box", NULL); dialog = GTK_WIDGET ( gtk_builder_get_object (builder, "zenity_warning_dialog")); text = gtk_builder_get_object (builder, "zenity_warning_text"); image = gtk_builder_get_object (builder, "zenity_warning_image"); - ok_button = GTK_WIDGET ( - gtk_builder_get_object (builder, "zenity_warning_ok_button")); break; case ZENITY_MSG_QUESTION: case ZENITY_MSG_SWITCH: - builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_question_dialog", "zenity_question_box", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_question_dialog")); text = gtk_builder_get_object (builder, "zenity_question_text"); image = gtk_builder_get_object (builder, "zenity_question_image"); - ok_button = NULL; break; case ZENITY_MSG_ERROR: - builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_error_dialog", "zenity_error_box", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_error_dialog")); text = gtk_builder_get_object (builder, "zenity_error_text"); image = gtk_builder_get_object (builder, "zenity_error_image"); - ok_button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_error_ok_button")); break; case ZENITY_MSG_INFO: - builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_info_dialog", "zenity_info_box", NULL); dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_info_dialog")); text = gtk_builder_get_object (builder, "zenity_info_text"); image = gtk_builder_get_object (builder, "zenity_info_image"); - ok_button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_info_ok_button")); break; default: @@ -137,18 +105,13 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) dialog = NULL; text = NULL; image = NULL; - ok_button = NULL; g_assert_not_reached (); break; } if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG (dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } if (builder == NULL) { @@ -156,18 +119,14 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) return; } - g_signal_connect (G_OBJECT (dialog), - "response", - G_CALLBACK (zenity_msg_dialog_response), - data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_msg_dialog_response), data); if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); - if (ok_button) { - if (data->ok_label) { - gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label); - } + if (data->ok_label) + { + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog) } switch (msg_data->mode) @@ -180,7 +139,6 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) case ZENITY_MSG_QUESTION: gtk_window_set_icon_name (GTK_WINDOW(dialog), "dialog-question"); - zenity_msg_construct_question_dialog (dialog, msg_data, data); break; case ZENITY_MSG_SWITCH: @@ -256,16 +214,18 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data) } static void -zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data) { +zenity_msg_dialog_response (GtkWidget *widget, char *rstr, gpointer data) +{ ZenityData *zen_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_util_exit_code_with_data (ZENITY_OK, zen_data); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -276,5 +236,5 @@ zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data) { zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/notification.c b/src/notification.c index dc25e59..295c1c2 100644 --- a/src/notification.c +++ b/src/notification.c @@ -88,7 +88,7 @@ on_notification_default_action (GSimpleAction *self, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - zenity_util_gapp_quit (NULL); + zenity_util_gapp_quit (NULL, zen_data); } static gboolean diff --git a/src/option.h b/src/option.h index df4150a..5da7cfe 100644 --- a/src/option.h +++ b/src/option.h @@ -2,7 +2,7 @@ * option.h * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public diff --git a/src/password.c b/src/password.c index 172fe4f..69dd683 100644 --- a/src/password.c +++ b/src/password.c @@ -4,7 +4,7 @@ * password.c * * Copyright © 2010 Arx Cruz - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,15 +33,13 @@ static ZenityData *zen_data; -static void zenity_password_dialog_response (GtkWidget *widget, - int response, gpointer data); +static void zenity_password_dialog_response (GtkWidget *widget, char *rstr, gpointer data); void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) { GtkBuilder *builder; GtkWidget *dialog; - GtkWidget *button; GtkWidget *grid; GtkWidget *label; int pass_row = 0; @@ -49,7 +47,7 @@ zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) /* Set global */ zen_data = data; - builder = zenity_util_load_ui_file ("zenity_password_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_password_dialog", "zenity_password_box", NULL); if (builder == NULL) { @@ -62,25 +60,16 @@ zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG(dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } - if (data->ok_label) - { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_password_ok_button")); - gtk_button_set_label (GTK_BUTTON(button), data->ok_label); + if (data->ok_label) { + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } if (data->cancel_label) { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_password_cancel_button")); - gtk_button_set_label (GTK_BUTTON(button), data->cancel_label); + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } grid = GTK_WIDGET(gtk_builder_get_object (builder, @@ -136,8 +125,7 @@ zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) if (data->modal) gtk_window_set_modal (GTK_WINDOW(dialog), TRUE); - g_signal_connect (dialog, "response", - G_CALLBACK(zenity_password_dialog_response), password_data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_password_dialog_response), password_data); zenity_util_show_dialog (dialog); @@ -151,18 +139,18 @@ zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) } static void -zenity_password_dialog_response (GtkWidget *widget, int response, - gpointer data) +zenity_password_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityPasswordData *password_data = data; GtkEntryBuffer *user_buff, *pass_buff; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); user_buff = gtk_entry_get_buffer (GTK_ENTRY(password_data->entry_username)); pass_buff = gtk_entry_get_buffer (GTK_ENTRY(password_data->entry_password)); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_util_exit_code_with_data (ZENITY_OK, zen_data); if (password_data->username) { g_print ("%s|%s\n", @@ -175,7 +163,7 @@ zenity_password_dialog_response (GtkWidget *widget, int response, } break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -186,5 +174,5 @@ zenity_password_dialog_response (GtkWidget *widget, int response, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/progress.c b/src/progress.c index 81d5e5f..cae1a6c 100644 --- a/src/progress.c +++ b/src/progress.c @@ -4,7 +4,7 @@ * progress.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -50,8 +50,7 @@ static gboolean auto_close; gint zenity_progress_timeout (gpointer data); gint zenity_progress_pulsate_timeout (gpointer data); -static void zenity_progress_dialog_response (GtkWidget *widget, - int response, gpointer data); +static void zenity_progress_dialog_response (GtkWidget *widget, char *rstr, gpointer data); static gboolean zenity_progress_pulsate_progress_bar (gpointer user_data) @@ -250,19 +249,15 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition, if (percentage == 100) { - GObject *button; - - button = gtk_builder_get_object (builder, - "zenity_progress_ok_button"); - gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE); - gtk_widget_grab_focus (GTK_WIDGET (button)); + adw_message_dialog_set_response_enabled (ADW_MESSAGE_DIALOG(parent), "ok", TRUE); + adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG(parent), "ok"); if (progress_data->autoclose) { zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - zenity_util_gapp_quit (parent); + zenity_util_gapp_quit (parent, zen_data); } } } @@ -276,17 +271,10 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition, { /* We assume that we are done, so stop the pulsating and de-sensitize * the buttons */ - GtkWidget *button; - - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_progress_ok_button")); - gtk_widget_set_sensitive (button, TRUE); - gtk_widget_grab_focus (button); + adw_message_dialog_set_response_enabled (ADW_MESSAGE_DIALOG(parent), "ok", TRUE); + adw_message_dialog_set_response_enabled (ADW_MESSAGE_DIALOG(parent), "cancel", FALSE); + adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG(parent), "ok"); - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_progress_cancel_button")); - - gtk_widget_set_sensitive (button, FALSE); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0); zenity_progress_pulsate_stop (); @@ -296,7 +284,7 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition, if (progress_data->autoclose) { zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); - zenity_util_gapp_quit (parent); + zenity_util_gapp_quit (parent, zen_data); } g_io_channel_shutdown (channel, TRUE, NULL); @@ -331,13 +319,11 @@ void zenity_progress (ZenityData *data, ZenityProgressData *progress_data) { GtkWidget *dialog; - GtkWidget *button; GObject *text; GObject *progress_bar; - GObject *cancel_button, *ok_button; zen_data = data; - builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_progress_dialog", "zenity_progress_box", NULL); if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -351,8 +337,7 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar"); - g_signal_connect (dialog, "response", - G_CALLBACK(zenity_progress_dialog_response), data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_progress_dialog_response), data); if (data->dialog_title) gtk_window_set_title (GTK_WINDOW(dialog), data->dialog_title); @@ -384,25 +369,16 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG(dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } - if (data->ok_label) - { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_progress_ok_button")); - gtk_button_set_label (GTK_BUTTON(button), data->ok_label); + if (data->ok_label) { + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } if (data->cancel_label) { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_progress_cancel_button")); - gtk_button_set_label (GTK_BUTTON(button), data->cancel_label); + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } if (progress_data->dialog_text) { @@ -416,21 +392,22 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) } autokill = progress_data->autokill; - auto_close = progress_data->autoclose; - ok_button = gtk_builder_get_object (builder, "zenity_progress_ok_button"); - no_cancel = progress_data->no_cancel; - cancel_button = - gtk_builder_get_object (builder, "zenity_progress_cancel_button"); - if (no_cancel) { - gtk_widget_hide (GTK_WIDGET(cancel_button)); + /* Unlike some other dialogs, this one starts off blank and we need to add + * the OK/Cancel buttons depending on the options. + */ + if (no_cancel) gtk_window_set_deletable (GTK_WINDOW(dialog), FALSE); - } + else + adw_message_dialog_add_response (ADW_MESSAGE_DIALOG(dialog), "cancel", _("_Cancel")); - if (no_cancel && auto_close) - gtk_widget_hide (GTK_WIDGET(ok_button)); + if (!auto_close) + { + adw_message_dialog_add_response (ADW_MESSAGE_DIALOG(dialog), "ok", _("_OK")); + adw_message_dialog_set_response_enabled (ADW_MESSAGE_DIALOG(dialog), "ok", FALSE); + } zenity_util_show_dialog (dialog); zenity_progress_read_info (progress_data); @@ -445,16 +422,17 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data) } static void -zenity_progress_dialog_response (GtkWidget *widget, int response, - gpointer data) +zenity_progress_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); + switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_util_exit_code_with_data (ZENITY_OK, zen_data); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: /* We do not want to kill the parent process, in order to give the * user the ability to choose the action to be taken. But we want * to give people the option to choose this behavior. @@ -478,5 +456,5 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/scale.c b/src/scale.c index 2140040..7ac0f41 100644 --- a/src/scale.c +++ b/src/scale.c @@ -4,7 +4,7 @@ * scale.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,19 +33,16 @@ static GtkWidget *scale; static void zenity_scale_value_changed (GtkWidget *widget, gpointer data); -static void zenity_scale_dialog_response (GtkWidget *widget, int response, - gpointer data); +static void zenity_scale_dialog_response (GtkWidget *widget, char *rstr, gpointer data); void zenity_scale (ZenityData *data, ZenityScaleData *scale_data) { g_autoptr(GtkBuilder) builder = NULL; GtkWidget *dialog; - GtkWidget *button; GObject *text; - builder = - zenity_util_load_ui_file ("zenity_scale_dialog", "adjustment1", NULL); + builder = zenity_util_load_ui_file ("zenity_scale_dialog", "zenity_scale_adjustment", "zenity_scale_box", NULL); if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -58,8 +55,7 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data) GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_hscale")); text = gtk_builder_get_object (builder, "zenity_scale_text"); - g_signal_connect (dialog, "response", - G_CALLBACK(zenity_scale_dialog_response), data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_scale_dialog_response), data); if (scale_data->min_value >= scale_data->max_value) { @@ -92,24 +88,17 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG (dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } - if (data->ok_label) { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_scale_ok_button")); - gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + if (data->ok_label) + { + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } if (data->cancel_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_scale_cancel_button")); - gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } if (scale_data->dialog_text) { @@ -151,18 +140,19 @@ zenity_scale_value_changed (GtkWidget *widget, gpointer data) } static void -zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data) +zenity_scale_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityData *zen_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_util_exit_code_with_data (ZENITY_OK, zen_data); g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale))); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -181,5 +171,5 @@ zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data) break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/text.c b/src/text.c index 1df25b2..f539c7a 100644 --- a/src/text.c +++ b/src/text.c @@ -4,7 +4,7 @@ * text.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,9 +38,8 @@ static ZenityTextData *zen_text_data; -static void zenity_text_dialog_response (GtkWidget *widget, int response, - gpointer data); -static void zenity_text_toggle_button (GtkToggleButton *button, gpointer data); +static void zenity_text_dialog_response (GtkWidget *widget, char *rstr, gpointer data); +static void zenity_text_toggle_button (GtkCheckButton *button, AdwMessageDialog *dialog); // TODO - I don't think gtk4 support for webkit is fully "there" yet. #ifdef HAVE_WEBKITGTK @@ -253,9 +252,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) { g_autoptr(GtkBuilder) builder = NULL; GtkWidget *dialog; - GtkWidget *ok_button; GtkWidget *checkbox; - GtkWidget *cancel_button; GObject *text_view; GtkTextBuffer *text_buffer; @@ -268,8 +265,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) #endif zen_text_data = text_data; - builder = - zenity_util_load_ui_file ("zenity_text_dialog", "textbuffer1", NULL); + builder = zenity_util_load_ui_file ("zenity_text_dialog", "zenity_text_box", NULL); if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -279,10 +275,6 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) dialog = GTK_WIDGET(gtk_builder_get_object (builder, "zenity_text_dialog")); - ok_button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_text_close_button")); - cancel_button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_text_cancel_button")); checkbox = GTK_WIDGET(gtk_builder_get_object (builder, "zenity_text_checkbox")); @@ -295,8 +287,6 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) gtk_window_set_icon_name (GTK_WINDOW(dialog), "accessories-text-editor"); - gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); - text_buffer = gtk_text_buffer_new (NULL); text_view = gtk_builder_get_object (builder, "zenity_text_view"); gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer); @@ -334,28 +324,24 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG(dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } if (data->ok_label) { - gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label); + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog); } - if (data->cancel_label) { - gtk_button_set_label (GTK_BUTTON (cancel_button), data->cancel_label); + if (data->cancel_label) + { + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog); } if (text_data->checkbox) { - gtk_widget_set_visible (GTK_WIDGET (checkbox), TRUE); - gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE); - gtk_button_set_label (GTK_BUTTON (checkbox), text_data->checkbox); + gtk_widget_set_visible (GTK_WIDGET(checkbox), TRUE); + gtk_check_button_set_label (GTK_CHECK_BUTTON(checkbox), text_data->checkbox); + adw_message_dialog_set_response_enabled (ADW_MESSAGE_DIALOG(dialog), "ok", FALSE); - g_signal_connect (checkbox, "toggled", - G_CALLBACK(zenity_text_toggle_button), ok_button); + g_signal_connect (checkbox, "toggled", G_CALLBACK(zenity_text_toggle_button), dialog); } if (data->width > -1 || data->height > -1) @@ -428,12 +414,9 @@ zenity_text (ZenityData *data, ZenityTextData *text_data) } static void -zenity_text_toggle_button (GtkToggleButton *button, gpointer data) +zenity_text_toggle_button (GtkCheckButton *button, AdwMessageDialog *dialog) { - GtkWidget *ok_button = GTK_WIDGET(data); - - gtk_widget_set_sensitive (ok_button, - gtk_toggle_button_get_active (button)); + adw_message_dialog_set_response_enabled (dialog, "ok", gtk_check_button_get_active (button)); } static void @@ -452,13 +435,14 @@ zenity_text_dialog_output (ZenityData *zen_data) } static void -zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) +zenity_text_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityData *zen_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_CLOSE: + case ZENITY_ESC: zenity_text_dialog_output (zen_data); zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK); break; @@ -477,5 +461,5 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) zenity_util_exit_code_with_data (ZENITY_ESC, zen_data); break; } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } diff --git a/src/tree.c b/src/tree.c index 6f07973..aba2a3b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -4,7 +4,7 @@ * tree.c * * Copyright © 2002 Sun Microsystems, Inc. - * Copyright © 2021 Logan Rathbone + * Copyright © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -47,8 +47,7 @@ static GIOChannel *channel; static int *zenity_tree_extract_column_indexes (char *indexes, int n_columns); static gboolean zenity_tree_column_is_hidden (int column_index); -static void zenity_tree_dialog_response (GtkWidget *widget, int response, - gpointer data); +static void zenity_tree_dialog_response (GtkWidget *widget, char *rstr, gpointer data); static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path, GtkTreeViewColumn *tree_col, gpointer data); @@ -349,7 +348,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) { g_autoptr(GtkBuilder) builder = NULL; GtkWidget *dialog; - GtkWidget *button; GObject *text; GtkTreeViewColumn *column; GtkListStore *model; @@ -358,7 +356,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) gboolean first_column = FALSE; int i, column_index, n_columns; - builder = zenity_util_load_ui_file ("zenity_tree_dialog", NULL); + builder = zenity_util_load_ui_file ("zenity_tree_dialog", "zenity_tree_box", NULL); if (builder == NULL) { data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR); @@ -406,8 +404,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) dialog = GTK_WIDGET(gtk_builder_get_object (builder, "zenity_tree_dialog")); - g_signal_connect (dialog, "response", - G_CALLBACK(zenity_tree_dialog_response), data); + g_signal_connect (dialog, "response", G_CALLBACK(zenity_tree_dialog_response), data); if (data->dialog_title) gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title); @@ -417,23 +414,15 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) if (data->extra_label) { - for (int i = 0; data->extra_label[i] != NULL; ++i) - { - gtk_dialog_add_button (GTK_DIALOG (dialog), - data->extra_label[i], i); - } + ZENITY_UTIL_ADD_EXTRA_LABELS (dialog) } if (data->ok_label) { - button = GTK_WIDGET(gtk_builder_get_object (builder, - "zenity_tree_ok_button")); - gtk_button_set_label (GTK_BUTTON (button), data->ok_label); + ZENITY_UTIL_SETUP_OK_BUTTON_LABEL (dialog) } if (data->cancel_label) { - button = GTK_WIDGET (gtk_builder_get_object (builder, - "zenity_tree_cancel_button")); - gtk_button_set_label (GTK_BUTTON (button), data->cancel_label); + ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL (dialog) } text = gtk_builder_get_object (builder, "zenity_tree_text"); @@ -804,18 +793,19 @@ zenity_tree_dialog_output (void) } static void -zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) +zenity_tree_dialog_response (GtkWidget *widget, char *rstr, gpointer data) { ZenityData *zen_data = data; + ZenityExitCode response = zenity_util_parse_dialog_response (rstr); switch (response) { - case GTK_RESPONSE_OK: + case ZENITY_OK: zenity_tree_dialog_output (); zenity_util_exit_code_with_data (ZENITY_OK, zen_data); break; - case GTK_RESPONSE_CANCEL: + case ZENITY_CANCEL: zen_data->exit_code = zenity_util_return_exit_code (ZENITY_CANCEL); break; @@ -839,7 +829,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) g_io_channel_shutdown (channel, TRUE, NULL); } - zenity_util_gapp_quit (GTK_WINDOW(widget)); + zenity_util_gapp_quit (GTK_WINDOW(widget), zen_data); } static void @@ -858,7 +848,7 @@ zenity_tree_row_activated (GtkTreeView *loc_tv, GtkTreePath *tree_path, parent = GTK_WINDOW(gtk_widget_get_native (GTK_WIDGET(tree_view))); - zenity_util_gapp_quit (parent); + zenity_util_gapp_quit (parent, zen_data); } static gboolean diff --git a/src/util.c b/src/util.c index ec60ba3..1cc21af 100644 --- a/src/util.c +++ b/src/util.c @@ -7,7 +7,7 @@ * © 1999, 2000 Red Hat Inc. * © 1998 James Henstridge * © 1995-2002 Free Software Foundation - * © 2021 Logan Rathbone + * © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -32,6 +32,7 @@ #include "util.h" #include "zenity.h" + #include #include #include @@ -210,8 +211,8 @@ zenity_util_show_help (GError **error) { } int -zenity_util_return_exit_code (ZenityExitCode value) { - +zenity_util_return_exit_code (ZenityExitCode value) +{ const char *env_var = NULL; int retval; @@ -416,15 +417,12 @@ zenity_util_show_dialog (GtkWidget *dialog) } gboolean -zenity_util_timeout_handle (gpointer data) +zenity_util_timeout_handle (AdwMessageDialog *dialog) { - GtkDialog *dialog = GTK_DIALOG (data); - - if (dialog != NULL) { - gtk_dialog_response (dialog, ZENITY_TIMEOUT); + if (dialog) { + adw_message_dialog_response (dialog, "timeout"); } else { - zenity_util_gapp_quit (GTK_WINDOW(dialog)); exit (ZENITY_TIMEOUT); } return FALSE; @@ -450,14 +448,61 @@ zenity_util_gapp_main (GtkWindow *window) } void -zenity_util_gapp_quit (GtkWindow *window) +zenity_util_gapp_quit (GtkWindow *window, ZenityData *data) { + /* This is a bit hack-ish, but GApplication doesn't really allow for + * customized exit statuses within that API. + */ + if (data->exit_code != 0) + exit (data->exit_code); + if (window) { g_assert (GTK_IS_WINDOW (window)); - gtk_window_set_application (window, NULL); + gtk_window_destroy (window); } else { g_application_release (g_application_get_default ()); } } + +int +zenity_util_parse_dialog_response (const char *response) +{ + if (g_strcmp0 (response, "ok") == 0 || g_strcmp0 (response, "yes") == 0) + { + return ZENITY_OK; + } + else if (g_strcmp0 (response, "cancel") == 0 || g_strcmp0 (response, "no") == 0) + { + return ZENITY_CANCEL; + } + else if (g_strcmp0 (response, "timeout") == 0) + { + return ZENITY_TIMEOUT; + } + else if (response[0] >= '0' && response[0] <= '9') + { + /* FIXME - atoi returns 0 on error, so this *could* mean the function + * failed - but that would be a programmer error, so we'll leave this + * in place. + */ + return atoi (response); + } + else + { + return ZENITY_ESC; + } +} + +GtkWidget * +zenity_util_add_button (AdwMessageDialog *dialog, const char *button_text, + ZenityExitCode response_id) +{ + GtkWidget *w = GTK_WIDGET(dialog); + g_autofree char *response_str = g_strdup_printf ("%d", response_id); + + adw_message_dialog_add_response (dialog, response_str, button_text); + + return w; +} diff --git a/src/util.h b/src/util.h index fd3d446..5ea703d 100644 --- a/src/util.h +++ b/src/util.h @@ -7,7 +7,7 @@ * © 1999, 2000 Red Hat Inc. * © 1998 James Henstridge * © 1995-2002 Free Software Foundation - * © 2021 Logan Rathbone + * © 2021-2023 Logan Rathbone * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,8 +33,7 @@ * Tom Tromey */ -#ifndef UTIL_H -#define UTIL_H +#pragma once #include "zenity.h" #include @@ -43,6 +42,17 @@ G_BEGIN_DECLS #define ZENITY_IMAGE_FULLPATH(filename) (PACKAGE_DATADIR "/" filename) +#define ZENITY_UTIL_ADD_EXTRA_LABELS(DIALOG) \ + for (int i = 0; data->extra_label[i] != NULL; ++i) { \ + zenity_util_add_button (ADW_MESSAGE_DIALOG (DIALOG), data->extra_label[i], i); \ + } + +#define ZENITY_UTIL_SETUP_OK_BUTTON_LABEL(DIALOG) \ + adw_message_dialog_set_response_label (ADW_MESSAGE_DIALOG(DIALOG), "ok", data->ok_label); + +#define ZENITY_UTIL_SETUP_CANCEL_BUTTON_LABEL(DIALOG) \ + adw_message_dialog_set_response_label (ADW_MESSAGE_DIALOG(DIALOG), "cancel", data->cancel_label); + GIcon *zenity_util_gicon_from_string (const char *str); GtkBuilder *zenity_util_load_ui_file (const char *widget_root, ...) G_GNUC_NULL_TERMINATED; @@ -53,11 +63,12 @@ void zenity_util_show_help (GError **error); int zenity_util_return_exit_code (ZenityExitCode value); void zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *data); void zenity_util_show_dialog (GtkWidget *widget); -gboolean zenity_util_timeout_handle (gpointer data); +gboolean zenity_util_timeout_handle (AdwMessageDialog *dialog); char *zenity_util_pango_font_description_to_css (PangoFontDescription *desc); void zenity_util_gapp_main (GtkWindow *window); -void zenity_util_gapp_quit (GtkWindow *window); +void zenity_util_gapp_quit (GtkWindow *window, ZenityData *data); +ZenityExitCode zenity_util_parse_dialog_response (const char *response); +GtkWidget *zenity_util_add_button (AdwMessageDialog *dialog, const char + *button_text, ZenityExitCode response_id); G_END_DECLS - -#endif /* UTIL_H */ diff --git a/src/zenity.gresource.xml b/src/zenity.gresource.xml deleted file mode 100644 index 68efa13..0000000 --- a/src/zenity.gresource.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - zenity.ui - - diff --git a/src/zenity.gresource.xml.in b/src/zenity.gresource.xml.in new file mode 100644 index 0000000..4671d46 --- /dev/null +++ b/src/zenity.gresource.xml.in @@ -0,0 +1,28 @@ + + + + + + + + zenity.ui + + diff --git a/src/zenity.h b/src/zenity.h index 0316ce5..20cac9f 100644 --- a/src/zenity.h +++ b/src/zenity.h @@ -1,15 +1,26 @@ /* vim: colorcolumn=80 ts=4 sw=4 */ -#ifndef ZENITY_H -#define ZENITY_H +#pragma once -#include +#include #include +#include "zenity-enums.h" /* auto-generated by build system */ + #include G_BEGIN_DECLS +typedef enum +{ + ZENITY_OK = -1, + ZENITY_CANCEL = -2, + ZENITY_ESC = -3, + ZENITY_ERROR = -4, + ZENITY_EXTRA = -5, + ZENITY_TIMEOUT = -6 +} ZenityExitCode; + typedef struct { char *dialog_title; char *ok_label; @@ -22,15 +33,6 @@ typedef struct { gboolean modal; } ZenityData; -typedef enum { - ZENITY_OK, - ZENITY_CANCEL, - ZENITY_ESC, - ZENITY_ERROR, - ZENITY_EXTRA, - ZENITY_TIMEOUT -} ZenityExitCode; - typedef struct { char *dialog_text; int day; @@ -188,5 +190,3 @@ void zenity_password_dialog ( ZenityData *data, ZenityPasswordData *password_data); void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data); G_END_DECLS - -#endif /* ZENITY_H */ diff --git a/src/zenity.ui b/src/zenity.ui index 03f9684..7fcbb02 100644 --- a/src/zenity.ui +++ b/src/zenity.ui @@ -5,748 +5,485 @@ - + + Adjust the scale value + 300 + 100 + zenity_scale_box + + _Cancel + _OK + + + 100 1 1 - - 1 - 0 - Adjust the scale value - 300 - 100 - - - 0 - - - 0 - vertical - 6 - - - center - 0 - Adjust the scale value - 0 - - - - - true - 1 - adjustment1 - 0 - right - - - - + + vertical + 6 + + + center + true + Adjust the scale value + 0 - - zenity_scale_cancel_button - zenity_scale_ok_button - - - - True - False - - - true - _Cancel - - - - - true - _OK - - + + + true + 1 + zenity_scale_adjustment + 0 + right - - - 0 + Text View 300 200 - - - 0 - 2 + zenity_text_box + + _Cancel + _OK + + + + 2 + + + 1 + vertical - - 1 - 0 - vertical - - - 1 - - - 2 - 2 - 0 - word - 2 - 2 - textbuffer1 - - - - - - - center - 0 + + 1 + + + false + word - - - - - - - zenity_text_cancel_button - zenity_text_close_button - - - - True - False - - - true - _Cancel + - - true - _OK + + center + 0 - - 0 + Calendar selection - - - 0 - 2 + zenity_calendar_box + + _Cancel + _OK + + + + 2 + + + vertical + 6 - - 0 - vertical + + 1 6 - - 1 - 0 - 6 - - - center - 0 - Select a date from below. - 1 - 0 - - - - - - - center - 0 - C_alendar: - 1 - zenity_calendar + + center + Select a date from below. + 1 0 - - Calendar - zenity_calendar - - - - - - center - - - - zenity_calendar_cancel_button - zenity_calendar_ok_button - - - - True - False - - true - _Cancel + + center + C_alendar: + 1 + zenity_calendar + 0 + + Calendar + zenity_calendar + - - true - _OK + + center + true - - 0 + Add a new entry - - - 0 - vertical - 2 - 12 - 12 - 12 - 12 - - - 0 + zenity_entry_box + + _Cancel + _OK + + + + vertical + 2 + 12 + 12 + 12 + 12 + + + + + 1 + vertical + 6 - - 1 - 0 - vertical - 6 - - - center - 0 - _Enter new text: - 1 - 0 - - - - - + + center + _Enter new text: + 1 + 0 - - - - - - zenity_entry_cancel_button - zenity_entry_ok_button - - - - True - False - - - true - _Cancel - - - - - true - _OK - - - - - - - 0 - Error - - - 0 - 14 - 12 - 12 - 12 - 12 - - - 0 - - 1 - 0 - 12 - - - center - 0 - dialog-error - large - - - - - center - An error has occurred. - 1 - 1 - 0 - - - + - - zenity_error_ok_button - - - - False - - - true - _OK - - - - - - 0 - - - 0 - 2 - - - 0 - - - 0 - 12 - 6 - 12 - 6 - 6 - 10 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - Forms dialog - - - - - - - - - - - zenity_forms_cancel_button - zenity_forms_ok_button - - - - True - False - - - true - _Cancel - - - - - true - _OK - - - - + + Error + zenity_error_box + + _OK + - - 0 - Information - - - 0 - 14 - 12 - 12 - 12 - 12 - - - - 0 + + 14 + 12 + 12 + 12 + 12 + + + + + 1 12 - + center - 0 - dialog-information + dialog-error large - + center - All updates are complete. - 1 - 1 - 0 + An error has occurred. + true + true + false - - zenity_info_ok_button - - - - True - False - - - true - _OK - - - - - - 0 - Progress - - - 0 - 2 - - - center - 0 - vertical - 6 + + zenity_forms_box + + _Cancel + _OK + + + + 2 + + + + + 12 + 6 + 12 + 6 + 6 + 10 - - center - 0 - Running... - 1 - 0 - + - - center - 0 - 0.10000000149 - + - - center - 0 - 0 - + + + + + + + + + + + + + + + + + + + + + + + Forms dialog + + + + - - zenity_progress_cancel_button - zenity_progress_ok_button - - - - True - False - - - true - _Cancel + + + Information + zenity_info_box + + _OK + + + + 14 + 12 + 12 + 12 + 12 + + + 12 + + + center + dialog-information + large - - true - _OK - 0 + + center + true + All updates are complete. + true + true + false - - 0 - Question - - - 0 - 14 - 12 - 12 - 12 - 12 + + Progress + zenity_progress_box + + + 2 + + + vertical + 6 - - 0 - 12 - - - 0 - dialog-question - large - - - - - center - Are you sure you want to proceed? - 1 - 1 - 0 - - + + center + Running... + 1 + 0 - - - - - - True - False - - - - - 0 - Select items from the list - 300 - 196 - - - 0 - - 0 - vertical - 6 - - - center - 0 - Select items from the list below. - 0 - - - - - 1 - 1 - - - - - - - - - + + center + true + 0.10000000149 + + + + + center + 0 - - zenity_tree_cancel_button - zenity_tree_ok_button - - - - False + + + Question + zenity_question_box + + _No + _Yes + + + + 14 + 12 + 12 + 12 + 12 + + + 12 - - true - _Cancel + + dialog-question + large - - true - _OK + + center + true + Are you sure you want to proceed? + true + true + false - - 0 - Warning - false - - - - 0 - 14 - 12 - 12 - 12 - 12 + + Select items from the list + 300 + 196 + zenity_tree_box + true + + _Cancel + _OK + + + + + + vertical + 6 - - 0 - 12 - - - 0 - dialog-warning - large - - - - - center - true - true - Are you sure you want to proceed? - 1 - 1 - - + + center + Select items from the list below. + 0 - - - - zenity_warning_ok_button - - - - True - False - - true - _OK + + 1 + 1 + + + + + + + - - - - - - - - + Warning false - - - - vertical - 14 - 12 - 12 - 12 - 12 + zenity_warning_box + + _OK + + + + 14 + 12 + 12 + 12 + 12 + + + 12 - - horizontal - 12 - - - dialog-password - large - - - - - Type your password - - + + dialog-warning + large - - 12 - 6 + + center + true + true + Are you sure you want to proceed? + true + true + false - + - - zenity_password_ok_button - zenity_password_cancel_button - - + + + Warning + false + zenity_password_box + + _Cancel + _OK + + + + vertical + 14 + 12 + 12 + 12 + 12 + - True - False + horizontal + 12 - - true - _OK + + dialog-password + large - - true - _Cancel + + Type your password - + + + 12 + 6 + + + -- cgit v1.2.1