2018-04-14 12:09:06 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
public class Tootle.AccountsButton : Gtk.MenuButton{
|
|
|
|
|
|
|
|
Granite.Widgets.Avatar avatar;
|
|
|
|
Gtk.Grid grid;
|
|
|
|
Gtk.Popover menu;
|
2018-04-15 10:03:40 +00:00
|
|
|
AccountView default_account;
|
2018-05-02 12:28:46 +00:00
|
|
|
Gtk.ModelButton item_settings;
|
2018-05-03 08:11:31 +00:00
|
|
|
Gtk.ModelButton item_refresh;
|
2018-05-14 14:43:10 +00:00
|
|
|
Gtk.ModelButton item_search;
|
2018-05-02 12:28:46 +00:00
|
|
|
Gtk.ModelButton item_favs;
|
2018-04-15 10:03:40 +00:00
|
|
|
|
|
|
|
private class AccountView : Gtk.Grid{
|
|
|
|
|
2018-04-15 11:29:55 +00:00
|
|
|
public Gtk.Label display_name;
|
2018-04-15 10:03:40 +00:00
|
|
|
public Gtk.Label user;
|
|
|
|
public Gtk.Button logout;
|
|
|
|
|
|
|
|
construct {
|
|
|
|
margin = 6;
|
|
|
|
margin_start = 14;
|
|
|
|
|
2018-04-15 11:29:55 +00:00
|
|
|
display_name = new Gtk.Label ("<b>Anonymous</b>");
|
|
|
|
display_name.hexpand = true;
|
|
|
|
display_name.halign = Gtk.Align.START;
|
|
|
|
display_name.use_markup = true;
|
2018-04-15 10:03:40 +00:00
|
|
|
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");
|
2018-04-27 18:50:08 +00:00
|
|
|
logout.clicked.connect (() => Tootle.accounts.logout ());
|
2018-04-15 10:03:40 +00:00
|
|
|
show_all ();
|
|
|
|
|
2018-04-15 11:29:55 +00:00
|
|
|
attach(display_name, 1, 0, 1, 1);
|
2018-04-15 10:03:40 +00:00
|
|
|
attach(user, 1, 1, 1, 1);
|
|
|
|
attach(logout, 2, 0, 2, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public AccountView (){}
|
|
|
|
|
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
construct{
|
|
|
|
avatar = new Granite.Widgets.Avatar.with_default_icon (24);
|
|
|
|
avatar.button_press_event.connect(event => {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2018-04-15 10:03:40 +00:00
|
|
|
default_account = new AccountView ();
|
|
|
|
|
2018-04-14 12:09:06 +00:00
|
|
|
var item_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
|
|
|
item_separator.hexpand = true;
|
|
|
|
|
2018-05-03 08:11:31 +00:00
|
|
|
item_refresh = new Gtk.ModelButton ();
|
|
|
|
item_refresh.text = _("Refresh");
|
2018-05-05 15:38:01 +00:00
|
|
|
item_refresh.clicked.connect (() => Tootle.app.refresh ());
|
2018-05-03 08:11:31 +00:00
|
|
|
|
2018-05-02 12:28:46 +00:00
|
|
|
item_favs = new Gtk.ModelButton ();
|
|
|
|
item_favs.text = _("Favorites");
|
2018-05-05 15:38:01 +00:00
|
|
|
item_favs.clicked.connect (() => Tootle.window.open_view (new FavoritesView ()));
|
2018-05-02 12:28:46 +00:00
|
|
|
|
2018-05-14 14:43:10 +00:00
|
|
|
item_search = new Gtk.ModelButton ();
|
|
|
|
item_search.text = _("Search");
|
|
|
|
item_search.clicked.connect (() => Tootle.window.open_view (new SearchView ()));
|
|
|
|
|
2018-05-02 12:28:46 +00:00
|
|
|
item_settings = new Gtk.ModelButton ();
|
2018-04-14 17:53:09 +00:00
|
|
|
item_settings.text = _("Settings");
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
grid = new Gtk.Grid ();
|
|
|
|
grid.orientation = Gtk.Orientation.VERTICAL;
|
|
|
|
grid.width_request = 200;
|
2018-04-15 10:03:40 +00:00
|
|
|
grid.attach(default_account, 0, 1, 1, 1);
|
2018-05-02 12:28:46 +00:00
|
|
|
grid.attach(item_separator, 0, 2, 1, 1);
|
2018-05-14 14:43:10 +00:00
|
|
|
grid.attach(item_favs, 0, 3, 1, 1);
|
|
|
|
grid.attach(new Gtk.Separator (Gtk.Orientation.HORIZONTAL), 0, 4, 1, 1);
|
|
|
|
grid.attach(item_refresh, 0, 5, 1, 1);
|
|
|
|
grid.attach(item_search, 0, 6, 1, 1);
|
|
|
|
//grid.attach(item_settings, 0, 8, 1, 1);
|
2018-04-14 12:09:06 +00:00
|
|
|
grid.show_all ();
|
|
|
|
|
|
|
|
menu = new Gtk.Popover (null);
|
|
|
|
menu.add (grid);
|
|
|
|
|
|
|
|
get_style_context ().add_class ("button_avatar");
|
|
|
|
popover = menu;
|
|
|
|
add(avatar);
|
|
|
|
show_all ();
|
2018-04-14 17:18:42 +00:00
|
|
|
|
2018-04-27 18:50:08 +00:00
|
|
|
Tootle.accounts.switched.connect (account => {
|
2018-04-15 10:03:40 +00:00
|
|
|
if (account != null){
|
2018-05-08 16:09:38 +00:00
|
|
|
Tootle.network.load_avatar (account.avatar, avatar, 24);
|
2018-04-15 11:29:55 +00:00
|
|
|
default_account.display_name.label = "<b>"+account.display_name+"</b>";
|
2018-04-15 10:03:40 +00:00
|
|
|
default_account.user.label = "@"+account.username;
|
|
|
|
}
|
2018-04-14 17:18:42 +00:00
|
|
|
});
|
2018-04-14 12:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public AccountsButton(){
|
|
|
|
Object();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|