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