tootle-linux-client/src/Dialogs/Preferences.vala

96 lines
3.3 KiB
Vala
Raw Normal View History

2018-05-20 14:43:42 +02:00
using Gtk;
2019-03-11 15:14:37 +01:00
public class Tootle.Dialogs.Preferences : Dialog {
2018-05-20 14:43:42 +02:00
2019-03-11 15:14:37 +01:00
private static Preferences dialog;
2018-05-20 14:43:42 +02:00
2018-05-30 14:58:27 +02:00
private SettingsSwitch switch_notifications;
private SettingsSwitch switch_watcher;
2018-06-13 15:13:41 +02:00
private SettingsSwitch switch_stream;
private SettingsSwitch switch_stream_public;
2019-03-11 15:14:37 +01:00
private Grid grid;
2018-05-20 14:43:42 +02:00
2019-03-11 15:14:37 +01:00
public Preferences () {
2018-06-13 15:13:41 +02:00
border_width = 6;
deletable = false;
resizable = false;
title = _("Settings");
2018-10-23 12:05:24 +02:00
transient_for = window;
2019-03-11 15:14:37 +01:00
2018-05-20 14:43:42 +02:00
int i = 0;
2019-03-11 15:14:37 +01:00
grid = new Grid ();
2018-06-13 15:13:41 +02:00
switch_watcher = new SettingsSwitch ("always-online");
switch_notifications = new SettingsSwitch ("notifications");
switch_notifications.state_set.connect (state => {
switch_watcher.sensitive = state;
return false;
});
switch_stream = new SettingsSwitch ("live-updates");
switch_stream_public = new SettingsSwitch ("live-updates-public");
switch_stream.state_set.connect (state => {
switch_stream_public.sensitive = state;
return false;
});
2019-03-11 15:14:37 +01:00
2018-05-20 23:37:33 +02:00
grid.attach (new Granite.HeaderLabel (_("Appearance")), 0, i++, 2, 1);
grid.attach (new SettingsLabel (_("Dark theme:")), 0, i);
grid.attach (new SettingsSwitch ("dark-theme"), 1, i++);
2019-03-11 15:14:37 +01:00
2018-05-20 14:43:42 +02:00
grid.attach (new Granite.HeaderLabel (_("Timelines")), 0, i++, 2, 1);
grid.attach (new SettingsLabel (_("Real-time updates:")), 0, i);
2018-06-13 15:13:41 +02:00
grid.attach (switch_stream, 1, i++);
grid.attach (new SettingsLabel (_("Update public timelines:")), 0, i);
grid.attach (switch_stream_public, 1, i++);
2019-03-11 15:14:37 +01:00
2018-05-25 12:00:11 +02:00
// grid.attach (new Granite.HeaderLabel (_("Caching")), 0, i++, 2, 1);
// grid.attach (new SettingsLabel (_("Use cache:")), 0, i);
// grid.attach (new SettingsSwitch ("cache"), 1, i++);
// grid.attach (new SettingsLabel (_("Max cache size (MB):")), 0, i);
2019-03-11 15:14:37 +01:00
// var cache_size = new SpinButton.with_range (16, 256, 1);
2018-05-25 12:00:11 +02:00
// settings.schema.bind ("cache-size", cache_size, "value", SettingsBindFlags.DEFAULT);
// grid.attach (cache_size, 1, i++);
2019-03-11 15:14:37 +01:00
2018-05-20 14:43:42 +02:00
grid.attach (new Granite.HeaderLabel (_("Notifications")), 0, i++, 2, 1);
2018-05-30 14:58:27 +02:00
grid.attach (new SettingsLabel (_("Display notifications:")), 0, i);
grid.attach (switch_notifications, 1, i++);
2018-05-20 14:43:42 +02:00
grid.attach (new SettingsLabel (_("Always receive notifications:")), 0, i);
2018-05-30 14:58:27 +02:00
grid.attach (switch_watcher, 1, i++);
2019-03-11 15:14:37 +01:00
var content = get_content_area () as Box;
2018-05-20 14:43:42 +02:00
content.pack_start (grid, false, false, 0);
2019-03-11 15:14:37 +01:00
var close = add_button (_("_Close"), ResponseType.CLOSE) as Button;
2018-05-20 14:43:42 +02:00
close.clicked.connect (() => {
destroy ();
dialog = null;
});
2019-03-11 15:14:37 +01:00
2018-05-20 14:43:42 +02:00
show_all ();
}
public static void open () {
if (dialog == null)
2019-03-11 15:14:37 +01:00
dialog = new Preferences ();
2018-05-20 14:43:42 +02:00
}
2019-03-11 15:14:37 +01:00
protected class SettingsLabel : Label {
2018-05-20 14:43:42 +02:00
public SettingsLabel (string text) {
label = text;
2019-03-11 15:14:37 +01:00
halign = Align.END;
2018-05-20 14:43:42 +02:00
margin_start = 12;
margin_end = 12;
}
}
2019-03-11 15:14:37 +01:00
protected class SettingsSwitch : Switch {
2018-05-20 14:43:42 +02:00
public SettingsSwitch (string setting) {
2019-03-11 15:14:37 +01:00
halign = Align.START;
valign = Align.CENTER;
2018-05-20 14:43:42 +02:00
margin_bottom = 6;
2020-05-29 14:19:35 +02:00
settings.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
2018-05-20 14:43:42 +02:00
}
}
}