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