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