2012-02-12 14:56:06 +00:00
|
|
|
/* edit_packet_comment_dlg.c
|
|
|
|
* Dialog box for editing or adding packet comments.
|
2012-02-13 17:33:05 +00:00
|
|
|
* Copyright 2012 Anders Broman <anders.broman@ericsson.com>
|
2012-02-12 14:56:06 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-02-12 14:56:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2012-02-29 16:51:32 +00:00
|
|
|
|
2012-09-24 19:30:23 +00:00
|
|
|
#include "ui/main_statusbar.h"
|
2012-02-12 14:56:06 +00:00
|
|
|
|
|
|
|
#include "ui/gtk/dlg_utils.h"
|
2012-09-10 19:48:16 +00:00
|
|
|
#include "ui/gtk/expert_comp_dlg.h"
|
2012-02-12 14:56:06 +00:00
|
|
|
#include "ui/gtk/gui_utils.h"
|
|
|
|
#include "ui/gtk/main.h"
|
2012-09-04 01:57:36 +00:00
|
|
|
#include "ui/gtk/packet_list.h"
|
2012-02-12 14:56:06 +00:00
|
|
|
#include "ui/gtk/edit_packet_comment_dlg.h"
|
|
|
|
|
2012-03-01 15:57:39 +00:00
|
|
|
static GtkWidget *edit_or_add_pkt_comment_dlg = NULL;
|
|
|
|
static GtkWidget *edit_or_add_capture_comment_dlg = NULL;
|
2012-02-12 14:56:06 +00:00
|
|
|
|
2012-02-13 17:33:05 +00:00
|
|
|
static void
|
2012-03-07 23:04:15 +00:00
|
|
|
pkt_comment_text_buff_ok_cb(GtkWidget *w _U_, GtkWidget *view)
|
2012-02-13 17:33:05 +00:00
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter start_iter;
|
|
|
|
GtkTextIter end_iter;
|
2012-12-22 21:14:13 +00:00
|
|
|
gchar *new_packet_comment;
|
2012-02-13 17:33:05 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-03-07 22:19:06 +00:00
|
|
|
new_packet_comment = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE /* whether to include invisible text */);
|
2012-02-13 17:33:05 +00:00
|
|
|
|
|
|
|
/*g_warning("The new comment is '%s'",new_packet_comment);*/
|
|
|
|
|
2012-09-04 02:35:25 +00:00
|
|
|
packet_list_update_packet_comment(new_packet_comment);
|
2012-09-10 19:48:16 +00:00
|
|
|
expert_comp_packet_comment_updated();
|
2013-06-19 23:37:38 +00:00
|
|
|
status_expert_update();
|
2012-02-13 17:33:05 +00:00
|
|
|
|
2012-03-07 22:38:02 +00:00
|
|
|
window_destroy(edit_or_add_pkt_comment_dlg);
|
2012-02-13 17:33:05 +00:00
|
|
|
|
|
|
|
}
|
2012-02-12 14:56:06 +00:00
|
|
|
|
2012-02-29 16:51:32 +00:00
|
|
|
|
|
|
|
static void
|
2012-03-07 23:04:15 +00:00
|
|
|
capture_comment_text_buff_ok_cb(GtkWidget *w _U_, GtkWidget *view)
|
2012-02-29 16:51:32 +00:00
|
|
|
{
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkTextIter start_iter;
|
|
|
|
GtkTextIter end_iter;
|
2012-12-22 21:14:13 +00:00
|
|
|
gchar *new_capture_comment;
|
2012-02-29 16:51:32 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-03-07 22:19:06 +00:00
|
|
|
new_capture_comment = gtk_text_buffer_get_text (buffer, &start_iter, &end_iter, FALSE /* whether to include invisible text */);
|
2012-02-29 16:51:32 +00:00
|
|
|
|
|
|
|
/*g_warning("The new comment is '%s'",new_capture_comment);*/
|
|
|
|
cf_update_capture_comment(&cfile, new_capture_comment);
|
|
|
|
|
2012-06-04 02:24:42 +00:00
|
|
|
/* Update the main window as appropriate */
|
|
|
|
main_update_for_unsaved_changes(&cfile);
|
2012-03-07 22:19:06 +00:00
|
|
|
|
2012-09-24 19:30:23 +00:00
|
|
|
status_capture_comment_update();
|
|
|
|
|
2012-03-07 22:38:02 +00:00
|
|
|
window_destroy(edit_or_add_capture_comment_dlg);
|
2012-02-29 16:51:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 14:34:20 +00:00
|
|
|
|
2012-02-12 14:56:06 +00:00
|
|
|
void
|
2012-02-12 23:09:14 +00:00
|
|
|
edit_packet_comment_dlg (GtkAction *action _U_, gpointer data _U_)
|
2012-02-12 14:56:06 +00:00
|
|
|
{
|
|
|
|
|
2012-02-12 21:15:11 +00:00
|
|
|
GtkWidget *vbox;
|
2012-02-12 15:48:57 +00:00
|
|
|
GtkWidget *view;
|
2012-09-03 17:56:24 +00:00
|
|
|
GtkWidget *scroll;
|
2012-02-12 21:15:11 +00:00
|
|
|
GtkWidget *bbox;
|
2012-05-24 21:38:22 +00:00
|
|
|
GtkWidget *ok_bt, *cancel_bt, *help_bt;
|
2012-12-22 21:14:13 +00:00
|
|
|
GtkTextBuffer *buffer;
|
2013-08-01 20:59:38 +00:00
|
|
|
gchar *opt_comment;
|
2012-02-12 14:56:06 +00:00
|
|
|
|
2012-02-28 06:05:32 +00:00
|
|
|
edit_or_add_pkt_comment_dlg = dlg_window_new ("Edit or Add Packet Comments");
|
2012-02-29 16:51:32 +00:00
|
|
|
gtk_widget_set_size_request (edit_or_add_pkt_comment_dlg, 500, 160);
|
2012-03-07 22:19:06 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (edit_or_add_pkt_comment_dlg), TRUE);
|
2012-03-08 01:24:31 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (edit_or_add_pkt_comment_dlg), DLG_OUTER_MARGIN);
|
2012-02-12 15:48:57 +00:00
|
|
|
|
2012-04-20 14:56:24 +00:00
|
|
|
vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, DLG_UNRELATED_SPACING, FALSE);
|
2012-02-12 21:15:11 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (edit_or_add_pkt_comment_dlg), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
2012-03-07 22:19:06 +00:00
|
|
|
|
2012-02-12 15:48:57 +00:00
|
|
|
view = gtk_text_view_new ();
|
2012-05-24 19:18:31 +00:00
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
|
2012-02-12 15:48:57 +00:00
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
2012-09-03 17:56:24 +00:00
|
|
|
gtk_widget_show (view);
|
|
|
|
|
|
|
|
scroll = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add(GTK_CONTAINER(scroll), view);
|
|
|
|
gtk_widget_show(scroll);
|
|
|
|
gtk_box_pack_start(GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
|
2012-02-12 16:18:25 +00:00
|
|
|
|
|
|
|
/* Get the comment */
|
2012-09-04 02:35:25 +00:00
|
|
|
opt_comment = packet_list_get_packet_comment();
|
2012-02-12 16:18:25 +00:00
|
|
|
/*g_warning("Fetched comment '%s'",opt_comment);*/
|
|
|
|
|
2012-02-12 21:15:11 +00:00
|
|
|
if(opt_comment){
|
2013-08-01 20:59:38 +00:00
|
|
|
gtk_text_buffer_set_text(buffer, opt_comment, -1);
|
|
|
|
g_free(opt_comment);
|
2012-02-12 21:15:11 +00:00
|
|
|
}
|
2012-02-12 15:48:57 +00:00
|
|
|
|
2012-02-12 21:15:11 +00:00
|
|
|
/* Button row. */
|
2012-05-24 21:38:22 +00:00
|
|
|
bbox = dlg_button_row_new (GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
|
2012-02-12 21:15:11 +00:00
|
|
|
gtk_box_pack_end (GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
|
|
|
|
2013-03-09 10:09:58 +00:00
|
|
|
ok_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_OK);
|
2012-03-07 23:04:15 +00:00
|
|
|
g_signal_connect (ok_bt, "clicked", G_CALLBACK(pkt_comment_text_buff_ok_cb), view);
|
|
|
|
gtk_widget_set_sensitive (ok_bt, TRUE);
|
2012-02-12 21:15:11 +00:00
|
|
|
|
2013-03-09 10:09:58 +00:00
|
|
|
cancel_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_CANCEL);
|
2012-03-07 23:04:15 +00:00
|
|
|
window_set_cancel_button (edit_or_add_pkt_comment_dlg, cancel_bt, window_cancel_button_cb);
|
2012-02-12 21:15:11 +00:00
|
|
|
|
2013-03-09 10:09:58 +00:00
|
|
|
help_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_HELP);
|
2012-03-01 16:03:42 +00:00
|
|
|
#if 0
|
2012-02-12 21:15:11 +00:00
|
|
|
g_signal_connect (help_bt, "clicked",/* G_CALLBACK(topic_cb)*/NULL, /*(gpointer)HELP_MANUAL_ADDR_RESOLVE_DIALOG*/NULL);
|
2012-03-01 16:03:42 +00:00
|
|
|
#endif
|
2012-02-13 17:33:05 +00:00
|
|
|
gtk_widget_set_sensitive (help_bt, FALSE);
|
2012-02-12 21:15:11 +00:00
|
|
|
|
2012-03-07 23:04:15 +00:00
|
|
|
gtk_widget_grab_default (ok_bt);
|
2012-02-12 21:15:11 +00:00
|
|
|
g_signal_connect (edit_or_add_pkt_comment_dlg, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
|
|
|
|
|
|
|
|
|
2012-02-12 15:48:57 +00:00
|
|
|
gtk_widget_show (edit_or_add_pkt_comment_dlg);
|
2012-11-26 16:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-29 16:51:32 +00:00
|
|
|
|
2012-03-01 15:57:39 +00:00
|
|
|
static void
|
|
|
|
edit_capture_comment_destroy_cb(GtkWidget *win _U_, gpointer user_data _U_)
|
|
|
|
{
|
|
|
|
/* Note that we no longer have an "Edit Capture Comment" dialog box. */
|
|
|
|
edit_or_add_capture_comment_dlg = NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-07 22:19:06 +00:00
|
|
|
void
|
2013-02-20 22:18:56 +00:00
|
|
|
edit_capture_comment_dlg_launch (void)
|
2012-02-29 16:51:32 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *view;
|
2012-09-03 17:56:24 +00:00
|
|
|
GtkWidget *scroll;
|
2012-02-29 16:51:32 +00:00
|
|
|
GtkWidget *bbox;
|
2012-05-24 21:38:22 +00:00
|
|
|
GtkWidget *ok_bt, *cancel_bt, *help_bt;
|
2012-02-29 16:51:32 +00:00
|
|
|
GtkTextBuffer *buffer = NULL;
|
|
|
|
const gchar *comment_str = NULL;
|
2012-05-24 18:11:55 +00:00
|
|
|
gchar *buf_str;
|
2012-02-29 16:51:32 +00:00
|
|
|
|
2012-03-01 15:57:39 +00:00
|
|
|
if (edit_or_add_capture_comment_dlg != NULL) {
|
|
|
|
/* There's already an "Edit Capture Comment" dialog box; reactivate it. */
|
|
|
|
reactivate_window(edit_or_add_capture_comment_dlg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-29 16:51:32 +00:00
|
|
|
edit_or_add_capture_comment_dlg = dlg_window_new ("Edit or Add Capture Comments");
|
|
|
|
gtk_widget_set_size_request (edit_or_add_capture_comment_dlg, 500, 160);
|
2012-03-07 22:19:06 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (edit_or_add_capture_comment_dlg), TRUE);
|
2012-03-08 01:24:31 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (edit_or_add_capture_comment_dlg), DLG_OUTER_MARGIN);
|
2012-02-29 16:51:32 +00:00
|
|
|
|
2012-03-01 15:57:39 +00:00
|
|
|
g_signal_connect(edit_or_add_capture_comment_dlg, "destroy",
|
|
|
|
G_CALLBACK(edit_capture_comment_destroy_cb), NULL);
|
|
|
|
|
2012-04-20 14:56:24 +00:00
|
|
|
vbox = ws_gtk_box_new(GTK_ORIENTATION_VERTICAL, DLG_UNRELATED_SPACING, FALSE);
|
2012-02-29 16:51:32 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (edit_or_add_capture_comment_dlg), vbox);
|
|
|
|
gtk_widget_show (vbox);
|
2012-03-07 22:19:06 +00:00
|
|
|
|
2012-02-29 16:51:32 +00:00
|
|
|
view = gtk_text_view_new ();
|
2012-05-24 21:35:41 +00:00
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
|
2012-02-29 16:51:32 +00:00
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
2012-09-03 17:56:24 +00:00
|
|
|
gtk_widget_show (view);
|
|
|
|
|
|
|
|
scroll = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add(GTK_CONTAINER(scroll), view);
|
|
|
|
gtk_widget_show(scroll);
|
|
|
|
gtk_box_pack_start(GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
|
2012-02-29 16:51:32 +00:00
|
|
|
|
|
|
|
/* Get the comment */
|
|
|
|
comment_str = cf_read_shb_comment(&cfile);
|
|
|
|
/*g_warning("Fetched comment '%s'",opt_comment);*/
|
|
|
|
|
|
|
|
if(comment_str != NULL){
|
2012-03-01 15:57:39 +00:00
|
|
|
buf_str = g_strdup_printf("%s", comment_str);
|
|
|
|
gtk_text_buffer_set_text (buffer, buf_str, -1);
|
2012-05-24 18:11:55 +00:00
|
|
|
g_free(buf_str);
|
2012-02-29 16:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Button row. */
|
2012-05-24 21:38:22 +00:00
|
|
|
bbox = dlg_button_row_new (GTK_STOCK_OK, GTK_STOCK_CANCEL, GTK_STOCK_HELP, NULL);
|
2012-02-29 16:51:32 +00:00
|
|
|
gtk_box_pack_end (GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
|
|
|
|
2013-03-09 10:09:58 +00:00
|
|
|
ok_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_OK);
|
2012-03-07 23:04:15 +00:00
|
|
|
g_signal_connect (ok_bt, "clicked", G_CALLBACK(capture_comment_text_buff_ok_cb), view);
|
|
|
|
gtk_widget_set_sensitive (ok_bt, TRUE);
|
2012-02-29 16:51:32 +00:00
|
|
|
|
2013-03-21 02:29:09 +00:00
|
|
|
cancel_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_CANCEL);
|
2012-03-07 23:04:15 +00:00
|
|
|
window_set_cancel_button (edit_or_add_capture_comment_dlg, cancel_bt, window_cancel_button_cb);
|
2012-02-29 16:51:32 +00:00
|
|
|
|
2013-03-09 10:09:58 +00:00
|
|
|
help_bt = (GtkWidget *)g_object_get_data (G_OBJECT(bbox), GTK_STOCK_HELP);
|
2012-03-01 16:03:42 +00:00
|
|
|
#if 0
|
2012-02-29 16:51:32 +00:00
|
|
|
g_signal_connect (help_bt, "clicked",/* G_CALLBACK(topic_cb)*/NULL, /*(gpointer)HELP_MANUAL_ADDR_RESOLVE_DIALOG*/NULL);
|
2012-03-01 16:03:42 +00:00
|
|
|
#endif
|
2012-02-29 16:51:32 +00:00
|
|
|
gtk_widget_set_sensitive (help_bt, FALSE);
|
|
|
|
|
2012-03-07 23:04:15 +00:00
|
|
|
gtk_widget_grab_default (ok_bt);
|
2012-02-29 16:51:32 +00:00
|
|
|
g_signal_connect (edit_or_add_capture_comment_dlg, "delete_event", G_CALLBACK(window_delete_event_cb), NULL);
|
|
|
|
|
|
|
|
|
|
|
|
gtk_widget_show (edit_or_add_capture_comment_dlg);
|
|
|
|
|
2012-03-28 23:54:50 +00:00
|
|
|
}
|
2014-02-25 20:42:35 +00:00
|
|
|
|
2013-02-20 22:08:00 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
edit_capture_comment_dlg_hide(void)
|
|
|
|
{
|
|
|
|
window_destroy(edit_or_add_capture_comment_dlg);
|
|
|
|
}
|
2015-02-15 18:58:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|