diff options
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | capture.c | 3 | ||||
-rw-r--r-- | colors.c | 4 | ||||
-rw-r--r-- | file.c | 24 | ||||
-rw-r--r-- | gtk/Makefile.am | 5 | ||||
-rw-r--r-- | gtk/capture_dlg.c | 4 | ||||
-rw-r--r-- | gtk/file_dlg.c | 6 | ||||
-rw-r--r-- | gtk/find_dlg.c | 4 | ||||
-rw-r--r-- | gtk/goto_dlg.c | 4 | ||||
-rw-r--r-- | gtk/gtkglobals.h | 6 | ||||
-rw-r--r-- | gtk/main.c | 29 | ||||
-rw-r--r-- | gtk/print_dlg.c | 4 | ||||
-rw-r--r-- | gtk/ui_util.c | 198 | ||||
-rw-r--r-- | prefs.c | 4 | ||||
-rw-r--r-- | ui_util.h | 56 | ||||
-rw-r--r-- | util.c | 132 | ||||
-rw-r--r-- | util.h | 18 |
17 files changed, 315 insertions, 189 deletions
diff --git a/Makefile.am b/Makefile.am index 4276a31513..b596543f8e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for Ethereal # -# $Id: Makefile.am,v 1.129 1999/12/09 04:06:53 nneul Exp $ +# $Id: Makefile.am,v 1.130 1999/12/09 07:19:01 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@zing.org> @@ -204,6 +204,7 @@ ethereal_SOURCES = \ timestamp.h \ util.c \ util.h \ + ui_util.h \ xdlc.c \ xdlc.h \ $(DISSECTOR_SOURCES) @@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.85 1999/11/30 23:56:34 gram Exp $ + * $Id: capture.c,v 1.86 1999/12/09 07:19:02 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -90,6 +90,7 @@ #include "gtk/menu.h" #include "capture.h" #include "util.h" +#include "ui_util.h" #include "prefs.h" #include "globals.h" @@ -1,7 +1,7 @@ /* colors.c * Definitions for color structures and routines * - * $Id: colors.c,v 1.17 1999/11/30 05:32:56 guy Exp $ + * $Id: colors.c,v 1.18 1999/12/09 07:19:02 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -41,7 +41,7 @@ #include "colors.h" #include "file.h" #include "dfilter.h" -#include "util.h" +#include "ui_util.h" extern capture_file cf; @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.134 1999/12/04 11:32:24 guy Exp $ + * $Id: file.c,v 1.135 1999/12/09 07:19:03 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -76,6 +76,7 @@ #include "print.h" #include "file.h" #include "util.h" +#include "ui_util.h" #include "gtk/proto_draw.h" #include "dfilter.h" #include "timestamp.h" @@ -229,6 +230,9 @@ close_cap_file(capture_file *cf, void *w) will there ever be more than one on the stack? */ gtk_statusbar_pop(GTK_STATUSBAR(w), file_ctx); + /* Restore the standard title bar message. */ + set_main_window_name("The Ethereal Network Analyzer"); + /* Disable all menu items that make sense only if you have a capture. */ set_menu_sensitivity("/File/Save", FALSE); set_menu_sensitivity("/File/Save As...", FALSE); @@ -247,13 +251,17 @@ close_cap_file(capture_file *cf, void *w) set_menu_sensitivity("/Tools/Summary", FALSE); } +/* Set the file name in the status line, in the name for the main window, + and in the name for the main window's icon. */ static void -set_statusbar_filename(capture_file *cf) +set_display_filename(capture_file *cf) { gchar *name_ptr; size_t msg_len; gchar *done_fmt = " File: %s Drops: %u"; gchar *done_msg; + gchar *win_name_fmt = "%s - Ethereal"; + gchar *win_name; if (!cf->is_tempfile) { /* Get the last component of the file name, and put that in the @@ -265,7 +273,7 @@ set_statusbar_filename(capture_file *cf) } else { /* The file we read is a temporary file from a live capture; we don't mention its name in the status bar. */ - name_ptr = "<none>"; + name_ptr = "<capture>"; } msg_len = strlen(name_ptr) + strlen(done_fmt) + 64; @@ -273,6 +281,12 @@ set_statusbar_filename(capture_file *cf) snprintf(done_msg, msg_len, done_fmt, name_ptr, cf->drops); gtk_statusbar_push(GTK_STATUSBAR(info_bar), file_ctx, done_msg); g_free(done_msg); + + msg_len = strlen(name_ptr) + strlen(win_name_fmt) + 1; + win_name = g_malloc(msg_len); + snprintf(win_name, msg_len, win_name_fmt, name_ptr); + set_main_window_name(win_name); + g_free(win_name); } int @@ -326,7 +340,7 @@ read_cap_file(capture_file *cf) gtk_progress_set_value(GTK_PROGRESS(prog_bar), 0); gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx); - set_statusbar_filename(cf); + set_display_filename(cf); /* Enable menu items that make sense if you have a capture file you've finished reading. */ @@ -471,7 +485,7 @@ finish_tail_cap_file(capture_file *cf) /* Pop the "<live capture in progress>" message off the status bar. */ gtk_statusbar_pop(GTK_STATUSBAR(info_bar), file_ctx); - set_statusbar_filename(cf); + set_display_filename(cf); /* Restore the "File/Open" menu item. */ set_menu_sensitivity("/File/Open...", TRUE); diff --git a/gtk/Makefile.am b/gtk/Makefile.am index e339ff390b..434ece6bbf 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for the GTK interface routines for Ethereal # -# $Id: Makefile.am,v 1.12 1999/12/07 22:06:25 gram Exp $ +# $Id: Makefile.am,v 1.13 1999/12/09 07:19:16 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@zing.org> @@ -56,4 +56,5 @@ libui_a_SOURCES = \ proto_draw.c \ proto_draw.h \ stream_prefs.c \ - stream_prefs.h + stream_prefs.h \ + ui_util.c diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 3831bf79ef..f9ff4bd574 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -1,7 +1,7 @@ /* capture_dlg.c * Routines for packet capture windows * - * $Id: capture_dlg.c,v 1.10 1999/12/07 22:11:02 guy Exp $ + * $Id: capture_dlg.c,v 1.11 1999/12/09 07:19:16 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -75,7 +75,7 @@ #include "main.h" #include "capture_dlg.h" #include "prefs_dlg.h" -#include "util.h" +#include "ui_util.h" /* Capture callback data keys */ #define E_CAP_IFACE_KEY "cap_iface" diff --git a/gtk/file_dlg.c b/gtk/file_dlg.c index d6f3980cb8..40672ba555 100644 --- a/gtk/file_dlg.c +++ b/gtk/file_dlg.c @@ -1,7 +1,7 @@ /* file_dlg.c * Dialog boxes for handling files * - * $Id: file_dlg.c,v 1.13 1999/12/06 09:02:48 guy Exp $ + * $Id: file_dlg.c,v 1.14 1999/12/09 07:19:17 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -52,8 +52,8 @@ #include "prefs_dlg.h" #endif -#ifndef __UTIL_H__ -#include "util.h" +#ifndef __UI_UTIL_H__ +#include "ui_util.h" #endif #ifndef __MENU_H__ diff --git a/gtk/find_dlg.c b/gtk/find_dlg.c index f9d5b1e2de..ba4f461836 100644 --- a/gtk/find_dlg.c +++ b/gtk/find_dlg.c @@ -1,7 +1,7 @@ /* find_dlg.c * Routines for "find frame" window * - * $Id: find_dlg.c,v 1.3 1999/11/06 06:54:02 guy Exp $ + * $Id: find_dlg.c,v 1.4 1999/12/09 07:19:17 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -44,7 +44,7 @@ #include "find_dlg.h" #include "prefs_dlg.h" -#include "util.h" +#include "ui_util.h" /* Capture callback data keys */ #define E_FIND_FILT_KEY "find_filter_te" diff --git a/gtk/goto_dlg.c b/gtk/goto_dlg.c index 03f662af21..02b16f6ea0 100644 --- a/gtk/goto_dlg.c +++ b/gtk/goto_dlg.c @@ -1,7 +1,7 @@ /* goto_dlg.c * Routines for "go to frame" window * - * $Id: goto_dlg.c,v 1.2 1999/11/30 07:27:29 guy Exp $ + * $Id: goto_dlg.c,v 1.3 1999/12/09 07:19:18 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -46,7 +46,7 @@ #include "goto_dlg.h" #include "prefs_dlg.h" -#include "util.h" +#include "ui_util.h" /* Capture callback data keys */ #define E_GOTO_FNUMBER_KEY "goto_fnumber_te" diff --git a/gtk/gtkglobals.h b/gtk/gtkglobals.h index 60f34068cb..32a23bdc39 100644 --- a/gtk/gtkglobals.h +++ b/gtk/gtkglobals.h @@ -1,7 +1,7 @@ /* gtkglobals.h * GTK-related Global defines, etc. * - * $Id: gtkglobals.h,v 1.1 1999/10/20 22:36:05 gram Exp $ + * $Id: gtkglobals.h,v 1.2 1999/12/09 07:19:18 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -30,8 +30,8 @@ #include <gtk/gtk.h> #endif -extern GtkWidget *file_sel, *packet_list, *tree_view, *byte_view, *prog_bar, - *info_bar; +extern GtkWidget *top_level, *file_sel, *packet_list, *tree_view, + *byte_view, *prog_bar, *info_bar; extern GdkFont *m_r_font, *m_b_font; extern GtkStyle *item_style; diff --git a/gtk/main.c b/gtk/main.c index 9a020e668a..7651067bdf 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.65 1999/12/07 22:59:18 guy Exp $ + * $Id: main.c,v 1.66 1999/12/09 07:19:18 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -100,6 +100,7 @@ #include "resolv.h" #include "follow.h" #include "util.h" +#include "ui_util.h" #include "proto_draw.h" #include "dfilter.h" #include "keys.h" @@ -107,8 +108,8 @@ FILE *data_out_file = NULL; packet_info pi; capture_file cf; -GtkWidget *file_sel, *packet_list, *tree_view, *byte_view, *prog_bar, - *info_bar; +GtkWidget *top_level, *file_sel, *packet_list, *tree_view, *byte_view, + *prog_bar, *info_bar; GdkFont *m_r_font, *m_b_font; guint main_ctx, file_ctx; gchar comp_info_str[256]; @@ -861,7 +862,7 @@ main(int argc, char *argv[]) #else gboolean capture_option_specified = FALSE; #endif - GtkWidget *window, *main_vbox, *menubar, *u_pane, *l_pane, + GtkWidget *main_vbox, *menubar, *u_pane, *l_pane, *bv_table, *bv_hscroll, *bv_vscroll, *stat_hbox, *tv_scrollw, *filter_bt, *filter_cm, *filter_te, *filter_reset; @@ -1183,25 +1184,25 @@ main(int argc, char *argv[]) } /* Main window */ - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_widget_set_name(window, "main window"); - gtk_signal_connect(GTK_OBJECT(window), "delete_event", + top_level = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_widget_set_name(top_level, "main window"); + gtk_signal_connect(GTK_OBJECT(top_level), "delete_event", GTK_SIGNAL_FUNC(file_quit_cmd_cb), "WM destroy"); - gtk_signal_connect(GTK_OBJECT(window), "destroy", + gtk_signal_connect(GTK_OBJECT(top_level), "destroy", GTK_SIGNAL_FUNC(file_quit_cmd_cb), "WM destroy"); - gtk_window_set_title(GTK_WINDOW(window), "The Ethereal Network Analyzer"); - gtk_widget_set_usize(GTK_WIDGET(window), DEF_WIDTH, -1); - gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE); + gtk_window_set_title(GTK_WINDOW(top_level), "The Ethereal Network Analyzer"); + gtk_widget_set_usize(GTK_WIDGET(top_level), DEF_WIDTH, -1); + gtk_window_set_policy(GTK_WINDOW(top_level), TRUE, TRUE, FALSE); /* Container for menu bar, paned windows and progress/info box */ main_vbox = gtk_vbox_new(FALSE, 1); gtk_container_border_width(GTK_CONTAINER(main_vbox), 1); - gtk_container_add(GTK_CONTAINER(window), main_vbox); + gtk_container_add(GTK_CONTAINER(top_level), main_vbox); gtk_widget_show(main_vbox); /* Menu bar */ get_main_menu(&menubar, &accel); - gtk_window_add_accel_group(GTK_WINDOW(window), accel); + gtk_window_add_accel_group(GTK_WINDOW(top_level), accel); gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0); gtk_widget_show(menubar); @@ -1362,7 +1363,7 @@ main(int argc, char *argv[]) /* No. Pop up the main window, and read in a capture file if we were told to. */ - gtk_widget_show(window); + gtk_widget_show(top_level); cf.colors = colfilter_new(); diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c index 079792573c..a90ab6f873 100644 --- a/gtk/print_dlg.c +++ b/gtk/print_dlg.c @@ -1,7 +1,7 @@ /* print_dlg.c * Dialog boxes for printing * - * $Id: print_dlg.c,v 1.9 1999/11/06 06:27:07 guy Exp $ + * $Id: print_dlg.c,v 1.10 1999/12/09 07:19:19 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -46,7 +46,7 @@ #endif #ifndef __UTIL_H__ -#include "util.h" +#include "ui_util.h" #endif static void print_cmd_toggle_dest(GtkWidget *widget, gpointer data); diff --git a/gtk/ui_util.c b/gtk/ui_util.c new file mode 100644 index 0000000000..084a843478 --- /dev/null +++ b/gtk/ui_util.c @@ -0,0 +1,198 @@ +/* ui_util.c + * UI utility routines + * + * $Id: ui_util.c,v 1.1 1999/12/09 07:19:20 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * 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. + * + * 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 "config.h" +#endif + +#include <glib.h> + +#include <gtk/gtk.h> + +#include <stdarg.h> +#include <stdio.h> + +#if 0 +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif + +#endif + +#ifdef NEED_SNPRINTF_H +# ifdef HAVE_STDARG_H +# include <stdarg.h> +# else +# include <varargs.h> +# endif +# include "snprintf.h" +#endif + +#include "gtkglobals.h" +#include "ui_util.h" + +#include "image/icon-excl.xpm" +#include "image/icon-ethereal.xpm" + +/* Set the name of the top-level window and its icon. + XXX - for some reason, KWM insists on making the icon name be just + the window name, in parentheses; perhaps it's trying to imitate + Windows here, or perhaps it's not the icon name that appears in + the taskbar. The KWM_WIN_TITLE string overrides that, but I + don't know how that gets set - it's set on "xterm"s, but they + aren't KWM-aware, as far as I know. */ +void +set_main_window_name(gchar *icon_name) +{ + gtk_window_set_title(GTK_WINDOW(top_level), icon_name); + gdk_window_set_icon_name(top_level->window, icon_name); +} + +static void simple_dialog_cancel_cb(GtkWidget *, gpointer); + +static const gchar bm_key[] = "button mask"; + +/* Simple dialog function - Displays a dialog box with the supplied message + * text. + * + * Args: + * type : One of ESD_TYPE_*. + * btn_mask : The address of a gint. The value passed in determines if + * the 'Cancel' button is displayed. The button pressed by the + * user is passed back. + * msg_format : Sprintf-style format of the text displayed in the dialog. + * ... : Argument list for msg_format + * + */ + +#define ESD_MAX_MSG_LEN 2048 +void +simple_dialog(gint type, gint *btn_mask, gchar *msg_format, ...) { + GtkWidget *win, *main_vb, *top_hb, *type_pm, *msg_label, + *bbox, *ok_btn, *cancel_btn; + GdkPixmap *pixmap; + GdkBitmap *mask; + GtkStyle *style; + GdkColormap *cmap; + va_list ap; + gchar message[ESD_MAX_MSG_LEN]; + gchar **icon; + + /* Main window */ + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_border_width(GTK_CONTAINER(win), 7); + + switch (type) { + case ESD_TYPE_WARN : + gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Warning"); + icon = icon_excl_xpm; + break; + case ESD_TYPE_CRIT : + gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Critical"); + icon = icon_excl_xpm; + break; + case ESD_TYPE_INFO : + default : + icon = icon_ethereal_xpm; + gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Information"); + break; + } + + gtk_object_set_data(GTK_OBJECT(win), bm_key, btn_mask); + + /* Container for our rows */ + main_vb = gtk_vbox_new(FALSE, 5); + gtk_container_border_width(GTK_CONTAINER(main_vb), 5); + gtk_container_add(GTK_CONTAINER(win), main_vb); + gtk_widget_show(main_vb); + + /* Top row: Icon and message text */ + top_hb = gtk_hbox_new(FALSE, 10); + gtk_container_add(GTK_CONTAINER(main_vb), top_hb); + gtk_widget_show(top_hb); + + style = gtk_widget_get_style(win); + cmap = gdk_colormap_get_system(); + pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, cmap, &mask, + &style->bg[GTK_STATE_NORMAL], icon); + type_pm = gtk_pixmap_new(pixmap, mask); + gtk_misc_set_alignment (GTK_MISC (type_pm), 0.5, 0.0); + gtk_container_add(GTK_CONTAINER(top_hb), type_pm); + gtk_widget_show(type_pm); + + /* Load our vararg list into the message string */ + va_start(ap, msg_format); + vsnprintf(message, ESD_MAX_MSG_LEN, msg_format, ap); + + msg_label = gtk_label_new(message); + gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL); + gtk_container_add(GTK_CONTAINER(top_hb), msg_label); + gtk_widget_show(msg_label); + + /* Button row */ + bbox = gtk_hbutton_box_new(); + gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END); + gtk_container_add(GTK_CONTAINER(main_vb), bbox); + gtk_widget_show(bbox); + + ok_btn = gtk_button_new_with_label ("OK"); + gtk_signal_connect_object(GTK_OBJECT(ok_btn), "clicked", + GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (win)); + gtk_container_add(GTK_CONTAINER(bbox), ok_btn); + GTK_WIDGET_SET_FLAGS(ok_btn, GTK_CAN_DEFAULT); + gtk_widget_grab_default(ok_btn); + gtk_widget_show(ok_btn); + + if (btn_mask && *btn_mask == ESD_BTN_CANCEL) { + cancel_btn = gtk_button_new_with_label("Cancel"); + gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked", + GTK_SIGNAL_FUNC(simple_dialog_cancel_cb), (gpointer) win); + gtk_container_add(GTK_CONTAINER(bbox), cancel_btn); + GTK_WIDGET_SET_FLAGS(cancel_btn, GTK_CAN_DEFAULT); + gtk_widget_show(cancel_btn); + } + + if (btn_mask) + *btn_mask = ESD_BTN_OK; + + gtk_widget_show(win); +} + +static void +simple_dialog_cancel_cb(GtkWidget *w, gpointer win) { + gint *btn_mask = (gint *) gtk_object_get_data(win, bm_key); + + if (btn_mask) + *btn_mask = ESD_BTN_CANCEL; + gtk_widget_destroy(GTK_WIDGET(win)); +} @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.23 1999/12/02 04:30:03 gerald Exp $ + * $Id: prefs.c,v 1.24 1999/12/09 07:19:04 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -51,7 +51,7 @@ #include "prefs.h" #include "column.h" #include "print.h" -#include "util.h" +#include "ui_util.h" /* Internal functions */ static int set_pref(gchar*, gchar*); diff --git a/ui_util.h b/ui_util.h new file mode 100644 index 0000000000..18908960d0 --- /dev/null +++ b/ui_util.h @@ -0,0 +1,56 @@ +/* ui_util.h + * Definitions for UI utility routines + * + * $Id: ui_util.h,v 1.1 1999/12/09 07:19:04 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * 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. + * + * 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. + */ + +#ifndef __UI_UTIL_H__ +#define __UI_UTIL_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Set the name of the top-level window and its icon. */ +void set_main_window_name(gchar *); + +/* Dialog type. */ +#define ESD_TYPE_INFO 0 +#define ESD_TYPE_WARN 1 +#define ESD_TYPE_CRIT 2 + +/* Which buttons to display. */ +#define ESD_BTN_OK 0 +#define ESD_BTN_CANCEL 1 + +#if __GNUC__ == 2 +void simple_dialog(gint, gint *, gchar *, ...) + __attribute__((format (printf, 3, 4))); +#else +void simple_dialog(gint, gint *, gchar *, ...); +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __UI_UTIL_H__ */ @@ -1,7 +1,7 @@ /* util.c * Utility routines * - * $Id: util.c,v 1.23 1999/11/22 06:24:42 gram Exp $ + * $Id: util.c,v 1.24 1999/12/09 07:19:05 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -29,18 +29,11 @@ #include <glib.h> -#include <gtk/gtk.h> - -#include <stdarg.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <errno.h> -#ifdef HAVE_FCNTL_H -#include <fcntl.h> -#endif - #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -64,128 +57,6 @@ #include "util.h" -#include "image/icon-excl.xpm" -#include "image/icon-ethereal.xpm" - -static void simple_dialog_cancel_cb(GtkWidget *, gpointer); - -const gchar *bm_key = "button mask"; - -/* Simple dialog function - Displays a dialog box with the supplied message - * text. - * - * Args: - * type : One of ESD_TYPE_*. - * btn_mask : The address of a gint. The value passed in determines if - * the 'Cancel' button is displayed. The button pressed by the - * user is passed back. - * msg_format : Sprintf-style format of the text displayed in the dialog. - * ... : Argument list for msg_format - * - */ - -#define ESD_MAX_MSG_LEN 2048 -void -simple_dialog(gint type, gint *btn_mask, gchar *msg_format, ...) { - GtkWidget *win, *main_vb, *top_hb, *type_pm, *msg_label, - *bbox, *ok_btn, *cancel_btn; - GdkPixmap *pixmap; - GdkBitmap *mask; - GtkStyle *style; - GdkColormap *cmap; - va_list ap; - gchar message[ESD_MAX_MSG_LEN]; - gchar **icon; - - /* Main window */ - win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_container_border_width(GTK_CONTAINER(win), 7); - - switch (type) { - case ESD_TYPE_WARN : - gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Warning"); - icon = icon_excl_xpm; - break; - case ESD_TYPE_CRIT : - gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Critical"); - icon = icon_excl_xpm; - break; - case ESD_TYPE_INFO : - default : - icon = icon_ethereal_xpm; - gtk_window_set_title(GTK_WINDOW(win), "Ethereal: Information"); - break; - } - - gtk_object_set_data(GTK_OBJECT(win), bm_key, btn_mask); - - /* Container for our rows */ - main_vb = gtk_vbox_new(FALSE, 5); - gtk_container_border_width(GTK_CONTAINER(main_vb), 5); - gtk_container_add(GTK_CONTAINER(win), main_vb); - gtk_widget_show(main_vb); - - /* Top row: Icon and message text */ - top_hb = gtk_hbox_new(FALSE, 10); - gtk_container_add(GTK_CONTAINER(main_vb), top_hb); - gtk_widget_show(top_hb); - - style = gtk_widget_get_style(win); - cmap = gdk_colormap_get_system(); - pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, cmap, &mask, - &style->bg[GTK_STATE_NORMAL], icon); - type_pm = gtk_pixmap_new(pixmap, mask); - gtk_misc_set_alignment (GTK_MISC (type_pm), 0.5, 0.0); - gtk_container_add(GTK_CONTAINER(top_hb), type_pm); - gtk_widget_show(type_pm); - - /* Load our vararg list into the message string */ - va_start(ap, msg_format); - vsnprintf(message, ESD_MAX_MSG_LEN, msg_format, ap); - - msg_label = gtk_label_new(message); - gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL); - gtk_container_add(GTK_CONTAINER(top_hb), msg_label); - gtk_widget_show(msg_label); - - /* Button row */ - bbox = gtk_hbutton_box_new(); - gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END); - gtk_container_add(GTK_CONTAINER(main_vb), bbox); - gtk_widget_show(bbox); - - ok_btn = gtk_button_new_with_label ("OK"); - gtk_signal_connect_object(GTK_OBJECT(ok_btn), "clicked", - GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (win)); - gtk_container_add(GTK_CONTAINER(bbox), ok_btn); - GTK_WIDGET_SET_FLAGS(ok_btn, GTK_CAN_DEFAULT); - gtk_widget_grab_default(ok_btn); - gtk_widget_show(ok_btn); - - if (btn_mask && *btn_mask == ESD_BTN_CANCEL) { - cancel_btn = gtk_button_new_with_label("Cancel"); - gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked", - GTK_SIGNAL_FUNC(simple_dialog_cancel_cb), (gpointer) win); - gtk_container_add(GTK_CONTAINER(bbox), cancel_btn); - GTK_WIDGET_SET_FLAGS(cancel_btn, GTK_CAN_DEFAULT); - gtk_widget_show(cancel_btn); - } - - if (btn_mask) - *btn_mask = ESD_BTN_OK; - - gtk_widget_show(win); -} - -static void -simple_dialog_cancel_cb(GtkWidget *w, gpointer win) { - gint *btn_mask = (gint *) gtk_object_get_data(win, bm_key); - - if (btn_mask) - *btn_mask = ESD_BTN_CANCEL; - gtk_widget_destroy(GTK_WIDGET(win)); -} - static char * setup_tmpdir(char *dir) { @@ -396,4 +267,3 @@ EBCDIC_to_ASCII1(guint8 c) { return EBCDIC_translate_ASCII[c]; } - @@ -1,7 +1,7 @@ /* util.h * Utility definitions * - * $Id: util.h,v 1.13 1999/11/22 06:24:42 gram Exp $ + * $Id: util.h,v 1.14 1999/12/09 07:19:05 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -30,22 +30,6 @@ extern "C" { #endif /* __cplusplus */ -/* Dialog type. */ -#define ESD_TYPE_INFO 0 -#define ESD_TYPE_WARN 1 -#define ESD_TYPE_CRIT 2 - -/* Which buttons to display. */ -#define ESD_BTN_OK 0 -#define ESD_BTN_CANCEL 1 - -#if __GNUC__ == 2 -void simple_dialog(gint, gint *, gchar *, ...) - __attribute__((format (printf, 3, 4))); -#else -void simple_dialog(gint, gint *, gchar *, ...); -#endif - int create_tempfile(char *, int, const char *); void ASCII_to_EBCDIC(guint8 *buf, guint bytes); |