2007-07-23 21:01:26 +00:00
|
|
|
/*
|
2007-08-14 13:53:03 +00:00
|
|
|
* Xmission - a cross-platform bittorrent client
|
2008-12-16 00:20:44 +00:00
|
|
|
* Copyright (C) 2007 Charles Kerr <charles@transmissionbt.com>
|
2007-07-23 21:01:26 +00:00
|
|
|
*
|
2007-08-14 13:53:03 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2007-08-18 17:19:49 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
2007-07-23 21:01:26 +00:00
|
|
|
*/
|
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
#include "foreach.h"
|
2007-08-23 19:02:33 +00:00
|
|
|
#include "filter.h"
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2007-08-03 05:11:03 +00:00
|
|
|
int
|
2007-09-20 19:47:19 +00:00
|
|
|
TorrentFilter :: GetFlags( const tr_torrent * tor )
|
2007-07-23 21:01:26 +00:00
|
|
|
{
|
2007-08-03 16:22:52 +00:00
|
|
|
int flags = 0;
|
2007-09-20 19:47:19 +00:00
|
|
|
const tr_stat * s = tr_torrentStat( (tr_torrent*)tor );
|
2007-07-23 21:01:26 +00:00
|
|
|
|
2008-12-21 20:02:21 +00:00
|
|
|
switch( s->activity )
|
2007-08-03 16:22:52 +00:00
|
|
|
{
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
flags |= FLAG_LEECHING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
flags |= FLAG_SEEDING;
|
|
|
|
break;
|
2007-08-23 19:02:33 +00:00
|
|
|
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
break;
|
2007-08-03 16:22:52 +00:00
|
|
|
}
|
|
|
|
|
2008-12-21 20:02:21 +00:00
|
|
|
flags |= ( ( s->pieceUploadSpeed + s->pieceDownloadSpeed ) > 0.01 )
|
2007-08-03 16:22:52 +00:00
|
|
|
? FLAG_ACTIVE
|
|
|
|
: FLAG_IDLE;
|
|
|
|
|
2007-09-26 01:55:04 +00:00
|
|
|
flags |= s->leftUntilDone
|
2007-08-23 19:02:33 +00:00
|
|
|
? FLAG_INCOMPLETE
|
|
|
|
: FLAG_COMPLETE;
|
|
|
|
|
|
|
|
flags |= FLAG_ALL;
|
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-23 19:02:33 +00:00
|
|
|
if( flags & FLAG_ALL ) ++counts[ALL];
|
|
|
|
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_COMPLETE ) ++counts[COMPLETE];
|
|
|
|
if( flags & FLAG_INCOMPLETE ) ++counts[INCOMPLETE];
|
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-23 19:02:33 +00:00
|
|
|
static const wxString names[N_FILTERS] = {
|
|
|
|
_("&All"),
|
|
|
|
_("&Complete"),
|
|
|
|
_("&Incomplete"),
|
|
|
|
_("&Seeding"),
|
|
|
|
_("&Leeching"),
|
|
|
|
_("Acti&ve"),
|
|
|
|
_("I&dle")
|
|
|
|
};
|
|
|
|
|
|
|
|
assert( 0<=show && show<N_FILTERS );
|
|
|
|
|
|
|
|
wxString xstr = names[show];
|
|
|
|
if( count )
|
|
|
|
xstr += wxString::Format(_T(" (%d)"), count );
|
2007-08-03 05:11:03 +00:00
|
|
|
return xstr;
|
2007-07-23 21:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-08-23 19:02:33 +00:00
|
|
|
TorrentFilter :: RemoveFailures( int show,
|
|
|
|
torrents_v & torrents )
|
2007-07-23 21:01:26 +00:00
|
|
|
{
|
|
|
|
torrents_v tmp;
|
|
|
|
|
2007-08-23 19:02:33 +00:00
|
|
|
foreach_const( torrents_v, torrents, it ) {
|
|
|
|
const int flags = GetFlags( *it );
|
|
|
|
if( ( ( show == ALL ) && ( flags & FLAG_ALL ) )
|
|
|
|
|| ( ( show == LEECHING ) && ( flags & FLAG_LEECHING ) )
|
|
|
|
|| ( ( show == SEEDING ) && ( flags & FLAG_SEEDING ) )
|
|
|
|
|| ( ( show == ACTIVE ) && ( flags & FLAG_ACTIVE ) )
|
|
|
|
|| ( ( show == IDLE ) && ( flags & FLAG_IDLE ) )
|
|
|
|
|| ( ( show == COMPLETE ) && ( flags & FLAG_COMPLETE ) )
|
|
|
|
|| ( ( show == INCOMPLETE ) && ( flags & FLAG_INCOMPLETE ) ) )
|
2007-07-23 21:01:26 +00:00
|
|
|
tmp.push_back( *it );
|
2007-08-23 19:02:33 +00:00
|
|
|
}
|
2007-07-23 21:01:26 +00:00
|
|
|
|
|
|
|
torrents.swap( tmp );
|
|
|
|
}
|