From fba999c9b80e247aaafc08511143657ae3ed02e0 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Sat, 3 Oct 2009 17:43:14 +0200 Subject: [PATCH] Add support for Google Reader + RSS Reader --- debian/control | 2 +- feedhandler.vala | 111 +++++++++++++++++++++++++++++++++++++++++++++--------- makefile | 2 +- 3 files changed, 95 insertions(+), 20 deletions(-) diff --git a/debian/control b/debian/control index 662e386..a2cc064 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: feedhandler Section: user/network Priority: extra Maintainer: Thomas Perl -Build-Depends: debhelper, vala, libdbus-glib-1-dev, libgtk2.0-dev +Build-Depends: debhelper, vala, libdbus-glib-1-dev, libgtk2.0-dev, libosso-dev, libsoup2.4-dev Standards-Version: 3.8.1 Homepage: http://feedhandler.garage.maemo.org/ diff --git a/feedhandler.vala b/feedhandler.vala index f36c392..e2e37cc 100644 --- a/feedhandler.vala +++ b/feedhandler.vala @@ -5,57 +5,132 @@ using Gtk; using GLib; +using Osso; +using Soup; + +public enum Reader { + RSS = 1, + GOOGLE, + GPODDER, +} [DBus (name="org.maemo.garage.feedhandler")] public class FeedHandler : GLib.Object { private MainLoop loop; + private DBus.Connection conn; + private Context context; + private string args_url; - public FeedHandler(MainLoop loop) { + public FeedHandler(MainLoop loop, DBus.Connection conn) { this.loop = loop; + this.conn = conn; + this.context = new Osso.Context("feedhandler", "2.0", false, null); + this.args_url = null; } [DBus (name = "mime_open")] public void mime_open(string url) { + int result; + Gtk.Dialog dlg = new Gtk.Dialog(); - dlg.add_button("Subscribe", Gtk.ResponseType.YES); + dlg.add_button("RSS Reader", Reader.RSS); + dlg.add_button("Google Reader", Reader.GOOGLE); + dlg.add_button("gPodder", Reader.GPODDER); dlg.add_button("Cancel", Gtk.ResponseType.CLOSE); - dlg.title = "feedhandler received a URL"; + dlg.title = "Select application for handling this feed"; dlg.vbox.add(new Gtk.Label(url)); dlg.show_all(); - if (dlg.run() == Gtk.ResponseType.YES) { - /* Example code for launching a RSS application */ - try { - GLib.Process.spawn_async(null, - {"gpodder", - "--fremantle", - "-s", - url}, null, GLib.SpawnFlags.SEARCH_PATH, null, null); - } catch (GLib.SpawnError e) { - stderr.printf("Can't launch: %s\n", e.message); - } - } + result = dlg.run(); dlg.destroy(); + + switch (result) { + case Reader.RSS: + add_to_rss_reader(url); + break; + case Reader.GOOGLE: + add_to_google(url); + break; + case Reader.GPODDER: + try { + GLib.Process.spawn_async(null, + {"gpodder", + "--fremantle", + "-s", + url}, null, GLib.SpawnFlags.SEARCH_PATH, null, null); + } catch (GLib.SpawnError e) { + stderr.printf("Can't launch: %s\n", e.message); + } + break; + } + message("URL received: %s", url); loop.quit(); } + + private void add_to_google(string url) + { + open_browser("http://fusion.google.com/add?feedurl=" + + URI.encode(url, null)); + } + + private void add_to_rss_reader(string url) + { + dynamic DBus.Object obj = conn.get_object( + "com.nokia.osso_rss_feed_reader_refresh", + "/com/nokia/osso_rss_feed_reader_refresh", + "com.nokia.osso_rss_feed_reader_refresh"); + obj.mime_open(url); + } + + private void open_browser(string url) + { + context.rpc_run_with_defaults("osso_browser", + "open_new_window", + null, + (int)'s', url, + (int)'\0'); + /* DBUS_TYPE_STRING is (int)'s' */ + /* DBUS_TYPE_INVALID is (int)'\0' */ + } + + public void set_args_url(string url) + { + args_url = url; + } + + public bool open_url_later() + { + mime_open(args_url); + return false; + } } static int main(string [] args) { MainLoop loop = new MainLoop(null, false); Gtk.init(ref args); + if (args.length != 1 && args.length != 2) { + stderr.printf("Usage: %s [URL]\n", args[0]); + return 1; + } try { - var conn = DBus.Bus.get(DBus.BusType.SESSION); + DBus.Connection 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); + FeedHandler server = new FeedHandler(loop, conn); conn.register_object("/org/maemo/garage/feedhandler", server); + if (args.length == 2) { + /* Add URL when the main loop is running */ + server.set_args_url(args[1]); + Idle.add(server.open_url_later); + } loop.run(); + } else { + stderr.printf("feedhandler is already running.\n"); } - } catch (Error e) { stderr.printf("OOps: %s\n", e.message); diff --git a/makefile b/makefile index c7cc4cd..bbe6180 100644 --- a/makefile +++ b/makefile @@ -3,7 +3,7 @@ APP=feedhandler OBJS=feedhandler.o -PACKAGES=glib-2.0 dbus-glib-1 gtk+-2.0 +PACKAGES=glib-2.0 dbus-glib-1 gtk+-2.0 libosso libsoup-2.4 DESTDIR ?= / PREFIX ?= /usr -- 1.7.9.5