1 /* vim: set sts=2 sw=2 et: */
3 * Copyright (C) 2008 Jari Tenhunen <jari.tenhunen@iki.fi>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
27 #include <hildon/hildon-caption.h>
28 #include <hildon/hildon-defines.h>
29 #include <hildon/hildon-number-editor.h>
34 static GConfClient * client = NULL;
40 client = gconf_client_get_default ();
47 settings_get_display_keepalive (gboolean default_value)
49 GConfValue * value = NULL;
51 gboolean val = default_value;
53 value = gconf_client_get (get_client (), GCONF_KEY_DISPLAY_KEEPALIVE, &err);
59 if (value->type == GCONF_VALUE_BOOL)
60 val = gconf_value_get_bool (value);
62 gconf_value_free (value);
69 settings_set_display_keepalive (gboolean val)
71 return gconf_client_set_bool (get_client (), GCONF_KEY_DISPLAY_KEEPALIVE, val, NULL);
75 settings_get_algorithm (gint default_value)
77 GConfValue * value = NULL;
79 gint val = default_value;
81 value = gconf_client_get (get_client (), GCONF_KEY_ALGORITHM, &err);
87 if (value->type == GCONF_VALUE_INT)
88 val = gconf_value_get_int (value);
90 gconf_value_free (value);
97 settings_set_algorithm (gint val)
99 return gconf_client_set_int (get_client (), GCONF_KEY_ALGORITHM, val, NULL);
103 settings_get_calibration (gint default_value)
108 val = gconf_client_get_int (get_client (), GCONF_KEY_CALIBRATION, &err);
120 settings_set_calibration (gint value)
122 return gconf_client_set_int (get_client (), GCONF_KEY_CALIBRATION, value, NULL);
126 settings_init (GConfClientNotifyFunc func, gpointer user_data)
128 gconf_client_add_dir (get_client (), GCONF_ROOT, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
129 gconf_client_notify_add (get_client (), GCONF_ROOT, func, user_data, NULL, NULL);
136 fix_hildon_number_editor (GtkWidget * widget, gpointer data)
138 if (GTK_IS_EDITABLE (widget)) {
139 gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
140 g_object_set (G_OBJECT (widget), "can-focus", FALSE, NULL);
145 calibration_editor_new (gint min, gint max)
149 control = hildon_number_editor_new (min, max);
150 /* we don't want that ugly cursor there */
151 gtk_container_forall (GTK_CONTAINER (control),
152 (GtkCallback) fix_hildon_number_editor, NULL);
158 settings_dialog_show (GtkWindow * parent)
164 GtkWidget *editor = NULL;
169 dialog = gtk_dialog_new_with_buttons("Settings",
172 GTK_DIALOG_DESTROY_WITH_PARENT |
173 GTK_DIALOG_NO_SEPARATOR,
174 "OK", GTK_RESPONSE_OK,
179 g_signal_connect (G_OBJECT (dialog), "delete_event", G_CALLBACK (gtk_widget_destroy), NULL);
181 vbox = gtk_vbox_new (FALSE, HILDON_MARGIN_DEFAULT);
182 gtk_container_set_border_width (GTK_CONTAINER (vbox), HILDON_MARGIN_DEFAULT);
183 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
185 group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL));
187 combo = GTK_COMBO_BOX (gtk_combo_box_new_text ());
188 gtk_combo_box_append_text (combo, "Simple FFT");
189 gtk_combo_box_append_text (combo, "Harmonic Product Spectrum");
190 gtk_combo_box_set_active (combo, settings_get_algorithm (DEFAULT_ALGORITHM));
191 caption = hildon_caption_new (group, "Pitch detection algorithm:",
192 GTK_WIDGET (combo), NULL, HILDON_CAPTION_OPTIONAL);
193 gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, 0);
195 editor = calibration_editor_new (CALIB_MIN, CALIB_MAX);
196 hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (editor), CALIB_DEFAULT);
197 caption = hildon_caption_new (group, "Calibration:",
198 editor, NULL, HILDON_CAPTION_OPTIONAL);
199 gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, 0);
202 control = gtk_check_button_new ();
203 caption = hildon_caption_new (group, "Keep display on:",
204 control, NULL, HILDON_CAPTION_OPTIONAL);
205 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (control),
206 settings_get_display_keepalive (DEFAULT_DISPLAY_KEEPALIVE));
207 gtk_box_pack_start (GTK_BOX (vbox), caption, FALSE, FALSE, 0);
209 gtk_widget_show_all (dialog);
210 res = gtk_dialog_run (GTK_DIALOG (dialog));
212 if (res == GTK_RESPONSE_OK) {
214 g_debug ("algorithm: %d", gtk_combo_box_get_active (combo));
215 settings_set_algorithm (gtk_combo_box_get_active (combo));
217 g_debug ("calib: %d", hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (editor)));
218 settings_set_calibration (hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (editor)));
220 g_debug ("keepalive: %d", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (control)));
221 settings_set_display_keepalive (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (control)));
224 gtk_widget_destroy (dialog);