source: trunk/wx/filter.cc @ 4494

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

get the wx client compiling again, at least.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.4 KB
Line 
1/*
2 * Xmission - a cross-platform bittorrent client
3 * Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 * $Id: filter.cc 4494 2008-01-05 08:05:17Z charles $
19 */
20
21#include "foreach.h"
22#include "filter.h"
23
24int
25TorrentFilter :: GetFlags( const tr_torrent * tor )
26{
27    int flags = 0;
28    const tr_stat * s = tr_torrentStat( (tr_torrent*)tor );
29
30    switch( s->status )
31    {
32        case TR_STATUS_DOWNLOAD:
33            flags |= FLAG_LEECHING;
34            break;
35
36        case TR_STATUS_DONE:
37        case TR_STATUS_SEED:
38            flags |= FLAG_SEEDING;
39            break;
40
41        case TR_STATUS_STOPPED:
42        case TR_STATUS_CHECK:
43        case TR_STATUS_CHECK_WAIT:
44            break;
45    }
46
47    flags |= ( ( s->rateUpload + s->rateDownload ) > 0.01 )
48        ? FLAG_ACTIVE
49        : FLAG_IDLE;
50
51    flags |= s->leftUntilDone
52        ? FLAG_INCOMPLETE
53        : FLAG_COMPLETE;
54
55    flags |= FLAG_ALL;
56
57    return flags;
58}
59
60void
61TorrentFilter :: CountHits( const torrents_v & torrents,
62                            int              * counts )
63{
64    memset( counts, '\0', sizeof(int) * N_FILTERS );
65    foreach_const( torrents_v, torrents, it ) {
66        const int flags = GetFlags( *it );
67        if( flags & FLAG_ALL )        ++counts[ALL];
68        if( flags & FLAG_LEECHING )   ++counts[LEECHING];
69        if( flags & FLAG_SEEDING )    ++counts[SEEDING];
70        if( flags & FLAG_ACTIVE )     ++counts[ACTIVE];
71        if( flags & FLAG_IDLE )       ++counts[IDLE];
72        if( flags & FLAG_COMPLETE )   ++counts[COMPLETE];
73        if( flags & FLAG_INCOMPLETE ) ++counts[INCOMPLETE];
74    }
75}
76
77wxString
78TorrentFilter :: GetName( int show, int count )
79{
80    static const wxString names[N_FILTERS] = {
81        _("&All"),
82        _("&Complete"),
83        _("&Incomplete"),
84        _("&Seeding"),
85        _("&Leeching"),
86        _("Acti&ve"),
87        _("I&dle")
88    };
89
90    assert( 0<=show && show<N_FILTERS );
91
92    wxString xstr = names[show];
93    if( count )
94        xstr += wxString::Format(_T(" (%d)"), count );
95    return xstr;
96}
97
98void
99TorrentFilter :: RemoveFailures( int            show,
100                                 torrents_v  &  torrents )
101{
102    torrents_v tmp;
103
104    foreach_const( torrents_v, torrents, it ) {
105        const int flags = GetFlags( *it );
106        if(   ( ( show == ALL )        && ( flags & FLAG_ALL ) )
107           || ( ( show == LEECHING )   && ( flags & FLAG_LEECHING ) )
108           || ( ( show == SEEDING )    && ( flags & FLAG_SEEDING ) )
109           || ( ( show == ACTIVE )     && ( flags & FLAG_ACTIVE ) )
110           || ( ( show == IDLE )       && ( flags & FLAG_IDLE ) )
111           || ( ( show == COMPLETE )   && ( flags & FLAG_COMPLETE ) )
112           || ( ( show == INCOMPLETE ) && ( flags & FLAG_INCOMPLETE ) ) )
113            tmp.push_back( *it );
114    }
115
116    torrents.swap( tmp );
117}
Note: See TracBrowser for help on using the repository browser.