diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index c0dae0318..5de7a3c6b 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -614,10 +614,14 @@ torrentInitFromInfo( tr_torrent * tor ) tor->completeness = tr_cpGetStatus( &tor->completion ); } +static void tr_torrentFireMetadataCompleted( tr_torrent * tor ); + void tr_torrentGotNewInfoDict( tr_torrent * tor ) { torrentInitFromInfo( tor ); + + tr_torrentFireMetadataCompleted( tor ); } static void @@ -1617,6 +1621,12 @@ tr_torrentSetCompletenessCallback( tr_torrent * tor, tor->completeness_func_user_data = user_data; } +void +tr_torrentClearCompletenessCallback( tr_torrent * torrent ) +{ + tr_torrentSetCompletenessCallback( torrent, NULL, NULL ); +} + void tr_torrentSetRatioLimitHitCallback( tr_torrent * tor, tr_torrent_ratio_limit_hit_func func, @@ -1628,12 +1638,6 @@ tr_torrentSetRatioLimitHitCallback( tr_torrent * tor, tor->ratio_limit_hit_func_user_data = user_data; } -void -tr_torrentClearCompletenessCallback( tr_torrent * torrent ) -{ - tr_torrentSetCompletenessCallback( torrent, NULL, NULL ); -} - void tr_torrentClearRatioLimitHitCallback( tr_torrent * torrent ) { @@ -1687,6 +1691,31 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) tr_torrentUnlock( tor ); } +/*** +**** +***/ + +static void +tr_torrentFireMetadataCompleted( tr_torrent * tor ) +{ + assert( tr_isTorrent( tor ) ); + + if( tor->metadata_func ) + tor->metadata_func( tor, tor->metadata_func_user_data ); +} + +void +tr_torrentSetMetadataCallback( tr_torrent * tor, + tr_torrent_metadata_func func, + void * user_data ) +{ + assert( tr_isTorrent( tor ) ); + + tor->metadata_func = func; + tor->metadata_func_user_data = user_data; +} + + /** *** File priorities **/ diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 60e49c211..6f5c6c166 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -219,11 +219,14 @@ struct tr_torrent time_t startDate; time_t anyDate; - tr_torrent_completeness_func * completeness_func; - void * completeness_func_user_data; + tr_torrent_metadata_func * metadata_func; + void * metadata_func_user_data; - tr_torrent_ratio_limit_hit_func * ratio_limit_hit_func; - void * ratio_limit_hit_func_user_data; + tr_torrent_completeness_func * completeness_func; + void * completeness_func_user_data; + + tr_torrent_ratio_limit_hit_func * ratio_limit_hit_func; + void * ratio_limit_hit_func_user_data; tr_bool isRunning; tr_bool isDeleting; diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index b606f98db..619b66758 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -1255,6 +1255,20 @@ void tr_torrentSetCompletenessCallback( void tr_torrentClearCompletenessCallback( tr_torrent * torrent ); + +typedef void ( tr_torrent_metadata_func )( tr_torrent * torrent, + void * user_data ); +/** + * Register to be notified whenever a torrent changes from + * having incomplete metadata to having complete metadata. + * This happens when a magnet link finishes downloading + * metadata from its peers. + */ +void tr_torrentSetMetadataCallback ( + tr_torrent * tor, + tr_torrent_metadata_func func, + void * user_data ); + /** * Register to be notified whenever a torrent's ratio limit * has been hit. This will be called when the torrent's