d7d0a4f9fe2b5cd75d327b036add57b7361ba6d9
[feedhandler] / feedhandler.vala
1 /**
2  * Feed Handler
3  * Copyright © 2009 Thomas Perl <thp@thpinfo.com>
4  **/
5
6 using Gtk;
7 using GLib;
8
9 [DBus (name="org.maemo.garage.feedhandler")]
10 public class FeedHandler : GLib.Object {
11     private MainLoop loop;
12
13     public FeedHandler(MainLoop loop) {
14         this.loop = loop;
15     }
16
17     [DBus (name = "mime_open")]
18     public void mime_open(string url) {
19         Gtk.Dialog dlg = new Gtk.Dialog();
20         dlg.add_button("Subscribe", Gtk.ResponseType.YES);
21         dlg.add_button("Cancel", Gtk.ResponseType.CLOSE);
22         dlg.title = "feedhandler received a URL";
23         dlg.vbox.add(new Gtk.Label(url));
24         dlg.show_all();
25         dlg.run();
26         dlg.destroy();
27         message("URL received: %s", url);
28         loop.quit();
29     }
30 }
31
32 static int main(string [] args) {
33     MainLoop loop = new MainLoop(null, false);
34     Gtk.init(ref args);
35     try {
36         var conn = DBus.Bus.get(DBus.BusType.SESSION);
37         dynamic DBus.Object bus = conn.get_object("org.freedesktop.DBus",
38                                                   "/org/freedesktop/DBus",
39                                                   "org.freedesktop.DBus");
40         uint request_name_result = bus.RequestName(
41                                  "org.maemo.garage.feedhandler", (uint)0);
42         if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER) {
43             FeedHandler server = new FeedHandler(loop);
44             conn.register_object("/org/maemo/garge/feedhandler", server);
45             loop.run();
46         }
47
48     }
49     catch (Error e) {
50         stderr.printf("OOps: %s\n", e.message);
51     }
52     return 0;
53 }
54