2018-04-14 14:09:06 +02:00
|
|
|
using Gtk;
|
|
|
|
using Gdk;
|
|
|
|
|
|
|
|
public class Tootle.HomeView : Tootle.AbstractView {
|
|
|
|
|
|
|
|
private string timeline;
|
|
|
|
private string pars;
|
|
|
|
|
|
|
|
public HomeView (string timeline = "home", string pars = "") {
|
|
|
|
base (true);
|
|
|
|
this.timeline = timeline;
|
|
|
|
this.pars = pars;
|
2018-04-14 19:53:09 +02:00
|
|
|
|
2018-04-18 11:13:22 +02:00
|
|
|
view.remove.connect (on_remove);
|
2018-04-20 13:51:18 +02:00
|
|
|
AccountManager.instance.switched.connect(on_account_changed);
|
2018-04-14 14:09:06 +02:00
|
|
|
|
|
|
|
// var s = new Status(1);
|
|
|
|
// s.content = "Test content, wow!";
|
|
|
|
// prepend (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_icon () {
|
|
|
|
return "user-home-symbolic";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string get_name () {
|
|
|
|
return "Home Timeline";
|
|
|
|
}
|
|
|
|
|
2018-04-15 12:03:40 +02:00
|
|
|
public void prepend(Status status){ //TODO: clear all on account switch
|
2018-04-18 11:13:22 +02:00
|
|
|
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
|
|
|
separator.show ();
|
|
|
|
|
2018-04-16 20:22:42 +02:00
|
|
|
var widget = new StatusWidget(status);
|
2018-04-18 11:13:22 +02:00
|
|
|
widget.separator = separator;
|
2018-04-14 14:09:06 +02:00
|
|
|
widget.rebind (status);
|
2018-04-19 20:38:30 +02:00
|
|
|
widget.button_press_event.connect(() => {
|
2018-04-21 11:21:03 +02:00
|
|
|
var open_status = status.reblog != null ? status.reblog : status;
|
|
|
|
var view = new StatusView (open_status);
|
2018-04-19 21:03:28 +02:00
|
|
|
Tootle.window.open_secondary_view (view);
|
|
|
|
return false;
|
2018-04-19 20:38:30 +02:00
|
|
|
});
|
2018-04-18 11:13:22 +02:00
|
|
|
view.pack_start(separator, false, false, 0);
|
2018-04-16 22:36:57 +02:00
|
|
|
view.pack_start(widget, false, false, 0);
|
2018-04-14 14:09:06 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 11:13:22 +02:00
|
|
|
public virtual void on_remove (Widget widget){
|
|
|
|
if (!(widget is StatusWidget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
//debug ("removed");
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:53:09 +02:00
|
|
|
public virtual void on_account_changed (Account? account){
|
|
|
|
if(account == null)
|
|
|
|
return;
|
|
|
|
|
2018-04-14 14:09:06 +02:00
|
|
|
var url = Settings.instance.instance_url;
|
|
|
|
url += "api/v1/timelines/";
|
|
|
|
url += this.timeline;
|
|
|
|
url += this.pars;
|
|
|
|
|
|
|
|
var msg = new Soup.Message("GET", url);
|
|
|
|
NetManager.instance.queue(msg, (sess, mess) => {
|
|
|
|
try{
|
|
|
|
NetManager.parse_array (mess).foreach_element ((array, i, node) => {
|
|
|
|
var object = node.get_object ();
|
|
|
|
if (object != null){
|
|
|
|
var status = Status.parse(object);
|
|
|
|
prepend (status);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
catch (GLib.Error e) {
|
|
|
|
warning ("Can't update feed");
|
|
|
|
warning (e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|