Fix #530740 – Use GtkBuilder instead of libglade
[anjuta-extras.git] / plugins / profiler / gprof-function-call-tree-view.c
blob8c35a7efc629a00a8bc6b7432cafe4067e633f31
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * gprof-function-call-tree-view.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
5 *
6 * gprof-function-call-tree-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-function-call-tree-view.h"
25 #include <glib/gi18n-lib.h>
27 struct _GProfFunctionCallTreeViewPriv
29 GtkBuilder *bxml;
30 GtkTreeStore *tree_store;
33 enum
35 COL_RECURSIVE = 0,
36 COL_NAME,
37 NUM_COLS
40 static void
41 gprof_function_call_tree_view_create_columns (GProfFunctionCallTreeView *self)
43 GtkTreeViewColumn *col;
44 GtkCellRenderer *renderer;
45 GtkWidget *tree_view;
47 tree_view = GTK_WIDGET (gtk_builder_get_object (self->priv->bxml,
48 "function_call_tree_view"));
50 /* Recursive icon */
51 col = gtk_tree_view_column_new ();
52 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
54 renderer = gtk_cell_renderer_pixbuf_new ();
55 gtk_tree_view_column_pack_start (col, renderer, TRUE);
56 gtk_tree_view_column_add_attribute (col, renderer, "stock-id", COL_RECURSIVE);
58 /* Function name */
59 col = gtk_tree_view_column_new ();
60 gtk_tree_view_column_set_title (col, _("Function Name"));
61 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
62 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree_view), col);
64 renderer = gtk_cell_renderer_text_new ();
65 gtk_tree_view_column_pack_start (col, renderer, TRUE);
66 gtk_tree_view_column_add_attribute (col, renderer, "text", COL_NAME);
67 gtk_tree_view_column_set_resizable (col, TRUE);
68 gtk_tree_view_column_set_reorderable (col, TRUE);
70 /* Model setup */
71 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view),
72 GTK_TREE_MODEL (self->priv->tree_store));
73 g_object_unref (self->priv->tree_store);
76 static void
77 gprof_function_call_tree_view_add_function (GProfFunctionCallTreeView *self,
78 GProfCallGraph *call_graph,
79 GProfCallGraphBlock *block,
80 GtkTreeIter *parent_iter)
82 GtkTreeIter child_iter;
83 GList *entry_iter;
84 GProfCallGraphBlockEntry *current_entry;
85 GProfCallGraphBlockEntry *current_child;
86 GProfCallGraphBlock *next_block;
87 GProfCallGraphBlockEntry *next_block_primary_entry;
88 gchar *current_entry_name;
89 gchar *next_block_name;
91 current_entry = gprof_call_graph_block_get_primary_entry (block);
92 current_entry_name = gprof_call_graph_block_entry_get_name (current_entry);
94 gtk_tree_store_append (self->priv->tree_store, &child_iter, parent_iter);
95 gtk_tree_store_set (self->priv->tree_store, &child_iter, COL_NAME,
96 current_entry_name, -1);
98 if (gprof_call_graph_block_is_recursive (block))
99 gtk_tree_store_set (self->priv->tree_store, &child_iter, COL_RECURSIVE,
100 GTK_STOCK_REFRESH, -1);
102 current_child = gprof_call_graph_block_get_first_child (block, &entry_iter);
104 while (current_child)
106 next_block = gprof_call_graph_find_block (call_graph,
107 gprof_call_graph_block_entry_get_name (current_child));
108 current_child = gprof_call_graph_block_entry_get_next (entry_iter,
109 &entry_iter);
111 if (next_block)
113 next_block_primary_entry = gprof_call_graph_block_get_primary_entry (next_block);
114 next_block_name = gprof_call_graph_block_entry_get_name (next_block_primary_entry);
116 /* Make sure we don't go into an infinite loop on recursive functions */
117 if (strcmp(next_block_name, current_entry_name) == 0)
118 continue;
120 gprof_function_call_tree_view_add_function (self, call_graph,
121 next_block, &child_iter);
127 static void
128 on_list_view_row_activated (GtkTreeView *list_view,
129 GtkTreePath *path,
130 GtkTreeViewColumn *col,
131 gpointer user_data)
133 GProfView *self;
134 GtkTreeIter list_iter;
135 GtkTreeModel *model;
136 gchar *selected_function_name;
138 self = GPROF_VIEW (user_data);
139 model = gtk_tree_view_get_model (list_view);
141 if (gtk_tree_model_get_iter (model, &list_iter, path))
143 gtk_tree_model_get (model,
144 &list_iter, COL_NAME,
145 &selected_function_name, -1);
147 gprof_view_show_symbol_in_editor (self, selected_function_name);
149 g_free (selected_function_name);
153 static void
154 gprof_function_call_tree_view_init (GProfFunctionCallTreeView *self)
156 GtkWidget *list_view;
157 GError* error = NULL;
159 self->priv = g_new0 (GProfFunctionCallTreeViewPriv, 1);
161 self->priv->bxml = gtk_builder_new ();
162 if (!gtk_builder_add_from_file (self->priv->bxml, PACKAGE_DATA_DIR"/glade/profiler-function-call-tree.ui", &error))
164 g_warning ("Couldn't load builder file: %s", error->message);
165 g_error_free (error);
168 self->priv->tree_store = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING,
169 G_TYPE_STRING);
171 gprof_function_call_tree_view_create_columns (self);
173 list_view = GTK_WIDGET (gtk_builder_get_object (self->priv->bxml, "function_call_tree_view"));
175 g_signal_connect (list_view, "row-activated",
176 G_CALLBACK (on_list_view_row_activated),
177 (gpointer) self);
180 static void
181 gprof_function_call_tree_view_finalize (GObject *obj)
183 GProfFunctionCallTreeView *self;
185 self = (GProfFunctionCallTreeView *) obj;
187 g_object_unref (self->priv->bxml);
188 g_free (self->priv);
191 static void
192 gprof_function_call_tree_view_class_init (GProfFunctionCallTreeViewClass *klass)
194 GObjectClass *object_class;
195 GProfViewClass *view_class;
197 object_class = (GObjectClass *) klass;
198 view_class = GPROF_VIEW_CLASS (klass);
200 object_class->finalize = gprof_function_call_tree_view_finalize;
201 view_class->refresh = gprof_function_call_tree_view_refresh;
202 view_class->get_widget = gprof_function_call_tree_view_get_widget;
205 GType
206 gprof_function_call_tree_view_get_type (void)
208 static GType obj_type = 0;
210 if (!obj_type)
212 static const GTypeInfo obj_info =
214 sizeof (GProfFunctionCallTreeViewClass),
215 (GBaseInitFunc) NULL,
216 (GBaseFinalizeFunc) NULL,
217 (GClassInitFunc) gprof_function_call_tree_view_class_init,
218 (GClassFinalizeFunc) NULL,
219 NULL, /* class_data */
220 sizeof (GProfFunctionCallTreeView),
221 0, /* n_preallocs */
222 (GInstanceInitFunc) gprof_function_call_tree_view_init,
223 NULL /* value_table */
225 obj_type = g_type_register_static (GPROF_VIEW_TYPE,
226 "GProfFunctionCallTreeView",
227 &obj_info, 0);
229 return obj_type;
232 GProfFunctionCallTreeView *
233 gprof_function_call_tree_view_new (GProfProfileData *profile_data,
234 IAnjutaSymbolManager *symbol_manager,
235 IAnjutaDocumentManager *document_manager)
237 GProfFunctionCallTreeView *view;
239 view = g_object_new (GPROF_FUNCTION_CALL_TREE_VIEW_TYPE, NULL);
240 gprof_view_set_data (GPROF_VIEW (view), profile_data);
241 gprof_view_set_symbol_manager (GPROF_VIEW (view), symbol_manager);
242 gprof_view_set_document_manager (GPROF_VIEW (view), document_manager);
244 return view;
247 void
248 gprof_function_call_tree_view_refresh (GProfView *view)
250 GProfFunctionCallTreeView *self;
251 GProfProfileData *data;
252 GProfCallGraph *call_graph;
253 GProfCallGraphBlock *current_block;
254 GList *root_iter;
255 GtkWidget *tree_view;
257 self = GPROF_FUNCTION_CALL_TREE_VIEW (view);
258 tree_view = GTK_WIDGET (gtk_builder_get_object (self->priv->bxml,
259 "function_call_tree_view"));
261 g_object_ref (self->priv->tree_store);
263 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), NULL);
264 gtk_tree_store_clear (self->priv->tree_store);
266 data = gprof_view_get_data (view);
267 call_graph = gprof_profile_data_get_call_graph (data);
269 current_block = gprof_call_graph_get_first_block (call_graph, &root_iter);
271 while (current_block)
273 gprof_function_call_tree_view_add_function (self, call_graph,
274 current_block, NULL);
275 current_block = gprof_call_graph_block_get_next(root_iter, &root_iter);
278 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view),
279 GTK_TREE_MODEL (self->priv->tree_store));
281 g_object_unref (self->priv->tree_store);
284 GtkWidget *
285 gprof_function_call_tree_view_get_widget (GProfView *view)
287 GProfFunctionCallTreeView *self;
289 self = GPROF_FUNCTION_CALL_TREE_VIEW (view);
291 return GTK_WIDGET (gtk_builder_get_object (self->priv->bxml,
292 "function_call_tree_scrolled"));