8617e8302c2b46a3122efbba665a44a34fb70127
[beifahrer] / src / settings-dialog.vala
1 /* This file is part of Beifahrer.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
5  * Beifahrer is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Beifahrer 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Beifahrer. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using Gtk;
20 using Hildon;
21
22 public class SettingsDialog : Gtk.Dialog {
23         public const string GCONF_KEY_USE_LOCATION = "/apps/beifahrer/use_location";
24         public const string GCONF_KEY_PRELOAD = "/apps/beifahrer/preload";
25
26         Hildon.CheckButton use_location;
27         Hildon.CheckButton preload;
28         GConf.Client gconf;
29
30         public SettingsDialog (Gtk.Window window) {
31                 set_title (_("Settings"));
32                 set_transient_for (window);
33
34                 var vbox = (VBox) get_content_area ();
35                 use_location = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
36                 use_location.set_label (_("Determine point of departure automatically"));
37                 preload = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
38                 preload.set_label (_("Preload lift details in the background"));
39                 vbox.pack_start (use_location, true, true, 0);
40                 vbox.pack_start (preload, true, true, 0);
41                 vbox.show_all ();
42
43                 add_button (_("Save"), ResponseType.APPLY);
44
45                 gconf = GConf.Client.get_default ();
46                 try {
47                         use_location.set_active (gconf.get_bool (GCONF_KEY_USE_LOCATION));
48                         preload.set_active (gconf.get_bool (GCONF_KEY_PRELOAD));
49                 } catch (Error e) {
50                         use_location.set_active (true);
51                 }
52
53                 response.connect (on_response);
54         }
55
56         void on_response (int response_id) {
57                 if (response_id == ResponseType.APPLY) try {
58                         gconf.set_bool (GCONF_KEY_USE_LOCATION, use_location.get_active ());
59                         gconf.set_bool (GCONF_KEY_PRELOAD, preload.get_active ());
60                         this.destroy ();
61                 } catch (Error e) {
62                 }
63         }
64 }