예제 #1
0
/**
 * send:
 * @account: #SharingTransfer to be send
 * @con: Connection used
 * @dead_mans_switch: Turn to %FALSE at least every 30 seconds.
 *
 * Sends #SharingTransfer to service.
 *
 * Returns: #SharingPluginInterfaceSendResult
 */
SharingPluginInterfaceSendResult send_mms (SharingTransfer* transfer,
    ConIcConnection* con, gboolean* dead_mans_switch)
{
    SharingPluginInterfaceSendResult ret = SHARING_SEND_SUCCESS;

    SharingEntry *entry = sharing_transfer_get_entry( transfer );

    gint result = 0;
    for (GSList* p = sharing_entry_get_media (entry); p != NULL; p = g_slist_next(p)) {
      SharingEntryMedia* media = p->data;
      /* Process media */
      if (!sharing_entry_media_get_sent (media)) {
	/* Post media */
	result = call_mms_dbus(media);
	/* Process post result */
	if (result == 0 /* EXAMPLE: MY_SEND_RESULT_SUCCESS */) {
	  /* If success mark media as sent */
	  sharing_entry_media_set_sent (media, TRUE);
	  /* And mark process to your internal data structure */
	  //my_send_task->upload_done += sharing_entry_media_get_size (media); 
	} else {
	  /* We have sent the file in last sharing-manager call */
	  //my_send_task->upload_done += sharing_entry_media_get_size (media);
	}
      }
    }
    return ret;
}
예제 #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;
}