5 namespace GameHub
.UI
.Dialogs
7 public class SettingsDialog
: Dialog
11 public SettingsDialog()
13 Object(transient_for
: Windows
.MainWindow
.instance
, deletable
: false, resizable
: false);
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
; });
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);
37 add_file_chooser(_("GOG games directory"), FileChooserAction
.SELECT_FOLDER
, paths
.gog_games
, v
=> { paths
.gog_games
= v
; });
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
) => {
48 case ResponseType
.CLOSE
:
54 add_button(_("Close"), ResponseType
.CLOSE
).margin_end
= 7;
58 private void add_switch(string text
, bool enabled
, owned SwitchAction action
)
60 var sw
= new
Switch();
62 sw
.halign
= Align
.END
;
63 sw
.notify
["active"].connect(() => { action(sw
.active
); });
65 var label
= new
Label(text
);
66 label
.halign
= Align
.START
;
69 var hbox
= new
Box(Orientation
.HORIZONTAL
, 12);
75 private void add_entry(string text
, string val
, owned EntryAction action
)
77 var entry
= new
Entry();
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
;
86 var hbox
= new
Box(Orientation
.HORIZONTAL
, 12);
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);
110 private void add_label(string text
)
112 var label
= new
Label(text
);
113 label
.halign
= Align
.START
;
114 label
.hexpand
= true;
118 private void add_header(string text
)
120 var label
= new
HeaderLabel(text
);
122 label
.halign
= Align
.START
;
123 label
.hexpand
= true;
127 private void add_link(string text
, string uri
)
129 var link
= new LinkButton
.with_label(uri
, text
);
130 link
.halign
= Align
.START
;
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);
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;
160 private delegate
void SwitchAction(bool active
);
161 private delegate
void EntryAction(string val
);