diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/main.c | 30 | ||||
-rw-r--r-- | gtk/main.h | 7 | ||||
-rw-r--r-- | gtk/menu.c | 9 | ||||
-rw-r--r-- | gtk/proto_draw.c | 43 | ||||
-rw-r--r-- | gtk/proto_draw.h | 2 |
5 files changed, 80 insertions, 11 deletions
diff --git a/gtk/main.c b/gtk/main.c index 5dd37998d9..c6335cb7e2 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -454,6 +454,36 @@ match_selected_plist_cb(GtkWidget *w _U_, gpointer data, MATCH_SELECTED_E action get_text_from_packet_list(data)); } +/* This function allows users to right click in the details window and copy the text + * information to the operating systems clipboard. + * + * We first check to see if a string representation is setup in the tree and then + * read the string. If not available then we try to grab the value. If all else + * fails we display a message to the user to indicate the copy could not be completed. + */ +void +copy_selected_plist_cb(GtkWidget *w _U_, gpointer data _U_) +{ + GString *gtk_text_str = g_string_new(""); + char labelstring[256]; + char *stringpointer = labelstring; + + if (cfile.finfo_selected->rep->representation != 0) { + g_string_sprintfa(gtk_text_str, "%s", cfile.finfo_selected->rep->representation); /* Get the represented data */ + } + if (gtk_text_str->len == 0) { /* If no representation then... */ + proto_item_fill_label(cfile.finfo_selected, stringpointer); /* Try to read the value */ + g_string_sprintfa(gtk_text_str, "%s", stringpointer); + } + if (gtk_text_str->len == 0) { /* Could not get item so display error msg */ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not acquire information to copy, try expanding or choosing another item"); + } + else + { + copy_to_clipboard(gtk_text_str); /* Copy string to clipboard */ + } + g_string_free(gtk_text_str, TRUE); /* Free the memory */ +} /* XXX: use a preference for this setting! */ diff --git a/gtk/main.h b/gtk/main.h index 6b279d7e98..7db0c64241 100644 --- a/gtk/main.h +++ b/gtk/main.h @@ -133,6 +133,13 @@ typedef enum { /** "bitwise or" this with MATCH_SELECTED_E value for instant apply instead of prepare only */ #define MATCH_SELECTED_APPLY_NOW 0x100 +/** User highlited item in details window and then right clicked and selected the copy option + * + * @param widget parent widget + * @param data parent widget + */ +extern void copy_selected_plist_cb(GtkWidget *w _U_, gpointer data); + /** User requested one of "Apply as Filter" or "Prepare a Filter" functions * by menu or context menu of protocol tree. * diff --git a/gtk/menu.c b/gtk/menu.c index 20b08ebc6b..1add529e5b 100644 --- a/gtk/menu.c +++ b/gtk/menu.c @@ -474,6 +474,10 @@ static GtkItemFactoryEntry packet_list_menu_items[] = static GtkItemFactoryEntry tree_view_menu_items[] = { + + ITEM_FACTORY_ENTRY("/Copy", NULL, copy_selected_plist_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/<separator>", NULL, NULL, 0, "<Separator>", NULL), + ITEM_FACTORY_ENTRY("/Expand Subtrees", NULL, expand_tree_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Expand All", NULL, expand_all_cb, 0, NULL, NULL), ITEM_FACTORY_ENTRY("/Collapse All", NULL, collapse_all_cb, 0, NULL, NULL), @@ -531,8 +535,11 @@ static GtkItemFactoryEntry tree_view_menu_items[] = static GtkItemFactoryEntry hexdump_menu_items[] = { - ITEM_FACTORY_ENTRY("/Copy", NULL, copy_hex_cb, + ITEM_FACTORY_ENTRY("/Copy", NULL, NULL, 0, "<Branch>", NULL), + ITEM_FACTORY_ENTRY("/Copy/...All Information", NULL, copy_hex_cb, 0, NULL, NULL), + ITEM_FACTORY_ENTRY("/Copy/...Text Only", NULL, copy_hex_cb, + 1, NULL, NULL), ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb, 0, NULL, NULL), }; diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c index 4080946fc6..ef4f466a90 100644 --- a/gtk/proto_draw.c +++ b/gtk/proto_draw.c @@ -806,7 +806,7 @@ savehex_dlg_destroy_cb(void) } void -copy_hex_cb(GtkWidget * w _U_, gpointer data _U_) +copy_hex_cb(GtkWidget * w _U_, gpointer data _U_, int data_type) { GtkWidget *bv; int len; @@ -814,6 +814,7 @@ copy_hex_cb(GtkWidget * w _U_, gpointer data _U_) const guint8 *data_p = NULL; GString *ASCII_representation = g_string_new(""); GString *byte_str = g_string_new(""); + GString *text_str = g_string_new(""); bv = get_notebook_bv_ptr(byte_nb_ptr); if (bv == NULL) { @@ -823,15 +824,31 @@ copy_hex_cb(GtkWidget * w _U_, gpointer data _U_) } data_p = get_byte_view_data_and_length(GTK_WIDGET(bv), &len); - - g_string_sprintfa(byte_str,"%04x ",i); /* Offset 0000 */ + + g_string_sprintfa(byte_str,"%04x ",i); /* Offset 0000 */ for (i=0; i<len; i++){ - g_string_sprintfa(ASCII_representation,"%c",isprint(*data_p) ? *data_p : '.'); - g_string_sprintfa(byte_str," %02x",*data_p++); - if ((i+1)%16==0 && i!=0){ - g_string_sprintfa(byte_str," %s\n%04x ",ASCII_representation->str,i+1); - g_string_assign (ASCII_representation,""); - } + if (data_type==1) { + if (isprint(*data_p)) { + g_string_sprintfa(ASCII_representation,"%c", *data_p); + } + else + { + if (*data_p==0x0a) { + g_string_sprintfa(ASCII_representation,"\n"); + } + } + } + else + { + g_string_sprintfa(ASCII_representation,"%c",isprint(*data_p) ? *data_p : '.'); + } + g_string_sprintfa(byte_str," %02x",*data_p++); + if ((i+1)%16==0 && i!=0){ + g_string_sprintfa(byte_str," %s\n%04x ",ASCII_representation->str,i+1); + g_string_sprintfa(text_str,"%s",ASCII_representation->str); + + g_string_assign (ASCII_representation,""); + } } if(ASCII_representation->len){ @@ -839,10 +856,18 @@ copy_hex_cb(GtkWidget * w _U_, gpointer data _U_) g_string_sprintfa(byte_str," "); } g_string_sprintfa(byte_str," %s\n",ASCII_representation->str); + g_string_sprintfa(text_str,"%s",ASCII_representation->str); } /* Now that we have the byte data, copy it into the default clipboard */ + if (data_type==1) { + copy_to_clipboard(text_str); + } + else + { copy_to_clipboard(byte_str); + } g_string_free(byte_str, TRUE); /* Free the memory */ + g_string_free(text_str, TRUE); /* Free the memory */ g_string_free(ASCII_representation, TRUE); /* Free the memory */ } diff --git a/gtk/proto_draw.h b/gtk/proto_draw.h index 7dd82ff6d0..3a3c5f09f2 100644 --- a/gtk/proto_draw.h +++ b/gtk/proto_draw.h @@ -114,7 +114,7 @@ extern void savehex_cb(GtkWidget * w, gpointer data); * @param w unused * @param data unused */ -extern void copy_hex_cb(GtkWidget * w, gpointer data); +extern void copy_hex_cb(GtkWidget * w, gpointer data, int data_type); #if GTK_MAJOR_VERSION < 2 /** Redraw a given byte view window. |