From e944335a838e194ef54d48a8d32f3e4f5eaacac7 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Wed, 12 Aug 2015 13:06:20 +0200 Subject: [PATCH] Adesso SolipaUtils::message_dialog supporta argomenti variabili alla printf (closes #453). --- src/utils.c | 15 +++++++++-- src/utils.h | 3 ++- tests/Makefile.am | 1 + tests/utils_message_dialog.c | 49 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 tests/utils_message_dialog.c diff --git a/src/utils.c b/src/utils.c index 3967309..64516ff 100644 --- a/src/utils.c +++ b/src/utils.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -1656,21 +1657,31 @@ gint solipa_message_dialog (GtkWidget *transient, GtkMessageType type, GtkButtonsType buttons, - const gchar *message_text) + const gchar *message_text, + ...) { gint risp; + va_list ap; + gchar *_message_text; GtkWidget *dialog; g_return_val_if_fail (GTK_IS_WINDOW (transient), GTK_RESPONSE_NONE); + va_start (ap, message_text); + _message_text = NULL; + g_vasprintf (&_message_text, message_text, ap); + va_end (ap); + dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (transient), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, type, buttons, - message_text); + _message_text); risp = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); + g_free (_message_text); + return risp; } diff --git a/src/utils.h b/src/utils.h index b6bd272..d00b7ff 100644 --- a/src/utils.h +++ b/src/utils.h @@ -95,7 +95,8 @@ void solipa_load_window_position (const gchar *app_name, GtkWidget *widget, cons gint solipa_message_dialog (GtkWidget *transient, GtkMessageType type, GtkButtonsType buttons, - const gchar *message_text); + const gchar *message_text, + ...); GtkWidget *solipa_info_bar (GtkMessageType type, const gchar *message_text); diff --git a/tests/Makefile.am b/tests/Makefile.am index 320b061..6c4bf75 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -32,4 +32,5 @@ noinst_PROGRAMS = allegato \ utils_gstring_initial_capital \ utils_gtktreemodel_copy \ utils_infobar \ + utils_message_dialog \ utils_round diff --git a/tests/utils_message_dialog.c b/tests/utils_message_dialog.c new file mode 100644 index 0000000..b79c1ed --- /dev/null +++ b/tests/utils_message_dialog.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +gboolean +on_w_delete_event (GtkWidget *widget, + GdkEvent *event, + gpointer user_data) +{ + return FALSE; +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *w; + + gtk_init (&argc, &argv); + + w = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (w, "delete-event", G_CALLBACK (on_w_delete_event), NULL); + g_signal_connect (w, "destroy", gtk_main_quit, NULL); + + solipa_message_dialog (w, + GTK_MESSAGE_WARNING, + GTK_BUTTONS_OK, + "Impossibile aprire il collegamento selezionato (%s): %s.", + "bla bla bla", + "nessun dettaglio"); + + return 0; +} -- 2.49.0