Display current account in menu

This commit is contained in:
bleakgrey 2018-04-15 13:03:40 +03:00
parent f5e9b4f2dc
commit 9eb35ac55f
5 changed files with 66 additions and 6 deletions

View File

@ -10,6 +10,28 @@ public class Tootle.Status{
public string avatar;
public string acct;
enum Visibility {
PUBLIC,
UNLISTED,
PRIVATE,
DIRECT;
public string to_string() {
switch (this) {
case PUBLIC:
return "public";
case UNLISTED:
return "unlisted";
case PRIVATE:
return "private";
case DIRECT:
return "direct";
default:
assert_not_reached();
}
}
}
public Status(int64 id) {
this.id = id;
}

View File

@ -117,7 +117,7 @@ public class Tootle.AccountManager : Object{
public void logout (){
current = null;
changed_current ();
changed_current (null);
}
}

View File

@ -89,6 +89,7 @@ public class Tootle.MainWindow: Gtk.Window {
}
private void show_main_views (){
mode.clear_children ();
add_view (home);
add_view (feed_local);
add_view (feed_federated);

View File

@ -44,7 +44,7 @@ public class Tootle.HomeView : Tootle.AbstractView {
return "Home Timeline";
}
public void prepend(Status status){
public void prepend(Status status){ //TODO: clear all on account switch
var widget = new StatusWidget();
widget.rebind (status);
view.pack_end (widget, false, false, 0);

View File

@ -5,6 +5,38 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
Granite.Widgets.Avatar avatar;
Gtk.Grid grid;
Gtk.Popover menu;
AccountView default_account;
private class AccountView : Gtk.Grid{
public Gtk.Label name;
public Gtk.Label user;
public Gtk.Button logout;
construct {
margin = 6;
margin_start = 14;
name = new Gtk.Label ("<b>Anonymous</b>");
name.hexpand = true;
name.halign = Gtk.Align.START;
name.use_markup = true;
user = new Gtk.Label ("@error");
user.halign = Gtk.Align.START;
logout = new Gtk.Button.from_icon_name ("pane-hide-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
logout.receives_default = false;
logout.tooltip_text = _("Log out");
logout.clicked.connect (() => AccountManager.instance.logout ());
show_all ();
attach(name, 1, 0, 1, 1);
attach(user, 1, 1, 1, 1);
attach(logout, 2, 0, 2, 2);
}
public AccountView (){}
}
construct{
avatar = new Granite.Widgets.Avatar.with_default_icon (24);
@ -12,9 +44,10 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
return false;
});
default_account = new AccountView ();
var item_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
item_separator.hexpand = true;
item_separator.margin_top = 6;
var item_settings = new Gtk.ModelButton ();
item_settings.text = _("Settings");
@ -22,8 +55,9 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
grid = new Gtk.Grid ();
grid.orientation = Gtk.Orientation.VERTICAL;
grid.width_request = 200;
grid.attach(item_separator, 0, 1, 1, 1);
grid.attach(item_settings, 0, 2, 1, 1);
grid.attach(default_account, 0, 1, 1, 1);
grid.attach(item_separator, 0, 2, 1, 1);
grid.attach(item_settings, 0, 3, 1, 1);
grid.show_all ();
menu = new Gtk.Popover (null);
@ -35,8 +69,11 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
show_all ();
AccountManager.instance.changed_current.connect (account => {
if (account != null)
if (account != null){
CacheManager.instance.load_avatar (account.avatar, avatar, 24);
default_account.name.label = "<b>"+account.display_name+"</b>";
default_account.user.label = "@"+account.username;
}
});
}