示例#1
0
gint call_mms_dbus(SharingEntryMedia *media)
{
	GError *error = NULL;
	DBusGConnection *connection;

	g_type_init();

	connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
	if (!connection)
	{
		g_printerr("Failed to open connection to system bus: %s\n", error->message);
		ULOG_DEBUG_L("Failed to open connection to system bus: %s\n", error->message);	
		g_clear_error(&error);
		return EXIT_FAILURE;
	}

	DBusGProxy *proxy;
	gint retval = 0;
	const gchar *local_file;
	const gchar *desc;
	const gchar *title;
	local_file = sharing_entry_media_get_localpath(media);
	desc = sharing_entry_media_get_desc(media);
	title = sharing_entry_media_get_title(media);

	proxy = dbus_g_proxy_new_for_name(connection, MMS_DBUS_NAME, MMS_DBUS_PATH, MMS_DBUS_IFACE);
	if (!dbus_g_proxy_call(proxy, MMS_SHARE_SIG, &error, G_TYPE_STRING, local_file, G_TYPE_STRING, title, G_TYPE_STRING, desc, G_TYPE_INVALID))
	{
		if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
			g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
			ULOG_DEBUG_L("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
		} else {
			g_printerr("Failed to call method: %s\n", error->message);
			ULOG_DEBUG_L("Failed to call method: %s\n", error->message);
		}
		g_clear_error(&error);
	}
	g_object_unref(proxy);

	return retval;
}
示例#2
0
SharingPluginInterfaceSendResult
sharing_plugin_interface_send (SharingTransfer* transfer, ConIcConnection* con,
    gboolean* dead_mans_switch)
{
	SharingEntry *entry = sharing_transfer_get_entry (transfer);
	DBusGConnection* connection = get_connection ();
	GSList* p;
	DBusGProxy *uploader = NULL;

	if (!connection)
	{
		return SHARING_SEND_ERROR_UNKNOWN;
	}

	uploader = dbus_g_proxy_new_for_name (connection,
			"com.imgur", 
			"/com/imgur",
			"com.imgur");
	
	for (p=sharing_entry_get_media (entry); p; p=g_slist_next (p))
	{
		SharingEntryMedia* media = p->data;
		GError *error = NULL;
		gchar *url = NULL;
		GHashTable *result = NULL;
		const gchar *filename =
			sharing_entry_media_get_localpath (media);
	
		if (sharing_entry_media_get_sent (media))
			continue; /* it was already sent */

		/* Great, so let's send it. */

		if (com_imgur_upload (uploader, filename, &result, &error))
		{
			GValue *url_v = g_hash_table_lookup (result, "imgur_page");

			if (url_v)
				url = g_strdup (g_value_get_string (url_v));

			if (result)
				g_hash_table_unref (result);
		}
		else
		{
			g_warning ("Error in upload: %s", error->message);
			g_error_free (error);
			return SHARING_SEND_ERROR_UNKNOWN;
		}

		if (url)
		{
			/* looks like a successful operation */
	
			/*
			 * At some point we may want a configuration
			 * setting that means that the libsharing
			 * plugin does *not* launch the browser.
			 * But this will only become useful when
			 * there is a GUI app to look at existing
			 * uploads.
			 */
	
			if (!launch_browser (connection, url))
			{
				g_free (url);
				return SHARING_SEND_ERROR_UNKNOWN;
			}

			g_free (url);
			sharing_entry_media_set_sent (media, TRUE);
		}
		else
		{
			return SHARING_SEND_ERROR_UNKNOWN;
		}

		*dead_mans_switch = 0; /* keepalive */
	}

	/* FIXME: don't we want to unref the connection? */
	
	return SHARING_SEND_SUCCESS;
}