Changeset 9627


Ignore:
Timestamp:
Nov 29, 2009, 8:27:55 AM (12 years ago)
Author:
charles
Message:

(trunk libT, gtk) #2625 "ability to create a magnet link" -- add hook for generating a magnet link from a tr_torrent, and use it in the Torrent Properties dialog in the GTK+ client

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/details.c

    r9601 r9627  
    7777
    7878    GtkWidget * hash_lb;
     79    GtkWidget * magnet_lb;
    7980    GtkWidget * privacy_lb;
    8081    GtkWidget * origin_lb;
     
    608609
    609610static void
     611gtr_label_set_text( GtkLabel * lb, const char * newstr )
     612{
     613    const char * oldstr = gtk_label_get_text( lb );
     614
     615    if( strcmp( oldstr, newstr ) )
     616        gtk_label_set_text( lb, newstr );
     617}
     618
     619static void
    610620refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n )
    611621{
    612622    int i;
     623    char * freeme;
    613624    const char * str;
    614625    const char * none = _( "None" );
     
    637648            str = _( "Public torrent" );
    638649    }
    639     gtk_label_set_text( GTK_LABEL( di->privacy_lb ), str );
     650    gtr_label_set_text( GTK_LABEL( di->privacy_lb ), str );
    640651
    641652
     
    666677        }
    667678    }
    668     gtk_label_set_text( GTK_LABEL( di->origin_lb ), str );
     679    gtr_label_set_text( GTK_LABEL( di->origin_lb ), str );
    669680
    670681
     
    697708            str = mixed;
    698709    }
    699     gtk_label_set_text( GTK_LABEL( di->destination_lb ), str );
     710    gtr_label_set_text( GTK_LABEL( di->destination_lb ), str );
    700711
    701712    /* state_lb */
     
    712723            str = mixed;
    713724    }
    714     gtk_label_set_text( GTK_LABEL( di->state_lb ), str );
     725    gtr_label_set_text( GTK_LABEL( di->state_lb ), str );
    715726
    716727
     
    730741            str = tr_strltime( buf, time(NULL)-baseline, sizeof( buf ) );
    731742    }
    732     gtk_label_set_text( GTK_LABEL( di->date_started_lb ), str );
     743    gtr_label_set_text( GTK_LABEL( di->date_started_lb ), str );
    733744
    734745
     
    748759            str = tr_strltime( buf, baseline, sizeof( buf ) );
    749760    }
    750     gtk_label_set_text( GTK_LABEL( di->eta_lb ), str );
     761    gtr_label_set_text( GTK_LABEL( di->eta_lb ), str );
    751762     
    752763
     
    784795            str = buf;
    785796        }
    786         gtk_label_set_text( GTK_LABEL( di->size_lb ), str );
     797        gtr_label_set_text( GTK_LABEL( di->size_lb ), str );
    787798    }
    788799
     
    819830        }
    820831    }
    821     gtk_label_set_text( GTK_LABEL( di->have_lb ), str );
     832    gtr_label_set_text( GTK_LABEL( di->have_lb ), str );
    822833
    823834
     
    840851        str = buf;
    841852    }
    842     gtk_label_set_text( GTK_LABEL( di->dl_lb ), str );
     853    gtr_label_set_text( GTK_LABEL( di->dl_lb ), str );
    843854
    844855
     
    851862        str = tr_strlsize( buf, sum, sizeof( buf ) );
    852863    }
    853     gtk_label_set_text( GTK_LABEL( di->ul_lb ), str );
     864    gtr_label_set_text( GTK_LABEL( di->ul_lb ), str );
    854865
    855866
     
    866877        str = tr_strlratio( buf, tr_getRatio( up, down ), sizeof( buf ) );
    867878    }
    868     gtk_label_set_text( GTK_LABEL( di->ratio_lb ), str );
     879    gtr_label_set_text( GTK_LABEL( di->ratio_lb ), str );
    869880
    870881    /* hash_lb */
     
    875886    else
    876887        str = mixed;
    877     gtk_label_set_text( GTK_LABEL( di->hash_lb ), str );
     888    gtr_label_set_text( GTK_LABEL( di->hash_lb ), str );
     889
     890    /* magnet lb */
     891    freeme = NULL;
     892    if( n<=0 )
     893        str = none;
     894    else if ( n>1 )
     895        str = mixed;
     896    else if( infos[0]->isPrivate )
     897        str = _( "Private Torrent" );
     898    else
     899        str = freeme = tr_torrentGetMagnetLink( torrents[0] );
     900    gtr_label_set_text( GTK_LABEL( di->magnet_lb ), str );
     901    tr_free( freeme );
    878902
    879903    /* error */
     
    892916    if( !str || !*str )
    893917        str = none;
    894     gtk_label_set_text( GTK_LABEL( di->error_lb ), str );
     918    gtr_label_set_text( GTK_LABEL( di->error_lb ), str );
    895919
    896920
     
    917941        }
    918942    }
    919     gtk_label_set_text( GTK_LABEL( di->last_activity_lb ), str );
     943    gtr_label_set_text( GTK_LABEL( di->last_activity_lb ), str );
    920944
    921945    g_free( stats );
     
    9901014        hig_workarea_add_row( t, &row, _( "Hash:" ), l, NULL );
    9911015        di->hash_lb = l;
     1016
     1017        /* magnet url */
     1018        l = g_object_new( GTK_TYPE_LABEL, "selectable", TRUE,
     1019                                          "ellipsize", PANGO_ELLIPSIZE_END,
     1020                                           NULL );
     1021        hig_workarea_add_row( t, &row, _( "Magnet link:" ), l, NULL );
     1022        di->magnet_lb = l;
    9921023
    9931024        /* privacy */
  • trunk/libtransmission/torrent-magnet.c

    r9585 r9627  
    298298    return ret;
    299299}
     300
     301char*
     302tr_torrentGetMagnetLink( const tr_torrent * tor )
     303{
     304    int i;
     305    char * ret;
     306    struct evbuffer * s;
     307
     308    assert( tr_isTorrent( tor ) );
     309
     310    s = evbuffer_new( );
     311    evbuffer_add_printf( s, "magnet:?xt=urn:btih:%s", tor->info.hashString );
     312    evbuffer_add_printf( s, "%s", "&dn=" );
     313    tr_http_escape( s, tr_torrentName( tor ), -1, TRUE );
     314    for( i=0; i<tor->info.trackerCount; ++i )
     315    {
     316        evbuffer_add_printf( s, "%s", "&tr=" );
     317        tr_http_escape( s, tor->info.trackers[i].announce, -1, TRUE );
     318    }
     319
     320    ret = tr_strndup( EVBUFFER_DATA( s ), EVBUFFER_LENGTH( s ) );
     321    evbuffer_free( s );
     322    return ret;
     323}
  • trunk/libtransmission/transmission.h

    r9591 r9627  
    11681168
    11691169/**
    1170  * This returns the the root directory of where the torrent is.
     1170 * Returns the the root directory of where the torrent is.
    11711171 *
    11721172 * This will usually be the downloadDir.  However if the torrent
     
    11751175 */
    11761176const char * tr_torrentGetCurrentDir( const tr_torrent * tor );
     1177
     1178
     1179/**
     1180 * Returns a newly-allocated string with a magnet link of the torrent.
     1181 * Use tr_free() to free the string when done.
     1182 */
     1183char* tr_torrentGetMagnetLink( const tr_torrent * tor );
    11771184
    11781185/**
Note: See TracChangeset for help on using the changeset viewer.