2018-04-14 12:09:06 +00:00
|
|
|
using Gtk;
|
|
|
|
using Granite;
|
|
|
|
|
|
|
|
public class Tootle.StatusWidget : Gtk.Grid {
|
|
|
|
|
2018-04-16 18:22:42 +00:00
|
|
|
public Status status;
|
|
|
|
|
2018-04-18 09:13:22 +00:00
|
|
|
public Gtk.Separator? separator;
|
2018-04-14 12:09:06 +00:00
|
|
|
public Granite.Widgets.Avatar avatar;
|
|
|
|
Gtk.Label user;
|
|
|
|
Gtk.Label content;
|
|
|
|
|
|
|
|
Gtk.Box counters;
|
|
|
|
Gtk.Label reblogs;
|
|
|
|
Gtk.Label favorites;
|
2018-04-16 18:22:42 +00:00
|
|
|
|
|
|
|
Gtk.ToggleButton reblog;
|
|
|
|
Gtk.ToggleButton favorite;
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
construct {
|
|
|
|
margin = 6;
|
2018-04-14 17:18:42 +00:00
|
|
|
|
2018-04-14 12:09:06 +00:00
|
|
|
avatar = new Granite.Widgets.Avatar.with_default_icon (32);
|
|
|
|
avatar.valign = Gtk.Align.START;
|
|
|
|
avatar.margin_end = 6;
|
|
|
|
user = new Gtk.Label ("Anonymous");
|
|
|
|
user.hexpand = true;
|
|
|
|
user.halign = Gtk.Align.START;
|
|
|
|
user.use_markup = true;
|
|
|
|
content = new Gtk.Label ("Error parsing text :c");
|
|
|
|
content.halign = Gtk.Align.START;
|
|
|
|
content.use_markup = true;
|
|
|
|
content.single_line_mode = false;
|
|
|
|
content.set_line_wrap (true);
|
|
|
|
//content.selectable = true; //TODO: toot page
|
|
|
|
content.justify = Gtk.Justification.LEFT;
|
|
|
|
content.margin_end = 6;
|
|
|
|
content.xalign = 0;
|
|
|
|
|
|
|
|
reblogs = new Gtk.Label ("0");
|
|
|
|
favorites = new Gtk.Label ("0");
|
2018-04-16 18:22:42 +00:00
|
|
|
|
|
|
|
reblog = get_action_button ();
|
|
|
|
reblog.toggled.connect (() => {
|
|
|
|
if (reblog.sensitive)
|
|
|
|
toggle_reblog ();
|
|
|
|
});
|
|
|
|
favorite = get_action_button (false);
|
|
|
|
favorite.toggled.connect (() => {
|
|
|
|
if (favorite.sensitive)
|
|
|
|
toggle_fav ();
|
|
|
|
});
|
|
|
|
|
2018-04-14 17:18:42 +00:00
|
|
|
counters = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); //TODO: currently useless
|
2018-04-14 12:09:06 +00:00
|
|
|
counters.margin_top = 6;
|
|
|
|
counters.margin_bottom = 12;
|
2018-04-16 18:22:42 +00:00
|
|
|
counters.add(reblog);
|
2018-04-14 12:09:06 +00:00
|
|
|
counters.add(reblogs);
|
2018-04-16 18:22:42 +00:00
|
|
|
counters.add(favorite);
|
2018-04-14 12:09:06 +00:00
|
|
|
counters.add(favorites);
|
|
|
|
counters.show_all ();
|
|
|
|
|
2018-04-18 09:13:22 +00:00
|
|
|
attach(avatar, 1, 0, 1, 3);
|
|
|
|
attach(user, 2, 1, 1, 1);
|
|
|
|
attach(content, 2, 2, 1, 1);
|
|
|
|
attach(counters, 2, 3, 1, 1);
|
2018-04-14 17:18:42 +00:00
|
|
|
show_all(); //TODO: display conversations
|
2018-04-14 12:09:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 18:22:42 +00:00
|
|
|
public StatusWidget (Status status) {
|
|
|
|
this.status = status;
|
2018-04-14 12:09:06 +00:00
|
|
|
get_style_context ().add_class ("status");
|
2018-04-18 09:13:22 +00:00
|
|
|
|
|
|
|
destroy.connect (() => {
|
|
|
|
if(separator != null)
|
|
|
|
separator.destroy ();
|
|
|
|
});
|
2018-04-14 12:09:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 18:22:42 +00:00
|
|
|
public void rebind (Status status = this.status){
|
2018-04-14 12:09:06 +00:00
|
|
|
user.label = "<b>"+status.acct+"</b>";
|
|
|
|
content.label = status.content;
|
|
|
|
|
|
|
|
reblogs.label = status.reblogs_count.to_string ();
|
|
|
|
favorites.label = status.favourites_count.to_string ();
|
|
|
|
|
2018-04-16 18:22:42 +00:00
|
|
|
reblog.active = status.reblogged;
|
|
|
|
reblog.sensitive = true;
|
|
|
|
favorite.active = status.favorited;
|
|
|
|
favorite.sensitive = true;
|
|
|
|
|
2018-04-14 17:18:42 +00:00
|
|
|
CacheManager.instance.load_avatar (status.avatar, this.avatar);
|
2018-04-14 12:09:06 +00:00
|
|
|
}
|
2018-04-16 18:22:42 +00:00
|
|
|
|
|
|
|
private Gtk.ToggleButton get_action_button (bool reblog = true){
|
|
|
|
var path = "edit-undo-symbolic";
|
|
|
|
if (!reblog)
|
|
|
|
path = "help-about-symbolic";
|
|
|
|
var icon = new Gtk.Image.from_icon_name (path, Gtk.IconSize.SMALL_TOOLBAR);
|
|
|
|
|
|
|
|
var button = new Gtk.ToggleButton ();
|
|
|
|
|
|
|
|
button.add (icon);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void toggle_reblog(){
|
|
|
|
var state = reblog.get_active ();
|
|
|
|
var action = "reblog";
|
|
|
|
if (!state)
|
|
|
|
action = "unreblog";
|
|
|
|
|
|
|
|
var msg = new Soup.Message("POST", Settings.instance.instance_url + "/api/v1/statuses/" + status.id.to_string () + "/" + action);
|
|
|
|
msg.finished.connect(() => {
|
|
|
|
status.reblogged = state;
|
|
|
|
reblog.sensitive = false;
|
|
|
|
favorite.sensitive = false;
|
|
|
|
if(state)
|
|
|
|
status.reblogs_count += 1;
|
|
|
|
else
|
|
|
|
status.reblogs_count -= 1;
|
|
|
|
rebind ();
|
|
|
|
});
|
|
|
|
NetManager.instance.queue(msg, (sess, mess) => {
|
|
|
|
//NetManager.parse (msg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void toggle_fav(){
|
|
|
|
var state = favorite.get_active ();
|
|
|
|
var action = "favourite";
|
|
|
|
if (!state)
|
|
|
|
action = "unfavourite";
|
|
|
|
|
|
|
|
var msg = new Soup.Message("POST", Settings.instance.instance_url + "/api/v1/statuses/" + status.id.to_string () + "/" + action);
|
|
|
|
msg.finished.connect(() => {
|
|
|
|
status.favorited = state;
|
|
|
|
reblog.sensitive = false;
|
|
|
|
favorite.sensitive = false;
|
|
|
|
if(state)
|
|
|
|
status.favourites_count += 1;
|
|
|
|
else
|
|
|
|
status.favourites_count -= 1;
|
|
|
|
rebind ();
|
|
|
|
});
|
|
|
|
NetManager.instance.queue(msg, (sess, mess) => {
|
|
|
|
//NetManager.parse (msg);
|
|
|
|
});
|
|
|
|
}
|
2018-04-14 12:09:06 +00:00
|
|
|
|
|
|
|
}
|