fix filter : add a list to module unloading will 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
39 GSList *g_filter_list = NULL ;
40
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 *
50 * \note The version of gtk-2.0 currently installed on
51 * my desktop misses some function of the newer
52 * gtk+ api. For the time being, I'll use the older api
53 * to keep compatibility with most systems.
54 */
55
56 typedef struct _FilterViewerData FilterViewerData;
57 typedef struct _FilterViewerDataLine FilterViewerDataLine;
58
59 /*
60 * Prototypes
61 */
62 GtkWidget *guifilter_get_widget(FilterViewerData *fvd);
63 FilterViewerData *gui_filter(Tab *tab);
64 void gui_filter_destructor(FilterViewerData *fvd);
65 FilterViewerDataLine* gui_filter_add_line(FilterViewerData *fvd);
66 void gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v);
67 void gui_filter_line_reset(FilterViewerDataLine *fvdl);
68 GtkWidget* h_guifilter(Tab *tab);
69 void filter_destroy_walk(gpointer data, gpointer user_data);
70
71 /*
72 * Callback functions
73 */
74 void callback_process_button(GtkWidget *widget, gpointer data);
75 void callback_add_button(GtkWidget *widget, gpointer data);
76 void callback_logical_op_box(GtkWidget *widget, gpointer data);
77 void callback_expression_field(GtkWidget *widget, gpointer data);
78
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 */
87 struct _FilterViewerDataLine {
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) */
95 };
96
97 /**
98 * @struct _FilterViewerData
99 *
100 * @brief Main structure of gui filter
101 * Main struct for the filter gui module
102 */
103 struct _FilterViewerData {
104 Tab *tab; /**< current tab of module */
105
106 GtkWidget *f_main_box; /**< main container */
107
108 GtkWidget *f_expression_field; /**< entire expression (GtkEntry) */
109 GtkWidget *f_process_button; /**< process expression button (GtkButton) */
110
111 GtkWidget *f_logical_op_junction_box; /**< linking operator box (GtkComboBox) */
112
113 int rows; /**< number of rows */
114 GPtrArray *f_lines; /**< array of FilterViewerDataLine */
115
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 */
120
121 GtkWidget *f_add_button; /**< add expression to current expression (GtkButton) */
122
123 };
124
125 /**
126 * @fn GtkWidget* guifilter_get_widget(FilterViewerData*)
127 *
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 */
133 GtkWidget*
134 guifilter_get_widget(FilterViewerData *fvd)
135 {
136 return fvd->f_main_box;
137 }
138
139 /**
140 * @fn FilterViewerData* gui_filter(Tab*)
141 *
142 * Constructor is used to create FilterViewerData data structure.
143 * @param tab The tab structure used by the widget
144 * @return The Filter viewer data created.
145 */
146 FilterViewerData*
147 gui_filter(Tab *tab)
148 {
149 g_print("filter::gui_filter()");
150
151 unsigned i;
152 GtkCellRenderer *renderer;
153 GtkTreeViewColumn *column;
154
155 FilterViewerData* fvd = g_new(FilterViewerData,1);
156
157 fvd->tab = tab;
158
159 // lttvwindow_register_traceset_notify(fvd->tab,
160 // filter_traceset_changed,
161 // filter_viewer_data);
162 // request_background_data(filter_viewer_data);
163
164 /*
165 * Initiating items for
166 * combo boxes
167 */
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
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
209 /*
210 * Initiating GtkTable layout
211 * starts with 2 rows and 5 columns and
212 * expands when expressions added
213 */
214 fvd->f_main_box = gtk_table_new(3,7,FALSE);
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);
217
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);
224 // gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0");
225 gtk_widget_show (fvd->f_expression_field);
226
227 g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed",
228 G_CALLBACK (callback_expression_field), (gpointer) fvd);
229
230 fvd->f_process_button = gtk_button_new_with_label("Process");
231 gtk_widget_show (fvd->f_process_button);
232
233 g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked",
234 G_CALLBACK (callback_process_button), (gpointer) fvd);
235
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);
238
239
240
241 /*
242 * Second half of the filter window
243 * - combo boxes featuring filtering options added to the expression
244 */
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);
250
251 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0);
252
253 fvd->f_logical_op_junction_box = gtk_combo_box_new_text();
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
260 //gtk_widget_show(fvd->f_logical_op_box);
261
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
264 gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1);
265
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);
271
272 /*
273 * show main container
274 */
275 gtk_widget_show(fvd->f_main_box);
276
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
284 g_filter_list = g_slist_append(
285 g_filter_list,
286 fvd);
287
288 return fvd;
289 }
290
291 /**
292 * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*)
293 *
294 * Adds a filter option line on the module tab
295 * @param fvd The filter module structure
296 * @return The line structure
297 */
298 FilterViewerDataLine*
299 gui_filter_add_line(FilterViewerData* fvd) {
300
301 FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1);
302
303 unsigned i;
304 fvdl->row = fvd->rows;
305 fvdl->visible = TRUE;
306
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
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);
316 // g_print("String field: %s\n",s->str);
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
326 fvdl->f_value_field = gtk_entry_new();
327
328 fvdl->f_logical_op_box = gtk_combo_box_new_text();
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 }
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);
340
341 gui_filter_line_reset(fvdl);
342 gui_filter_line_set_visible(fvdl,TRUE);
343
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);
349
350 return fvdl;
351 }
352
353 /**
354 * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean)
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 */
360 void
361 gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) {
362
363 fvdl->visible = v;
364 if(v) {
365 gtk_widget_show(fvdl->f_not_op_box);
366 gtk_widget_show(fvdl->f_field_box);
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 {
371 gtk_widget_hide(fvdl->f_not_op_box);
372 gtk_widget_hide(fvdl->f_field_box);
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
380 /**
381 * @fn void gui_filter_line_reset(FilterViewerDataLine*)
382 *
383 * Sets selections of all boxes in current FilterViewerDataLine
384 * to default value (0)
385 * @param fvdl pointer to current FilterViewerDataLine
386 */
387 void
388 gui_filter_line_reset(FilterViewerDataLine *fvdl) {
389
390 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0);
391 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0);
392 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0);
393 gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),"");
394 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0);
395 }
396
397 /**
398 * @fn void gui_filter_destructor(FilterViewerData*)
399 *
400 * Destructor for the filter gui module
401 * @param fvd The module structure
402 */
403 void
404 gui_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 }
412 // if(tab != NULL) {
413 // lttvwindow_unregister_traceset_notify(fvd->tab,
414 // filter_traceset_changed,
415 // filter_viewer_data);
416 // }
417 lttvwindowtraces_background_notify_remove(fvd);
418
419 g_filter_list = g_slist_remove(g_filter_list, fvd);
420
421 g_free(fvd);
422 }
423
424
425 /**
426 * @fn GtkWidget* h_guifilter(Tab*)
427 *
428 * Filter Module's constructor hook
429 *
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.
434 */
435 GtkWidget *
436 h_guifilter(Tab *tab)
437 {
438 FilterViewerData* f = gui_filter(tab) ;
439
440 if(f)
441 return guifilter_get_widget(f);
442 else return NULL;
443
444 }
445
446 /**
447 * @fn static void init()
448 *
449 * This function initializes the Filter Viewer functionnality through the
450 * gtkTraceSet API.
451 */
452 static void init() {
453
454 lttvwindow_register_constructor("guifilter",
455 "/",
456 "Insert Filter Module",
457 hGuiFilterInsert_xpm,
458 "Insert Filter Module",
459 h_guifilter);
460 }
461
462 /**
463 * @fn void filter_destroy_walk(gpointer,gpointer)
464 *
465 * Initiate the destruction of the current gui module
466 * on the GTK Interface
467 */
468 void
469 filter_destroy_walk(gpointer data, gpointer user_data)
470 {
471 FilterViewerData *fvd = (FilterViewerData*)data;
472
473 g_debug("CFV.c : filter_destroy_walk, %p", fvd);
474
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 /**
481 * @fn static void destroy()
482 * @brief plugin's destroy function
483 *
484 * This function releases the memory reserved by the module and unregisters
485 * everything that has been registered in the gtkTraceSet API.
486 */
487 static void destroy() {
488
489 g_slist_foreach(g_filter_list, filter_destroy_walk, NULL );
490
491 lttvwindow_unregister_constructor(h_guifilter);
492
493 }
494
495 /**
496 * @fn void callback_process_button(GtkWidget*,gpointer)
497 *
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 */
502 void
503 callback_process_button(GtkWidget *widget, gpointer data) {
504
505 g_debug("callback_process_button(): Processing expression");
506
507 FilterViewerData *fvd = (FilterViewerData*)data;
508
509 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
510 LttvFilter* filter = lttv_filter_new();
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);
514 //SetFilter(fvd->tab,filter);
515 lttvwindow_report_filter(fvd->tab, filter);
516 }
517 }
518
519 /**
520 * @fn void callback_expression_field(GtkWidget*,gpointer)
521 *
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 */
526 void
527 callback_expression_field(GtkWidget *widget, gpointer data) {
528
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 /**
540 * @fn void callback_add_button(GtkWidget*,gpointer)
541 *
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 */
546 void
547 callback_add_button(GtkWidget *widget, gpointer data) {
548
549 g_debug("callback_add_button(): processing simple expressions");
550
551 unsigned i;
552
553 FilterViewerData *fvd = (FilterViewerData*)data;
554 FilterViewerDataLine *fvdl = NULL;
555 GString* a_filter_string = g_string_new("");
556
557 /*
558 * adding linking operator to
559 * string
560 */
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)));
563 g_string_append(a_filter_string,s->str);
564 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
565
566 /* begin expression */
567 g_string_append_c(a_filter_string,'(');
568
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 */
576 for(i=0;i<fvd->f_lines->len;i++) {
577 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
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);
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
593 /*
594 * resetting simple expression lines
595 */
596 gui_filter_line_reset(fvdl);
597 if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line
598 }
599
600 /* end expression */
601 g_string_append_c(a_filter_string,')');
602
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);
605
606 }
607
608 /**
609 * @fn void callback_logical_op_box(GtkWidget*,gpointer)
610 *
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 */
615 void
616 callback_logical_op_box(GtkWidget *widget, gpointer data) {
617
618 g_debug("callback_logical_op_box(): adding new simple expression");
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) {
627 if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return;
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 }
640
641 LTTV_MODULE("guifilter", "Filter window", \
642 "Graphical module that let user specify their filtering options", \
643 init, destroy, "lttvwindow")
644
This page took 0.043089 seconds and 5 git commands to generate.