2 * Routines for the file set dialog
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.
40 #include "compat_macros.h"
41 #include "simple_dialog.h"
43 #include "gui_utils.h"
44 #include "dlg_utils.h"
50 #include <epan/filesystem.h>
53 #include "fileset_dlg.h"
58 * Keep a static pointer to the current "File Set" window, if
59 * any, so that if somebody tries to do "File Set" while there's
60 * already a "File Set" window up, we just pop up the existing
61 * one, rather than creating a new one.
63 static GtkWidget *fs_w;
67 /* various widget related global data */
70 GtkTooltips *tooltips;
72 GtkWidget *fs_first_rb;
77 /* open the file corresponding to the given fileset entry */
79 fs_open_entry(fileset_entry *entry)
85 /* make a copy of the filename (cf_close will indirectly destroy it right now) */
86 fname = g_strdup(entry->fullname);
88 /* close the old and open the new file */
90 if (cf_open(&cfile, fname, FALSE, &err) == CF_OK) {
98 /* radio button was pressed/released */
100 fs_rb_cb(GtkWidget *open_bt, gpointer fs_data)
102 fileset_entry *entry = fs_data;
104 /* button release should have no effect */
105 if(!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(open_bt) )) {
109 fs_open_entry(entry);
113 /* the window was closed, cleanup things */
115 fs_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
117 /* Note that we no longer have a "File Set" dialog box. */
122 /* get creation date (converted from filename) */
125 fileset_dlg_name2date_dup(const char * name) {
131 /* just to be sure ... */
132 if(!fileset_filename_match_pattern(name)) {
136 /* find char position behind the last underscore */
137 pfx = strrchr(name, '_');
141 /* start conversion behind that underscore */
142 filename = g_strdup_printf("%c%c%c%c.%c%c.%c%c %c%c:%c%c:%c%c",
143 /* year */ name[pos] , name[pos+1], name[pos+2], name[pos+3],
144 /* month */ name[pos+4], name[pos+5],
145 /* day */ name[pos+6], name[pos+7],
146 /* hour */ name[pos+8], name[pos+9],
147 /* min */ name[pos+10], name[pos+11],
148 /* second */ name[pos+12], name[pos+13]);
154 /* this file is a part of the current file set, add it to the dialog */
156 fileset_dlg_add_file(fileset_entry *entry) {
170 created = fileset_dlg_name2date_dup(entry->name);
172 /* if this file doesn't follow the fiel set pattern, */
173 /* use the creation time of that file */
174 local = localtime(&entry->ctime);
175 created = g_strdup_printf("%04u.%02u.%02u %02u:%02u:%02u",
176 local->tm_year+1900, local->tm_mon+1, local->tm_mday,
177 local->tm_hour, local->tm_min, local->tm_sec);
180 local = localtime(&entry->mtime);
181 modified = g_strdup_printf("%04u.%02u.%02u %02u:%02u:%02u",
182 local->tm_year+1900, local->tm_mon+1, local->tm_mday,
183 local->tm_hour, local->tm_min, local->tm_sec);
184 size = g_strdup_printf("%ld Bytes", entry->size);
186 fs_rb = RADIO_BUTTON_NEW_WITH_LABEL(fs_first_rb, entry->name);
191 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (fs_rb), entry->current);
193 gtk_tooltips_set_tip(tooltips, fs_rb, "Open this capture file", NULL);
194 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_rb, 0, 1, row, row+1);
195 SIGNAL_CONNECT(fs_rb, "toggled", fs_rb_cb, entry);
196 gtk_widget_show(fs_rb);
198 fs_lb = gtk_label_new(created);
199 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 1, 2, row, row+1);
200 gtk_widget_set_sensitive(fs_lb, entry->current);
201 gtk_widget_show(fs_lb);
203 fs_lb = gtk_label_new(modified);
204 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 2, 3, row, row+1);
205 gtk_widget_set_sensitive(fs_lb, entry->current);
206 gtk_widget_show(fs_lb);
208 fs_lb = gtk_label_new(size);
209 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 3, 4, row, row+1);
210 gtk_widget_set_sensitive(fs_lb, entry->current);
211 gtk_widget_show(fs_lb);
213 title = g_strdup_printf("Wireshark: %u File%s in Set", row, plurality(row, "", "s"));
214 gtk_window_set_title(GTK_WINDOW(fs_w), title);
217 title = g_strdup_printf("... in directory: %s", fileset_get_dirname());
218 gtk_label_set(GTK_LABEL(fs_dir_lb), title);
223 gtk_widget_show_all(fs_tb);
231 /* init the fileset table */
233 fileset_init_table(GtkWidget *parent)
238 fs_tb = gtk_table_new(6,1, FALSE);
239 gtk_table_set_row_spacings(GTK_TABLE(fs_tb), 1);
240 gtk_table_set_col_spacings(GTK_TABLE(fs_tb), 12);
241 gtk_container_add(GTK_CONTAINER(parent), fs_tb);
246 fs_lb = gtk_label_new("Filename");
247 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 0, 1, row, row+1);
249 fs_lb = gtk_label_new("Created");
250 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 1, 2, row, row+1);
252 fs_lb = gtk_label_new("Last Modified");
253 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 2, 3, row, row+1);
255 fs_lb = gtk_label_new("Size");
256 gtk_table_attach_defaults(GTK_TABLE(fs_tb), fs_lb, 3, 4, row, row+1);
258 gtk_widget_hide(fs_tb);
260 gtk_window_set_title(GTK_WINDOW(fs_w), "Wireshark: 0 Files in Set");
262 gtk_label_set(GTK_LABEL(fs_dir_lb), "No capture file loaded!");
268 /* open the fileset dialog */
270 fileset_cb(GtkWidget *w _U_, gpointer d _U_)
272 GtkWidget *main_vb, *bbox, *close_bt, *help_bt;
273 #if GTK_MAJOR_VERSION < 2
274 GtkAccelGroup *accel_group;
279 /* There's already a "File Set" dialog box; reactivate it. */
280 reactivate_window(fs_w);
284 fs_w = window_new(GTK_WINDOW_TOPLEVEL, "");
286 tooltips = gtk_tooltips_new();
288 #if GTK_MAJOR_VERSION < 2
289 /* Accelerator group for the accelerators (or, as they're called in
290 Windows and, I think, in Motif, "mnemonics"; Alt+<key> is a mnemonic,
291 Ctrl+<key> is an accelerator). */
292 accel_group = gtk_accel_group_new();
293 gtk_window_add_accel_group(GTK_WINDOW(fs_w), accel_group);
296 main_vb = gtk_vbox_new(FALSE, 5);
297 gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
298 gtk_container_add(GTK_CONTAINER(fs_w), main_vb);
300 /* add a dummy container, so we can replace the table later */
301 fs_tb_vb = gtk_vbox_new(FALSE, 0);
302 gtk_container_add(GTK_CONTAINER(main_vb), fs_tb_vb);
304 fs_dir_lb = gtk_label_new("");
305 gtk_container_add(GTK_CONTAINER(main_vb), fs_dir_lb);
307 fileset_init_table(fs_tb_vb);
309 /* Button row: close button */
310 if(topic_available(HELP_FILESET_DIALOG)) {
311 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_HELP, NULL);
313 bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
315 gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 5);
317 close_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
318 window_set_cancel_button(fs_w, close_bt, window_cancel_button_cb);
319 gtk_tooltips_set_tip(tooltips, close_bt, "Close this window.", NULL);
321 if(topic_available(HELP_FILESET_DIALOG)) {
322 help_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_HELP);
323 SIGNAL_CONNECT(help_bt, "clicked", topic_cb, HELP_FILESET_DIALOG);
326 gtk_widget_grab_default(close_bt);
328 SIGNAL_CONNECT(fs_w, "delete_event", window_delete_event_cb, NULL);
329 SIGNAL_CONNECT(fs_w, "destroy", fs_destroy_cb, NULL);
331 /* init the dialog content */
332 fileset_update_dlg();
334 gtk_widget_show_all(fs_w);
335 window_present(fs_w);
339 /* open the next file in the file set, or do nothing if already the last file */
341 fileset_next_cb(GtkWidget *w _U_, gpointer d _U_)
343 fileset_entry *entry;
345 entry = fileset_get_next();
348 fs_open_entry(entry);
353 /* open the previous file in the file set, or do nothing if already the first file */
355 fileset_previous_cb(GtkWidget *w _U_, gpointer d _U_)
357 fileset_entry *entry;
359 entry = fileset_get_previous();
362 fs_open_entry(entry);
367 /* a new capture file was opened, browse the dir and look for files matching the given file set */
369 fileset_file_opened(const char *fname) {
370 fileset_add_dir(fname);
372 window_present(fs_w);
375 /* update the menu */
376 set_menus_for_file_set(TRUE /* file_set */,
377 fileset_get_previous() != NULL, fileset_get_next() != NULL );
381 /* the capture file was closed */
383 fileset_file_closed(void)
386 /* reinit the table, title and alike */
387 gtk_widget_ref(fs_tb_vb);
388 gtk_widget_destroy(fs_tb);
390 fileset_init_table(fs_tb_vb);
391 window_present(fs_w);
396 /* update the menu */
397 set_menus_for_file_set(FALSE /* file_set */,
398 fileset_get_previous() != NULL, fileset_get_next() != NULL );