Changeset 9635 for trunk/gtk/util.c


Ignore:
Timestamp:
Nov 29, 2009, 8:35:48 PM (12 years ago)
Author:
charles
Message:

(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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r9628 r9635  
    376376            else {
    377377                if( gtr_is_hex_hashcode( argv[i] ) )
    378                     ret = g_slist_prepend( ret, g_strdup( argv[i] ) );
     378                    ret = g_slist_prepend( ret, g_strdup_printf( "magnet:?xt=urn:btih:%s", argv[i] ) );
    379379                g_free( filename );
    380380            }
     
    565565    /* FIXME: why is this static? */
    566566    static gboolean success = FALSE;
     567
    567568#ifdef HAVE_DBUS_GLIB
    568     DBusGProxy * proxy = NULL;
    569     GError * err = NULL;
    570     DBusGConnection * conn;
    571     char * file_contents;
     569    char * payload;
    572570    gsize file_length;
    573 
     571    char * file_contents = NULL;
     572
     573    /* If it's a file, load its contents and send them over the wire...
     574     * it might be a temporary file that's going to disappear. */
    574575    if( g_file_get_contents( filename, &file_contents, &file_length, NULL ) )
    575     {
    576         char * b64 = tr_base64_encode( file_contents, file_length, NULL );
     576        payload = tr_base64_encode( file_contents, file_length, NULL );
     577    else if( gtr_is_supported_url( filename ) || gtr_is_magnet_link( filename ) )
     578        payload = tr_strdup( filename );
     579    else
     580        payload = NULL;
     581
     582    if( payload != NULL )
     583    {
     584        GError * err = NULL;
     585        DBusGConnection * conn;
     586        DBusGProxy * proxy = NULL;
     587
    577588        if(( conn = dbus_g_bus_get( DBUS_BUS_SESSION, &err )))
    578589            proxy = dbus_g_proxy_new_for_name (conn, VALUE_SERVICE_NAME,
     
    581592        else if( err )
    582593           g_message( "err: %s", err->message );
     594
    583595        if( proxy )
    584596            dbus_g_proxy_call( proxy, "AddMetainfo", &err,
    585                                G_TYPE_STRING, b64,
     597                               G_TYPE_STRING, payload,
    586598                               G_TYPE_INVALID,
    587599                               G_TYPE_BOOLEAN, &success,
     
    595607            dbus_g_connection_unref( conn );
    596608
    597         tr_free( b64 );
    598         g_free( file_contents );
    599     }
    600     else g_message( "couldn't read %s", filename );
     609        tr_free( payload );
     610    }
     611
     612    g_free( file_contents );
    601613
    602614#endif
Note: See TracChangeset for help on using the changeset viewer.