1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
5 * Copyright (C) Massimo Cora' 2006 <maxcvs@gmail.com>
7 * preferences.c is free software.
9 * You may redistribute it and/or modify it under the terms of the
10 * GNU General Public License, as published by the Free Software
11 * Foundation; either version 2, or (at your option) any later version.
13 * plugin.h is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with plugin.h. See the file "COPYING". If not,
20 * write to: The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #include "vggeneralprefs.h"
26 #include "vgmemcheckprefs.h"
27 #include "vgcachegrindprefs.h"
28 #include "vghelgrindprefs.h"
29 #include "preferences.h"
32 #include <gconf/gconf-client.h>
33 #include <libgnomevfs/gnome-vfs.h>
34 #include <libanjuta/anjuta-debug.h>
36 #define EDITOR_KEY "/apps/anjuta/valgrind/editor"
37 #define NUM_LINES_KEY "/apps/anjuta/valgrind/num-lines"
38 #define EXE_PATH "/apps/anjuta/valgrind/exe-path"
40 #define VALGRIND_DEFAULT_BIN "/usr/bin/valgrind"
45 PAGE_ADDRCHECK
= PAGE_MEMCHECK
,
50 struct _ValgrindPluginPrefsPriv
{
51 GtkWidget
* pages
[4]; /* must be used only to retrieve gconf parameters.
52 * Do NOT return these as widgets that can be destroyed */
56 static void valgrind_plugin_prefs_class_init(ValgrindPluginPrefsClass
*klass
);
57 static void valgrind_plugin_prefs_init(ValgrindPluginPrefs
*sp
);
58 static void valgrind_plugin_prefs_finalize(GObject
*object
);
60 static GObjectClass
*parent_class
= NULL
;
63 spin_changed (GtkSpinButton
*spin
, GdkEvent
*event
, const char *key
)
68 gconf
= gconf_client_get_default ();
70 num
= gtk_spin_button_get_value_as_int (spin
);
71 gconf_client_set_int (gconf
, key
, num
, NULL
);
73 g_object_unref (gconf
);
79 /*-----------------------------------------------------------------------------
80 * Callback for valgrind exe file path selection
84 on_exe_path_entry_changed (GtkFileChooser
*chooser
, const char *key
)
89 gconf
= gconf_client_get_default ();
91 str
= gtk_file_chooser_get_filename (chooser
);
93 DEBUG_PRINT ("str is %s key is %s", str
, key
);
95 gconf_client_set_string (gconf
, key
, str
? str
: "", NULL
);
98 g_object_unref (gconf
);
102 /*-----------------------------------------------------------------------------
103 * build and returns a widget containing the general prefs of alleyoop/valgrind
107 build_general_prefs ()
110 GtkWidget
*vbox
, *hbox
, *label
, *main_label
, *gen_page
, *widget
;
111 GtkSpinButton
*numlines
;
116 gconf
= gconf_client_get_default ();
118 vbox
= gtk_vbox_new (FALSE
, 6);
120 hbox
= gtk_hbox_new (FALSE
, 6);
122 main_label
= gtk_label_new ("");
123 gtk_label_set_markup (GTK_LABEL (main_label
), _("<b>Valgrind general preferences</b>"));
125 gtk_box_pack_start (GTK_BOX (hbox
), main_label
, FALSE
, FALSE
, 0);
126 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
128 hbox
= gtk_hbox_new (FALSE
, 6);
129 label
= gtk_label_new (_("Valgrind binary file path:"));
130 gtk_widget_show (label
);
131 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
133 str_file
= gconf_client_get_string (gconf
, EXE_PATH
, &err
);
135 if (str_file
== NULL
|| err
!= NULL
|| strlen (str_file
) <= 0) {
136 str_file
= g_strdup (VALGRIND_DEFAULT_BIN
);
139 if (!g_path_is_absolute(str_file
))
140 DEBUG_PRINT("Not absolute");
143 gtk_file_chooser_button_new (_("Choose Valgrind Binary File Path..."),
144 GTK_FILE_CHOOSER_ACTION_OPEN
);
146 if ( gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (widget
), str_file
) == FALSE
)
147 DEBUG_PRINT ("error: could not select file uri with gtk_file_chooser_select_filename ()");
151 /* grab every change in file selection */
152 g_signal_connect (widget
, "selection-changed", G_CALLBACK (on_exe_path_entry_changed
), EXE_PATH
);
154 gtk_widget_show (widget
);
155 gtk_box_pack_start (GTK_BOX (hbox
), widget
, TRUE
, TRUE
, 0);
157 gtk_widget_show (hbox
);
158 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
160 hbox
= gtk_hbox_new (FALSE
, 6);
162 label
= gtk_label_new (_("Preview"));
163 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
165 num
= gconf_client_get_int (gconf
, NUM_LINES_KEY
, NULL
);
166 numlines
= GTK_SPIN_BUTTON (gtk_spin_button_new_with_range (0, (gdouble
) INT_MAX
, 1));
167 gtk_spin_button_set_digits (numlines
, 0);
168 gtk_spin_button_set_numeric (numlines
, TRUE
);
169 gtk_spin_button_set_value (numlines
, (gdouble
) num
);
171 g_signal_connect (numlines
, "focus-out-event", G_CALLBACK (spin_changed
), NUM_LINES_KEY
);
172 gtk_widget_show (GTK_WIDGET (numlines
));
173 gtk_box_pack_start (GTK_BOX (hbox
), GTK_WIDGET (numlines
), FALSE
, FALSE
, 0);
175 label
= gtk_label_new (_("lines above and below the target line."));
176 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
177 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
179 /* create a fresh new general prefs widget and add it to the vbox */
180 gen_page
= g_object_new (VG_TYPE_GENERAL_PREFS
, NULL
);
181 gtk_box_pack_start (GTK_BOX (vbox
), gen_page
, FALSE
, FALSE
, 0);
183 gtk_widget_show_all (vbox
);
188 valgrind_plugin_prefs_create_argv (ValgrindPluginPrefs
*valprefs
, const char *tool
)
192 ValgrindPluginPrefsPriv
*priv
;
196 g_return_val_if_fail (valprefs
!= NULL
, NULL
);
198 priv
= valprefs
->priv
;
200 argv
= g_ptr_array_new ();
202 gconf
= gconf_client_get_default ();
203 str_file
= gconf_client_get_string (gconf
, EXE_PATH
, NULL
);
205 g_ptr_array_add (argv
, str_file
);
208 if (!strcmp (tool
, "memcheck")) {
209 g_ptr_array_add (argv
, "--tool=memcheck");
210 page
= PAGE_MEMCHECK
;
211 } else if (!strcmp (tool
, "addrcheck")) {
212 g_ptr_array_add (argv
, "--tool=addrcheck");
213 page
= PAGE_ADDRCHECK
;
214 } else if (!strcmp (tool
, "cachegrind")) {
215 g_ptr_array_add (argv
, "--tool=cachegrind");
216 page
= PAGE_CACHEGRIND
;
217 } else if (!strcmp (tool
, "helgrind")) {
218 g_ptr_array_add (argv
, "--tool=helgrind");
219 page
= PAGE_HELGRIND
;
221 g_assert_not_reached ();
225 g_ptr_array_add (argv
, "--tool=memcheck");
226 page
= PAGE_MEMCHECK
;
229 /* next, apply the general prefs */
230 vg_tool_prefs_get_argv (VG_TOOL_PREFS (priv
->pages
[PAGE_GENERAL
]), tool
, argv
);
232 /* finally, apply the current view's prefs */
233 vg_tool_prefs_get_argv (VG_TOOL_PREFS (priv
->pages
[page
]), tool
, argv
);
239 valgrind_plugin_prefs_get_anj_prefs (void)
241 return build_general_prefs ();
245 valgrind_plugin_prefs_get_general_widget (void)
247 return g_object_new (VG_TYPE_GENERAL_PREFS
, NULL
);
251 valgrind_plugin_prefs_get_memcheck_widget (void)
253 return g_object_new (VG_TYPE_MEMCHECK_PREFS
, NULL
);
257 valgrind_plugin_prefs_get_cachegrind_widget (void)
259 return g_object_new (VG_TYPE_CACHEGRIND_PREFS
, NULL
);
263 valgrind_plugin_prefs_get_helgrind_widget (void)
265 return g_object_new (VG_TYPE_HELGRIND_PREFS
, NULL
);
270 valgrind_plugin_prefs_get_type(void)
272 static GType type
= 0;
275 static const GTypeInfo our_info
= {
276 sizeof (ValgrindPluginPrefsClass
),
279 (GClassInitFunc
)valgrind_plugin_prefs_class_init
,
282 sizeof (ValgrindPluginPrefs
),
284 (GInstanceInitFunc
)valgrind_plugin_prefs_init
,
287 type
= g_type_register_static(G_TYPE_OBJECT
,
288 "ValgrindPluginPrefs", &our_info
, 0);
295 valgrind_plugin_prefs_class_init(ValgrindPluginPrefsClass
*klass
)
297 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
299 parent_class
= g_type_class_peek_parent(klass
);
300 object_class
->finalize
= valgrind_plugin_prefs_finalize
;
304 valgrind_plugin_prefs_init(ValgrindPluginPrefs
*obj
)
306 ValgrindPluginPrefsPriv
*priv
;
307 obj
->priv
= g_new0(ValgrindPluginPrefsPriv
, 1);
311 /* build our own widgets. These will be used only by VgActions to retrieve
313 priv
->pages
[PAGE_GENERAL
] = g_object_new (VG_TYPE_GENERAL_PREFS
, NULL
);
314 priv
->pages
[PAGE_MEMCHECK
] = g_object_new (VG_TYPE_MEMCHECK_PREFS
, NULL
);
315 priv
->pages
[PAGE_CACHEGRIND
] = g_object_new (VG_TYPE_CACHEGRIND_PREFS
, NULL
);
316 priv
->pages
[PAGE_HELGRIND
] = g_object_new (VG_TYPE_HELGRIND_PREFS
, NULL
);
320 valgrind_plugin_prefs_finalize(GObject
*object
)
322 ValgrindPluginPrefs
*cobj
;
323 cobj
= VALGRIND_PLUGINPREFS(object
);
325 /* FIXME: Free private members, etc. */
327 G_OBJECT_CLASS(parent_class
)->finalize(object
);
330 ValgrindPluginPrefs
*
331 valgrind_plugin_prefs_new(void)
333 ValgrindPluginPrefs
*obj
;
335 obj
= VALGRIND_PLUGINPREFS(g_object_new(VALGRIND_TYPE_PLUGINPREFS
, NULL
));