Remove redundant signal

This commit is contained in:
bleakgrey 2018-04-14 20:53:09 +03:00
parent 54605b898c
commit f5e9b4f2dc
5 changed files with 24 additions and 15 deletions

View file

@ -2,7 +2,7 @@ using GLib;
public class Tootle.AccountManager : Object{ 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 added(Account account);
public abstract signal void removed(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"); var access_token = root.get_string_member ("access_token");
settings.access_token = access_token; settings.access_token = access_token;
debug ("Got access token"); debug ("Got access token");
Tootle.app.state_updated (); update_current ();
} }
catch (GLib.Error e) { catch (GLib.Error e) {
warning ("Can't get access token"); warning ("Can't get access token");
@ -114,5 +114,10 @@ public class Tootle.AccountManager : Object{
}); });
return msg; return msg;
} }
public void logout (){
current = null;
changed_current ();
}
} }

View file

@ -8,7 +8,6 @@ namespace Tootle{
public class Application : Granite.Application { public class Application : Granite.Application {
public abstract signal void state_updated();
public abstract signal void toast(string title); public abstract signal void toast(string title);
public abstract signal void error(string error); public abstract signal void error(string error);
@ -32,6 +31,11 @@ namespace Tootle{
protected override void activate () { protected override void activate () {
window.present (); window.present ();
var has_token = AccountManager.instance.has_access_token();
if(has_token)
AccountManager.instance.update_current ();
else
AccountManager.instance.changed_current (null);
} }
} }

View file

@ -22,8 +22,7 @@ public class Tootle.MainWindow: Gtk.Window {
set_titlebar (header); set_titlebar (header);
window_position = WindowPosition.CENTER; window_position = WindowPosition.CENTER;
Tootle.app.state_updated.connect(on_state_update); AccountManager.instance.changed_current.connect(on_account_changed);
on_state_update ();
} }
construct { construct {
@ -72,19 +71,16 @@ public class Tootle.MainWindow: Gtk.Window {
NetManager.instance.finished.connect (() => spinner.hide ()); NetManager.instance.finished.connect (() => spinner.hide ());
} }
private void on_state_update(){ private void on_account_changed(Account? account){
mode.hide (); mode.hide ();
button_toot.hide (); button_toot.hide ();
accounts.hide (); accounts.hide ();
stack.forall (widget => stack.remove (widget)); stack.forall (widget => stack.remove (widget));
var has_token = AccountManager.instance.has_access_token(); if(account == null)
if(!has_token)
show_setup_views (); show_setup_views ();
else else
show_main_views (); show_main_views ();
AccountManager.instance.update_current ();
} }
private void show_setup_views (){ private void show_setup_views (){

View file

@ -28,7 +28,8 @@ public class Tootle.HomeView : Tootle.AbstractView {
this.pars = pars; this.pars = pars;
show_all(); show_all();
request_update ();
AccountManager.instance.changed_current.connect(on_account_changed);
// var s = new Status(1); // var s = new Status(1);
// s.content = "Test content, wow!"; // s.content = "Test content, wow!";
@ -49,7 +50,10 @@ public class Tootle.HomeView : Tootle.AbstractView {
view.pack_end (widget, false, false, 0); 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; var url = Settings.instance.instance_url;
url += "api/v1/timelines/"; url += "api/v1/timelines/";
url += this.timeline; url += this.timeline;
@ -71,7 +75,6 @@ public class Tootle.HomeView : Tootle.AbstractView {
warning (e.message); warning (e.message);
} }
}); });
return msg;
} }
} }

View file

@ -17,7 +17,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
item_separator.margin_top = 6; item_separator.margin_top = 6;
var item_settings = new Gtk.ModelButton (); var item_settings = new Gtk.ModelButton ();
item_settings.text = _("Settings"); item_settings.text = _("Settings");
grid = new Gtk.Grid (); grid = new Gtk.Grid ();
grid.orientation = Gtk.Orientation.VERTICAL; grid.orientation = Gtk.Orientation.VERTICAL;
@ -35,7 +35,8 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
show_all (); show_all ();
AccountManager.instance.changed_current.connect (account => { 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);
}); });
} }