Commit 0680e22f authored by winckel's avatar winckel
Browse files

Added buttons, menu items and calback functions to open and save messages files.

Added menu items and calback functions to open and save filters files.
By default, the signal list tree view show the last received signals, this can be stop by selecting manually another signal (not the last one).
Removed the "new" button, the signals list is cleared before each new aquisition or when opening a messages file becausethe signal list may not be compatible between to list of signals!
Enabled column header clicks and created callback functions to display and modify column filters.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4316 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 4c01f4f7
......@@ -9,6 +9,7 @@
#include "ui_notif_dlg.h"
#include "ui_main_screen.h"
#include "ui_menu_bar.h"
#include "ui_callbacks.h"
#include "ui_interface.h"
#include "ui_notifications.h"
......@@ -21,45 +22,59 @@
static gboolean ui_handle_socket_connection_failed(gint fd);
gboolean ui_callback_on_open(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_on_open_messages(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Open event occurred");
CHECK_FCT(ui_file_chooser());
g_debug("Open replay event occurred");
CHECK_FCT(ui_messages_open_file_chooser());
return TRUE;
}
gboolean ui_callback_on_save_messages(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Save replay event occurred");
// CHECK_FCT(ui_file_chooser());
return TRUE;
}
gboolean ui_callback_on_open_filters(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Open filters event occurred");
CHECK_FCT(ui_filters_open_file_chooser());
return TRUE;
}
gboolean ui_callback_on_save_filters(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("Save filters event occurred");
CHECK_FCT(ui_filters_save_file_chooser());
return TRUE;
}
gboolean ui_callback_on_about(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_on_about(GtkWidget *widget, GdkEvent *event, gpointer data)
{
return TRUE;
}
gboolean
ui_callback_on_select_signal(GtkTreeSelection *selection,
GtkTreeModel *model,
GtkTreePath *path,
gboolean path_currently_selected,
gpointer user_data)
gboolean ui_callback_on_select_signal(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path,
gboolean path_currently_selected, gpointer user_data)
{
ui_text_view_t *text_view;
GtkTreeIter iter;
text_view = (ui_text_view_t *)user_data;
text_view = (ui_text_view_t *) user_data;
g_assert(text_view != NULL);
if (gtk_tree_model_get_iter(model, &iter, path))
if (gtk_tree_model_get_iter (model, &iter, path))
{
GValue buffer_store = G_VALUE_INIT;
gpointer buffer;
gtk_tree_model_get_value(model, &iter, COL_BUFFER, &buffer_store);
gtk_tree_model_get_value (model, &iter, COL_BUFFER, &buffer_store);
buffer = g_value_get_pointer(&buffer_store);
buffer = g_value_get_pointer (&buffer_store);
if (!path_currently_selected)
{
......@@ -76,43 +91,47 @@ ui_callback_on_select_signal(GtkTreeSelection *selection,
void ui_signal_add_to_list(gpointer data, gpointer user_data)
{
buffer_t *signal_buffer;
GtkTreePath *path;
GtkTreeViewColumn *focus_column;
signal_buffer = (buffer_t *)data;
gtk_tree_view_get_cursor (GTK_TREE_VIEW(ui_main_data.signalslist), &path, &focus_column);
get_message_id(root, signal_buffer, &signal_buffer->message_id);
signal_buffer = (buffer_t *) data;
ui_tree_view_new_signal_ind(signal_buffer->message_number,
message_id_to_string(signal_buffer->message_id),
get_origin_task_id(signal_buffer),
get_destination_task_id(signal_buffer),
data);
get_message_id (root, signal_buffer, &signal_buffer->message_id);
ui_tree_view_new_signal_ind (signal_buffer->message_number, message_id_to_string (signal_buffer->message_id),
get_origin_task_id (signal_buffer), get_destination_task_id (signal_buffer), data);
/* Increment number of messages */
ui_main_data.nb_message_received++;
/* Check if no signal was selected in the list or if it was the last signal */
if ((ui_main_data.path_last == NULL) || (gtk_tree_path_compare(ui_main_data.path_last, path) == 0))
{
/* Advance to the new last signal */
ui_callback_signal_go_to_last (NULL, NULL, NULL);
}
}
static gboolean ui_handle_update_signal_list(gint fd, void *data,
size_t data_length)
static gboolean ui_handle_update_signal_list(gint fd, void *data, size_t data_length)
{
pipe_new_signals_list_message_t *signal_list_message;
/* Enable buttons to move in the list of signals */
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_clear_button), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_button), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_last_button), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_first_button), TRUE);
ui_set_sensitive_move_buttons (TRUE);
signal_list_message = (pipe_new_signals_list_message_t *)data;
signal_list_message = (pipe_new_signals_list_message_t *) data;
g_assert(signal_list_message != NULL);
g_assert(signal_list_message->signal_list != NULL);
g_list_foreach(signal_list_message->signal_list, ui_signal_add_to_list, NULL);
g_list_foreach (signal_list_message->signal_list, ui_signal_add_to_list, NULL);
/* Free the list but not user data associated with each element */
g_list_free(signal_list_message->signal_list);
g_list_free (signal_list_message->signal_list);
/* Free the message */
free(signal_list_message);
free (signal_list_message);
return TRUE;
}
......@@ -121,17 +140,15 @@ static gboolean ui_handle_socket_connection_failed(gint fd)
{
GtkWidget *dialogbox;
dialogbox = gtk_message_dialog_new(GTK_WINDOW(ui_main_data.window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Failed to connect to provided host/ip address");
dialogbox = gtk_message_dialog_new (GTK_WINDOW(ui_main_data.window), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"Failed to connect to provided host/ip address");
gtk_dialog_run(GTK_DIALOG(dialogbox));
gtk_widget_destroy(dialogbox);
gtk_dialog_run (GTK_DIALOG(dialogbox));
gtk_widget_destroy (dialogbox);
/* Re-enable connect button */
ui_enable_connect_button();
ui_enable_connect_button ();
return TRUE;
}
......@@ -139,45 +156,42 @@ static gboolean ui_handle_socket_connection_lost(gint fd)
{
GtkWidget *dialogbox;
dialogbox = gtk_message_dialog_new(GTK_WINDOW(ui_main_data.window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Connection with remote host has been lost");
dialogbox = gtk_message_dialog_new (GTK_WINDOW(ui_main_data.window), GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"Connection with remote host has been lost");
gtk_dialog_run(GTK_DIALOG(dialogbox));
gtk_widget_destroy(dialogbox);
gtk_dialog_run (GTK_DIALOG(dialogbox));
gtk_widget_destroy (dialogbox);
/* Re-enable connect button */
ui_enable_connect_button();
ui_enable_connect_button ();
return TRUE;
}
static gboolean ui_handle_socket_xml_definition(gint fd, void *data,
size_t data_length)
static gboolean ui_handle_socket_xml_definition(gint fd, void *data, size_t data_length)
{
pipe_xml_definition_message_t *xml_definition_message;
xml_definition_message = (pipe_xml_definition_message_t *)data;
xml_definition_message = (pipe_xml_definition_message_t *) data;
g_assert(xml_definition_message != NULL);
g_assert(data_length == sizeof(pipe_xml_definition_message_t));
xml_parse_buffer(xml_definition_message->xml_definition,
xml_definition_message->xml_definition_length);
xml_parse_buffer (xml_definition_message->xml_definition, xml_definition_message->xml_definition_length);
free(data);
free (data);
return TRUE;
}
gboolean ui_pipe_callback(gint source, gpointer user_data)
{
void *input_data = NULL;
size_t input_data_length = 0;
pipe_input_header_t input_header;
void *input_data = NULL;
size_t input_data_length = 0;
pipe_input_header_t input_header;
/* Read the header */
if (read(source, &input_header, sizeof(input_header)) < 0) {
if (read (source, &input_header, sizeof(input_header)) < 0)
{
g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
return FALSE;
}
......@@ -185,24 +199,27 @@ gboolean ui_pipe_callback(gint source, gpointer user_data)
input_data_length = input_header.message_size - sizeof(input_header);
/* Checking for non-header part */
if (input_data_length > 0) {
input_data = malloc(input_data_length);
if (input_data_length > 0)
{
input_data = malloc (input_data_length);
if (read(source, input_data, input_data_length) < 0) {
if (read (source, input_data, input_data_length) < 0)
{
g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
return FALSE;
}
}
switch (input_header.message_type) {
switch (input_header.message_type)
{
case UI_PIPE_CONNECTION_FAILED:
return ui_handle_socket_connection_failed(source);
return ui_handle_socket_connection_failed (source);
case UI_PIPE_XML_DEFINITION:
return ui_handle_socket_xml_definition(source, input_data, input_data_length);
return ui_handle_socket_xml_definition (source, input_data, input_data_length);
case UI_PIPE_CONNECTION_LOST:
return ui_handle_socket_connection_lost(source);
return ui_handle_socket_connection_lost (source);
case UI_PIPE_UPDATE_SIGNAL_LIST:
return ui_handle_update_signal_list(source, input_data, input_data_length);
return ui_handle_update_signal_list (source, input_data, input_data_length);
default:
g_debug("[gui] Unhandled message type %u", input_header.message_type);
g_assert_not_reached();
......@@ -210,105 +227,108 @@ gboolean ui_pipe_callback(gint source, gpointer user_data)
return FALSE;
}
gboolean ui_callback_on_connect(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_on_connect(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
const char *ip;
uint16_t port;
int pipe_fd[2];
uint16_t port;
int pipe_fd[2];
g_debug("Connect event occurred");
port = atoi(gtk_entry_get_text(GTK_ENTRY(ui_main_data.portentry)));
ip = gtk_entry_get_text(GTK_ENTRY(ui_main_data.ipentry));
port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.portentry)));
ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ipentry));
if ((ip == NULL) || (port == 0)) {
if ((ip == NULL) || (port == 0))
{
g_warning("NULL parameter given for ip address or port = 0");
/* TODO: add dialog box here */
return FALSE;
}
ui_pipe_new(pipe_fd, ui_pipe_callback, NULL);
ui_pipe_new (pipe_fd, ui_pipe_callback, NULL);
memcpy(ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2);
memcpy (ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2);
/* Disable the connect button */
ui_disable_connect_button();
ui_disable_connect_button ();
/* Disable buttons to move in the list of signals */
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_clear_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_last_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_first_button), FALSE);
ui_tree_view_destroy_list(ui_main_data.signalslist);
if (socket_connect_to_remote_host(ip, port, pipe_fd[1]) != 0) {
ui_enable_connect_button();
ui_callback_signal_clear_list (widget, event, data);
if (socket_connect_to_remote_host (ip, port, pipe_fd[1]) != 0)
{
ui_enable_connect_button ();
return FALSE;
}
return TRUE;
}
gboolean ui_callback_on_disconnect(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_on_disconnect(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
g_debug("Disconnect event occurred");
ui_pipe_write_message(ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT,
NULL, 0);
ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0);
ui_enable_connect_button();
ui_enable_connect_button ();
return TRUE;
}
gboolean ui_callback_signal_go_to(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_signal_go_to(GtkWidget *widget, GdkEvent *event, gpointer data)
{
ui_tree_view_select_row (ui_main_data.nb_message_received / 2, NULL);
return TRUE;
}
gboolean ui_callback_signal_go_to_first(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_signal_go_to_first(GtkWidget *widget, GdkEvent *event, gpointer data)
{
ui_tree_view_select_row(0);
ui_tree_view_select_row (0, NULL);
return TRUE;
}
gboolean ui_callback_signal_go_to_last(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_signal_go_to_last(GtkWidget *widget, GdkEvent *event, gpointer data)
{
ui_tree_view_select_row(ui_main_data.nb_message_received - 1);
GtkTreePath *path;
ui_tree_view_select_row (ui_main_data.nb_message_received - 1, &path);
ui_main_data.path_last = path;
return TRUE;
}
gboolean ui_callback_signal_clear_list(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_signal_clear_list(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* Disable buttons to move in the list of signals */
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_clear_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_last_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_first_button), FALSE);
ui_set_sensitive_move_buttons (FALSE);
ui_tree_view_destroy_list(ui_main_data.signalslist);
/* Clear list of signals */
ui_tree_view_destroy_list (ui_main_data.signalslist);
return TRUE;
}
gboolean ui_callback_on_tree_view_select(GtkWidget *widget,
GdkEvent *event,
gpointer data)
gboolean ui_callback_on_tree_view_select(GtkWidget *widget, GdkEvent *event, gpointer data)
{
/* We have to retrieve the ip address and port of remote host */
g_debug("List selection event occurred");
return TRUE;
}
gboolean ui_callback_on_tree_column_header_click_signal(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("ui_callback_on_tree_column_header_click_signal\n");
return TRUE;
}
gboolean ui_callback_on_tree_column_header_click_from(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("ui_callback_on_tree_column_header_click_from\n");
return TRUE;
}
gboolean ui_callback_on_tree_column_header_click_to(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_debug("ui_callback_on_tree_column_header_click_to\n");
return TRUE;
}
#ifndef UI_CALLBACKS_H_
#define UI_CALLBACKS_H_
gboolean ui_callback_on_open(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_open_messages(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_save_messages(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_open_filters(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_save_filters(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_about(GtkWidget *widget,
GdkEvent *event,
......@@ -49,4 +61,16 @@ gboolean ui_callback_signal_clear_list(GtkWidget *widget,
gboolean ui_pipe_callback(gint source, gpointer user_data);
gboolean ui_callback_on_tree_column_header_click_signal(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_tree_column_header_click_from(GtkWidget *widget,
GdkEvent *event,
gpointer data);
gboolean ui_callback_on_tree_column_header_click_to(GtkWidget *widget,
GdkEvent *event,
gpointer data);
#endif /* UI_CALLBACKS_H_ */
......@@ -14,6 +14,9 @@ typedef struct {
/* Buttons */
GtkToolItem *open_replay_file;
GtkToolItem *save_replay_file;
GtkToolItem *open_filters_file;
GtkToolItem *save_filters_file;
GtkToolItem *connect;
GtkToolItem *disconnect;
......@@ -25,6 +28,7 @@ typedef struct {
GtkToolItem *signals_go_to_first_button;
GtkTreeSelection *selection;
GtkTreePath *path_last;
/* Nb of messages received */
guint nb_message_received;
......
......@@ -5,12 +5,24 @@
#include "ui_menu_bar.h"
#include "ui_callbacks.h"
void ui_set_sensitive_move_buttons(gboolean enable)
{
// gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_clear_button), enable);
// gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_button), enable);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_last_button), enable);
gtk_widget_set_sensitive(GTK_WIDGET(ui_main_data.signals_go_to_first_button), enable);
}
int ui_menu_bar_create(GtkWidget *vbox)
{
GtkWidget *menubar;
GtkWidget *filemenu, *helpmenu;
GtkWidget *file;
GtkWidget *help;
GtkWidget *open_messages;
GtkWidget *save_messages;
GtkWidget *open_filters;
GtkWidget *save_filters;
GtkWidget *quit;
GtkWidget *about;
......@@ -23,11 +35,19 @@ int ui_menu_bar_create(GtkWidget *vbox)
filemenu = gtk_menu_new();
file = gtk_menu_item_new_with_label("File");
open_messages = gtk_menu_item_new_with_label("Open messages file");
save_messages = gtk_menu_item_new_with_label("Save messages file");
open_filters = gtk_menu_item_new_with_label("Open filters file");
save_filters = gtk_menu_item_new_with_label("Save filters file");
quit = gtk_menu_item_new_with_label("Quit");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open_messages);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save_messages);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open_filters);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save_filters);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
/* Create the Help submenu */
......@@ -44,6 +64,18 @@ int ui_menu_bar_create(GtkWidget *vbox)
/* Add the menubar to the vbox */
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);
g_signal_connect(G_OBJECT(open_messages), "activate",
G_CALLBACK(ui_callback_on_open_messages), NULL);
g_signal_connect(G_OBJECT(save_messages), "activate",
G_CALLBACK(ui_callback_on_save_messages), NULL);
g_signal_connect(G_OBJECT(open_filters), "activate",
G_CALLBACK(ui_callback_on_open_filters), NULL);
g_signal_connect(G_OBJECT(save_filters), "activate",
G_CALLBACK(ui_callback_on_save_filters), NULL);
g_signal_connect(G_OBJECT(quit), "activate",
G_CALLBACK(gtk_main_quit), NULL);
......@@ -70,6 +102,7 @@ int ui_toolbar_create(GtkWidget *vbox)
gtk_container_set_border_width(GTK_CONTAINER(toolbar), 2);
#if 0 /* Not useful anymore, signals list is cleared before every new replay file opening or remote connection */
/* Button to clear signal list and clear signal dissect view */
{
ui_main_data.signals_clear_button = gtk_tool_button_new_from_stock(GTK_STOCK_NEW);
......@@ -83,18 +116,55 @@ int ui_toolbar_create(GtkWidget *vbox)
g_signal_connect(G_OBJECT(ui_main_data.signals_clear_button), "clicked",
G_CALLBACK(ui_callback_signal_clear_list), NULL);
}
#endif
/* Button to open replay file */
{
ui_main_data.open_replay_file = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.open_replay_file),
"Open new replay file");
"Open messages file");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ui_main_data.open_replay_file, -1);
g_signal_connect(G_OBJECT(ui_main_data.open_replay_file), "clicked",
G_CALLBACK(ui_callback_on_open), NULL);
G_CALLBACK(ui_callback_on_open_messages), NULL);
}
/* Button to save replay file */
{
ui_main_data.save_replay_file = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.save_replay_file),
"Save messages file");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ui_main_data.save_replay_file, -1);
g_signal_connect(G_OBJECT(ui_main_data.save_replay_file), "clicked",
G_CALLBACK(ui_callback_on_save_messages), NULL);
}
#if 0 /* Too much button in the bar, it is confusing ! */
/* Button to open filters file */
{
ui_main_data.open_filters_file = gtk_tool_button_new_from_stock(GTK_STOCK_OPEN);
gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.open_filters_file),
"Open filters file");
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ui_main_data.open_filters_file, -1);
g_signal_connect(G_OBJECT(ui_main_data.open_filters_file), "clicked",
G_CALLBACK(ui_callback_on_open_filters), NULL);
}
/* Button to save filters file */
{
ui_main_data.save_filters_file = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(ui_main_data.save_filters_file),
"Save filters file");