Make copy summary work for new_packet_list.

XXX The enum in .h file does not seem to work???

svn path=/trunk/; revision=29467
This commit is contained in:
Anders Broman 2009-08-18 14:40:51 +00:00
parent 43cbf13ad4
commit 3208870317
3 changed files with 78 additions and 3 deletions

View File

@ -88,7 +88,6 @@
#include "gtk/gui_stat_menu.h"
#include "gtk/main.h"
#include "gtk/menus.h"
#include "gtk/main_packet_list.h"
#include "gtk/main_toolbar.h"
#include "gtk/main_welcome.h"
#include "gtk/uat_gui.h"
@ -96,6 +95,8 @@
#ifdef NEW_PACKET_LIST
#include "gtk/new_packet_list.h"
#else
#include "gtk/main_packet_list.h"
#endif
#ifdef HAVE_IGE_MAC_INTEGRATION
@ -938,7 +939,11 @@ static GtkItemFactoryEntry packet_list_menu_items[] =
{"/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
{"/Copy", NULL, NULL, 0, "<Branch>", NULL,},
#ifndef NEW_PACKET_LIST
#ifdef NEW_PACKET_LIST
{"/Copy/Summary (Text)", NULL, GTK_MENU_FUNC(new_packet_list_copy_summary_cb), CS_TEXT, NULL, NULL,},
{"/Copy/Summary (CSV)", NULL, GTK_MENU_FUNC(new_packet_list_copy_summary_cb), CS_CSV, NULL, NULL,},
{"/Copy/<separator>", NULL, NULL, 0, "<Separator>", NULL,},
#else
{"/Copy/Summary (Text)", NULL, GTK_MENU_FUNC(packet_list_copy_summary_cb), CS_TEXT, NULL, NULL,},
{"/Copy/Summary (CSV)", NULL, GTK_MENU_FUNC(packet_list_copy_summary_cb), CS_CSV, NULL, NULL,},
{"/Copy/<separator>", NULL, NULL, 0, "<Separator>", NULL,},

View File

@ -39,6 +39,7 @@
#include "gui_utils.h"
#include "packet_list_store.h"
#include "gtk/new_packet_list.h"
#include "epan/column_info.h"
#include "epan/prefs.h"
#include <epan/packet.h>
@ -793,6 +794,62 @@ filter_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data _U_)
return FALSE;
}
static gboolean
get_col_text_from_record( PacketListRecord *record, gint col_num, gchar** cell_text){
if (col_based_on_frame_data(&cfile.cinfo, col_num)) {
col_fill_in_frame_data(record->fdata, &cfile.cinfo, col_num);
*cell_text = g_strdup(cfile.cinfo.col_data[col_num]);
}else
*cell_text = g_strdup(record->col_text[col_num]);
return TRUE;
}
/* XXX fore some reason this does not work in th .h file XXX*/
/* Different modes of copying summary data */
typedef enum {
CS_TEXT, /* Packet summary data (tab separated) */
CS_CSV /* Packet summary data (comma separated) */
} copy_summary_type;
void
new_packet_list_copy_summary_cb(GtkWidget * w _U_, gpointer data _U_, gint copy_type)
{
gint col;
gchar *celltext;
GString* text;
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(packetlist->view));
GtkTreeSelection *selection;
GtkTreeIter iter;
PacketListRecord *record;
if(CS_CSV == copy_type) {
text = g_string_new("\"");
} else {
text = g_string_new("");
}
if (cfile.current_frame) {
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(packetlist->view));
gtk_tree_selection_get_selected(selection, NULL, &iter);
record = new_packet_list_get_record(model, &iter);
for(col = 0; col < cfile.cinfo.num_cols; ++col) {
if(col != 0) {
if(CS_CSV == copy_type) {
g_string_append(text,"\",\"");
} else {
g_string_append_c(text, '\t');
}
}
if(get_col_text_from_record( record, col, &celltext))
g_string_append(text,celltext);
}
if(CS_CSV == copy_type) {
g_string_append_c(text,'"');
}
copy_to_clipboard(text);
}
g_string_free(text,TRUE);
}
#endif /* NEW_PACKET_LIST */

View File

@ -26,7 +26,6 @@
#define __NEW_PACKET_LIST_H__
#ifdef NEW_PACKET_LIST
#include <gtk/gtk.h>
GtkWidget *new_packet_list_create(void);
@ -49,6 +48,20 @@ extern void new_packet_list_mark_frame_cb(GtkWidget *widget, gpointer data);
void new_packet_list_mark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_);
void new_packet_list_unmark_all_frames_cb(GtkWidget *w _U_, gpointer data _U_);
/* Different modes of copying summary data */
typedef enum {
CS_TEXT, /* Packet summary data (tab separated) */
CS_CSV /* Packet summary data (comma separated) */
} copy_summary_type;
/** Called when user clicks on menu item to copy summary data.
*
* @param w Not used.
* @param data Not used.
* @param copy_type Mode in which to copy data (e.g. tab-separated, CSV)
*/
void new_packet_list_copy_summary_cb(GtkWidget * w _U_, gpointer data _U_, copy_summary_type copy_type);
#endif /* NEW_PACKET_LIST */
#endif /* __NEW_PACKET_LIST_H__ */