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