示例#1
0
GtkWidget *
statusbar_new(void)
{
    GtkWidget *status_hbox;

    /* Status hbox */
    status_hbox = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1, FALSE);
    gtk_container_set_border_width(GTK_CONTAINER(status_hbox), 0);

    /* info (main) statusbar */
    info_bar_new();

    /* packets statusbar */
    packets_bar_new();

    /* profile statusbar */
    profile_bar_new();

    /* expert info indicator */
    status_expert_new();

    /* Capture comments indicator */
    status_capture_comment_new();

    /* Pane for the statusbar */
    status_pane_left = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
    gtk_widget_show(status_pane_left);
    status_pane_right = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
    gtk_widget_show(status_pane_right);

    return status_hbox;
}
示例#2
0
GtkWidget*
protocols_prefs_show(void)
{
        GtkWidget   *main_tb, *main_vb;
        GtkWidget   *display_hidden_cb;
        int pos = 0;

        /* Main vertical box */
        main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 7, FALSE);
        gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);

        /* Main table */
        main_tb = gtk_table_new(PROTOCOLS_TABLE_ROWS, 1, FALSE);
        gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
        gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
        gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
        gtk_widget_show(main_tb);

        /* Show hidden protocol items in packet list */
        display_hidden_cb = create_preference_check_button(main_tb, pos++,
            "Display hidden protocol items:", 
            "Display all hidden protocol items in the packet list.",
            prefs.display_hidden_proto_items);
        g_object_set_data(G_OBJECT(main_vb), PROTOCOLS_SHOW_HIDDEN_KEY, display_hidden_cb);

        /* Show 'em what we got */
        gtk_widget_show_all(main_vb);

        return main_vb;
}
示例#3
0
/*
 * Construct a simple text page widget from a file.
 */
GtkWidget * text_page_new(const char *absolute_path)
{
    GtkWidget *page_vb, *txt_scrollw, *txt;

    page_vb =ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
    gtk_container_set_border_width(GTK_CONTAINER(page_vb), 1);
    txt_scrollw = scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scrollw),
                                   GTK_SHADOW_IN);
    gtk_box_pack_start(GTK_BOX(page_vb), txt_scrollw, TRUE, TRUE, 0);

    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scrollw),
                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    txt = gtk_text_view_new();
    gtk_text_view_set_editable(GTK_TEXT_VIEW(txt), FALSE);
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt), GTK_WRAP_WORD);
    gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(txt), FALSE);
    /* XXX: there seems to be no way to add a small border *around* the whole text,
     * so the text will be "bump" against the edges.
     * the following is only working for left and right edges,
     * there is no such thing for top and bottom :-( */
    /* gtk_text_view_set_left_margin(GTK_TEXT_VIEW(txt), 3); */
    /* gtk_text_view_set_right_margin(GTK_TEXT_VIEW(txt), 3); */

    g_object_set_data(G_OBJECT(page_vb), TEXT_KEY, txt);

    text_page_set_text(page_vb, absolute_path);
    gtk_container_add(GTK_CONTAINER(txt_scrollw), txt);
    gtk_widget_show(txt_scrollw);
    gtk_widget_show(txt);

    return page_vb;
}
示例#4
0
static GtkWidget *
scroll_box_dynamic_new(GtkWidget *child_box, guint max_childs, guint scrollw_y_size) {
    GtkWidget * parent_box;


    parent_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
    gtk_box_pack_start(GTK_BOX(parent_box), GTK_WIDGET(child_box), TRUE, TRUE, 0);
    g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_CHILD_BOX, child_box);
    g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_MAX_CHILDS, GINT_TO_POINTER(max_childs));
    g_object_set_data(G_OBJECT(parent_box), SCROLL_BOX_SCROLLW_Y_SIZE, GINT_TO_POINTER(scrollw_y_size));
    gtk_widget_show_all(parent_box);

    return parent_box;
}
示例#5
0
void
pixmap_save_cb(GtkWidget *w, gpointer pixmap_ptr _U_)
{
	GtkWidget *save_as_w;
#if GTK_CHECK_VERSION(2,22,0)
	surface_info_t *surface_info = g_object_get_data(G_OBJECT(w), "surface-info");
#else
	GdkPixmap *pixmap = g_object_get_data(G_OBJECT(w), "pixmap");
#endif
	GdkPixbuf *pixbuf;
	GdkPixbufFormat *pixbuf_format;
	GtkWidget *main_vb, *save_as_type_hb, *type_lb, *type_cm;
	GSList *file_formats,*ffp;
	GdkWindow *parent;

	gchar *format_name;
	guint format_index = 0;
	guint default_index = 0;

	gchar *filename, *file_type;
	GError *error = NULL;
	gboolean ret;
	GtkWidget *msg_dialog;

#if GTK_CHECK_VERSION(2,22,0)
	pixbuf = gdk_pixbuf_get_from_surface (surface_info->surface,
		0, 0, surface_info->width, surface_info->height);
#else
	pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, NULL,
					      0, 0, 0, 0, -1, -1);
#endif
	if(!pixbuf) {
		simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
			      "%sCould not get image from graph%s",
			      simple_dialog_primary_start(),
			      simple_dialog_primary_end());
		return;
	}

	save_as_w = file_selection_new("Wireshark: Save Graph As ...",
				       FILE_SELECTION_SAVE);
	gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(save_as_w), TRUE);

	/* Container for each row of widgets */
	main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
	file_selection_set_extra_widget(save_as_w, main_vb);
	gtk_widget_show(main_vb);

	save_as_type_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE);
	gtk_box_pack_start(GTK_BOX(main_vb), save_as_type_hb, FALSE, FALSE, 0);
	gtk_widget_show(save_as_type_hb);

	type_lb = gtk_label_new("File type: ");
	gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_lb, FALSE, FALSE, 0);
	gtk_widget_show(type_lb);

	type_cm = gtk_combo_box_text_new();
	gtk_box_pack_start(GTK_BOX(save_as_type_hb), type_cm, FALSE, FALSE, 0);

	/* List all of the file formats the gdk-pixbuf library supports */
	file_formats = gdk_pixbuf_get_formats();
	ffp = file_formats;
	while(ffp) {
		pixbuf_format = ffp->data;
		if (gdk_pixbuf_format_is_writable(pixbuf_format)) {
			format_name = gdk_pixbuf_format_get_name(pixbuf_format);
			 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(type_cm),
						  format_name);
			if (!(g_ascii_strcasecmp(format_name, "png")))
				default_index = format_index;
			format_index++;
		}
		ffp = g_slist_next(ffp);
	}
	g_slist_free(file_formats);

	gtk_combo_box_set_active(GTK_COMBO_BOX(type_cm), default_index);
	gtk_widget_show(type_cm);

	gtk_widget_show(save_as_w);
	window_present(save_as_w);
	parent = gtk_widget_get_parent_window(w);
	gdk_window_set_transient_for(gtk_widget_get_window(save_as_w), parent);

	/*
	 * Loop until the user either selects a file or gives up.
	 */
	for (;;) {
		if (gtk_dialog_run(GTK_DIALOG(save_as_w)) != GTK_RESPONSE_ACCEPT) {
			/* They clicked "Cancel" or closed the dialog or.... */
			window_destroy(save_as_w);
			return;
		}

		filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(save_as_w));

		/* Perhaps the user specified a directory instead of a file.
		   Check whether they did. */
		if (test_for_directory(filename) == EISDIR) {
			/* It's a directory - set the file selection box to display that
			   directory, and leave the selection box displayed. */
			set_last_open_dir(filename);
			g_free(filename);
			file_selection_set_current_folder(save_as_w,
							  get_last_open_dir());
			gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(save_as_w), "");
			continue;
		}

		file_type = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(type_cm));
		ret = gdk_pixbuf_save(pixbuf, filename, file_type, &error, NULL);
		g_free(filename);
		g_free(file_type);

		if (!ret) {
			msg_dialog = gtk_message_dialog_new(GTK_WINDOW(save_as_w),
                                          GTK_DIALOG_DESTROY_WITH_PARENT,
                                          GTK_MESSAGE_ERROR,
                                          GTK_BUTTONS_OK,
                                          "%s", error->message);
			gtk_dialog_run(GTK_DIALOG(msg_dialog));
			gtk_widget_destroy(msg_dialog);
			continue;
		}

		window_destroy(save_as_w);
		return;
	}
}
示例#6
0
GtkWidget*
gui_prefs_show(void)
{
	GtkWidget *main_grid, *main_vb;
#ifdef _WIN32
	GtkWidget *console_open_om, *enable_update_cb;
#endif
	GtkWidget *fileopen_rb, *fileopen_dir_te, *fileopen_preview_te;
	GtkWidget *recent_files_count_max_te, *recent_df_entries_max_te, *ask_unsaved_cb, *find_wrap_cb;
	GtkWidget *use_pref_save_cb;
	GtkWidget *show_version_om;
	GtkWidget *auto_scroll_cb, *scroll_percent_te;
	GtkWidget *webbrowser_te;
	GtkWidget *save_position_cb, *save_size_cb, *save_maximized_cb;
#if defined(HAVE_IGE_MAC_INTEGRATION) || defined(HAVE_GTKOSXAPPLICATION)
	GtkWidget *macosx_style_cb;
#endif
	GtkWidget *expert_info_eyecandy_cb;

	int        pos = 0;
	char       current_val_str[128];

	/* The columns haven't been changed yet */
	cfile.columns_changed = FALSE;

	/* Main vertical box */
	main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 7, FALSE);
	gtk_container_set_border_width( GTK_CONTAINER(main_vb), 5 );

	/* Main grid */
	main_grid = ws_gtk_grid_new();
	gtk_box_pack_start(GTK_BOX(main_vb), main_grid, FALSE, FALSE, 0);
#if GTK_CHECK_VERSION(3,0,0)
        gtk_widget_set_vexpand(GTK_WIDGET(main_grid), FALSE); /* Ignore VEXPAND requests from children */
#endif
	ws_gtk_grid_set_row_spacing(GTK_GRID(main_grid), 10);
	ws_gtk_grid_set_column_spacing(GTK_GRID(main_grid), 15);

	/* Geometry prefs */
	save_position_cb = create_preference_check_button(main_grid, pos++,
	    "Save window position:",
	    "Save the position of the main window.",
	    prefs.gui_geometry_save_position);
	g_object_set_data(G_OBJECT(main_vb), GEOMETRY_POSITION_KEY, save_position_cb);

	save_size_cb = create_preference_check_button(main_grid, pos++,
	    "Save window size:",
	    "Save the size of the main window.",
	    prefs.gui_geometry_save_size);
	g_object_set_data(G_OBJECT(main_vb), GEOMETRY_SIZE_KEY, save_size_cb);

	save_maximized_cb = create_preference_check_button(main_grid, pos++,
	    "Save maximized state:",
	    "Save the maximized state of the main window.",
	    prefs.gui_geometry_save_maximized);
	g_object_set_data(G_OBJECT(main_vb), GEOMETRY_MAXIMIZED_KEY, save_maximized_cb);

#ifdef _WIN32
	enable_update_cb = create_preference_check_button(main_grid, pos++,
	    "Check for updates:",
	    "Periodically check for new versions of Wireshark.",
	    prefs.gui_update_enabled);
	g_object_set_data(G_OBJECT(main_vb), ENABLE_UPDATE_KEY, enable_update_cb);
#endif

#if defined(HAVE_IGE_MAC_INTEGRATION) || defined(HAVE_GTKOSXAPPLICATION)
	macosx_style_cb = create_preference_check_button(main_grid, pos++,
	    "Mac OS X style",
	    "Create a Mac OS X look and feel. Checking this box will move the "
	    "menu bar to the top of the screen instead of the top of the Wireshark window. "
	    "Requires a restart of Wireshark to take effect.",
	    prefs.gui_macosx_style);
	g_object_set_data(G_OBJECT(main_vb), MACOSX_STYLE_KEY, macosx_style_cb);
#endif

#ifdef _WIN32
	/* How the console window should be opened */
	console_open_om = create_preference_option_menu(main_grid, pos++,
	    "Open a console window",
	    "Whether to open a console window "
	    "(Automatic will open a console if messages appear).",
	    gui_console_open_vals, prefs.gui_console_open);
	g_object_set_data(G_OBJECT(main_vb), GUI_CONSOLE_OPEN_KEY, console_open_om);
#endif

	/* Allow user to select where they want the File Open dialog to open to
	 * by default */
	fileopen_rb = create_preference_radio_buttons(main_grid, pos++,
	    "\"File Open\" dialog behavior:",
	    "Which directory the \"File Open\" dialog should start with.",
	    gui_fileopen_vals, prefs.gui_fileopen_style);

	/* Directory to default File Open dialog to */
	fileopen_dir_te = create_preference_entry(main_grid, pos++,
	    "Directory:",
	    "The \"File Open\" dialog defaults always to this directory.",
	    prefs.gui_fileopen_dir);
	g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_KEY, fileopen_rb);
	g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_DIR_KEY, fileopen_dir_te);
	g_signal_connect(fileopen_rb, "clicked", G_CALLBACK(fileopen_selected_cb), main_vb);
	g_signal_connect(fileopen_dir_te, "focus-out-event",
	    G_CALLBACK(fileopen_dir_changed_cb), main_vb);

	/* File Open dialog preview timeout */
	fileopen_preview_te = create_preference_entry(main_grid, pos++,
	    "\"File Open\" preview timeout:",
	    "Reading preview data in the \"File Open\" dialog will be stopped after given seconds.",
	    open_file_preview_str);
	g_snprintf(current_val_str, sizeof(current_val_str), "%d", prefs.gui_fileopen_preview);
	gtk_entry_set_text(GTK_ENTRY(fileopen_preview_te), current_val_str);
	g_object_set_data(G_OBJECT(main_vb), GUI_FILEOPEN_PREVIEW_KEY, fileopen_preview_te);
	g_signal_connect(fileopen_preview_te, "focus_out_event", G_CALLBACK(fileopen_preview_changed_cb), main_vb);

	/* Number of recent entries in the display filter list ... */
	recent_df_entries_max_te = create_preference_entry(main_grid, pos++,
	    "Maximum recent filters:",
	    "Maximum number of recent entries in filter display list.",
	    recent_df_entries_max_str);
	g_snprintf(current_val_str, sizeof(current_val_str), "%d", prefs.gui_recent_df_entries_max);
	gtk_entry_set_text(GTK_ENTRY(recent_df_entries_max_te), current_val_str);
	g_object_set_data(G_OBJECT(main_vb), GUI_RECENT_DF_ENTRIES_KEY, recent_df_entries_max_te);
	g_signal_connect(recent_df_entries_max_te, "focus_out_event", G_CALLBACK(recent_df_entries_changed_cb), main_vb);

	/* Number of entries in the recent_files list ... */
	recent_files_count_max_te = create_preference_entry(main_grid, pos++,
	    "Maximum recent files:",
	    "Maximum number of entries in the \"File/Open Recent\" list.",
	    recent_files_count_max_str);
	g_snprintf(current_val_str, sizeof(current_val_str), "%d", prefs.gui_recent_files_count_max);
	gtk_entry_set_text(GTK_ENTRY(recent_files_count_max_te), current_val_str);
	g_object_set_data(G_OBJECT(main_vb), GUI_RECENT_FILES_COUNT_KEY, recent_files_count_max_te);
	g_signal_connect(recent_files_count_max_te, "focus_out_event", G_CALLBACK(recent_files_count_changed_cb), main_vb);

	fileopen_selected_cb(NULL, main_vb);

	/* ask for unsaved capture files? */
	ask_unsaved_cb = create_preference_check_button(main_grid, pos++,
	    "Confirm unsaved capture files:",
	    "Whether a dialog should pop up in case of an unsaved capture file.",
	    prefs.gui_ask_unsaved);
	g_object_set_data(G_OBJECT(main_vb), GUI_ASK_UNSAVED_KEY, ask_unsaved_cb);

	/* do we want to wrap when searching for data? */
	find_wrap_cb = create_preference_check_button(main_grid, pos++,
	    "Wrap to end/beginning of file during a find:",
	    "Whether a search should wrap in a capture file.",
	    prefs.gui_find_wrap);
	g_object_set_data(G_OBJECT(main_vb), GUI_FIND_WRAP_KEY, find_wrap_cb);

	/* show an explicit Save button for settings dialogs (preferences and alike)? */
	use_pref_save_cb = create_preference_check_button(main_grid, pos++,
	    "Settings dialogs show a save button:",
	    "Whether the various settings dialogs (e.g. Preferences) should "
	    "use an explicit save button - for advanced users.",
	    prefs.gui_use_pref_save);
	g_object_set_data(G_OBJECT(main_vb), GUI_USE_PREF_SAVE_KEY, use_pref_save_cb);

	/* Show version in welcome and/or title screen */
	show_version_om = create_preference_option_menu(main_grid, pos++,
	    "Welcome screen and title bar shows version",
	    "Whether version should be shown in the start page and/or main screen's title bar.",
	    gui_version_placement_vals, prefs.gui_version_placement);
	g_object_set_data(G_OBJECT(main_vb), GUI_SHOW_VERSION_KEY, show_version_om);

	/* Whether to auto scroll when expanding items */
	auto_scroll_cb = create_preference_check_button(main_grid, pos++,
		"Auto scroll on expansion:",
	    "Whether the details view should be automatically scrolled up when expanding an item.",
	    prefs.gui_auto_scroll_on_expand );
	g_object_set_data(G_OBJECT(main_vb), GUI_AUTO_SCROLL_KEY, auto_scroll_cb);

	/* Where to auto scroll to when expanding items */
	scroll_percent_te = create_preference_entry(main_grid, pos++,
		"Auto scroll percentage:",
	    "Where to scroll the expanded item to within the view e.g. 0% = top of view, 50% = center of view.",
	    scroll_percent_preview_str);
	g_snprintf(current_val_str, sizeof(current_val_str), "%d", prefs.gui_auto_scroll_percentage);
	gtk_entry_set_text(GTK_ENTRY(scroll_percent_te), current_val_str);
	g_object_set_data(G_OBJECT(main_vb), GUI_SCROLL_PERCENT_KEY, scroll_percent_te);
	g_signal_connect(scroll_percent_te, "focus_out_event", G_CALLBACK(scroll_percent_changed_cb), main_vb);

	/* Webbrowser */
	if (browser_needs_pref()) {
	    webbrowser_te = create_preference_entry(main_grid, pos++,
						    "Web browser command:",
						    "Command line to desired browser.",
						    prefs.gui_webbrowser);
	    gtk_entry_set_text(GTK_ENTRY(webbrowser_te), prefs.gui_webbrowser);
	    g_object_set_data(G_OBJECT(main_vb), GUI_WEBBROWSER_KEY, webbrowser_te);
	}

	/* Enable Expert Infos Dialog Tab Label "eye-candy" */
	expert_info_eyecandy_cb = create_preference_check_button(main_grid, pos++,
	    "Display icons in the Expert Infos dialog tab labels:",
	    "Whether icon images should be displayed in the Expert Infos dialog tab labels.",
	    prefs.gui_expert_composite_eyecandy );
	g_object_set_data(G_OBJECT(main_vb), GUI_EXPERT_EYECANDY_KEY, expert_info_eyecandy_cb);

	/* Show 'em what we got */
	gtk_widget_show_all(main_vb);

	return(main_vb);
}
示例#7
0
addr_resolution_dlg (GtkAction *action _U_, gpointer data _U_)
{

    GtkWidget *vbox;
    GtkWidget *view;
    GtkWidget *scroll;
    GtkWidget *bbox;
    GtkWidget *ok_bt, *cancel_bt, *help_bt;
    GtkTextBuffer *buffer;

    addr_resolution_dlg_w = dlg_window_new ("Address Resolution");
    gtk_widget_set_size_request (addr_resolution_dlg_w, 750, 350);
    gtk_window_set_resizable (GTK_WINDOW (addr_resolution_dlg_w), TRUE);
    gtk_container_set_border_width (GTK_CONTAINER (addr_resolution_dlg_w), DLG_OUTER_MARGIN);

    vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, DLG_UNRELATED_SPACING, FALSE);
    gtk_container_add (GTK_CONTAINER (addr_resolution_dlg_w), vbox);
    gtk_widget_show (vbox);

    view = gtk_text_view_new ();
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
#if GTK_CHECK_VERSION(3, 0, 0)
    gtk_widget_override_font(view, user_font_get_regular());
#else
    gtk_widget_modify_font(view, user_font_get_regular());
#endif
    gtk_widget_show (view);

    scroll = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
示例#8
0
    COPY_ADDRESS(&(rule_info->net_src), &(pinfo->net_src));
    COPY_ADDRESS(&(rule_info->net_dst), &(pinfo->net_dst));
    rule_info->ptype = pinfo->ptype;
    rule_info->srcport = pinfo->srcport;
    rule_info->destport = pinfo->destport;
    rule_info->inbound = TRUE;
    rule_info->deny = TRUE;
    rule_info->product = 0;

    rule_w = dlg_window_new("Firewall ACL Rules");

    gtk_widget_set_name(rule_w, "Firewall ACL rule window");
    gtk_container_set_border_width(GTK_CONTAINER(rule_w), 6);

    /* setup the container */
    vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 6, FALSE);
    gtk_container_add(GTK_CONTAINER(rule_w), vbox);

    /* rule type selectors hbox */
    hbox = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1, FALSE);
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

    /* product selector */
    label = gtk_label_new("Product");
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);

    product_combo_box = gtk_combo_box_text_new();
    for (i = 0; i < NUM_PRODS; i++) {
        gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(product_combo_box), products[i].name);
    }
    g_object_set_data(G_OBJECT(product_combo_box), WS_RULE_INFO_KEY, rule_info);
示例#9
0
GtkWidget*
capture_prefs_show(void)
{
	GtkWidget	*main_tb, *main_vb;
	GtkWidget	*if_cbxe, *if_lb, *promisc_cb, *pcap_ng_cb, *sync_cb, *auto_scroll_cb, *show_info_cb;
	GtkWidget	*ifopts_lb, *ifopts_bt;
	GList		*if_list, *combo_list;
	int		err;
	int		row = 0;
	const gchar     *tooltips_text;

	/* Main vertical box */
	main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 7, FALSE);
	gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);

	/* Main table */
	main_tb = gtk_table_new(CAPTURE_TABLE_ROWS, 2, FALSE);
	gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
	gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
	gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
	gtk_widget_show(main_tb);

	/* Default device */
	if_lb = gtk_label_new("Default interface:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_lb), 1.0f, 0.5f);
	gtk_widget_show(if_lb);

	if_cbxe = gtk_combo_box_text_new_with_entry();
	/*
	 * XXX - what if we can't get the list?
	 */
	if_list = capture_interface_list(&err, NULL);
	combo_list = build_capture_combo_list(if_list, FALSE);
	free_interface_list(if_list);
	if (combo_list != NULL) {
		GList *combo_entry;
		for (combo_entry = combo_list; combo_entry != NULL; combo_entry = g_list_next(combo_entry)) {
				 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(if_cbxe), combo_entry->data);
		}
	}
	if (prefs.capture_device) {
		gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(if_cbxe))),
				   prefs.capture_device);
	}
	else if (combo_list != NULL) {
		gtk_combo_box_set_active(GTK_COMBO_BOX(if_cbxe), 0);
	}
	free_capture_combo_list(combo_list);

	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_cbxe, 1, 2, row, row+1);
	tooltips_text = "The default interface to be captured from.";
	gtk_widget_set_tooltip_text(if_lb, tooltips_text);
	gtk_widget_set_tooltip_text(gtk_bin_get_child(GTK_BIN(if_cbxe)), tooltips_text);
	gtk_widget_show(if_cbxe);
	g_object_set_data(G_OBJECT(main_vb), DEVICE_KEY, if_cbxe);
	row++;

	/* Interface properties */
	ifopts_lb = gtk_label_new("Interfaces:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), ifopts_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(ifopts_lb), 1.0f, 0.5f);
	gtk_widget_show(ifopts_lb);

	ifopts_bt = gtk_button_new_from_stock(WIRESHARK_STOCK_EDIT);
	tooltips_text = "Open a dialog box to set various interface options.";
	gtk_widget_set_tooltip_text(ifopts_lb, tooltips_text);
	gtk_widget_set_tooltip_text(ifopts_bt, tooltips_text);
	g_signal_connect(ifopts_bt, "clicked", G_CALLBACK(ifopts_edit_cb), NULL);
	gtk_table_attach_defaults(GTK_TABLE(main_tb), ifopts_bt, 1, 2, row, row+1);
	row++;

	/* Promiscuous mode */
	promisc_cb = create_preference_check_button(main_tb, row++,
	    "Capture packets in promiscuous mode:",
	    "Usually a network card will only capture the traffic sent to its own network address. "
	    "If you want to capture all traffic that the network card can \"see\", mark this option. "
	    "See the FAQ for some more details of capturing packets from a switched network. ",
	    prefs.capture_prom_mode);
	g_object_set_data(G_OBJECT(main_vb), PROM_MODE_KEY, promisc_cb);

	/* Pcap-NG format */
	pcap_ng_cb = create_preference_check_button(main_tb, row++,
	    "Capture packets in pcap-ng format:",
	    "Capture packets in the next-generation capture file format.",
	    prefs.capture_pcap_ng);
	g_object_set_data(G_OBJECT(main_vb), PCAP_NG_KEY, pcap_ng_cb);

	/* Real-time capture */
	sync_cb = create_preference_check_button(main_tb, row++,
	    "Update list of packets in real time:",
	    "Update the list of packets while capture is in progress. "
	    "Don't use this option if you notice packet drops.",
	    prefs.capture_real_time);
	g_object_set_data(G_OBJECT(main_vb), CAPTURE_REAL_TIME_KEY, sync_cb);

	/* Auto-scroll real-time capture */
	auto_scroll_cb = create_preference_check_button(main_tb, row++,
	    "Automatic scrolling in live capture:",
	    "Automatic scrolling of the packet list while live capture is in progress. ",
	    prefs.capture_auto_scroll);
	g_object_set_data(G_OBJECT(main_vb), AUTO_SCROLL_KEY, auto_scroll_cb);

	/* Show capture info dialog */
	show_info_cb = create_preference_check_button(main_tb, row++,
	    "Hide capture info dialog:",
	    "Hide the capture info dialog while capturing. ",
	    !prefs.capture_show_info);
	g_object_set_data(G_OBJECT(main_vb), SHOW_INFO_KEY, show_info_cb);

	/* Show 'em what we got */
	gtk_widget_show_all(main_vb);

	return(main_vb);
}
void
filter_expression_save_dlg(gpointer data)
{
	GtkWidget   *main_vb, *main_filter_save_hb, *filter_save_frame,
		    *filter_save_type_vb, *filter_save_type_hb, *entry_hb,
		    *bbox, *ok_bt, *cancel_bt, *help_bt, *filter_text_box,
		    *label_text_box;

	const char *expr;

	/* The filter requested */
	expr = gtk_entry_get_text(GTK_ENTRY(data));

	if (filter_save_frame_w != NULL) {
		/* There's already a "Filter Save" dialog box; reactivate it. */
		reactivate_window(filter_save_frame_w);
		return;
	}

	filter_save_frame_w = dlg_window_new("Wireshark: Save Filter");

	/* Container for each row of widgets */
	main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
	gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
	gtk_container_add(GTK_CONTAINER(filter_save_frame_w), main_vb);
	gtk_widget_show(main_vb);


	/* */
	main_filter_save_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
	gtk_box_pack_start(GTK_BOX (main_vb), main_filter_save_hb, TRUE, TRUE, 0);
	gtk_widget_show(main_filter_save_hb);

	/* Filter Save frame */
	filter_save_frame = gtk_frame_new("Save Filter as...");
	gtk_box_pack_start(GTK_BOX(main_filter_save_hb), filter_save_frame,
	    TRUE, TRUE, 0);
	gtk_widget_show(filter_save_frame);

	filter_save_type_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
	gtk_container_set_border_width(GTK_CONTAINER(filter_save_type_vb), 3);
	gtk_container_add(GTK_CONTAINER(filter_save_frame),
	    filter_save_type_vb);
	gtk_widget_show(filter_save_type_vb);

	/* filter_save type row */
	filter_save_type_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
	gtk_box_pack_start(GTK_BOX (filter_save_type_vb), filter_save_type_hb, TRUE, TRUE, 0);

	gtk_widget_show(filter_save_type_hb);

	/* filter_save row */
	entry_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
	gtk_box_pack_start(GTK_BOX(filter_save_type_vb), entry_hb, FALSE,
	    FALSE, 0);
	gtk_widget_show(entry_hb);

	filter_text_box = gtk_entry_new();
	gtk_box_pack_start(GTK_BOX(entry_hb), filter_text_box, TRUE, TRUE, 0);
	g_signal_connect(filter_text_box, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL);
	g_signal_connect(filter_text_box, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL);
	g_signal_connect(filter_save_frame_w, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL);

	gtk_entry_set_text(GTK_ENTRY(filter_text_box), expr);
	gtk_widget_show(filter_text_box);

	label_text_box = gtk_entry_new();
	gtk_box_pack_start(GTK_BOX(entry_hb), label_text_box, TRUE, TRUE, 0);
	gtk_entry_set_text(GTK_ENTRY(label_text_box), "Filter");
	gtk_widget_show(label_text_box);

	/* Button row */
	bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL,
	    GTK_STOCK_HELP, NULL);
	gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
	gtk_widget_show(bbox);

	ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
	g_signal_connect(ok_bt, "clicked", G_CALLBACK(filter_save_ok_cb),
	filter_save_frame_w);

	cancel_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
	g_signal_connect(cancel_bt, "clicked", G_CALLBACK(filter_save_close_cb),
	filter_save_frame_w);

	help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
	g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb),
	(gpointer)HELP_FILTER_SAVE_DIALOG);

	g_object_set_data(G_OBJECT(filter_save_frame_w),
	    E_FILTER_SAVE_EXPR_KEY, filter_text_box);
	g_object_set_data(G_OBJECT(filter_save_frame_w),
	    E_FILTER_SAVE_LABEL_KEY, label_text_box);

	dlg_set_activate(label_text_box, ok_bt);

	/* Give the initial focus to the "offset" entry box. */
	gtk_widget_grab_focus(label_text_box);

	g_signal_connect(filter_save_frame_w, "delete_event",
	G_CALLBACK(window_delete_event_cb), NULL);
	g_signal_connect(filter_save_frame_w, "destroy",
	G_CALLBACK(filter_save_frame_destroy_cb), NULL);

	gtk_widget_show(filter_save_frame_w);
	window_present(filter_save_frame_w);
}
GtkWidget *
font_color_prefs_show(void)
{
  GtkWidget     *main_vb, *main_grid, *label, *combo_box;
  GtkWidget     *font_sample, *color_sample, *colorsel;
  static const gchar   *mt[] = {
    "Marked packet foreground",          /* MFG_IDX 0*/
    "Marked packet background",          /* MBG_IDX 1*/
    "Ignored packet foreground",         /* IFG_IDX 2*/
    "Ignored packet background",         /* IBG_IDX 3*/
    "'Follow Stream' client foreground", /* CFG_IDX 4*/
    "'Follow Stream' client background", /* CBG_IDX 5*/
    "'Follow Stream' server foreground", /* SFG_IDX 6*/
    "'Follow Stream' server background", /* SBG_IDX 7*/
    "Valid filter text entry",           /* FTV_IDX 8*/
    "Invalid filter text entry",         /* FTI_IDX 9*/
    "Deprecated filter text entry"       /* FTD_IDX 10*/
  };
  int            mcount = sizeof(mt) / sizeof (gchar *);
  GtkTextBuffer *buf;
  GtkTextIter    iter;
  GRand         *rand_state     = g_rand_new();
  GString       *preview_string = g_string_new("");
  int            i;

#define GRID_FONT_ROW      0
#define GRID_COLOR_ROW     1
#define GRID_COLOR_SEL_ROW 3

  /* The font hasn't been changed yet. */
  font_changed = FALSE;

  color_t_to_gdkxxx(&tcolors[MFG_IDX], &prefs.gui_marked_fg);
  color_t_to_gdkxxx(&tcolors[MBG_IDX], &prefs.gui_marked_bg);
  color_t_to_gdkxxx(&tcolors[IFG_IDX], &prefs.gui_ignored_fg);
  color_t_to_gdkxxx(&tcolors[IBG_IDX], &prefs.gui_ignored_bg);
  color_t_to_gdkxxx(&tcolors[CFG_IDX], &prefs.st_client_fg);
  color_t_to_gdkxxx(&tcolors[CBG_IDX], &prefs.st_client_bg);
  color_t_to_gdkxxx(&tcolors[SFG_IDX], &prefs.st_server_fg);
  color_t_to_gdkxxx(&tcolors[SBG_IDX], &prefs.st_server_bg);
  color_t_to_gdkxxx(&tcolors[FTV_IDX], &prefs.gui_text_valid);
  color_t_to_gdkxxx(&tcolors[FTI_IDX], &prefs.gui_text_invalid);
  color_t_to_gdkxxx(&tcolors[FTD_IDX], &prefs.gui_text_deprecated);
  color_t_to_gdkxxx(&filter_text_fg, &filter_text_fg_color);

#if ! GTK_CHECK_VERSION(3,4,0)
  for (i=0; i<MAX_IDX; i++) {
    tcolors_orig[i] = tcolors[i];
  }
#endif

  curcolor = &tcolors[CFG_IDX];

  /* Enclosing containers for each row of widgets */
  main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE);
  gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);

  main_grid = ws_gtk_grid_new();
  gtk_box_pack_start(GTK_BOX(main_vb), main_grid, FALSE, FALSE, 0);
  ws_gtk_grid_set_row_spacing(GTK_GRID(main_grid), 40);
  ws_gtk_grid_set_column_spacing(GTK_GRID(main_grid), 15);
  gtk_widget_show(main_grid);

  label = gtk_label_new("Main window font:");
  gtk_misc_set_alignment(GTK_MISC(label), 1.0f, 0.5f);
  ws_gtk_grid_attach_extended(GTK_GRID(main_grid), label,
                              0, GRID_FONT_ROW, 1, 1,
                              (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
  gtk_widget_show(label);

  font_button = gtk_font_button_new_with_font(prefs.gui_gtk2_font_name);
  gtk_font_button_set_title(GTK_FONT_BUTTON(font_button), "Wireshark: Font");
  ws_gtk_grid_attach(GTK_GRID(main_grid), font_button,
                     1, GRID_FONT_ROW, 1, 1);
  gtk_widget_show(font_button);

  g_string_printf(preview_string, " %s 0123456789",
                  font_pangrams[g_rand_int_range(rand_state, 0, NUM_FONT_PANGRAMS)]);

  font_sample = gtk_text_view_new();
  gtk_text_view_set_editable(GTK_TEXT_VIEW(font_sample), FALSE);
  buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(font_sample));
  gtk_text_buffer_get_start_iter(buf, &iter);
  srand((unsigned int) time(NULL));
  gtk_text_buffer_insert(buf, &iter, preview_string->str, -1);
  ws_gtk_grid_attach_extended(GTK_GRID(main_grid), font_sample,
                              2, GRID_FONT_ROW, 1, 1,
                              (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
  g_signal_connect(font_button, "font-set", G_CALLBACK(select_font), NULL);
  gtk_widget_show(font_sample);

  g_string_free(preview_string, TRUE);
  g_object_set_data(G_OBJECT(font_button), FONT_SAMPLE_KEY, font_sample);

  label = gtk_label_new("Colors:");
  gtk_misc_set_alignment(GTK_MISC(label), 1.0f, 0.5f);
  ws_gtk_grid_attach_extended(GTK_GRID(main_grid), label,
                              0, GRID_COLOR_ROW, 1, 1,
                              (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0,0);
  gtk_widget_show(label);

  /* We have to create this now, and configure it below. */

#if GTK_CHECK_VERSION(3,4,0)
  /* XXX: There appears to be a bug in the GTK3 GtkColorChooserWidget such that
   *  when in the GtkColorChooserWidget "customize" mode (aka "color-edit" mode)
   *  selecting a color doesn't trigger a "motify::rgba" callback.
   *  The effect is that the sample text FG/BG colors don't update for the GTK3
   *  GtkColorChooserWidget in "custon color edit node").
   *  I expect use of the "customize mode" will be minimal and that the bug will
   *  not be very noticeable.
   *  (A GTK3 bug report has beem submitted.
   */
#endif
  colorsel = gtk_color_xxx_new();

  combo_box = gtk_combo_box_text_new();
  for (i = 0; i < mcount; i++){
    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), mt[i]);
  }
  gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), CFG_IDX);
  g_signal_connect(combo_box, "changed", G_CALLBACK(update_current_color), colorsel);
  ws_gtk_grid_attach(GTK_GRID(main_grid), combo_box,
                     1, GRID_COLOR_ROW, 1, 1);

  gtk_widget_show(combo_box);

  color_sample = gtk_text_view_new();
  update_font(user_font_get_regular(), font_sample, color_sample);
  gtk_text_view_set_editable(GTK_TEXT_VIEW(color_sample), FALSE);
  buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(color_sample));
  gtk_text_buffer_get_start_iter(buf, &iter);

  gtk_text_buffer_create_tag(buf, "marked",
                             TAG_PROP_FG_COLOR, &tcolors[MFG_IDX],
                             TAG_PROP_BG_COLOR, &tcolors[MBG_IDX],
                             NULL);
  gtk_text_buffer_create_tag(buf, "ignored",
                             TAG_PROP_FG_COLOR, &tcolors[IFG_IDX],
                             TAG_PROP_BG_COLOR, &tcolors[IBG_IDX],
                             NULL);
  gtk_text_buffer_create_tag(buf, "client",
                             TAG_PROP_FG_COLOR, &tcolors[CFG_IDX],
                             TAG_PROP_BG_COLOR, &tcolors[CBG_IDX],
                             NULL);
  gtk_text_buffer_create_tag(buf, "server",
                             TAG_PROP_FG_COLOR, &tcolors[SFG_IDX],
                             TAG_PROP_BG_COLOR, &tcolors[SBG_IDX],
                             NULL);
  gtk_text_buffer_create_tag(buf, "text_valid",
                             TAG_PROP_FG_COLOR, &filter_text_fg,
                             TAG_PROP_BG_COLOR, &tcolors[FTV_IDX],
                             NULL);
  gtk_text_buffer_create_tag(buf, "text_invalid",
                             TAG_PROP_FG_COLOR, &filter_text_fg,
                             TAG_PROP_BG_COLOR, &tcolors[FTI_IDX],
                             NULL);
  gtk_text_buffer_create_tag(buf, "text_deprecated",
                             TAG_PROP_FG_COLOR, &filter_text_fg,
                             TAG_PROP_BG_COLOR, &tcolors[FTD_IDX],
                             NULL);

  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_MARKED_TEXT,  -1,
                                           "marked", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_IGNORED_TEXT, -1,
                                           "ignored", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_CLIENT_TEXT,  -1,
                                           "client", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_SERVER_TEXT,  -1,
                                           "server", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_TEXT_VALID_TEXT,  -1,
                                           "text_valid", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_TEXT_INVALID_TEXT,  -1,
                                           "text_invalid", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_TEXT_DEPRECATED_TEXT,  -1,
                                           "text_deprecated", NULL);

  ws_gtk_grid_attach_extended(GTK_GRID(main_grid), color_sample,
                              2, GRID_COLOR_ROW, 1, 2,
                              (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), (GtkAttachOptions)0, 0, 0);
  gtk_widget_show(color_sample);

  gtk_color_xxx_set_yyy(GTK_COLOR_XXX(colorsel), curcolor);
  ws_gtk_grid_attach_extended(GTK_GRID(main_grid), colorsel,
                              1, GRID_COLOR_SEL_ROW, 2, 1,
                              (GtkAttachOptions)(GTK_FILL|GTK_EXPAND), (GtkAttachOptions)0, 0, 0);

  g_object_set_data(G_OBJECT(combo_box), COLOR_SAMPLE_KEY, color_sample);
  g_object_set_data(G_OBJECT(colorsel),  COLOR_SAMPLE_KEY, color_sample);
  g_signal_connect(colorsel, COLOR_CHANGED_SIGNAL, G_CALLBACK(update_text_color), NULL);
  gtk_widget_show(colorsel);

  g_rand_free(rand_state);
  gtk_widget_show(main_vb);
  return main_vb;
}
示例#12
0
static GtkWidget *
display_simple_dialog(gint type, gint btn_mask, char *message)
{
  GtkWidget   *win, *main_vb, *top_hb, *msg_vb, *type_pm, *msg_label, *ask_cb,
              *bbox, *ok_bt, *yes_bt, *bt, *save_bt, *dont_save_bt;

  /* Main window */
  switch (type) {
  case ESD_TYPE_WARN :
    type_pm = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
    break;
  case ESD_TYPE_CONFIRMATION:
    type_pm = gtk_image_new_from_stock( GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
    break;
  case ESD_TYPE_ERROR:
    type_pm = gtk_image_new_from_stock( GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
    break;
  case ESD_TYPE_STOP :
    type_pm = gtk_image_new_from_stock( GTK_STOCK_STOP, GTK_ICON_SIZE_DIALOG);
    break;
  case ESD_TYPE_INFO :
  default :
    type_pm = gtk_image_new_from_stock( GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
    break;
  }

  /*
   * 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.
   * For now, we give it a Win32 title of just "Wireshark"; we should
   * arguably take an argument for the title.
   */
  if(btn_mask == ESD_BTN_NONE) {
    win = splash_window_new();
  } else {
#ifdef _WIN32
    win = dlg_window_new("Wireshark");
#else
    win = dlg_window_new("");
#endif
  }

  gtk_window_set_modal(GTK_WINDOW(win), TRUE);
  gtk_container_set_border_width(GTK_CONTAINER(win), 6);

  /* Container for our rows */
  main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 12, FALSE);
  gtk_container_add(GTK_CONTAINER(win), main_vb);
  gtk_widget_show(main_vb);

  /* Top row: Icon and message text */
  top_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12, FALSE);
  gtk_container_set_border_width(GTK_CONTAINER(main_vb), 6);
  gtk_box_pack_start(GTK_BOX(main_vb), top_hb, TRUE, TRUE, 0);
  gtk_widget_show(top_hb);

  gtk_misc_set_alignment (GTK_MISC (type_pm), 0.5f, 0.0f);
  gtk_box_pack_start(GTK_BOX(top_hb), type_pm, TRUE, TRUE, 0);
  gtk_widget_show(type_pm);

  /* column for message and optional check button */
  msg_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 6, FALSE);
  gtk_box_set_spacing(GTK_BOX(msg_vb), 24);
  gtk_box_pack_start(GTK_BOX(top_hb), msg_vb, TRUE, TRUE, 0);
  gtk_widget_show(msg_vb);

  /* message */
  msg_label = gtk_label_new(message);

  gtk_label_set_markup(GTK_LABEL(msg_label), message);
  gtk_label_set_selectable(GTK_LABEL(msg_label), TRUE);
  g_object_set(gtk_widget_get_settings(msg_label),
    "gtk-label-select-on-focus", FALSE, NULL);

  gtk_label_set_justify(GTK_LABEL(msg_label), GTK_JUSTIFY_FILL);
  gtk_misc_set_alignment (GTK_MISC (type_pm), 0.5f, 0.0f);
  gtk_box_pack_start(GTK_BOX(msg_vb), msg_label, TRUE, TRUE, 0);
  gtk_label_set_line_wrap(GTK_LABEL(msg_label), TRUE);
  gtk_widget_show(msg_label);

  if(btn_mask == ESD_BTN_NONE) {
    gtk_widget_show(win);
    return win;
  }

  /* optional check button */
  ask_cb = gtk_check_button_new_with_label("replace with text...");
  gtk_box_pack_start(GTK_BOX(msg_vb), ask_cb, TRUE, TRUE, 0);
  g_object_set_data(G_OBJECT(win), CHECK_BUTTON, ask_cb);

  /* Button row */
  switch(btn_mask) {
  case(ESD_BTN_OK):
    bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
    break;
  case(ESD_BTN_OK | ESD_BTN_CANCEL):
    bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
    break;
  case(ESD_BTN_CLEAR | ESD_BTN_CANCEL):
    bbox = dlg_button_row_new(GTK_STOCK_CLEAR, GTK_STOCK_CANCEL, NULL);
    break;
  case(ESD_BTNS_YES_NO_CANCEL):
    bbox = dlg_button_row_new(GTK_STOCK_YES, GTK_STOCK_NO, GTK_STOCK_CANCEL, NULL);
    break;
  case(ESD_BTNS_SAVE_DONTSAVE_CANCEL):
    bbox = dlg_button_row_new(GTK_STOCK_SAVE, WIRESHARK_STOCK_DONT_SAVE, GTK_STOCK_CANCEL, NULL);
    break;
  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;
  case (ESD_BTNS_QUIT_DONTSAVE_CANCEL):
    bbox = dlg_button_row_new(WIRESHARK_STOCK_QUIT_DONT_SAVE, GTK_STOCK_CANCEL, NULL);
    break;
  case(ESD_BTNS_YES_NO):
    bbox = dlg_button_row_new(GTK_STOCK_YES, GTK_STOCK_NO, NULL);
    break;
  default:
    g_assert_not_reached();
    bbox = NULL;
    break;
  }
  gtk_box_pack_start(GTK_BOX(main_vb), bbox, TRUE, TRUE, 0);
  gtk_widget_show(bbox);

  ok_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
  if(ok_bt) {
    g_object_set_data(G_OBJECT(ok_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_OK));
    g_signal_connect(ok_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
  }

  save_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_SAVE);
  if (save_bt) {
    g_object_set_data(G_OBJECT(save_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_SAVE));
    g_signal_connect(save_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
  }

  dont_save_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_DONT_SAVE);
  if (dont_save_bt) {
    g_object_set_data(G_OBJECT(dont_save_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_DONT_SAVE));
    g_signal_connect(dont_save_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
  }

  dont_save_bt = (GtkWidget *)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);
  }
  bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLEAR);
  if(bt) {
    g_object_set_data(G_OBJECT(bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_CLEAR));
    g_signal_connect(bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
  }

  yes_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_YES);
  if(yes_bt) {
    g_object_set_data(G_OBJECT(yes_bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_YES));
    g_signal_connect(yes_bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
  }

  bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_NO);
  if(bt) {
    g_object_set_data(G_OBJECT(bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_NO));
    g_signal_connect(bt, "clicked", G_CALLBACK(simple_dialog_cancel_cb), win);
  }

  bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
  if(bt) {
    g_object_set_data(G_OBJECT(bt), CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_CANCEL));
    window_set_cancel_button(win, bt, simple_dialog_cancel_cb);
  }

  if(!bt) {
    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);
    }
  }

  dlg_button_focus_nth(bbox, 0);

  gtk_widget_show(win);

  return win;
}
示例#13
0
  double        seconds;
  int		i;
  int		tot_invokes, tot_rr;
  double	tot_invokes_size, tot_rr_size;

  /* initialize the tally */
  summary_fill_in(&cfile, &summary);

  /* initial computations */
  seconds = summary.stop_time - summary.start_time;

  sum_open_w = dlg_window_new("GSM MAP Statistics: Summary");  /* transient_for top_level */
  gtk_window_set_destroy_with_parent (GTK_WINDOW(sum_open_w), TRUE);

  /* Container for each row of widgets */
  main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
  gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
  gtk_container_add(GTK_CONTAINER(sum_open_w), main_vb);
  gtk_widget_show(main_vb);

  /* File frame */
  file_fr = gtk_frame_new("File");
  gtk_box_pack_start(GTK_BOX (main_vb), file_fr, TRUE, TRUE, 0);
  gtk_widget_show(file_fr);

  file_box = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
  gtk_container_add(GTK_CONTAINER(file_fr), file_box);
  gtk_widget_show(file_box);

  /* filename */
  g_snprintf(string_buff, SUM_STR_MAX, "Name: %s", ((summary.filename) ? summary.filename : "None"));
示例#14
0
GtkWidget *
stream_prefs_show(void)
{
  GtkWidget *main_vb, *main_tb, *label, *combo_box;
  GtkWidget *sample, *colorsel;
  int        width, height, i;
  const gchar     *mt[] = {
	  "Marked packet foreground",		/* MFG_IDX 0*/
	  "Marked packet background",		/* MBG_IDX 1*/
	  "Ignored packet foreground",		/* IFG_IDX 2*/
	  "Ignored packet background",		/* IBG_IDX 3*/
	  "TCP stream client foreground",	/* CFG_IDX 4*/
	  "TCP stream client background",	/* CBG_IDX 5*/
	  "TCP stream server foreground",	/* SFG_IDX 6*/
	  "TCP stream server background"	/* SBG_IDX 7*/
  };
  int mcount = sizeof(mt) / sizeof (gchar *);
  GtkTextBuffer *buf;
  GtkTextIter    iter;
  PangoLayout   *layout;

  color_t_to_gdkcolor(&tcolors[MFG_IDX], &prefs.gui_marked_fg);
  color_t_to_gdkcolor(&tcolors[MBG_IDX], &prefs.gui_marked_bg);
  color_t_to_gdkcolor(&tcolors[IFG_IDX], &prefs.gui_ignored_fg);
  color_t_to_gdkcolor(&tcolors[IBG_IDX], &prefs.gui_ignored_bg);
  color_t_to_gdkcolor(&tcolors[CFG_IDX], &prefs.st_client_fg);
  color_t_to_gdkcolor(&tcolors[CBG_IDX], &prefs.st_client_bg);
  color_t_to_gdkcolor(&tcolors[SFG_IDX], &prefs.st_server_fg);
  color_t_to_gdkcolor(&tcolors[SBG_IDX], &prefs.st_server_bg);

  curcolor = &tcolors[CFG_IDX];

  /* Enclosing containers for each row of widgets */
  main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE);
  gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);

  main_tb = gtk_table_new(3, 3, FALSE);
  gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0);
  gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
  gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15);
  gtk_widget_show(main_tb);

  label = gtk_label_new("Set:");
  gtk_misc_set_alignment(GTK_MISC(label), 1.0f, 0.5f);
  gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, 0, 1);
  gtk_widget_show(label);

  /* We have to create this now, and configure it below. */
  colorsel = gtk_color_selection_new();

  combo_box = gtk_combo_box_text_new();
  for (i = 0; i < mcount; i++){
	   gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), mt[i]);
  }
  gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), CFG_IDX);
  g_signal_connect(combo_box, "changed", G_CALLBACK(update_current_color), colorsel);
  gtk_table_attach(GTK_TABLE(main_tb), combo_box, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);

  gtk_widget_show(combo_box);

  sample = gtk_text_view_new();
  layout = gtk_widget_create_pango_layout(sample, SAMPLE_SERVER_TEXT);
  pango_layout_get_pixel_size(layout, &width, &height);
  g_object_unref(G_OBJECT(layout));
  gtk_widget_set_size_request(sample, width, height * 2);
  gtk_text_view_set_editable(GTK_TEXT_VIEW(sample), FALSE);
  buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(sample));
  gtk_text_buffer_get_start_iter(buf, &iter);
  gtk_text_buffer_create_tag(buf, "marked",
                             "foreground-gdk", &tcolors[MFG_IDX],
                             "background-gdk", &tcolors[MBG_IDX], NULL);
  gtk_text_buffer_create_tag(buf, "ignored",
                             "foreground-gdk", &tcolors[IFG_IDX],
                             "background-gdk", &tcolors[IBG_IDX], NULL);
  gtk_text_buffer_create_tag(buf, "client",
                             "foreground-gdk", &tcolors[CFG_IDX],
                             "background-gdk", &tcolors[CBG_IDX], NULL);
  gtk_text_buffer_create_tag(buf, "server",
                             "foreground-gdk", &tcolors[SFG_IDX],
                             "background-gdk", &tcolors[SBG_IDX], NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_MARKED_TEXT, -1,
                                           "marked", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_IGNORED_TEXT, -1,
                                           "ignored", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_CLIENT_TEXT, -1,
                                           "client", NULL);
  gtk_text_buffer_insert_with_tags_by_name(buf, &iter, SAMPLE_SERVER_TEXT, -1,
                                           "server", NULL);
  gtk_table_attach_defaults(GTK_TABLE(main_tb), sample, 2, 3, 0, 2);
  gtk_widget_show(sample);

  gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel),
                                        curcolor);
  gtk_table_attach(GTK_TABLE(main_tb), colorsel, 0, 3, 2, 3,
		  GTK_SHRINK, GTK_SHRINK, 0, 0);

  g_object_set_data(G_OBJECT(colorsel), STREAM_SAMPLE_KEY, sample);
  g_signal_connect(colorsel, "color-changed", G_CALLBACK(update_text_color), NULL);
  gtk_widget_show(colorsel);

  gtk_widget_show(main_vb);
  return(main_vb);
}
示例#15
0
/* The purpose of this is, to have one place available, where all button rows
 * from all dialogs are laid out. This will:
 *
 * a.) keep the button layout more consistent over the different dialogs
 * b.) being able to switch between different button layouts, e.g.:
 *     e.g. Win32: "OK" "Apply" "Cancel"
 *     e.g. GNOME: "Apply" "Cancel" "OK"
 */
GtkWidget *
dlg_button_row_new(const gchar *stock_id_first, ...)
{
    gint         buttons  = 0;
    va_list      stock_id_list;
    const gchar *stock_id = stock_id_first;
    GtkWidget   *hbox;
    GtkWidget   *button_hbox;
    GtkWidget   *help_hbox;
    GtkWidget   *button;

    const gchar *apply         = NULL;
    const gchar *cancel        = NULL;
    const gchar *cap_start     = NULL;
    const gchar *cap_stop      = NULL;
    const gchar *cap_options   = NULL;
#ifdef _WIN32
    const gchar *cap_details   = NULL;
#endif
    const gchar *clear         = NULL;
    const gchar *closex        = NULL;
    const gchar *copy          = NULL;
    const gchar *create_stat   = NULL;
    const gchar *delete_id     = NULL;
    const gchar *dont_save     = NULL;
    const gchar *filter_stream = NULL;
    const gchar *find          = NULL;
    const gchar *help          = NULL;
    const gchar *jump          = NULL;
    const gchar *no            = NULL;
    const gchar *ok            = NULL;
    const gchar *print         = NULL;
    const gchar *save          = NULL;
    const gchar *save_as       = NULL;
    const gchar *save_all      = NULL;
    const gchar *stop          = NULL;
    const gchar *yes           = NULL;
    const gchar *refresh       = NULL;
    const gchar *add           = NULL;
#ifdef HAVE_GEOIP
    const gchar *map           = NULL;
#endif /* HAVE_GEOIP */
    const gchar *follow_stream = NULL;
    const gchar *graph_a_b     = NULL;
    const gchar *graph_b_a     = NULL;


    va_start(stock_id_list, stock_id_first);

    /* get all buttons needed */
    while(stock_id != NULL) {
        if (strcmp(stock_id, GTK_STOCK_OK) == 0) {
            ok = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_CREATE_STAT) == 0) {
            create_stat = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_APPLY) == 0) {
            apply = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_SAVE) == 0) {
            save = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_SAVE_AS) == 0) {
            save_as = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_SAVE_ALL) == 0) {
            save_all = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_DONT_SAVE) == 0) {
            dont_save = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_QUIT_DONT_SAVE) == 0) {
            dont_save = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_CANCEL) == 0) {
            cancel = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_CLOSE) == 0) {
            closex = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_CLEAR) == 0) {
            clear = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_REFRESH) == 0) {
            refresh = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_ADD) == 0) {
           add = stock_id;
#ifdef HAVE_LIBPCAP
        } else if (strcmp(stock_id, WIRESHARK_STOCK_CAPTURE_START) == 0) {
            cap_start = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_CAPTURE_STOP) == 0) {
            cap_stop = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_CAPTURE_OPTIONS) == 0) {
            cap_options = stock_id;
#ifdef _WIN32
        } else if (strcmp(stock_id, WIRESHARK_STOCK_CAPTURE_DETAILS) == 0) {
            cap_details = stock_id;
#endif
#endif /* HAVE_LIBPCAP */
#ifdef HAVE_GEOIP
        } else if (strcmp(stock_id, WIRESHARK_STOCK_MAP) == 0) {
            map = stock_id;
#endif /* HAVE_GEOIP */
        } else if (strcmp(stock_id, WIRESHARK_STOCK_FOLLOW_STREAM) == 0) {
            follow_stream = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_STOP) == 0) {
            stop = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_HELP) == 0) {
            help = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_PRINT) == 0) {
            print = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_FIND) == 0) {
            find = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_JUMP_TO) == 0) {
            jump = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_YES) == 0) {
            yes = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_NO) == 0) {
            no = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_FILTER_OUT_STREAM) == 0) {
            filter_stream = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_DELETE) == 0) {
            delete_id = stock_id;
        } else if (strcmp(stock_id, GTK_STOCK_COPY) == 0) {
            copy = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_GRAPH_A_B) == 0) {
            graph_a_b = stock_id;
        } else if (strcmp(stock_id, WIRESHARK_STOCK_GRAPH_B_A) == 0) {
            graph_b_a = stock_id;
        } else {
            /* we don't know that button! */
            g_assert_not_reached();
        }
        buttons++;
        stock_id = va_arg(stock_id_list, gchar *);
    }
    va_end(stock_id_list);

    hbox = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, DLG_BUTTON_SPACING, FALSE);
    gtk_widget_show(hbox);

    button_hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
    gtk_box_pack_end(GTK_BOX(hbox), button_hbox, TRUE, TRUE, 0);
    g_object_set_data(G_OBJECT(hbox), BUTTON_HBOX_KEY, button_hbox);
    gtk_widget_show(button_hbox);
    gtk_box_set_spacing(GTK_BOX(button_hbox), DLG_BUTTON_SPACING);

    help_hbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
    gtk_box_pack_end(GTK_BOX(hbox), help_hbox, FALSE, FALSE, 0);
    gtk_widget_show(help_hbox);
    gtk_box_set_spacing(GTK_BOX(help_hbox), DLG_BUTTON_SPACING);

    if (buttons == 0) {
        /* if no buttons wanted, simply do nothing */
        return hbox;
    }

    if (buttons == 1) {
        /* if only one button, simply put it in the middle (default) */
        dlg_button_new(hbox, button_hbox, stock_id_first);
        return hbox;
    }

    /* do we have a help button? -> special handling for it */
    if (help) {
        button = ws_gtk_button_new_from_stock(help);
        gtk_widget_set_can_default(button, TRUE);
        g_object_set_data(G_OBJECT(hbox), help, button);
        gtk_box_pack_start(GTK_BOX(help_hbox), button, FALSE, FALSE, 0);
        gtk_widget_show(button);
        buttons--;
    }

    /* do we have a copy button? -> special handling for it */
    if (copy) {
        button = ws_gtk_button_new_from_stock(copy);
        gtk_widget_set_can_default(button, TRUE);
        g_object_set_data(G_OBJECT(hbox), copy, button);
        gtk_box_pack_start(GTK_BOX(help_hbox), button, FALSE, FALSE, 0);
        gtk_widget_show(button);
        buttons--;
    }

    /* do we have a refresh button? -> special handling for it */
    if (refresh) {
        button = ws_gtk_button_new_from_stock(refresh);
        g_object_set_data(G_OBJECT(hbox), refresh, button);
        gtk_box_pack_start(GTK_BOX(help_hbox), button, FALSE, FALSE, 0);
        gtk_widget_show(button);
        buttons--;
    }

    /* do we have an add button? -> special handling for it */
    if (add) {
        button = ws_gtk_button_new_from_stock(add);
        g_object_set_data(G_OBJECT(hbox), add, button);
        gtk_box_pack_start(GTK_BOX(help_hbox), button, FALSE, FALSE, 0);
        gtk_widget_show(button);
        buttons--;
    }

#ifdef HAVE_GEOIP
    /* do we have a map button? -> special handling for it */
    if (map) {
        button = ws_gtk_button_new_from_stock(map);
        gtk_widget_set_can_default(button, TRUE);
        g_object_set_data(G_OBJECT(hbox), map, button);
        gtk_box_pack_start(GTK_BOX(help_hbox), button, FALSE, FALSE, 0);
        gtk_widget_show(button);
        buttons--;
    }
#endif /* HAVE_GEOIP */

    /* if more than one button, sort buttons from left to right */
    /* (the whole button cluster will then be right aligned) */
    gtk_button_box_set_layout (GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END);

#if !defined(_WIN32)
    /* beware: sequence of buttons are important! */

    /* XXX: this can be implemented more elegant of course, but it works as it should */
    if (buttons == 2) {
        if (ok && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, ok);
            return hbox;
        }
        if (print && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, print);
            return hbox;
        }
        if (find && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, find);
            return hbox;
        }
        if (jump && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, jump);
            return hbox;
        }
        if (save && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, save);
            return hbox;
        }
        if (ok && clear) {
            dlg_button_new(hbox, button_hbox, clear);
            dlg_button_new(hbox, button_hbox, ok);
            return hbox;
        }
        if (save && closex) {
            dlg_button_new(hbox, button_hbox, closex);
            dlg_button_new(hbox, button_hbox, save);
            return hbox;
        }
        if (create_stat && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, create_stat);
            return hbox;
        }
        if (cap_start && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, cap_start);
            return hbox;
        }
        if (cap_stop && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, cap_stop);
            return hbox;
        }
        if (delete_id && cancel) {
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, delete_id);
            return hbox;
        }
    }
    if (buttons == 3) {
        if (ok && save && closex) {
            dlg_button_new(hbox, button_hbox, save);
            dlg_button_new(hbox, button_hbox, closex);
            dlg_button_new(hbox, button_hbox, ok);
            return hbox;
        }
        if (ok && apply && cancel) {
            dlg_button_new(hbox, button_hbox, apply);
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, ok);
            return hbox;
        }
        if (apply && save && closex) {
            dlg_button_new(hbox, button_hbox, save);
            dlg_button_new(hbox, button_hbox, closex);
            dlg_button_new(hbox, button_hbox, apply);
            return hbox;
        }
        if (yes && no && cancel) {
            dlg_button_new(hbox, button_hbox, no);
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, yes);
            return hbox;
        }
        if (save && dont_save && cancel) {
            dlg_button_new(hbox, button_hbox, dont_save);
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, save);
            return hbox;
        }
    }
    if (buttons == 4) {
        if (ok && apply && save && cancel) {
            dlg_button_new(hbox, button_hbox, save);
            dlg_button_new(hbox, button_hbox, apply);
            dlg_button_new(hbox, button_hbox, cancel);
            dlg_button_new(hbox, button_hbox, ok);
            return hbox;
        }
        if (ok && apply && save && closex) {
            dlg_button_new(hbox, button_hbox, save);
            dlg_button_new(hbox, button_hbox, apply);
            dlg_button_new(hbox, button_hbox, closex);
            dlg_button_new(hbox, button_hbox, ok);
            return hbox;
        }
    }
#endif

    /* beware: sequence of buttons is important! */
    if (ok            != NULL) dlg_button_new(hbox, button_hbox, ok);
    if (delete_id     != NULL) dlg_button_new(hbox, button_hbox, delete_id);
    if (jump          != NULL) dlg_button_new(hbox, button_hbox, jump);
    if (find          != NULL) dlg_button_new(hbox, button_hbox, find);
    if (print         != NULL) dlg_button_new(hbox, button_hbox, print);
    if (create_stat   != NULL) dlg_button_new(hbox, button_hbox, create_stat);
    if (apply         != NULL) dlg_button_new(hbox, button_hbox, apply);
    if (yes           != NULL) dlg_button_new(hbox, button_hbox, yes);
    if (no            != NULL) dlg_button_new(hbox, button_hbox, no);
    if (save          != NULL) dlg_button_new(hbox, button_hbox, save);
    if (save_as       != NULL) dlg_button_new(hbox, button_hbox, save_as);
    if (save_all      != NULL) dlg_button_new(hbox, button_hbox, save_all);
    if (dont_save     != NULL) dlg_button_new(hbox, button_hbox, dont_save);
    if (cap_start     != NULL) dlg_button_new(hbox, button_hbox, cap_start);
    if (cap_stop      != NULL) dlg_button_new(hbox, button_hbox, cap_stop);
    if (cap_options   != NULL) dlg_button_new(hbox, button_hbox, cap_options);
#ifdef _WIN32
    if (cap_details   != NULL) dlg_button_new(hbox, button_hbox, cap_details);
#endif
    if (stop          != NULL) dlg_button_new(hbox, button_hbox, stop);
    if (clear         != NULL) dlg_button_new(hbox, button_hbox, clear);
    if (filter_stream != NULL) dlg_button_new(hbox, button_hbox, filter_stream);
    if (follow_stream != NULL) dlg_button_new(hbox, button_hbox, follow_stream);
    if (graph_a_b     != NULL) dlg_button_new(hbox, button_hbox, graph_a_b);
    if (graph_b_a     != NULL) dlg_button_new(hbox, button_hbox, graph_b_a);
    if (closex        != NULL) dlg_button_new(hbox, button_hbox, closex);
    if (cancel        != NULL) dlg_button_new(hbox, button_hbox, cancel);

    return hbox;
}
示例#16
0
/* Capture callback data keys */
#define E_GOTO_FNUMBER_KEY     "goto_fnumber_te"

static void
goto_frame_ok_cb(GtkWidget *ok_bt, gpointer parent_w);

void
goto_frame_cb(GtkWidget *w _U_, gpointer d _U_)
{
  GtkWidget     *goto_frame_w, *main_vb, *fnumber_hb, *fnumber_lb, *fnumber_te,
                *bbox, *ok_bt, *cancel_bt, *help_bt;

  goto_frame_w = dlg_window_new("Wireshark: Go To Packet");

  /* Container for each row of widgets */
  main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 3, FALSE);
  gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
  gtk_container_add(GTK_CONTAINER(goto_frame_w), main_vb);
  gtk_widget_show(main_vb);

  /* Frame number row */
  fnumber_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE);
  gtk_container_add(GTK_CONTAINER(main_vb), fnumber_hb);
  gtk_widget_show(fnumber_hb);

  fnumber_lb = gtk_label_new("Packet number:");
  gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_lb, FALSE, FALSE, 0);
  gtk_widget_show(fnumber_lb);

  fnumber_te = gtk_entry_new();
  gtk_box_pack_start(GTK_BOX(fnumber_hb), fnumber_te, FALSE, FALSE, 0);
示例#17
0
static GtkWidget *
build_heur_dissectors_treeview(void)
{
  GtkWidget  *bbox, *proto_list, *label, *proto_sw, *proto_vb, *button,
             *ok_bt, *save_bt, *cancel_bt;

  static const gchar *titles[] = { "Status", "Heuristic Protocol", "Description" };
  GtkListStore *proto_store;
  GtkCellRenderer *proto_rend;
  GtkTreeViewColumn *proto_col;

  /* Protocol list */
  proto_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE);
  gtk_widget_show(proto_vb);

  proto_sw = scrolled_window_new(NULL, NULL);
  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(proto_sw),
                                   GTK_SHADOW_IN);
  gtk_box_pack_start(GTK_BOX(proto_vb), proto_sw, TRUE, TRUE, 0);
  gtk_widget_show(proto_sw);

  proto_store = gtk_list_store_new(4, G_TYPE_BOOLEAN, G_TYPE_STRING,
                                   G_TYPE_STRING, G_TYPE_POINTER);
  show_heur_selection(proto_store);
  /* default sort on "abbrev" column */
  gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(proto_store), 1,
                                       GTK_SORT_ASCENDING);

  proto_list = tree_view_new(GTK_TREE_MODEL(proto_store));
  gtk_container_add(GTK_CONTAINER(proto_sw), proto_list);

  proto_rend = gtk_cell_renderer_toggle_new();
  g_signal_connect(proto_rend, "toggled", G_CALLBACK(status_toggled), proto_store);
  proto_col = gtk_tree_view_column_new_with_attributes(titles[0], proto_rend, "active", 0, NULL);
  gtk_tree_view_column_set_sort_column_id(proto_col, 0);
  g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
  gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);

  proto_rend = gtk_cell_renderer_text_new();
  proto_col = gtk_tree_view_column_new_with_attributes(titles[1], proto_rend, "text", 1, NULL);
  gtk_tree_view_column_set_sort_column_id(proto_col, 1);
  g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
  gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);

  proto_rend = gtk_cell_renderer_text_new();
  proto_col = gtk_tree_view_column_new_with_attributes(titles[2], proto_rend, "text", 2, NULL);
  gtk_tree_view_column_set_sort_column_id(proto_col, 2);
  g_signal_connect(proto_col, "clicked", G_CALLBACK(proto_col_clicked_cb), proto_list);
  gtk_tree_view_append_column(GTK_TREE_VIEW(proto_list), proto_col);

  gtk_tree_view_set_search_column(GTK_TREE_VIEW(proto_list), 1); /* col 1 in the *model* */
  g_object_unref(G_OBJECT(proto_store));
  gtk_widget_show(proto_list);

  label = gtk_label_new("Disabling a heuristic dissector prevents higher "
			"layer protocols from being displayed");
  gtk_misc_set_alignment(GTK_MISC(label), 0.5f, 0.5f);
  gtk_widget_show(label);
  gtk_box_pack_start(GTK_BOX(proto_vb), label, FALSE, FALSE, 5);

  bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
  gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
  gtk_box_set_spacing(GTK_BOX(bbox), 5);
  gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
  gtk_widget_show(bbox);

  /* Enable All */
  button = gtk_button_new_with_label("Enable All");
  g_signal_connect(button, "clicked", G_CALLBACK(enable_all_cb), proto_list);
  gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
  gtk_widget_show(button);

  /* Disable All */
  button = gtk_button_new_with_label("Disable All");
  g_signal_connect(button, "clicked", G_CALLBACK(disable_all_cb), proto_list);
  gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
  gtk_widget_show(button);

  /* Invert */
  button = gtk_button_new_with_label("Invert");
  g_signal_connect(button, "clicked", G_CALLBACK(toggle_all_cb), proto_list);
  gtk_box_pack_start(GTK_BOX(bbox), button, TRUE, TRUE, 0);
  gtk_widget_show(button);


  /* Button row */
  bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_APPLY, GTK_STOCK_SAVE, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
  gtk_box_pack_start(GTK_BOX(proto_vb), bbox, FALSE, FALSE, 0);
  gtk_widget_show(bbox);

  ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
  /*g_signal_connect(ok_bt, "clicked", G_CALLBACK(proto_ok_cb), proto_w);*/
  gtk_widget_grab_default(ok_bt);

  /*apply_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_APPLY);*/
 /* g_signal_connect(apply_bt, "clicked", G_CALLBACK(proto_apply_cb), proto_w);*/

  save_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_SAVE);
 /* g_signal_connect(save_bt, "clicked", G_CALLBACK(proto_save_cb), proto_w);*/

  cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
  window_set_cancel_button(proto_w, cancel_bt, proto_cancel_cb);

  /*help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);*/
  /*g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_ENABLED_PROTOCOLS_DIALOG);*/

  /*g_signal_connect(proto_w, "delete_event", G_CALLBACK(proto_delete_event_cb), NULL);*/
  g_signal_connect(proto_w, "destroy", G_CALLBACK(heur_proto_destroy_cb), NULL);

  gtk_widget_show(proto_w);

  gtk_widget_grab_focus(proto_list); /* XXX: force focus to the tree_view. This hack req'd so "type-ahead find"
                                      *  will be effective after the window is displayed. The issue is
                                      *  that any call to gtk_tree_view_column_set_sort_column_id above
                                      *  apparently sets the focus to the column header button and thus
                                      *  type-ahead find is, in effect, disabled on the column.
                                      *  Also required: a grab_focus whenever the column header is
                                      *  clicked to change the column sort order since the click
                                      *  also changes the focus to the column header button.
                                      *  Is there a better way to do this ?
                                      */

  /* hide the Save button if the user uses implicit save */
  if(!prefs.gui_use_pref_save) {
    gtk_widget_hide(save_bt);
  }

  return proto_vb;

}
示例#18
0
static void
ifopts_edit_cb(GtkWidget *w, gpointer data _U_)
{
	GtkWidget	  *ifopts_edit_dlg, *cur_scr_win, *main_hb, *main_tb,
			  *cur_opts_fr, *ed_opts_fr, *main_vb,
			  *if_descr_lb,
			  *if_hide_lb,
			  *bbox, *ok_bt, *cancel_bt, *help_bt;

	GtkListStore	  *list_store;
	GtkWidget	  *list;
	GtkTreeViewColumn *column;
	GtkCellRenderer   *renderer;
 	GtkTreeView       *list_view;
	GtkTreeSelection  *selection;

	int row = 0;

	GtkWidget   *caller   = gtk_widget_get_toplevel(w);

	/* Has an edit dialog box already been opened for that top-level
	   widget? */
	ifopts_edit_dlg = g_object_get_data(G_OBJECT(caller), IFOPTS_DIALOG_PTR_KEY);
	if (ifopts_edit_dlg != NULL) {
		/* Yes.  Just re-activate that dialog box. */
		reactivate_window(ifopts_edit_dlg);
		return;
	}

	/* create a new dialog */
	ifopts_edit_dlg = dlg_conf_window_new("Wireshark: Preferences: Interface Options");
	gtk_window_set_default_size(GTK_WINDOW(ifopts_edit_dlg), 1000, 440);

	main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);
	gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
	gtk_container_add(GTK_CONTAINER(ifopts_edit_dlg), main_vb);
	gtk_widget_show(main_vb);

	/* create current options frame */
	cur_opts_fr = gtk_frame_new("Interfaces");
	gtk_box_pack_start(GTK_BOX(main_vb), cur_opts_fr, TRUE, TRUE, 0);
	gtk_widget_show(cur_opts_fr);

	/* create a scrolled window to pack the current options TreeView widget into */
	cur_scr_win = scrolled_window_new(NULL, NULL);
	gtk_container_set_border_width(GTK_CONTAINER(cur_scr_win), 3);
	gtk_container_add(GTK_CONTAINER(cur_opts_fr), cur_scr_win);
	gtk_widget_show(cur_scr_win);

	/*
	 * Create current options TreeView.
	 */
	list_store = gtk_list_store_new(N_COLUMN,	/* Total number of columns XXX	*/
					G_TYPE_STRING,	/* Device			*/
					G_TYPE_STRING,	/* Description			*/
#ifdef HAVE_PCAP_CREATE
					G_TYPE_BOOLEAN,	/* Monitor mode		*/
#endif
					G_TYPE_STRING,	/* Default link-layer		*/
					G_TYPE_STRING,	/* Comment			*/
					G_TYPE_BOOLEAN,	/* Hide?			*/
					G_TYPE_INT);	/* Dlt 				*/

	list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));

	list_view = GTK_TREE_VIEW(list);

	/* The view now holds a reference.  We can get rid of our own reference */
	g_object_unref (G_OBJECT (list_store));

	/*
	 * Create the first column packet, associating the "text" attribute of the
	 * cell_renderer to the first column of the model
	 */
	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Device", renderer,
							   "text", DEVICE_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, TRUE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
#ifdef _WIN32
	gtk_tree_view_column_set_min_width(column, 230);
#else
	gtk_tree_view_column_set_min_width(column, 70);
#endif
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Description", renderer,
							   "text", DESC_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, TRUE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
	gtk_tree_view_column_set_min_width(column, 260);
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);

#ifdef HAVE_PCAP_CREATE
	/*
	 * XXX - for some reason, this doesn't show up.
	 */
	renderer = gtk_cell_renderer_toggle_new ();
	column = gtk_tree_view_column_new_with_attributes ("Default to monitor mode", renderer,
							   "active", DEF_MONITOR_MODE_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, FALSE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);
#endif

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Default link-layer", renderer,
							   "text", DEF_LINK_LAYER_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, TRUE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
	gtk_tree_view_column_set_min_width(column, 230);
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);

	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Comment", renderer,
							   "text", COMMENT_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, TRUE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
	gtk_tree_view_column_set_min_width(column, 100);
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);

	renderer = gtk_cell_renderer_toggle_new ();
	column = gtk_tree_view_column_new_with_attributes ("Hide?", renderer,
							   "active", HIDE_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, FALSE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);

#if 0
	/* Don't show the DLT column */
	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("DLT", renderer,
							   "text", DLT_COLUMN,
							   NULL);

	gtk_tree_view_column_set_resizable(column, TRUE);
	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
	gtk_tree_view_column_set_min_width(column, 40);
	/* Add the column to the view. */
	gtk_tree_view_append_column (list_view, column);
#endif
	/* Setup the selection handler */
	selection = gtk_tree_view_get_selection(list_view);
	gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);

	cur_list = list;
	gtk_container_add(GTK_CONTAINER(cur_scr_win), cur_list);

	if_selection = selection;

	g_signal_connect (G_OBJECT (selection), "changed", /* select_row */
			  G_CALLBACK (ifopts_edit_ifsel_cb),
			  NULL);

	gtk_widget_show(cur_list);

	/* add interface names to cell */
	ifopts_if_liststore_add();

	/* create edit options frame */
	ed_opts_fr = gtk_frame_new("Properties");
	gtk_box_pack_start(GTK_BOX(main_vb), ed_opts_fr, FALSE, FALSE, 0);
	gtk_widget_show(ed_opts_fr);

	main_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE);
	gtk_container_set_border_width(GTK_CONTAINER(main_hb), 3);
	gtk_container_add(GTK_CONTAINER(ed_opts_fr), main_hb);
	gtk_widget_show(main_hb);

	/* table to hold description text entry and hide button */
	main_tb = gtk_table_new(IFOPTS_TABLE_ROWS, 4, FALSE);
	gtk_box_pack_start(GTK_BOX(main_hb), main_tb, TRUE, FALSE, 10);
	gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10);
	gtk_table_set_col_spacings(GTK_TABLE(main_tb), 10);
	gtk_widget_show(main_tb);

	if_dev_lb = gtk_label_new("Device:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_dev_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_dev_lb), 1.0f, 0.5f);
	gtk_widget_show(if_dev_lb);

	if_dev_lb = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_dev_lb, 1, 2, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_dev_lb), 0.0f, 0.5f);
	gtk_widget_show(if_dev_lb);
	row++;

	if_name_lb = gtk_label_new("Description:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_name_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_name_lb), 1.0f, 0.5f);
	gtk_widget_show(if_name_lb);

	if_name_lb = gtk_label_new("");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_name_lb, 1, 2, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_name_lb), 0.0f, 0.5f);
	gtk_widget_show(if_name_lb);
	row++;

#ifdef HAVE_PCAP_CREATE
	/* create "monitor mode" label and button */
	if_monitor_lb = gtk_label_new("Monitor mode:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_monitor_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_monitor_lb), 1.0f, 0.5f);
	gtk_widget_show(if_monitor_lb);

	if_monitor_cb = gtk_check_button_new();
	g_signal_connect(if_monitor_cb, "toggled", G_CALLBACK(ifopts_edit_monitor_changed_cb),
			cur_list);
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_monitor_cb, 1, 2, row, row+1);
	gtk_widget_show(if_monitor_cb);
        row++;
#endif

	if_linktype_lb = gtk_label_new("Default link-layer header type:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_linktype_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_linktype_lb), 1.0f, 0.5f);
	gtk_widget_show(if_linktype_lb);

	if_linktype_cb = gtk_combo_box_text_new();
	num_linktypes = 0;
	interfaces_info_nochange = FALSE;
	g_signal_connect(if_linktype_cb, "changed", G_CALLBACK(ifopts_edit_linktype_changed_cb),
			cur_list);
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_linktype_cb, 1, 2, row, row+1);
	gtk_widget_show(if_linktype_cb);
	row++;

	/* create interface description label and text entry */
	if_descr_lb = gtk_label_new("Comment:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_descr_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_descr_lb), 1.0f, 0.5f);
	gtk_widget_show(if_descr_lb);

	if_descr_te = gtk_entry_new();
	g_signal_connect(if_descr_te, "changed", G_CALLBACK(ifopts_edit_descr_changed_cb),
			cur_list);
	gtk_entry_set_max_length(GTK_ENTRY(if_descr_te), IFOPTS_MAX_DESCR_LEN);
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_descr_te, 1, 2, row, row+1);
	gtk_widget_show(if_descr_te);
	row++;

	/* create "hide interface" label and button */
	if_hide_lb = gtk_label_new("Hide interface?:");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_hide_lb, 0, 1, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_hide_lb), 1.0f, 0.5f);
	gtk_widget_show(if_hide_lb);

	if_hide_cb = gtk_check_button_new();
	g_signal_connect(if_hide_cb, "toggled", G_CALLBACK(ifopts_edit_hide_changed_cb),
			cur_list);
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_hide_cb, 1, 2, row, row+1);
	gtk_widget_show(if_hide_cb);

	if_default_if_lb = gtk_label_new("(Default interface cannot be hidden)");
	gtk_table_attach_defaults(GTK_TABLE(main_tb), if_default_if_lb, 1, 3, row, row+1);
	gtk_misc_set_alignment(GTK_MISC(if_default_if_lb), 0.15f, 0.5f);
	row++;

	/* button row: OK and Cancel buttons */
	bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
	gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
	gtk_widget_show(bbox);

	ok_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_OK);
	gtk_widget_set_tooltip_text(ok_bt, "Save changes and exit dialog");
	g_signal_connect(ok_bt, "clicked", G_CALLBACK(ifopts_edit_ok_cb), ifopts_edit_dlg);

	cancel_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CANCEL);
	gtk_widget_set_tooltip_text(cancel_bt, "Cancel and exit dialog");
        window_set_cancel_button(ifopts_edit_dlg, cancel_bt, window_cancel_button_cb);

	help_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
	g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb),
			 (gpointer)HELP_CAPTURE_INTERFACE_OPTIONS_DIALOG);
	gtk_widget_set_tooltip_text (help_bt, "Show topic specific help");

	gtk_widget_grab_default(ok_bt);

	g_signal_connect(ifopts_edit_dlg, "delete_event", G_CALLBACK(window_delete_event_cb),
                 NULL);
	/* Call a handler when we're destroyed, so we can inform
	   our caller, if any, that we've been destroyed. */
	g_signal_connect(ifopts_edit_dlg, "destroy", G_CALLBACK(ifopts_edit_destroy_cb), NULL);

	/* Set the key for the new dialog to point to our caller. */
	g_object_set_data(G_OBJECT(ifopts_edit_dlg), IFOPTS_CALLER_PTR_KEY, caller);
	/* Set the key for the caller to point to us */
	g_object_set_data(G_OBJECT(caller), IFOPTS_DIALOG_PTR_KEY, ifopts_edit_dlg);

	gtk_widget_show(ifopts_edit_dlg); /* triggers ifopts_edit_ifsel_cb() with the  */
                                          /*  "interfaces" TreeView first row selected */
	window_present(ifopts_edit_dlg);
}
示例#19
0
/*
 * Create and pop up the progress dialog; allocate a "progdlg_t"
 * and initialize it to contain all information the implementation
 * needs in order to manipulate the dialog, and return a pointer to
 * it.
 *
 * The first argument is the task to do, e.g. "Loading".
 * The second argument is the item to do, e.g. "capture.cap".
 * The third argument is TRUE if the "terminate this operation" button should
 * be a "Stop" button (meaning that the operation is stopped, but not undone),
 * and FALSE if it should be a "Cancel" button (meaning that it's stopped
 * and anything it's done would be undone)
 * The fourth argument is a pointer to a Boolean variable that will be
 *   set to TRUE if the user hits that button.
 *
 * XXX - provide a way to specify the progress in units, with the total
 * number of units specified as an argument when the progress dialog
 * is created; updates would be given in units, with the progress dialog
 * code computing the percentage, and the progress bar would have a
 * label "0" on the left and <total number of units> on the right, with
 * a label in the middle giving the number of units we've processed
 * so far.  This could be used when filtering packets, for example; we
 * wouldn't always use it, as we have no idea how many packets are to
 * be read.
 */
progdlg_t *
create_progress_dlg(const gchar *task_title, const gchar *item_title,
                    gboolean terminate_is_stop, gboolean *stop_flag)
{
    progdlg_t *dlg;
    GtkWidget *dlg_w, *main_vb, *title_lb, *status_lb, *elapsed_lb, *time_left_lb, *percentage_lb;
    GtkWidget *prog_bar, *bbox, *cancel_bt;
    GtkWidget *static_vb, *tmp_lb, *main_hb, *dynamic_vb, *percentage_hb;
    gchar     *task_title_dup;
    gchar     *item_title_dup;

    dlg = g_malloc(sizeof (progdlg_t));

    /* limit the item_title to some reasonable length */
    item_title_dup = g_strdup(item_title);
    if (strlen(item_title_dup) > 110) {
        g_strlcpy(&item_title_dup[100], "...", 4);
    }

    dlg->title = g_strdup_printf("%s: %s", task_title, item_title_dup);

    dlg_w = dlg_window_new(dlg->title);
    gtk_window_set_modal(GTK_WINDOW(dlg_w), TRUE);

    /*
     * Container for dialog widgets.
     */
    main_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);
    gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5);
    gtk_container_add(GTK_CONTAINER(dlg_w), main_vb);

    /*
     * Static labels (left dialog side, labels aligned to the right)
     */
    static_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);
    task_title_dup = g_strdup_printf ("%s:", task_title);
    tmp_lb = gtk_label_new(task_title_dup);
    gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0f, 0.0f);
    gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
    tmp_lb = gtk_label_new("Status:");
    gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0f, 0.0f);
    gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
    tmp_lb = gtk_label_new("Elapsed Time:");
    gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0f, 0.0f);
    gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
    tmp_lb = gtk_label_new("Time Left:");
    gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0f, 0.0f);
    gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);
    tmp_lb = gtk_label_new("Progress:");
    gtk_misc_set_alignment(GTK_MISC(tmp_lb), 1.0f, 0.0f);
    gtk_box_pack_start(GTK_BOX(static_vb), tmp_lb, FALSE, TRUE, 3);


    /*
     * Dynamic labels (right dialog side, labels aligned to the left)
     */
    dynamic_vb = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, 1, FALSE);

    /*
     * Put the item_title here as a label indicating what we're
     * doing; set its alignment and padding so it's aligned on the
     * left.
     */
    title_lb = gtk_label_new(item_title_dup);
    gtk_box_pack_start(GTK_BOX(dynamic_vb), title_lb, FALSE, TRUE, 3);
    gtk_misc_set_alignment(GTK_MISC(title_lb), 0.0f, 0.0f);
    gtk_misc_set_padding(GTK_MISC(title_lb), 0, 0);

    /* same for "Status" */
    status_lb = gtk_label_new("");
    gtk_box_pack_start(GTK_BOX(dynamic_vb), status_lb, FALSE, TRUE, 3);
    gtk_misc_set_alignment(GTK_MISC(status_lb), 0.0f, 0.0f);
    gtk_misc_set_padding(GTK_MISC(status_lb), 0, 0);
    dlg->status_lb = (GtkLabel *) status_lb;

    /* same for "Elapsed Time" */
    elapsed_lb = gtk_label_new("00:00");
    gtk_box_pack_start(GTK_BOX(dynamic_vb), elapsed_lb, FALSE, TRUE, 3);
    gtk_misc_set_alignment(GTK_MISC(elapsed_lb), 0.0f, 0.0f);
    gtk_misc_set_padding(GTK_MISC(elapsed_lb), 0, 0);
    dlg->elapsed_lb = (GtkLabel *) elapsed_lb;

    /* same for "Time Left" */
    time_left_lb = gtk_label_new("--:--");
    gtk_box_pack_start(GTK_BOX(dynamic_vb), time_left_lb, FALSE, TRUE, 3);
    gtk_misc_set_alignment(GTK_MISC(time_left_lb), 0.0f, 0.0f);
    gtk_misc_set_padding(GTK_MISC(time_left_lb), 0, 0);
    dlg->time_left_lb = (GtkLabel *) time_left_lb;

    /*
     * The progress bar (in its own horizontal box, including
     * percentage value)
     */
    percentage_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1, FALSE);
    gtk_box_pack_start(GTK_BOX(dynamic_vb), percentage_hb, FALSE, TRUE, 3);

    prog_bar = gtk_progress_bar_new();
    gtk_box_pack_start(GTK_BOX(percentage_hb), prog_bar, FALSE, TRUE, 3);

    percentage_lb = gtk_label_new("  0%");
    gtk_misc_set_alignment(GTK_MISC(percentage_lb), 0.0f, 0.0f);
    gtk_box_pack_start(GTK_BOX(percentage_hb), percentage_lb, FALSE, TRUE, 3);
    dlg->percentage_lb = (GtkLabel *) percentage_lb;

    /*
     * Attach a pointer to the progress bar widget to the top-level widget.
     */
    g_object_set_data(G_OBJECT(dlg_w), PROG_BAR_KEY, prog_bar);

    /*
     * Static and dynamic boxes are now complete
     */
    main_hb = ws_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1, FALSE);
    gtk_box_pack_start(GTK_BOX(main_hb), static_vb, FALSE, TRUE, 3);
    gtk_box_pack_start(GTK_BOX(main_hb), dynamic_vb, FALSE, TRUE, 3);
    gtk_box_pack_start(GTK_BOX(main_vb), main_hb, FALSE, TRUE, 3);

    /* Button row */
    bbox = dlg_button_row_new(terminate_is_stop ? GTK_STOCK_STOP :
                              GTK_STOCK_CANCEL, NULL);
    gtk_container_add(GTK_CONTAINER(main_vb), bbox);
    gtk_widget_show(bbox);

    cancel_bt = g_object_get_data(G_OBJECT(bbox), terminate_is_stop ? GTK_STOCK_STOP :
                                GTK_STOCK_CANCEL);
    gtk_widget_grab_default(cancel_bt);

    /*
     * Allow user to either click the "Cancel"/"Stop" button, or
     * the close button on the window, to stop an operation in
     * progress.
     */
    g_signal_connect(cancel_bt, "clicked", G_CALLBACK(stop_cb), stop_flag);
    g_signal_connect(dlg_w, "delete_event", G_CALLBACK(delete_event_cb), stop_flag);

    gtk_widget_show_all(dlg_w);

    dlg->dlg_w = dlg_w;

    g_get_current_time(&dlg->start_time);
    memset(&dlg->last_time, 0, sizeof(dlg->last_time));

    g_free(task_title_dup);
    g_free(item_title_dup);

    return dlg;
}