Fix #530740 – Use GtkBuilder instead of libglade
[anjuta-extras.git] / plugins / profiler / gprof-view.c
blob1da7f2de7f11d7925350508f0ce486e6aaa0162b
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * gprof-view.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
5 *
6 * gprof-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-view.h"
26 struct _GProfViewPriv
28 GProfProfileData *profile_data;
29 IAnjutaSymbolManager *symbol_manager;
30 IAnjutaDocumentManager *document_manager;
33 static void
34 gprof_view_init (GProfView *self)
36 self->priv = g_new0 (GProfViewPriv, 1);
39 static void
40 gprof_view_finalize (GObject *obj)
42 GProfView *self;
44 self = (GProfView *) obj;
46 gprof_profile_data_free (self->priv->profile_data);
47 g_free(self->priv);
50 static void
51 gprof_view_class_init (GProfViewClass *klass)
53 GObjectClass *object_class;
55 object_class = (GObjectClass *) klass;
56 object_class->finalize = gprof_view_finalize;
58 klass->refresh = NULL;
59 klass->get_widget = NULL;
62 GType
63 gprof_view_get_type (void)
65 static GType obj_type = 0;
67 if (!obj_type)
69 static const GTypeInfo obj_info =
71 sizeof (GProfViewClass),
72 (GBaseInitFunc) NULL,
73 (GBaseFinalizeFunc) NULL,
74 (GClassInitFunc) gprof_view_class_init,
75 (GClassFinalizeFunc) NULL,
76 NULL, /* class_data */
77 sizeof (GProfView),
78 0, /* n_preallocs */
79 (GInstanceInitFunc) gprof_view_init,
80 NULL /* value_table */
82 obj_type = g_type_register_static (G_TYPE_OBJECT,
83 "GProfView", &obj_info, 0);
85 return obj_type;
88 void
89 gprof_view_set_data (GProfView *self, GProfProfileData *profile_data)
91 self->priv->profile_data = g_object_ref (profile_data);
94 GProfProfileData *
95 gprof_view_get_data (GProfView *self)
97 return self->priv->profile_data;
100 void
101 gprof_view_set_symbol_manager (GProfView *self,
102 IAnjutaSymbolManager *symbol_manager)
104 self->priv->symbol_manager = symbol_manager;
107 void
108 gprof_view_set_document_manager (GProfView *self,
109 IAnjutaDocumentManager *document_manager)
111 self->priv->document_manager = document_manager;
114 void
115 gprof_view_show_symbol_in_editor (GProfView *self,
116 const gchar *symbol_name)
118 IAnjutaIterable *symbol_iter;
119 IAnjutaSymbol *symbol;
120 guint line;
122 if (self->priv->symbol_manager &&
123 self->priv->document_manager)
125 symbol_iter = ianjuta_symbol_manager_search (self->priv->symbol_manager,
126 IANJUTA_SYMBOL_TYPE_FUNCTION,
127 TRUE,
128 IANJUTA_SYMBOL_FIELD_SIMPLE,
129 symbol_name,
130 FALSE,
131 TRUE,
132 FALSE,
135 NULL);
137 if (symbol_iter &&
138 ianjuta_iterable_get_length (symbol_iter, NULL) > 0)
140 GFile* file;
141 symbol = IANJUTA_SYMBOL (symbol_iter);
142 file = ianjuta_symbol_get_file (symbol, NULL);
143 line = ianjuta_symbol_get_line (symbol, NULL);
145 ianjuta_document_manager_goto_file_line (self->priv->document_manager,
146 file, line, NULL);
148 g_object_unref (symbol_iter);
149 g_object_unref (file);
154 void
155 gprof_view_refresh (GProfView *self)
157 /* Don't refresh views if we don't have any data to work with */
158 if (gprof_profile_data_has_data (self->priv->profile_data))
159 GPROF_VIEW_GET_CLASS (self)->refresh (self);
162 GtkWidget *
163 gprof_view_get_widget (GProfView *self)
165 return GPROF_VIEW_GET_CLASS (self)->get_widget (self);
168 void
169 gprof_view_format_float (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
170 GtkTreeModel *model, GtkTreeIter *iter,
171 gpointer column_number)
173 gfloat number;
174 gchar *formatted_number;
176 gtk_tree_model_get (model, iter, GPOINTER_TO_INT (column_number), &number,
177 -1);
179 formatted_number = g_strdup_printf ("%0.2f", number);
180 g_object_set (renderer, "text", formatted_number, NULL);
182 g_free (formatted_number);