Fix #530740 – Use GtkBuilder instead of libglade
[anjuta-extras.git] / plugins / profiler / gprof-flat-profile-view.c
blobae5f37578532ff15fb036fad3f7d53dd6bf74899
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * gprof-flat-profile-view.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
5 *
6 * gprof-flat-profile-view.c is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2, or (at your option) any later version.
12 * plugin.c is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with plugin.c. See the file "COPYING". If not,
19 * write to: The Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include "gprof-flat-profile-view.h"
25 #include <glib/gi18n-lib.h>
27 struct _GProfFlatProfileViewPriv
29 GtkBuilder *bxml;
30 GtkListStore *list_store;
33 enum
35 COL_NAME = 0,
36 COL_TIME_PERC,
37 COL_CUM_SEC,
38 COL_SELF_SEC,
39 COL_CALLS,
40 COL_AVG_MS,
41 COL_TOTAL_MS,
42 NUM_COLS
45 static void
46 gprof_flat_profile_view_create_columns (GProfFlatProfileView *self)
48 GtkTreeViewColumn *col;
49 GtkCellRenderer *renderer;
50 GtkWidget *list_view;
52 list_view = GTK_WIDGET (gtk_builder_get_object (self->priv->bxml, "flat_profile_view"));
54 /* Function name */
55 col = gtk_tree_view_column_new ();
56 gtk_tree_view_column_set_title (col, _("Function Name"));
57 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
60 renderer = gtk_cell_renderer_text_new ();
61 gtk_tree_view_column_pack_start (col, renderer, TRUE);
62 gtk_tree_view_column_add_attribute (col, renderer, "text", COL_NAME);
63 gtk_tree_view_column_set_resizable (col, TRUE);
64 gtk_tree_view_column_set_reorderable (col, TRUE);
66 /* Function time percentage */
67 col = gtk_tree_view_column_new ();
68 gtk_tree_view_column_set_title (col, _("% Time"));
69 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
71 renderer = gtk_cell_renderer_text_new ();
72 gtk_tree_view_column_pack_start (col, renderer, TRUE);
73 gtk_tree_view_column_set_cell_data_func (col, renderer,
74 gprof_view_format_float,
75 GINT_TO_POINTER (COL_TIME_PERC),
76 NULL);
77 gtk_tree_view_column_set_resizable (col, TRUE);
78 gtk_tree_view_column_set_reorderable (col, TRUE);
80 /* Cumulative seconds */
81 col = gtk_tree_view_column_new ();
82 gtk_tree_view_column_set_title (col, _("Cumulative Seconds"));
83 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
85 renderer = gtk_cell_renderer_text_new ();
86 gtk_tree_view_column_pack_start (col, renderer, TRUE);
87 gtk_tree_view_column_set_cell_data_func (col, renderer,
88 gprof_view_format_float,
89 GINT_TO_POINTER (COL_CUM_SEC),
90 NULL);
91 gtk_tree_view_column_set_resizable (col, TRUE);
92 gtk_tree_view_column_set_reorderable (col, TRUE);
94 /* Self seconds */
95 col = gtk_tree_view_column_new ();
97 /* The number of seconds that this function, excluding other functions it
98 * calls, takes to execute. */
99 gtk_tree_view_column_set_title (col, _("Self Seconds"));
100 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
102 renderer = gtk_cell_renderer_text_new ();
103 gtk_tree_view_column_pack_start (col, renderer, TRUE);
104 gtk_tree_view_column_set_cell_data_func (col, renderer,
105 gprof_view_format_float,
106 GINT_TO_POINTER (COL_SELF_SEC),
107 NULL);
108 gtk_tree_view_column_set_resizable (col, TRUE);
109 gtk_tree_view_column_set_reorderable (col, TRUE);
111 /* Calls */
112 col = gtk_tree_view_column_new ();
113 gtk_tree_view_column_set_title (col, _("Calls"));
114 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
116 renderer = gtk_cell_renderer_text_new ();
117 gtk_tree_view_column_pack_start (col, renderer, TRUE);
118 gtk_tree_view_column_add_attribute (col, renderer, "text", COL_CALLS);
119 gtk_tree_view_column_set_resizable (col, TRUE);
120 gtk_tree_view_column_set_reorderable (col, TRUE);
122 /* Self ms/call */
123 col = gtk_tree_view_column_new ();
125 /* The average number of milliseconds spent in a function, excluding
126 * the functions that it calls. */
127 gtk_tree_view_column_set_title (col, _("Self ms/call"));
128 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
130 renderer = gtk_cell_renderer_text_new ();
131 gtk_tree_view_column_pack_start (col, renderer, TRUE);
132 gtk_tree_view_column_set_cell_data_func (col, renderer,
133 gprof_view_format_float,
134 GINT_TO_POINTER (COL_AVG_MS),
135 NULL);
136 gtk_tree_view_column_set_resizable (col, TRUE);
137 gtk_tree_view_column_set_reorderable (col, TRUE);
139 /* Total ms/call */
140 col = gtk_tree_view_column_new ();
142 /* Same as self ms/call, but includes called functions. */
143 gtk_tree_view_column_set_title (col, _("Total ms/call"));
144 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), col);
146 renderer = gtk_cell_renderer_text_new ();
147 gtk_tree_view_column_pack_start (col, renderer, TRUE);
148 gtk_tree_view_column_set_cell_data_func (col, renderer,
149 gprof_view_format_float,
150 GINT_TO_POINTER (COL_TOTAL_MS),
151 NULL);
152 gtk_tree_view_column_set_resizable (col, TRUE);
153 gtk_tree_view_column_set_reorderable (col, TRUE);
155 /* Model setup */
156 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view),
157 GTK_TREE_MODEL (self->priv->list_store));
158 g_object_unref (self->priv->list_store);
162 static void
163 on_list_view_row_activated (GtkTreeView *list_view,
164 GtkTreePath *path,
165 GtkTreeViewColumn *col,
166 gpointer user_data)
168 GProfView *self;
169 GtkTreeIter list_iter;
170 GtkTreeModel *model;
171 gchar *selected_function_name;
173 self = GPROF_VIEW (user_data);
174 model = gtk_tree_view_get_model (list_view);
176 if (gtk_tree_model_get_iter (model, &list_iter, path))
178 gtk_tree_model_get (model,
179 &list_iter, COL_NAME,
180 &selected_function_name, -1);
182 gprof_view_show_symbol_in_editor (self, selected_function_name);
184 g_free (selected_function_name);
188 static void
189 gprof_flat_profile_view_init (GProfFlatProfileView *self)
191 GError* error = NULL;
192 GtkWidget *list_view;
194 self->priv = g_new0 (GProfFlatProfileViewPriv, 1);
196 self->priv->bxml = gtk_builder_new ();
197 if (!gtk_builder_add_from_file (self->priv->bxml, PACKAGE_DATA_DIR"/glade/profiler-flat-profile.ui", &error))
199 g_warning ("Couldn't load builder file: %s", error->message);
200 g_error_free (error);
203 self->priv->list_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING,
204 G_TYPE_FLOAT, G_TYPE_FLOAT,
205 G_TYPE_FLOAT, G_TYPE_UINT,
206 G_TYPE_FLOAT, G_TYPE_FLOAT);
208 gprof_flat_profile_view_create_columns (self);
210 list_view = GTK_WIDGET (gtk_builder_get_object (self->priv->bxml, "flat_profile_view"));
212 g_signal_connect (list_view, "row-activated",
213 G_CALLBACK (on_list_view_row_activated),
214 (gpointer) self);
218 static void
219 gprof_flat_profile_view_finalize (GObject *obj)
221 GProfFlatProfileView *self;
223 self = (GProfFlatProfileView *) obj;
225 g_object_unref (self->priv->bxml);
226 g_free (self->priv);
229 static void
230 gprof_flat_profile_view_class_init (GProfFlatProfileViewClass *klass)
232 GObjectClass *object_class;
233 GProfViewClass *view_class;
235 object_class = (GObjectClass *) klass;
236 view_class = GPROF_VIEW_CLASS (klass);
238 object_class->finalize = gprof_flat_profile_view_finalize;
239 view_class->refresh = gprof_flat_profile_view_refresh;
240 view_class->get_widget = gprof_flat_profile_view_get_widget;
243 GType
244 gprof_flat_profile_view_get_type (void)
246 static GType obj_type = 0;
248 if (!obj_type)
250 static const GTypeInfo obj_info =
252 sizeof (GProfFlatProfileViewClass),
253 (GBaseInitFunc) NULL,
254 (GBaseFinalizeFunc) NULL,
255 (GClassInitFunc) gprof_flat_profile_view_class_init,
256 (GClassFinalizeFunc) NULL,
257 NULL, /* class_data */
258 sizeof (GProfFlatProfileView),
259 0, /* n_preallocs */
260 (GInstanceInitFunc) gprof_flat_profile_view_init,
261 NULL /* value_table */
263 obj_type = g_type_register_static (GPROF_VIEW_TYPE,
264 "GProfFlatProfileView", &obj_info, 0);
266 return obj_type;
269 GProfFlatProfileView *
270 gprof_flat_profile_view_new (GProfProfileData *profile_data,
271 IAnjutaSymbolManager *symbol_manager,
272 IAnjutaDocumentManager *document_manager)
274 GProfFlatProfileView *view;
276 view = g_object_new (GPROF_FLAT_PROFILE_VIEW_TYPE, NULL);
277 gprof_view_set_data (GPROF_VIEW (view), profile_data);
278 gprof_view_set_symbol_manager (GPROF_VIEW (view), symbol_manager);
279 gprof_view_set_document_manager (GPROF_VIEW (view), document_manager);
281 return view;
284 void
285 gprof_flat_profile_view_refresh (GProfView *view)
287 GProfFlatProfileView *self;
288 GProfProfileData *data;
289 GProfFlatProfile *flat_profile;
290 GProfFlatProfileEntry *current_entry;
291 GList *entry_iter;
292 GtkWidget *list_view;
293 GtkTreeIter view_iter;
295 self = GPROF_FLAT_PROFILE_VIEW (view);
296 list_view = GTK_WIDGET (gtk_builder_get_object (self->priv->bxml, "flat_profile_view"));
298 g_object_ref (self->priv->list_store);
299 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view), NULL);
300 gtk_list_store_clear (self->priv->list_store);
302 data = gprof_view_get_data (view);
303 flat_profile = gprof_profile_data_get_flat_profile (data);
304 current_entry = gprof_flat_profile_get_first_entry (flat_profile,
305 &entry_iter);
307 while (current_entry)
309 gtk_list_store_append (self->priv->list_store, &view_iter);
310 gtk_list_store_set (self->priv->list_store, &view_iter,
311 COL_NAME,
312 gprof_flat_profile_entry_get_name (current_entry),
313 COL_TIME_PERC,
314 gprof_flat_profile_entry_get_time_perc (current_entry),
315 COL_CUM_SEC,
316 gprof_flat_profile_entry_get_cum_sec (current_entry),
317 COL_SELF_SEC,
318 gprof_flat_profile_entry_get_self_sec (current_entry),
319 COL_CALLS,
320 gprof_flat_profile_entry_get_calls (current_entry),
321 COL_AVG_MS,
322 gprof_flat_profile_entry_get_avg_ms (current_entry),
323 COL_TOTAL_MS,
324 gprof_flat_profile_entry_get_total_ms (current_entry),
325 -1);
327 current_entry = gprof_flat_profile_entry_get_next (entry_iter,
328 &entry_iter);
331 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view),
332 GTK_TREE_MODEL (self->priv->list_store));
333 g_object_unref (self->priv->list_store);
337 GtkWidget *
338 gprof_flat_profile_view_get_widget (GProfView *view)
340 GProfFlatProfileView *self;
342 self = GPROF_FLAT_PROFILE_VIEW (view);
344 return GTK_WIDGET (gtk_builder_get_object (self->priv->bxml, "flat_profile_scrolled"));