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