Add new Preferences dialog

This commit is contained in:
Bleak Grey 2020-05-31 21:55:40 +03:00
parent 94c3d43fe1
commit f6c7b1795e
6 changed files with 201 additions and 84 deletions

View File

@ -9,4 +9,4 @@ Terminal=false
Categories=GNOME;GTK;Network;
Keywords=toot;mastodon;social;network;post;
X-GNOME-Gettext-Domain=com.github.bleakgrey.tootle
X-GNOME-UsesNotifications=true
X-GNOME-UsesNotifications=true

View File

@ -10,5 +10,6 @@
<file preprocess="xml-stripblanks">ui/widgets/accounts_button_item.ui</file>
<file preprocess="xml-stripblanks">ui/dialogs/compose.ui</file>
<file preprocess="xml-stripblanks">ui/dialogs/main.ui</file>
<file preprocess="xml-stripblanks">ui/dialogs/preferences.ui</file>
</gresource>
</gresources>

View File

@ -0,0 +1,185 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<requires lib="libhandy" version="0.0"/>
<template class="TootleDialogsPreferences" parent="HdyPreferencesWindow">
<property name="default_height">600</property>
<property name="default_width">500</property>
<property name="width_request">300</property>
<!--<property name="search_enabled">false</property>-->
<!--Application-->
<child>
<object class="HdyPreferencesPage">
<property name="icon_name">preferences-other-symbolic</property>
<property name="title" translatable="yes">Application</property>
<property name="visible">True</property>
<child>
<object class="HdyPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Appearance</property>
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="activatable_widget">use_dark_mode</property>
<property name="title" translatable="yes">Dark theme</property>
<child type="action">
<object class="GtkSwitch" id="use_dark_mode">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="HdyPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Behavior</property>
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="activatable_widget">autostart</property>
<property name="title" translatable="yes">Autostart</property>
<property name="subtitle" translatable="yes">Start minimized at boot</property>
<child type="action">
<object class="GtkSwitch" id="autostart">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="activatable_widget">work_in_background</property>
<property name="title" translatable="yes">Background work</property>
<property name="subtitle" translatable="yes">Receive notifications even when the app window is closed</property>
<child type="action">
<object class="GtkSwitch" id="work_in_background">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="HdyComboRow" id="default_post_visibility">
<property name="visible">True</property>
<property name="title" translatable="yes">Default post visibility</property>
</object>
</child>
</object>
</child>
</object>
</child>
<!--Timelines-->
<child>
<object class="HdyPreferencesPage">
<property name="icon_name">view-list-symbolic</property>
<property name="title" translatable="yes">Timelines</property>
<property name="visible">True</property>
<child>
<object class="HdyPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Appearance</property>
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="activatable_widget">timeline_page_size</property>
<property name="title" translatable="yes">Posts per page</property>
<child type="action">
<object class="GtkSpinButton" id="timeline_page_size">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<property name="digits">0</property>
<property name="adjustment">page_adjustment</property>
</object>
</child>
</object>
</child>
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="activatable_widget">post_text_size</property>
<property name="title" translatable="yes">Post text size</property>
<child type="action">
<object class="GtkSpinButton" id="post_text_size">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<property name="digits">0</property>
<property name="adjustment">font_adjustment</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="HdyPreferencesGroup">
<property name="visible">True</property>
<property name="title" translatable="yes">Behavior</property>
<child>
<object class="HdyActionRow" id="live_updates_row">
<property name="visible">True</property>
<property name="activatable_widget">live_updates</property>
<property name="title" translatable="yes">Stream timelines</property>
<property name="subtitle" translatable="yes">Add and remove posts in real-time</property>
<child type="action">
<object class="GtkSwitch" id="live_updates">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
<child>
<object class="HdyActionRow">
<property name="visible">True</property>
<property name="activatable_widget">public_live_updates</property>
<property name="sensitive" bind-source="live_updates" bind-property="state" bind-flags="sync-create"></property>
<property name="title" translatable="yes">Stream public timelines</property>
<property name="subtitle" translatable="yes">Warning: This will use more resources on crowded instances</property>
<child type="action">
<object class="GtkSwitch" id="public_live_updates">
<property name="visible">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
<object class="GtkAdjustment" id="page_adjustment">
<property name="lower">10</property>
<property name="upper">50</property>
<property name="value">20</property>
<property name="page-increment">1</property>
<property name="step-increment">1</property>
</object>
<object class="GtkAdjustment" id="font_adjustment">
<property name="lower">14</property>
<property name="upper">32</property>
<property name="value">14</property>
<property name="page-increment">1</property>
<property name="step-increment">1</property>
</object>
</interface>

View File

@ -9,7 +9,7 @@ public class Build {
public static void print_info () {
var os_name = get_os_info ("NAME");
var os_ver = get_os_info ("VERSION");
message (@"$(Build.NAME) $(Build.VERSION)");
message (@"$NAME $VERSION");
message (@"Running on: $os_name $os_ver");
message (@"Build type: FROM_SOURCE");
}

View File

@ -19,7 +19,7 @@ public class Tootle.Dialogs.MainWindow: Gtk.Window, ISavedWindow {
protected Hdy.ViewSwitcher timeline_switcher;
[GtkChild]
protected Widgets.AccountsButton accounts_button;
Views.Base? last_view = null;
construct {

View File

@ -1,95 +1,26 @@
using Gtk;
public class Tootle.Dialogs.Preferences : Dialog {
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/dialogs/preferences.ui")]
public class Tootle.Dialogs.Preferences : Hdy.PreferencesWindow {
private static Preferences dialog;
[GtkChild]
Hdy.ComboRow default_post_visibility;
private SettingsSwitch switch_notifications;
private SettingsSwitch switch_watcher;
private SettingsSwitch switch_stream;
private SettingsSwitch switch_stream_public;
private Grid grid;
public Preferences () {
border_width = 6;
deletable = false;
resizable = false;
title = _("Settings");
construct {
transient_for = window;
int i = 0;
grid = new Grid ();
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;
default_post_visibility.set_for_enum (typeof (API.Visibility), e => {
var i = e.get_value ();
var vis = API.Visibility.all ()[i];
default_post_visibility.subtitle = vis.get_desc ();
return vis.get_name ();
});
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++);
grid.attach (new Granite.HeaderLabel (_("Timelines")), 0, i++, 2, 1);
grid.attach (new SettingsLabel (_("Real-time updates:")), 0, i);
grid.attach (switch_stream, 1, i++);
grid.attach (new SettingsLabel (_("Update public timelines:")), 0, i);
grid.attach (switch_stream_public, 1, i++);
// 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);
// var cache_size = new SpinButton.with_range (16, 256, 1);
// settings.schema.bind ("cache-size", cache_size, "value", SettingsBindFlags.DEFAULT);
// grid.attach (cache_size, 1, i++);
grid.attach (new Granite.HeaderLabel (_("Notifications")), 0, i++, 2, 1);
grid.attach (new SettingsLabel (_("Display notifications:")), 0, i);
grid.attach (switch_notifications, 1, i++);
grid.attach (new SettingsLabel (_("Always receive notifications:")), 0, i);
grid.attach (switch_watcher, 1, i++);
var content = get_content_area () as Box;
content.pack_start (grid, false, false, 0);
var close = add_button (_("_Close"), ResponseType.CLOSE) as Button;
close.clicked.connect (() => {
destroy ();
dialog = null;
});
show_all ();
show ();
}
public static void open () {
if (dialog == null)
dialog = new Preferences ();
}
protected class SettingsLabel : Label {
public SettingsLabel (string text) {
label = text;
halign = Align.END;
margin_start = 12;
margin_end = 12;
}
}
protected class SettingsSwitch : Switch {
public SettingsSwitch (string setting) {
halign = Align.START;
valign = Align.CENTER;
margin_bottom = 6;
settings.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
}
new Preferences ();
}
}