Ethereal-dev: [Ethereal-dev] [Patch] show user-defined string in window titles - feature/patch
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Nathan Jennings <njen@xxxxxxxxxxxx>
Date: Thu, 02 Dec 2004 02:02:25 -0500
ronnie sahlberg wrote:
Why not just add the '-C' flag that someone else suggested as a short term solution and let whatever that flag specifies replace the '- Ethereal' string on the main window. Then the users can decide themself how and what they want specified as the title and we dont have to worry about policy.
I now see your point and agree that this is, at least, a good starting point. It may even end up being OK to leave in as *the* solution. It's flexible, let's the user decide on any string and avoids any Windows, or other platform, special cases. So, IMO, it's not a big deal that it doesn't automatically follow my host name changes. ;o)
Please see the attached patch. I ended up doing the following:Created a new preference setting named "gui.window_title". By default it's empty, so the standard titles are displayed. When a user-defined string is entered, it's prepended to the existing titles. For example, if I entered "[My host]" for the preference, I'd end up with something like this in the main window:
[My Host] The Ethereal Network Analyzer The same goes for the capture options and capture info dialogs. NOTE: There is a bug with this patch! :o(You must click "Save", then "OK" in the preferences dialog in order for the custom window title to show up correctly in the capture info dialog. I don't know why. Hopefully this can be easily corrected. The main window and capture options dialog work OK.
For the command-line or a script, the title can be passed as: ethereal -o "gui.window_title:[My Host]" Please let me know if I missed something or you have any other suggestions. -Nathan
Index: AUTHORS
===================================================================
--- AUTHORS (revision 12628)
+++ AUTHORS (working copy)
@@ -1933,7 +1933,7 @@
Support for saving RTP analysis data in CSV form
}
-Nathan Jennings <njen [AT] bellsouth.net> {
+Nathan Jennings <njen [AT] triad.rr.com> {
Support for user-supplied interface descriptions
Support for hiding interfaces in drop-down list in capture
dialog
Index: gtk/capture_info_dlg.c
===================================================================
--- gtk/capture_info_dlg.c (revision 12628)
+++ gtk/capture_info_dlg.c (working copy)
@@ -86,6 +86,7 @@
GtkWidget *counts_fr, *running_tb, *running_label, *bbox;
capture_info_ui_t *info;
gchar *cap_w_title;
+ gchar *title_iface;
info = g_malloc0(sizeof(capture_info_ui_t));
info->counts[0].title = "Total";
@@ -113,10 +114,14 @@
info->counts[11].title = "Other";
info->counts[11].value_ptr = &(cinfo->counts->other);
- cap_w_title = g_strdup_printf("Ethereal: Capture - Interface %s", iface);
+ /* use user-defined title if preference is set */
+ title_iface = g_strdup_printf("Ethereal: Capture - Interface %s", iface);
+ cap_w_title = create_user_window_title(title_iface);
info->cap_w = dlg_window_new(cap_w_title);
+ g_free(title_iface);
g_free(cap_w_title);
+
gtk_window_set_modal(GTK_WINDOW(info->cap_w), TRUE);
/* Container for capture display widgets */
Index: gtk/gui_prefs.c
===================================================================
--- gtk/gui_prefs.c (revision 12628)
+++ gtk/gui_prefs.c (working copy)
@@ -80,6 +80,7 @@
#define GUI_ASK_UNSAVED_KEY "ask_unsaved"
#define GUI_WEBBROWSER_KEY "webbrowser"
#define GUI_FIND_WRAP_KEY "find_wrap"
+#define GUI_WINDOW_TITLE_KEY "window_title"
#define GUI_TOOLBAR_STYLE_KEY "toolbar_style"
@@ -173,9 +174,9 @@
static char open_file_preview_str[128] = "";
#if GTK_MAJOR_VERSION < 2
+#define GUI_TABLE_ROWS 11
+#else
#define GUI_TABLE_ROWS 10
-#else
-#define GUI_TABLE_ROWS 9
#endif
GtkWidget*
@@ -192,6 +193,7 @@
GtkWidget *filter_toolbar_placement_om;
GtkWidget *recent_files_count_max_te, *ask_unsaved_cb, *find_wrap_cb;
GtkWidget *webbrowser_te;
+ GtkWidget *window_title_te;
GtkWidget *save_position_cb, *save_size_cb, *save_maximized_cb;
#if GTK_MAJOR_VERSION < 2
GtkWidget *expander_style_om, *line_style_om;
@@ -343,13 +345,18 @@
OBJECT_SET_DATA(main_vb, GUI_FIND_WRAP_KEY, find_wrap_cb);
/* Webbrowser */
- if(browser_needs_pref()) {
+ if (browser_needs_pref()) {
webbrowser_te = create_preference_entry(main_tb, pos++,
"Web browser command:", NULL, prefs.gui_webbrowser);
gtk_entry_set_text(GTK_ENTRY(webbrowser_te), prefs.gui_webbrowser);
OBJECT_SET_DATA(main_vb, GUI_WEBBROWSER_KEY, webbrowser_te);
}
+ /* Window title */
+ window_title_te = create_preference_entry(main_tb, pos++,
+ "Custom window title (prepended to existing titles):", NULL, prefs.gui_window_title);
+ gtk_entry_set_text(GTK_ENTRY(window_title_te), prefs.gui_window_title);
+ OBJECT_SET_DATA(main_vb, GUI_WINDOW_TITLE_KEY, window_title_te);
/* Show 'em what we got */
gtk_widget_show_all(main_vb);
@@ -456,12 +463,16 @@
prefs.gui_find_wrap =
gtk_toggle_button_get_active(OBJECT_GET_DATA(w, GUI_FIND_WRAP_KEY));
- if(browser_needs_pref()) {
+ if (browser_needs_pref()) {
g_free(prefs.gui_webbrowser);
prefs.gui_webbrowser = g_strdup(gtk_entry_get_text(
GTK_ENTRY(OBJECT_GET_DATA(w, GUI_WEBBROWSER_KEY))));
}
+ if (prefs.gui_window_title != NULL)
+ g_free(prefs.gui_window_title);
+ prefs.gui_window_title = g_strdup(gtk_entry_get_text(
+ GTK_ENTRY(OBJECT_GET_DATA(w, GUI_WINDOW_TITLE_KEY))));
/*
* XXX - we need to have a way to fetch the preferences into
@@ -631,3 +642,4 @@
}
return;
}
+
Index: gtk/capture_dlg.c
===================================================================
--- gtk/capture_dlg.c (revision 12628)
+++ gtk/capture_dlg.c (working copy)
@@ -527,6 +527,7 @@
GtkWidget *buffer_size_lb, *buffer_size_sb;
#endif
guint32 value;
+ gchar *cap_title;
if (cap_open_w != NULL) {
/* There's already a "Capture Options" dialog box; reactivate it. */
@@ -566,8 +567,12 @@
g_free(cant_get_if_list_errstr);
}
- cap_open_w = dlg_window_new("Ethereal: Capture Options");
+ /* use user-defined title if preference is set */
+ cap_title = create_user_window_title("Ethereal: Capture Options");
+ cap_open_w = dlg_window_new(cap_title);
+ g_free(cap_title);
+
tooltips = gtk_tooltips_new();
#if GTK_MAJOR_VERSION < 2
Index: gtk/main.c
===================================================================
--- gtk/main.c (revision 12628)
+++ gtk/main.c (working copy)
@@ -2943,6 +2943,7 @@
GList *filter_list = NULL;
GtkTooltips *tooltips;
GtkAccelGroup *accel;
+ gchar *title;
/* Display filter construct dialog has an Apply button, and "OK" not
only sets our text widget, it activates it (i.e., it causes us to
filter the capture). */
@@ -2952,8 +2953,12 @@
TRUE
};
+ /* use user-defined title if preference is set */
+ title = create_user_window_title("The Ethereal Network Analyzer");
+
/* Main window */
- top_level = window_new(GTK_WINDOW_TOPLEVEL, "The Ethereal Network Analyzer");
+ top_level = window_new(GTK_WINDOW_TOPLEVEL, title);
+ g_free(title);
tooltips = gtk_tooltips_new();
@@ -3151,3 +3156,4 @@
status_pane = gtk_hpaned_new();
gtk_widget_show(status_pane);
}
+
Index: gtk/ui_util.c
===================================================================
--- gtk/ui_util.c (revision 12628)
+++ gtk/ui_util.c (working copy)
@@ -570,8 +570,13 @@
void
set_main_window_name(gchar *window_name)
{
- gtk_window_set_title(GTK_WINDOW(top_level), window_name);
- gdk_window_set_icon_name(top_level->window, window_name);
+ gchar *title;
+
+ /* use user-defined window title if preference is set */
+ title = create_user_window_title(window_name);
+ gtk_window_set_title(GTK_WINDOW(top_level), title);
+ gdk_window_set_icon_name(top_level->window, title);
+ g_free(title);
}
@@ -1013,3 +1018,21 @@
gtk_editable_copy_clipboard((GtkEditable *)text); /* Copy the byte data into the clipboard */
#endif
}
+
+/*
+ * Create a new window title string with user-defined title preference.
+ * (Or ignore it if unspecified).
+ */
+gchar *
+create_user_window_title(gchar *caption)
+{
+ /* fail-safe */
+ if (caption == NULL)
+ return g_strdup("");
+
+ /* no user-defined title specified */
+ if ((prefs.gui_window_title == NULL) || (*prefs.gui_window_title == '\0'))
+ return g_strdup(caption);
+
+ return g_strdup_printf("%s %s", prefs.gui_window_title, caption);
+}
Index: gtk/ui_util.h
===================================================================
--- gtk/ui_util.h (revision 12628)
+++ gtk/ui_util.h (working copy)
@@ -297,4 +297,12 @@
*/
extern void copy_to_clipboard(GString *str);
+/** Create a new window title that includes user-defined preference string.
+ *
+ * @param caption string you want included in title (appended to user-defined string)
+ * @return a newly created title string including user-defined preference (if specified)
+ */
+extern gchar *create_user_window_title(gchar *caption);
+
+
#endif /* __GTKGUIUI_UTIL_H__ */
Index: epan/prefs.c
===================================================================
--- epan/prefs.c (revision 12628)
+++ epan/prefs.c (working copy)
@@ -1046,6 +1046,7 @@
prefs.gui_ask_unsaved = TRUE;
prefs.gui_find_wrap = TRUE;
prefs.gui_webbrowser = g_strdup("mozilla %s");
+ prefs.gui_window_title = g_strdup("");
prefs.gui_layout_type = layout_type_5;
prefs.gui_layout_content_1 = layout_pane_content_plist;
prefs.gui_layout_content_2 = layout_pane_content_pdetails;
@@ -1360,6 +1361,7 @@
#define PRS_GUI_TOOLBAR_MAIN_SHOW "gui.toolbar_main_show"
#define PRS_GUI_TOOLBAR_MAIN_STYLE "gui.toolbar_main_style"
#define PRS_GUI_WEBBROWSER "gui.webbrowser"
+#define PRS_GUI_WINDOW_TITLE "gui.window_title"
#define PRS_GUI_LAYOUT_TYPE "gui.layout_type"
#define PRS_GUI_LAYOUT_CONTENT_1 "gui.layout_content_1"
#define PRS_GUI_LAYOUT_CONTENT_2 "gui.layout_content_2"
@@ -1695,6 +1697,10 @@
} else if (strcmp(pref_name, PRS_GUI_WEBBROWSER) == 0) {
g_free(prefs.gui_webbrowser);
prefs.gui_webbrowser = g_strdup(value);
+ } else if (strcmp(pref_name, PRS_GUI_WINDOW_TITLE) == 0) {
+ if (prefs.gui_window_title != NULL)
+ g_free(prefs.gui_window_title);
+ prefs.gui_window_title = g_strdup(value);
} else if (strcmp(pref_name, PRS_GUI_LAYOUT_TYPE) == 0) {
prefs.gui_layout_type = strtoul(value, NULL, 10);
if (prefs.gui_layout_type == layout_unused ||
@@ -2306,6 +2312,10 @@
fprintf(pf, "# Ex: mozilla %%s\n");
fprintf(pf, PRS_GUI_WEBBROWSER ": %s\n", prefs.gui_webbrowser);
+ fprintf(pf, "\n# Custom window title. (Prepended to existing titles.)\n");
+ fprintf(pf, PRS_GUI_WINDOW_TITLE ": %s\n",
+ prefs.gui_window_title);
+
fprintf (pf, "\n######## User Interface: Layout ########\n");
fprintf(pf, "\n# Layout type (1-6).\n");
@@ -2510,6 +2520,7 @@
dest->gui_geometry_save_size = src->gui_geometry_save_size;
dest->gui_geometry_save_maximized = src->gui_geometry_save_maximized;
dest->gui_webbrowser = g_strdup(src->gui_webbrowser);
+ dest->gui_window_title = g_strdup(src->gui_window_title);
/* values for the capture dialog box */
dest->capture_device = g_strdup(src->capture_device);
dest->capture_devices_descr = g_strdup(src->capture_devices_descr);
@@ -2550,6 +2561,10 @@
}
g_free(pr->gui_webbrowser);
pr->gui_webbrowser = NULL;
+ if (pr->gui_window_title != NULL) {
+ g_free(pr->gui_window_title);
+ pr->gui_window_title = NULL;
+ }
if (pr->capture_device != NULL) {
g_free(pr->capture_device);
pr->capture_device = NULL;
@@ -2579,3 +2594,4 @@
g_list_free(pr->col_list);
pr->col_list = NULL;
}
+
Index: epan/prefs.h
===================================================================
--- epan/prefs.h (revision 12628)
+++ epan/prefs.h (working copy)
@@ -134,6 +134,7 @@
gboolean gui_ask_unsaved;
gboolean gui_find_wrap;
gchar *gui_webbrowser;
+ gchar *gui_window_title;
layout_type_e gui_layout_type;
layout_pane_content_e gui_layout_content_1;
layout_pane_content_e gui_layout_content_2;
@@ -350,3 +351,4 @@
extern int prefs_set_pref(char *prefarg);
#endif /* prefs.h */
+
- Follow-Ups:
- Prev by Date: [Ethereal-dev] False [TCP Dup ACK] indicators
- Next by Date: [Ethereal-dev] Gbps ethereal functionality check
- Previous by thread: Re: [Ethereal-dev] False [TCP Dup ACK] indicators
- Next by thread: Re: [Ethereal-dev] [Patch] show user-defined string in window titles - feature/patch submission
- Index(es):





