[evolution-rss] implement org.gnome.feed.Reader this basically mean support feeds comming from epiphany. Also drop o



commit 40e6ecf6e353b5cece930198aecb688e6c401cca
Author: Lucian Langa <lucilanga gnome org>
Date:   Sat May 28 13:51:34 2011 +0300

    implement org.gnome.feed.Reader
    this basically mean support feeds comming from epiphany.
    Also drop old dbus interface as it is obsolete now.

 src/dbus.c                 |  230 ++++++++++++++++++++++++++-----------------
 src/evolution-import-rss.c |  237 ++++++++++---------------------------------
 2 files changed, 195 insertions(+), 272 deletions(-)
---
diff --git a/src/dbus.c b/src/dbus.c
index 9b67a68..4104342 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*  Evoution RSS Reader Plugin
- *  Copyright (C) 2007-2009  Lucian Langa <cooly gnome eu org>
+ *  Copyright (C) 2007-2011  Lucian Langa <cooly gnome eu org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -36,13 +36,46 @@ extern int rss_verbose_debug;
 #include "notification.h"
 #include "dbus.h"
 
-#define DBUS_PATH "/org/gnome/evolution/mail/rss"
-#define RSS_DBUS_SERVICE "org.gnome.evolution.mail.rss"
-//#define DBUS_INTERFACE "org.gnome.evolution.mail.rss.in"
-#define DBUS_INTERFACE "org.gnome.evolution.mail.rss"
-#define DBUS_REPLY_INTERFACE "org.gnome.evolution.mail.rss.out"
+#define RSS_DBUS_PATH "/org/gnome/feed/Reader"
+#define RSS_DBUS_SERVICE "org.gnome.feed.Reader"
+#define RSS_DBUS_INTERFACE "org.gnome.feed.Reader"
+
+gboolean subscribe_method(gchar *url);
+
+static void
+method_call_cb (GDBusConnection       *connection,
+		const gchar           *sender,
+		const gchar           *object_path,
+		const gchar           *interface_name,
+		const gchar           *method_name,
+		GVariant              *parameters,
+		GDBusMethodInvocation *invocation,
+		gpointer               user_data);
 
 static GDBusConnection *connection = NULL;
+
+static GDBusNodeInfo *nodeinfo = NULL;
+
+static const gchar introspection_xml[] =
+	"<node name='/org/gnome/feed/Reader'>"
+		"<interface name='org.gnome.feed.Reader'>"
+			"<method name='Ping'>"
+				"<arg name='result' type='b' direction='out'/>"
+			"</method>"
+			"<method name='Subscribe'>"
+				"<arg name='url' type='s'/>"
+				"<arg name='result' type='b' direction='out'/>"
+			"</method>"
+		"</interface>"
+	"</node>";
+
+static const GDBusInterfaceVTable vtable =
+{
+	method_call_cb,
+	NULL,
+	NULL
+};
+
 static gboolean enabled = FALSE;
 
 extern rssfeed *rf;
@@ -58,6 +91,45 @@ reinit_dbus (gpointer user_data)
 	return TRUE;
 }
 
+gboolean
+subscribe_method(gchar *url)
+{
+	add_feed *feed = g_new0(add_feed, 1);
+	feed->feed_url = url;
+	feed->add=1;
+	feed->enabled=feed->validate=1;
+	feed->fetch_html = 0;
+	if (feed->feed_url && strlen(feed->feed_url)) {
+		g_print("New Feed received: %s\n", url);
+		feed->feed_url = sanitize_url(feed->feed_url);
+		d("sanitized feed URL: %s\n", feed->feed_url);
+		if (g_hash_table_find(rf->hr, check_if_match, feed->feed_url)) {
+			rss_error(NULL, NULL, _("Error adding feed."),
+				_("Feed already exists!"));
+				//return FALSE;
+				/* we return true here since org.gnome.feed.Reader
+				 * doesn't support status */
+				return TRUE;
+		}
+		if (setup_feed(feed)) {
+			gchar *msg = g_strdup_printf(_("Importing URL: %s"),
+					feed->feed_url);
+			taskbar_push_message(msg);
+			g_free(msg);
+		}
+		if (rf->treeview)
+			store_redraw(GTK_TREE_VIEW(rf->treeview));
+		save_gconf_feed();
+#if (DATASERVER_VERSION >= 2033001)
+		camel_operation_pop_message (NULL);
+#else
+	camel_operation_end(NULL);
+#endif
+	}
+	g_free(url);
+	return TRUE;
+}
+
 static void
 connection_closed_cb (GDBusConnection *pconnection,
 	gboolean remote_peer_vanished, GError *error,
@@ -71,80 +143,68 @@ connection_closed_cb (GDBusConnection *pconnection,
 }
 
 static void
-signal_cb (GDBusConnection *connection,
-		const gchar *sender_name,
-		const gchar *object_path,
-		const gchar *interface_name,
-		const gchar *signal_name,
-		GVariant *parameters,
-		gpointer user_data)
+method_call_cb (GDBusConnection       *connection,
+		const gchar           *sender,
+		const gchar           *object_path,
+		const gchar           *interface_name,
+		const gchar           *method_name,
+		GVariant              *parameters,
+		GDBusMethodInvocation *invocation,
+		gpointer               user_data)
 {
-	if (g_strcmp0 (interface_name, DBUS_INTERFACE) != 0
-	|| g_strcmp0 (object_path, DBUS_PATH) != 0)
-		return;
-
-	d("interface:%s!\n", interface_name);
-	d("path:%s!\n", object_path);
-	d("signal_name:%s!\n", signal_name);
-
-
-	if (!g_strcmp0 (signal_name, "import")) {
-		gchar *url = NULL;
-		add_feed *feed = g_new0(add_feed, 1);
+	gchar *url;
+	gboolean res = FALSE;
+	d("method:%s\n", method_name);
+	if (!g_strcmp0 (method_name, "Subscribe")) {
 		g_variant_get (parameters, "(s)", &url);
-		feed->feed_url = url;
-		feed->add=1;
-		feed->enabled=feed->validate=1;
-		feed->fetch_html = 0;
-		if (feed->feed_url && strlen(feed->feed_url)) {
-			g_print("New Feed received: %s\n", url);
-			feed->feed_url = sanitize_url(feed->feed_url);
-			d("sanitized feed URL: %s\n", feed->feed_url);
-			if (g_hash_table_find(rf->hr, check_if_match, feed->feed_url)) {
-				rss_error(NULL, NULL, _("Error adding feed."),
-					_("Feed already exists!"));
-					return;
-			}
-			if (setup_feed(feed)) {
-				gchar *msg = g_strdup_printf(_("Importing URL: %s"),
-						feed->feed_url);
-				taskbar_push_message(msg);
-				g_free(msg);
-			}
-			if (rf->treeview)
-				store_redraw(GTK_TREE_VIEW(rf->treeview));
-			save_gconf_feed();
-#if (DATASERVER_VERSION >= 2033001)
-			camel_operation_pop_message (NULL);
-#else
-		camel_operation_end(NULL);
-#endif
-		}
-		g_free(url);
+		res = subscribe_method(url);
+		g_dbus_method_invocation_return_value (invocation,
+			g_variant_new ("(b)", res));
+	}
+	if (!g_strcmp0 (method_name, "Ping")) {
+		g_dbus_method_invocation_return_value (invocation,
+			g_variant_new ("(b)", TRUE));
 	}
+}
 
-	if (!g_strcmp0 (signal_name, "ping")) {
-		GDBusMessage *message;
-		GVariantBuilder *builder;
-		GError *error = NULL;
-		d("Ping! received from %s\n", interface_name);
-
-		if (!(message = g_dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, "pong")))
-			return;
-		d("Sending Pong! back\n");
-		builder = g_variant_builder_new (G_VARIANT_TYPE_TUPLE);
-		g_variant_builder_add(builder, "s", "ponging");
-		g_dbus_message_set_body (message, g_variant_builder_end (builder));
-		g_dbus_connection_send_message (connection, message,
-			G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error);
-		g_object_unref (message);
-		if (error) {
-			g_debug ("Error while sending ping-request: %s", error->message);
-			g_error_free (error);
-		}
+static void
+on_bus_acquired (GDBusConnection *connection,
+		const gchar     *name,
+		gpointer         user_data)
+{
+	guint reg_id;
+	GError     *error = NULL;
+	nodeinfo = g_dbus_node_info_new_for_xml (introspection_xml,
+				NULL);
+
+	reg_id = g_dbus_connection_register_object (connection,
+		RSS_DBUS_PATH,
+		nodeinfo->interfaces[0],
+		&vtable,
+		NULL, NULL,
+		&error);
+	if (!reg_id) {
+		g_printerr ("Failed to register bus object: %s\n", error->message);
+		g_error_free (error);
 	}
 }
 
+static void
+on_name_acquired (GDBusConnection *connection,
+		const gchar     *name,
+		gpointer         user_data)
+{
+	d("Name aquired.\n");
+}
+
+static void
+on_name_lost (GDBusConnection *connection,
+		const gchar     *name,
+		gpointer         user_data)
+{
+	d("Name lost.\n");
+}
+
 gboolean
 init_gdbus (void)
 {
@@ -161,25 +221,15 @@ init_gdbus (void)
 	g_signal_connect (connection, "closed",
 		G_CALLBACK (connection_closed_cb), NULL);
 
-	if (!g_dbus_connection_signal_subscribe (
-		connection,
-		NULL,
+	g_bus_own_name (G_BUS_TYPE_SESSION,
 		RSS_DBUS_SERVICE,
-/*		DBUS_INTERFACE,*/
-		NULL,
-		DBUS_PATH,
-		NULL,
-		G_DBUS_SIGNAL_FLAGS_NONE,
-		signal_cb,
+		G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
+		on_bus_acquired,
+		on_name_acquired,
+		on_name_lost,
 		NULL,
-		NULL)) {
-			g_warning ("%s: Failed to subscribe for a signal", G_STRFUNC);
-			goto fail;
-		}
-	return FALSE;
-
+		NULL);
 
-fail:	g_object_unref(connection);
-	return TRUE;
+	return FALSE;
 }
 
diff --git a/src/evolution-import-rss.c b/src/evolution-import-rss.c
index f1a4812..fa43229 100644
--- a/src/evolution-import-rss.c
+++ b/src/evolution-import-rss.c
@@ -32,13 +32,11 @@
 #include <gio/gio.h>
 
 #define d(x)
-#define EVOLUTION "evolution&"
+#define EVOLUTION "/opt/gnome-dev/bin/evolution&"
 
-#define DBUS_PATH "/org/gnome/evolution/mail/rss"
-#define RSS_DBUS_SERVICE "org.gnome.evolution.mail.rss"
-//#define DBUS_INTERFACE "org.gnome.evolution.mail.rss.in"
-#define DBUS_INTERFACE "org.gnome.evolution.mail.rss"
-#define DBUS_REPLY_INTERFACE "org.gnome.evolution.mail.rss.out"
+#define RSS_DBUS_PATH "/org/gnome/feed/Reader"
+#define RSS_DBUS_SERVICE "org.gnome.feed.Reader"
+#define RSS_DBUS_INTERFACE "org.gnome.feed.Reader"
 
 //evolution ping roud-trip time in ms, somebody suggest a real value here
 #define EVOLUTION_PING_TIMEOUT 5000
@@ -46,64 +44,50 @@
 #define run(x) G_STMT_START { g_message ("%s", x); system (x); } G_STMT_END
 
 static GDBusConnection *connection = NULL;
+GDBusProxy *proxy;
 
 static gboolean init_gdbus (void);
 
 static gboolean enabled = FALSE;
 GMainLoop *loop;
 gboolean evo_running = FALSE;
-static gchar *feed = NULL;
+const gchar *feed = NULL;
 
+gboolean send_dbus_ping (void);
+gboolean subscribe_feed(const gchar *url);
 
-static void
+gboolean
 send_dbus_ping (void)
 {
-	GDBusMessage *message;
-	GVariantBuilder *builder;
-	GError *error = NULL;
-
-	if (!(message = g_dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, "ping")))
-		return;
-	printf("ping evolution...\n");
-	builder = g_variant_builder_new (G_VARIANT_TYPE_TUPLE);
-	g_variant_builder_add(builder, "s", "evolution-rss");
-	g_dbus_message_set_body (message, g_variant_builder_end (builder));
-	g_dbus_connection_send_message (connection, message,
-		G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error);
-	g_object_unref (message);
-	if (error) {
-		g_debug ("Error while sending ping-request: %s", error->message);
-		g_error_free (error);
-	}
+	GVariant *ret;
+	gboolean val = FALSE;
+
+	d("ping evolution...\n");
+	ret = g_dbus_proxy_call_sync (proxy, "Ping",
+			NULL,
+			G_DBUS_CALL_FLAGS_NONE,
+			-1,
+			NULL,
+			NULL);
+	if (ret)
+		g_variant_get_child (ret, 0, "b", &val);
+	return val;
 }
 
-static void
-send_dbus_message (const char *name, const char *data)
+gboolean
+subscribe_feed(const gchar *url)
 {
-	GDBusMessage *message;
-	GVariantBuilder *builder;
-	GError *error = NULL;
-
-	/* Create a new message on the DBUS_INTERFACE */
-	if (!(message = g_dbus_message_new_signal (DBUS_PATH, DBUS_INTERFACE, name)))
-		return;
-
-	builder = g_variant_builder_new (G_VARIANT_TYPE_TUPLE);
-
-	/* Appends the data as an argument to the message */
-	g_variant_builder_add (builder, "s", data);
-	g_dbus_message_set_body (message, g_variant_builder_end (builder));
-
-	/* Sends the message */
-	g_dbus_connection_send_message (connection, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error);
-
-	/* Frees the message */
-	g_object_unref (message);
-
-	if (error) {
-		g_debug ("%s: Error while sending DBus message: %s", G_STRFUNC, error->message);
-		g_error_free (error);
-	}
+	GVariant *ret;
+	gboolean val;
+
+	ret = g_dbus_proxy_call_sync (proxy, "Subscribe",
+			g_variant_new("(s)", url),
+			G_DBUS_CALL_FLAGS_NONE,
+			-1,
+			NULL,
+			NULL);
+	g_variant_get_child (ret, 0, "b", &val);
+	return val;
 }
 
 static gboolean
@@ -118,32 +102,6 @@ reinit_gdbus (gpointer user_data)
 }
 
 static void
-signal_cb (GDBusConnection *connection,
-		const gchar *sender_name,
-		const gchar *object_path,
-		const gchar *interface_name,
-		const gchar *signal_name,
-		GVariant *parameters,
-		gpointer user_data)
-{
-	if (g_strcmp0 (interface_name, DBUS_INTERFACE) != 0
-	|| g_strcmp0 (object_path, DBUS_PATH) != 0)
-		return;
-
-	d(g_print("interface:%s!\n", interface_name));
-	d(g_print("path:%s!\n", object_path));
-	d(g_print("signal_name:%s!\n", signal_name));
-
-	if (!g_strcmp0 (signal_name, "pong")) {
-		evo_running = TRUE;
-		d(g_print("pong\n"));
-		send_dbus_message ("import", feed);
-		g_usleep(300);
-		g_main_loop_quit(loop);
-	}
-}
-
-static void
 connection_closed_cb  (GDBusConnection *pconnection,
 	gboolean remote_peer_vanished, GError *error, gpointer user_data)
 {
@@ -152,15 +110,6 @@ connection_closed_cb  (GDBusConnection *pconnection,
 	connection = NULL;
 
 	g_timeout_add (3000, reinit_gdbus, NULL);
-#if 0
-	else if (dbus_message_is_signal (message, DBUS_REPLY_INTERFACE, "pong")) {
-		g_print("pong!\n");
-		evo_running = TRUE;
-		g_main_loop_quit(loop);
-		return DBUS_HANDLER_RESULT_HANDLED;
-	}
-	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-#endif
 }
 
 static gboolean
@@ -183,29 +132,6 @@ init_gdbus (void)
 }
 
 static gboolean
-no_evo_cb (gpointer user_data)
-{
-	if (!evo_running) {
-		g_print("no evolution running!\n");
-		g_print("trying to start...\n");
-		run(EVOLUTION);
-		sleep(30);
-		send_dbus_ping ();
-	}
-	return FALSE;
-}
-
-
-static gboolean
-main_prog(gpointer user_data)
-{
-	if (connection != NULL)
-		send_dbus_ping ();
-	g_timeout_add (EVOLUTION_PING_TIMEOUT, no_evo_cb, NULL);
-	return FALSE;
-}
-
-static gboolean
 err_evo_cb (gpointer user_data)
 {
 	g_print("cannot start evolution...retry %d\n", GPOINTER_TO_INT(user_data));
@@ -213,35 +139,10 @@ err_evo_cb (gpointer user_data)
 	return TRUE;
 }
 
-static void
-on_bus_acquired (GDBusConnection *connection,
-		const gchar     *name,
-		gpointer         user_data)
-{
-	g_print("Auquired bus connection.\n");
-}
-
-static void
-on_name_acquired (GDBusConnection *connection,
-		const gchar     *name,
-		gpointer         user_data)
-{
-	g_print("Name aquired.\n");
-}
-
-static void
-on_name_lost (GDBusConnection *connection,
-		const gchar     *name,
-		gpointer         user_data)
-{
-	g_print("Name lost.\n");
-}
-
 int
 main (int argc, char *argv[])
 {
 	guint i=0;
-	guint owner_id;
 
 	feed = argv[1];
 	if (!feed) {
@@ -252,15 +153,6 @@ main (int argc, char *argv[])
 	g_type_init ();
 
 
-	owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
-		RSS_DBUS_SERVICE,
-		G_BUS_NAME_OWNER_FLAGS_NONE,
-		on_bus_acquired,
-		on_name_acquired,
-		on_name_lost,
-		NULL,
-		NULL);
-
 	loop = g_main_loop_new (NULL, FALSE);
 
 	if (!init_gdbus ())
@@ -269,53 +161,34 @@ main (int argc, char *argv[])
 	g_signal_connect (connection, "closed",
 		G_CALLBACK (connection_closed_cb), NULL);
 
-	g_timeout_add (100, main_prog, NULL);
-
-	if (!g_dbus_connection_signal_subscribe (
-		connection,
-		NULL,
-		RSS_DBUS_SERVICE,
-		NULL,
-		NULL,
-		NULL,
-		G_DBUS_SIGNAL_FLAGS_NONE,
-		signal_cb,
-		NULL,
-		NULL)) {
-			g_warning ("%s: Failed to subscribe for a signal", G_STRFUNC);
-			goto fail;
-		}
-
-	g_main_loop_run(loop);
-
-	while (!evo_running && i < 2) {
+	proxy = g_dbus_proxy_new_sync (connection,
+			G_DBUS_PROXY_FLAGS_NONE,
+			NULL,
+			RSS_DBUS_SERVICE,
+			RSS_DBUS_PATH,
+			RSS_DBUS_INTERFACE,
+			NULL,
+			NULL);
+
+	evo_running = send_dbus_ping ();
+
+	while (!evo_running && i<2) {
 		run(EVOLUTION);
 		g_print("Starting evolution...\n");
-		g_usleep(30);
-		send_dbus_ping ();
+		while (!(evo_running = send_dbus_ping ()))
+			sleep(1);
+		if (evo_running)
+			break;
 		g_timeout_add (EVOLUTION_PING_TIMEOUT, err_evo_cb, GINT_TO_POINTER(i++));
 		g_main_loop_run(loop);
 	}
 
-#if 0
 	if (evo_running) {
-		if (s)
-			send_dbus_message ("evolution_rss_feed", s);
-		else
-			g_print("Syntax: evolution-import-rss URL\n");
-	} else {
-		g_print("evolution repetably failed to start!\n");
-		g_print("Cannot add feed!");
+		gboolean result = subscribe_feed(feed);
+		g_print("Success:%d\n", result);
+		return result;
 	}
 
-	if (bus != NULL) {
-		dbus_connection_unref (bus);
-		bus = NULL;
-	}
-	return 0;
-#endif
-
-fail:	return FALSE;
-
+	return FALSE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]