IAccountListener -> IAccountHolder
This commit is contained in:
parent
8337f18604
commit
43647fa9d4
|
@ -56,7 +56,7 @@ sources = files(
|
|||
'src/Services/Accounts/InstanceAccount.vala',
|
||||
'src/Services/Accounts/AccountStore.vala',
|
||||
'src/Services/Accounts/FileAccountStore.vala',
|
||||
'src/Services/Accounts/IAccountListener.vala',
|
||||
'src/Services/Accounts/IAccountHolder.vala',
|
||||
'src/Services/Accounts/Mastodon/MastodonAccount.vala',
|
||||
'src/Services/Streams.vala',
|
||||
'src/Services/Settings.vala',
|
||||
|
|
|
@ -5,6 +5,9 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
|||
public ArrayList<InstanceAccount> saved { get; set; default = new ArrayList<InstanceAccount> (); }
|
||||
public InstanceAccount? active { get; set; default = null; }
|
||||
|
||||
public signal void changed (ArrayList<InstanceAccount> accounts);
|
||||
public signal void switched (InstanceAccount? account);
|
||||
|
||||
public bool ensure_active_account () {
|
||||
var has_active = false;
|
||||
var account = find_by_handle (settings.active_account);
|
||||
|
@ -14,9 +17,9 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
|||
}
|
||||
|
||||
has_active = account != null;
|
||||
if (has_active)
|
||||
activate (account);
|
||||
else
|
||||
activate (account);
|
||||
|
||||
if (!has_active)
|
||||
app.present_window ();
|
||||
|
||||
return has_active;
|
||||
|
@ -53,7 +56,7 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
|||
message (@"Removing account: $(account.handle)");
|
||||
account.unsubscribe ();
|
||||
saved.remove (account);
|
||||
saved.notify_property ("size");
|
||||
changed (saved);
|
||||
save ();
|
||||
ensure_active_account ();
|
||||
}
|
||||
|
@ -70,22 +73,29 @@ public abstract class Tootle.AccountStore : GLib.Object {
|
|||
return iter.@get ();
|
||||
}
|
||||
|
||||
public void activate (InstanceAccount account) {
|
||||
message (@"Activating $(account.handle)...");
|
||||
account.verify_credentials.begin ((obj, res) => {
|
||||
try {
|
||||
account.verify_credentials.end (res);
|
||||
account.error = null;
|
||||
}
|
||||
catch (Error e) {
|
||||
warning (@"Couldn't activate account $(account.handle):");
|
||||
warning (e.message);
|
||||
account.error = e;
|
||||
}
|
||||
});
|
||||
public void activate (InstanceAccount? account) {
|
||||
if (account == null) {
|
||||
message ("Reset active account");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
message (@"Activating $(account.handle)...");
|
||||
account.verify_credentials.begin ((obj, res) => {
|
||||
try {
|
||||
account.verify_credentials.end (res);
|
||||
account.error = null;
|
||||
settings.active_account = account.handle;
|
||||
}
|
||||
catch (Error e) {
|
||||
warning (@"Couldn't activate account $(account.handle):");
|
||||
warning (e.message);
|
||||
account.error = e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
accounts.active = account;
|
||||
settings.active_account = account.handle;
|
||||
switched (active);
|
||||
}
|
||||
|
||||
[Signal (detailed = true)]
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
public interface Tootle.IAccountHolder : GLib.Object {
|
||||
|
||||
protected abstract InstanceAccount? account { get; set; default = null; }
|
||||
|
||||
protected void account_listener_init () {
|
||||
accounts.switched.connect (on_account_changed);
|
||||
accounts.changed.connect (on_accounts_changed);
|
||||
on_account_changed (accounts.active);
|
||||
}
|
||||
protected void account_listener_free () {
|
||||
accounts.switched.disconnect (on_account_changed);
|
||||
accounts.changed.disconnect (on_accounts_changed);
|
||||
}
|
||||
|
||||
public virtual void on_account_changed (InstanceAccount? account) {}
|
||||
public virtual void on_accounts_changed (Gee.ArrayList<InstanceAccount> accounts) {}
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
[Deprecated]
|
||||
public interface Tootle.IAccountListener : GLib.Object {
|
||||
|
||||
protected void account_listener_init () {
|
||||
accounts.notify["active"].connect (_on_active_acc_update);
|
||||
accounts.saved.notify["size"].connect (_on_saved_accs_update);
|
||||
on_account_changed (accounts.active);
|
||||
}
|
||||
protected void account_listener_free () {
|
||||
accounts.notify["active"].disconnect (_on_active_acc_update);
|
||||
accounts.saved.notify["size"].disconnect (_on_saved_accs_update);
|
||||
}
|
||||
|
||||
void _on_active_acc_update (ParamSpec s) {
|
||||
on_account_changed (accounts.active);
|
||||
}
|
||||
|
||||
void _on_saved_accs_update (ParamSpec s) {
|
||||
on_accounts_changed (accounts.saved);
|
||||
}
|
||||
|
||||
public virtual void on_account_changed (InstanceAccount? account) {}
|
||||
public virtual void on_accounts_changed (Gee.ArrayList<InstanceAccount> accounts) {}
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using Gtk;
|
||||
using Gdk;
|
||||
|
||||
public class Tootle.Views.Notifications : Views.Timeline, IAccountListener, IStreamListener {
|
||||
public class Tootle.Views.Notifications : Views.Timeline, IAccountHolder, IStreamListener {
|
||||
|
||||
protected int64 last_id = 0;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using Gtk;
|
||||
|
||||
public class Tootle.Views.Thread : Views.Base, IAccountListener {
|
||||
public class Tootle.Views.Thread : Views.Base, IAccountHolder {
|
||||
|
||||
protected InstanceAccount? account { get; set; default = null; }
|
||||
public API.Status root_status { get; construct set; }
|
||||
protected InstanceAccount? account = null;
|
||||
protected Widgets.Status root_widget;
|
||||
|
||||
public Thread (API.Status status) {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
using Gtk;
|
||||
using Gdk;
|
||||
|
||||
public class Tootle.Views.Timeline : IAccountListener, IStreamListener, Views.Base {
|
||||
public class Tootle.Views.Timeline : IAccountHolder, IStreamListener, Views.Base {
|
||||
|
||||
public string url { get; construct set; }
|
||||
public bool is_public { get; construct set; default = false; }
|
||||
public Type accepts { get; set; default = typeof (API.Status); }
|
||||
|
||||
protected InstanceAccount? account = null;
|
||||
protected InstanceAccount? account { get; set; default = null; }
|
||||
protected ulong on_status_added_sigig;
|
||||
|
||||
public bool is_last_page { get; set; default = false; }
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using Gtk;
|
||||
|
||||
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/accounts_button.ui")]
|
||||
public class Tootle.Widgets.AccountsButton : Gtk.MenuButton, IAccountListener {
|
||||
public class Tootle.Widgets.AccountsButton : Gtk.MenuButton, IAccountHolder {
|
||||
|
||||
protected InstanceAccount? account { get; set; default = null; }
|
||||
|
||||
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/accounts_button_item.ui")]
|
||||
class Item : ListBoxRow {
|
||||
|
|
Loading…
Reference in New Issue