~ubuntu-branches/ubuntu/hardy/transmission/hardy-updates

« back to all changes in this revision

Viewing changes to wx/filter.cc

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2007-10-26 16:02:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20071026160239-2c0agn7q1ken0xsp
Tags: upstream-0.90.dfsg
ImportĀ upstreamĀ versionĀ 0.90.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 3178 2007-09-26 01:55:04Z charles $
 
19
 */
 
20
 
 
21
#include "foreach.h"
 
22
#include "filter.h"
 
23
 
 
24
int
 
25
TorrentFilter :: 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_STOPPING:
 
42
        case TR_STATUS_STOPPED:
 
43
        case TR_STATUS_CHECK:
 
44
        case TR_STATUS_CHECK_WAIT:
 
45
            break;
 
46
    }
 
47
 
 
48
    flags |= ( ( s->rateUpload + s->rateDownload ) > 0.01 )
 
49
        ? FLAG_ACTIVE
 
50
        : FLAG_IDLE;
 
51
 
 
52
    flags |= s->leftUntilDone
 
53
        ? FLAG_INCOMPLETE
 
54
        : FLAG_COMPLETE;
 
55
 
 
56
    flags |= FLAG_ALL;
 
57
 
 
58
    return flags;
 
59
}
 
60
 
 
61
void
 
62
TorrentFilter :: CountHits( const torrents_v & torrents,
 
63
                            int              * counts )
 
64
{
 
65
    memset( counts, '\0', sizeof(int) * N_FILTERS );
 
66
    foreach_const( torrents_v, torrents, it ) {
 
67
        const int flags = GetFlags( *it );
 
68
        if( flags & FLAG_ALL )        ++counts[ALL];
 
69
        if( flags & FLAG_LEECHING )   ++counts[LEECHING];
 
70
        if( flags & FLAG_SEEDING )    ++counts[SEEDING];
 
71
        if( flags & FLAG_ACTIVE )     ++counts[ACTIVE];
 
72
        if( flags & FLAG_IDLE )       ++counts[IDLE];
 
73
        if( flags & FLAG_COMPLETE )   ++counts[COMPLETE];
 
74
        if( flags & FLAG_INCOMPLETE ) ++counts[INCOMPLETE];
 
75
    }
 
76
}
 
77
 
 
78
wxString
 
79
TorrentFilter :: GetName( int show, int count )
 
80
{
 
81
    static const wxString names[N_FILTERS] = {
 
82
        _("&All"),
 
83
        _("&Complete"),
 
84
        _("&Incomplete"),
 
85
        _("&Seeding"),
 
86
        _("&Leeching"),
 
87
        _("Acti&ve"),
 
88
        _("I&dle")
 
89
    };
 
90
 
 
91
    assert( 0<=show && show<N_FILTERS );
 
92
 
 
93
    wxString xstr = names[show];
 
94
    if( count )
 
95
        xstr += wxString::Format(_T(" (%d)"), count );
 
96
    return xstr;
 
97
}
 
98
 
 
99
void
 
100
TorrentFilter :: RemoveFailures( int            show,
 
101
                                 torrents_v  &  torrents )
 
102
{
 
103
    torrents_v tmp;
 
104
 
 
105
    foreach_const( torrents_v, torrents, it ) {
 
106
        const int flags = GetFlags( *it );
 
107
        if(   ( ( show == ALL )        && ( flags & FLAG_ALL ) )
 
108
           || ( ( show == LEECHING )   && ( flags & FLAG_LEECHING ) )
 
109
           || ( ( show == SEEDING )    && ( flags & FLAG_SEEDING ) )
 
110
           || ( ( show == ACTIVE )     && ( flags & FLAG_ACTIVE ) )
 
111
           || ( ( show == IDLE )       && ( flags & FLAG_IDLE ) )
 
112
           || ( ( show == COMPLETE )   && ( flags & FLAG_COMPLETE ) )
 
113
           || ( ( show == INCOMPLETE ) && ( flags & FLAG_INCOMPLETE ) ) )
 
114
            tmp.push_back( *it );
 
115
    }
 
116
 
 
117
    torrents.swap( tmp );
 
118
}