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