Make it possible to edit capture comments
authorAnders Broman <anders.broman@ericsson.com>
Sun, 26 Feb 2012 17:04:28 +0000 (17:04 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Sun, 26 Feb 2012 17:04:28 +0000 (17:04 -0000)
svn path=/trunk/; revision=41193

summary.c
summary.h
ui/gtk/summary_dlg.c
wiretap/wtap.c
wiretap/wtap.def
wiretap/wtap.h

index 134106221b188a97a94191ead6e55bf2227d5b8c..bc4df8a2fcd84e2805907b9435549e78876ee29d 100644 (file)
--- 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
index 15a2aaaa9db50c8079236a69cebd8869fb825568..a1d062e6a1fb9de725a126665c66e6637e877627 100644 (file)
--- 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 */
 
index 944934af0a016668a631fd35d225b7e2badec496..0a303783ca335c616222b8fe75799bf2b05f8b15 100644 (file)
@@ -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
index 00c12f0191958fa09c8d341626dde2e6bce085e5..7a6ee5ca48c5072b41883f5bc7bbf21b88034701 100644 (file)
@@ -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;
index 738e6e9074f5a673b1009bfeae496a1a9f798269..c5f4b897f3e8093610110d757b496ea58fc73fa7 100644 (file)
@@ -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
 
 
index 1f0a23baac1ee6d49078b1f4191bf6f6c8536c2f..798bcae2d767b894e5b6407660f60d0f3214646a 100644 (file)
@@ -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);