Commit | Line | Data |
---|---|---|
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 | |
b9ce0bad YB |
15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
16 | * MA 02110-1301, USA. | |
91ad3f0a | 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); |
e433e6d6 | 64 | FilterViewerData *gui_filter(LttvPlugin *plugin); |
91ad3f0a | 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); | |
e433e6d6 | 69 | GtkWidget* h_guifilter(LttvPlugin *plugin); |
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); | |
2422ba7b | 82 | void 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 | 92 | struct _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 | 108 | struct _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 | 141 | GtkWidget* |
142 | guifilter_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 | */ |
154 | FilterViewerData* | |
e433e6d6 | 155 | gui_filter(LttvPlugin *plugin) |
91ad3f0a | 156 | { |
f88c5bfa | 157 | g_debug("filter::gui_filter()"); |
2b715e58 | 158 | |
159 | unsigned i; | |
91ad3f0a | 160 | |
161 | FilterViewerData* fvd = g_new(FilterViewerData,1); | |
162 | ||
e433e6d6 | 163 | fvd->plugin = plugin; |
91ad3f0a | 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")); | |
6471e71f | 188 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.subname")); |
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")); | |
33bdc8dd | 192 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.target_pid")); |
2b715e58 | 193 | /* |
194 | * TODO: Add core.xml fields here ! | |
195 | */ | |
6471e71f | 196 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("channel.name")); |
2b715e58 | 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); |
294a2716 | 219 | gtk_window_set_title(GTK_WINDOW(fvd->f_window), "LTTV Filter"); |
93ac601b | 220 | gtk_window_set_transient_for(GTK_WINDOW(fvd->f_window), |
e433e6d6 | 221 | GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(fvd->plugin->top_widget)))); |
93ac601b | 222 | gtk_window_set_destroy_with_parent(GTK_WINDOW(fvd->f_window), TRUE); |
5339b49a | 223 | gtk_window_set_resizable(GTK_WINDOW(fvd->f_window), FALSE); |
6a4f1205 | 224 | |
4ed9b7ba | 225 | /* |
226 | * Initiating GtkTable layout | |
227 | * starts with 2 rows and 5 columns and | |
228 | * expands when expressions added | |
229 | */ | |
1f7f7fe2 | 230 | fvd->f_main_box = gtk_table_new(3,7,FALSE); |
4ed9b7ba | 231 | gtk_table_set_row_spacings(GTK_TABLE(fvd->f_main_box),5); |
232 | gtk_table_set_col_spacings(GTK_TABLE(fvd->f_main_box),5); | |
91ad3f0a | 233 | |
6a4f1205 | 234 | gtk_container_add(GTK_CONTAINER(fvd->f_window), GTK_WIDGET(fvd->f_main_box)); |
235 | ||
4ed9b7ba | 236 | /* |
237 | * First half of the filter window | |
238 | * - textual entry of filter expression | |
239 | * - processing button | |
240 | */ | |
241 | fvd->f_expression_field = gtk_entry_new(); //gtk_scrolled_window_new (NULL, NULL); | |
3cea5310 | 242 | g_signal_connect (G_OBJECT(fvd->f_expression_field), |
243 | "key-press-event", G_CALLBACK (callback_enter_check), (gpointer)fvd); | |
c2774e9d | 244 | // gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),"state.cpu>0"); |
4ed9b7ba | 245 | gtk_widget_show (fvd->f_expression_field); |
246 | ||
c2774e9d | 247 | g_signal_connect (G_OBJECT (fvd->f_expression_field), "changed", |
248 | G_CALLBACK (callback_expression_field), (gpointer) fvd); | |
249 | ||
4ed9b7ba | 250 | fvd->f_process_button = gtk_button_new_with_label("Process"); |
251 | gtk_widget_show (fvd->f_process_button); | |
252 | ||
c2774e9d | 253 | g_signal_connect (G_OBJECT (fvd->f_process_button), "clicked", |
254 | G_CALLBACK (callback_process_button), (gpointer) fvd); | |
255 | ||
1f7f7fe2 | 256 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_expression_field,0,6,0,1,GTK_FILL,GTK_FILL,0,0); |
257 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_process_button,6,7,0,1,GTK_FILL,GTK_FILL,0,0); | |
c2774e9d | 258 | |
259 | ||
4ed9b7ba | 260 | |
261 | /* | |
262 | * Second half of the filter window | |
263 | * - combo boxes featuring filtering options added to the expression | |
264 | */ | |
c2774e9d | 265 | fvd->f_add_button = gtk_button_new_with_label("Add Expression"); |
266 | gtk_widget_show (fvd->f_add_button); | |
267 | ||
268 | g_signal_connect (G_OBJECT (fvd->f_add_button), "clicked", | |
269 | G_CALLBACK (callback_add_button), (gpointer) fvd); | |
4ed9b7ba | 270 | |
2422ba7b | 271 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,2,3,GTK_FILL,GTK_FILL,0,0); |
272 | ||
273 | fvd->f_cancel_button = gtk_button_new_with_label("Cancel"); | |
274 | gtk_widget_show (fvd->f_cancel_button); | |
275 | g_signal_connect (G_OBJECT (fvd->f_cancel_button), "clicked", | |
276 | G_CALLBACK (callback_cancel_button), (gpointer) fvd); | |
277 | ||
278 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_cancel_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0); | |
c2774e9d | 279 | |
280 | fvd->f_logical_op_junction_box = gtk_combo_box_new_text(); | |
2b715e58 | 281 | for(i=0;i<fvd->f_logical_op_options->len;i++) { |
282 | GString* s = g_ptr_array_index(fvd->f_logical_op_options,i); | |
283 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str); | |
284 | } | |
285 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0); | |
286 | ||
c2774e9d | 287 | //gtk_widget_show(fvd->f_logical_op_box); |
2b99ec10 | 288 | |
c2774e9d | 289 | 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); |
290 | ||
203eb6f7 | 291 | gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1); |
292 | ||
c2774e9d | 293 | /* initialize a new line */ |
294 | fvd->f_lines = g_ptr_array_new(); | |
295 | fvd->rows = 1; | |
296 | FilterViewerDataLine* fvdl = gui_filter_add_line(fvd); | |
297 | g_ptr_array_add(fvd->f_lines,(gpointer) fvdl); | |
4ed9b7ba | 298 | |
c2774e9d | 299 | /* |
300 | * show main container | |
301 | */ | |
4ed9b7ba | 302 | gtk_widget_show(fvd->f_main_box); |
6a4f1205 | 303 | gtk_widget_show(fvd->f_window); |
4ed9b7ba | 304 | |
91ad3f0a | 305 | |
306 | g_object_set_data_full( | |
307 | G_OBJECT(guifilter_get_widget(fvd)), | |
308 | "filter_viewer_data", | |
309 | fvd, | |
310 | (GDestroyNotify)gui_filter_destructor); | |
311 | ||
0fc64e11 | 312 | g_filter_list = g_slist_append( |
313 | g_filter_list, | |
314 | fvd); | |
4ed9b7ba | 315 | |
91ad3f0a | 316 | return fvd; |
317 | } | |
318 | ||
c2774e9d | 319 | /** |
7e7af7f2 | 320 | * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*) |
852f16bb | 321 | * |
c2774e9d | 322 | * Adds a filter option line on the module tab |
323 | * @param fvd The filter module structure | |
324 | * @return The line structure | |
325 | */ | |
326 | FilterViewerDataLine* | |
327 | gui_filter_add_line(FilterViewerData* fvd) { | |
328 | ||
329 | FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1); | |
330 | ||
2b715e58 | 331 | unsigned i; |
c2774e9d | 332 | fvdl->row = fvd->rows; |
333 | fvdl->visible = TRUE; | |
2b715e58 | 334 | |
1f7f7fe2 | 335 | fvdl->f_not_op_box = gtk_combo_box_new_text(); |
336 | for(i=0;i<fvd->f_not_op_options->len;i++) { | |
337 | GString* s = g_ptr_array_index(fvd->f_not_op_options,i); | |
338 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str); | |
339 | } | |
340 | ||
2b715e58 | 341 | fvdl->f_field_box = gtk_combo_box_new_text(); |
342 | for(i=0;i<fvd->f_field_options->len;i++) { | |
343 | GString* s = g_ptr_array_index(fvd->f_field_options,i); | |
1f7f7fe2 | 344 | // g_print("String field: %s\n",s->str); |
2b715e58 | 345 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str); |
346 | } | |
347 | ||
348 | fvdl->f_math_op_box = gtk_combo_box_new_text(); | |
349 | for(i=0;i<fvd->f_math_op_options->len;i++) { | |
350 | GString* s = g_ptr_array_index(fvd->f_math_op_options,i); | |
351 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str); | |
352 | } | |
353 | ||
c2774e9d | 354 | fvdl->f_value_field = gtk_entry_new(); |
c2774e9d | 355 | |
356 | fvdl->f_logical_op_box = gtk_combo_box_new_text(); | |
2b715e58 | 357 | for(i=0;i<fvd->f_logical_op_options->len;i++) { |
358 | GString* s = g_ptr_array_index(fvd->f_logical_op_options,i); | |
359 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str); | |
360 | } | |
c2774e9d | 361 | gtk_widget_set_events(fvdl->f_logical_op_box, |
362 | GDK_ENTER_NOTIFY_MASK | | |
363 | GDK_LEAVE_NOTIFY_MASK | | |
364 | GDK_FOCUS_CHANGE_MASK); | |
365 | ||
366 | g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed", | |
367 | G_CALLBACK (callback_logical_op_box), (gpointer) fvd); | |
2b715e58 | 368 | |
369 | gui_filter_line_reset(fvdl); | |
370 | gui_filter_line_set_visible(fvdl,TRUE); | |
c2774e9d | 371 | |
1f7f7fe2 | 372 | 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); |
373 | 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); | |
374 | 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); | |
375 | 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); | |
376 | 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 | 377 | |
378 | return fvdl; | |
379 | } | |
380 | ||
852f16bb | 381 | /** |
7e7af7f2 | 382 | * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean) |
852f16bb | 383 | * |
384 | * Change visible state of current FilterViewerDataLine | |
385 | * @param fvdl pointer to the current FilterViewerDataLine | |
386 | * @param v TRUE: sets visible, FALSE: sets invisible | |
387 | */ | |
7e7af7f2 | 388 | void |
389 | gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) { | |
c2774e9d | 390 | |
391 | fvdl->visible = v; | |
392 | if(v) { | |
1f7f7fe2 | 393 | gtk_widget_show(fvdl->f_not_op_box); |
2b715e58 | 394 | gtk_widget_show(fvdl->f_field_box); |
c2774e9d | 395 | gtk_widget_show(fvdl->f_math_op_box); |
396 | gtk_widget_show(fvdl->f_value_field); | |
397 | gtk_widget_show(fvdl->f_logical_op_box); | |
398 | } else { | |
1f7f7fe2 | 399 | gtk_widget_hide(fvdl->f_not_op_box); |
2b715e58 | 400 | gtk_widget_hide(fvdl->f_field_box); |
c2774e9d | 401 | gtk_widget_hide(fvdl->f_math_op_box); |
402 | gtk_widget_hide(fvdl->f_value_field); | |
403 | gtk_widget_hide(fvdl->f_logical_op_box); | |
404 | } | |
405 | ||
406 | } | |
407 | ||
852f16bb | 408 | /** |
7e7af7f2 | 409 | * @fn void gui_filter_line_reset(FilterViewerDataLine*) |
852f16bb | 410 | * |
411 | * Sets selections of all boxes in current FilterViewerDataLine | |
412 | * to default value (0) | |
413 | * @param fvdl pointer to current FilterViewerDataLine | |
414 | */ | |
7e7af7f2 | 415 | void |
416 | gui_filter_line_reset(FilterViewerDataLine *fvdl) { | |
c2774e9d | 417 | |
1f7f7fe2 | 418 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0); |
2b715e58 | 419 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0); |
c2774e9d | 420 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0); |
da2e1bfb | 421 | gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),""); |
c2774e9d | 422 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0); |
423 | } | |
424 | ||
425 | /** | |
7e7af7f2 | 426 | * @fn void gui_filter_destructor(FilterViewerData*) |
852f16bb | 427 | * |
c2774e9d | 428 | * Destructor for the filter gui module |
429 | * @param fvd The module structure | |
430 | */ | |
91ad3f0a | 431 | void |
432 | gui_filter_destructor(FilterViewerData *fvd) | |
433 | { | |
91ad3f0a | 434 | /* May already been done by GTK window closing */ |
435 | if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){ | |
436 | g_info("widget still exists"); | |
437 | } | |
da2e1bfb | 438 | // if(tab != NULL) { |
439 | // lttvwindow_unregister_traceset_notify(fvd->tab, | |
440 | // filter_traceset_changed, | |
441 | // filter_viewer_data); | |
442 | // } | |
91ad3f0a | 443 | lttvwindowtraces_background_notify_remove(fvd); |
0fc64e11 | 444 | |
445 | g_filter_list = g_slist_remove(g_filter_list, fvd); | |
6a4f1205 | 446 | |
91ad3f0a | 447 | g_free(fvd); |
448 | } | |
449 | ||
91ad3f0a | 450 | |
451 | /** | |
7e7af7f2 | 452 | * @fn GtkWidget* h_guifilter(Tab*) |
852f16bb | 453 | * |
454 | * Filter Module's constructor hook | |
91ad3f0a | 455 | * |
852f16bb | 456 | * This constructor is given as a parameter to the menuitem and toolbar button |
457 | * registration. It creates the list. | |
e433e6d6 | 458 | * @param obj Object to interact with. |
852f16bb | 459 | * @return The widget created. |
91ad3f0a | 460 | */ |
461 | GtkWidget * | |
e433e6d6 | 462 | h_guifilter(LttvPlugin *plugin) |
91ad3f0a | 463 | { |
0fe54b01 YB |
464 | gui_filter(plugin); |
465 | ||
466 | /* TODO ybrosseau 2011-02-04: We should probably return a widget here */ | |
467 | return NULL; | |
91ad3f0a | 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); | |
064565c5 | 539 | } else { |
540 | filter = NULL; | |
1f7f7fe2 | 541 | } |
e433e6d6 | 542 | /* Remove the old filter if present */ |
543 | //g_object_set_data_full(fvd->obj, "filter", filter, | |
544 | // (GDestroyNotify)lttv_filter_destroy); | |
545 | //g_object_notify(fvd->obj, "filter"); | |
546 | lttv_plugin_update_filter(fvd->plugin, filter); | |
c2774e9d | 547 | } |
548 | ||
2422ba7b | 549 | /** |
550 | * @fn void callback_cancel_button(GtkWidget*,gpointer) | |
551 | * | |
552 | * The Cancel Button callback function | |
553 | * @param widget The Button widget passed to the callback function | |
554 | * @param data Data sent along with the callback function | |
555 | */ | |
556 | void | |
557 | callback_cancel_button(GtkWidget *widget, gpointer data) { | |
558 | ||
559 | FilterViewerData *fvd = (FilterViewerData*)data; | |
560 | gtk_widget_destroy(fvd->f_window); | |
561 | } | |
562 | ||
3cea5310 | 563 | gboolean callback_enter_check(GtkWidget *widget, |
564 | GdkEventKey *event, | |
565 | gpointer user_data) | |
566 | { | |
f42883f9 | 567 | g_debug("typed : %x", event->keyval); |
3cea5310 | 568 | switch(event->keyval) { |
569 | case GDK_Return: | |
570 | case GDK_KP_Enter: | |
571 | case GDK_ISO_Enter: | |
572 | case GDK_3270_Enter: | |
f42883f9 | 573 | callback_process_button(widget, user_data); |
3cea5310 | 574 | break; |
575 | default: | |
576 | break; | |
577 | } | |
578 | return FALSE; | |
579 | } | |
580 | ||
c2774e9d | 581 | /** |
7e7af7f2 | 582 | * @fn void callback_expression_field(GtkWidget*,gpointer) |
852f16bb | 583 | * |
c2774e9d | 584 | * The Add Button callback function |
585 | * @param widget The Button widget passed to the callback function | |
586 | * @param data Data sent along with the callback function | |
587 | */ | |
7e7af7f2 | 588 | void |
589 | callback_expression_field(GtkWidget *widget, gpointer data) { | |
da2e1bfb | 590 | |
c2774e9d | 591 | FilterViewerData *fvd = (FilterViewerData*)data; |
592 | ||
593 | if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) { | |
594 | gtk_widget_show(fvd->f_logical_op_junction_box); | |
595 | } else { | |
596 | gtk_widget_hide(fvd->f_logical_op_junction_box); | |
597 | } | |
598 | } | |
599 | ||
600 | ||
601 | /** | |
7e7af7f2 | 602 | * @fn void callback_add_button(GtkWidget*,gpointer) |
852f16bb | 603 | * |
c2774e9d | 604 | * The Add Button callback function |
605 | * @param widget The Button widget passed to the callback function | |
606 | * @param data Data sent along with the callback function | |
607 | */ | |
7e7af7f2 | 608 | void |
609 | callback_add_button(GtkWidget *widget, gpointer data) { | |
c2774e9d | 610 | |
da2e1bfb | 611 | g_debug("callback_add_button(): processing simple expressions"); |
c2774e9d | 612 | |
da2e1bfb | 613 | unsigned i; |
614 | ||
c2774e9d | 615 | FilterViewerData *fvd = (FilterViewerData*)data; |
616 | FilterViewerDataLine *fvdl = NULL; | |
617 | GString* a_filter_string = g_string_new(""); | |
2b715e58 | 618 | |
da2e1bfb | 619 | /* |
620 | * adding linking operator to | |
621 | * string | |
622 | */ | |
2b715e58 | 623 | GString* s; |
624 | 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 | 625 | a_filter_string = g_string_append(a_filter_string,s->str); |
da2e1bfb | 626 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0); |
c2774e9d | 627 | |
da2e1bfb | 628 | /* begin expression */ |
4ec0c904 | 629 | a_filter_string = g_string_append_c(a_filter_string,'('); |
2b715e58 | 630 | |
da2e1bfb | 631 | /* |
632 | * For each simple expression, add the resulting string | |
633 | * to the filter string | |
634 | * | |
635 | * Each simple expression takes the following schema | |
636 | * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value] | |
637 | */ | |
c2774e9d | 638 | for(i=0;i<fvd->f_lines->len;i++) { |
639 | fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i); | |
1f7f7fe2 | 640 | |
641 | s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box))); | |
4ec0c904 | 642 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 | 643 | |
644 | s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box))); | |
4ec0c904 | 645 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 | 646 | |
647 | s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box))); | |
4ec0c904 | 648 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 | 649 | |
4ec0c904 | 650 | a_filter_string = g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field))); |
2b715e58 | 651 | |
652 | s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box))); | |
4ec0c904 | 653 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 | 654 | |
da2e1bfb | 655 | /* |
656 | * resetting simple expression lines | |
657 | */ | |
c2774e9d | 658 | gui_filter_line_reset(fvdl); |
2b715e58 | 659 | if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line |
c2774e9d | 660 | } |
661 | ||
da2e1bfb | 662 | /* end expression */ |
4ec0c904 | 663 | a_filter_string = g_string_append_c(a_filter_string,')'); |
c2774e9d | 664 | |
2b715e58 | 665 | g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))); |
666 | gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str); | |
c2774e9d | 667 | |
668 | } | |
669 | ||
670 | /** | |
7e7af7f2 | 671 | * @fn void callback_logical_op_box(GtkWidget*,gpointer) |
852f16bb | 672 | * |
c2774e9d | 673 | * The logical op box callback function |
674 | * @param widget The Button widget passed to the callback function | |
675 | * @param data Data sent along with the callback function | |
676 | */ | |
7e7af7f2 | 677 | void |
678 | callback_logical_op_box(GtkWidget *widget, gpointer data) { | |
c2774e9d | 679 | |
da2e1bfb | 680 | g_debug("callback_logical_op_box(): adding new simple expression"); |
c2774e9d | 681 | |
682 | FilterViewerData *fvd = (FilterViewerData*)data; | |
683 | FilterViewerDataLine *fvdl = NULL; | |
684 | ||
685 | int i; | |
686 | for(i=0;i<fvd->f_lines->len;i++) { | |
687 | fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i); | |
688 | if(fvdl->f_logical_op_box == widget) { | |
da2e1bfb | 689 | if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return; |
c2774e9d | 690 | if(i==fvd->f_lines->len-1) { /* create a new line */ |
691 | fvd->rows++; | |
692 | FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd); | |
693 | g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2); | |
694 | } else { | |
695 | FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1); | |
696 | if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE); | |
697 | } | |
698 | } | |
699 | } | |
700 | ||
701 | } | |
91ad3f0a | 702 | |
703 | LTTV_MODULE("guifilter", "Filter window", \ | |
704 | "Graphical module that let user specify their filtering options", \ | |
705 | init, destroy, "lttvwindow") | |
706 |