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); |
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); |
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 { |
e433e6d6 |
108 | LttvPlugin *plugin; /**< Plugin on which we interact. */ |
91ad3f0a |
109 | |
6a4f1205 |
110 | GtkWidget *f_window; /**< filter window */ |
111 | |
7e7af7f2 |
112 | GtkWidget *f_main_box; /**< main container */ |
4ed9b7ba |
113 | |
7e7af7f2 |
114 | GtkWidget *f_expression_field; /**< entire expression (GtkEntry) */ |
115 | GtkWidget *f_process_button; /**< process expression button (GtkButton) */ |
4ed9b7ba |
116 | |
7e7af7f2 |
117 | GtkWidget *f_logical_op_junction_box; /**< linking operator box (GtkComboBox) */ |
4ed9b7ba |
118 | |
7e7af7f2 |
119 | int rows; /**< number of rows */ |
120 | GPtrArray *f_lines; /**< array of FilterViewerDataLine */ |
2b715e58 |
121 | |
7e7af7f2 |
122 | GPtrArray *f_not_op_options; /**< array of operators types for not_op box */ |
123 | GPtrArray *f_logical_op_options; /**< array of operators types for logical_op box */ |
124 | GPtrArray *f_field_options; /**< array of field types for field box */ |
125 | GPtrArray *f_math_op_options; /**< array of operators types for math_op box */ |
2b715e58 |
126 | |
7e7af7f2 |
127 | GtkWidget *f_add_button; /**< add expression to current expression (GtkButton) */ |
6a4f1205 |
128 | |
91ad3f0a |
129 | }; |
130 | |
c2774e9d |
131 | /** |
7e7af7f2 |
132 | * @fn GtkWidget* guifilter_get_widget(FilterViewerData*) |
852f16bb |
133 | * |
c2774e9d |
134 | * This function returns the current main widget |
135 | * used by this module |
136 | * @param fvd the module struct |
137 | * @return The main widget |
138 | */ |
7e7af7f2 |
139 | GtkWidget* |
140 | guifilter_get_widget(FilterViewerData *fvd) |
91ad3f0a |
141 | { |
01eb9889 |
142 | return fvd->f_window; |
91ad3f0a |
143 | } |
144 | |
145 | /** |
7e7af7f2 |
146 | * @fn FilterViewerData* gui_filter(Tab*) |
852f16bb |
147 | * |
148 | * Constructor is used to create FilterViewerData data structure. |
7e7af7f2 |
149 | * @param tab The tab structure used by the widget |
852f16bb |
150 | * @return The Filter viewer data created. |
91ad3f0a |
151 | */ |
152 | FilterViewerData* |
e433e6d6 |
153 | gui_filter(LttvPlugin *plugin) |
91ad3f0a |
154 | { |
f88c5bfa |
155 | g_debug("filter::gui_filter()"); |
2b715e58 |
156 | |
157 | unsigned i; |
91ad3f0a |
158 | GtkCellRenderer *renderer; |
159 | GtkTreeViewColumn *column; |
160 | |
161 | FilterViewerData* fvd = g_new(FilterViewerData,1); |
162 | |
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")); |
ffd088ef |
188 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.facility")); |
2b715e58 |
189 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.category")); |
190 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.time")); |
191 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("event.tsc")); |
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 | */ |
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")); |
7b5f6cf1 |
199 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.thread_brand")); |
2b715e58 |
200 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.pid")); |
201 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.ppid")); |
202 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.creation_time")); |
203 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.insertion_time")); |
204 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_mode")); |
205 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.execution_submode")); |
206 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.process_status")); |
207 | g_ptr_array_add(fvd->f_field_options,(gpointer) g_string_new("state.cpu")); |
208 | |
209 | fvd->f_math_op_options = g_ptr_array_new(); //g_array_new(FALSE,FALSE,7); |
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 | g_ptr_array_add(fvd->f_math_op_options,(gpointer) g_string_new(">=")); |
217 | |
218 | |
6a4f1205 |
219 | fvd->f_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
294a2716 |
220 | gtk_window_set_title(GTK_WINDOW(fvd->f_window), "LTTV Filter"); |
93ac601b |
221 | gtk_window_set_transient_for(GTK_WINDOW(fvd->f_window), |
e433e6d6 |
222 | GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(fvd->plugin->top_widget)))); |
93ac601b |
223 | gtk_window_set_destroy_with_parent(GTK_WINDOW(fvd->f_window), TRUE); |
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 | |
1f7f7fe2 |
271 | gtk_table_attach( GTK_TABLE(fvd->f_main_box),fvd->f_add_button,6,7,1,2,GTK_FILL,GTK_FILL,0,0); |
c2774e9d |
272 | |
273 | fvd->f_logical_op_junction_box = gtk_combo_box_new_text(); |
2b715e58 |
274 | for(i=0;i<fvd->f_logical_op_options->len;i++) { |
275 | GString* s = g_ptr_array_index(fvd->f_logical_op_options,i); |
276 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvd->f_logical_op_junction_box), s->str); |
277 | } |
278 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0); |
279 | |
c2774e9d |
280 | //gtk_widget_show(fvd->f_logical_op_box); |
2b99ec10 |
281 | |
c2774e9d |
282 | 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); |
283 | |
203eb6f7 |
284 | gtk_container_set_border_width(GTK_CONTAINER(fvd->f_main_box), 1); |
285 | |
c2774e9d |
286 | /* initialize a new line */ |
287 | fvd->f_lines = g_ptr_array_new(); |
288 | fvd->rows = 1; |
289 | FilterViewerDataLine* fvdl = gui_filter_add_line(fvd); |
290 | g_ptr_array_add(fvd->f_lines,(gpointer) fvdl); |
4ed9b7ba |
291 | |
c2774e9d |
292 | /* |
293 | * show main container |
294 | */ |
4ed9b7ba |
295 | gtk_widget_show(fvd->f_main_box); |
6a4f1205 |
296 | gtk_widget_show(fvd->f_window); |
4ed9b7ba |
297 | |
91ad3f0a |
298 | |
299 | g_object_set_data_full( |
300 | G_OBJECT(guifilter_get_widget(fvd)), |
301 | "filter_viewer_data", |
302 | fvd, |
303 | (GDestroyNotify)gui_filter_destructor); |
304 | |
0fc64e11 |
305 | g_filter_list = g_slist_append( |
306 | g_filter_list, |
307 | fvd); |
4ed9b7ba |
308 | |
91ad3f0a |
309 | return fvd; |
310 | } |
311 | |
c2774e9d |
312 | /** |
7e7af7f2 |
313 | * @fn FilterViewerDataLine* gui_filter_add_line(FilterViewerData*) |
852f16bb |
314 | * |
c2774e9d |
315 | * Adds a filter option line on the module tab |
316 | * @param fvd The filter module structure |
317 | * @return The line structure |
318 | */ |
319 | FilterViewerDataLine* |
320 | gui_filter_add_line(FilterViewerData* fvd) { |
321 | |
322 | FilterViewerDataLine* fvdl = g_new(FilterViewerDataLine,1); |
323 | |
2b715e58 |
324 | unsigned i; |
c2774e9d |
325 | fvdl->row = fvd->rows; |
326 | fvdl->visible = TRUE; |
2b715e58 |
327 | |
1f7f7fe2 |
328 | fvdl->f_not_op_box = gtk_combo_box_new_text(); |
329 | for(i=0;i<fvd->f_not_op_options->len;i++) { |
330 | GString* s = g_ptr_array_index(fvd->f_not_op_options,i); |
331 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_not_op_box), s->str); |
332 | } |
333 | |
2b715e58 |
334 | fvdl->f_field_box = gtk_combo_box_new_text(); |
335 | for(i=0;i<fvd->f_field_options->len;i++) { |
336 | GString* s = g_ptr_array_index(fvd->f_field_options,i); |
1f7f7fe2 |
337 | // g_print("String field: %s\n",s->str); |
2b715e58 |
338 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_field_box), s->str); |
339 | } |
340 | |
341 | fvdl->f_math_op_box = gtk_combo_box_new_text(); |
342 | for(i=0;i<fvd->f_math_op_options->len;i++) { |
343 | GString* s = g_ptr_array_index(fvd->f_math_op_options,i); |
344 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_math_op_box), s->str); |
345 | } |
346 | |
c2774e9d |
347 | fvdl->f_value_field = gtk_entry_new(); |
c2774e9d |
348 | |
349 | fvdl->f_logical_op_box = gtk_combo_box_new_text(); |
2b715e58 |
350 | for(i=0;i<fvd->f_logical_op_options->len;i++) { |
351 | GString* s = g_ptr_array_index(fvd->f_logical_op_options,i); |
352 | gtk_combo_box_append_text(GTK_COMBO_BOX(fvdl->f_logical_op_box), s->str); |
353 | } |
c2774e9d |
354 | gtk_widget_set_events(fvdl->f_logical_op_box, |
355 | GDK_ENTER_NOTIFY_MASK | |
356 | GDK_LEAVE_NOTIFY_MASK | |
357 | GDK_FOCUS_CHANGE_MASK); |
358 | |
359 | g_signal_connect (G_OBJECT (fvdl->f_logical_op_box), "changed", |
360 | G_CALLBACK (callback_logical_op_box), (gpointer) fvd); |
2b715e58 |
361 | |
362 | gui_filter_line_reset(fvdl); |
363 | gui_filter_line_set_visible(fvdl,TRUE); |
c2774e9d |
364 | |
1f7f7fe2 |
365 | 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); |
366 | 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); |
367 | 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); |
368 | 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); |
369 | 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 |
370 | |
371 | return fvdl; |
372 | } |
373 | |
852f16bb |
374 | /** |
7e7af7f2 |
375 | * @fn void gui_filter_line_set_visible(FilterViewerDataLine*,gboolean) |
852f16bb |
376 | * |
377 | * Change visible state of current FilterViewerDataLine |
378 | * @param fvdl pointer to the current FilterViewerDataLine |
379 | * @param v TRUE: sets visible, FALSE: sets invisible |
380 | */ |
7e7af7f2 |
381 | void |
382 | gui_filter_line_set_visible(FilterViewerDataLine *fvdl, gboolean v) { |
c2774e9d |
383 | |
384 | fvdl->visible = v; |
385 | if(v) { |
1f7f7fe2 |
386 | gtk_widget_show(fvdl->f_not_op_box); |
2b715e58 |
387 | gtk_widget_show(fvdl->f_field_box); |
c2774e9d |
388 | gtk_widget_show(fvdl->f_math_op_box); |
389 | gtk_widget_show(fvdl->f_value_field); |
390 | gtk_widget_show(fvdl->f_logical_op_box); |
391 | } else { |
1f7f7fe2 |
392 | gtk_widget_hide(fvdl->f_not_op_box); |
2b715e58 |
393 | gtk_widget_hide(fvdl->f_field_box); |
c2774e9d |
394 | gtk_widget_hide(fvdl->f_math_op_box); |
395 | gtk_widget_hide(fvdl->f_value_field); |
396 | gtk_widget_hide(fvdl->f_logical_op_box); |
397 | } |
398 | |
399 | } |
400 | |
852f16bb |
401 | /** |
7e7af7f2 |
402 | * @fn void gui_filter_line_reset(FilterViewerDataLine*) |
852f16bb |
403 | * |
404 | * Sets selections of all boxes in current FilterViewerDataLine |
405 | * to default value (0) |
406 | * @param fvdl pointer to current FilterViewerDataLine |
407 | */ |
7e7af7f2 |
408 | void |
409 | gui_filter_line_reset(FilterViewerDataLine *fvdl) { |
c2774e9d |
410 | |
1f7f7fe2 |
411 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_not_op_box),0); |
2b715e58 |
412 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_field_box),0); |
c2774e9d |
413 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_math_op_box),0); |
da2e1bfb |
414 | gtk_entry_set_text(GTK_ENTRY(fvdl->f_value_field),""); |
c2774e9d |
415 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvdl->f_logical_op_box),0); |
416 | } |
417 | |
418 | /** |
7e7af7f2 |
419 | * @fn void gui_filter_destructor(FilterViewerData*) |
852f16bb |
420 | * |
c2774e9d |
421 | * Destructor for the filter gui module |
422 | * @param fvd The module structure |
423 | */ |
91ad3f0a |
424 | void |
425 | gui_filter_destructor(FilterViewerData *fvd) |
426 | { |
91ad3f0a |
427 | /* May already been done by GTK window closing */ |
428 | if(GTK_IS_WIDGET(guifilter_get_widget(fvd))){ |
429 | g_info("widget still exists"); |
430 | } |
da2e1bfb |
431 | // if(tab != NULL) { |
432 | // lttvwindow_unregister_traceset_notify(fvd->tab, |
433 | // filter_traceset_changed, |
434 | // filter_viewer_data); |
435 | // } |
91ad3f0a |
436 | lttvwindowtraces_background_notify_remove(fvd); |
0fc64e11 |
437 | |
438 | g_filter_list = g_slist_remove(g_filter_list, fvd); |
6a4f1205 |
439 | |
91ad3f0a |
440 | g_free(fvd); |
441 | } |
442 | |
91ad3f0a |
443 | |
444 | /** |
7e7af7f2 |
445 | * @fn GtkWidget* h_guifilter(Tab*) |
852f16bb |
446 | * |
447 | * Filter Module's constructor hook |
91ad3f0a |
448 | * |
852f16bb |
449 | * This constructor is given as a parameter to the menuitem and toolbar button |
450 | * registration. It creates the list. |
e433e6d6 |
451 | * @param obj Object to interact with. |
852f16bb |
452 | * @return The widget created. |
91ad3f0a |
453 | */ |
454 | GtkWidget * |
e433e6d6 |
455 | h_guifilter(LttvPlugin *plugin) |
91ad3f0a |
456 | { |
e433e6d6 |
457 | FilterViewerData* f = gui_filter(plugin) ; |
6a4f1205 |
458 | |
6a4f1205 |
459 | return NULL; |
91ad3f0a |
460 | } |
461 | |
91ad3f0a |
462 | /** |
7e7af7f2 |
463 | * @fn static void init() |
852f16bb |
464 | * |
465 | * This function initializes the Filter Viewer functionnality through the |
466 | * gtkTraceSet API. |
91ad3f0a |
467 | */ |
468 | static void init() { |
469 | |
470 | lttvwindow_register_constructor("guifilter", |
471 | "/", |
472 | "Insert Filter Module", |
473 | hGuiFilterInsert_xpm, |
474 | "Insert Filter Module", |
2b99ec10 |
475 | h_guifilter); |
91ad3f0a |
476 | } |
477 | |
c2774e9d |
478 | /** |
7e7af7f2 |
479 | * @fn void filter_destroy_walk(gpointer,gpointer) |
852f16bb |
480 | * |
c2774e9d |
481 | * Initiate the destruction of the current gui module |
482 | * on the GTK Interface |
483 | */ |
7e7af7f2 |
484 | void |
485 | filter_destroy_walk(gpointer data, gpointer user_data) |
91ad3f0a |
486 | { |
487 | FilterViewerData *fvd = (FilterViewerData*)data; |
488 | |
c2774e9d |
489 | g_debug("CFV.c : filter_destroy_walk, %p", fvd); |
da2e1bfb |
490 | |
91ad3f0a |
491 | /* May already have been done by GTK window closing */ |
492 | if(GTK_IS_WIDGET(guifilter_get_widget(fvd))) |
493 | gtk_widget_destroy(guifilter_get_widget(fvd)); |
494 | } |
495 | |
496 | /** |
7e7af7f2 |
497 | * @fn static void destroy() |
852f16bb |
498 | * @brief plugin's destroy function |
91ad3f0a |
499 | * |
852f16bb |
500 | * This function releases the memory reserved by the module and unregisters |
501 | * everything that has been registered in the gtkTraceSet API. |
91ad3f0a |
502 | */ |
503 | static void destroy() { |
0fc64e11 |
504 | |
505 | g_slist_foreach(g_filter_list, filter_destroy_walk, NULL ); |
91ad3f0a |
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 | |
da2e1bfb |
521 | g_debug("callback_process_button(): Processing expression"); |
522 | |
c2774e9d |
523 | FilterViewerData *fvd = (FilterViewerData*)data; |
064565c5 |
524 | LttvFilter* filter; |
c2774e9d |
525 | |
1f7f7fe2 |
526 | if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) { |
064565c5 |
527 | filter = lttv_filter_new(); |
da2e1bfb |
528 | GString* s = g_string_new(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))); |
529 | lttv_filter_append_expression(filter,s->str); |
530 | g_string_free(s,TRUE); |
064565c5 |
531 | } else { |
532 | filter = NULL; |
1f7f7fe2 |
533 | } |
e433e6d6 |
534 | /* Remove the old filter if present */ |
535 | //g_object_set_data_full(fvd->obj, "filter", filter, |
536 | // (GDestroyNotify)lttv_filter_destroy); |
537 | //g_object_notify(fvd->obj, "filter"); |
538 | lttv_plugin_update_filter(fvd->plugin, filter); |
c2774e9d |
539 | } |
540 | |
3cea5310 |
541 | gboolean callback_enter_check(GtkWidget *widget, |
542 | GdkEventKey *event, |
543 | gpointer user_data) |
544 | { |
f42883f9 |
545 | g_debug("typed : %x", event->keyval); |
3cea5310 |
546 | switch(event->keyval) { |
547 | case GDK_Return: |
548 | case GDK_KP_Enter: |
549 | case GDK_ISO_Enter: |
550 | case GDK_3270_Enter: |
f42883f9 |
551 | callback_process_button(widget, user_data); |
3cea5310 |
552 | break; |
553 | default: |
554 | break; |
555 | } |
556 | return FALSE; |
557 | } |
558 | |
c2774e9d |
559 | /** |
7e7af7f2 |
560 | * @fn void callback_expression_field(GtkWidget*,gpointer) |
852f16bb |
561 | * |
c2774e9d |
562 | * The Add Button callback function |
563 | * @param widget The Button widget passed to the callback function |
564 | * @param data Data sent along with the callback function |
565 | */ |
7e7af7f2 |
566 | void |
567 | callback_expression_field(GtkWidget *widget, gpointer data) { |
da2e1bfb |
568 | |
c2774e9d |
569 | FilterViewerData *fvd = (FilterViewerData*)data; |
570 | |
571 | if(strlen(gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))) !=0) { |
572 | gtk_widget_show(fvd->f_logical_op_junction_box); |
573 | } else { |
574 | gtk_widget_hide(fvd->f_logical_op_junction_box); |
575 | } |
576 | } |
577 | |
578 | |
579 | /** |
7e7af7f2 |
580 | * @fn void callback_add_button(GtkWidget*,gpointer) |
852f16bb |
581 | * |
c2774e9d |
582 | * The Add Button callback function |
583 | * @param widget The Button widget passed to the callback function |
584 | * @param data Data sent along with the callback function |
585 | */ |
7e7af7f2 |
586 | void |
587 | callback_add_button(GtkWidget *widget, gpointer data) { |
c2774e9d |
588 | |
da2e1bfb |
589 | g_debug("callback_add_button(): processing simple expressions"); |
c2774e9d |
590 | |
da2e1bfb |
591 | unsigned i; |
592 | |
c2774e9d |
593 | FilterViewerData *fvd = (FilterViewerData*)data; |
594 | FilterViewerDataLine *fvdl = NULL; |
595 | GString* a_filter_string = g_string_new(""); |
2b715e58 |
596 | |
da2e1bfb |
597 | /* |
598 | * adding linking operator to |
599 | * string |
600 | */ |
2b715e58 |
601 | GString* s; |
602 | 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 |
603 | a_filter_string = g_string_append(a_filter_string,s->str); |
da2e1bfb |
604 | gtk_combo_box_set_active(GTK_COMBO_BOX(fvd->f_logical_op_junction_box),0); |
c2774e9d |
605 | |
da2e1bfb |
606 | /* begin expression */ |
4ec0c904 |
607 | a_filter_string = g_string_append_c(a_filter_string,'('); |
2b715e58 |
608 | |
da2e1bfb |
609 | /* |
610 | * For each simple expression, add the resulting string |
611 | * to the filter string |
612 | * |
613 | * Each simple expression takes the following schema |
614 | * [not operator '!',' '] [field type] [math operator '<','<=','>','>=','=','!='] [value] |
615 | */ |
c2774e9d |
616 | for(i=0;i<fvd->f_lines->len;i++) { |
617 | fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i); |
1f7f7fe2 |
618 | |
619 | s = g_ptr_array_index(fvd->f_not_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_not_op_box))); |
4ec0c904 |
620 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 |
621 | |
622 | s = g_ptr_array_index(fvd->f_field_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_field_box))); |
4ec0c904 |
623 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 |
624 | |
625 | s = g_ptr_array_index(fvd->f_math_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_math_op_box))); |
4ec0c904 |
626 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 |
627 | |
4ec0c904 |
628 | a_filter_string = g_string_append(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvdl->f_value_field))); |
2b715e58 |
629 | |
630 | s = g_ptr_array_index(fvd->f_logical_op_options,gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box))); |
4ec0c904 |
631 | a_filter_string = g_string_append(a_filter_string,s->str); |
2b715e58 |
632 | |
da2e1bfb |
633 | /* |
634 | * resetting simple expression lines |
635 | */ |
c2774e9d |
636 | gui_filter_line_reset(fvdl); |
2b715e58 |
637 | if(i) gui_filter_line_set_visible(fvdl,FALSE); // Only keep the first line |
c2774e9d |
638 | } |
639 | |
da2e1bfb |
640 | /* end expression */ |
4ec0c904 |
641 | a_filter_string = g_string_append_c(a_filter_string,')'); |
c2774e9d |
642 | |
2b715e58 |
643 | g_string_prepend(a_filter_string,gtk_entry_get_text(GTK_ENTRY(fvd->f_expression_field))); |
644 | gtk_entry_set_text(GTK_ENTRY(fvd->f_expression_field),a_filter_string->str); |
c2774e9d |
645 | |
646 | } |
647 | |
648 | /** |
7e7af7f2 |
649 | * @fn void callback_logical_op_box(GtkWidget*,gpointer) |
852f16bb |
650 | * |
c2774e9d |
651 | * The logical op box callback function |
652 | * @param widget The Button widget passed to the callback function |
653 | * @param data Data sent along with the callback function |
654 | */ |
7e7af7f2 |
655 | void |
656 | callback_logical_op_box(GtkWidget *widget, gpointer data) { |
c2774e9d |
657 | |
da2e1bfb |
658 | g_debug("callback_logical_op_box(): adding new simple expression"); |
c2774e9d |
659 | |
660 | FilterViewerData *fvd = (FilterViewerData*)data; |
661 | FilterViewerDataLine *fvdl = NULL; |
662 | |
663 | int i; |
664 | for(i=0;i<fvd->f_lines->len;i++) { |
665 | fvdl = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i); |
666 | if(fvdl->f_logical_op_box == widget) { |
da2e1bfb |
667 | if(gtk_combo_box_get_active(GTK_COMBO_BOX(fvdl->f_logical_op_box)) == 0) return; |
c2774e9d |
668 | if(i==fvd->f_lines->len-1) { /* create a new line */ |
669 | fvd->rows++; |
670 | FilterViewerDataLine* fvdl2 = gui_filter_add_line(fvd); |
671 | g_ptr_array_add(fvd->f_lines,(gpointer) fvdl2); |
672 | } else { |
673 | FilterViewerDataLine *fvdl2 = (FilterViewerDataLine*)g_ptr_array_index(fvd->f_lines,i+1); |
674 | if(!fvdl2->visible) gui_filter_line_set_visible(fvdl2,TRUE); |
675 | } |
676 | } |
677 | } |
678 | |
679 | } |
91ad3f0a |
680 | |
681 | LTTV_MODULE("guifilter", "Filter window", \ |
682 | "Graphical module that let user specify their filtering options", \ |
683 | init, destroy, "lttvwindow") |
684 | |