In attachment is source

I have problem that, after calling fetch() feed list is not updated and I don't know why, printf() reports there are new entries, but they are not displayed
class Feed : Gtk.EventBox {
    
	public string _id;
    public string _title;
	public string _link;
    public string _source;
    public string _icon;
    public Gee.ArrayList<Item> _items;
    public Client _client;

    private Gtk.Alignment align;
    private Gtk.Alignment left_align;
    private Gtk.Alignment right_align;    
    private Gtk.VBox left_vbox;
    private Gtk.VBox right_vbox;
    private Gtk.Alignment items_align;
    private Gtk.VBox items_vbox;
    private Gtk.HBox main_hbox;
    private Gtk.Label title_label;    
    private Gtk.Alignment icon_align;    
    private Gtk.EventBox icon_eventbox;
    private Gtk.Image icon_image;
    private Gtk.Alignment remove_align;    
    private Gtk.EventBox remove_eventbox;
    private Gtk.Image remove_image;

    construct {

        /* main object with padding */
        align = new Gtk.Alignment(0.0f, 0.0f, 0.0f, 0.0f);
        add(align);

        main_hbox = new Gtk.HBox(false, 5);
        align.add(main_hbox);

        
        /* left part with icon and remove button */
        left_align = new Gtk.Alignment(0.0f, 0.0f, 0.0f, 1.0f);
        main_hbox.pack_start(left_align);

        left_vbox = new Gtk.VBox(false, 0);
        left_align.add(left_vbox);
        
        /* icon  */
        icon_align = new Gtk.Alignment (0.0f, 0.0f, 0.0f, 0.0f);

        icon_eventbox = new Gtk.EventBox();
        icon_align.add(icon_eventbox);

        icon_image = new Gtk.Image();
        icon_eventbox.add(icon_image);

        left_vbox.pack_start(icon_align);


        /* remove button */
        remove_align = new Gtk.Alignment(0.0f, 1.0f, 0.0f, 0.0f);

        remove_eventbox = new Gtk.EventBox();
        remove_align.add(remove_eventbox);

        remove_image = new Gtk.Image.from_icon_name("list-remove-symbolic", Gtk.IconSize.BUTTON);
        remove_eventbox.add(remove_image);

        left_vbox.pack_end(remove_align);


        /* right part with title of feed and items */        
        right_align = new Gtk.Alignment(0.0f, 0.0f, 0.0f, 0.0f);
        main_hbox.pack_end(right_align);
    
        right_vbox = new Gtk.VBox(false, 0);  
        right_align.add(right_vbox);
        
        title_label = new Gtk.Label("");  
        title_label.set_alignment(0.0f, 0.0f);
        right_vbox.pack_start(title_label);

        items_align = new Gtk.Alignment(0.0f, 0.0f, 0.0f, 0.0f);
        items_vbox = new Gtk.VBox(false, 0);
        items_align.add(items_vbox);
        right_vbox.pack_end(items_align);   
    }

    public void fetch() {
        _id = _client.add_feed(_source);
        render();
    }

    public void render() {

        /* after construction of GTK, create */
        load();
        load_items();

        remove_eventbox.button_press_event.connect(() => {
            _client.remove_feed(_id);
            destroy();
            return true;
        });

        title_label.set_markup("<b>" + _title + "</b>");
        icon_image.set_from_file(_icon);

        var items_buf = new Gtk.VBox(false, 0);

        foreach (Item cur_item in _items) {
           

            
            stderr.printf("%s %s\n", cur_item._title, cur_item._date);
            //if (cur_item._read == "0") {
                cur_item.render();
                items_vbox.pack_start(cur_item);
            //}
        }
        items_vbox = items_buf;
        show_all();
    }

    public void load() {
        stderr.printf("JSON: %s\n", _client.get_feed_details(_id));

        var parser = new Json.Parser();
        parser.load_from_data(_client.get_feed_details(_id));
   
        var cur_object = parser.get_root().get_object().get_object_member("0");
        
        _title = cur_object.get_string_member("title");
        _link = cur_object.get_string_member("link");
        _source = cur_object.get_string_member("source");
        _icon = "../favicon.ico";
    }

    private void load_items() {

        /* init array */
        _items = new Gee.ArrayList<Item>();        

        /* load all items for better performance */        
        stderr.printf("JSON: %s\n", _client.get_items(_id));

        var parser = new Json.Parser();
        parser.load_from_data(_client.get_items(_id));

        var root_object_items = parser.get_root().get_object();

        for (int item_index = 0; root_object_items.has_member(item_index.to_string()); item_index++) {
            
            var cur_object_item = root_object_items.get_object_member(item_index.to_string());
            var cur_item = new Item();

            cur_item._id = cur_object_item.get_string_member("id");
            cur_item._title = cur_object_item.get_string_member("title");
            cur_item._link = cur_object_item.get_string_member("link");
            cur_item._date = cur_object_item.get_string_member("date");
            cur_item._read = cur_object_item.get_string_member("read");

            cur_item._client = _client;
           _items.add(cur_item);
        }

        /* sort items by date (new first, old at end) */
        _items.sort_with_data((CompareDataFunc) sort_func_items);
    }

}
_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to