2007-07-23 21:01:26 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*/
|
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
#include "foreach.h"
|
2007-07-23 21:01:26 +00:00
|
|
|
#include "torrent-filter.h"
|
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
int
|
|
|
|
TorrentFilter :: GetFlags( const tr_torrent_t * tor )
|
2007-07-23 21:01:26 +00:00
|
|
|
{
|
2007-08-03 16:22:52 +00:00
|
|
|
int flags = 0;
|
2007-08-03 05:11:03 +00:00
|
|
|
const tr_stat_t * s = tr_torrentStat( (tr_torrent_t*)tor );
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2007-08-03 16:22:52 +00:00
|
|
|
switch( s->status )
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPING:
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
flags |= FLAG_STOPPED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
flags |= FLAG_LEECHING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DONE:
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
flags |= FLAG_SEEDING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags |= ( ( s->rateUpload + s->rateDownload ) > 0.01 )
|
|
|
|
? FLAG_ACTIVE
|
|
|
|
: FLAG_IDLE;
|
|
|
|
|
|
|
|
flags |= s->left
|
|
|
|
? FLAG_DONE
|
|
|
|
: FLAG_NOT_DONE;
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2007-08-03 16:22:52 +00:00
|
|
|
return flags;
|
2007-08-03 05:11:03 +00:00
|
|
|
}
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
void
|
|
|
|
TorrentFilter :: CountHits( const torrents_v & torrents,
|
|
|
|
int * counts )
|
|
|
|
{
|
|
|
|
memset( counts, '\0', sizeof(int) * N_FILTERS );
|
|
|
|
foreach_const( torrents_v, torrents, it ) {
|
|
|
|
const int flags = GetFlags( *it );
|
2007-08-03 16:22:52 +00:00
|
|
|
if( flags & FLAG_STOPPED ) ++counts[STOPPED];
|
|
|
|
if( flags & FLAG_LEECHING ) ++counts[LEECHING];
|
|
|
|
if( flags & FLAG_SEEDING ) ++counts[SEEDING];
|
|
|
|
if( flags & FLAG_ACTIVE ) ++counts[ACTIVE];
|
|
|
|
if( flags & FLAG_IDLE ) ++counts[IDLE];
|
|
|
|
if( flags & FLAG_DONE ) ++counts[DONE];
|
|
|
|
if( flags & FLAG_NOT_DONE ) ++counts[NOT_DONE];
|
2007-08-03 05:11:03 +00:00
|
|
|
}
|
2007-07-23 21:01:26 +00:00
|
|
|
}
|
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
wxString
|
|
|
|
TorrentFilter :: GetName( int show, int count )
|
2007-07-23 21:01:26 +00:00
|
|
|
{
|
2007-08-03 05:11:03 +00:00
|
|
|
wxString xstr;
|
|
|
|
|
|
|
|
switch( show )
|
|
|
|
{
|
2007-08-03 16:22:52 +00:00
|
|
|
case SEEDING: xstr = _("&Seeds"); break;
|
|
|
|
case LEECHING: xstr = _("&Leeches"); break;
|
|
|
|
case STOPPED: xstr = _("Sto&pped"); break;
|
|
|
|
case ACTIVE: xstr = _("&Active"); break;
|
|
|
|
case IDLE: xstr = _("&Idle"); break;
|
|
|
|
case DONE: xstr = _("&Done"); break;
|
|
|
|
case NOT_DONE: xstr = _("&Not Done"); break;
|
2007-08-03 05:11:03 +00:00
|
|
|
default: assert(0);
|
|
|
|
}
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
xstr += wxString::Format(_T(" (%d)"), count );
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
return xstr;
|
2007-07-23 21:01:26 +00:00
|
|
|
}
|
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
|
2007-07-23 21:01:26 +00:00
|
|
|
void
|
2007-08-03 05:11:03 +00:00
|
|
|
TorrentFilter :: RemoveFailures( int flags, torrents_v& torrents )
|
2007-07-23 21:01:26 +00:00
|
|
|
{
|
|
|
|
torrents_v tmp;
|
|
|
|
|
|
|
|
for( torrents_v::iterator it(torrents.begin()), end(torrents.end()); it!=end; ++it )
|
2007-08-03 05:11:03 +00:00
|
|
|
if( flags & GetFlags ( *it ) )
|
2007-07-23 21:01:26 +00:00
|
|
|
tmp.push_back( *it );
|
|
|
|
|
|
|
|
torrents.swap( tmp );
|
|
|
|
}
|