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