Deprecate settings.current_account property

This commit is contained in:
Bleak Grey 2021-02-20 14:02:25 +03:00
parent 1b08b37b9f
commit 7454ece650
3 changed files with 24 additions and 27 deletions

View File

@ -10,8 +10,8 @@
<schema path="/com/github/bleakgrey/tootle/" id="com.github.bleakgrey.tootle" gettext-domain="com.github.bleakgrey.tootle">
<key name="current-account" type="i">
<default>0</default>
<key name="active-account" type="s">
<default>''</default>
</key>
<key name="dark-theme" type="b">
<default>false</default>

View File

@ -8,19 +8,16 @@ public abstract class Tootle.AccountStore : GLib.Object {
// TODO: Make settings.current_account a string
public bool ensure_active_account () {
var has_active = false;
var account = find_by_handle (settings.active_account);
if (!saved.is_empty) {
if (settings.current_account > saved.size || settings.current_account <= 0)
settings.current_account = 0;
var last_account = saved[settings.current_account];
if (active != last_account) {
activate (last_account);
has_active = true;
}
if (account == null && !saved.is_empty) {
account = saved[0];
}
if (!has_active)
has_active = account != null;
if (has_active)
activate (account);
else
app.present_window ();
return has_active;
@ -59,21 +56,21 @@ public abstract class Tootle.AccountStore : GLib.Object {
saved.remove (account);
saved.notify_property ("size");
save ();
var id = settings.current_account - 1;
if (saved.size < 1)
active = null;
else {
if (id > saved.size - 1)
id = saved.size - 1;
else if (id < saved.size - 1)
id = 0;
}
settings.current_account = id;
ensure_active_account ();
}
public InstanceAccount? find_by_handle (string handle) {
var iter = saved.filter (acc => {
return acc.handle == handle;
});
iter.next ();
if (!iter.valid)
return null;
else
return iter.@get ();
}
public void activate (InstanceAccount account) {
message (@"Activating $(account.handle)...");
account.verify_credentials.begin ((obj, res) => {
@ -89,7 +86,7 @@ public abstract class Tootle.AccountStore : GLib.Object {
});
accounts.active = account;
settings.current_account = accounts.saved.index_of (account);
settings.active_account = account.handle;
}
[Signal (detailed = true)]

View File

@ -2,7 +2,7 @@ using GLib;
public class Tootle.Settings : GLib.Settings {
public int current_account { get; set; }
public string active_account { get; set; }
public bool dark_theme { get; set; }
public bool autostart { get; set; }
public bool work_in_background { get; set; }
@ -20,7 +20,7 @@ public class Tootle.Settings : GLib.Settings {
public Settings () {
Object (schema_id: Build.DOMAIN);
init ("current-account");
init ("active-account");
init ("dark-theme");
init ("autostart");
init ("work-in-background");