2 * Dialog boxes for preferences for the stream window
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/prefs.h>
34 #include "../globals.h"
37 #include "gtk/color_utils.h"
38 #include "gtk/prefs_stream.h"
40 #include "gtk/follow_tcp.h"
41 #include "gtk/main_packet_list.h"
44 #define SAMPLE_MARKED_TEXT "Sample marked packet text\n"
45 #define SAMPLE_IGNORED_TEXT "Sample ignored packet text\n"
46 #define SAMPLE_CLIENT_TEXT "Sample TCP stream client text\n"
47 #define SAMPLE_SERVER_TEXT "Sample TCP stream server text\n"
56 #define MAX_IDX 8 /* set this to the number of IDX values */
57 #define STREAM_SAMPLE_KEY "stream_entry"
58 #define STREAM_CS_KEY "stream_colorselection"
64 static void update_text_color(GtkWidget *, gpointer);
65 static void update_current_color(GtkWidget *, gpointer);
67 static GdkColor tcolors[MAX_IDX], *curcolor = NULL;
72 GtkWidget *main_vb, *main_tb, *label, *combo_box;
73 GtkWidget *sample, *colorsel;
76 "Marked packet foreground", /* MFG_IDX 0*/
77 "Marked packet background", /* MBG_IDX 1*/
78 "Ignored packet foreground", /* IFG_IDX 2*/
79 "Ignored packet background", /* IBG_IDX 3*/
80 "TCP stream client foreground", /* CFG_IDX 4*/
81 "TCP stream client background", /* CBG_IDX 5*/
82 "TCP stream server foreground", /* SFG_IDX 6*/
83 "TCP stream server background" /* SBG_IDX 7*/
85 int mcount = sizeof(mt) / sizeof (gchar *);
90 color_t_to_gdkcolor(&tcolors[MFG_IDX], &prefs.gui_marked_fg);
91 color_t_to_gdkcolor(&tcolors[MBG_IDX], &prefs.gui_marked_bg);
92 color_t_to_gdkcolor(&tcolors[IFG_IDX], &prefs.gui_ignored_fg);
93 color_t_to_gdkcolor(&tcolors[IBG_IDX], &prefs.gui_ignored_bg);
94 color_t_to_gdkcolor(&tcolors[CFG_IDX], &prefs.st_client_fg);
95 color_t_to_gdkcolor(&tcolors[CBG_IDX], &prefs.st_client_bg);
96 color_t_to_gdkcolor(&tcolors[SFG_IDX], &prefs.st_server_fg);
97 color_t_to_gdkcolor(&tcolors[SBG_IDX], &prefs.st_server_bg);
99 curcolor = &tcolors[CFG_IDX];
101 /* Enclosing containers for each row of widgets */
102 main_vb = gtk_vbox_new(FALSE, 5);
103 gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
105 main_tb = gtk_table_new(3, 3, FALSE);
106 gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
107 gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
108 gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
109 gtk_widget_show(main_tb);
111 label = gtk_label_new("Set:");
112 gtk_misc_set_alignment(GTK_MISC(label), 1.0f, 0.5f);
113 gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, 0, 1);
114 gtk_widget_show(label);
116 /* We have to create this now, and configure it below. */
117 colorsel = gtk_color_selection_new();
119 combo_box = gtk_combo_box_new_text ();
120 for (i = 0; i < mcount; i++){
121 gtk_combo_box_append_text (GTK_COMBO_BOX (combo_box), mt[i]);
123 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), CFG_IDX);
124 g_signal_connect(combo_box, "changed", G_CALLBACK(update_current_color), colorsel);
125 gtk_table_attach(GTK_TABLE(main_tb), combo_box, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
127 gtk_widget_show(combo_box);
129 sample = gtk_text_view_new();
130 layout = gtk_widget_create_pango_layout(sample, SAMPLE_SERVER_TEXT);
131 pango_layout_get_pixel_size(layout, &width, &height);
132 g_object_unref(G_OBJECT(layout));
133 gtk_widget_set_size_request(sample, width, height * 2);
134 gtk_text_view_set_editable(GTK_TEXT_VIEW(sample), FALSE);
135 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(sample));
136 gtk_text_buffer_get_start_iter(buf, &iter);
137 gtk_text_buffer_create_tag(buf, "marked",
138 "foreground-gdk", &tcolors[MFG_IDX],
139 "background-gdk", &tcolors[MBG_IDX], NULL);
140 gtk_text_buffer_create_tag(buf, "ignored",
141 "foreground-gdk", &tcolors[IFG_IDX],
142 "background-gdk", &tcolors[IBG_IDX], NULL);
143 gtk_text_buffer_create_tag(buf, "client",
144 "foreground-gdk", &tcolors[CFG_IDX],
145 "background-gdk", &tcolors[CBG_IDX], NULL);
146 gtk_text_buffer_create_tag(buf, "server",
147 "foreground-gdk", &tcolors[SFG_IDX],
148 "background-gdk", &tcolors[SBG_IDX], NULL);
149 gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_MARKED_TEXT, -1,
151 gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_IGNORED_TEXT, -1,
153 gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_CLIENT_TEXT, -1,
155 gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_SERVER_TEXT, -1,
157 gtk_table_attach_defaults(GTK_TABLE(main_tb), sample, 2, 3, 0, 2);
158 gtk_widget_show(sample);
160 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel),
162 gtk_table_attach(GTK_TABLE(main_tb), colorsel, 0, 3, 2, 3,
163 GTK_SHRINK, GTK_SHRINK, 0, 0);
165 g_object_set_data(G_OBJECT(colorsel), STREAM_SAMPLE_KEY, sample);
166 g_signal_connect(colorsel, "color-changed", G_CALLBACK(update_text_color), NULL);
167 gtk_widget_show(colorsel);
169 gtk_widget_show(main_vb);
174 update_text_color(GtkWidget *w, gpointer data _U_) {
175 GtkTextView *sample = g_object_get_data(G_OBJECT(w), STREAM_SAMPLE_KEY);
179 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(w), curcolor);
181 buf = gtk_text_view_get_buffer(sample);
182 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buf), "marked");
183 g_object_set(tag, "foreground-gdk", &tcolors[MFG_IDX], "background-gdk",
184 &tcolors[MBG_IDX], NULL);
185 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buf), "ignored");
186 g_object_set(tag, "foreground-gdk", &tcolors[IFG_IDX], "background-gdk",
187 &tcolors[IBG_IDX], NULL);
188 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buf), "client");
189 g_object_set(tag, "foreground-gdk", &tcolors[CFG_IDX], "background-gdk",
190 &tcolors[CBG_IDX], NULL);
191 tag = gtk_text_tag_table_lookup(gtk_text_buffer_get_tag_table(buf), "server");
192 g_object_set(tag, "foreground-gdk", &tcolors[SFG_IDX], "background-gdk",
193 &tcolors[SBG_IDX], NULL);
197 update_current_color(GtkWidget *combo_box, gpointer data)
199 GtkColorSelection *colorsel = data;
202 i = gtk_combo_box_get_active (GTK_COMBO_BOX(combo_box));
203 curcolor = &tcolors[i];
205 gtk_color_selection_set_current_color(colorsel, curcolor);
209 stream_prefs_fetch(GtkWidget *w _U_)
211 gdkcolor_to_color_t(&prefs.gui_marked_fg, &tcolors[MFG_IDX]);
212 gdkcolor_to_color_t(&prefs.gui_marked_bg, &tcolors[MBG_IDX]);
213 gdkcolor_to_color_t(&prefs.gui_ignored_fg, &tcolors[IFG_IDX]);
214 gdkcolor_to_color_t(&prefs.gui_ignored_bg, &tcolors[IBG_IDX]);
215 gdkcolor_to_color_t(&prefs.st_client_fg, &tcolors[CFG_IDX]);
216 gdkcolor_to_color_t(&prefs.st_client_bg, &tcolors[CBG_IDX]);
217 gdkcolor_to_color_t(&prefs.st_server_fg, &tcolors[SFG_IDX]);
218 gdkcolor_to_color_t(&prefs.st_server_bg, &tcolors[SBG_IDX]);
222 stream_prefs_apply(GtkWidget *w _U_)
224 follow_tcp_redraw_all();
226 #ifndef NEW_PACKET_LIST
227 packet_list_update_marked_frames();
228 packet_list_update_ignored_frames();
233 stream_prefs_destroy(GtkWidget *w _U_)