From f5e9b4f2dc49d5ab8c14578728a2c032c7b78ae7 Mon Sep 17 00:00:00 2001 From: bleakgrey Date: Sat, 14 Apr 2018 20:53:09 +0300 Subject: [PATCH] Remove redundant signal --- src/AccountManager.vala | 9 +++++++-- src/Application.vala | 6 +++++- src/MainWindow.vala | 10 +++------- src/Views/HomeView.vala | 9 ++++++--- src/Widgets/AccountsButton.vala | 5 +++-- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/AccountManager.vala b/src/AccountManager.vala index 3ef8208..c7c1ed9 100644 --- a/src/AccountManager.vala +++ b/src/AccountManager.vala @@ -2,7 +2,7 @@ using GLib; public class Tootle.AccountManager : Object{ - public abstract signal void changed_current(Account account); + public abstract signal void changed_current(Account? account); public abstract signal void added(Account account); public abstract signal void removed(Account account); @@ -89,7 +89,7 @@ public class Tootle.AccountManager : Object{ var access_token = root.get_string_member ("access_token"); settings.access_token = access_token; debug ("Got access token"); - Tootle.app.state_updated (); + update_current (); } catch (GLib.Error e) { warning ("Can't get access token"); @@ -114,5 +114,10 @@ public class Tootle.AccountManager : Object{ }); return msg; } + + public void logout (){ + current = null; + changed_current (); + } } diff --git a/src/Application.vala b/src/Application.vala index 7142090..6898c79 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -8,7 +8,6 @@ namespace Tootle{ public class Application : Granite.Application { - public abstract signal void state_updated(); public abstract signal void toast(string title); public abstract signal void error(string error); @@ -32,6 +31,11 @@ namespace Tootle{ protected override void activate () { window.present (); + var has_token = AccountManager.instance.has_access_token(); + if(has_token) + AccountManager.instance.update_current (); + else + AccountManager.instance.changed_current (null); } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 7781cce..3971342 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -22,8 +22,7 @@ public class Tootle.MainWindow: Gtk.Window { set_titlebar (header); window_position = WindowPosition.CENTER; - Tootle.app.state_updated.connect(on_state_update); - on_state_update (); + AccountManager.instance.changed_current.connect(on_account_changed); } construct { @@ -72,19 +71,16 @@ public class Tootle.MainWindow: Gtk.Window { NetManager.instance.finished.connect (() => spinner.hide ()); } - private void on_state_update(){ + private void on_account_changed(Account? account){ mode.hide (); button_toot.hide (); accounts.hide (); stack.forall (widget => stack.remove (widget)); - var has_token = AccountManager.instance.has_access_token(); - if(!has_token) + if(account == null) show_setup_views (); else show_main_views (); - - AccountManager.instance.update_current (); } private void show_setup_views (){ diff --git a/src/Views/HomeView.vala b/src/Views/HomeView.vala index 92c7481..e9add79 100644 --- a/src/Views/HomeView.vala +++ b/src/Views/HomeView.vala @@ -28,7 +28,8 @@ public class Tootle.HomeView : Tootle.AbstractView { this.pars = pars; show_all(); - request_update (); + + AccountManager.instance.changed_current.connect(on_account_changed); // var s = new Status(1); // s.content = "Test content, wow!"; @@ -49,7 +50,10 @@ public class Tootle.HomeView : Tootle.AbstractView { view.pack_end (widget, false, false, 0); } - public virtual Soup.Message request_update (){ + public virtual void on_account_changed (Account? account){ + if(account == null) + return; + var url = Settings.instance.instance_url; url += "api/v1/timelines/"; url += this.timeline; @@ -71,7 +75,6 @@ public class Tootle.HomeView : Tootle.AbstractView { warning (e.message); } }); - return msg; } } diff --git a/src/Widgets/AccountsButton.vala b/src/Widgets/AccountsButton.vala index 758578f..08334f9 100644 --- a/src/Widgets/AccountsButton.vala +++ b/src/Widgets/AccountsButton.vala @@ -17,7 +17,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{ item_separator.margin_top = 6; var item_settings = new Gtk.ModelButton (); - item_settings.text = _("Settings"); + item_settings.text = _("Settings"); grid = new Gtk.Grid (); grid.orientation = Gtk.Orientation.VERTICAL; @@ -35,7 +35,8 @@ public class Tootle.AccountsButton : Gtk.MenuButton{ show_all (); AccountManager.instance.changed_current.connect (account => { - CacheManager.instance.load_avatar (account.avatar, avatar, 24); + if (account != null) + CacheManager.instance.load_avatar (account.avatar, avatar, 24); }); }