aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Broman <anders.broman@ericsson.com>2012-02-26 17:04:28 +0000
committerAnders Broman <anders.broman@ericsson.com>2012-02-26 17:04:28 +0000
commit38c69c84316d96ba5513e86a3745b02472730434 (patch)
treed596516237fe03a9ec7b96cd63c85f617768baa4
parente5a91c8632651e7959e2ab53fe98e2c53c935cb7 (diff)
Make it possible to edit capture comments
svn path=/trunk/; revision=41193
-rw-r--r--summary.c9
-rw-r--r--summary.h14
-rw-r--r--ui/gtk/summary_dlg.c81
-rw-r--r--wiretap/wtap.c7
-rw-r--r--wiretap/wtap.def1
-rw-r--r--wiretap/wtap.h1
6 files changed, 103 insertions, 10 deletions
diff --git a/summary.c b/summary.c
index 134106221b..bc4df8a2fc 100644
--- a/summary.c
+++ b/summary.c
@@ -220,3 +220,12 @@ summary_fill_in_capture(capture_file *cf,capture_options *capture_opts, summary_
}
}
#endif
+
+void
+summary_update_comment(capture_file *cf, gchar *comment)
+{
+
+ /* Get info from SHB */
+ wtap_write_shb_comment(cf->wth, comment);
+
+} \ No newline at end of file
diff --git a/summary.h b/summary.h
index 15a2aaaa9d..a1d062e6a1 100644
--- a/summary.h
+++ b/summary.h
@@ -61,19 +61,19 @@ typedef struct _summary_tally {
double filtered_start; /**< time in seconds, with msec resolution */
double filtered_stop; /**< time in seconds, with msec resolution */
const char *filename;
- gint64 file_length; /**< file length in bytes */
- int file_type; /**< wiretap file type */
- int encap_type; /**< wiretap encapsulation type */
+ gint64 file_length; /**< file length in bytes */
+ int file_type; /**< wiretap file type */
+ int encap_type; /**< wiretap encapsulation type */
gboolean has_snap; /**< TRUE if maximum capture packet length is known */
- int snap; /**< Maximum captured packet length */
- gboolean drops_known; /**< TRUE if number of packet drops is known */
+ int snap; /**< Maximum captured packet length */
+ gboolean drops_known; /**< TRUE if number of packet drops is known */
guint64 drops; /**< number of packet drops */
const char *dfilter; /**< display filter */
gboolean is_tempfile;
/* from SHB, use summary_fill_shb_inf() to get values */
gchar *opt_comment; /**< comment from SHB block */
gchar *shb_hardware; /**< Capture HW from SHB block */
- gchar *shb_os; /**< The OS the capture was made on from SHB block */
+ gchar *shb_os; /**< The OS the capture was made on from SHB block */
gchar *shb_user_appl; /**< The application that made the capture from SHB block */
/* capture related, use summary_fill_in_capture() to get values */
GArray *ifaces;
@@ -87,6 +87,8 @@ summary_fill_in(capture_file *cf, summary_tally *st);
extern void
summary_fill_in_capture(capture_file *cf, capture_options *capture_opts, summary_tally *st);
#endif
+extern void
+summary_update_comment(capture_file *cf, gchar *comment);
#endif /* summary.h */
diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c
index 944934af0a..0a303783ca 100644
--- a/ui/gtk/summary_dlg.c
+++ b/ui/gtk/summary_dlg.c
@@ -129,6 +129,36 @@ time_to_string(char *string_buff, gulong string_buff_size, time_t ti_time)
ti_tm->tm_sec);
}
+static void
+summary_comment_text_buff_save_cb(GtkWidget *w _U_, GtkWidget *view)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter start_iter;
+ GtkTextIter end_iter;
+ gchar *new_comment = NULL;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ gtk_text_buffer_get_start_iter (buffer, &start_iter);
+ gtk_text_buffer_get_end_iter (buffer, &end_iter);
+
+ new_comment = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE /* whether to include invisible text */);
+
+ /*g_warning("The new comment is '%s'",new_packet_comment);*/
+
+ summary_update_comment(&cfile, new_comment);
+
+}
+
+static void
+summary_comment_text_buff_clear_cb(GtkWidget *w _U_, GtkWidget *view)
+{
+ GtkTextBuffer *buffer;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ gtk_text_buffer_set_text (buffer, "", -1);
+
+}
+
void
summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
{
@@ -222,10 +252,53 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
add_string_to_table(table, &row, "Packet size limit:", string_buff);
}
- if (summary.opt_comment != NULL) {
- /* comment */
- add_string_to_table(table, &row, "Comment:", summary.opt_comment);
- }
+ /* Only allow editing of comment if filetype is PCAPNG */
+ if(summary.file_type == WTAP_FILE_PCAPNG){
+ GtkWidget *comment_vbox;
+ GtkWidget *view;
+ GtkTextBuffer *buffer = NULL;
+ const gchar *buf_str;
+ GtkWidget *save_bt, *clear_bt;
+
+ comment_vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (main_vb), comment_vbox);
+ gtk_widget_show (comment_vbox);
+
+ view = gtk_text_view_new ();
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ if(summary.opt_comment == NULL){
+ buf_str = g_strdup_printf("[None]");
+ }else{
+ buf_str = g_strdup_printf("%s", summary.opt_comment);
+ }
+ gtk_text_buffer_set_text (buffer, buf_str, -1);
+ gtk_container_add(GTK_CONTAINER(comment_vbox), view);
+ gtk_widget_show (view);
+
+ /* Button row. */
+ bbox = dlg_button_row_new (GTK_STOCK_SAVE, GTK_STOCK_CLEAR, NULL);
+ gtk_box_pack_end (GTK_BOX(comment_vbox), bbox, FALSE, FALSE, 0);
+
+ save_bt = g_object_get_data (G_OBJECT(bbox), GTK_STOCK_SAVE);
+ g_signal_connect (save_bt, "clicked", G_CALLBACK(summary_comment_text_buff_save_cb), view);
+ gtk_widget_set_sensitive (save_bt, TRUE);
+ gtk_widget_set_tooltip_text(save_bt,
+ "You need to save the the capture file as well to save the updated comment");
+
+
+ clear_bt = g_object_get_data(G_OBJECT(bbox), GTK_STOCK_CLEAR);
+ g_signal_connect(clear_bt, "clicked", G_CALLBACK(summary_comment_text_buff_clear_cb), view);
+ gtk_widget_set_tooltip_text(clear_bt,
+ "Clears the text from the box, not the capture");
+
+ gtk_widget_grab_default (save_bt);
+
+ }else{
+ if (summary.opt_comment != NULL) {
+ /* comment */
+ add_string_to_table(table, &row, "Comment:", summary.opt_comment);
+ }
+ }
/*
* We must have no un-time-stamped packets (i.e., the number of
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index 00c12f0191..7a6ee5ca48 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -112,6 +112,13 @@ wtapng_section_t* wtap_file_get_shb_info(wtap *wth)
return shb_hdr;
}
+void wtap_write_shb_comment(wtap *wth, gchar *comment)
+{
+ g_free(wth->shb_hdr.opt_comment);
+ wth->shb_hdr.opt_comment = comment;
+
+}
+
wtapng_iface_descriptions_t* wtap_file_get_idb_info(wtap *wth)
{
wtapng_iface_descriptions_t *idb_info;
diff --git a/wiretap/wtap.def b/wiretap/wtap.def
index 738e6e9074..c5f4b897f3 100644
--- a/wiretap/wtap.def
+++ b/wiretap/wtap.def
@@ -78,6 +78,7 @@ wtap_short_string_to_encap
wtap_short_string_to_file_type
wtap_snapshot_length
wtap_strerror
+wtap_write_shb_comment
wtap_wtap_encap_to_pcap_encap
diff --git a/wiretap/wtap.h b/wiretap/wtap.h
index 1f0a23baac..798bcae2d7 100644
--- a/wiretap/wtap.h
+++ b/wiretap/wtap.h
@@ -1036,6 +1036,7 @@ int wtap_file_encap(wtap *wth);
int wtap_file_tsprecision(wtap *wth);
wtapng_section_t* wtap_file_get_shb_info(wtap *wth);
wtapng_iface_descriptions_t *wtap_file_get_idb_info(wtap *wth);
+void wtap_write_shb_comment(wtap *wth, gchar *comment);
/*** close the current file ***/
void wtap_sequential_close(wtap *wth);