Updated Spanish translation
[anjuta-git-plugin.git] / plugins / profiler / gprof-function-call-tree-view.c
blob4cf3006d67c1d091e1d443e3ddc07528de20c7a8
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 GladeXML *gxml;
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 = glade_xml_get_widget (self->priv->gxml,
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;
158 self->priv = g_new0 (GProfFunctionCallTreeViewPriv, 1);
160 self->priv->gxml = glade_xml_new (PACKAGE_DATA_DIR
161 "/glade/profiler-function-call-tree.glade",
162 NULL, NULL);
163 self->priv->tree_store = gtk_tree_store_new (NUM_COLS, G_TYPE_STRING,
164 G_TYPE_STRING);
166 gprof_function_call_tree_view_create_columns (self);
168 list_view = glade_xml_get_widget (self->priv->gxml, "function_call_tree_view");
170 g_signal_connect (list_view, "row-activated",
171 G_CALLBACK (on_list_view_row_activated),
172 (gpointer) self);
175 static void
176 gprof_function_call_tree_view_finalize (GObject *obj)
178 GProfFunctionCallTreeView *self;
180 self = (GProfFunctionCallTreeView *) obj;
182 g_object_unref (self->priv->gxml);
183 g_free (self->priv);
186 static void
187 gprof_function_call_tree_view_class_init (GProfFunctionCallTreeViewClass *klass)
189 GObjectClass *object_class;
190 GProfViewClass *view_class;
192 object_class = (GObjectClass *) klass;
193 view_class = GPROF_VIEW_CLASS (klass);
195 object_class->finalize = gprof_function_call_tree_view_finalize;
196 view_class->refresh = gprof_function_call_tree_view_refresh;
197 view_class->get_widget = gprof_function_call_tree_view_get_widget;
200 GType
201 gprof_function_call_tree_view_get_type (void)
203 static GType obj_type = 0;
205 if (!obj_type)
207 static const GTypeInfo obj_info =
209 sizeof (GProfFunctionCallTreeViewClass),
210 (GBaseInitFunc) NULL,
211 (GBaseFinalizeFunc) NULL,
212 (GClassInitFunc) gprof_function_call_tree_view_class_init,
213 (GClassFinalizeFunc) NULL,
214 NULL, /* class_data */
215 sizeof (GProfFunctionCallTreeView),
216 0, /* n_preallocs */
217 (GInstanceInitFunc) gprof_function_call_tree_view_init,
218 NULL /* value_table */
220 obj_type = g_type_register_static (GPROF_VIEW_TYPE,
221 "GProfFunctionCallTreeView",
222 &obj_info, 0);
224 return obj_type;
227 GProfFunctionCallTreeView *
228 gprof_function_call_tree_view_new (GProfProfileData *profile_data,
229 IAnjutaSymbolManager *symbol_manager,
230 IAnjutaDocumentManager *document_manager)
232 GProfFunctionCallTreeView *view;
234 view = g_object_new (GPROF_FUNCTION_CALL_TREE_VIEW_TYPE, NULL);
235 gprof_view_set_data (GPROF_VIEW (view), profile_data);
236 gprof_view_set_symbol_manager (GPROF_VIEW (view), symbol_manager);
237 gprof_view_set_document_manager (GPROF_VIEW (view), document_manager);
239 return view;
242 void
243 gprof_function_call_tree_view_refresh (GProfView *view)
245 GProfFunctionCallTreeView *self;
246 GProfProfileData *data;
247 GProfCallGraph *call_graph;
248 GProfCallGraphBlock *current_block;
249 GList *root_iter;
250 GtkWidget *tree_view;
252 self = GPROF_FUNCTION_CALL_TREE_VIEW (view);
253 tree_view = glade_xml_get_widget (self->priv->gxml,
254 "function_call_tree_view");
256 g_object_ref (self->priv->tree_store);
258 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), NULL);
259 gtk_tree_store_clear (self->priv->tree_store);
261 data = gprof_view_get_data (view);
262 call_graph = gprof_profile_data_get_call_graph (data);
264 current_block = gprof_call_graph_get_first_block (call_graph, &root_iter);
266 while (current_block)
268 gprof_function_call_tree_view_add_function (self, call_graph,
269 current_block, NULL);
270 current_block = gprof_call_graph_block_get_next(root_iter, &root_iter);
273 gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view),
274 GTK_TREE_MODEL (self->priv->tree_store));
276 g_object_unref (self->priv->tree_store);
279 GtkWidget *
280 gprof_function_call_tree_view_get_widget (GProfView *view)
282 GProfFunctionCallTreeView *self;
284 self = GPROF_FUNCTION_CALL_TREE_VIEW (view);
286 return glade_xml_get_widget (self->priv->gxml,
287 "function_call_tree_scrolled");