source: trunk/wx/torrent-filter.cc @ 2469

Last change on this file since 2469 was 2469, checked in by charles, 15 years ago

torrent filter counts work now.

File size: 2.1 KB
Line 
1/*
2 * This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 */
10
11#include "torrent-filter.h"
12
13bool
14TorrentFilter :: Test( int show, tr_torrent_t * tor )
15{
16    if( show == SHOW_ALL )
17        return true;
18
19    const tr_stat_t * stat = tr_torrentStat( tor );
20
21    if( show == SHOW_DOWNLOADING )
22        return stat->status == TR_STATUS_DOWNLOAD;
23
24    if( show == SHOW_UPLOADING )
25        return stat->status == TR_STATUS_SEED;
26
27    if( show == SHOW_COMPLETE )
28        return stat->cpStatus != TR_CP_INCOMPLETE;
29
30    if( show == SHOW_INCOMPLETE )
31        return stat->cpStatus == TR_CP_INCOMPLETE;
32
33    if( show == SHOW_ACTIVE )
34        return ( stat->rateUpload + stat->rateDownload ) >= 0.01;
35
36    if( show == SHOW_INACTIVE )
37        return ( stat->rateUpload + stat->rateDownload ) < 0.01;
38
39    abort ();
40}
41
42int
43TorrentFilter :: CountHits ( int show, const torrents_v& torrents )
44{
45    int i = 0;
46
47    for( torrents_v::const_iterator it(torrents.begin()), end(torrents.end()); it!=end; ++it )
48        if( Test( show, *it ) )
49            ++i;
50
51    return i;
52}
53
54void
55TorrentFilter :: RemoveFailures( int show, torrents_v& torrents )
56{
57    torrents_v tmp;
58
59    for( torrents_v::iterator it(torrents.begin()), end(torrents.end()); it!=end; ++it )
60        if( Test( show, *it ) )
61            tmp.push_back( *it );
62
63    torrents.swap( tmp );
64}
65
66
67wxString
68TorrentFilter :: getFilterName( int show )
69{
70    switch( show )
71    {
72        case SHOW_ALL:         return _("All");
73        case SHOW_DOWNLOADING: return _("Downloading");
74        case SHOW_UPLOADING:   return _("Uploading");
75        case SHOW_COMPLETE:    return _("Complete");
76        case SHOW_INCOMPLETE:  return _("Incomplete");
77        case SHOW_ACTIVE:      return _("Active");
78        case SHOW_INACTIVE:    return _("Inactive");
79        default:               abort();
80    }
81
82    return _T(""); //notreached
83}
Note: See TracBrowser for help on using the repository browser.