/* $Id$ */ /*- * Copyright (c) 2005 Benedikt Meurer * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program 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 General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_STDARG_H #include #endif #include #include /** * thunar_dialogs_show_error: * @widget : a #GtkWidget on which the error dialog should be shown or %NULL. * @error : a #GError, which gives a more precise description of the problem or %NULL. * @format : the printf()-style format for the primary problem description. * @... : argument list for the @format. * * Displays an error dialog on @widget using the @format as primary message and optionally * displaying @error as secondary error text. * * If @widget is not %NULL and @widget is part of a #GtkWindow, the function makes sure * that the toplevel window is visible prior to displaying the error dialog. **/ void thunar_dialogs_show_error (GtkWidget *widget, const GError *error, const gchar *format, ...) { GtkWidget *dialog; GtkWidget *window; va_list args; gchar *primary_text; /* determine the toplevel window and make sure it's shown */ window = (widget != NULL) ? gtk_widget_get_toplevel (widget) : NULL; if (G_LIKELY (window != NULL)) gtk_widget_show_now (window); /* determine the primary error text */ va_start (args, format); primary_text = g_strdup_vprintf (format, args); va_end (args); /* allocate the error dialog */ dialog = gtk_message_dialog_new ((GtkWindow *) window, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("%s."), primary_text); /* set secondary text if an error is provided */ if (G_LIKELY (error != NULL)) gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("%s."), error->message); /* display the dialog */ gtk_dialog_run (GTK_DIALOG (dialog)); /* cleanup */ gtk_widget_destroy (dialog); g_free (primary_text); }