Fix some warnings in lttv/modules/gui
[lttv.git] / lttv / modules / gui / filter / filter.c
CommitLineData
91ad3f0a 1/* This file is part of the Linux Trace Toolkit viewer
852f16bb 2 * Copyright (C) 2005 Simon Bouvier-Zappa
91ad3f0a 3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
4e4d11b3 19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
91ad3f0a 23#include <glib.h>
24#include <string.h>
25#include <gtk/gtk.h>
26#include <gdk/gdk.h>
3cea5310 27#include <gdk/gdkkeysyms.h>
91ad3f0a 28
29#include <lttv/lttv.h>
30#include <lttv/module.h>
31#include <lttv/hook.h>
32#include <lttv/filter.h>
33
34#include <lttvwindow/lttvwindow.h>
35#include <lttvwindow/lttvwindowtraces.h>
36
37#include "hGuiFilterInsert.xpm"
38
0fc64e11 39
40GSList *g_filter_list = NULL ;
41
7e7af7f2 42/*! \file lttv/modules/gui/filter/filter.c
43 * \brief Graphic filter interface.
44 *
45 * The gui filter facility gives the user an easy to use
46 * basic interface to construct and modify at will a filter
47 * expression. User may either decide to write it himself in
48 * expression text entry or add simple expressions using the
49 * many choices boxes.
50 *
da2e1bfb 51 * \note The version of gtk-2.0 currently installed on
7e7af7f2 52 * my desktop misses some function of the newer
da2e1bfb 53 * gtk+ api. For the time being, I'll use the older api
7e7af7f2 54 * to keep compatibility with most systems.
2b715e58 55 */
56
91ad3f0a 57typedef struct _FilterViewerData FilterViewerData;
c2774e9d 58typedef struct _FilterViewerDataLine FilterViewerDataLine;
91ad3f0a 59
4ed9b7ba 60/*
61 * Prototypes
62 */
91ad3f0a 63GtkWidget *guifilter_get_widget(FilterViewerData *fvd);
e433e6d6 64FilterViewerData *gui_filter(LttvPlugin *plugin);
91ad3f0a 65void gui_filter_destructor(FilterViewerData *fvd);
c2774e9d 66FilterViewerDataLine* gui_filter_add_line(FilterViewerData *fvd);
67void gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v);
68void gui_filter_line_reset(FilterViewerDataLine *fvdl);
e433e6d6 69GtkWidget* h_guifilter(LttvPlugin *plugin);
c2774e9d 70void filter_destroy_walk(gpointer data, gpointer user_data);
91ad3f0a 71
c2774e9d 72/*
73 * Callback functions
74 */
75void callback_process_button(GtkWidget *widget, gpointer data);
3cea5310 76gboolean callback_enter_check(GtkWidget *widget,
77 GdkEventKey *event,
78 gpointer user_data);
c2774e9d 79void callback_add_button(GtkWidget *widget, gpointer data);
80void callback_logical_op_box(GtkWidget *widget, gpointer data);
81void callback_expression_field(GtkWidget *widget, gpointer data);
2422ba7b 82void callback_cancel_button(GtkWidget *widget, gpointer data);
c2774e9d 83
852f16bb 84/**
85 * @struct _FilterViewerDataLine
86 *
87 * @brief Defines a simple expression
88 * This structures defines a simple
89 * expression whithin the main filter
90 * viewer data
91 */
c2774e9d 92struct _FilterViewerDataLine {
7e7af7f2 93 int row; /**< row number */
94 gboolean visible; /**< visible state */
95 GtkWidget *f_not_op_box; /**< '!' operator (GtkComboBox) */
96 GtkWidget *f_logical_op_box; /**< '&,|,^' operators (GtkComboBox) */
97 GtkWidget *f_field_box; /**< field types (GtkComboBox) */
98 GtkWidget *f_math_op_box; /**< '>,>=,<,<=,=,!=' operators (GtkComboBox) */
99 GtkWidget *f_value_field; /**< expression's value (GtkComboBox) */
c2774e9d 100};
101
102/**
7e7af7f2 103 * @struct _FilterViewerData
104 *
105 * @brief Main structure of gui filter
106 * Main struct for the filter gui module
c2774e9d 107 */
91ad3f0a 108struct _FilterViewerData {
e433e6d6 109 LttvPlugin *plugin; /**< Plugin on which we interact. */
91ad3f0a 110
6a4f1205 111 GtkWidget *f_window; /**< filter window */
112
7e7af7f2 113 GtkWidget *f_main_box; /**< main container */
4ed9b7ba 114
7e7af7f2 115 GtkWidget *f_expression_field; /**< entire expression (GtkEntry) */
116 GtkWidget *f_process_button; /**< process expression button (GtkButton) */
4ed9b7ba 117
7e7af7f2 118 GtkWidget *f_logical_op_junction_box; /**< linking operator box (GtkComboBox) */
4ed9b7ba 119
7e7af7f2 120 int rows; /**< number of rows */
121 GPtrArray *f_lines; /**< array of FilterViewerDataLine */
2b715e58 122
7e7af7f2 123 GPtrArray *f_not_op_options; /**< array of operators types for not_op box */
124 GPtrArray *f_logical_op_options; /**< array of operators types for logical_op box */
125 GPtrArray *f_field_options; /**< array of field types for field box */
126 GPtrArray *f_math_op_options; /**< array of operators types for math_op box */
2b715e58 127
7e7af7f2 128 GtkWidget *f_add_button; /**< add expression to current expression (GtkButton) */
2422ba7b 129 GtkWidget *f_cancel_button; /**< cancel and close dialog (GtkButton) */
6a4f1205 130
91ad3f0a 131};
132
c2774e9d 133/**
7e7af7f2 134 * @fn GtkWidget* guifilter_get_widget(FilterViewerData*)
852f16bb 135 *
c2774e9d 136 * This function returns the current main widget
137 * used by this module
138 * @param fvd the module struct
139 * @return The main widget
140 */
7e7af7f2 141GtkWidget*
142guifilter_get_widget(FilterViewerData *fvd)
91ad3f0a 143{
01eb9889 144 return fvd->f_window;
91ad3f0a 145}
146
147/**
7e7af7f2 148 * @fn FilterViewerData* gui_filter(Tab*)
852f16bb 149 *
150 * Constructor is used to create FilterViewerData data structure.
7e7af7f2 151 * @param tab The tab structure used by the widget
852f16bb 152 * @return The Filter viewer data created.
91ad3f0a 153 */
154FilterViewerData*
e433e6d6 155gui_filter(LttvPlugin *plugin)
91ad3f0a 156{
f88c5bfa 157 g_debug("filter::gui_filter()");
2b715e58 158
159 unsigned i;
91ad3f0a 160
161 FilterViewerData* fvd = g_new(FilterViewerData,1);
162
e433e6d6 163 fvd->plugin = plugin;
91ad3f0a 164
da2e1bfb 165// lttvwindow_register_traceset_notify(fvd->tab,
166// filter_traceset_changed,
167// filter_viewer_data);
91ad3f0a 168// request_background_data(filter_viewer_data);
4ed9b7ba 169
2b715e58 170 /*
171 * Initiating items for
172 * combo boxes
173 */
1f7f7fe2 174 fvd->f_not_op_options = g_ptr_array_new();
175 g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new(""));
176 g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new("!"));
177
2b715e58 178 fvd->f_logical_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,sizeof(gchar));
179 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new(""));
180 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("&"));
181 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("|"));
182 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("!"));
183 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("^"));
184
185 fvd->f_field_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,16);
186 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new(""));
187 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.name"));
6471e71f 188 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.subname"));
2b715e58 189 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.category"));
190 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.time"));
191 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.tsc"));
33bdc8dd 192 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.target_pid"));
2b715e58 193 /*
194 * TODO: Add core.xml fields here !
195 */
6471e71f 196 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("channel.name"));
2b715e58 197 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("trace.name"));
4f85064b 198 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_name"));
7b5f6cf1 199 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.thread_brand"));
2b715e58 200 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.pid"));
201 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.ppid"));
202 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.creation_time"));
203 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.insertion_time"));
204 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_mode"));
205 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_submode"));
206 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_status"));
207 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.cpu"));
208
209 fvd->f_math_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,7);
210 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(""));
211 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("="));
212 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("!="));
213 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<"));
214 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<="));
215 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">"));
216 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">="));
217
218
6a4f1205 219 fvd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
294a2716 220 gtk_window_set_title(GTK_WINDOW(fvd->f_window), "LTTV Filter");
93ac601b 221 gtk_window_set_transient_for(GTK_WINDOW(fvd->f_window),
e433e6d6 222 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(fvd->plugin->top_widget))));
93ac601b 223 gtk_window_set_destroy_with_parent(GTK_WINDOW(fvd->f_window), TRUE);
5339b49a 224 gtk_window_set_resizable(GTK_WINDOW(fvd->f_window), FALSE);
6a4f1205 225
4ed9b7ba 226 /*
227 * Initiating GtkTable layout
228 * starts with 2 rows and 5 columns and
229 * expands when expressions added
230 */
1f7f7fe2 231 fvd->f_main_box = gtk_table_new(3,7,FALSE);
4ed9b7ba 232 gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5);
233 gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5);
91ad3f0a 234
6a4f1205 235 gtk_container_add(GTK_CONTAINER(fvd->f_window), GTK_WIDGET(fvd->f_main_box));
236
4ed9b7ba 237 /*
238 * First half of the filter window
239 * - textual entry of filter expression
240 * - processing button
241 */
242 fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL);
3cea5310 243 g_signal_connect (G_OBJECT(fvd->f_expression_field),
244 "key-press-event", G_CALLBACK (callback_enter_check), (gpointer)fvd);
c2774e9d 245// gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0");
4ed9b7ba 246 gtk_widget_show (fvd->f_expression_field);
247
c2774e9d 248 g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed",
249 G_CALLBACK (callback_expression_field), (gpointer) fvd);
250
4ed9b7ba 251 fvd->f_process_button = gtk_button_new_with_label("Process");
252 gtk_widget_show (fvd->f_process_button);
253
c2774e9d 254 g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked",
255 G_CALLBACK (callback_process_button), (gpointer) fvd);
256
1f7f7fe2 257 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0);
258 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0);
c2774e9d 259
260
4ed9b7ba 261
262 /*
263 * Second half of the filter window
264 * - combo boxes featuring filtering options added to the expression
265 */
c2774e9d 266 fvd->f_add_button = gtk_button_new_with_label("Add Expression");
267 gtk_widget_show (fvd->f_add_button);
268
269 g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked",
270 G_CALLBACK (callback_add_button), (gpointer) fvd);
4ed9b7ba 271
2422ba7b 272 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,2,3,GTK_FILL,GTK_FILL,0,0);
273
274 fvd->f_cancel_button = gtk_button_new_with_label("Cancel");
275 gtk_widget_show (fvd->f_cancel_button);
276 g_signal_connect (G_OBJECT (fvd->f_cancel_button), "clicked",
277 G_CALLBACK (callback_cancel_button), (gpointer) fvd);
278
279 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_cancel_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0);
c2774e9d 280
281 fvd->f_logical_op_junction_box = gtk_combo_box_new_text();
2b715e58 282 for(i=0;i<fvd->f_logical_op_options->len;i++) {
283 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
284 gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str);
285 }
286 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
287
c2774e9d 288 //gtk_widget_show(fvd->f_logical_op_box);
2b99ec10 289
c2774e9d 290 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_logical_op_junction_box,0,1,1,2,GTK_SHRINK,GTK_FILL,0,0);
291
203eb6f7 292 gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1);
293
c2774e9d 294 /* initialize a new line */
295 fvd->f_lines = g_ptr_array_new();
296 fvd->rows = 1;
297 FilterViewerDataLine* fvdl = gui_filter_add_line(fvd);
298 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl);
4ed9b7ba 299
c2774e9d 300 /*
301 * show main container
302 */
4ed9b7ba 303 gtk_widget_show(fvd->f_main_box);
6a4f1205 304 gtk_widget_show(fvd->f_window);
4ed9b7ba 305
91ad3f0a 306
307 g_object_set_data_full(
308 G_OBJECT(guifilter_get_widget(fvd)),
309 "filter_viewer_data",
310 fvd,
311 (GDestroyNotify)gui_filter_destructor);
312
0fc64e11 313 g_filter_list = g_slist_append(
314 g_filter_list,
315 fvd);
4ed9b7ba 316
91ad3f0a 317 return fvd;
318}
319
c2774e9d 320/**
7e7af7f2 321 * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*)
852f16bb 322 *
c2774e9d 323 * Adds a filter option line on the module tab
324 * @param fvd The filter module structure
325 * @return The line structure
326 */
327FilterViewerDataLine*
328gui_filter_add_line(FilterViewerData* fvd) {
329
330 FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1);
331
2b715e58 332 unsigned i;
c2774e9d 333 fvdl->row = fvd->rows;
334 fvdl->visible = TRUE;
2b715e58 335
1f7f7fe2 336 fvdl->f_not_op_box = gtk_combo_box_new_text();
337 for(i=0;i<fvd->f_not_op_options->len;i++) {
338 GString* s = g_ptr_array_index(fvd->f_not_op_options,i);
339 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str);
340 }
341
2b715e58 342 fvdl->f_field_box = gtk_combo_box_new_text();
343 for(i=0;i<fvd->f_field_options->len;i++) {
344 GString* s = g_ptr_array_index(fvd->f_field_options,i);
1f7f7fe2 345// g_print("String field: %s\n",s->str);
2b715e58 346 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str);
347 }
348
349 fvdl->f_math_op_box = gtk_combo_box_new_text();
350 for(i=0;i<fvd->f_math_op_options->len;i++) {
351 GString* s = g_ptr_array_index(fvd->f_math_op_options,i);
352 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str);
353 }
354
c2774e9d 355 fvdl->f_value_field = gtk_entry_new();
c2774e9d 356
357 fvdl->f_logical_op_box = gtk_combo_box_new_text();
2b715e58 358 for(i=0;i<fvd->f_logical_op_options->len;i++) {
359 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
360 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str);
361 }
c2774e9d 362 gtk_widget_set_events(fvdl->f_logical_op_box,
363 GDK_ENTER_NOTIFY_MASK |
364 GDK_LEAVE_NOTIFY_MASK |
365 GDK_FOCUS_CHANGE_MASK);
366
367 g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed",
368 G_CALLBACK (callback_logical_op_box), (gpointer) fvd);
2b715e58 369
370 gui_filter_line_reset(fvdl);
371 gui_filter_line_set_visible(fvdl,TRUE);
c2774e9d 372
1f7f7fe2 373 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_not_op_box,0,1,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0);
374 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_field_box,1,3,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0);
375 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_math_op_box,3,4,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0);
376 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_value_field,4,5,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0);
377 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_logical_op_box,5,6,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0);
c2774e9d 378
379 return fvdl;
380}
381
852f16bb 382/**
7e7af7f2 383 * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean)
852f16bb 384 *
385 * Change visible state of current FilterViewerDataLine
386 * @param fvdl pointer to the current FilterViewerDataLine
387 * @param v TRUE: sets visible, FALSE: sets invisible
388 */
7e7af7f2 389void
390gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) {
c2774e9d 391
392 fvdl->visible = v;
393 if(v) {
1f7f7fe2 394 gtk_widget_show(fvdl->f_not_op_box);
2b715e58 395 gtk_widget_show(fvdl->f_field_box);
c2774e9d 396 gtk_widget_show(fvdl->f_math_op_box);
397 gtk_widget_show(fvdl->f_value_field);
398 gtk_widget_show(fvdl->f_logical_op_box);
399 } else {
1f7f7fe2 400 gtk_widget_hide(fvdl->f_not_op_box);
2b715e58 401 gtk_widget_hide(fvdl->f_field_box);
c2774e9d 402 gtk_widget_hide(fvdl->f_math_op_box);
403 gtk_widget_hide(fvdl->f_value_field);
404 gtk_widget_hide(fvdl->f_logical_op_box);
405 }
406
407}
408
852f16bb 409/**
7e7af7f2 410 * @fn void gui_filter_line_reset(FilterViewerDataLine*)
852f16bb 411 *
412 * Sets selections of all boxes in current FilterViewerDataLine
413 * to default value (0)
414 * @param fvdl pointer to current FilterViewerDataLine
415 */
7e7af7f2 416void
417gui_filter_line_reset(FilterViewerDataLine *fvdl) {
c2774e9d 418
1f7f7fe2 419 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0);
2b715e58 420 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0);
c2774e9d 421 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0);
da2e1bfb 422 gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),"");
c2774e9d 423 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0);
424}
425
426/**
7e7af7f2 427 * @fn void gui_filter_destructor(FilterViewerData*)
852f16bb 428 *
c2774e9d 429 * Destructor for the filter gui module
430 * @param fvd The module structure
431 */
91ad3f0a 432void
433gui_filter_destructor(FilterViewerData *fvd)
434{
91ad3f0a 435 /* May already been done by GTK window closing */
436 if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){
437 g_info("widget still exists");
438 }
da2e1bfb 439// if(tab != NULL) {
440// lttvwindow_unregister_traceset_notify(fvd->tab,
441// filter_traceset_changed,
442// filter_viewer_data);
443// }
91ad3f0a 444 lttvwindowtraces_background_notify_remove(fvd);
0fc64e11 445
446 g_filter_list = g_slist_remove(g_filter_list, fvd);
6a4f1205 447
91ad3f0a 448 g_free(fvd);
449}
450
91ad3f0a 451
452/**
7e7af7f2 453 * @fn GtkWidget* h_guifilter(Tab*)
852f16bb 454 *
455 * Filter Module's constructor hook
91ad3f0a 456 *
852f16bb 457 * This constructor is given as a parameter to the menuitem and toolbar button
458 * registration. It creates the list.
e433e6d6 459 * @param obj Object to interact with.
852f16bb 460 * @return The widget created.
91ad3f0a 461 */
462GtkWidget *
e433e6d6 463h_guifilter(LttvPlugin *plugin)
91ad3f0a 464{
6a4f1205 465 return NULL;
91ad3f0a 466}
467
91ad3f0a 468/**
7e7af7f2 469 * @fn static void init()
852f16bb 470 *
471 * This function initializes the Filter Viewer functionnality through the
472 * gtkTraceSet API.
91ad3f0a 473 */
474static void init() {
475
476 lttvwindow_register_constructor("guifilter",
477 "/",
478 "Insert Filter Module",
479 hGuiFilterInsert_xpm,
480 "Insert Filter Module",
2b99ec10 481 h_guifilter);
91ad3f0a 482}
483
c2774e9d 484/**
7e7af7f2 485 * @fn void filter_destroy_walk(gpointer,gpointer)
852f16bb 486 *
c2774e9d 487 * Initiate the destruction of the current gui module
488 * on the GTK Interface
489 */
7e7af7f2 490void
491filter_destroy_walk(gpointer data, gpointer user_data)
91ad3f0a 492{
493 FilterViewerData *fvd = (FilterViewerData*)data;
494
c2774e9d 495 g_debug("CFV.c : filter_destroy_walk, %p", fvd);
da2e1bfb 496
91ad3f0a 497 /* May already have been done by GTK window closing */
498 if(GTK_IS_WIDGET(guifilter_get_widget(fvd)))
499 gtk_widget_destroy(guifilter_get_widget(fvd));
500}
501
502/**
7e7af7f2 503 * @fn static void destroy()
852f16bb 504 * @brief plugin's destroy function
91ad3f0a 505 *
852f16bb 506 * This function releases the memory reserved by the module and unregisters
507 * everything that has been registered in the gtkTraceSet API.
91ad3f0a 508 */
509static void destroy() {
0fc64e11 510
511 g_slist_foreach(g_filter_list, filter_destroy_walk, NULL );
91ad3f0a 512
2b99ec10 513 lttvwindow_unregister_constructor(h_guifilter);
91ad3f0a 514
515}
516
c2774e9d 517/**
7e7af7f2 518 * @fn void callback_process_button(GtkWidget*,gpointer)
852f16bb 519 *
c2774e9d 520 * The Process Button callback function
521 * @param widget The Button widget passed to the callback function
522 * @param data Data sent along with the callback function
523 */
7e7af7f2 524void
525callback_process_button(GtkWidget *widget, gpointer data) {
c2774e9d 526
da2e1bfb 527 g_debug("callback_process_button(): Processing expression");
528
c2774e9d 529 FilterViewerData *fvd = (FilterViewerData*)data;
064565c5 530 LttvFilter* filter;
c2774e9d 531
1f7f7fe2 532 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
064565c5 533 filter = lttv_filter_new();
da2e1bfb 534 GString* s = g_string_new(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
535 lttv_filter_append_expression(filter,s->str);
536 g_string_free(s,TRUE);
064565c5 537 } else {
538 filter = NULL;
1f7f7fe2 539 }
e433e6d6 540 /* Remove the old filter if present */
541 //g_object_set_data_full(fvd->obj, "filter", filter,
542 // (GDestroyNotify)lttv_filter_destroy);
543 //g_object_notify(fvd->obj, "filter");
544 lttv_plugin_update_filter(fvd->plugin, filter);
c2774e9d 545}
546
2422ba7b 547/**
548 * @fn void callback_cancel_button(GtkWidget*,gpointer)
549 *
550 * The Cancel Button callback function
551 * @param widget The Button widget passed to the callback function
552 * @param data Data sent along with the callback function
553 */
554void
555callback_cancel_button(GtkWidget *widget, gpointer data) {
556
557 FilterViewerData *fvd = (FilterViewerData*)data;
558 gtk_widget_destroy(fvd->f_window);
559}
560
3cea5310 561gboolean callback_enter_check(GtkWidget *widget,
562 GdkEventKey *event,
563 gpointer user_data)
564{
f42883f9 565 g_debug("typed : %x", event->keyval);
3cea5310 566 switch(event->keyval) {
567 case GDK_Return:
568 case GDK_KP_Enter:
569 case GDK_ISO_Enter:
570 case GDK_3270_Enter:
f42883f9 571 callback_process_button(widget, user_data);
3cea5310 572 break;
573 default:
574 break;
575 }
576 return FALSE;
577}
578
c2774e9d 579/**
7e7af7f2 580 * @fn void callback_expression_field(GtkWidget*,gpointer)
852f16bb 581 *
c2774e9d 582 * The Add Button callback function
583 * @param widget The Button widget passed to the callback function
584 * @param data Data sent along with the callback function
585 */
7e7af7f2 586void
587callback_expression_field(GtkWidget *widget, gpointer data) {
da2e1bfb 588
c2774e9d 589 FilterViewerData *fvd = (FilterViewerData*)data;
590
591 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
592 gtk_widget_show(fvd->f_logical_op_junction_box);
593 } else {
594 gtk_widget_hide(fvd->f_logical_op_junction_box);
595 }
596}
597
598
599/**
7e7af7f2 600 * @fn void callback_add_button(GtkWidget*,gpointer)
852f16bb 601 *
c2774e9d 602 * The Add Button callback function
603 * @param widget The Button widget passed to the callback function
604 * @param data Data sent along with the callback function
605 */
7e7af7f2 606void
607callback_add_button(GtkWidget *widget, gpointer data) {
c2774e9d 608
da2e1bfb 609 g_debug("callback_add_button(): processing simple expressions");
c2774e9d 610
da2e1bfb 611 unsigned i;
612
c2774e9d 613 FilterViewerData *fvd = (FilterViewerData*)data;
614 FilterViewerDataLine *fvdl = NULL;
615 GString* a_filter_string = g_string_new("");
2b715e58 616
da2e1bfb 617 /*
618 * adding linking operator to
619 * string
620 */
2b715e58 621 GString* s;
622 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box)));
4ec0c904 623 a_filter_string = g_string_append(a_filter_string,s->str);
da2e1bfb 624 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
c2774e9d 625
da2e1bfb 626 /* begin expression */
4ec0c904 627 a_filter_string = g_string_append_c(a_filter_string,'(');
2b715e58 628
da2e1bfb 629 /*
630 * For each simple expression, add the resulting string
631 * to the filter string
632 *
633 * Each simple expression takes the following schema
634 * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value]
635 */
c2774e9d 636 for(i=0;i<fvd->f_lines->len;i++) {
637 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
1f7f7fe2 638
639 s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box)));
4ec0c904 640 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 641
642 s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box)));
4ec0c904 643 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 644
645 s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box)));
4ec0c904 646 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 647
4ec0c904 648 a_filter_string = g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field)));
2b715e58 649
650 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)));
4ec0c904 651 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 652
da2e1bfb 653 /*
654 * resetting simple expression lines
655 */
c2774e9d 656 gui_filter_line_reset(fvdl);
2b715e58 657 if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line
c2774e9d 658 }
659
da2e1bfb 660 /* end expression */
4ec0c904 661 a_filter_string = g_string_append_c(a_filter_string,')');
c2774e9d 662
2b715e58 663 g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
664 gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str);
c2774e9d 665
666}
667
668/**
7e7af7f2 669 * @fn void callback_logical_op_box(GtkWidget*,gpointer)
852f16bb 670 *
c2774e9d 671 * The logical op box callback function
672 * @param widget The Button widget passed to the callback function
673 * @param data Data sent along with the callback function
674 */
7e7af7f2 675void
676callback_logical_op_box(GtkWidget *widget, gpointer data) {
c2774e9d 677
da2e1bfb 678 g_debug("callback_logical_op_box(): adding new simple expression");
c2774e9d 679
680 FilterViewerData *fvd = (FilterViewerData*)data;
681 FilterViewerDataLine *fvdl = NULL;
682
683 int i;
684 for(i=0;i<fvd->f_lines->len;i++) {
685 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
686 if(fvdl->f_logical_op_box == widget) {
da2e1bfb 687 if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return;
c2774e9d 688 if(i==fvd->f_lines->len-1) { /* create a new line */
689 fvd->rows++;
690 FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd);
691 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2);
692 } else {
693 FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1);
694 if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE);
695 }
696 }
697 }
698
699}
91ad3f0a 700
701LTTV_MODULE("guifilter", "Filter window", \
702 "Graphical module that let user specify their filtering options", \
703 init, destroy, "lttvwindow")
704
This page took 0.095162 seconds and 4 git commands to generate.