mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-08 15:48:41 +01:00
Add settings view
This commit is contained in:
parent
5a854a7ae0
commit
1dd8e20577
@ -36,5 +36,15 @@
|
||||
<summary>Cache images to reduce network load</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
<key name="cache-size" type="i">
|
||||
<default>64</default>
|
||||
<summary>Cache size</summary>
|
||||
<description>Sets the maximum size of cached content</description>
|
||||
</key>
|
||||
<key name="live-updates" type="b">
|
||||
<default>true</default>
|
||||
<summary>Update timelines in real-time</summary>
|
||||
<description></description>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
|
@ -45,6 +45,7 @@ executable(
|
||||
'src/Widgets/AttachmentWidget.vala',
|
||||
'src/Widgets/AttachmentBox.vala',
|
||||
'src/Dialogs/PostDialog.vala',
|
||||
'src/Dialogs/SettingsDialog.vala',
|
||||
'src/Views/AbstractView.vala',
|
||||
'src/Views/AddAccountView.vala',
|
||||
'src/Views/TimelineView.vala',
|
||||
|
73
src/Dialogs/SettingsDialog.vala
Normal file
73
src/Dialogs/SettingsDialog.vala
Normal file
@ -0,0 +1,73 @@
|
||||
using Gtk;
|
||||
using Tootle;
|
||||
|
||||
public class Tootle.SettingsDialog : Gtk.Dialog {
|
||||
|
||||
private static SettingsDialog dialog;
|
||||
|
||||
private Gtk.Grid grid;
|
||||
|
||||
public SettingsDialog () {
|
||||
Object (
|
||||
border_width: 6,
|
||||
deletable: false,
|
||||
resizable: false,
|
||||
title: _("Settings"),
|
||||
transient_for: Tootle.window
|
||||
);
|
||||
|
||||
int i = 0;
|
||||
grid = new Gtk.Grid ();
|
||||
|
||||
grid.attach (new Granite.HeaderLabel (_("Timelines")), 0, i++, 2, 1);
|
||||
grid.attach (new SettingsLabel (_("Real-time updates:")), 0, i);
|
||||
grid.attach (new SettingsSwitch ("live-updates"), 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 Gtk.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 (_("Always receive notifications:")), 0, i);
|
||||
grid.attach (new SettingsSwitch ("always-online"), 1, i++);
|
||||
|
||||
var content = get_content_area () as Gtk.Box;
|
||||
content.pack_start (grid, false, false, 0);
|
||||
|
||||
var close = add_button (_("_Close"), Gtk.ResponseType.CLOSE) as Gtk.Button;
|
||||
close.clicked.connect (() => {
|
||||
destroy ();
|
||||
dialog = null;
|
||||
});
|
||||
|
||||
show_all ();
|
||||
}
|
||||
|
||||
public static void open () {
|
||||
if (dialog == null)
|
||||
dialog = new SettingsDialog ();
|
||||
}
|
||||
|
||||
protected class SettingsLabel : Gtk.Label {
|
||||
public SettingsLabel (string text) {
|
||||
label = text;
|
||||
halign = Gtk.Align.END;
|
||||
margin_start = 12;
|
||||
margin_end = 12;
|
||||
}
|
||||
}
|
||||
|
||||
protected class SettingsSwitch : Gtk.Switch {
|
||||
public SettingsSwitch (string setting) {
|
||||
halign = Gtk.Align.START;
|
||||
valign = Gtk.Align.CENTER;
|
||||
margin_bottom = 6;
|
||||
Tootle.settings.schema.bind (setting, this, "active", SettingsBindFlags.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -20,10 +20,8 @@ public class Tootle.NetManager : GLib.Object {
|
||||
private Notificator? notificator;
|
||||
|
||||
construct {
|
||||
cache_path = "%s/%s".printf (GLib.Environment.get_user_cache_dir (), "tootle");
|
||||
cache_path = "%s/%s".printf (GLib.Environment.get_user_cache_dir (), Tootle.app.application_id);
|
||||
cache = new Soup.Cache (cache_path, Soup.CacheType.SINGLE_USER);
|
||||
cache.set_max_size (1024 * 1024 * 64); // 64 mb
|
||||
|
||||
session = new Soup.Session ();
|
||||
session.ssl_strict = true;
|
||||
session.ssl_use_system_ca_file = true;
|
||||
@ -35,16 +33,18 @@ public class Tootle.NetManager : GLib.Object {
|
||||
finished ();
|
||||
});
|
||||
|
||||
Tootle.app.shutdown.connect (() => {
|
||||
cache.dump ();
|
||||
});
|
||||
Tootle.settings.changed.connect (on_settings_changed);
|
||||
on_settings_changed ();
|
||||
|
||||
// Soup.Logger logger = new Soup.Logger (Soup.LoggerLogLevel.BODY, -1);
|
||||
// session.add_feature (logger);
|
||||
}
|
||||
|
||||
public NetManager() {
|
||||
GLib.Object();
|
||||
if (Tootle.settings.cache) {
|
||||
session.add_feature (cache);
|
||||
Tootle.app.shutdown.connect (() => cache.flush ());
|
||||
}
|
||||
|
||||
Tootle.accounts.switched.connect (acc => {
|
||||
if (notificator != null)
|
||||
@ -57,6 +57,24 @@ public class Tootle.NetManager : GLib.Object {
|
||||
});
|
||||
}
|
||||
|
||||
private void on_settings_changed () {
|
||||
cache.set_max_size (1024 * 1024 * Tootle.settings.cache_size);
|
||||
|
||||
var has_cache = session.has_feature (cache.get_type ());
|
||||
if (Tootle.settings.cache) {
|
||||
if (!has_cache) {
|
||||
debug ("Turning on cache");
|
||||
session.add_feature (cache);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (has_cache) {
|
||||
debug ("Turning off cache");
|
||||
session.remove_feature (cache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void abort (Soup.Message msg) {
|
||||
session.cancel_message (msg, 0);
|
||||
}
|
||||
@ -161,6 +179,4 @@ public class Tootle.NetManager : GLib.Object {
|
||||
Tootle.network.queue (msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -39,17 +39,26 @@ public class Tootle.Notificator : GLib.Object {
|
||||
var type = root.get_string_member ("event");
|
||||
switch (type) {
|
||||
case "update":
|
||||
var status = Status.parse (sanitize (root));
|
||||
network.status_added (ref status, "home");
|
||||
if (Tootle.settings.live_updates) {
|
||||
var status = Status.parse (sanitize (root));
|
||||
network.status_added (ref status, "home");
|
||||
}
|
||||
else
|
||||
Tootle.app.toast ("New post available");
|
||||
|
||||
break;
|
||||
case "delete":
|
||||
var id = int64.parse (root.get_string_member("payload"));
|
||||
network.status_removed (id);
|
||||
if (Tootle.settings.live_updates) {
|
||||
var id = int64.parse (root.get_string_member("payload"));
|
||||
network.status_removed (id);
|
||||
}
|
||||
|
||||
break;
|
||||
case "notification":
|
||||
var notif = Notification.parse (sanitize (root));
|
||||
toast (notif);
|
||||
network.notification (ref notif);
|
||||
|
||||
break;
|
||||
default:
|
||||
warning ("Unknown push event: %s", type);
|
||||
|
@ -7,6 +7,8 @@ public class Tootle.SettingsManager : Granite.Services.Settings {
|
||||
public string instance_url { get; set; }
|
||||
public bool always_online { get; set; }
|
||||
public bool cache { get; set; }
|
||||
public int cache_size { get; set; }
|
||||
public bool live_updates { get; set; }
|
||||
|
||||
public void clear_account (){
|
||||
access_token = "null";
|
||||
|
@ -67,6 +67,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||
|
||||
item_settings = new Gtk.ModelButton ();
|
||||
item_settings.text = _("Settings");
|
||||
item_settings.clicked.connect (() => SettingsDialog.open ());
|
||||
|
||||
grid = new Gtk.Grid ();
|
||||
grid.orientation = Gtk.Orientation.VERTICAL;
|
||||
@ -77,7 +78,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
||||
grid.attach(new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 4, 1, 1);
|
||||
grid.attach(item_refresh, 0, 5, 1, 1);
|
||||
grid.attach(item_search, 0, 6, 1, 1);
|
||||
//grid.attach(item_settings, 0, 8, 1, 1);
|
||||
grid.attach(item_settings, 0, 8, 1, 1);
|
||||
grid.show_all ();
|
||||
|
||||
menu = new Gtk.Popover (null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user