Imported Upstream version 0.3~20101226
[debian/pino.git] / src / feed_view.vala
1 using Gtk;
2
3 /** Here we view all our statuses from one feed */
4 public class FeedView : ScrolledWindow {
5         
6         private VBox vbox;
7         private FeedModel model;
8         private VScrollbar scroll;
9         
10         public FeedView() {
11                 set_policy(PolicyType.AUTOMATIC, PolicyType.ALWAYS);
12                 
13                 vbox = new VBox(false, 2);
14                 add_with_viewport(vbox);
15                 
16                 scroll = (VScrollbar) get_vscrollbar();
17                 scroll.value_changed.connect(() => {
18                         //debug(scroll.get_value().to_string());
19                         
20                         double max = scroll.adjustment.upper;
21                         double current = scroll.get_value();
22                         double scroll_size = scroll.adjustment.page_size;
23                         
24                         if(current != 0 && current + scroll_size == max) {
25                                 debug("max");
26                                 if(model.stream != null) {
27                                         model.stream.menu_more();
28                                 }
29                         }
30                 });
31         }
32         
33         public void set_model(FeedModel model) {
34                 this.model = model;
35                 
36                 foreach(Status status in model) {
37                         add_item(status);
38                 }
39                 
40                 this.model.status_added.connect((status) => { add_item(status); });
41                 this.model.status_inserted.connect(insert_item);
42                 this.model.status_removed.connect(remove_item);
43         }
44         
45         private StatusDelegate new_delegate(Status status) {
46                 StatusDelegate widget = new StatusDelegate(status);
47                 widget.show_all();
48                 debug("ok");
49                 return widget;
50         }
51         
52         public StatusDelegate add_item(Status status) {
53                 StatusDelegate widget = new_delegate(status);
54                 vbox.pack_start(widget, false, false, 0);
55                 
56                 return widget;
57         }
58         
59         public void insert_item(int index, Status status) {
60                 StatusDelegate widget = add_item(status);
61                 vbox.reorder_child(widget, index);
62         }
63         
64         public void remove_item(int index) {
65                 Widget widget = vbox.get_children().nth_data(index);
66                 vbox.remove(widget);
67         }
68 }