2018-04-14 12:09:06 +00:00
|
|
|
using Gtk;
|
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/accounts_button.ui")]
|
|
|
|
public class Tootle.Widgets.AccountsButton : Gtk.MenuButton, IAccountListener {
|
|
|
|
|
|
|
|
[GtkTemplate (ui = "/com/github/bleakgrey/tootle/ui/widgets/accounts_button_item.ui")]
|
2020-07-06 16:40:17 +00:00
|
|
|
class Item : Grid {
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Widgets.Avatar avatar;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Label title;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Label handle;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Button profile;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Button forget;
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
public Item (InstanceAccount acc, AccountsButton _self) {
|
|
|
|
avatar.url = acc.avatar;
|
2020-05-30 16:48:20 +00:00
|
|
|
title.label = acc.display_name;
|
2020-05-29 12:19:35 +00:00
|
|
|
handle.label = acc.handle;
|
|
|
|
|
|
|
|
profile.clicked.connect (() => {
|
|
|
|
Views.Profile.open_from_id (acc.id);
|
|
|
|
_self.active = false;
|
|
|
|
});
|
|
|
|
|
2020-05-30 16:48:20 +00:00
|
|
|
forget.clicked.connect (() => {
|
2020-05-29 12:19:35 +00:00
|
|
|
_self.active = false;
|
|
|
|
accounts.remove (acc);
|
|
|
|
});
|
2018-04-15 10:03:40 +00:00
|
|
|
}
|
2019-03-09 11:42:27 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public Item.add_new () {
|
2020-05-30 16:48:20 +00:00
|
|
|
title.label = _("New Account");
|
2020-05-29 12:19:35 +00:00
|
|
|
handle.label = _("Click to add");
|
|
|
|
profile.destroy ();
|
2020-05-30 16:48:20 +00:00
|
|
|
forget.destroy ();
|
2018-05-27 16:25:16 +00:00
|
|
|
}
|
2018-04-15 10:03:40 +00:00
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
2020-07-06 16:40:17 +00:00
|
|
|
bool invalidated = true;
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Widgets.Avatar avatar;
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
ListBox account_list;
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
ModelButton item_accounts;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
ModelButton item_prefs;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
ModelButton item_refresh;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
ModelButton item_search;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Button item_favs;
|
2020-05-29 12:19:35 +00:00
|
|
|
[GtkChild]
|
2020-07-06 16:40:17 +00:00
|
|
|
Button item_conversations;
|
|
|
|
[GtkChild]
|
|
|
|
Button item_bookmarks;
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
construct {
|
2020-07-10 14:22:38 +00:00
|
|
|
account_listener_init ();
|
2019-03-09 11:42:27 +00:00
|
|
|
|
2020-07-06 16:40:17 +00:00
|
|
|
item_refresh.clicked.connect (() => {
|
|
|
|
app.refresh ();
|
|
|
|
});
|
2019-03-09 11:42:27 +00:00
|
|
|
Desktop.set_hotkey_tooltip (item_refresh, null, app.ACCEL_REFRESH);
|
|
|
|
|
2020-07-06 16:40:17 +00:00
|
|
|
item_favs.clicked.connect (() => {
|
|
|
|
window.open_view (new Views.Favorites ());
|
|
|
|
popover.popdown ();
|
|
|
|
});
|
|
|
|
item_conversations.clicked.connect (() => {
|
|
|
|
window.open_view (new Views.Conversations ());
|
|
|
|
popover.popdown ();
|
|
|
|
});
|
|
|
|
item_bookmarks.clicked.connect (() => {
|
|
|
|
window.open_view (new Views.Bookmarks ());
|
|
|
|
popover.popdown ();
|
|
|
|
});
|
|
|
|
item_search.clicked.connect (() => {
|
|
|
|
window.open_view (new Views.Search ());
|
|
|
|
popover.popdown ();
|
|
|
|
});
|
|
|
|
item_prefs.clicked.connect (() => {
|
|
|
|
Dialogs.Preferences.open ();
|
|
|
|
popover.popdown ();
|
|
|
|
});
|
2020-05-29 12:19:35 +00:00
|
|
|
|
|
|
|
on_account_changed (null);
|
2019-03-09 11:42:27 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
notify["active"].connect (() => {
|
|
|
|
if (active && invalidated)
|
|
|
|
rebuild ();
|
2018-05-27 16:25:16 +00:00
|
|
|
});
|
2019-03-09 11:42:27 +00:00
|
|
|
|
2020-07-06 16:40:17 +00:00
|
|
|
account_list.row_activated.connect (on_selection_changed);
|
2018-05-27 16:25:16 +00:00
|
|
|
}
|
2020-07-10 14:22:38 +00:00
|
|
|
~AccountsButton () {
|
|
|
|
account_listener_free ();
|
|
|
|
}
|
2019-03-09 11:42:27 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
protected void on_selection_changed (ListBoxRow r) {
|
|
|
|
var i = r.get_index ();
|
|
|
|
if (i >= accounts.saved.size) {
|
|
|
|
active = false;
|
|
|
|
window.open_view (new Views.NewAccount (true));
|
2020-07-06 16:40:17 +00:00
|
|
|
popover.popdown ();
|
2020-05-29 12:19:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var account = accounts.saved.@get (i);
|
|
|
|
if (accounts.active == account)
|
|
|
|
return;
|
|
|
|
|
|
|
|
accounts.switch_account (i);
|
2020-07-06 16:40:17 +00:00
|
|
|
popover.popdown ();
|
2018-04-14 12:09:06 +00:00
|
|
|
}
|
2019-03-09 11:42:27 +00:00
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public virtual void on_accounts_changed (Gee.ArrayList<InstanceAccount> accounts) {
|
|
|
|
invalidated = true;
|
|
|
|
if (active)
|
|
|
|
rebuild ();
|
2018-05-27 16:25:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 12:19:35 +00:00
|
|
|
public virtual void on_account_changed (InstanceAccount? account) {
|
|
|
|
if (account == null) {
|
|
|
|
avatar.url = null;
|
|
|
|
item_accounts.text = "<b>" + _("No active account") + "</b>";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
avatar.url = account.avatar;
|
|
|
|
item_accounts.text = @"<b>$(account.display_name)</b>\n$(account.handle) ";
|
|
|
|
}
|
|
|
|
item_accounts.use_markup = true;
|
2018-06-02 09:27:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 16:40:17 +00:00
|
|
|
void rebuild () {
|
2020-05-29 12:19:35 +00:00
|
|
|
account_list.@foreach (w => account_list.remove (w));
|
|
|
|
accounts.saved.@foreach (acc => {
|
|
|
|
var item = new Item (acc, this);
|
|
|
|
var row = new ListBoxRow ();
|
|
|
|
row.add (item);
|
|
|
|
row.show ();
|
|
|
|
|
|
|
|
account_list.insert (row, -1);
|
|
|
|
if (accounts.active == acc)
|
|
|
|
row.activate ();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
var new_row = new ListBoxRow ();
|
|
|
|
new_row.add (new Item.add_new ());
|
|
|
|
new_row.selectable = false;
|
|
|
|
new_row.show ();
|
|
|
|
account_list.insert (new_row, -1);
|
|
|
|
|
|
|
|
invalidated = false;
|
2018-05-31 12:13:21 +00:00
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
}
|