(trunk gtk) #2096 "magnet links" -- if a user (or, more likely, web browser) starts up a second copy of Transmission to add a magnet link via its command line, delegate that magnet link back to the already-running copy of Transmission via DBus.

This commit is contained in:
Charles Kerr 2009-11-29 20:35:48 +00:00
parent ce7cda7a66
commit 7d0cd82014
2 changed files with 32 additions and 15 deletions

View File

@ -954,7 +954,7 @@ tr_core_add_ctor( TrCore * core, tr_ctor * ctor )
/* invoked remotely via dbus. */
gboolean
tr_core_add_metainfo( TrCore * core,
const char * base64_metainfo,
const char * payload,
gboolean * setme_success,
GError ** gerr UNUSED )
{
@ -964,7 +964,12 @@ tr_core_add_metainfo( TrCore * core,
{
*setme_success = FALSE;
}
else
else if( gtr_is_supported_url( payload ) || gtr_is_magnet_link( payload ) )
{
tr_core_add_from_url( core, payload );
*setme_success = TRUE;
}
else /* base64-encoded metainfo */
{
int err;
int file_length;
@ -975,7 +980,7 @@ tr_core_add_metainfo( TrCore * core,
ctor = tr_ctorNew( session );
tr_core_apply_defaults( ctor );
file_contents = tr_base64_decode( base64_metainfo, -1, &file_length );
file_contents = tr_base64_decode( payload, -1, &file_length );
err = tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length );
if( !err )

View File

@ -375,7 +375,7 @@ checkfilenames( int argc, char **argv )
ret = g_slist_prepend( ret, filename );
else {
if( gtr_is_hex_hashcode( argv[i] ) )
ret = g_slist_prepend( ret, g_strdup( argv[i] ) );
ret = g_slist_prepend( ret, g_strdup_printf( "magnet:?xt=urn:btih:%s", argv[i] ) );
g_free( filename );
}
}
@ -564,25 +564,37 @@ gtr_dbus_add_torrent( const char * filename )
{
/* FIXME: why is this static? */
static gboolean success = FALSE;
#ifdef HAVE_DBUS_GLIB
DBusGProxy * proxy = NULL;
char * payload;
gsize file_length;
char * file_contents = NULL;
/* If it's a file, load its contents and send them over the wire...
* it might be a temporary file that's going to disappear. */
if( g_file_get_contents( filename, &file_contents, &file_length, NULL ) )
payload = tr_base64_encode( file_contents, file_length, NULL );
else if( gtr_is_supported_url( filename ) || gtr_is_magnet_link( filename ) )
payload = tr_strdup( filename );
else
payload = NULL;
if( payload != NULL )
{
GError * err = NULL;
DBusGConnection * conn;
char * file_contents;
gsize file_length;
DBusGProxy * proxy = NULL;
if( g_file_get_contents( filename, &file_contents, &file_length, NULL ) )
{
char * b64 = tr_base64_encode( file_contents, file_length, NULL );
if(( conn = dbus_g_bus_get( DBUS_BUS_SESSION, &err )))
proxy = dbus_g_proxy_new_for_name (conn, VALUE_SERVICE_NAME,
VALUE_SERVICE_OBJECT_PATH,
VALUE_SERVICE_INTERFACE );
else if( err )
g_message( "err: %s", err->message );
if( proxy )
dbus_g_proxy_call( proxy, "AddMetainfo", &err,
G_TYPE_STRING, b64,
G_TYPE_STRING, payload,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &success,
G_TYPE_INVALID );
@ -594,10 +606,10 @@ gtr_dbus_add_torrent( const char * filename )
if( conn )
dbus_g_connection_unref( conn );
tr_free( b64 );
g_free( file_contents );
tr_free( payload );
}
else g_message( "couldn't read %s", filename );
g_free( file_contents );
#endif
return success;