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