ui_callbacks.c 19.5 KB
Newer Older
1
2
3
4
#if HAVE_CONFIG_H
# include "config.h"
#endif

Cedric Roux's avatar
 
Cedric Roux committed
5
6
7
8
9
#include <stdlib.h>
#include <stdint.h>

#include <gtk/gtk.h>

10
#include "rc.h"
Cedric Roux's avatar
 
Cedric Roux committed
11

Cedric Roux's avatar
Cedric Roux committed
12
13
14
#include "socket.h"

#include "ui_notif_dlg.h"
Cedric Roux's avatar
 
Cedric Roux committed
15
#include "ui_main_screen.h"
16
#include "ui_menu_bar.h"
Cedric Roux's avatar
 
Cedric Roux committed
17
18
19
20
21
#include "ui_callbacks.h"
#include "ui_interface.h"
#include "ui_notifications.h"
#include "ui_tree_view.h"
#include "ui_signal_dissect_view.h"
winckel's avatar
winckel committed
22
#include "ui_filters.h"
Cedric Roux's avatar
 
Cedric Roux committed
23

Cedric Roux's avatar
Cedric Roux committed
24
25
26
27
#include "types.h"
#include "locate_root.h"
#include "xml_parse.h"

28
29
30
static gboolean refresh_message_list = TRUE;
static gboolean filters_changed = FALSE;

winckel's avatar
winckel committed
31
gboolean ui_callback_on_open_messages(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
32
{
winckel's avatar
winckel committed
33
34
    gboolean refresh = (data != NULL) ? TRUE : FALSE;

35
    g_message("Open messages event occurred %d", refresh);
winckel's avatar
winckel committed
36
37
38
39
40
41
42
43
44

    if (refresh && (ui_main_data.messages_file_name != NULL))
    {
        CHECK_FCT(ui_messages_read (ui_main_data.messages_file_name));
    }
    else
    {
        CHECK_FCT(ui_messages_open_file_chooser());
    }
45
46
47
48

    return TRUE;
}

winckel's avatar
winckel committed
49
gboolean ui_callback_on_save_messages(GtkWidget *widget, gpointer data)
50
{
51
    g_message("Save messages event occurred");
52
53
54
55
    // CHECK_FCT(ui_file_chooser());
    return TRUE;
}

56
gboolean ui_callback_on_filters_enabled(GtkToolButton *button, gpointer data)
57
58
59
60
{
    gboolean enabled;
    gboolean changed;

61
    enabled = gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON(button));
62

63
    g_debug("Filters enabled event occurred %d", enabled);
64

65
    changed = ui_filters_enable (enabled);
66
67
68

    if (changed)
    {
69
        /* Set the tool tip text */
70
71
        if (enabled)
        {
72
73
74
            gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM(button), "Disable messages filtering");
        }
        else
75
        {
76
            gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM(button), "Enable messages filtering");
77
        }
78
        ui_tree_view_refilter ();
79

80
        if (ui_main_data.messages_list != NULL)
81
82
83
        {
            GtkTreePath *path_row;

84
            /* Get the currently selected message */
85
            gtk_tree_view_get_cursor (GTK_TREE_VIEW(ui_main_data.messages_list), &path_row, NULL);
86
87
88
            if (path_row != NULL)
            {
                /* Center the message in the middle of the list if possible */
89
90
                gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(ui_main_data.messages_list), path_row, NULL, TRUE, 0.5,
                                              0.0);
91
            }
92
        }
93
94
95
96
97
    }

    return TRUE;
}

winckel's avatar
winckel committed
98
gboolean ui_callback_on_open_filters(GtkWidget *widget, gpointer data)
99
{
100
    g_message("Open filters event occurred");
101
102
103
104
    CHECK_FCT(ui_filters_open_file_chooser());
    return TRUE;
}

winckel's avatar
winckel committed
105
gboolean ui_callback_on_save_filters(GtkWidget *widget, gpointer data)
106
{
107
    g_message("Save filters event occurred");
108
    CHECK_FCT(ui_filters_save_file_chooser());
Cedric Roux's avatar
 
Cedric Roux committed
109
110
111
    return TRUE;
}

winckel's avatar
winckel committed
112
113
114
115
116
117
118
119
120
121
gboolean ui_callback_on_enable_filters(GtkWidget *widget, gpointer data)
{
    gboolean enabled;

    enabled = gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON(ui_main_data.filters_enabled));
    gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON(ui_main_data.filters_enabled), !enabled);

    return TRUE;
}

winckel's avatar
winckel committed
122
gboolean ui_callback_on_about(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
123
{
124
#if defined(PACKAGE_STRING)
125
    ui_notification_dialog (GTK_MESSAGE_INFO, "about", "Eurecom %s", PACKAGE_STRING);
126
#else
127
    ui_notification_dialog (GTK_MESSAGE_INFO, "about", "Eurecom itti_analyzer");
128
#endif
Cedric Roux's avatar
 
Cedric Roux committed
129
130
131
132

    return TRUE;
}

133
134
gboolean ui_callback_on_select_signal(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path,
                                      gboolean path_currently_selected, gpointer user_data)
Cedric Roux's avatar
 
Cedric Roux committed
135
{
winckel's avatar
winckel committed
136
    static gpointer buffer_current;
Cedric Roux's avatar
Cedric Roux committed
137
    ui_text_view_t *text_view;
Cedric Roux's avatar
 
Cedric Roux committed
138
139
    GtkTreeIter iter;

winckel's avatar
winckel committed
140
    g_debug("Message selected %d %p %p %s", path_currently_selected, buffer_current, path, gtk_tree_path_to_string(path));
Cedric Roux's avatar
 
Cedric Roux committed
141

winckel's avatar
winckel committed
142
143
144
    if (!path_currently_selected)
    {
        text_view = (ui_text_view_t *) user_data;
Cedric Roux's avatar
Cedric Roux committed
145

winckel's avatar
winckel committed
146
        g_assert(text_view != NULL);
Cedric Roux's avatar
 
Cedric Roux committed
147

148
        if (gtk_tree_model_get_iter (model, &iter, path))
winckel's avatar
winckel committed
149
150
151
        {
            GValue buffer_store = G_VALUE_INIT;
            gpointer buffer;
Cedric Roux's avatar
Cedric Roux committed
152

winckel's avatar
winckel committed
153
154
            GValue message_id_store = G_VALUE_INIT;
            guint message_id;
Cedric Roux's avatar
Cedric Roux committed
155

156
157
            gtk_tree_model_get_value (model, &iter, COL_BUFFER, &buffer_store);
            buffer = g_value_get_pointer (&buffer_store);
Cedric Roux's avatar
Cedric Roux committed
158

winckel's avatar
winckel committed
159
            g_debug("  Get iter %p %p", buffer_current, buffer);
Cedric Roux's avatar
Cedric Roux committed
160

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
            if (ui_tree_view_last_event)
            {
                g_debug("last_event %p %d %d", ui_tree_view_last_event, ui_tree_view_last_event->type, ui_tree_view_last_event->button);

                if (ui_tree_view_last_event->type == GDK_BUTTON_PRESS)
                {
                    /* Callback is due to a button click */
                    ui_main_data.follow_last = FALSE;

                    if (ui_tree_view_last_event->button == 3)
                    {
                        /* It was a right mouse click */
                        int item;

                        /* Clear event */
                        ui_tree_view_last_event = NULL;

                        gtk_tree_model_get (model, &iter, COL_MESSAGE_ID, &message_id, -1);
                        item = ui_filters_search_id (&ui_filters.messages, message_id);

                        if (ui_main_data.menu_filter_messages == NULL)
                        {
                            ui_create_filter_menu (&ui_main_data.menu_filter_messages, &ui_filters.messages);
                        }

                        g_debug("Message selected right click %d %d %s", message_id, item, ui_filters.messages.items[item].name);
                        gtk_check_menu_item_set_active (
                                GTK_CHECK_MENU_ITEM(ui_filters.messages.items[item].menu_item),
                                !gtk_check_menu_item_get_active (
                                        GTK_CHECK_MENU_ITEM(ui_filters.messages.items[item].menu_item)));
                        g_debug("Message selected right click new state %d", gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(ui_filters.messages.items[item].menu_item)));

                        return FALSE;
                    }
                }

                /* Clear event */
                ui_tree_view_last_event = NULL;
            }

winckel's avatar
winckel committed
201
            if (buffer_current != buffer)
202
            {
winckel's avatar
winckel committed
203
204
                buffer_current = buffer;

205
206
                gtk_tree_model_get_value (model, &iter, COL_MESSAGE_ID, &message_id_store);
                message_id = g_value_get_uint (&message_id_store);
winckel's avatar
winckel committed
207
208
209
210
211
212
213
214
215

                /* Clear the view */
                CHECK_FCT_DO(ui_signal_dissect_clear_view(text_view), return FALSE);

                if (ui_main_data.display_message_header)
                {
                    CHECK_FCT_DO(dissect_signal_header((buffer_t*)buffer, ui_signal_set_text, text_view), return FALSE);
                }

216
217
218
219
220
221
                if ((strcmp (message_id_to_string (message_id), "ERROR_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "WARNING_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "NOTICE_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "INFO_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "DEBUG_LOG") == 0)
                        || (strcmp (message_id_to_string (message_id), "GENERIC_LOG") == 0))
winckel's avatar
winckel committed
222
223
224
225
226
227
228
                {
                    gchar *data;
                    gint data_size;
                    uint32_t message_header_type_size;

                    if (ui_main_data.display_message_header)
                    {
229
                        ui_signal_set_text (text_view, "\n", 1);
winckel's avatar
winckel committed
230
231
                    }

232
233
234
                    message_header_type_size = get_message_header_type_size ();
                    data = (gchar *) buffer_at_offset ((buffer_t*) buffer, message_header_type_size);
                    data_size = get_message_size ((buffer_t*) buffer);
winckel's avatar
winckel committed
235

236
                    g_debug("    message header type size: %u, data size: %u %p %d", message_header_type_size, data_size, buffer, ui_main_data.follow_last);
winckel's avatar
winckel committed
237

238
239
240
                    ui_signal_set_text (text_view, data, data_size);
                }
                else
winckel's avatar
winckel committed
241
242
243
244
245
246
                {
                    g_debug("    dissect message %d %p %d", message_id, buffer, ui_main_data.follow_last);

                    /* Dissect the signal */
                    CHECK_FCT_DO(dissect_signal((buffer_t*)buffer, ui_signal_set_text, text_view), return FALSE);
                }
Cedric Roux's avatar
Cedric Roux committed
247
            }
Cedric Roux's avatar
Cedric Roux committed
248
        }
Cedric Roux's avatar
 
Cedric Roux committed
249
250
251
252
    }
    return TRUE;
}

Cedric Roux's avatar
Cedric Roux committed
253
254
void ui_signal_add_to_list(gpointer data, gpointer user_data)
{
winckel's avatar
winckel committed
255
    gboolean goto_last = user_data ? TRUE : FALSE;
Cedric Roux's avatar
Cedric Roux committed
256
    buffer_t *signal_buffer;
257
258
    GtkTreePath *path;
    GtkTreeViewColumn *focus_column;
259
260
    uint32_t lte_frame;
    uint32_t lte_slot;
261
262
    uint32_t origin_task_id;
    uint32_t destination_task_id;
winckel's avatar
winckel committed
263
    uint32_t instance;
Cedric Roux's avatar
Cedric Roux committed
264

265
266
    char lte_time[15];

267
    gtk_tree_view_get_cursor (GTK_TREE_VIEW(ui_main_data.messages_list), &path, &focus_column);
Cedric Roux's avatar
Cedric Roux committed
268

269
    signal_buffer = (buffer_t *) data;
Cedric Roux's avatar
Cedric Roux committed
270

271
272
273
    lte_frame = get_lte_frame (signal_buffer);
    lte_slot = get_lte_slot (signal_buffer);
    sprintf (lte_time, "%d.%02d", lte_frame, lte_slot);
274

275
    get_message_id (root, signal_buffer, &signal_buffer->message_id);
276
277
    origin_task_id = get_task_id (signal_buffer, origin_task_id_type);
    destination_task_id = get_task_id (signal_buffer, destination_task_id_type);
winckel's avatar
winckel committed
278
    instance = get_instance (signal_buffer);
279

280
281
282
283
    ui_tree_view_new_signal_ind (signal_buffer->message_number, lte_time, signal_buffer->message_id,
                                 message_id_to_string (signal_buffer->message_id), origin_task_id,
                                 task_id_to_string (origin_task_id, origin_task_id_type), destination_task_id,
                                 task_id_to_string (destination_task_id, destination_task_id_type), instance, data);
284
285
286

    /* Increment number of messages */
    ui_main_data.nb_message_received++;
287

winckel's avatar
winckel committed
288
    if ((ui_main_data.follow_last) && (goto_last))
289
290
    {
        /* Advance to the new last signal */
291
        ui_tree_view_select_row (ui_tree_view_get_filtered_number () - 1);
292
    }
Cedric Roux's avatar
Cedric Roux committed
293
294
}

295
static gboolean ui_handle_update_signal_list(gint fd, void *data, size_t data_length)
Cedric Roux's avatar
Cedric Roux committed
296
297
298
{
    pipe_new_signals_list_message_t *signal_list_message;

299
    /* Enable buttons to move in the list of signals */
300
    ui_set_sensitive_move_buttons (TRUE);
301

302
    signal_list_message = (pipe_new_signals_list_message_t *) data;
Cedric Roux's avatar
Cedric Roux committed
303
304
305
306

    g_assert(signal_list_message != NULL);
    g_assert(signal_list_message->signal_list != NULL);

winckel's avatar
winckel committed
307
    g_list_foreach (signal_list_message->signal_list, ui_signal_add_to_list, (gpointer) TRUE);
Cedric Roux's avatar
Cedric Roux committed
308

309
    /* Free the list but not user data associated with each element */
310
    g_list_free (signal_list_message->signal_list);
311
    /* Free the message */
312
    free (signal_list_message);
Cedric Roux's avatar
Cedric Roux committed
313

314
    ui_gtk_flush_events ();
315

Cedric Roux's avatar
Cedric Roux committed
316
317
318
319
320
321
322
    return TRUE;
}

static gboolean ui_handle_socket_connection_failed(gint fd)
{
    GtkWidget *dialogbox;

323
324
325
    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");
Cedric Roux's avatar
Cedric Roux committed
326

327
328
    gtk_dialog_run (GTK_DIALOG(dialogbox));
    gtk_widget_destroy (dialogbox);
Cedric Roux's avatar
Cedric Roux committed
329
330

    /* Re-enable connect button */
331
    ui_enable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
332
333
334
335
336
337
338
    return TRUE;
}

static gboolean ui_handle_socket_connection_lost(gint fd)
{
    GtkWidget *dialogbox;

339
340
341
    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");
Cedric Roux's avatar
Cedric Roux committed
342

343
344
    gtk_dialog_run (GTK_DIALOG(dialogbox));
    gtk_widget_destroy (dialogbox);
Cedric Roux's avatar
Cedric Roux committed
345
346

    /* Re-enable connect button */
347
    ui_enable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
348
349
350
    return TRUE;
}

351
static gboolean ui_handle_socket_xml_definition(gint fd, void *data, size_t data_length)
Cedric Roux's avatar
Cedric Roux committed
352
353
354
{
    pipe_xml_definition_message_t *xml_definition_message;

355
    xml_definition_message = (pipe_xml_definition_message_t *) data;
Cedric Roux's avatar
Cedric Roux committed
356
357
358
    g_assert(xml_definition_message != NULL);
    g_assert(data_length == sizeof(pipe_xml_definition_message_t));

359
    xml_parse_buffer (xml_definition_message->xml_definition, xml_definition_message->xml_definition_length);
Cedric Roux's avatar
Cedric Roux committed
360

361
    free (data);
Cedric Roux's avatar
Cedric Roux committed
362
363
364
365
366
367

    return TRUE;
}

gboolean ui_pipe_callback(gint source, gpointer user_data)
{
368
369
370
    void *input_data = NULL;
    size_t input_data_length = 0;
    pipe_input_header_t input_header;
Cedric Roux's avatar
Cedric Roux committed
371
372

    /* Read the header */
373
374
    if (read (source, &input_header, sizeof(input_header)) < 0)
    {
Cedric Roux's avatar
Cedric Roux committed
375
376
377
378
379
380
381
        g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
        return FALSE;
    }

    input_data_length = input_header.message_size - sizeof(input_header);

    /* Checking for non-header part */
382
383
384
    if (input_data_length > 0)
    {
        input_data = malloc (input_data_length);
Cedric Roux's avatar
Cedric Roux committed
385

386
387
        if (read (source, input_data, input_data_length) < 0)
        {
Cedric Roux's avatar
Cedric Roux committed
388
389
390
391
392
            g_warning("Failed to read from pipe %d: %s", source, g_strerror(errno));
            return FALSE;
        }
    }

393
394
    switch (input_header.message_type)
    {
Cedric Roux's avatar
Cedric Roux committed
395
        case UI_PIPE_CONNECTION_FAILED:
396
            return ui_handle_socket_connection_failed (source);
Cedric Roux's avatar
Cedric Roux committed
397
        case UI_PIPE_XML_DEFINITION:
398
            return ui_handle_socket_xml_definition (source, input_data, input_data_length);
Cedric Roux's avatar
Cedric Roux committed
399
        case UI_PIPE_CONNECTION_LOST:
400
            return ui_handle_socket_connection_lost (source);
Cedric Roux's avatar
Cedric Roux committed
401
        case UI_PIPE_UPDATE_SIGNAL_LIST:
402
            return ui_handle_update_signal_list (source, input_data, input_data_length);
Cedric Roux's avatar
Cedric Roux committed
403
        default:
404
            g_warning("[gui] Unhandled message type %u", input_header.message_type);
Cedric Roux's avatar
Cedric Roux committed
405
406
407
408
409
            g_assert_not_reached();
    }
    return FALSE;
}

winckel's avatar
winckel committed
410
gboolean ui_callback_on_connect(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
411
412
413
{
    /* We have to retrieve the ip address and port of remote host */
    const char *ip;
414
415
    uint16_t port;
    int pipe_fd[2];
Cedric Roux's avatar
 
Cedric Roux committed
416

winckel's avatar
winckel committed
417
418
    port = atoi (gtk_entry_get_text (GTK_ENTRY(ui_main_data.port_entry)));
    ip = gtk_entry_get_text (GTK_ENTRY(ui_main_data.ip_entry));
Cedric Roux's avatar
 
Cedric Roux committed
419

420
421
    g_message("Connect event occurred to %s:%d", ip, port);

422
    if (strlen (ip) == 0)
423
424
425
426
427
428
    {
        ui_notification_dialog (GTK_MESSAGE_WARNING, "Connect", "Empty host ip address");
        return FALSE;
    }

    if (port == 0)
429
    {
430
        ui_notification_dialog (GTK_MESSAGE_WARNING, "Connect", "Invalid host port value");
Cedric Roux's avatar
Cedric Roux committed
431
432
433
        return FALSE;
    }

434
    ui_pipe_new (pipe_fd, ui_pipe_callback, NULL);
Cedric Roux's avatar
Cedric Roux committed
435

436
    memcpy (ui_main_data.pipe_fd, pipe_fd, sizeof(int) * 2);
Cedric Roux's avatar
Cedric Roux committed
437
438

    /* Disable the connect button */
439
    ui_disable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
440

winckel's avatar
winckel committed
441
    ui_callback_signal_clear_list (widget, data);
442
443
444
445

    if (socket_connect_to_remote_host (ip, port, pipe_fd[1]) != 0)
    {
        ui_enable_connect_button ();
Cedric Roux's avatar
Cedric Roux committed
446
447
        return FALSE;
    }
448
    ui_set_title ("%s:%d", ip, port);
Cedric Roux's avatar
 
Cedric Roux committed
449
450
451
452

    return TRUE;
}

winckel's avatar
winckel committed
453
gboolean ui_callback_on_disconnect(GtkWidget *widget, gpointer data)
Cedric Roux's avatar
 
Cedric Roux committed
454
455
456
{
    /* We have to retrieve the ip address and port of remote host */

457
    g_message("Disconnect event occurred");
Cedric Roux's avatar
Cedric Roux committed
458

459
    ui_pipe_write_message (ui_main_data.pipe_fd[0], UI_PIPE_DISCONNECT_EVT, NULL, 0);
Cedric Roux's avatar
Cedric Roux committed
460

461
    ui_enable_connect_button ();
Cedric Roux's avatar
 
Cedric Roux committed
462
463
464
    return TRUE;
}

winckel's avatar
winckel committed
465
466
467
468
469
470
471
472
gboolean ui_callback_signal_go_to_first(GtkWidget *widget, gpointer data)
{
    ui_tree_view_select_row (0);
    ui_main_data.follow_last = FALSE;

    return TRUE;
}

winckel's avatar
winckel committed
473
gboolean ui_callback_signal_go_to(GtkWidget *widget, gpointer data)
474
{
winckel's avatar
winckel committed
475
    gtk_window_set_focus (GTK_WINDOW(ui_main_data.window), ui_main_data.signals_go_to_entry);
476
477
478
    return TRUE;
}

winckel's avatar
winckel committed
479
gboolean ui_callback_signal_go_to_entry(GtkWidget *widget, gpointer data)
480
{
winckel's avatar
winckel committed
481
    // gtk_entry_buffer_set_text(GTK_ENTRY(ui_main_data.signals_go_to_entry), "");
482
    gtk_window_set_focus (GTK_WINDOW(ui_main_data.window), ui_main_data.messages_list);
483
484
485
    return TRUE;
}

winckel's avatar
winckel committed
486
gboolean ui_callback_signal_go_to_last(GtkWidget *widget, gpointer data)
487
{
488
    ui_tree_view_select_row (ui_tree_view_get_filtered_number () - 1);
winckel's avatar
winckel committed
489
490
491
492
    ui_main_data.follow_last = TRUE;

    return TRUE;
}
493

winckel's avatar
winckel committed
494
495
496
497
498
499
gboolean ui_callback_display_message_header(GtkWidget *widget, gpointer data)
{
    ui_main_data.display_message_header = !ui_main_data.display_message_header;
    // TODO refresh textview.
    return TRUE;
}
500

winckel's avatar
winckel committed
501
502
503
504
gboolean ui_callback_display_brace(GtkWidget *widget, gpointer data)
{
    ui_main_data.display_brace = !ui_main_data.display_brace;
    // TODO refresh textview.
505
506
507
    return TRUE;
}

winckel's avatar
winckel committed
508
gboolean ui_callback_signal_clear_list(GtkWidget *widget, gpointer data)
509
510
{
    /* Disable buttons to move in the list of signals */
511
    ui_set_sensitive_move_buttons (FALSE);
512
    ui_set_title ("");
513

514
    /* Clear list of signals */
515
    ui_tree_view_destroy_list (ui_main_data.messages_list);
winckel's avatar
winckel committed
516
517
518

    if (ui_main_data.text_view != NULL)
    {
519
        ui_signal_dissect_clear_view (ui_main_data.text_view);
winckel's avatar
winckel committed
520
521
522
523
524
525
526
    }

    return TRUE;
}

static void ui_callback_on_menu_items_selected(GtkWidget *widget, gpointer data)
{
527
    gboolean active = data != NULL;
winckel's avatar
winckel committed
528
529
530
531
532
533
534
535
536
537
538

    if (GTK_IS_CHECK_MENU_ITEM(widget))
    {
        gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget), active);
    }
}

gboolean ui_callback_on_menu_none(GtkWidget *widget, gpointer data)
{
    GtkWidget *menu = (GtkWidget *) data;

539
    g_debug("ui_callback_on_menu_none occurred %lx %lx)", (long) widget, (long) data);
winckel's avatar
winckel committed
540

541
    refresh_message_list = FALSE;
542
    gtk_container_foreach (GTK_CONTAINER(menu), ui_callback_on_menu_items_selected, (gpointer) FALSE);
543
544
545
546
547
548
549
    refresh_message_list = TRUE;

    if (filters_changed);
    {
        ui_tree_view_refilter();
        filters_changed = FALSE;
    }
winckel's avatar
winckel committed
550
551
552
553
554
555
556
557

    return TRUE;
}

gboolean ui_callback_on_menu_all(GtkWidget *widget, gpointer data)
{
    GtkWidget *menu = (GtkWidget *) data;

558
    g_debug("ui_callback_on_menu_all occurred %lx %lx)", (long) widget, (long) data);
winckel's avatar
winckel committed
559

560
    refresh_message_list = FALSE;
561
    gtk_container_foreach (GTK_CONTAINER(menu), ui_callback_on_menu_items_selected, (gpointer) TRUE);
562
563
564
565
566
567
568
    refresh_message_list = TRUE;

    if (filters_changed);
    {
        ui_tree_view_refilter();
        filters_changed = FALSE;
    }
winckel's avatar
winckel committed
569

570
571
572
    return TRUE;
}

573
gboolean ui_callback_on_menu_item_selected(GtkWidget *widget, gpointer data)
574
{
winckel's avatar
winckel committed
575
    ui_filter_item_t *filter_entry = data;
winckel's avatar
winckel committed
576
    gboolean enabled;
winckel's avatar
winckel committed
577

winckel's avatar
winckel committed
578
    enabled = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget));
579
580
581
    if (filter_entry->enabled != enabled)
    {
        filter_entry->enabled = enabled;
582
583
584
585
586
587
588
589
        if (refresh_message_list)
        {
            ui_tree_view_refilter();
        }
        else
        {
            filters_changed = TRUE;
        }
590
    }
591
    g_debug("ui_callback_on_menu_item_selected occurred %p %p %s %d (%d messages to display)", widget, data, filter_entry->name, enabled, ui_tree_view_get_filtered_number());
winckel's avatar
winckel committed
592

593
594
595
    return TRUE;
}

winckel's avatar
winckel committed
596
597
598
599
gboolean ui_callback_on_tree_column_header_click(GtkWidget *widget, gpointer data)
{
    col_type_e col = (col_type_e) data;

600
    g_debug("ui_callback_on_tree_column_header_click %d", col);
winckel's avatar
winckel committed
601
602
    switch (col)
    {
603
        case COL_MESSAGE:
winckel's avatar
winckel committed
604
605
606
607
608
609
610
611
612
613
614
            ui_show_filter_menu (&ui_main_data.menu_filter_messages, &ui_filters.messages);
            break;

        case COL_FROM_TASK:
            ui_show_filter_menu (&ui_main_data.menu_filter_origin_tasks, &ui_filters.origin_tasks);
            break;

        case COL_TO_TASK:
            ui_show_filter_menu (&ui_main_data.menu_filter_destination_tasks, &ui_filters.destination_tasks);
            break;

winckel's avatar
winckel committed
615
616
617
618
        case COL_INSTANCE:
            ui_show_filter_menu (&ui_main_data.menu_filter_instances, &ui_filters.instances);
            break;

winckel's avatar
winckel committed
619
620
621
622
623
        default:
            g_warning("Unknown column filter %d in call to ui_callback_on_tree_column_header_click", col);
            return FALSE;
    }

624
625
    return TRUE;
}