1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 08:13:27 +00:00

* simplify the filters a bit.

* fix a bug in filtering complete/incomplete.
* when adding torrents, save a copy in transmission's torrents directory.
This commit is contained in:
Charles Kerr 2007-08-23 19:02:33 +00:00
parent 3ce8d7bfd6
commit 2bc52d3bfe
4 changed files with 91 additions and 83 deletions

View file

@ -11,7 +11,7 @@ bin_PROGRAMS = Xmission
Xmission_SOURCES = \
speed-stats.cc \
torrent-filter.cc \
filter.cc \
torrent-list.cc \
torrent-stats.cc \
xmission.cc

View file

@ -19,7 +19,7 @@
*/
#include "foreach.h"
#include "torrent-filter.h"
#include "filter.h"
int
TorrentFilter :: GetFlags( const tr_torrent_t * tor )
@ -29,13 +29,6 @@ TorrentFilter :: GetFlags( const tr_torrent_t * tor )
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;
@ -44,6 +37,12 @@ TorrentFilter :: GetFlags( const tr_torrent_t * tor )
case TR_STATUS_SEED:
flags |= FLAG_SEEDING;
break;
case TR_STATUS_STOPPING:
case TR_STATUS_STOPPED:
case TR_STATUS_CHECK:
case TR_STATUS_CHECK_WAIT:
break;
}
flags |= ( ( s->rateUpload + s->rateDownload ) > 0.01 )
@ -51,8 +50,10 @@ TorrentFilter :: GetFlags( const tr_torrent_t * tor )
: FLAG_IDLE;
flags |= s->left
? FLAG_DONE
: FLAG_NOT_DONE;
? FLAG_INCOMPLETE
: FLAG_COMPLETE;
flags |= FLAG_ALL;
return flags;
}
@ -64,47 +65,54 @@ TorrentFilter :: CountHits( const torrents_v & torrents,
memset( counts, '\0', sizeof(int) * N_FILTERS );
foreach_const( torrents_v, torrents, it ) {
const int flags = GetFlags( *it );
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];
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];
}
}
wxString
TorrentFilter :: GetName( int show, int count )
{
wxString xstr;
static const wxString names[N_FILTERS] = {
_("&All"),
_("&Complete"),
_("&Incomplete"),
_("&Seeding"),
_("&Leeching"),
_("Acti&ve"),
_("I&dle")
};
switch( show )
{
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;
default: assert(0);
}
xstr += wxString::Format(_T(" (%d)"), count );
assert( 0<=show && show<N_FILTERS );
wxString xstr = names[show];
if( count )
xstr += wxString::Format(_T(" (%d)"), count );
return xstr;
}
void
TorrentFilter :: RemoveFailures( int flags, torrents_v& torrents )
TorrentFilter :: RemoveFailures( int show,
torrents_v & torrents )
{
torrents_v tmp;
for( torrents_v::iterator it(torrents.begin()), end(torrents.end()); it!=end; ++it )
if( flags & GetFlags ( *it ) )
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 ) ) )
tmp.push_back( *it );
}
torrents.swap( tmp );
}

View file

@ -27,27 +27,28 @@
class TorrentFilter
{
private:
enum ShowFlags
{
FLAG_ALL = (1<<0),
FLAG_COMPLETE = (1<<1),
FLAG_INCOMPLETE = (1<<2),
FLAG_SEEDING = (1<<3),
FLAG_LEECHING = (1<<4),
FLAG_ACTIVE = (1<<5),
FLAG_IDLE = (1<<6)
};
public:
typedef std::vector<tr_torrent_t*> torrents_v;
enum ShowFlags
{
FLAG_SEEDING = (1<<0),
FLAG_LEECHING = (1<<1),
FLAG_STOPPED = (1<<2),
FLAG_ACTIVE = (1<<3),
FLAG_IDLE = (1<<4),
FLAG_DONE = (1<<5),
FLAG_NOT_DONE = (1<<6)
};
enum Show {
SEEDING, LEECHING, STOPPED,
ALL,
COMPLETE, INCOMPLETE,
SEEDING, LEECHING,
ACTIVE, IDLE,
DONE, NOT_DONE,
N_FILTERS
};

View file

@ -64,7 +64,7 @@ extern "C"
#include "foreach.h"
#include "speed-stats.h"
#include "torrent-filter.h"
#include "filter.h"
#include "torrent-list.h"
#include "torrent-stats.h"
@ -168,7 +168,7 @@ public:
void OnDeselectAll( wxCommandEvent& );
void OnDeselectAllUpdate( wxUpdateUIEvent& );
void OnFilterToggled( wxCommandEvent& );
void OnFilterChanged( wxCommandEvent& );
void OnPulse( wxTimerEvent& );
@ -192,10 +192,10 @@ private:
SpeedStats * mySpeedStats;
torrents_v myTorrents;
torrents_v mySelectedTorrents;
int myFilterFlags;
int myFilter;
std::string mySavePath;
time_t myExitTime;
wxToggleButton * myFilterToggles[TorrentFilter::N_FILTERS];
wxToggleButton* myFilterButtons[TorrentFilter::N_FILTERS];
private:
DECLARE_EVENT_TABLE()
@ -212,7 +212,7 @@ enum
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_COMMAND_RANGE( ID_Filter, ID_Filter+TorrentFilter::N_FILTERS, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, MyFrame::OnFilterToggled )
EVT_COMMAND_RANGE( ID_Filter, ID_Filter+TorrentFilter::N_FILTERS, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, MyFrame::OnFilterChanged )
EVT_MENU ( wxID_ABOUT, MyFrame::OnAbout )
EVT_TIMER ( ID_Pulse, MyFrame::OnPulse )
EVT_MENU ( wxID_EXIT, MyFrame::OnExit )
@ -235,16 +235,21 @@ IMPLEMENT_APP(MyApp)
void
MyFrame :: OnFilterToggled( wxCommandEvent& e )
MyFrame :: OnFilterChanged( wxCommandEvent& e )
{
const int index = e.GetId() - ID_Filter;
int flags = 1<<index;
const bool active = myFilterToggles[index]->GetValue ( );
if( active )
myFilterFlags |= flags;
else
myFilterFlags &= ~flags;
ApplyCurrentFilter ( );
static bool ignore = false;
if( !ignore )
{
myFilter = e.GetId() - ID_Filter;
std::cerr << " OnFilterChanged, myFilter is now " << myFilter << std::endl;
ApplyCurrentFilter ( );
ignore = true;
for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
myFilterButtons[i]->SetValue( i==myFilter );
ignore = false;
}
}
void
@ -366,7 +371,7 @@ void MyFrame :: OnOpen( wxCommandEvent& WXUNUSED(event) )
tr_torrent_t * tor = tr_torrentInit( handle,
filename.c_str(),
mySavePath.c_str(),
0, NULL );
TR_FLAG_SAVE, NULL );
if( tor )
myTorrents.push_back( tor );
}
@ -421,14 +426,14 @@ MyFrame :: RefreshFilterCounts( )
int hits[ TorrentFilter :: N_FILTERS ];
TorrentFilter::CountHits( myTorrents, hits );
for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
myFilterToggles[i]->SetLabel( TorrentFilter::GetName( i, hits[i] ) );
myFilterButtons[i]->SetLabel( TorrentFilter::GetName( i, hits[i] ) );
}
void
MyFrame :: ApplyCurrentFilter( )
{
torrents_v tmp( myTorrents );
TorrentFilter :: RemoveFailures( myFilterFlags, tmp );
TorrentFilter :: RemoveFailures( myFilter, tmp );
myTorrentList->Assign( tmp );
}
@ -494,7 +499,7 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
myLogoIcon( transmission_xpm ),
myTrayIconIcon( systray_xpm ),
mySpeedStats( 0 ),
myFilterFlags( ~0 ),
myFilter( TorrentFilter::ALL ),
myExitTime( 0 )
{
myTrayIcon = new wxTaskBarIcon;
@ -611,27 +616,21 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
wxPanel * panel_1 = new wxPanel( hsplit, wxID_ANY );
wxBoxSizer * buttonSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer * buttonSizer = new wxBoxSizer( wxVERTICAL );
wxStaticText * text = new wxStaticText( panel_1, wxID_ANY, _("Show:") );
buttonSizer->Add( text, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 3 );
int rightButtonSpacing[TorrentFilter::N_FILTERS] = { 0, 0, 10, 0, 10, 0, 0 };
for( int i=0; i<TorrentFilter::N_FILTERS; ++i ) {
wxToggleButton * tb = new wxToggleButton( panel_1, ID_Filter+i, TorrentFilter::GetName(i) );
tb->SetValue( true );
myFilterToggles[i] = tb;
//buttonSizer->Add( tb, 0, wxRIGHT, rightButtonSpacing[i] );
buttonSizer->Add( tb, 1, wxEXPAND|wxRIGHT, rightButtonSpacing[i] );
wxToggleButton * b = new wxToggleButton( panel_1, ID_Filter+i, TorrentFilter::GetName(i), wxDefaultPosition, wxDefaultSize, (i==0)?wxRB_GROUP:0 );
b->SetValue( i==0 );
myFilterButtons[i] = b;
buttonSizer->Add( b, 1, wxGROW, 0 );
}
myTorrentList = new TorrentListCtrl( handle, myConfig, panel_1 );
myTorrentList->AddListener( this );
wxBoxSizer * panelSizer = new wxBoxSizer( wxVERTICAL );
panelSizer->Add( new wxStaticLine( panel_1 ), 0, wxEXPAND, 0 );
panelSizer->Add( buttonSizer, 0, 0, 0 );
panelSizer->Add( myTorrentList, 1, wxEXPAND, 0 );
wxBoxSizer * panelSizer = new wxBoxSizer( wxHORIZONTAL );
panelSizer->Add( buttonSizer, 0, wxALL, 5 );
panelSizer->Add( myTorrentList, 1, wxGROW|wxALL, 5 );
panel_1->SetSizer( panelSizer );