2000-07-05 02:45:42 +00:00
|
|
|
/* simple_dialog.c
|
|
|
|
* Simple message dialog box routines.
|
2000-01-03 06:59:25 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-01-03 06:59:25 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2000-01-03 06:59:25 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-01-03 06:59:25 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-01-03 06:59:25 +00:00
|
|
|
* 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 "config.h"
|
|
|
|
#endif
|
2008-04-13 03:32:24 +00:00
|
|
|
#include <stdio.h>
|
2000-01-03 06:59:25 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2008-04-13 03:32:24 +00:00
|
|
|
#include <epan/strutil.h>
|
2000-01-03 06:59:25 +00:00
|
|
|
|
2008-04-13 03:32:24 +00:00
|
|
|
#include "../simple_dialog.h"
|
2000-01-03 06:59:25 +00:00
|
|
|
|
2008-04-13 03:32:24 +00:00
|
|
|
#include "gtk/gtkglobals.h"
|
|
|
|
#include "gtk/dlg_utils.h"
|
|
|
|
#include "gtk/gui_utils.h"
|
|
|
|
#include "gtk/stock_icons.h"
|
2004-05-01 22:55:22 +00:00
|
|
|
|
2004-01-31 01:28:11 +00:00
|
|
|
#include "image/stock_dialog_error_48.xpm"
|
|
|
|
#include "image/stock_dialog_info_48.xpm"
|
|
|
|
#include "image/stock_dialog_warning_48.xpm"
|
2005-09-20 01:53:38 +00:00
|
|
|
#include "image/stock_dialog_stop_48.xpm"
|
2000-01-03 06:59:25 +00:00
|
|
|
|
2008-04-13 03:32:24 +00:00
|
|
|
|
2000-01-03 06:59:25 +00:00
|
|
|
static void simple_dialog_cancel_cb(GtkWidget *, gpointer);
|
|
|
|
|
2004-01-29 23:07:17 +00:00
|
|
|
#define CALLBACK_FCT_KEY "ESD_Callback_Fct"
|
|
|
|
#define CALLBACK_BTN_KEY "ESD_Callback_Btn"
|
|
|
|
#define CALLBACK_DATA_KEY "ESD_Callback_Data"
|
2005-04-16 19:18:05 +00:00
|
|
|
#define CHECK_BUTTON "ESD_Check_Button"
|
2000-01-03 06:59:25 +00:00
|
|
|
|
2004-04-16 23:17:13 +00:00
|
|
|
/*
|
|
|
|
* Queue for messages requested before we have a main window.
|
2000-01-03 06:59:25 +00:00
|
|
|
*/
|
2004-04-16 23:17:13 +00:00
|
|
|
typedef struct {
|
|
|
|
gint type;
|
|
|
|
gint btn_mask;
|
|
|
|
char *message;
|
|
|
|
} queued_message_t;
|
2007-01-20 02:05:49 +00:00
|
|
|
|
2004-04-16 23:17:13 +00:00
|
|
|
static GSList *message_queue;
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
display_simple_dialog(gint type, gint btn_mask, char *message)
|
|
|
|
{
|
2005-04-16 19:18:05 +00:00
|
|
|
GtkWidget *win, *main_vb, *top_hb, *msg_vb, *type_pm, *msg_label, *ask_cb,
|
2004-07-13 07:15:45 +00:00
|
|
|
*bbox, *ok_bt, *yes_bt, *bt, *save_bt, *dont_save_bt;
|
2000-01-03 06:59:25 +00:00
|
|
|
GdkPixmap *pixmap;
|
|
|
|
GdkBitmap *mask;
|
|
|
|
GtkStyle *style;
|
|
|
|
GdkColormap *cmap;
|
2005-08-08 17:22:55 +00:00
|
|
|
const gchar **icon;
|
2000-01-03 06:59:25 +00:00
|
|
|
|
|
|
|
/* Main window */
|
2004-02-12 22:24:28 +00:00
|
|
|
switch (type) {
|
2000-01-03 06:59:25 +00:00
|
|
|
case ESD_TYPE_WARN :
|
2004-01-31 01:28:11 +00:00
|
|
|
icon = stock_dialog_warning_48_xpm;
|
2000-01-03 06:59:25 +00:00
|
|
|
break;
|
2004-02-11 03:55:48 +00:00
|
|
|
case ESD_TYPE_CONFIRMATION:
|
|
|
|
icon = stock_dialog_warning_48_xpm;
|
2004-01-31 12:13:23 +00:00
|
|
|
break;
|
2004-01-31 02:25:46 +00:00
|
|
|
case ESD_TYPE_ERROR:
|
2004-01-31 01:28:11 +00:00
|
|
|
icon = stock_dialog_error_48_xpm;
|
2000-01-03 06:59:25 +00:00
|
|
|
break;
|
2005-09-20 01:53:38 +00:00
|
|
|
case ESD_TYPE_STOP :
|
|
|
|
icon = stock_dialog_stop_48_xpm;
|
|
|
|
break;
|
2000-01-03 06:59:25 +00:00
|
|
|
case ESD_TYPE_INFO :
|
|
|
|
default :
|
2004-01-31 01:28:11 +00:00
|
|
|
icon = stock_dialog_info_48_xpm;
|
2000-01-03 06:59:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-02-11 03:40:17 +00:00
|
|
|
/*
|
|
|
|
* The GNOME HIG:
|
|
|
|
*
|
|
|
|
* http://developer.gnome.org/projects/gup/hig/1.0/windows.html#alert-windows
|
|
|
|
*
|
|
|
|
* says that the title should be empty for alert boxes, so there's "less
|
|
|
|
* visual noise and confounding text."
|
|
|
|
*
|
|
|
|
* The Windows HIG:
|
|
|
|
*
|
|
|
|
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch09f.asp
|
|
|
|
*
|
|
|
|
* says it should
|
|
|
|
*
|
|
|
|
* ...appropriately identify the source of the message -- usually
|
|
|
|
* the name of the object. For example, if the message results
|
|
|
|
* from editing a document, the title text is the name of the
|
|
|
|
* document, optionally followed by the application name. If the
|
|
|
|
* message results from a non-document object, then use the
|
|
|
|
* application name."
|
|
|
|
*
|
|
|
|
* and notes that the title is important "because message boxes might
|
|
|
|
* not always the the result of current user interaction" (e.g., some
|
|
|
|
* app might randomly pop something up, e.g. some browser letting you
|
|
|
|
* know that it couldn't fetch something because of a timeout).
|
|
|
|
*
|
|
|
|
* It also says not to use "warning" or "caution", as there's already
|
|
|
|
* an icon that tells you what type of alert it is, and that you
|
|
|
|
* shouldn't say "error", as that provides no useful information.
|
|
|
|
*
|
|
|
|
* So we give it a title on Win32, and don't give it one on UN*X.
|
2006-05-22 07:29:40 +00:00
|
|
|
* For now, we give it a Win32 title of just "Wireshark"; we should
|
2004-02-11 03:40:17 +00:00
|
|
|
* arguably take an argument for the title.
|
|
|
|
*/
|
2005-09-20 01:53:38 +00:00
|
|
|
if(btn_mask == ESD_BTN_NONE) {
|
|
|
|
win = splash_window_new();
|
|
|
|
} else {
|
2004-02-11 03:40:17 +00:00
|
|
|
#ifdef _WIN32
|
2006-05-22 07:29:40 +00:00
|
|
|
win = dlg_window_new("Wireshark");
|
2004-02-11 03:40:17 +00:00
|
|
|
#else
|
2005-09-20 01:53:38 +00:00
|
|
|
win = dlg_window_new("");
|
2004-01-31 12:13:23 +00:00
|
|
|
#endif
|
2005-09-20 01:53:38 +00:00
|
|
|
}
|
2004-01-31 12:13:23 +00:00
|
|
|
|
2004-02-12 22:24:28 +00:00
|
|
|
gtk_window_set_modal(GTK_WINDOW(win), TRUE);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(win), 6);
|
2000-08-23 06:56:31 +00:00
|
|
|
|
2000-01-03 06:59:25 +00:00
|
|
|
/* Container for our rows */
|
2004-01-31 12:13:23 +00:00
|
|
|
main_vb = gtk_vbox_new(FALSE, 12);
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(win), main_vb);
|
|
|
|
gtk_widget_show(main_vb);
|
|
|
|
|
|
|
|
/* Top row: Icon and message text */
|
2004-01-31 12:13:23 +00:00
|
|
|
top_hb = gtk_hbox_new(FALSE, 12);
|
2008-06-29 15:51:43 +00:00
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(main_vb), 6);
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), top_hb);
|
|
|
|
gtk_widget_show(top_hb);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2005-04-16 19:18:05 +00:00
|
|
|
/* icon */
|
2000-01-03 06:59:25 +00:00
|
|
|
style = gtk_widget_get_style(win);
|
|
|
|
cmap = gdk_colormap_get_system();
|
|
|
|
pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, cmap, &mask,
|
2005-08-08 17:22:55 +00:00
|
|
|
&style->bg[GTK_STATE_NORMAL], (gchar **) icon);
|
2000-01-03 06:59:25 +00:00
|
|
|
type_pm = gtk_pixmap_new(pixmap, mask);
|
2009-04-21 16:57:52 +00:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (type_pm), 0.5f, 0.0f);
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(top_hb), type_pm);
|
|
|
|
gtk_widget_show(type_pm);
|
|
|
|
|
2005-04-16 19:18:05 +00:00
|
|
|
/* column for message and optional check button */
|
|
|
|
msg_vb = gtk_vbox_new(FALSE, 6);
|
|
|
|
gtk_box_set_spacing(GTK_BOX(msg_vb), 24);
|
|
|
|
gtk_container_add(GTK_CONTAINER(top_hb), msg_vb);
|
|
|
|
gtk_widget_show(msg_vb);
|
|
|
|
|
|
|
|
/* message */
|
2000-01-03 06:59:25 +00:00
|
|
|
msg_label = gtk_label_new(message);
|
2004-01-31 12:13:23 +00:00
|
|
|
|
|
|
|
gtk_label_set_markup(GTK_LABEL(msg_label), message);
|
2004-01-31 12:49:54 +00:00
|
|
|
gtk_label_set_selectable(GTK_LABEL(msg_label), TRUE);
|
2008-04-07 01:05:55 +00:00
|
|
|
#if GTK_CHECK_VERSION(2,9,0)
|
2007-01-20 02:05:49 +00:00
|
|
|
g_object_set(gtk_widget_get_settings(msg_label),
|
|
|
|
"gtk-label-select-on-focus", FALSE, NULL);
|
2004-01-31 12:13:23 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL);
|
2009-04-21 16:57:52 +00:00
|
|
|
gtk_misc_set_alignment (GTK_MISC (type_pm), 0.5f, 0.0f);
|
2005-04-16 19:18:05 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(msg_vb), msg_label);
|
2007-03-01 02:18:18 +00:00
|
|
|
gtk_label_set_line_wrap(GTK_LABEL(msg_label), TRUE);
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_widget_show(msg_label);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2005-09-20 01:53:38 +00:00
|
|
|
if(btn_mask == ESD_BTN_NONE) {
|
|
|
|
gtk_widget_show(win);
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
2005-04-16 19:18:05 +00:00
|
|
|
/* optional check button */
|
|
|
|
ask_cb = gtk_check_button_new_with_label("replace with text...");
|
|
|
|
gtk_container_add(GTK_CONTAINER(msg_vb), ask_cb);
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(win), CHECK_BUTTON, ask_cb);
|
2005-04-16 19:18:05 +00:00
|
|
|
|
2000-01-03 06:59:25 +00:00
|
|
|
/* Button row */
|
2004-01-29 23:07:17 +00:00
|
|
|
switch(btn_mask) {
|
|
|
|
case(ESD_BTN_OK):
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
|
|
|
|
break;
|
2004-06-18 07:41:21 +00:00
|
|
|
case(ESD_BTN_OK | ESD_BTN_CANCEL):
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
|
|
|
|
break;
|
2004-01-31 12:13:23 +00:00
|
|
|
case(ESD_BTN_CLEAR | ESD_BTN_CANCEL):
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_CLEAR, GTK_STOCK_CANCEL, NULL);
|
2004-01-29 23:07:17 +00:00
|
|
|
break;
|
2004-02-04 01:10:37 +00:00
|
|
|
case(ESD_BTNS_YES_NO_CANCEL):
|
2004-01-29 23:07:17 +00:00
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_YES, GTK_STOCK_NO, GTK_STOCK_CANCEL, NULL);
|
|
|
|
break;
|
2004-07-13 07:15:45 +00:00
|
|
|
case(ESD_BTNS_SAVE_DONTSAVE_CANCEL):
|
2006-05-28 17:19:08 +00:00
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_SAVE, WIRESHARK_STOCK_DONT_SAVE, GTK_STOCK_CANCEL, NULL);
|
2004-07-13 07:15:45 +00:00
|
|
|
break;
|
2009-05-27 02:42:43 +00:00
|
|
|
case(ESD_BTNS_SAVE_QUIT_DONTSAVE_CANCEL):
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_SAVE, WIRESHARK_STOCK_QUIT_DONT_SAVE, GTK_STOCK_CANCEL, NULL);
|
|
|
|
break;
|
2004-06-17 21:34:12 +00:00
|
|
|
case(ESD_BTNS_YES_NO):
|
|
|
|
bbox = dlg_button_row_new(GTK_STOCK_YES, GTK_STOCK_NO, NULL);
|
|
|
|
break;
|
2004-01-29 23:07:17 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2004-01-31 03:22:42 +00:00
|
|
|
bbox = NULL;
|
|
|
|
break;
|
2004-01-21 21:19:34 +00:00
|
|
|
}
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(main_vb), bbox);
|
|
|
|
gtk_widget_show(bbox);
|
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
|
2004-01-31 12:13:23 +00:00
|
|
|
if(ok_bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(ok_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_OK));
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(ok_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
2004-01-31 12:13:23 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
save_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_SAVE);
|
2004-07-13 07:15:45 +00:00
|
|
|
if (save_bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(save_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_SAVE));
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(save_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
2004-07-13 07:15:45 +00:00
|
|
|
}
|
2007-01-20 02:05:49 +00:00
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
dont_save_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_DONT_SAVE);
|
2004-07-13 07:15:45 +00:00
|
|
|
if (dont_save_bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(dont_save_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_DONT_SAVE));
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(dont_save_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
2007-01-20 02:05:49 +00:00
|
|
|
}
|
2009-05-27 02:42:43 +00:00
|
|
|
|
|
|
|
dont_save_bt = g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_QUIT_DONT_SAVE);
|
|
|
|
if (dont_save_bt) {
|
|
|
|
g_object_set_data(G_OBJECT(dont_save_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_QUIT_DONT_SAVE));
|
|
|
|
g_signal_connect(dont_save_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
|
|
|
}
|
2008-04-11 16:04:54 +00:00
|
|
|
bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLEAR);
|
2004-01-29 23:07:17 +00:00
|
|
|
if(bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_CLEAR));
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
2004-01-29 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
yes_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_YES);
|
2004-06-17 21:34:12 +00:00
|
|
|
if(yes_bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(yes_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_YES));
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(yes_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
2004-01-29 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_NO);
|
2004-01-29 23:07:17 +00:00
|
|
|
if(bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_NO));
|
2008-04-11 23:16:06 +00:00
|
|
|
g_signal_connect(bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
|
2004-01-29 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
|
2004-01-29 23:07:17 +00:00
|
|
|
if(bt) {
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_CANCEL));
|
2004-05-26 03:49:24 +00:00
|
|
|
window_set_cancel_button(win, bt, simple_dialog_cancel_cb);
|
2000-01-03 06:59:25 +00:00
|
|
|
}
|
|
|
|
|
2004-01-31 12:13:23 +00:00
|
|
|
if(!bt) {
|
2004-06-17 21:34:12 +00:00
|
|
|
if(yes_bt) {
|
|
|
|
window_set_cancel_button(win, yes_bt, simple_dialog_cancel_cb);
|
|
|
|
} else {
|
|
|
|
window_set_cancel_button(win, ok_bt, simple_dialog_cancel_cb);
|
|
|
|
}
|
2004-01-31 12:13:23 +00:00
|
|
|
}
|
|
|
|
|
2007-01-20 02:05:49 +00:00
|
|
|
dlg_button_focus_nth(bbox, 0);
|
|
|
|
|
2000-01-03 06:59:25 +00:00
|
|
|
gtk_widget_show(win);
|
2004-01-29 23:07:17 +00:00
|
|
|
|
|
|
|
return win;
|
2000-01-03 06:59:25 +00:00
|
|
|
}
|
|
|
|
|
2004-04-16 23:17:13 +00:00
|
|
|
void
|
|
|
|
display_queued_messages(void)
|
|
|
|
{
|
|
|
|
queued_message_t *queued_message;
|
|
|
|
|
|
|
|
while (message_queue != NULL) {
|
|
|
|
queued_message = message_queue->data;
|
|
|
|
message_queue = g_slist_remove(message_queue, queued_message);
|
|
|
|
|
|
|
|
display_simple_dialog(queued_message->type, queued_message->btn_mask,
|
|
|
|
queued_message->message);
|
|
|
|
|
|
|
|
g_free(queued_message->message);
|
|
|
|
g_free(queued_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simple dialog function - Displays a dialog box with the supplied message
|
|
|
|
* text.
|
|
|
|
*
|
|
|
|
* Args:
|
|
|
|
* type : One of ESD_TYPE_*.
|
|
|
|
* btn_mask : The value passed in determines which buttons are displayed.
|
|
|
|
* msg_format : Sprintf-style format of the text displayed in the dialog.
|
|
|
|
* ... : Argument list for msg_format
|
|
|
|
*/
|
|
|
|
|
|
|
|
gpointer
|
2004-06-04 21:12:01 +00:00
|
|
|
vsimple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, va_list ap)
|
2004-04-16 23:17:13 +00:00
|
|
|
{
|
2004-06-29 22:21:04 +00:00
|
|
|
gchar *vmessage;
|
2004-04-16 23:17:13 +00:00
|
|
|
gchar *message;
|
|
|
|
queued_message_t *queued_message;
|
|
|
|
GtkWidget *win;
|
2004-05-16 18:42:55 +00:00
|
|
|
GdkWindowState state = 0;
|
2004-04-16 23:17:13 +00:00
|
|
|
|
|
|
|
/* Format the message. */
|
2004-06-29 22:21:04 +00:00
|
|
|
vmessage = g_strdup_vprintf(msg_format, ap);
|
|
|
|
|
|
|
|
/* convert character encoding from locale to UTF8 (using iconv) */
|
|
|
|
message = g_locale_to_utf8(vmessage, -1, NULL, NULL, NULL);
|
|
|
|
g_free(vmessage);
|
2004-04-16 23:17:13 +00:00
|
|
|
|
2004-05-16 18:42:55 +00:00
|
|
|
if (top_level != NULL) {
|
|
|
|
state = gdk_window_get_state(top_level->window);
|
|
|
|
}
|
|
|
|
|
2007-01-20 02:05:49 +00:00
|
|
|
/* If we don't yet have a main window or it's iconified, don't show the
|
|
|
|
dialog. If showing up a dialog, while main window is iconified, program
|
|
|
|
will become unresponsive! */
|
2004-05-17 21:15:28 +00:00
|
|
|
if (top_level == NULL || state & GDK_WINDOW_STATE_ICONIFIED) {
|
2004-05-16 18:42:55 +00:00
|
|
|
|
2004-04-16 23:17:13 +00:00
|
|
|
queued_message = g_malloc(sizeof (queued_message_t));
|
|
|
|
queued_message->type = type;
|
|
|
|
queued_message->btn_mask = btn_mask;
|
|
|
|
queued_message->message = message;
|
|
|
|
message_queue = g_slist_append(message_queue, queued_message);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have any queued up messages? If so, pop them up.
|
|
|
|
*/
|
|
|
|
display_queued_messages();
|
|
|
|
|
|
|
|
win = display_simple_dialog(type, btn_mask, message);
|
|
|
|
|
|
|
|
g_free(message);
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpointer
|
2004-06-04 21:12:01 +00:00
|
|
|
simple_dialog(ESD_TYPE_E type, gint btn_mask, const gchar *msg_format, ...)
|
2004-04-16 23:17:13 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
gpointer ret;
|
|
|
|
|
|
|
|
va_start(ap, msg_format);
|
|
|
|
ret = vsimple_dialog(type, btn_mask, msg_format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-01-03 06:59:25 +00:00
|
|
|
static void
|
2004-01-29 23:07:17 +00:00
|
|
|
simple_dialog_cancel_cb(GtkWidget *w, gpointer win) {
|
2008-04-11 16:04:54 +00:00
|
|
|
gint button = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w), CALLBACK_BTN_KEY));
|
|
|
|
simple_dialog_cb_t callback_fct = g_object_get_data(G_OBJECT(win), CALLBACK_FCT_KEY);
|
|
|
|
gpointer data = g_object_get_data(G_OBJECT(win), CALLBACK_DATA_KEY);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2004-01-29 23:07:17 +00:00
|
|
|
if (callback_fct)
|
|
|
|
(callback_fct) (win, button, data);
|
2006-10-31 01:44:11 +00:00
|
|
|
|
|
|
|
window_destroy(GTK_WIDGET(win));
|
2004-01-29 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
2005-09-20 01:53:38 +00:00
|
|
|
void
|
|
|
|
simple_dialog_close(gpointer dialog)
|
|
|
|
{
|
2008-04-11 16:04:54 +00:00
|
|
|
window_destroy(GTK_WIDGET(dialog));
|
2005-09-20 01:53:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-29 23:07:17 +00:00
|
|
|
void simple_dialog_set_cb(gpointer dialog, simple_dialog_cb_t callback_fct, gpointer data)
|
|
|
|
{
|
|
|
|
|
2008-04-11 16:04:54 +00:00
|
|
|
g_object_set_data(G_OBJECT(GTK_WIDGET(dialog)), CALLBACK_FCT_KEY, callback_fct);
|
|
|
|
g_object_set_data(G_OBJECT(GTK_WIDGET(dialog)), CALLBACK_DATA_KEY, data);
|
2000-01-03 06:59:25 +00:00
|
|
|
}
|
2004-02-03 17:59:01 +00:00
|
|
|
|
2007-04-24 05:46:13 +00:00
|
|
|
void simple_dialog_check_set(gpointer dialog, gchar *text _U_) {
|
2008-04-11 16:04:54 +00:00
|
|
|
GtkWidget *ask_cb = g_object_get_data(G_OBJECT(dialog), CHECK_BUTTON);
|
2005-04-16 19:18:05 +00:00
|
|
|
|
|
|
|
gtk_button_set_label(GTK_BUTTON(ask_cb), text);
|
|
|
|
gtk_widget_show(ask_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean simple_dialog_check_get(gpointer dialog) {
|
2008-04-11 16:04:54 +00:00
|
|
|
GtkWidget *ask_cb = g_object_get_data(G_OBJECT(GTK_WIDGET(dialog)), CHECK_BUTTON);
|
2005-04-16 19:18:05 +00:00
|
|
|
|
|
|
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ask_cb));
|
|
|
|
}
|
|
|
|
|
2004-02-03 17:59:01 +00:00
|
|
|
char *
|
|
|
|
simple_dialog_primary_start(void) {
|
2008-04-12 01:41:53 +00:00
|
|
|
return "<span weight=\"bold\" size=\"larger\">";
|
2004-02-03 17:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
simple_dialog_primary_end(void) {
|
2008-04-12 01:41:53 +00:00
|
|
|
return "</span>";
|
2004-02-03 17:59:01 +00:00
|
|
|
}
|
2004-05-01 22:55:22 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
simple_dialog_format_message(const char *msg)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (msg) {
|
|
|
|
str = xml_escape(msg);
|
|
|
|
} else {
|
|
|
|
str = NULL;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|