update compat
[lttv.git] / tags / LinuxTraceToolkitViewer-0.10.0-pre-115102007 / 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);
e433e6d6 64FilterViewerData *gui_filter(LttvPlugin *plugin);
91ad3f0a 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);
e433e6d6 69GtkWidget* h_guifilter(LttvPlugin *plugin);
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);
2422ba7b 82void callback_cancel_button(GtkWidget *widget, gpointer data);
c2774e9d 83
852f16bb 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 */
c2774e9d 92struct _FilterViewerDataLine {
7e7af7f2 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) */
c2774e9d 100};
101
102/**
7e7af7f2 103 * @struct _FilterViewerData
104 *
105 * @brief Main structure of gui filter
106 * Main struct for the filter gui module
c2774e9d 107 */
91ad3f0a 108struct _FilterViewerData {
e433e6d6 109 LttvPlugin *plugin; /**< Plugin on which we interact. */
91ad3f0a 110
6a4f1205 111 GtkWidget *f_window; /**< filter window */
112
7e7af7f2 113 GtkWidget *f_main_box; /**< main container */
4ed9b7ba 114
7e7af7f2 115 GtkWidget *f_expression_field; /**< entire expression (GtkEntry) */
116 GtkWidget *f_process_button; /**< process expression button (GtkButton) */
4ed9b7ba 117
7e7af7f2 118 GtkWidget *f_logical_op_junction_box; /**< linking operator box (GtkComboBox) */
4ed9b7ba 119
7e7af7f2 120 int rows; /**< number of rows */
121 GPtrArray *f_lines; /**< array of FilterViewerDataLine */
2b715e58 122
7e7af7f2 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 */
2b715e58 127
7e7af7f2 128 GtkWidget *f_add_button; /**< add expression to current expression (GtkButton) */
2422ba7b 129 GtkWidget *f_cancel_button; /**< cancel and close dialog (GtkButton) */
6a4f1205 130
91ad3f0a 131};
132
c2774e9d 133/**
7e7af7f2 134 * @fn GtkWidget* guifilter_get_widget(FilterViewerData*)
852f16bb 135 *
c2774e9d 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 */
7e7af7f2 141GtkWidget*
142guifilter_get_widget(FilterViewerData *fvd)
91ad3f0a 143{
01eb9889 144 return fvd->f_window;
91ad3f0a 145}
146
147/**
7e7af7f2 148 * @fn FilterViewerData* gui_filter(Tab*)
852f16bb 149 *
150 * Constructor is used to create FilterViewerData data structure.
7e7af7f2 151 * @param tab The tab structure used by the widget
852f16bb 152 * @return The Filter viewer data created.
91ad3f0a 153 */
154FilterViewerData*
e433e6d6 155gui_filter(LttvPlugin *plugin)
91ad3f0a 156{
f88c5bfa 157 g_debug("filter::gui_filter()");
2b715e58 158
159 unsigned i;
91ad3f0a 160 GtkCellRenderer *renderer;
161 GtkTreeViewColumn *column;
162
163 FilterViewerData* fvd = g_new(FilterViewerData,1);
164
e433e6d6 165 fvd->plugin = plugin;
91ad3f0a 166
da2e1bfb 167// lttvwindow_register_traceset_notify(fvd->tab,
168// filter_traceset_changed,
169// filter_viewer_data);
91ad3f0a 170// request_background_data(filter_viewer_data);
4ed9b7ba 171
2b715e58 172 /*
173 * Initiating items for
174 * combo boxes
175 */
1f7f7fe2 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
2b715e58 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"));
ffd088ef 190 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.facility"));
2b715e58 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"));
33bdc8dd 194 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.target_pid"));
2b715e58 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"));
4f85064b 200 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_name"));
7b5f6cf1 201 g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.thread_brand"));
2b715e58 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
6a4f1205 221 fvd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
294a2716 222 gtk_window_set_title(GTK_WINDOW(fvd->f_window), "LTTV Filter");
93ac601b 223 gtk_window_set_transient_for(GTK_WINDOW(fvd->f_window),
e433e6d6 224 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(fvd->plugin->top_widget))));
93ac601b 225 gtk_window_set_destroy_with_parent(GTK_WINDOW(fvd->f_window), TRUE);
5339b49a 226 gtk_window_set_resizable(GTK_WINDOW(fvd->f_window), FALSE);
6a4f1205 227
4ed9b7ba 228 /*
229 * Initiating GtkTable layout
230 * starts with 2 rows and 5 columns and
231 * expands when expressions added
232 */
1f7f7fe2 233 fvd->f_main_box = gtk_table_new(3,7,FALSE);
4ed9b7ba 234 gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5);
235 gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5);
91ad3f0a 236
6a4f1205 237 gtk_container_add(GTK_CONTAINER(fvd->f_window), GTK_WIDGET(fvd->f_main_box));
238
4ed9b7ba 239 /*
240 * First half of the filter window
241 * - textual entry of filter expression
242 * - processing button
243 */
244 fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL);
3cea5310 245 g_signal_connect (G_OBJECT(fvd->f_expression_field),
246 "key-press-event", G_CALLBACK (callback_enter_check), (gpointer)fvd);
c2774e9d 247// gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0");
4ed9b7ba 248 gtk_widget_show (fvd->f_expression_field);
249
c2774e9d 250 g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed",
251 G_CALLBACK (callback_expression_field), (gpointer) fvd);
252
4ed9b7ba 253 fvd->f_process_button = gtk_button_new_with_label("Process");
254 gtk_widget_show (fvd->f_process_button);
255
c2774e9d 256 g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked",
257 G_CALLBACK (callback_process_button), (gpointer) fvd);
258
1f7f7fe2 259 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0);
260 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0);
c2774e9d 261
262
4ed9b7ba 263
264 /*
265 * Second half of the filter window
266 * - combo boxes featuring filtering options added to the expression
267 */
c2774e9d 268 fvd->f_add_button = gtk_button_new_with_label("Add Expression");
269 gtk_widget_show (fvd->f_add_button);
270
271 g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked",
272 G_CALLBACK (callback_add_button), (gpointer) fvd);
4ed9b7ba 273
2422ba7b 274 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,2,3,GTK_FILL,GTK_FILL,0,0);
275
276 fvd->f_cancel_button = gtk_button_new_with_label("Cancel");
277 gtk_widget_show (fvd->f_cancel_button);
278 g_signal_connect (G_OBJECT (fvd->f_cancel_button), "clicked",
279 G_CALLBACK (callback_cancel_button), (gpointer) fvd);
280
281 gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_cancel_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0);
c2774e9d 282
283 fvd->f_logical_op_junction_box = gtk_combo_box_new_text();
2b715e58 284 for(i=0;i<fvd->f_logical_op_options->len;i++) {
285 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
286 gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str);
287 }
288 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
289
c2774e9d 290 //gtk_widget_show(fvd->f_logical_op_box);
2b99ec10 291
c2774e9d 292 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);
293
203eb6f7 294 gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1);
295
c2774e9d 296 /* initialize a new line */
297 fvd->f_lines = g_ptr_array_new();
298 fvd->rows = 1;
299 FilterViewerDataLine* fvdl = gui_filter_add_line(fvd);
300 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl);
4ed9b7ba 301
c2774e9d 302 /*
303 * show main container
304 */
4ed9b7ba 305 gtk_widget_show(fvd->f_main_box);
6a4f1205 306 gtk_widget_show(fvd->f_window);
4ed9b7ba 307
91ad3f0a 308
309 g_object_set_data_full(
310 G_OBJECT(guifilter_get_widget(fvd)),
311 "filter_viewer_data",
312 fvd,
313 (GDestroyNotify)gui_filter_destructor);
314
0fc64e11 315 g_filter_list = g_slist_append(
316 g_filter_list,
317 fvd);
4ed9b7ba 318
91ad3f0a 319 return fvd;
320}
321
c2774e9d 322/**
7e7af7f2 323 * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*)
852f16bb 324 *
c2774e9d 325 * Adds a filter option line on the module tab
326 * @param fvd The filter module structure
327 * @return The line structure
328 */
329FilterViewerDataLine*
330gui_filter_add_line(FilterViewerData* fvd) {
331
332 FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1);
333
2b715e58 334 unsigned i;
c2774e9d 335 fvdl->row = fvd->rows;
336 fvdl->visible = TRUE;
2b715e58 337
1f7f7fe2 338 fvdl->f_not_op_box = gtk_combo_box_new_text();
339 for(i=0;i<fvd->f_not_op_options->len;i++) {
340 GString* s = g_ptr_array_index(fvd->f_not_op_options,i);
341 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str);
342 }
343
2b715e58 344 fvdl->f_field_box = gtk_combo_box_new_text();
345 for(i=0;i<fvd->f_field_options->len;i++) {
346 GString* s = g_ptr_array_index(fvd->f_field_options,i);
1f7f7fe2 347// g_print("String field: %s\n",s->str);
2b715e58 348 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str);
349 }
350
351 fvdl->f_math_op_box = gtk_combo_box_new_text();
352 for(i=0;i<fvd->f_math_op_options->len;i++) {
353 GString* s = g_ptr_array_index(fvd->f_math_op_options,i);
354 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str);
355 }
356
c2774e9d 357 fvdl->f_value_field = gtk_entry_new();
c2774e9d 358
359 fvdl->f_logical_op_box = gtk_combo_box_new_text();
2b715e58 360 for(i=0;i<fvd->f_logical_op_options->len;i++) {
361 GString* s = g_ptr_array_index(fvd->f_logical_op_options,i);
362 gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str);
363 }
c2774e9d 364 gtk_widget_set_events(fvdl->f_logical_op_box,
365 GDK_ENTER_NOTIFY_MASK |
366 GDK_LEAVE_NOTIFY_MASK |
367 GDK_FOCUS_CHANGE_MASK);
368
369 g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed",
370 G_CALLBACK (callback_logical_op_box), (gpointer) fvd);
2b715e58 371
372 gui_filter_line_reset(fvdl);
373 gui_filter_line_set_visible(fvdl,TRUE);
c2774e9d 374
1f7f7fe2 375 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);
376 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);
377 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);
378 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);
379 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 380
381 return fvdl;
382}
383
852f16bb 384/**
7e7af7f2 385 * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean)
852f16bb 386 *
387 * Change visible state of current FilterViewerDataLine
388 * @param fvdl pointer to the current FilterViewerDataLine
389 * @param v TRUE: sets visible, FALSE: sets invisible
390 */
7e7af7f2 391void
392gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) {
c2774e9d 393
394 fvdl->visible = v;
395 if(v) {
1f7f7fe2 396 gtk_widget_show(fvdl->f_not_op_box);
2b715e58 397 gtk_widget_show(fvdl->f_field_box);
c2774e9d 398 gtk_widget_show(fvdl->f_math_op_box);
399 gtk_widget_show(fvdl->f_value_field);
400 gtk_widget_show(fvdl->f_logical_op_box);
401 } else {
1f7f7fe2 402 gtk_widget_hide(fvdl->f_not_op_box);
2b715e58 403 gtk_widget_hide(fvdl->f_field_box);
c2774e9d 404 gtk_widget_hide(fvdl->f_math_op_box);
405 gtk_widget_hide(fvdl->f_value_field);
406 gtk_widget_hide(fvdl->f_logical_op_box);
407 }
408
409}
410
852f16bb 411/**
7e7af7f2 412 * @fn void gui_filter_line_reset(FilterViewerDataLine*)
852f16bb 413 *
414 * Sets selections of all boxes in current FilterViewerDataLine
415 * to default value (0)
416 * @param fvdl pointer to current FilterViewerDataLine
417 */
7e7af7f2 418void
419gui_filter_line_reset(FilterViewerDataLine *fvdl) {
c2774e9d 420
1f7f7fe2 421 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0);
2b715e58 422 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0);
c2774e9d 423 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0);
da2e1bfb 424 gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),"");
c2774e9d 425 gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0);
426}
427
428/**
7e7af7f2 429 * @fn void gui_filter_destructor(FilterViewerData*)
852f16bb 430 *
c2774e9d 431 * Destructor for the filter gui module
432 * @param fvd The module structure
433 */
91ad3f0a 434void
435gui_filter_destructor(FilterViewerData *fvd)
436{
91ad3f0a 437 /* May already been done by GTK window closing */
438 if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){
439 g_info("widget still exists");
440 }
da2e1bfb 441// if(tab != NULL) {
442// lttvwindow_unregister_traceset_notify(fvd->tab,
443// filter_traceset_changed,
444// filter_viewer_data);
445// }
91ad3f0a 446 lttvwindowtraces_background_notify_remove(fvd);
0fc64e11 447
448 g_filter_list = g_slist_remove(g_filter_list, fvd);
6a4f1205 449
91ad3f0a 450 g_free(fvd);
451}
452
91ad3f0a 453
454/**
7e7af7f2 455 * @fn GtkWidget* h_guifilter(Tab*)
852f16bb 456 *
457 * Filter Module's constructor hook
91ad3f0a 458 *
852f16bb 459 * This constructor is given as a parameter to the menuitem and toolbar button
460 * registration. It creates the list.
e433e6d6 461 * @param obj Object to interact with.
852f16bb 462 * @return The widget created.
91ad3f0a 463 */
464GtkWidget *
e433e6d6 465h_guifilter(LttvPlugin *plugin)
91ad3f0a 466{
e433e6d6 467 FilterViewerData* f = gui_filter(plugin) ;
6a4f1205 468
6a4f1205 469 return NULL;
91ad3f0a 470}
471
91ad3f0a 472/**
7e7af7f2 473 * @fn static void init()
852f16bb 474 *
475 * This function initializes the Filter Viewer functionnality through the
476 * gtkTraceSet API.
91ad3f0a 477 */
478static void init() {
479
480 lttvwindow_register_constructor("guifilter",
481 "/",
482 "Insert Filter Module",
483 hGuiFilterInsert_xpm,
484 "Insert Filter Module",
2b99ec10 485 h_guifilter);
91ad3f0a 486}
487
c2774e9d 488/**
7e7af7f2 489 * @fn void filter_destroy_walk(gpointer,gpointer)
852f16bb 490 *
c2774e9d 491 * Initiate the destruction of the current gui module
492 * on the GTK Interface
493 */
7e7af7f2 494void
495filter_destroy_walk(gpointer data, gpointer user_data)
91ad3f0a 496{
497 FilterViewerData *fvd = (FilterViewerData*)data;
498
c2774e9d 499 g_debug("CFV.c : filter_destroy_walk, %p", fvd);
da2e1bfb 500
91ad3f0a 501 /* May already have been done by GTK window closing */
502 if(GTK_IS_WIDGET(guifilter_get_widget(fvd)))
503 gtk_widget_destroy(guifilter_get_widget(fvd));
504}
505
506/**
7e7af7f2 507 * @fn static void destroy()
852f16bb 508 * @brief plugin's destroy function
91ad3f0a 509 *
852f16bb 510 * This function releases the memory reserved by the module and unregisters
511 * everything that has been registered in the gtkTraceSet API.
91ad3f0a 512 */
513static void destroy() {
0fc64e11 514
515 g_slist_foreach(g_filter_list, filter_destroy_walk, NULL );
91ad3f0a 516
2b99ec10 517 lttvwindow_unregister_constructor(h_guifilter);
91ad3f0a 518
519}
520
c2774e9d 521/**
7e7af7f2 522 * @fn void callback_process_button(GtkWidget*,gpointer)
852f16bb 523 *
c2774e9d 524 * The Process Button callback function
525 * @param widget The Button widget passed to the callback function
526 * @param data Data sent along with the callback function
527 */
7e7af7f2 528void
529callback_process_button(GtkWidget *widget, gpointer data) {
c2774e9d 530
da2e1bfb 531 g_debug("callback_process_button(): Processing expression");
532
c2774e9d 533 FilterViewerData *fvd = (FilterViewerData*)data;
064565c5 534 LttvFilter* filter;
c2774e9d 535
1f7f7fe2 536 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
064565c5 537 filter = lttv_filter_new();
da2e1bfb 538 GString* s = g_string_new(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
539 lttv_filter_append_expression(filter,s->str);
540 g_string_free(s,TRUE);
064565c5 541 } else {
542 filter = NULL;
1f7f7fe2 543 }
e433e6d6 544 /* Remove the old filter if present */
545 //g_object_set_data_full(fvd->obj, "filter", filter,
546 // (GDestroyNotify)lttv_filter_destroy);
547 //g_object_notify(fvd->obj, "filter");
548 lttv_plugin_update_filter(fvd->plugin, filter);
c2774e9d 549}
550
2422ba7b 551/**
552 * @fn void callback_cancel_button(GtkWidget*,gpointer)
553 *
554 * The Cancel Button callback function
555 * @param widget The Button widget passed to the callback function
556 * @param data Data sent along with the callback function
557 */
558void
559callback_cancel_button(GtkWidget *widget, gpointer data) {
560
561 FilterViewerData *fvd = (FilterViewerData*)data;
562 gtk_widget_destroy(fvd->f_window);
563}
564
3cea5310 565gboolean callback_enter_check(GtkWidget *widget,
566 GdkEventKey *event,
567 gpointer user_data)
568{
f42883f9 569 g_debug("typed : %x", event->keyval);
3cea5310 570 switch(event->keyval) {
571 case GDK_Return:
572 case GDK_KP_Enter:
573 case GDK_ISO_Enter:
574 case GDK_3270_Enter:
f42883f9 575 callback_process_button(widget, user_data);
3cea5310 576 break;
577 default:
578 break;
579 }
580 return FALSE;
581}
582
c2774e9d 583/**
7e7af7f2 584 * @fn void callback_expression_field(GtkWidget*,gpointer)
852f16bb 585 *
c2774e9d 586 * The Add Button callback function
587 * @param widget The Button widget passed to the callback function
588 * @param data Data sent along with the callback function
589 */
7e7af7f2 590void
591callback_expression_field(GtkWidget *widget, gpointer data) {
da2e1bfb 592
c2774e9d 593 FilterViewerData *fvd = (FilterViewerData*)data;
594
595 if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) {
596 gtk_widget_show(fvd->f_logical_op_junction_box);
597 } else {
598 gtk_widget_hide(fvd->f_logical_op_junction_box);
599 }
600}
601
602
603/**
7e7af7f2 604 * @fn void callback_add_button(GtkWidget*,gpointer)
852f16bb 605 *
c2774e9d 606 * The Add Button callback function
607 * @param widget The Button widget passed to the callback function
608 * @param data Data sent along with the callback function
609 */
7e7af7f2 610void
611callback_add_button(GtkWidget *widget, gpointer data) {
c2774e9d 612
da2e1bfb 613 g_debug("callback_add_button(): processing simple expressions");
c2774e9d 614
da2e1bfb 615 unsigned i;
616
c2774e9d 617 FilterViewerData *fvd = (FilterViewerData*)data;
618 FilterViewerDataLine *fvdl = NULL;
619 GString* a_filter_string = g_string_new("");
2b715e58 620
da2e1bfb 621 /*
622 * adding linking operator to
623 * string
624 */
2b715e58 625 GString* s;
626 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box)));
4ec0c904 627 a_filter_string = g_string_append(a_filter_string,s->str);
da2e1bfb 628 gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0);
c2774e9d 629
da2e1bfb 630 /* begin expression */
4ec0c904 631 a_filter_string = g_string_append_c(a_filter_string,'(');
2b715e58 632
da2e1bfb 633 /*
634 * For each simple expression, add the resulting string
635 * to the filter string
636 *
637 * Each simple expression takes the following schema
638 * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value]
639 */
c2774e9d 640 for(i=0;i<fvd->f_lines->len;i++) {
641 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
1f7f7fe2 642
643 s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box)));
4ec0c904 644 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 645
646 s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box)));
4ec0c904 647 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 648
649 s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box)));
4ec0c904 650 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 651
4ec0c904 652 a_filter_string = g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field)));
2b715e58 653
654 s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)));
4ec0c904 655 a_filter_string = g_string_append(a_filter_string,s->str);
2b715e58 656
da2e1bfb 657 /*
658 * resetting simple expression lines
659 */
c2774e9d 660 gui_filter_line_reset(fvdl);
2b715e58 661 if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line
c2774e9d 662 }
663
da2e1bfb 664 /* end expression */
4ec0c904 665 a_filter_string = g_string_append_c(a_filter_string,')');
c2774e9d 666
2b715e58 667 g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field)));
668 gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str);
c2774e9d 669
670}
671
672/**
7e7af7f2 673 * @fn void callback_logical_op_box(GtkWidget*,gpointer)
852f16bb 674 *
c2774e9d 675 * The logical op box callback function
676 * @param widget The Button widget passed to the callback function
677 * @param data Data sent along with the callback function
678 */
7e7af7f2 679void
680callback_logical_op_box(GtkWidget *widget, gpointer data) {
c2774e9d 681
da2e1bfb 682 g_debug("callback_logical_op_box(): adding new simple expression");
c2774e9d 683
684 FilterViewerData *fvd = (FilterViewerData*)data;
685 FilterViewerDataLine *fvdl = NULL;
686
687 int i;
688 for(i=0;i<fvd->f_lines->len;i++) {
689 fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i);
690 if(fvdl->f_logical_op_box == widget) {
da2e1bfb 691 if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return;
c2774e9d 692 if(i==fvd->f_lines->len-1) { /* create a new line */
693 fvd->rows++;
694 FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd);
695 g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2);
696 } else {
697 FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1);
698 if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE);
699 }
700 }
701 }
702
703}
91ad3f0a 704
705LTTV_MODULE("guifilter", "Filter window", \
706 "Graphical module that let user specify their filtering options", \
707 init, destroy, "lttvwindow")
708
This page took 0.081961 seconds and 4 git commands to generate.