Humble Bundle support
[GameHub.git] / src / ui / dialogs / SettingsDialog.vala
blob5fc0f9fe02cc97ef2eef92d3dd27d382bd229b0e
1 using Gtk;
2 using Granite;
3 using GameHub.Utils;
5 namespace GameHub.UI.Dialogs
7 public class SettingsDialog: Dialog
9 private Box box;
11 public SettingsDialog()
13 Object(transient_for: Windows.MainWindow.instance, deletable: false, resizable: false);
15 set_modal(true);
17 var content = get_content_area();
18 content.set_size_request(480, -1);
20 box = new Box(Orientation.VERTICAL, 0);
21 box.margin_start = box.margin_end = 8;
23 var ui = Settings.UI.get_instance();
24 var paths = FSUtils.Paths.Settings.get_instance();
25 var steam_auth = Settings.Auth.Steam.get_instance();
27 add_switch(_("Use dark theme"), ui.dark_theme, e => { ui.dark_theme = e; });
28 add_separator();
30 add_header("Steam");
31 add_labeled_link(_("Steam API keys have limited number of uses per day"), _("Generate key"), "https://steamcommunity.com/dev/apikey");
32 add_entry(_("Steam API key"), steam_auth.api_key, v => { steam_auth.api_key = v; });
33 add_file_chooser(_("Steam installation directory"), FileChooserAction.SELECT_FOLDER, paths.steam_home, v => { paths.steam_home = v; }, false);
34 add_separator();
36 add_header("GOG");
37 add_file_chooser(_("GOG games directory"), FileChooserAction.SELECT_FOLDER, paths.gog_games, v => { paths.gog_games = v; });
38 add_separator();
40 add_header("Humble Bundle");
41 add_file_chooser(_("Humble Bundle games directory"), FileChooserAction.SELECT_FOLDER, paths.humble_games, v => { paths.humble_games = v; });
43 content.pack_start(box, false, false, 0);
45 response.connect((source, response_id) => {
46 switch(response_id)
48 case ResponseType.CLOSE:
49 destroy();
50 break;
52 });
54 add_button(_("Close"), ResponseType.CLOSE).margin_end = 7;
55 show_all();
58 private void add_switch(string text, bool enabled, owned SwitchAction action)
60 var sw = new Switch();
61 sw.active = enabled;
62 sw.halign = Align.END;
63 sw.notify["active"].connect(() => { action(sw.active); });
65 var label = new Label(text);
66 label.halign = Align.START;
67 label.hexpand = true;
69 var hbox = new Box(Orientation.HORIZONTAL, 12);
70 hbox.add(label);
71 hbox.add(sw);
72 add_widget(hbox);
75 private void add_entry(string text, string val, owned EntryAction action)
77 var entry = new Entry();
78 entry.text = val;
79 entry.notify["text"].connect(() => { action(entry.text); });
80 entry.set_size_request(280, -1);
82 var label = new Label(text);
83 label.halign = Align.START;
84 label.hexpand = true;
86 var hbox = new Box(Orientation.HORIZONTAL, 12);
87 hbox.add(label);
88 hbox.add(entry);
89 add_widget(hbox);
92 private void add_file_chooser(string text, FileChooserAction mode, string val, owned EntryAction action, bool create=true)
94 var chooser = new FileChooserButton(text, mode);
95 chooser.create_folders = create;
96 chooser.select_filename(FSUtils.expand(val));
97 chooser.file_set.connect(() => { action(chooser.get_filename()); });
98 chooser.set_size_request(280, -1);
100 var label = new Label(text);
101 label.halign = Align.START;
102 label.hexpand = true;
104 var hbox = new Box(Orientation.HORIZONTAL, 12);
105 hbox.add(label);
106 hbox.add(chooser);
107 add_widget(hbox);
110 private void add_label(string text)
112 var label = new Label(text);
113 label.halign = Align.START;
114 label.hexpand = true;
115 add_widget(label);
118 private void add_header(string text)
120 var label = new HeaderLabel(text);
121 label.xpad = 4;
122 label.halign = Align.START;
123 label.hexpand = true;
124 add_widget(label);
127 private void add_link(string text, string uri)
129 var link = new LinkButton.with_label(uri, text);
130 link.halign = Align.START;
131 link.hexpand = true;
132 add_widget(link);
135 private void add_labeled_link(string label_text, string text, string uri)
137 var label = new Label(label_text);
138 label.halign = Align.START;
140 var link = new LinkButton.with_label(uri, text);
141 link.halign = Align.START;
143 var hbox = new Box(Orientation.HORIZONTAL, 12);
144 hbox.add(label);
145 hbox.add(link);
146 add_widget(hbox);
149 private void add_separator()
151 add_widget(new Separator(Orientation.HORIZONTAL));
154 private void add_widget(Widget widget)
156 if(!(widget is HeaderLabel)) widget.margin = 4;
157 box.add(widget);
160 private delegate void SwitchAction(bool active);
161 private delegate void EntryAction(string val);