(trunk) minor transmission.h API cleanup.

1. remove tr_sessionGetActiveTorrentCount()
2. make tr_sessionCountTorrents() package-visible instead of public.
3. make tr_torrentGetActivity() private instead of public.
This commit is contained in:
Charles Kerr
2010-04-29 23:08:11 +00:00
parent 31f4d24004
commit d384b38f07
8 changed files with 39 additions and 35 deletions

View File

@@ -339,9 +339,8 @@ refreshActions( struct cbdata * data )
} }
{ {
tr_session * session = tr_core_session( data->core ); const int total = tr_core_get_torrent_count( data->core );
const int active = tr_sessionGetActiveTorrentCount( session ); const int active = tr_core_get_active_torrent_count( data->core );
const int total = tr_sessionCountTorrents( session );
action_sensitize( "pause-all-torrents", active != 0 ); action_sensitize( "pause-all-torrents", active != 0 );
action_sensitize( "start-all-torrents", active != total ); action_sensitize( "start-all-torrents", active != total );
} }

View File

@@ -1417,15 +1417,9 @@ tr_core_set_hibernation_allowed( TrCore * core,
static void static void
maybeInhibitHibernation( TrCore * core ) maybeInhibitHibernation( TrCore * core )
{ {
gboolean inhibit = pref_flag_get( PREF_KEY_INHIBIT_HIBERNATION ); /* inhibit if it's enabled *AND* all the torrents are paused */
const gboolean inhibit = pref_flag_get( PREF_KEY_INHIBIT_HIBERNATION )
/* always allow hibernation when all the torrents are paused */ && ( tr_core_get_active_torrent_count( core ) == 0 );
if( inhibit ) {
tr_session * session = tr_core_session( core );
if( tr_sessionGetActiveTorrentCount( session ) == 0 )
inhibit = FALSE;
}
tr_core_set_hibernation_allowed( core, !inhibit ); tr_core_set_hibernation_allowed( core, !inhibit );
} }
@@ -1687,3 +1681,29 @@ tr_core_torrent_changed( TrCore * core, int id )
while( gtk_tree_model_iter_next( model, &iter ) ); while( gtk_tree_model_iter_next( model, &iter ) );
} }
int
tr_core_get_torrent_count( TrCore * core )
{
return gtk_tree_model_iter_n_children( tr_core_model( core ), NULL );
}
int
tr_core_get_active_torrent_count( TrCore * core )
{
GtkTreeIter iter;
GtkTreeModel * model = tr_core_model( core );
int activeCount = 0;
if( gtk_tree_model_get_iter_first( model, &iter ) ) do
{
int activity;
gtk_tree_model_get( model, &iter, MC_ACTIVITY, &activity, -1 );
if( activity != TR_STATUS_STOPPED )
++activeCount;
}
while( gtk_tree_model_iter_next( model, &iter ) );
return activeCount;
}

View File

@@ -99,6 +99,10 @@ GtkTreeModel * tr_core_model( TrCore * self );
tr_session * tr_core_session( TrCore * self ); tr_session * tr_core_session( TrCore * self );
int tr_core_get_active_torrent_count( TrCore * self );
int tr_core_get_torrent_count( TrCore * self );
/****** /******
******* *******
******/ ******/

View File

@@ -173,7 +173,7 @@ getTorrents( tr_session * session,
else /* all of them */ else /* all of them */
{ {
tr_torrent * tor = NULL; tr_torrent * tor = NULL;
const int n = tr_sessionCountTorrents( session ); const int n = tr_sessionCountTorrents( session );
torrents = tr_new0( tr_torrent *, n ); torrents = tr_new0( tr_torrent *, n );
while( ( tor = tr_torrentNext( session, tor ) ) ) while( ( tor = tr_torrentNext( session, tor ) ) )
torrents[torrentCount++] = tor; torrents[torrentCount++] = tor;

View File

@@ -2391,18 +2391,3 @@ tr_sessionSetProxyPassword( tr_session * session,
session->proxyPassword = tr_strdup( password ); session->proxyPassword = tr_strdup( password );
} }
} }
int
tr_sessionGetActiveTorrentCount( tr_session * session )
{
int ret = 0;
tr_torrent * tor = NULL;
assert( tr_isSession( session ) );
while(( tor = tr_torrentNext( session, tor )))
if( tr_torrentGetActivity( tor ) != TR_STATUS_STOPPED )
++ret;
return ret;
}

View File

@@ -199,6 +199,8 @@ const struct tr_address* tr_sessionGetPublicAddress( const tr_session *, int tr
struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * ); struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * );
int tr_sessionCountTorrents( const tr_session * session );
enum enum
{ {
SESSION_MAGIC_NUMBER = 3845, SESSION_MAGIC_NUMBER = 3845,

View File

@@ -635,8 +635,6 @@ tr_port_forwarding;
tr_port_forwarding tr_sessionGetPortForwarding( const tr_session * session ); tr_port_forwarding tr_sessionGetPortForwarding( const tr_session * session );
int tr_sessionCountTorrents( const tr_session * session );
typedef enum typedef enum
{ {
TR_CLIENT_TO_PEER = 0, TR_UP = 0, TR_CLIENT_TO_PEER = 0, TR_UP = 0,
@@ -744,8 +742,6 @@ tr_torrent ** tr_sessionLoadTorrents( tr_session * session,
tr_ctor * ctor, tr_ctor * ctor,
int * setmeCount ); int * setmeCount );
int tr_sessionGetActiveTorrentCount( tr_session * session );
/** @} */ /** @} */
/** /**
@@ -1649,8 +1645,6 @@ typedef enum
} }
tr_torrent_activity; tr_torrent_activity;
tr_torrent_activity tr_torrentGetActivity( tr_torrent * );
enum enum
{ {
TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */ TR_PEER_FROM_INCOMING = 0, /* connections made to the listening port */

View File

@@ -901,7 +901,7 @@ Session :: addTorrent( QString key, QString localPath )
if( !keyHandled ) { if( !keyHandled ) {
const QByteArray tmp = key.toUtf8(); const QByteArray tmp = key.toUtf8();
tr_bencDictAddRaw( args, "metainfo", tmp.constData(), tmp.length() ); tr_bencDictAddRaw( args, "metainfo", tmp.constData(), tmp.length() );
keyHandled; // treat it as base64 keyHandled = true; // treat it as base64
} }
exec( &top ); exec( &top );