mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
#1369: clarify the different torrent status & callbacks' APIs and typenames
This commit is contained in:
26
cli/cli.c
26
cli/cli.c
@@ -173,9 +173,9 @@ escape( char * out,
|
||||
}
|
||||
|
||||
static void
|
||||
torrentStateChanged( tr_torrent * torrent UNUSED,
|
||||
cp_status_t status UNUSED,
|
||||
void * user_data UNUSED )
|
||||
torrentCompletenessChanged( tr_torrent * torrent UNUSED,
|
||||
tr_completeness completeness UNUSED,
|
||||
void * user_data UNUSED )
|
||||
{
|
||||
system( finishCall );
|
||||
}
|
||||
@@ -184,10 +184,10 @@ static int leftToScrape = 0;
|
||||
|
||||
static void
|
||||
scrapeDoneFunc( struct tr_handle * session UNUSED,
|
||||
long response_code,
|
||||
const void * response,
|
||||
size_t response_byte_count,
|
||||
void * host )
|
||||
long response_code,
|
||||
const void * response,
|
||||
size_t response_byte_count,
|
||||
void * host )
|
||||
{
|
||||
tr_benc top, *files;
|
||||
|
||||
@@ -260,18 +260,18 @@ getStatusStr( const tr_stat * st,
|
||||
char * buf,
|
||||
size_t buflen )
|
||||
{
|
||||
if( st->status & TR_STATUS_CHECK_WAIT )
|
||||
if( st->activity & TR_STATUS_CHECK_WAIT )
|
||||
{
|
||||
tr_snprintf( buf, buflen, "Waiting to verify local files" );
|
||||
}
|
||||
else if( st->status & TR_STATUS_CHECK )
|
||||
else if( st->activity & TR_STATUS_CHECK )
|
||||
{
|
||||
tr_snprintf( buf, buflen,
|
||||
"Verifying local files (%.2f%%, %.2f%% valid)",
|
||||
100 * st->recheckProgress,
|
||||
100.0 * st->percentDone );
|
||||
}
|
||||
else if( st->status & TR_STATUS_DOWNLOAD )
|
||||
else if( st->activity & TR_STATUS_DOWNLOAD )
|
||||
{
|
||||
char ratioStr[80];
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
@@ -287,7 +287,7 @@ getStatusStr( const tr_stat * st,
|
||||
st->rateUpload,
|
||||
ratioStr );
|
||||
}
|
||||
else if( st->status & TR_STATUS_SEED )
|
||||
else if( st->activity & TR_STATUS_SEED )
|
||||
{
|
||||
char ratioStr[80];
|
||||
tr_strlratio( ratioStr, st->ratio, sizeof( ratioStr ) );
|
||||
@@ -473,7 +473,7 @@ main( int argc,
|
||||
#ifndef WIN32
|
||||
signal( SIGHUP, sigHandler );
|
||||
#endif
|
||||
tr_torrentSetStatusCallback( tor, torrentStateChanged, NULL );
|
||||
tr_torrentSetCompletenessCallback( tor, torrentCompletenessChanged, NULL );
|
||||
tr_torrentStart( tor );
|
||||
|
||||
if( verify )
|
||||
@@ -512,7 +512,7 @@ main( int argc,
|
||||
}
|
||||
|
||||
st = tr_torrentStat( tor );
|
||||
if( st->status & TR_STATUS_STOPPED )
|
||||
if( st->activity & TR_STATUS_STOPPED )
|
||||
break;
|
||||
|
||||
getStatusStr( st, line, sizeof( line ) );
|
||||
|
||||
@@ -70,10 +70,9 @@ countActiveTorrents( GtkTreeModel * model,
|
||||
GtkTreeIter * iter,
|
||||
gpointer activeTorrentCount )
|
||||
{
|
||||
int status = -1;
|
||||
|
||||
gtk_tree_model_get( model, iter, MC_STATUS, &status, -1 );
|
||||
if( status != TR_STATUS_STOPPED )
|
||||
int activity = -1;
|
||||
gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
|
||||
if( activity != TR_STATUS_STOPPED )
|
||||
*(int*)activeTorrentCount += 1;
|
||||
return FALSE; /* keep iterating */
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ accumulateStatusForeach( GtkTreeModel * model,
|
||||
GtkTreeIter * iter,
|
||||
gpointer user_data )
|
||||
{
|
||||
int status = 0;
|
||||
int activity = 0;
|
||||
struct counts_data * counts = user_data;
|
||||
|
||||
++counts->totalCount;
|
||||
|
||||
gtk_tree_model_get( model, iter, MC_STATUS, &status, -1 );
|
||||
gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
|
||||
|
||||
if( TR_STATUS_IS_ACTIVE( status ) )
|
||||
if( TR_STATUS_IS_ACTIVE( activity ) )
|
||||
++counts->activeCount;
|
||||
else
|
||||
++counts->inactiveCount;
|
||||
|
||||
@@ -79,7 +79,7 @@ getProgressString( const tr_info * info,
|
||||
tr_strlratio( buf3, torStat->ratio, sizeof( buf3 ) ) );
|
||||
|
||||
/* add time when downloading */
|
||||
if( torStat->status == TR_STATUS_DOWNLOAD )
|
||||
if( torStat->activity == TR_STATUS_DOWNLOAD )
|
||||
{
|
||||
const int eta = torStat->eta;
|
||||
GString * gstr = g_string_new( str );
|
||||
@@ -138,7 +138,7 @@ getShortStatusString( const tr_stat * torStat )
|
||||
{
|
||||
GString * gstr = g_string_new( NULL );
|
||||
|
||||
switch( torStat->status )
|
||||
switch( torStat->activity )
|
||||
{
|
||||
case TR_STATUS_STOPPED:
|
||||
g_string_assign( gstr, _( "Paused" ) );
|
||||
@@ -159,7 +159,7 @@ getShortStatusString( const tr_stat * torStat )
|
||||
case TR_STATUS_SEED:
|
||||
{
|
||||
char buf[128];
|
||||
if( torStat->status != TR_STATUS_DOWNLOAD )
|
||||
if( torStat->activity != TR_STATUS_DOWNLOAD )
|
||||
{
|
||||
tr_strlratio( buf, torStat->ratio, sizeof( buf ) );
|
||||
g_string_append_printf( gstr, _( "Ratio: %s" ), buf );
|
||||
@@ -180,9 +180,9 @@ getShortStatusString( const tr_stat * torStat )
|
||||
static char*
|
||||
getStatusString( const tr_stat * torStat )
|
||||
{
|
||||
const int isActive = torStat->status != TR_STATUS_STOPPED;
|
||||
const int isChecking = torStat->status == TR_STATUS_CHECK
|
||||
|| torStat->status == TR_STATUS_CHECK_WAIT;
|
||||
const int isActive = torStat->activity != TR_STATUS_STOPPED;
|
||||
const int isChecking = torStat->activity == TR_STATUS_CHECK
|
||||
|| torStat->activity == TR_STATUS_CHECK_WAIT;
|
||||
|
||||
GString * gstr = g_string_new( NULL );
|
||||
|
||||
@@ -190,7 +190,7 @@ getStatusString( const tr_stat * torStat )
|
||||
{
|
||||
g_string_assign( gstr, torStat->errorString );
|
||||
}
|
||||
else switch( torStat->status )
|
||||
else switch( torStat->activity )
|
||||
{
|
||||
case TR_STATUS_STOPPED:
|
||||
case TR_STATUS_CHECK_WAIT:
|
||||
@@ -376,14 +376,10 @@ torrent_cell_renderer_render(
|
||||
GdkRectangle my_expose;
|
||||
int w, h;
|
||||
struct TorrentCellRendererPrivate * p = self->priv;
|
||||
GtkCellRenderer * text_renderer =
|
||||
torStat->error != 0
|
||||
? p->
|
||||
text_renderer_err
|
||||
: p->
|
||||
text_renderer;
|
||||
const gboolean isActive = torStat->status !=
|
||||
TR_STATUS_STOPPED;
|
||||
GtkCellRenderer * text_renderer = torStat->error != 0
|
||||
? p->text_renderer_err
|
||||
: p->text_renderer;
|
||||
const gboolean isActive = torStat->activity != TR_STATUS_STOPPED;
|
||||
|
||||
my_bg = *background_area;
|
||||
my_bg.x += cell->xpad;
|
||||
|
||||
@@ -377,8 +377,8 @@ compareByState( GtkTreeModel * model,
|
||||
int sa, sb, ret;
|
||||
|
||||
/* first by state */
|
||||
gtk_tree_model_get( model, a, MC_STATUS, &sa, -1 );
|
||||
gtk_tree_model_get( model, b, MC_STATUS, &sb, -1 );
|
||||
gtk_tree_model_get( model, a, MC_ACTIVITY, &sa, -1 );
|
||||
gtk_tree_model_get( model, b, MC_ACTIVITY, &sb, -1 );
|
||||
ret = sa - sb;
|
||||
|
||||
/* second by progress */
|
||||
@@ -714,21 +714,21 @@ tr_core_handle( TrCore * core )
|
||||
}
|
||||
|
||||
static gboolean
|
||||
statsForeach( GtkTreeModel * model,
|
||||
statsForeach( GtkTreeModel * model,
|
||||
GtkTreePath * path UNUSED,
|
||||
GtkTreeIter * iter,
|
||||
gpointer gstats )
|
||||
GtkTreeIter * iter,
|
||||
gpointer gstats )
|
||||
{
|
||||
tr_torrent * tor;
|
||||
struct core_stats * stats = gstats;
|
||||
int status;
|
||||
int activity;
|
||||
|
||||
gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
|
||||
status = tr_torrentGetStatus( tor );
|
||||
activity = tr_torrentGetActivity( tor );
|
||||
|
||||
if( status == TR_STATUS_DOWNLOAD )
|
||||
if( activity == TR_STATUS_DOWNLOAD )
|
||||
++stats->downloadCount;
|
||||
else if( status == TR_STATUS_SEED )
|
||||
else if( activity == TR_STATUS_SEED )
|
||||
++stats->seedingCount;
|
||||
|
||||
return FALSE;
|
||||
@@ -795,7 +795,7 @@ tr_core_add_torrent( TrCore * self,
|
||||
MC_NAME_COLLATED, collated,
|
||||
MC_TORRENT, gtor,
|
||||
MC_TORRENT_RAW, tor,
|
||||
MC_STATUS, torStat->status,
|
||||
MC_ACTIVITY, torStat->activity,
|
||||
-1 );
|
||||
|
||||
/* cleanup */
|
||||
@@ -1009,19 +1009,19 @@ update_foreach( GtkTreeModel * model,
|
||||
GtkTreeIter * iter,
|
||||
gpointer data UNUSED )
|
||||
{
|
||||
int oldStatus;
|
||||
int newStatus;
|
||||
int oldActivity;
|
||||
int newActivity;
|
||||
TrTorrent * gtor;
|
||||
|
||||
/* maybe update the status column in the model */
|
||||
gtk_tree_model_get( model, iter,
|
||||
MC_TORRENT, >or,
|
||||
MC_STATUS, &oldStatus,
|
||||
MC_ACTIVITY, &oldActivity,
|
||||
-1 );
|
||||
newStatus = tr_torrentGetStatus( tr_torrent_handle( gtor ) );
|
||||
if( newStatus != oldStatus )
|
||||
newActivity = tr_torrentGetActivity( tr_torrent_handle( gtor ) );
|
||||
if( newActivity != oldActivity )
|
||||
gtk_list_store_set( GTK_LIST_STORE( model ), iter,
|
||||
MC_STATUS, newStatus,
|
||||
MC_ACTIVITY, newActivity,
|
||||
-1 );
|
||||
|
||||
/* cleanup */
|
||||
@@ -1185,7 +1185,7 @@ maybeInhibitHibernation( TrCore * core )
|
||||
tr_handle * session = tr_core_handle( core );
|
||||
tr_torrent * tor = NULL;
|
||||
while(( tor = tr_torrentNext( session, tor )))
|
||||
if(( active = ( tr_torrentGetStatus( tor ) != TR_STATUS_STOPPED )))
|
||||
if(( active = ( tr_torrentGetActivity( tor ) != TR_STATUS_STOPPED )))
|
||||
break;
|
||||
if( !active )
|
||||
inhibit = FALSE;
|
||||
|
||||
@@ -217,7 +217,7 @@ enum
|
||||
MC_NAME_COLLATED,
|
||||
MC_TORRENT,
|
||||
MC_TORRENT_RAW,
|
||||
MC_STATUS,
|
||||
MC_ACTIVITY,
|
||||
MC_ROW_COUNT
|
||||
};
|
||||
|
||||
|
||||
@@ -162,22 +162,22 @@ notifyInMainThread( gpointer user_data )
|
||||
}
|
||||
|
||||
static void
|
||||
statusChangedCallback( tr_torrent * tor UNUSED,
|
||||
cp_status_t status,
|
||||
void * user_data )
|
||||
completenessChangedCallback( tr_torrent * tor UNUSED,
|
||||
tr_completeness completeness,
|
||||
void * user_data )
|
||||
{
|
||||
if( status == TR_CP_COMPLETE )
|
||||
if( completeness == TR_CP_COMPLETE )
|
||||
g_idle_add( notifyInMainThread, user_data );
|
||||
}
|
||||
|
||||
static TrTorrent *
|
||||
maketorrent( tr_torrent * handle )
|
||||
maketorrent( tr_torrent * tor )
|
||||
{
|
||||
TrTorrent * tor = g_object_new( TR_TORRENT_TYPE, NULL );
|
||||
TrTorrent * gtor = g_object_new( TR_TORRENT_TYPE, NULL );
|
||||
|
||||
tor->priv->handle = handle;
|
||||
tr_torrentSetStatusCallback( handle, statusChangedCallback, tor );
|
||||
return tor;
|
||||
gtor->priv->handle = tor;
|
||||
tr_torrentSetCompletenessCallback( tor, completenessChangedCallback, gtor );
|
||||
return gtor;
|
||||
}
|
||||
|
||||
TrTorrent*
|
||||
@@ -258,7 +258,7 @@ tr_torrent_status_str( TrTorrent * gtor )
|
||||
const int upeers = MAX ( st->peersGettingFromUs, 0 );
|
||||
const int eta = st->eta;
|
||||
|
||||
switch( st->status )
|
||||
switch( st->activity )
|
||||
{
|
||||
case TR_STATUS_CHECK_WAIT:
|
||||
top =
|
||||
|
||||
@@ -318,15 +318,15 @@ checkFilterMode( filter_mode_t filter_mode,
|
||||
switch( filter_mode )
|
||||
{
|
||||
case FILTER_MODE_DOWNLOADING:
|
||||
ret = tr_torrentGetStatus( tor ) == TR_STATUS_DOWNLOAD;
|
||||
ret = tr_torrentGetActivity( tor ) == TR_STATUS_DOWNLOAD;
|
||||
break;
|
||||
|
||||
case FILTER_MODE_SEEDING:
|
||||
ret = tr_torrentGetStatus( tor ) == TR_STATUS_SEED;
|
||||
ret = tr_torrentGetActivity( tor ) == TR_STATUS_SEED;
|
||||
break;
|
||||
|
||||
case FILTER_MODE_PAUSED:
|
||||
ret = tr_torrentGetStatus( tor ) == TR_STATUS_STOPPED;
|
||||
ret = tr_torrentGetActivity( tor ) == TR_STATUS_STOPPED;
|
||||
break;
|
||||
|
||||
case FILTER_MODE_ACTIVE:
|
||||
|
||||
@@ -292,7 +292,7 @@ tr_cpLeftUntilComplete( const tr_completion * cp )
|
||||
return cp->tor->info.totalSize - cp->sizeNow;
|
||||
}
|
||||
|
||||
cp_status_t
|
||||
tr_completeness
|
||||
tr_cpGetStatus( const tr_completion * cp )
|
||||
{
|
||||
if( cp->sizeNow == cp->tor->info.totalSize ) return TR_CP_COMPLETE;
|
||||
|
||||
@@ -36,7 +36,7 @@ void tr_cpClose( tr_completion * );
|
||||
|
||||
/* General */
|
||||
|
||||
cp_status_t tr_cpGetStatus( const tr_completion * );
|
||||
tr_completeness tr_cpGetStatus( const tr_completion * );
|
||||
|
||||
uint64_t tr_cpHaveTotal( const tr_completion * );
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ addField( const tr_torrent * tor,
|
||||
else if( !strcmp( key, "startDate" ) )
|
||||
tr_bencDictAddInt( d, key, st->startDate );
|
||||
else if( !strcmp( key, "status" ) )
|
||||
tr_bencDictAddInt( d, key, st->status );
|
||||
tr_bencDictAddInt( d, key, st->activity );
|
||||
else if( !strcmp( key, "swarmSpeed" ) )
|
||||
tr_bencDictAddInt( d, key, (int)( st->swarmSpeed * 1024 ) );
|
||||
else if( !strcmp( key, "timesCompleted" ) )
|
||||
|
||||
@@ -543,7 +543,7 @@ torrentRealInit( tr_handle * h,
|
||||
TR_DOWN ) );
|
||||
}
|
||||
|
||||
tor->cpStatus = tr_cpGetStatus( tor->completion );
|
||||
tor->completeness = tr_cpGetStatus( tor->completion );
|
||||
|
||||
tor->tracker = tr_trackerNew( tor );
|
||||
tor->trackerSubscription =
|
||||
@@ -739,8 +739,8 @@ tr_torrentStatCached( tr_torrent * tor )
|
||||
: tr_torrentStat( tor );
|
||||
}
|
||||
|
||||
tr_torrent_status
|
||||
tr_torrentGetStatus( tr_torrent * tor )
|
||||
tr_torrent_activity
|
||||
tr_torrentGetActivity( tr_torrent * tor )
|
||||
{
|
||||
tr_torrentRecheckCompleteness( tor );
|
||||
|
||||
@@ -750,7 +750,7 @@ tr_torrentGetStatus( tr_torrent * tor )
|
||||
return TR_STATUS_CHECK_WAIT;
|
||||
if( !tor->isRunning )
|
||||
return TR_STATUS_STOPPED;
|
||||
if( tor->cpStatus == TR_CP_INCOMPLETE )
|
||||
if( tor->completeness == TR_CP_INCOMPLETE )
|
||||
return TR_STATUS_DOWNLOAD;
|
||||
|
||||
return TR_STATUS_SEED;
|
||||
@@ -773,7 +773,7 @@ tr_torrentStat( tr_torrent * tor )
|
||||
|
||||
s = &tor->stats;
|
||||
s->id = tor->uniqueId;
|
||||
s->status = tr_torrentGetStatus( tor );
|
||||
s->activity = tr_torrentGetActivity( tor );
|
||||
s->error = tor->error;
|
||||
memcpy( s->errorString, tor->errorString,
|
||||
sizeof( s->errorString ) );
|
||||
@@ -808,11 +808,11 @@ tr_torrentStat( tr_torrent * tor )
|
||||
s->leftUntilDone = tr_cpLeftUntilDone( tor->completion );
|
||||
s->sizeWhenDone = tr_cpSizeWhenDone( tor->completion );
|
||||
|
||||
s->recheckProgress = s->status == TR_STATUS_CHECK
|
||||
? 1.0 -
|
||||
s->recheckProgress = s->activity == TR_STATUS_CHECK
|
||||
? 1.0 -
|
||||
( tr_torrentCountUncheckedPieces( tor ) /
|
||||
(double) tor->info.pieceCount )
|
||||
: 0.0;
|
||||
: 0.0;
|
||||
|
||||
s->swarmSpeed = tr_rcRate( tor->swarmSpeed );
|
||||
|
||||
@@ -1101,7 +1101,7 @@ checkAndStartImpl( void * vtor )
|
||||
tor->isRunning = 1;
|
||||
*tor->errorString = '\0';
|
||||
tr_torrentResetTransferStats( tor );
|
||||
tor->cpStatus = tr_cpGetStatus( tor->completion );
|
||||
tor->completeness = tr_cpGetStatus( tor->completion );
|
||||
tr_torrentSaveResume( tor );
|
||||
tor->startDate = time( NULL );
|
||||
tr_trackerStart( tor->tracker );
|
||||
@@ -1225,7 +1225,7 @@ tr_torrentFree( tr_torrent * tor )
|
||||
tr_handle * handle = tor->session;
|
||||
tr_globalLock( handle );
|
||||
|
||||
tr_torrentClearStatusCallback( tor );
|
||||
tr_torrentClearCompletenessCallback( tor );
|
||||
tr_runInEventThread( handle, closeTorrent, tor );
|
||||
|
||||
tr_globalUnlock( handle );
|
||||
@@ -1265,58 +1265,58 @@ getCompletionString( int type )
|
||||
}
|
||||
|
||||
static void
|
||||
fireStatusChange( tr_torrent * tor,
|
||||
cp_status_t status )
|
||||
fireCompletenessChange( tr_torrent * tor,
|
||||
tr_completeness status )
|
||||
{
|
||||
assert( tor );
|
||||
assert(
|
||||
status == TR_CP_INCOMPLETE || status == TR_CP_DONE || status ==
|
||||
TR_CP_COMPLETE );
|
||||
assert( ( status == TR_CP_INCOMPLETE )
|
||||
|| ( status == TR_CP_DONE )
|
||||
|| ( status == TR_CP_COMPLETE ) );
|
||||
|
||||
if( tor->status_func )
|
||||
tor->status_func( tor, status, tor->status_func_user_data );
|
||||
if( tor->completeness_func )
|
||||
tor->completeness_func( tor, status, tor->completeness_func_user_data );
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentSetStatusCallback( tr_torrent * tor,
|
||||
tr_torrent_status_func func,
|
||||
void * user_data )
|
||||
tr_torrentSetCompletenessCallback( tr_torrent * tor,
|
||||
tr_torrent_completeness_func func,
|
||||
void * user_data )
|
||||
{
|
||||
assert( tor );
|
||||
tor->status_func = func;
|
||||
tor->status_func_user_data = user_data;
|
||||
tor->completeness_func = func;
|
||||
tor->completeness_func_user_data = user_data;
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentClearStatusCallback( tr_torrent * torrent )
|
||||
tr_torrentClearCompletenessCallback( tr_torrent * torrent )
|
||||
{
|
||||
tr_torrentSetStatusCallback( torrent, NULL, NULL );
|
||||
tr_torrentSetCompletenessCallback( torrent, NULL, NULL );
|
||||
}
|
||||
|
||||
void
|
||||
tr_torrentRecheckCompleteness( tr_torrent * tor )
|
||||
{
|
||||
cp_status_t cpStatus;
|
||||
tr_completeness completeness;
|
||||
|
||||
tr_torrentLock( tor );
|
||||
|
||||
cpStatus = tr_cpGetStatus( tor->completion );
|
||||
completeness = tr_cpGetStatus( tor->completion );
|
||||
|
||||
if( cpStatus != tor->cpStatus )
|
||||
if( completeness != tor->completeness )
|
||||
{
|
||||
const int recentChange = tor->downloadedCur != 0;
|
||||
|
||||
if( recentChange )
|
||||
{
|
||||
tr_torinf( tor, _( "State changed from \"%1$s\" to \"%2$s\"" ),
|
||||
getCompletionString( tor->cpStatus ),
|
||||
getCompletionString( cpStatus ) );
|
||||
getCompletionString( tor->completeness ),
|
||||
getCompletionString( completeness ) );
|
||||
}
|
||||
|
||||
tor->cpStatus = cpStatus;
|
||||
fireStatusChange( tor, cpStatus );
|
||||
tor->completeness = completeness;
|
||||
fireCompletenessChange( tor, completeness );
|
||||
|
||||
if( recentChange && ( cpStatus == TR_CP_COMPLETE ) )
|
||||
if( recentChange && ( completeness == TR_CP_COMPLETE ) )
|
||||
{
|
||||
tr_trackerCompleted( tor->tracker );
|
||||
|
||||
@@ -1332,7 +1332,7 @@ tr_torrentRecheckCompleteness( tr_torrent * tor )
|
||||
int
|
||||
tr_torrentIsSeed( const tr_torrent * tor )
|
||||
{
|
||||
return tor->cpStatus == TR_CP_COMPLETE || tor->cpStatus == TR_CP_DONE;
|
||||
return tor->completeness == TR_CP_COMPLETE || tor->completeness == TR_CP_DONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -194,7 +194,7 @@ struct tr_torrent
|
||||
struct tr_completion * completion;
|
||||
|
||||
struct tr_bitfield * checkedPieces;
|
||||
cp_status_t cpStatus;
|
||||
tr_completeness completeness;
|
||||
|
||||
struct tr_tracker * tracker;
|
||||
struct tr_publisher_tag * trackerSubscription;
|
||||
@@ -211,8 +211,8 @@ struct tr_torrent
|
||||
time_t doneDate;
|
||||
time_t startDate;
|
||||
|
||||
tr_torrent_status_func * status_func;
|
||||
void * status_func_user_data;
|
||||
tr_torrent_completeness_func * completeness_func;
|
||||
void * completeness_func_user_data;
|
||||
|
||||
unsigned int isRunning : 1;
|
||||
unsigned int isDeleting : 1;
|
||||
|
||||
@@ -389,7 +389,7 @@ typedef enum
|
||||
TR_RPC_TORRENT_STARTED,
|
||||
TR_RPC_TORRENT_STOPPED,
|
||||
TR_RPC_TORRENT_REMOVING,
|
||||
TR_RPC_TORRENT_CHANGED,
|
||||
TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */
|
||||
TR_RPC_SESSION_CHANGED
|
||||
}
|
||||
tr_rpc_callback_type;
|
||||
@@ -407,17 +407,23 @@ typedef enum
|
||||
}
|
||||
tr_rpc_callback_status;
|
||||
|
||||
typedef tr_rpc_callback_status ( *tr_rpc_func )( tr_session *
|
||||
handle,
|
||||
tr_rpc_callback_type type,
|
||||
struct tr_torrent *
|
||||
tor_or_null,
|
||||
void *
|
||||
user_data );
|
||||
typedef tr_rpc_callback_status (*tr_rpc_func)(tr_session * session,
|
||||
tr_rpc_callback_type type,
|
||||
struct tr_torrent * tor_or_null,
|
||||
void * user_data );
|
||||
|
||||
void tr_sessionSetRPCCallback( tr_session * handle,
|
||||
tr_rpc_func func,
|
||||
void * user_data );
|
||||
/**
|
||||
* Register to be notified whenever something is changed via RPC,
|
||||
* such as a torrent being added, removed, started, stopped, etc.
|
||||
*
|
||||
* func is invoked FROM LIBTRANSMISSION'S THREAD!
|
||||
* This means func must be fast (to avoid blocking peers),
|
||||
* shouldn't call libtransmission functions (to avoid deadlock),
|
||||
* and shouldn't modify client-level memory without using a mutex!
|
||||
*/
|
||||
void tr_sessionSetRPCCallback( tr_session * session,
|
||||
tr_rpc_func func,
|
||||
void * user_data );
|
||||
|
||||
/**
|
||||
***
|
||||
@@ -969,28 +975,34 @@ void tr_torrentSetAnnounceList( tr_torrent * torrent,
|
||||
typedef enum
|
||||
{
|
||||
TR_CP_INCOMPLETE, /* doesn't have all the desired pieces */
|
||||
TR_CP_DONE, /* has all the pieces but the DND ones */
|
||||
TR_CP_DONE, /* has all the desired pieces, but not all pieces */
|
||||
TR_CP_COMPLETE /* has every piece */
|
||||
}
|
||||
cp_status_t;
|
||||
tr_completeness;
|
||||
|
||||
typedef void ( tr_torrent_status_func )( tr_torrent * torrent,
|
||||
cp_status_t status,
|
||||
void * user_data );
|
||||
typedef void ( tr_torrent_completeness_func )( tr_torrent * torrent,
|
||||
tr_completeness completeness,
|
||||
void * user_data );
|
||||
|
||||
/**
|
||||
* Register to be notified whenever a torrent's state changes.
|
||||
* Register to be notified whenever a torrent's "completeness"
|
||||
* changes. This will be called, for example, when a torrent
|
||||
* finishes downloading and changes from TR_CP_INCOMPLETE to
|
||||
* either TR_CP_COMPLETE or TR_CP_DONE.
|
||||
*
|
||||
* func is invoked FROM LIBTRANSMISSION'S THREAD!
|
||||
* This means func must be fast (to avoid blocking peers),
|
||||
* shouldn't call libtransmission functions (to avoid deadlock),
|
||||
* and shouldn't modify client-level memory without using a mutex!
|
||||
*
|
||||
* @see tr_completeness
|
||||
*/
|
||||
void tr_torrentSetStatusCallback( tr_torrent * torrent,
|
||||
tr_torrent_status_func func,
|
||||
void * user_data );
|
||||
void tr_torrentSetCompletenessCallback(
|
||||
tr_torrent * torrent,
|
||||
tr_torrent_completeness_func func,
|
||||
void * user_data );
|
||||
|
||||
void tr_torrentClearStatusCallback( tr_torrent * torrent );
|
||||
void tr_torrentClearCompletenessCallback( tr_torrent * torrent );
|
||||
|
||||
|
||||
/**
|
||||
@@ -1154,6 +1166,12 @@ struct tr_info
|
||||
tr_file * files;
|
||||
};
|
||||
|
||||
/**
|
||||
* What the torrent is doing right now.
|
||||
*
|
||||
* Note: these values will become a straight enum at some point in the future.
|
||||
* Do not rely on their current `bitfield' implementation
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TR_STATUS_CHECK_WAIT = ( 1 << 0 ), /* Waiting in queue to check files */
|
||||
@@ -1162,7 +1180,7 @@ typedef enum
|
||||
TR_STATUS_SEED = ( 1 << 3 ), /* Seeding */
|
||||
TR_STATUS_STOPPED = ( 1 << 4 ) /* Torrent is stopped */
|
||||
}
|
||||
tr_torrent_status;
|
||||
tr_torrent_activity;
|
||||
|
||||
#define TR_STATUS_IS_ACTIVE( s ) ( ( s ) != TR_STATUS_STOPPED )
|
||||
|
||||
@@ -1174,7 +1192,7 @@ typedef enum
|
||||
}
|
||||
tr_lockfile_state_t;
|
||||
|
||||
tr_torrent_status tr_torrentGetStatus( tr_torrent * );
|
||||
tr_torrent_activity tr_torrentGetActivity( tr_torrent * );
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -1198,8 +1216,8 @@ typedef struct tr_stat
|
||||
@see tr_torrentId() */
|
||||
int id;
|
||||
|
||||
/** The torrent's current status */
|
||||
tr_torrent_status status;
|
||||
/** What is this torrent doing right now? */
|
||||
tr_torrent_activity activity;
|
||||
|
||||
/** Our current announce URL, or NULL if none.
|
||||
This URL may change during the session if the torrent's
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
@end
|
||||
|
||||
void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * torrentData)
|
||||
void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, void * torrentData)
|
||||
{
|
||||
[(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:)
|
||||
withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO];
|
||||
@@ -950,22 +950,22 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
|
||||
- (BOOL) isActive
|
||||
{
|
||||
return fStat->status != TR_STATUS_STOPPED;
|
||||
return fStat->activity != TR_STATUS_STOPPED;
|
||||
}
|
||||
|
||||
- (BOOL) isSeeding
|
||||
{
|
||||
return fStat->status == TR_STATUS_SEED;
|
||||
return fStat->activity == TR_STATUS_SEED;
|
||||
}
|
||||
|
||||
- (BOOL) isChecking
|
||||
{
|
||||
return fStat->status == TR_STATUS_CHECK || fStat->status == TR_STATUS_CHECK_WAIT;
|
||||
return fStat->activity == TR_STATUS_CHECK || fStat->activity == TR_STATUS_CHECK_WAIT;
|
||||
}
|
||||
|
||||
- (BOOL) isCheckingWaiting
|
||||
{
|
||||
return fStat->status == TR_STATUS_CHECK_WAIT;
|
||||
return fStat->activity == TR_STATUS_CHECK_WAIT;
|
||||
}
|
||||
|
||||
- (BOOL) allDownloaded
|
||||
@@ -1107,10 +1107,10 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
}
|
||||
|
||||
//add time when downloading
|
||||
if (fStat->status == TR_STATUS_DOWNLOAD || ([self isSeeding]
|
||||
if (fStat->activity == TR_STATUS_DOWNLOAD || ([self isSeeding]
|
||||
&& (fRatioSetting == NSOnState || (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"]))))
|
||||
{
|
||||
int eta = fStat->status == TR_STATUS_DOWNLOAD ? [self eta] : [self etaRatio];
|
||||
int eta = fStat->activity == TR_STATUS_DOWNLOAD ? [self eta] : [self etaRatio];
|
||||
string = [string stringByAppendingFormat: @" - %@", [self etaString: eta]];
|
||||
}
|
||||
|
||||
@@ -1130,7 +1130,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (fStat->status)
|
||||
switch (fStat->activity)
|
||||
{
|
||||
case TR_STATUS_STOPPED:
|
||||
if (fWaitToStart)
|
||||
@@ -1193,7 +1193,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
//append even if error
|
||||
if ([self isActive] && ![self isChecking])
|
||||
{
|
||||
if (fStat->status == TR_STATUS_DOWNLOAD)
|
||||
if (fStat->activity == TR_STATUS_DOWNLOAD)
|
||||
string = [string stringByAppendingFormat: @" - %@: %@, %@: %@",
|
||||
NSLocalizedString(@"DL", "Torrent -> status string"), [NSString stringForSpeed: [self downloadRate]],
|
||||
NSLocalizedString(@"UL", "Torrent -> status string"), [NSString stringForSpeed: [self uploadRate]]];
|
||||
@@ -1209,7 +1209,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
{
|
||||
NSString * string;
|
||||
|
||||
switch (fStat->status)
|
||||
switch (fStat->activity)
|
||||
{
|
||||
case TR_STATUS_STOPPED:
|
||||
if (fWaitToStart)
|
||||
@@ -1259,7 +1259,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
|
||||
- (NSString *) stateString
|
||||
{
|
||||
switch (fStat->status)
|
||||
switch (fStat->activity)
|
||||
{
|
||||
case TR_STATUS_STOPPED:
|
||||
return NSLocalizedString(@"Paused", "Torrent -> status string");
|
||||
@@ -1707,7 +1707,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
||||
fInfo = tr_torrentInfo(fHandle);
|
||||
}
|
||||
|
||||
tr_torrentSetStatusCallback(fHandle, completenessChangeCallback, self);
|
||||
tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self);
|
||||
|
||||
fNameString = [[NSString alloc] initWithUTF8String: fInfo->name];
|
||||
fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];
|
||||
|
||||
Reference in New Issue
Block a user