print debug
[lttv.git] / ltt / branches / poly / lttv / modules / gui / filter / filter.c
CommitLineData
91ad3f0a 1/* This file is part of the Linux Trace Toolkit viewer
852f16bb 2 * Copyright (C) 2005 Simon Bouvier-Zappa
91ad3f0a 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
4e4d11b3 19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
91ad3f0a 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
0fc64e11 38
39GSList *g_filter_list = NULL ;
40
7e7af7f2 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 *
da2e1bfb 50 * \note The version of gtk-2.0 currently installed on
7e7af7f2 51 * my desktop misses some function of the newer
da2e1bfb 52 * gtk+ api. For the time being, I'll use the older api
7e7af7f2 53 * to keep compatibility with most systems.
2b715e58 54 */
55
91ad3f0a 56typedef struct _FilterViewerData FilterViewerData;
c2774e9d 57typedef struct _FilterViewerDataLine FilterViewerDataLine;
91ad3f0a 58
4ed9b7ba 59/*
60 * Prototypes
61 */
91ad3f0a 62GtkWidget *guifilter_get_widget(FilterViewerData *fvd);
63FilterViewerData *gui_filter(Tab *tab);
64void gui_filter_destructor(FilterViewerData *fvd);
c2774e9d 65FilterViewerDataLine* gui_filter_add_line(FilterViewerData *fvd);
66void gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v);
67void gui_filter_line_reset(FilterViewerDataLine *fvdl);
2b99ec10 68GtkWidget* h_guifilter(Tab *tab);
c2774e9d 69void filter_destroy_walk(gpointer data, gpointer user_data);
91ad3f0a 70
c2774e9d 71/*
72 * Callback functions
73 */
74void callback_process_button(GtkWidget *widget, gpointer data);
75void callback_add_button(GtkWidget *widget, gpointer data);
76void callback_logical_op_box(GtkWidget *widget, gpointer data);
77void callback_expression_field(GtkWidget *widget, gpointer data);
78
852f16bb 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 */
c2774e9d 87struct _FilterViewerDataLine {
7e7af7f2 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) */
c2774e9d 95};
96
97/**
7e7af7f2 98 * @struct _FilterViewerData
99 *
100 * @brief Main structure of gui filter
101 * Main struct for the filter gui module
c2774e9d 102 */
91ad3f0a 103struct _FilterViewerData {
7e7af7f2 104 Tab *tab; /**< current tab of module */
91ad3f0a 105
6a4f1205 106 GtkWidget *f_window; /**< filter window */
107
7e7af7f2 108 GtkWidget *f_main_box; /**< main container */
4ed9b7ba 109
7e7af7f2 110 GtkWidget *f_expression_field; /**< entire expression (GtkEntry) */
111 GtkWidget *f_process_button; /**< process expression button (GtkButton) */
4ed9b7ba 112
7e7af7f2 113 GtkWidget *f_logical_op_junction_box; /**< linking operator box (GtkComboBox) */
4ed9b7ba 114
7e7af7f2 115 int rows; /**< number of rows */
116 GPtrArray *f_lines; /**< array of FilterViewerDataLine */
2b715e58 117
7e7af7f2 118 GPtrArray *f_not_op_options; /**< array of operators types for not_op box */
119 GPtrArray *f_logical_op_options; /**< array of operators types for logical_op box */
120 GPtrArray *f_field_options; /**< array of field types for field box */
121 GPtrArray *f_math_op_options; /**< array of operators types for math_op box */
2b715e58 122
7e7af7f2 123 GtkWidget *f_add_button; /**< add expression to current expression (GtkButton) */
6a4f1205 124
125 gchar *name; /**< Name of the window in the main window */
91ad3f0a 126};
127
c2774e9d 128/**
7e7af7f2 129 * @fn GtkWidget* guifilter_get_widget(FilterViewerData*)
852f16bb 130 *
c2774e9d 131 * This function returns the current main widget
132 * used by this module
133 * @param fvd the module struct
134 * @return The main widget
135 */
7e7af7f2 136GtkWidget*
137guifilter_get_widget(FilterViewerData *fvd)
91ad3f0a 138{
01eb9889 139 return fvd->f_window;
91ad3f0a 140}
141
142/**
7e7af7f2 143 * @fn FilterViewerData* gui_filter(Tab*)
852f16bb 144 *
145 * Constructor is used to create FilterViewerData data structure.
7e7af7f2 146 * @param tab The tab structure used by the widget
852f16bb 147 * @return The Filter viewer data created.
91ad3f0a 148 */
149FilterViewerData*
150gui_filter(Tab *tab)
151{
4ed9b7ba 152 g_print("filter::gui_filter()");
2b715e58 153
154 unsigned i;
91ad3f0a 155 GtkCellRenderer *renderer;
156 GtkTreeViewColumn *column;
157
158 FilterViewerData* fvd = g_new(FilterViewerData,1);
159
160 fvd->tab = tab;
161
da2e1bfb 162// lttvwindow_register_traceset_notify(fvd->tab,
163// filter_traceset_changed,
164// filter_viewer_data);
91ad3f0a 165// request_background_data(filter_viewer_data);
4ed9b7ba 166
2b715e58 167 /*
168 * Initiating items for
169 * combo boxes
170 */
1f7f7fe2 171 fvd->f_not_op_options = g_ptr_array_new();
172 g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new(""));
173 g_ptr_array_add(fvd->f_not_op_options,(gpointer) g_string_new("!"));
174
2b715e58 175 fvd->f_logical_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,sizeof(gchar));
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 g_ptr_array_add(fvd->f_logical_op_options,(gpointer) g_string_new("|"));
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
182 fvd->f_field_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,16);
183 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new(""));
184 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.name"));
185 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.category"));
186 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.time"));
187 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.tsc"));
188 /*
189 * TODO: Add core.xml fields here !
190 */
191 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("tracefile.name"));
192 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("trace.name"));
193 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.pid"));
194 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.ppid"));
195 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.creation_time"));
196 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.insertion_time"));
197 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_mode"));
198 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_submode"));
199 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_status"));
200 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.cpu"));
201
202 fvd->f_math_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,7);
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 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new("<="));
208 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">"));
209 g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">="));
210
211
6a4f1205 212 fvd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
213
4ed9b7ba 214 /*
215 * Initiating GtkTable layout
216 * starts with 2 rows and 5 columns and
217 * expands when expressions added
218 */
1f7f7fe2 219 fvd->f_main_box = gtk_table_new(3,7,FALSE);
4ed9b7ba 220 gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5);
221 gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5);
91ad3f0a 222
6a4f1205 223 gtk_container_add(GTK_CONTAINER(fvd->f_window), GTK_WIDGET(fvd->f_main_box));
224
4ed9b7ba 225 /*
226 * First half of the filter window
227 * - textual entry of filter expression
228 * - processing button
229 */
230 fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL);
c2774e9d 231// gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0");
4ed9b7ba 232 gtk_widget_show (fvd->f_expression_field);
233
c2774e9d 234 g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed",
235 G_CALLBACK (callback_expression_field), (gpointer) fvd);
236
4ed9b7ba 237 fvd->f_process_button = gtk_button_new_with_label("Process");
238 gtk_widget_show (fvd->f_process_button);
239
c2774e9d 240 g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked",
241 G_CALLBACK (callback_process_button), (gpointer) fvd);
242
1f7f7fe2 243 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0);
244 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0);
c2774e9d 245
246
4ed9b7ba 247
248 /*
249 * Second half of the filter window
250 * - combo boxes featuring filtering options added to the expression
251 */
c2774e9d 252 fvd->f_add_button = gtk_button_new_with_label("Add Expression");
253 gtk_widget_show (fvd->f_add_button);
254
255 g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked",
256 G_CALLBACK (callback_add_button), (gpointer) fvd);
4ed9b7ba 257
1f7f7fe2 258 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0);
c2774e9d 259
260 fvd->f_logical_op_junction_box = gtk_combo_box_new_text();
2b715e58 261 for(i=0;i<fvd->f_logical_op_options->len;i++) {
262 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
263 gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str);
264 }
265 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
266
c2774e9d 267 //gtk_widget_show(fvd->f_logical_op_box);
2b99ec10 268
c2774e9d 269 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);
270
203eb6f7 271 gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1);
272
c2774e9d 273 /* initialize a new line */
274 fvd->f_lines = g_ptr_array_new();
275 fvd->rows = 1;
276 FilterViewerDataLine* fvdl = gui_filter_add_line(fvd);
277 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl);
4ed9b7ba 278
c2774e9d 279 /*
280 * show main container
281 */
4ed9b7ba 282 gtk_widget_show(fvd->f_main_box);
6a4f1205 283 gtk_widget_show(fvd->f_window);
4ed9b7ba 284
91ad3f0a 285
286 g_object_set_data_full(
287 G_OBJECT(guifilter_get_widget(fvd)),
288 "filter_viewer_data",
289 fvd,
290 (GDestroyNotify)gui_filter_destructor);
291
0fc64e11 292 g_filter_list = g_slist_append(
293 g_filter_list,
294 fvd);
4ed9b7ba 295
91ad3f0a 296 return fvd;
297}
298
c2774e9d 299/**
7e7af7f2 300 * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*)
852f16bb 301 *
c2774e9d 302 * Adds a filter option line on the module tab
303 * @param fvd The filter module structure
304 * @return The line structure
305 */
306FilterViewerDataLine*
307gui_filter_add_line(FilterViewerData* fvd) {
308
309 FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1);
310
2b715e58 311 unsigned i;
c2774e9d 312 fvdl->row = fvd->rows;
313 fvdl->visible = TRUE;
2b715e58 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
1f7f7fe2 352 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);
353 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);
354 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);
355 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);
356 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 357
358 return fvdl;
359}
360
852f16bb 361/**
7e7af7f2 362 * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean)
852f16bb 363 *
364 * Change visible state of current FilterViewerDataLine
365 * @param fvdl pointer to the current FilterViewerDataLine
366 * @param v TRUE: sets visible, FALSE: sets invisible
367 */
7e7af7f2 368void
369gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) {
c2774e9d 370
371 fvdl->visible = v;
372 if(v) {
1f7f7fe2 373 gtk_widget_show(fvdl->f_not_op_box);
2b715e58 374 gtk_widget_show(fvdl->f_field_box);
c2774e9d 375 gtk_widget_show(fvdl->f_math_op_box);
376 gtk_widget_show(fvdl->f_value_field);
377 gtk_widget_show(fvdl->f_logical_op_box);
378 } else {
1f7f7fe2 379 gtk_widget_hide(fvdl->f_not_op_box);
2b715e58 380 gtk_widget_hide(fvdl->f_field_box);
c2774e9d 381 gtk_widget_hide(fvdl->f_math_op_box);
382 gtk_widget_hide(fvdl->f_value_field);
383 gtk_widget_hide(fvdl->f_logical_op_box);
384 }
385
386}
387
852f16bb 388/**
7e7af7f2 389 * @fn void gui_filter_line_reset(FilterViewerDataLine*)
852f16bb 390 *
391 * Sets selections of all boxes in current FilterViewerDataLine
392 * to default value (0)
393 * @param fvdl pointer to current FilterViewerDataLine
394 */
7e7af7f2 395void
396gui_filter_line_reset(FilterViewerDataLine *fvdl) {
c2774e9d 397
1f7f7fe2 398 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0);
2b715e58 399 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0);
c2774e9d 400 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0);
da2e1bfb 401 gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),"");
c2774e9d 402 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0);
403}
404
405/**
7e7af7f2 406 * @fn void gui_filter_destructor(FilterViewerData*)
852f16bb 407 *
c2774e9d 408 * Destructor for the filter gui module
409 * @param fvd The module structure
410 */
91ad3f0a 411void
412gui_filter_destructor(FilterViewerData *fvd)
413{
414 Tab *tab = fvd->tab;
415
416 /* May already been done by GTK window closing */
417 if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){
418 g_info("widget still exists");
419 }
da2e1bfb 420// if(tab != NULL) {
421// lttvwindow_unregister_traceset_notify(fvd->tab,
422// filter_traceset_changed,
423// filter_viewer_data);
424// }
91ad3f0a 425 lttvwindowtraces_background_notify_remove(fvd);
0fc64e11 426
427 g_filter_list = g_slist_remove(g_filter_list, fvd);
6a4f1205 428
429 main_window_remove_child_window(tab, fvd->name);
430
431 g_free(fvd->name);
0fc64e11 432
91ad3f0a 433 g_free(fvd);
434}
435
91ad3f0a 436
437/**
7e7af7f2 438 * @fn GtkWidget* h_guifilter(Tab*)
852f16bb 439 *
440 * Filter Module's constructor hook
91ad3f0a 441 *
852f16bb 442 * This constructor is given as a parameter to the menuitem and toolbar button
443 * registration. It creates the list.
444 * @param tab A pointer to the parent window.
445 * @return The widget created.
91ad3f0a 446 */
447GtkWidget *
2b99ec10 448h_guifilter(Tab *tab)
91ad3f0a 449{
450 FilterViewerData* f = gui_filter(tab) ;
6a4f1205 451 f->name = g_new(gchar, 256);
452
453 snprintf(f->name, 256, "guifilter %p", f);
91ad3f0a 454
455 if(f)
6a4f1205 456 main_window_add_child_window(tab, f,
457 f->name, (GDestroyNotify)gui_filter_destructor);
458 return NULL;
91ad3f0a 459
460}
461
91ad3f0a 462/**
7e7af7f2 463 * @fn static void init()
852f16bb 464 *
465 * This function initializes the Filter Viewer functionnality through the
466 * gtkTraceSet API.
91ad3f0a 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/**
7e7af7f2 479 * @fn void filter_destroy_walk(gpointer,gpointer)
852f16bb 480 *
c2774e9d 481 * Initiate the destruction of the current gui module
482 * on the GTK Interface
483 */
7e7af7f2 484void
485filter_destroy_walk(gpointer data, gpointer user_data)
91ad3f0a 486{
487 FilterViewerData *fvd = (FilterViewerData*)data;
488
c2774e9d 489 g_debug("CFV.c : filter_destroy_walk, %p", fvd);
da2e1bfb 490
91ad3f0a 491 /* May already have been done by GTK window closing */
492 if(GTK_IS_WIDGET(guifilter_get_widget(fvd)))
493 gtk_widget_destroy(guifilter_get_widget(fvd));
494}
495
496/**
7e7af7f2 497 * @fn static void destroy()
852f16bb 498 * @brief plugin's destroy function
91ad3f0a 499 *
852f16bb 500 * This function releases the memory reserved by the module and unregisters
501 * everything that has been registered in the gtkTraceSet API.
91ad3f0a 502 */
503static void destroy() {
0fc64e11 504
505 g_slist_foreach(g_filter_list, filter_destroy_walk, NULL );
91ad3f0a 506
2b99ec10 507 lttvwindow_unregister_constructor(h_guifilter);
91ad3f0a 508
509}
510
c2774e9d 511/**
7e7af7f2 512 * @fn void callback_process_button(GtkWidget*,gpointer)
852f16bb 513 *
c2774e9d 514 * The Process Button callback function
515 * @param widget The Button widget passed to the callback function
516 * @param data Data sent along with the callback function
517 */
7e7af7f2 518void
519callback_process_button(GtkWidget *widget, gpointer data) {
c2774e9d 520
da2e1bfb 521 g_debug("callback_process_button(): Processing expression");
522
c2774e9d 523 FilterViewerData *fvd = (FilterViewerData*)data;
524
1f7f7fe2 525 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
526 LttvFilter* filter = lttv_filter_new();
da2e1bfb 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);
a998b781 530 //SetFilter(fvd->tab,filter);
531 lttvwindow_report_filter(fvd->tab, filter);
1f7f7fe2 532 }
c2774e9d 533}
534
535/**
7e7af7f2 536 * @fn void callback_expression_field(GtkWidget*,gpointer)
852f16bb 537 *
c2774e9d 538 * The Add Button callback function
539 * @param widget The Button widget passed to the callback function
540 * @param data Data sent along with the callback function
541 */
7e7af7f2 542void
543callback_expression_field(GtkWidget *widget, gpointer data) {
da2e1bfb 544
c2774e9d 545 FilterViewerData *fvd = (FilterViewerData*)data;
546
547 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
548 gtk_widget_show(fvd->f_logical_op_junction_box);
549 } else {
550 gtk_widget_hide(fvd->f_logical_op_junction_box);
551 }
552}
553
554
555/**
7e7af7f2 556 * @fn void callback_add_button(GtkWidget*,gpointer)
852f16bb 557 *
c2774e9d 558 * The Add Button callback function
559 * @param widget The Button widget passed to the callback function
560 * @param data Data sent along with the callback function
561 */
7e7af7f2 562void
563callback_add_button(GtkWidget *widget, gpointer data) {
c2774e9d 564
da2e1bfb 565 g_debug("callback_add_button(): processing simple expressions");
c2774e9d 566
da2e1bfb 567 unsigned i;
568
c2774e9d 569 FilterViewerData *fvd = (FilterViewerData*)data;
570 FilterViewerDataLine *fvdl = NULL;
571 GString* a_filter_string = g_string_new("");
2b715e58 572
da2e1bfb 573 /*
574 * adding linking operator to
575 * string
576 */
2b715e58 577 GString* s;
578 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box)));
2b715e58 579 g_string_append(a_filter_string,s->str);
da2e1bfb 580 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
c2774e9d 581
da2e1bfb 582 /* begin expression */
2b715e58 583 g_string_append_c(a_filter_string,'(');
584
da2e1bfb 585 /*
586 * For each simple expression, add the resulting string
587 * to the filter string
588 *
589 * Each simple expression takes the following schema
590 * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value]
591 */
c2774e9d 592 for(i=0;i<fvd->f_lines->len;i++) {
593 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
1f7f7fe2 594
595 s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box)));
596 g_string_append(a_filter_string,s->str);
2b715e58 597
598 s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box)));
599 g_string_append(a_filter_string,s->str);
600
601 s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box)));
602 g_string_append(a_filter_string,s->str);
603
604 g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field)));
605
606 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)));
607 g_string_append(a_filter_string,s->str);
608
da2e1bfb 609 /*
610 * resetting simple expression lines
611 */
c2774e9d 612 gui_filter_line_reset(fvdl);
2b715e58 613 if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line
c2774e9d 614 }
615
da2e1bfb 616 /* end expression */
2b715e58 617 g_string_append_c(a_filter_string,')');
c2774e9d 618
2b715e58 619 g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
620 gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str);
c2774e9d 621
622}
623
624/**
7e7af7f2 625 * @fn void callback_logical_op_box(GtkWidget*,gpointer)
852f16bb 626 *
c2774e9d 627 * The logical op box callback function
628 * @param widget The Button widget passed to the callback function
629 * @param data Data sent along with the callback function
630 */
7e7af7f2 631void
632callback_logical_op_box(GtkWidget *widget, gpointer data) {
c2774e9d 633
da2e1bfb 634 g_debug("callback_logical_op_box(): adding new simple expression");
c2774e9d 635
636 FilterViewerData *fvd = (FilterViewerData*)data;
637 FilterViewerDataLine *fvdl = NULL;
638
639 int i;
640 for(i=0;i<fvd->f_lines->len;i++) {
641 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
642 if(fvdl->f_logical_op_box == widget) {
da2e1bfb 643 if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return;
c2774e9d 644 if(i==fvd->f_lines->len-1) { /* create a new line */
645 fvd->rows++;
646 FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd);
647 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2);
648 } else {
649 FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1);
650 if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE);
651 }
652 }
653 }
654
655}
91ad3f0a 656
657LTTV_MODULE("guifilter", "Filter window", \
658 "Graphical module that let user specify their filtering options", \
659 init, destroy, "lttvwindow")
660
This page took 0.05516 seconds and 4 git commands to generate.