empty filter field removes filter
[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{
f88c5bfa 152 g_debug("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"));
ffd088ef 185 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.facility"));
2b715e58 186 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.category"));
187 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.time"));
188 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.tsc"));
189 /*
190 * TODO: Add core.xml fields here !
191 */
192 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("tracefile.name"));
193 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("trace.name"));
4f85064b 194 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_name"));
2b715e58 195 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.pid"));
196 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.ppid"));
197 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.creation_time"));
198 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.insertion_time"));
199 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_mode"));
200 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_submode"));
201 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_status"));
202 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.cpu"));
203
204 fvd->f_math_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,7);
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 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
213
6a4f1205 214 fvd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
215
4ed9b7ba 216 /*
217 * Initiating GtkTable layout
218 * starts with 2 rows and 5 columns and
219 * expands when expressions added
220 */
1f7f7fe2 221 fvd->f_main_box = gtk_table_new(3,7,FALSE);
4ed9b7ba 222 gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5);
223 gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5);
91ad3f0a 224
6a4f1205 225 gtk_container_add(GTK_CONTAINER(fvd->f_window), GTK_WIDGET(fvd->f_main_box));
226
4ed9b7ba 227 /*
228 * First half of the filter window
229 * - textual entry of filter expression
230 * - processing button
231 */
232 fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL);
c2774e9d 233// gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0");
4ed9b7ba 234 gtk_widget_show (fvd->f_expression_field);
235
c2774e9d 236 g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed",
237 G_CALLBACK (callback_expression_field), (gpointer) fvd);
238
4ed9b7ba 239 fvd->f_process_button = gtk_button_new_with_label("Process");
240 gtk_widget_show (fvd->f_process_button);
241
c2774e9d 242 g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked",
243 G_CALLBACK (callback_process_button), (gpointer) fvd);
244
1f7f7fe2 245 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0);
246 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0);
c2774e9d 247
248
4ed9b7ba 249
250 /*
251 * Second half of the filter window
252 * - combo boxes featuring filtering options added to the expression
253 */
c2774e9d 254 fvd->f_add_button = gtk_button_new_with_label("Add Expression");
255 gtk_widget_show (fvd->f_add_button);
256
257 g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked",
258 G_CALLBACK (callback_add_button), (gpointer) fvd);
4ed9b7ba 259
1f7f7fe2 260 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0);
c2774e9d 261
262 fvd->f_logical_op_junction_box = gtk_combo_box_new_text();
2b715e58 263 for(i=0;i<fvd->f_logical_op_options->len;i++) {
264 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
265 gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str);
266 }
267 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
268
c2774e9d 269 //gtk_widget_show(fvd->f_logical_op_box);
2b99ec10 270
c2774e9d 271 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);
272
203eb6f7 273 gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1);
274
c2774e9d 275 /* initialize a new line */
276 fvd->f_lines = g_ptr_array_new();
277 fvd->rows = 1;
278 FilterViewerDataLine* fvdl = gui_filter_add_line(fvd);
279 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl);
4ed9b7ba 280
c2774e9d 281 /*
282 * show main container
283 */
4ed9b7ba 284 gtk_widget_show(fvd->f_main_box);
6a4f1205 285 gtk_widget_show(fvd->f_window);
4ed9b7ba 286
91ad3f0a 287
288 g_object_set_data_full(
289 G_OBJECT(guifilter_get_widget(fvd)),
290 "filter_viewer_data",
291 fvd,
292 (GDestroyNotify)gui_filter_destructor);
293
0fc64e11 294 g_filter_list = g_slist_append(
295 g_filter_list,
296 fvd);
4ed9b7ba 297
91ad3f0a 298 return fvd;
299}
300
c2774e9d 301/**
7e7af7f2 302 * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*)
852f16bb 303 *
c2774e9d 304 * Adds a filter option line on the module tab
305 * @param fvd The filter module structure
306 * @return The line structure
307 */
308FilterViewerDataLine*
309gui_filter_add_line(FilterViewerData* fvd) {
310
311 FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1);
312
2b715e58 313 unsigned i;
c2774e9d 314 fvdl->row = fvd->rows;
315 fvdl->visible = TRUE;
2b715e58 316
1f7f7fe2 317 fvdl->f_not_op_box = gtk_combo_box_new_text();
318 for(i=0;i<fvd->f_not_op_options->len;i++) {
319 GString* s = g_ptr_array_index(fvd->f_not_op_options,i);
320 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str);
321 }
322
2b715e58 323 fvdl->f_field_box = gtk_combo_box_new_text();
324 for(i=0;i<fvd->f_field_options->len;i++) {
325 GString* s = g_ptr_array_index(fvd->f_field_options,i);
1f7f7fe2 326// g_print("String field: %s\n",s->str);
2b715e58 327 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str);
328 }
329
330 fvdl->f_math_op_box = gtk_combo_box_new_text();
331 for(i=0;i<fvd->f_math_op_options->len;i++) {
332 GString* s = g_ptr_array_index(fvd->f_math_op_options,i);
333 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str);
334 }
335
c2774e9d 336 fvdl->f_value_field = gtk_entry_new();
c2774e9d 337
338 fvdl->f_logical_op_box = gtk_combo_box_new_text();
2b715e58 339 for(i=0;i<fvd->f_logical_op_options->len;i++) {
340 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
341 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str);
342 }
c2774e9d 343 gtk_widget_set_events(fvdl->f_logical_op_box,
344 GDK_ENTER_NOTIFY_MASK |
345 GDK_LEAVE_NOTIFY_MASK |
346 GDK_FOCUS_CHANGE_MASK);
347
348 g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed",
349 G_CALLBACK (callback_logical_op_box), (gpointer) fvd);
2b715e58 350
351 gui_filter_line_reset(fvdl);
352 gui_filter_line_set_visible(fvdl,TRUE);
c2774e9d 353
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
852f16bb 363/**
7e7af7f2 364 * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean)
852f16bb 365 *
366 * Change visible state of current FilterViewerDataLine
367 * @param fvdl pointer to the current FilterViewerDataLine
368 * @param v TRUE: sets visible, FALSE: sets invisible
369 */
7e7af7f2 370void
371gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) {
c2774e9d 372
373 fvdl->visible = v;
374 if(v) {
1f7f7fe2 375 gtk_widget_show(fvdl->f_not_op_box);
2b715e58 376 gtk_widget_show(fvdl->f_field_box);
c2774e9d 377 gtk_widget_show(fvdl->f_math_op_box);
378 gtk_widget_show(fvdl->f_value_field);
379 gtk_widget_show(fvdl->f_logical_op_box);
380 } else {
1f7f7fe2 381 gtk_widget_hide(fvdl->f_not_op_box);
2b715e58 382 gtk_widget_hide(fvdl->f_field_box);
c2774e9d 383 gtk_widget_hide(fvdl->f_math_op_box);
384 gtk_widget_hide(fvdl->f_value_field);
385 gtk_widget_hide(fvdl->f_logical_op_box);
386 }
387
388}
389
852f16bb 390/**
7e7af7f2 391 * @fn void gui_filter_line_reset(FilterViewerDataLine*)
852f16bb 392 *
393 * Sets selections of all boxes in current FilterViewerDataLine
394 * to default value (0)
395 * @param fvdl pointer to current FilterViewerDataLine
396 */
7e7af7f2 397void
398gui_filter_line_reset(FilterViewerDataLine *fvdl) {
c2774e9d 399
1f7f7fe2 400 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0);
2b715e58 401 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0);
c2774e9d 402 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0);
da2e1bfb 403 gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),"");
c2774e9d 404 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0);
405}
406
407/**
7e7af7f2 408 * @fn void gui_filter_destructor(FilterViewerData*)
852f16bb 409 *
c2774e9d 410 * Destructor for the filter gui module
411 * @param fvd The module structure
412 */
91ad3f0a 413void
414gui_filter_destructor(FilterViewerData *fvd)
415{
416 Tab *tab = fvd->tab;
417
418 /* May already been done by GTK window closing */
419 if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){
420 g_info("widget still exists");
421 }
da2e1bfb 422// if(tab != NULL) {
423// lttvwindow_unregister_traceset_notify(fvd->tab,
424// filter_traceset_changed,
425// filter_viewer_data);
426// }
91ad3f0a 427 lttvwindowtraces_background_notify_remove(fvd);
0fc64e11 428
429 g_filter_list = g_slist_remove(g_filter_list, fvd);
6a4f1205 430
431 main_window_remove_child_window(tab, fvd->name);
432
433 g_free(fvd->name);
0fc64e11 434
91ad3f0a 435 g_free(fvd);
436}
437
91ad3f0a 438
439/**
7e7af7f2 440 * @fn GtkWidget* h_guifilter(Tab*)
852f16bb 441 *
442 * Filter Module's constructor hook
91ad3f0a 443 *
852f16bb 444 * This constructor is given as a parameter to the menuitem and toolbar button
445 * registration. It creates the list.
446 * @param tab A pointer to the parent window.
447 * @return The widget created.
91ad3f0a 448 */
449GtkWidget *
2b99ec10 450h_guifilter(Tab *tab)
91ad3f0a 451{
452 FilterViewerData* f = gui_filter(tab) ;
6a4f1205 453 f->name = g_new(gchar, 256);
454
455 snprintf(f->name, 256, "guifilter %p", f);
91ad3f0a 456
457 if(f)
6a4f1205 458 main_window_add_child_window(tab, f,
459 f->name, (GDestroyNotify)gui_filter_destructor);
460 return NULL;
91ad3f0a 461
462}
463
91ad3f0a 464/**
7e7af7f2 465 * @fn static void init()
852f16bb 466 *
467 * This function initializes the Filter Viewer functionnality through the
468 * gtkTraceSet API.
91ad3f0a 469 */
470static void init() {
471
472 lttvwindow_register_constructor("guifilter",
473 "/",
474 "Insert Filter Module",
475 hGuiFilterInsert_xpm,
476 "Insert Filter Module",
2b99ec10 477 h_guifilter);
91ad3f0a 478}
479
c2774e9d 480/**
7e7af7f2 481 * @fn void filter_destroy_walk(gpointer,gpointer)
852f16bb 482 *
c2774e9d 483 * Initiate the destruction of the current gui module
484 * on the GTK Interface
485 */
7e7af7f2 486void
487filter_destroy_walk(gpointer data, gpointer user_data)
91ad3f0a 488{
489 FilterViewerData *fvd = (FilterViewerData*)data;
490
c2774e9d 491 g_debug("CFV.c : filter_destroy_walk, %p", fvd);
da2e1bfb 492
91ad3f0a 493 /* May already have been done by GTK window closing */
494 if(GTK_IS_WIDGET(guifilter_get_widget(fvd)))
495 gtk_widget_destroy(guifilter_get_widget(fvd));
496}
497
498/**
7e7af7f2 499 * @fn static void destroy()
852f16bb 500 * @brief plugin's destroy function
91ad3f0a 501 *
852f16bb 502 * This function releases the memory reserved by the module and unregisters
503 * everything that has been registered in the gtkTraceSet API.
91ad3f0a 504 */
505static void destroy() {
0fc64e11 506
507 g_slist_foreach(g_filter_list, filter_destroy_walk, NULL );
91ad3f0a 508
2b99ec10 509 lttvwindow_unregister_constructor(h_guifilter);
91ad3f0a 510
511}
512
c2774e9d 513/**
7e7af7f2 514 * @fn void callback_process_button(GtkWidget*,gpointer)
852f16bb 515 *
c2774e9d 516 * The Process Button callback function
517 * @param widget The Button widget passed to the callback function
518 * @param data Data sent along with the callback function
519 */
7e7af7f2 520void
521callback_process_button(GtkWidget *widget, gpointer data) {
c2774e9d 522
da2e1bfb 523 g_debug("callback_process_button(): Processing expression");
524
c2774e9d 525 FilterViewerData *fvd = (FilterViewerData*)data;
064565c5 526 LttvFilter* filter;
c2774e9d 527
1f7f7fe2 528 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
064565c5 529 filter = lttv_filter_new();
da2e1bfb 530 GString* s = g_string_new(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
531 lttv_filter_append_expression(filter,s->str);
532 g_string_free(s,TRUE);
a998b781 533 //SetFilter(fvd->tab,filter);
064565c5 534 } else {
535 filter = NULL;
1f7f7fe2 536 }
064565c5 537 lttvwindow_report_filter(fvd->tab, filter);
c2774e9d 538}
539
540/**
7e7af7f2 541 * @fn void callback_expression_field(GtkWidget*,gpointer)
852f16bb 542 *
c2774e9d 543 * The Add Button callback function
544 * @param widget The Button widget passed to the callback function
545 * @param data Data sent along with the callback function
546 */
7e7af7f2 547void
548callback_expression_field(GtkWidget *widget, gpointer data) {
da2e1bfb 549
c2774e9d 550 FilterViewerData *fvd = (FilterViewerData*)data;
551
552 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
553 gtk_widget_show(fvd->f_logical_op_junction_box);
554 } else {
555 gtk_widget_hide(fvd->f_logical_op_junction_box);
556 }
557}
558
559
560/**
7e7af7f2 561 * @fn void callback_add_button(GtkWidget*,gpointer)
852f16bb 562 *
c2774e9d 563 * The Add Button callback function
564 * @param widget The Button widget passed to the callback function
565 * @param data Data sent along with the callback function
566 */
7e7af7f2 567void
568callback_add_button(GtkWidget *widget, gpointer data) {
c2774e9d 569
da2e1bfb 570 g_debug("callback_add_button(): processing simple expressions");
c2774e9d 571
da2e1bfb 572 unsigned i;
573
c2774e9d 574 FilterViewerData *fvd = (FilterViewerData*)data;
575 FilterViewerDataLine *fvdl = NULL;
576 GString* a_filter_string = g_string_new("");
2b715e58 577
da2e1bfb 578 /*
579 * adding linking operator to
580 * string
581 */
2b715e58 582 GString* s;
583 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 584 g_string_append(a_filter_string,s->str);
da2e1bfb 585 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
c2774e9d 586
da2e1bfb 587 /* begin expression */
2b715e58 588 g_string_append_c(a_filter_string,'(');
589
da2e1bfb 590 /*
591 * For each simple expression, add the resulting string
592 * to the filter string
593 *
594 * Each simple expression takes the following schema
595 * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value]
596 */
c2774e9d 597 for(i=0;i<fvd->f_lines->len;i++) {
598 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
1f7f7fe2 599
600 s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box)));
601 g_string_append(a_filter_string,s->str);
2b715e58 602
603 s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box)));
604 g_string_append(a_filter_string,s->str);
605
606 s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box)));
607 g_string_append(a_filter_string,s->str);
608
609 g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field)));
610
611 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)));
612 g_string_append(a_filter_string,s->str);
613
da2e1bfb 614 /*
615 * resetting simple expression lines
616 */
c2774e9d 617 gui_filter_line_reset(fvdl);
2b715e58 618 if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line
c2774e9d 619 }
620
da2e1bfb 621 /* end expression */
2b715e58 622 g_string_append_c(a_filter_string,')');
c2774e9d 623
2b715e58 624 g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
625 gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str);
c2774e9d 626
627}
628
629/**
7e7af7f2 630 * @fn void callback_logical_op_box(GtkWidget*,gpointer)
852f16bb 631 *
c2774e9d 632 * The logical op box callback function
633 * @param widget The Button widget passed to the callback function
634 * @param data Data sent along with the callback function
635 */
7e7af7f2 636void
637callback_logical_op_box(GtkWidget *widget, gpointer data) {
c2774e9d 638
da2e1bfb 639 g_debug("callback_logical_op_box(): adding new simple expression");
c2774e9d 640
641 FilterViewerData *fvd = (FilterViewerData*)data;
642 FilterViewerDataLine *fvdl = NULL;
643
644 int i;
645 for(i=0;i<fvd->f_lines->len;i++) {
646 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
647 if(fvdl->f_logical_op_box == widget) {
da2e1bfb 648 if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return;
c2774e9d 649 if(i==fvd->f_lines->len-1) { /* create a new line */
650 fvd->rows++;
651 FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd);
652 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2);
653 } else {
654 FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1);
655 if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE);
656 }
657 }
658 }
659
660}
91ad3f0a 661
662LTTV_MODULE("guifilter", "Filter window", \
663 "Graphical module that let user specify their filtering options", \
664 init, destroy, "lttvwindow")
665
This page took 0.05531 seconds and 4 git commands to generate.