Integrate adding files with the file manager
[anjuta-git-plugin.git] / plugins / valgrind / vghelgrindprefs.c
bloba8b8a556d1cab7b96654589dded9f69634ec177d
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2003 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program 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. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <string.h>
30 #include <gconf/gconf-client.h>
31 #include <glib/gi18n.h>
33 #include "vghelgrindprefs.h"
36 #define PRIVATE_STACKS_KEY "/apps/anjuta/valgrind/helgrind/private-stacks"
37 #define SHOW_LAST_ACCESS_KEY "/apps/anjuta/valgrind/helgrind/show-last-access"
39 static void vg_helgrind_prefs_class_init (VgHelgrindPrefsClass *klass);
40 static void vg_helgrind_prefs_init (VgHelgrindPrefs *prefs);
41 static void vg_helgrind_prefs_destroy (GtkObject *obj);
42 static void vg_helgrind_prefs_finalize (GObject *obj);
44 static void helgrind_prefs_apply (VgToolPrefs *prefs);
45 static void helgrind_prefs_get_argv (VgToolPrefs *prefs, const char *tool, GPtrArray *argv);
48 static VgToolPrefsClass *parent_class = NULL;
51 GType
52 vg_helgrind_prefs_get_type (void)
54 static GType type = 0;
56 if (!type) {
57 static const GTypeInfo info = {
58 sizeof (VgHelgrindPrefsClass),
59 NULL, /* base_class_init */
60 NULL, /* base_class_finalize */
61 (GClassInitFunc) vg_helgrind_prefs_class_init,
62 NULL, /* class_finalize */
63 NULL, /* class_data */
64 sizeof (VgHelgrindPrefs),
65 0, /* n_preallocs */
66 (GInstanceInitFunc) vg_helgrind_prefs_init,
69 type = g_type_register_static (VG_TYPE_TOOL_PREFS, "VgHelgrindPrefs", &info, 0);
72 return type;
75 static void
76 vg_helgrind_prefs_class_init (VgHelgrindPrefsClass *klass)
78 GObjectClass *object_class = G_OBJECT_CLASS (klass);
79 GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
80 VgToolPrefsClass *tool_class = VG_TOOL_PREFS_CLASS (klass);
82 parent_class = g_type_class_ref (VG_TYPE_TOOL_PREFS);
84 object_class->finalize = vg_helgrind_prefs_finalize;
85 gtk_object_class->destroy = vg_helgrind_prefs_destroy;
87 /* virtual methods */
88 tool_class->apply = helgrind_prefs_apply;
89 tool_class->get_argv = helgrind_prefs_get_argv;
93 static void
94 toggle_button_toggled (GtkToggleButton *toggle, const char *key)
96 GConfClient *gconf;
97 gboolean bool;
99 gconf = gconf_client_get_default ();
101 bool = gtk_toggle_button_get_active (toggle);
102 gconf_client_set_bool (gconf, key, bool, NULL);
104 g_object_unref (gconf);
107 static void
108 menu_item_activated (GtkMenuItem *item, const char *key)
110 GConfClient *gconf;
111 const char *str;
113 gconf = gconf_client_get_default ();
115 str = g_object_get_data (G_OBJECT (item), "value");
116 gconf_client_set_string (gconf, key, str, NULL);
118 g_object_unref (gconf);
121 static char *show_last_access_opts[] = { "no", "some", "all" };
123 static GtkWidget *
124 show_last_access_new (GConfClient *gconf)
126 GtkWidget *omenu, *menu, *item;
127 int history = 0;
128 char *str;
129 int i;
131 str = gconf_client_get_string (gconf, SHOW_LAST_ACCESS_KEY, NULL);
133 menu = gtk_menu_new ();
134 for (i = 0; i < 3; i++) {
135 if (str && !strcmp (show_last_access_opts[i], str))
136 history = i;
138 item = gtk_menu_item_new_with_label (show_last_access_opts[i]);
139 g_object_set_data (G_OBJECT (item), "value", show_last_access_opts[i]);
140 g_signal_connect (item, "activate", G_CALLBACK (menu_item_activated), SHOW_LAST_ACCESS_KEY);
141 gtk_widget_show (item);
143 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
146 gtk_widget_show (menu);
147 omenu = gtk_option_menu_new ();
148 gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
149 gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), history);
151 g_free (str);
153 return omenu;
156 static void
157 vg_helgrind_prefs_init (VgHelgrindPrefs *prefs)
159 GtkWidget *widget, *hbox;
160 GConfClient *gconf;
161 gboolean bool;
163 gconf = gconf_client_get_default ();
165 VG_TOOL_PREFS (prefs)->label = _("Helgrind");
167 gtk_box_set_spacing (GTK_BOX (prefs), 6);
169 bool = gconf_client_get_bool (gconf, PRIVATE_STACKS_KEY, NULL);
170 widget = gtk_check_button_new_with_label (_("Assume thread stacks are used privately"));
171 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), bool);
172 g_signal_connect (widget, "toggled", G_CALLBACK (toggle_button_toggled), PRIVATE_STACKS_KEY);
173 prefs->private_stacks = GTK_TOGGLE_BUTTON (widget);
174 gtk_widget_show (widget);
175 gtk_box_pack_start (GTK_BOX (prefs), widget, FALSE, FALSE, 0);
177 hbox = gtk_hbox_new (FALSE, 6);
179 widget = gtk_label_new (_("Show location of last word access on error:"));
180 gtk_widget_show (widget);
181 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
183 widget = show_last_access_new (gconf);
184 prefs->show_last_access = GTK_OPTION_MENU (widget);
185 gtk_widget_show (widget);
186 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
188 gtk_widget_show (hbox);
189 gtk_box_pack_start (GTK_BOX (prefs), hbox, FALSE, FALSE, 0);
191 g_object_unref (gconf);
194 static void
195 vg_helgrind_prefs_finalize (GObject *obj)
197 G_OBJECT_CLASS (parent_class)->finalize (obj);
200 static void
201 vg_helgrind_prefs_destroy (GtkObject *obj)
203 GTK_OBJECT_CLASS (parent_class)->destroy (obj);
207 static void
208 helgrind_prefs_apply (VgToolPrefs *prefs)
213 enum {
214 ARG_TYPE_BOOL,
215 ARG_TYPE_STRING
218 static struct {
219 const char *key;
220 const char *arg;
221 char *buf;
222 int type;
223 int dval;
224 } helgrind_args[] = {
225 { PRIVATE_STACKS_KEY, "--private-stacks", NULL, ARG_TYPE_BOOL, 0 },
226 { SHOW_LAST_ACCESS_KEY, "--show-last-access", NULL, ARG_TYPE_STRING, 0 },
229 static void
230 helgrind_prefs_get_argv (VgToolPrefs *prefs, const char *tool, GPtrArray *argv)
232 GConfClient *gconf;
233 gboolean bool;
234 char *str;
235 int i;
237 gconf = gconf_client_get_default ();
239 for (i = 0; i < G_N_ELEMENTS (helgrind_args); i++) {
240 const char *arg = helgrind_args[i].arg;
241 const char *key = helgrind_args[i].key;
243 g_free (helgrind_args[i].buf);
244 if (helgrind_args[i].type == ARG_TYPE_BOOL) {
245 bool = gconf_client_get_bool (gconf, key, NULL) ? 1 : 0;
246 if (bool == helgrind_args[i].dval)
247 continue;
249 helgrind_args[i].buf = g_strdup_printf ("%s=%s", arg, bool ? "yes" : "no");
250 } else {
251 if (!(str = gconf_client_get_string (gconf, key, NULL)) || *str == '\0') {
252 helgrind_args[i].buf = NULL;
253 g_free (str);
254 continue;
257 helgrind_args[i].buf = g_strdup_printf ("%s=%s", arg, str);
258 g_free (str);
261 g_ptr_array_add (argv, helgrind_args[i].buf);
264 g_object_unref (gconf);