122 lines
3.2 KiB
C
122 lines
3.2 KiB
C
/*
|
|
Copyright (c) 2005 Joshua Elsasser. All rights reserved.
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
modification, are permitted provided that the following conditions
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
notice, this list of conditions and the following disclaimer.
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
notice, this list of conditions and the following disclaimer in the
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS "AS IS" AND
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "util.h"
|
|
|
|
static void
|
|
errcb(GtkWidget *widget, int resp, gpointer data);
|
|
|
|
gboolean
|
|
strbool(const char *str) {
|
|
switch(str[0]) {
|
|
case 'y':
|
|
case 'Y':
|
|
case '1':
|
|
case 'j':
|
|
case 'e':
|
|
return TRUE;
|
|
default:
|
|
if(0 == g_ascii_strcasecmp("on", str))
|
|
return TRUE;
|
|
break;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
GtkWidget *
|
|
errmsg(GtkWidget *wind, const char *format, ...) {
|
|
GtkWidget *dialog;
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
dialog = verrmsg(wind, NULL, NULL, format, ap);
|
|
va_end(ap);
|
|
|
|
return dialog;
|
|
}
|
|
|
|
GtkWidget *
|
|
errmsg_full(GtkWidget *wind, errfunc_t func, void *data,
|
|
const char *format, ...) {
|
|
GtkWidget *dialog;
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
dialog = verrmsg(wind, func, data, format, ap);
|
|
va_end(ap);
|
|
|
|
return dialog;
|
|
}
|
|
|
|
GtkWidget *
|
|
verrmsg(GtkWidget *wind, errfunc_t func, void *data,
|
|
const char *format, va_list ap) {
|
|
GtkWidget *dialog;
|
|
char *msg;
|
|
GList *funcdata;
|
|
|
|
msg = g_strdup_vprintf(format, ap);
|
|
|
|
if(NULL == wind)
|
|
dialog = gtk_message_dialog_new(
|
|
NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", msg);
|
|
else
|
|
dialog = gtk_message_dialog_new(
|
|
GTK_WINDOW(wind), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", msg);
|
|
|
|
if(NULL == func)
|
|
funcdata = NULL;
|
|
else
|
|
funcdata = g_list_append(g_list_append(NULL, func), data);
|
|
g_signal_connect(dialog, "response", G_CALLBACK(errcb), funcdata);
|
|
if(NULL != wind)
|
|
gtk_widget_show_all(dialog);
|
|
g_free(msg);
|
|
|
|
return dialog;
|
|
}
|
|
|
|
static void
|
|
errcb(GtkWidget *widget, int resp SHUTUP, gpointer data) {
|
|
GList *funcdata;
|
|
errfunc_t func;
|
|
|
|
if(NULL != data) {
|
|
funcdata = g_list_first(data);
|
|
func = funcdata->data;
|
|
data = funcdata->next->data;
|
|
func(data);
|
|
g_list_free(funcdata);
|
|
}
|
|
|
|
gtk_widget_destroy(widget);
|
|
}
|