2
public class News : Service
12
ShadowedLabel label_list;
19
reload = get_reload_label(_("news"));
21
label_list = new ShadowedLabel("");
23
label_list.reactive = true;
24
label_list.button_release_event.connect ((e) => {
26
label_list.get_transformed_position (out root_x, out root_y);
27
var url = news[int.min ((int)((e.y - root_y) / ((label_list.height - 20) / 10.0f)), 9)].url;
28
var uris = new List<string> ();
31
AppInfo.get_default_for_uri_scheme ("http").launch_uris (uris, null);
32
} catch (Error e) { warning (e.message); }
36
settings = new Settings ("org.pantheon.gazette.news");
37
settings.changed.connect( (key) => { if (key != "update-interval") update(); });
38
session = new Soup.SessionAsync ();
40
Timeout.add(settings.get_int("update-interval"), update);
41
var label = new ShadowedLabel ("<span font='20' face='Raleway'>%s</span>".printf (_("News")));
42
label_list.y = label.height + 12;
44
reload.y = label_list.y;
45
reload.x = label_list.x;
48
add_child (label_list);
51
public override void create ()
55
public override bool update ()
56
{ debug("Updating News");
58
label_list.reactive = false;
60
label_list.label = "<span face='Open Sans Light' font='16'>" + _("Loading news,\nplease wait.") + "</span>";
61
var soup_url = settings.get_string ("rss-url");
62
message = new Soup.Message ("GET", soup_url);
63
session.queue_message (message, (session, m) =>
65
var output = (string)m.response_body.data;
71
var offset = output.index_of ("<item>");
73
for (var i = 0; i < 10; i++) {
74
offset = output.index_of ("<title>", offset) + 7;
75
var title = output.substring (offset, output.index_of ("</title>", offset) - offset);
76
offset = output.index_of ("<link>", offset) + 6;
77
var url = output.substring (offset, output.index_of ("</link>", offset) - offset);
78
news[i] = {ellipsize(title, 40), url};
80
var list = "<span font='12' face='Open Sans'>";
81
for (var i = 0; i < news.length; i++) {
82
list += news[i].title + "\n";
84
label_list.label = list + "</span>";
85
label_list.reactive = true;