Debian packaging: 0.0.4-1
[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 namespace Hildon {
23         [CCode (cname = "hildon_gtk_entry_set_placeholder_text")]
24         extern static void gtk_entry_set_placeholder_text (Gtk.Entry entry, string placeholder_text);
25
26         [CCode (cname = "hildon_gtk_entry_set_input_mode")]
27         extern static void gtk_entry_set_input_mode (Gtk.Entry entry, Hildon.GtkInputMode mode);
28 }
29
30 public class SettingsDialog : Gtk.Dialog {
31         public const string GCONF_KEY_USE_LOCATION = "/apps/beifahrer/use_location";
32         public const string GCONF_KEY_PRELOAD = "/apps/beifahrer/preload";
33         public const string GCONF_KEY_USERNAME = "/apps/beifahrer/adac/username";
34         public const string GCONF_KEY_PASSWORD = "/apps/beifahrer/adac/password";
35
36         Hildon.CheckButton use_location;
37         Hildon.CheckButton preload;
38         Hildon.Entry username;
39         Hildon.Entry password;
40         GConf.Client gconf;
41
42         public SettingsDialog (Gtk.Window window) {
43                 set_title (_("Settings"));
44                 set_transient_for (window);
45
46                 var vbox = (VBox) get_content_area ();
47                 use_location = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
48                 use_location.set_label (_("Determine point of departure automatically"));
49                 preload = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
50                 preload.set_label (_("Preload lift details in the background"));
51                 username = new Hildon.Entry (SizeType.FINGER_HEIGHT);
52                 Hildon.gtk_entry_set_placeholder_text (username, _("Username"));
53                 password = new Hildon.Entry (SizeType.FINGER_HEIGHT);
54                 password.set_visibility (false);
55                 Hildon.gtk_entry_set_placeholder_text (password, _("Password"));
56                 vbox.pack_start (use_location, true, true, 0);
57                 vbox.pack_start (preload, true, true, 0);
58                 vbox.pack_start (username, true, true, 0);
59                 vbox.pack_start (password, true, true, 0);
60                 vbox.show_all ();
61
62                 add_button (_("Save"), ResponseType.APPLY);
63
64                 gconf = GConf.Client.get_default ();
65                 try {
66                         use_location.set_active (gconf.get_bool (GCONF_KEY_USE_LOCATION));
67                         preload.set_active (gconf.get_bool (GCONF_KEY_PRELOAD));
68                         username.set_text (gconf.get_string (GCONF_KEY_USERNAME));
69                         password.set_text (gconf.get_string (GCONF_KEY_PASSWORD));
70                 } catch (Error e) {
71                         use_location.set_active (true);
72                 }
73
74                 response.connect (on_response);
75         }
76
77         void on_response (int response_id) {
78                 if (response_id == ResponseType.APPLY) try {
79                         gconf.set_bool (GCONF_KEY_USE_LOCATION, use_location.get_active ());
80                         gconf.set_bool (GCONF_KEY_PRELOAD, preload.get_active ());
81                         gconf.set_string (GCONF_KEY_USERNAME, username.get_text ());
82                         gconf.set_string (GCONF_KEY_PASSWORD, password.get_text ());
83                         this.destroy ();
84                 } catch (Error e) {
85                 }
86         }
87 }