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