filter core:
[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;
1f7f7fe2 77 GtkWidget *f_not_op_box;
c2774e9d 78 GtkWidget *f_logical_op_box;
2b715e58 79 GtkWidget *f_field_box;
c2774e9d 80 GtkWidget *f_math_op_box;
81 GtkWidget *f_value_field;
82};
83
84/**
85 * @struct _FilterViewerData
86 * Main struct for the filter gui module
87 */
91ad3f0a 88struct _FilterViewerData {
89 Tab *tab;
90
4ed9b7ba 91 GtkWidget *f_main_box;
92
93 GtkWidget *f_hbox1;
94 GtkWidget *f_hbox2;
95
96 GtkWidget *f_expression_field;
97 GtkWidget *f_process_button;
98
c2774e9d 99 GtkWidget *f_logical_op_junction_box;
4ed9b7ba 100
c2774e9d 101 int rows;
102 GPtrArray *f_lines;
2b715e58 103
1f7f7fe2 104 GPtrArray *f_not_op_options;
2b715e58 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 */
1f7f7fe2 156 fvd->f_not_op_options = g_ptr_array_new();
157 g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new(""));
158 g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new("!"));
159
2b715e58 160 fvd->f_logical_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,sizeof(gchar));
161 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new(""));
162 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("&"));
163 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("|"));
164 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("!"));
165 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("^"));
166
167 fvd->f_field_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,16);
168 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new(""));
169 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.name"));
170 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.category"));
171 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.time"));
172 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.tsc"));
173 /*
174 * TODO: Add core.xml fields here !
175 */
176 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("tracefile.name"));
177 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("trace.name"));
178 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.pid"));
179 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.ppid"));
180 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.creation_time"));
181 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.insertion_time"));
182 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_mode"));
183 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_submode"));
184 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_status"));
185 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.cpu"));
186
187 fvd->f_math_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,7);
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 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<"));
192 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<="));
193 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">"));
194 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">="));
195
196
4ed9b7ba 197 /*
198 * Initiating GtkTable layout
199 * starts with 2 rows and 5 columns and
200 * expands when expressions added
201 */
1f7f7fe2 202 fvd->f_main_box = gtk_table_new(3,7,FALSE);
4ed9b7ba 203 gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5);
204 gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5);
91ad3f0a 205
4ed9b7ba 206 /*
207 * First half of the filter window
208 * - textual entry of filter expression
209 * - processing button
210 */
211 fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL);
c2774e9d 212// gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0");
4ed9b7ba 213 gtk_widget_show (fvd->f_expression_field);
214
c2774e9d 215 g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed",
216 G_CALLBACK (callback_expression_field), (gpointer) fvd);
217
4ed9b7ba 218 fvd->f_process_button = gtk_button_new_with_label("Process");
219 gtk_widget_show (fvd->f_process_button);
220
c2774e9d 221 g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked",
222 G_CALLBACK (callback_process_button), (gpointer) fvd);
223
1f7f7fe2 224 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0);
225 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0);
c2774e9d 226
227
4ed9b7ba 228
229 /*
230 * Second half of the filter window
231 * - combo boxes featuring filtering options added to the expression
232 */
c2774e9d 233 fvd->f_add_button = gtk_button_new_with_label("Add Expression");
234 gtk_widget_show (fvd->f_add_button);
235
236 g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked",
237 G_CALLBACK (callback_add_button), (gpointer) fvd);
4ed9b7ba 238
1f7f7fe2 239 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0);
c2774e9d 240
241 fvd->f_logical_op_junction_box = gtk_combo_box_new_text();
2b715e58 242 for(i=0;i<fvd->f_logical_op_options->len;i++) {
243 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
244 gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str);
245 }
246 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
247
c2774e9d 248 //gtk_widget_show(fvd->f_logical_op_box);
2b99ec10 249
c2774e9d 250 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);
251
252 /* initialize a new line */
253 fvd->f_lines = g_ptr_array_new();
254 fvd->rows = 1;
255 FilterViewerDataLine* fvdl = gui_filter_add_line(fvd);
256 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl);
4ed9b7ba 257
c2774e9d 258 /*
259 * show main container
260 */
4ed9b7ba 261 gtk_widget_show(fvd->f_main_box);
262
91ad3f0a 263
264 g_object_set_data_full(
265 G_OBJECT(guifilter_get_widget(fvd)),
266 "filter_viewer_data",
267 fvd,
268 (GDestroyNotify)gui_filter_destructor);
269
4ed9b7ba 270
91ad3f0a 271 return fvd;
272}
273
c2774e9d 274/**
275 * Adds a filter option line on the module tab
276 * @param fvd The filter module structure
277 * @return The line structure
278 */
279FilterViewerDataLine*
280gui_filter_add_line(FilterViewerData* fvd) {
281
282 FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1);
283
2b715e58 284 unsigned i;
c2774e9d 285 fvdl->row = fvd->rows;
286 fvdl->visible = TRUE;
2b715e58 287
288 /*
c2774e9d 289 fvdl->f_struct_box = gtk_combo_box_new_text();
290 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_struct_box), "");
291 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_struct_box), "event");
292 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_struct_box), "tracefile");
293 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_struct_box), "trace");
294 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_struct_box), "state");
295 gtk_widget_show(fvdl->f_struct_box);
2b715e58 296
c2774e9d 297 fvdl->f_subfield_box = gtk_combo_box_new_text();
298 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "");
299 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "name");
300 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "category");
301 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "time");
302 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "tsc");
303 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "pid");
304 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "ppid");
305 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "creation time");
306 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "insertion time");
307 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "process name");
308 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "execution mode");
309 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "execution submode");
310 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "process status");
311 gtk_combo_box_append_text (GTK_COMBO_BOX (fvdl->f_subfield_box), "cpu");
312 gtk_widget_show(fvdl->f_subfield_box);
2b715e58 313 */
c2774e9d 314
1f7f7fe2 315 fvdl->f_not_op_box = gtk_combo_box_new_text();
316 for(i=0;i<fvd->f_not_op_options->len;i++) {
317 GString* s = g_ptr_array_index(fvd->f_not_op_options,i);
318 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str);
319 }
320
2b715e58 321 fvdl->f_field_box = gtk_combo_box_new_text();
322 for(i=0;i<fvd->f_field_options->len;i++) {
323 GString* s = g_ptr_array_index(fvd->f_field_options,i);
1f7f7fe2 324// g_print("String field: %s\n",s->str);
2b715e58 325 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str);
326 }
327
328 fvdl->f_math_op_box = gtk_combo_box_new_text();
329 for(i=0;i<fvd->f_math_op_options->len;i++) {
330 GString* s = g_ptr_array_index(fvd->f_math_op_options,i);
331 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str);
332 }
333
c2774e9d 334 fvdl->f_value_field = gtk_entry_new();
c2774e9d 335
336 fvdl->f_logical_op_box = gtk_combo_box_new_text();
2b715e58 337 for(i=0;i<fvd->f_logical_op_options->len;i++) {
338 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
339 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str);
340 }
c2774e9d 341 gtk_widget_set_events(fvdl->f_logical_op_box,
342 GDK_ENTER_NOTIFY_MASK |
343 GDK_LEAVE_NOTIFY_MASK |
344 GDK_FOCUS_CHANGE_MASK);
345
346 g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed",
347 G_CALLBACK (callback_logical_op_box), (gpointer) fvd);
2b715e58 348
349 gui_filter_line_reset(fvdl);
350 gui_filter_line_set_visible(fvdl,TRUE);
c2774e9d 351
2b715e58 352// 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);
353// 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);
1f7f7fe2 354 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);
355 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);
356 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);
357 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);
358 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvdl->f_logical_op_box,5,6,fvd->rows+1,fvd->rows+2,GTK_SHRINK,GTK_FILL,0,0);
c2774e9d 359
360 return fvdl;
361}
362
363void gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) {
364
365 fvdl->visible = v;
366 if(v) {
2b715e58 367// gtk_widget_show(fvdl->f_struct_box);
368// gtk_widget_show(fvdl->f_subfield_box);
1f7f7fe2 369 gtk_widget_show(fvdl->f_not_op_box);
2b715e58 370 gtk_widget_show(fvdl->f_field_box);
c2774e9d 371 gtk_widget_show(fvdl->f_math_op_box);
372 gtk_widget_show(fvdl->f_value_field);
373 gtk_widget_show(fvdl->f_logical_op_box);
374 } else {
2b715e58 375// gtk_widget_hide(fvdl->f_struct_box);
376// gtk_widget_hide(fvdl->f_subfield_box);
1f7f7fe2 377 gtk_widget_hide(fvdl->f_not_op_box);
2b715e58 378 gtk_widget_hide(fvdl->f_field_box);
c2774e9d 379 gtk_widget_hide(fvdl->f_math_op_box);
380 gtk_widget_hide(fvdl->f_value_field);
381 gtk_widget_hide(fvdl->f_logical_op_box);
382 }
383
384}
385
386void gui_filter_line_reset(FilterViewerDataLine *fvdl) {
387
2b715e58 388// gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_struct_box),0);
389// gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_subfield_box),0);
1f7f7fe2 390 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0);
2b715e58 391 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0);
c2774e9d 392 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0);
393 gtk_entry_set_text(GTK_COMBO_BOX(fvdl->f_value_field),"");
394 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0);
395}
396
397/**
398 * Destructor for the filter gui module
399 * @param fvd The module structure
400 */
91ad3f0a 401void
402gui_filter_destructor(FilterViewerData *fvd)
403{
404 Tab *tab = fvd->tab;
405
406 /* May already been done by GTK window closing */
407 if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){
408 g_info("widget still exists");
409 }
410 if(tab != NULL) {
411 lttvwindow_unregister_traceset_notify(fvd->tab,
412 filter_traceset_changed,
413 filter_viewer_data);
414 }
415 lttvwindowtraces_background_notify_remove(fvd);
416
417 g_free(fvd);
418}
419
c2774e9d 420/**
421 * Hook function
422 * @param hook_data The hook data
423 * @param call_data The call data
424 * @return Success/Failure of operation
425 */
91ad3f0a 426gboolean
427filter_traceset_changed(void * hook_data, void * call_data) {
428
429 return FALSE;
430}
431
c2774e9d 432/**
433 * Hook function
434 * @param hook_data The hook data
435 * @param call_data The call data
436 * @return Success/Failure of operation
437 */
91ad3f0a 438gboolean
439filter_viewer_data(void * hook_data, void * call_data) {
440
441 return FALSE;
442}
443
444/**
445 * Filter Module's constructor hook
446 *
447 * This constructor is given as a parameter to the menuitem and toolbar button
448 * registration. It creates the list.
c2774e9d 449 * @param tab A pointer to the parent window.
91ad3f0a 450 * @return The widget created.
451 */
452GtkWidget *
2b99ec10 453h_guifilter(Tab *tab)
91ad3f0a 454{
455 FilterViewerData* f = gui_filter(tab) ;
456
2b99ec10 457 g_print("FilterViewerData:%p\n",f);
91ad3f0a 458 if(f)
459 return guifilter_get_widget(f);
460 else return NULL;
461
462}
463
91ad3f0a 464/**
c2774e9d 465 * This function initializes the Filter Viewer functionnality through the
91ad3f0a 466 * gtkTraceSet API.
467 */
468static void init() {
469
470 lttvwindow_register_constructor("guifilter",
471 "/",
472 "Insert Filter Module",
473 hGuiFilterInsert_xpm,
474 "Insert Filter Module",
2b99ec10 475 h_guifilter);
91ad3f0a 476}
477
c2774e9d 478/**
479 * Initiate the destruction of the current gui module
480 * on the GTK Interface
481 */
91ad3f0a 482void filter_destroy_walk(gpointer data, gpointer user_data)
483{
484 FilterViewerData *fvd = (FilterViewerData*)data;
485
c2774e9d 486 g_debug("CFV.c : filter_destroy_walk, %p", fvd);
91ad3f0a 487 /* May already have been done by GTK window closing */
488 if(GTK_IS_WIDGET(guifilter_get_widget(fvd)))
489 gtk_widget_destroy(guifilter_get_widget(fvd));
490}
491
492/**
493 * plugin's destroy function
494 *
495 * This function releases the memory reserved by the module and unregisters
496 * everything that has been registered in the gtkTraceSet API.
497 */
498static void destroy() {
499
2b99ec10 500 lttvwindow_unregister_constructor(h_guifilter);
91ad3f0a 501
502}
503
c2774e9d 504/**
505 * The Process Button callback function
506 * @param widget The Button widget passed to the callback function
507 * @param data Data sent along with the callback function
508 */
509void callback_process_button(GtkWidget *widget, gpointer data) {
510
511 FilterViewerData *fvd = (FilterViewerData*)data;
512
1f7f7fe2 513 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
514 LttvFilter* filter = lttv_filter_new();
515 lttv_filter_append_expression(filter,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
516 }
c2774e9d 517}
518
519/**
520 * The Add Button callback function
521 * @param widget The Button widget passed to the callback function
522 * @param data Data sent along with the callback function
523 */
524void callback_expression_field(GtkWidget *widget, gpointer data) {
525
526 FilterViewerData *fvd = (FilterViewerData*)data;
527
528 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
529 gtk_widget_show(fvd->f_logical_op_junction_box);
530 } else {
531 gtk_widget_hide(fvd->f_logical_op_junction_box);
532 }
533}
534
535
536/**
537 * The Add Button callback function
538 * @param widget The Button widget passed to the callback function
539 * @param data Data sent along with the callback function
540 */
541void callback_add_button(GtkWidget *widget, gpointer data) {
542
543 g_print("filter::callback_add_button()\n");
544
545 FilterViewerData *fvd = (FilterViewerData*)data;
546 FilterViewerDataLine *fvdl = NULL;
547 GString* a_filter_string = g_string_new("");
2b715e58 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_print("s:%p\n",s);
552 g_print("string:%s\n",s);
553 g_string_append(a_filter_string,s->str);
c2774e9d 554 gtk_combo_box_set_active(fvd->f_logical_op_junction_box,0);
555
2b715e58 556 g_print("passe junction\n");
c2774e9d 557
2b715e58 558 g_string_append_c(a_filter_string,'(');
559
c2774e9d 560 int i;
561 for(i=0;i<fvd->f_lines->len;i++) {
562 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
1f7f7fe2 563
564 s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box)));
565 g_string_append(a_filter_string,s->str);
2b715e58 566
567 s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box)));
568 g_string_append(a_filter_string,s->str);
569
570 s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box)));
571 g_string_append(a_filter_string,s->str);
572
573 g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field)));
574
575 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)));
576 g_string_append(a_filter_string,s->str);
577
c2774e9d 578 gui_filter_line_reset(fvdl);
2b715e58 579 if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line
c2774e9d 580 }
581
2b715e58 582 g_string_append_c(a_filter_string,')');
c2774e9d 583
2b715e58 584 g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
585 gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str);
c2774e9d 586
587}
588
589/**
590 * The logical op box callback function
591 * @param widget The Button widget passed to the callback function
592 * @param data Data sent along with the callback function
593 */
594void callback_logical_op_box(GtkWidget *widget, gpointer data) {
595
596 g_print("filter::callback_logical_op_box()\n");
597
598 FilterViewerData *fvd = (FilterViewerData*)data;
599 FilterViewerDataLine *fvdl = NULL;
600
601 int i;
602 for(i=0;i<fvd->f_lines->len;i++) {
603 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
604 if(fvdl->f_logical_op_box == widget) {
605 if(gtk_combo_box_get_active(fvdl->f_logical_op_box) == 0) return;
606 if(i==fvd->f_lines->len-1) { /* create a new line */
607 fvd->rows++;
608 FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd);
609 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2);
610 } else {
611 FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1);
612 if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE);
613 }
614 }
615 }
616
617}
91ad3f0a 618
619LTTV_MODULE("guifilter", "Filter window", \
620 "Graphical module that let user specify their filtering options", \
621 init, destroy, "lttvwindow")
622
This page took 0.049137 seconds and 4 git commands to generate.