Created open game functionality in the player. Fix #37.
[rodin/chimara.git] / tests / error.c
1 /*  Copyright 2006 P.F. Chimento
2  *  This file is part of GNOME Inform 7.
3  * 
4  *  GNOME Inform 7 is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  GNOME Inform 7 is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with GNOME Inform 7; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18  
19 #include <gtk/gtk.h>
20 #include <stdarg.h>
21
22 #include "error.h"
23
24 /* Create and display an error dialog box, with parent window parent, and
25 message format string msg. If err is not NULL, tack the error message on to the
26 end of the format string. */
27 void 
28 error_dialog(GtkWindow *parent, GError *err, const gchar *msg, ...) 
29 {
30     va_list ap;
31     
32     va_start(ap, msg);
33     gchar buffer[1024];
34     g_vsnprintf(buffer, 1024, msg, ap);
35     va_end(ap);
36     
37     gchar *message;
38     if(err) {
39         message = g_strconcat(buffer, err->message, NULL);
40         g_error_free(err);
41     } else
42         message = g_strdup(buffer);
43     
44     GtkWidget *dialog = gtk_message_dialog_new(parent,
45           parent? GTK_DIALOG_DESTROY_WITH_PARENT : 0,
46           GTK_MESSAGE_ERROR,
47           GTK_BUTTONS_OK,
48           message);
49     gtk_dialog_run(GTK_DIALOG(dialog));
50     gtk_widget_destroy(dialog);
51     g_free(message);
52 }