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