initial commit (remove welcome, add code)
[feedhandler] / feedhandler.vala
diff --git a/feedhandler.vala b/feedhandler.vala
new file mode 100644 (file)
index 0000000..d7d0a4f
--- /dev/null
@@ -0,0 +1,54 @@
+/**
+ * Feed Handler
+ * Copyright © 2009 Thomas Perl <thp@thpinfo.com>
+ **/
+
+using Gtk;
+using GLib;
+
+[DBus (name="org.maemo.garage.feedhandler")]
+public class FeedHandler : GLib.Object {
+    private MainLoop loop;
+
+    public FeedHandler(MainLoop loop) {
+        this.loop = loop;
+    }
+
+    [DBus (name = "mime_open")]
+    public void mime_open(string url) {
+        Gtk.Dialog dlg = new Gtk.Dialog();
+        dlg.add_button("Subscribe", Gtk.ResponseType.YES);
+        dlg.add_button("Cancel", Gtk.ResponseType.CLOSE);
+        dlg.title = "feedhandler received a URL";
+        dlg.vbox.add(new Gtk.Label(url));
+        dlg.show_all();
+        dlg.run();
+        dlg.destroy();
+        message("URL received: %s", url);
+        loop.quit();
+    }
+}
+
+static int main(string [] args) {
+    MainLoop loop = new MainLoop(null, false);
+    Gtk.init(ref args);
+    try {
+        var conn = DBus.Bus.get(DBus.BusType.SESSION);
+        dynamic DBus.Object bus = conn.get_object("org.freedesktop.DBus",
+                                                  "/org/freedesktop/DBus",
+                                                  "org.freedesktop.DBus");
+        uint request_name_result = bus.RequestName(
+                                 "org.maemo.garage.feedhandler", (uint)0);
+        if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER) {
+            FeedHandler server = new FeedHandler(loop);
+            conn.register_object("/org/maemo/garge/feedhandler", server);
+            loop.run();
+        }
+
+    }
+    catch (Error e) {
+        stderr.printf("OOps: %s\n", e.message);
+    }
+    return 0;
+}
+