* 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:
parent
3ce8d7bfd6
commit
2bc52d3bfe
|
@ -11,7 +11,7 @@ bin_PROGRAMS = Xmission
|
||||||
|
|
||||||
Xmission_SOURCES = \
|
Xmission_SOURCES = \
|
||||||
speed-stats.cc \
|
speed-stats.cc \
|
||||||
torrent-filter.cc \
|
filter.cc \
|
||||||
torrent-list.cc \
|
torrent-list.cc \
|
||||||
torrent-stats.cc \
|
torrent-stats.cc \
|
||||||
xmission.cc
|
xmission.cc
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "foreach.h"
|
#include "foreach.h"
|
||||||
#include "torrent-filter.h"
|
#include "filter.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
TorrentFilter :: GetFlags( const tr_torrent_t * tor )
|
TorrentFilter :: GetFlags( const tr_torrent_t * tor )
|
||||||
|
@ -29,13 +29,6 @@ TorrentFilter :: GetFlags( const tr_torrent_t * tor )
|
||||||
|
|
||||||
switch( s->status )
|
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:
|
case TR_STATUS_DOWNLOAD:
|
||||||
flags |= FLAG_LEECHING;
|
flags |= FLAG_LEECHING;
|
||||||
break;
|
break;
|
||||||
|
@ -44,6 +37,12 @@ TorrentFilter :: GetFlags( const tr_torrent_t * tor )
|
||||||
case TR_STATUS_SEED:
|
case TR_STATUS_SEED:
|
||||||
flags |= FLAG_SEEDING;
|
flags |= FLAG_SEEDING;
|
||||||
break;
|
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 )
|
flags |= ( ( s->rateUpload + s->rateDownload ) > 0.01 )
|
||||||
|
@ -51,8 +50,10 @@ TorrentFilter :: GetFlags( const tr_torrent_t * tor )
|
||||||
: FLAG_IDLE;
|
: FLAG_IDLE;
|
||||||
|
|
||||||
flags |= s->left
|
flags |= s->left
|
||||||
? FLAG_DONE
|
? FLAG_INCOMPLETE
|
||||||
: FLAG_NOT_DONE;
|
: FLAG_COMPLETE;
|
||||||
|
|
||||||
|
flags |= FLAG_ALL;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
@ -64,47 +65,54 @@ TorrentFilter :: CountHits( const torrents_v & torrents,
|
||||||
memset( counts, '\0', sizeof(int) * N_FILTERS );
|
memset( counts, '\0', sizeof(int) * N_FILTERS );
|
||||||
foreach_const( torrents_v, torrents, it ) {
|
foreach_const( torrents_v, torrents, it ) {
|
||||||
const int flags = GetFlags( *it );
|
const int flags = GetFlags( *it );
|
||||||
if( flags & FLAG_STOPPED ) ++counts[STOPPED];
|
if( flags & FLAG_ALL ) ++counts[ALL];
|
||||||
if( flags & FLAG_LEECHING ) ++counts[LEECHING];
|
if( flags & FLAG_LEECHING ) ++counts[LEECHING];
|
||||||
if( flags & FLAG_SEEDING ) ++counts[SEEDING];
|
if( flags & FLAG_SEEDING ) ++counts[SEEDING];
|
||||||
if( flags & FLAG_ACTIVE ) ++counts[ACTIVE];
|
if( flags & FLAG_ACTIVE ) ++counts[ACTIVE];
|
||||||
if( flags & FLAG_IDLE ) ++counts[IDLE];
|
if( flags & FLAG_IDLE ) ++counts[IDLE];
|
||||||
if( flags & FLAG_DONE ) ++counts[DONE];
|
if( flags & FLAG_COMPLETE ) ++counts[COMPLETE];
|
||||||
if( flags & FLAG_NOT_DONE ) ++counts[NOT_DONE];
|
if( flags & FLAG_INCOMPLETE ) ++counts[INCOMPLETE];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString
|
wxString
|
||||||
TorrentFilter :: GetName( int show, int count )
|
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 )
|
assert( 0<=show && show<N_FILTERS );
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
wxString xstr = names[show];
|
||||||
|
if( count )
|
||||||
xstr += wxString::Format(_T(" (%d)"), count );
|
xstr += wxString::Format(_T(" (%d)"), count );
|
||||||
|
|
||||||
return xstr;
|
return xstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TorrentFilter :: RemoveFailures( int flags, torrents_v& torrents )
|
TorrentFilter :: RemoveFailures( int show,
|
||||||
|
torrents_v & torrents )
|
||||||
{
|
{
|
||||||
torrents_v tmp;
|
torrents_v tmp;
|
||||||
|
|
||||||
for( torrents_v::iterator it(torrents.begin()), end(torrents.end()); it!=end; ++it )
|
foreach_const( torrents_v, torrents, it ) {
|
||||||
if( flags & GetFlags ( *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 );
|
tmp.push_back( *it );
|
||||||
|
}
|
||||||
|
|
||||||
torrents.swap( tmp );
|
torrents.swap( tmp );
|
||||||
}
|
}
|
|
@ -27,27 +27,28 @@
|
||||||
|
|
||||||
class TorrentFilter
|
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:
|
public:
|
||||||
|
|
||||||
typedef std::vector<tr_torrent_t*> torrents_v;
|
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 {
|
enum Show {
|
||||||
SEEDING, LEECHING, STOPPED,
|
ALL,
|
||||||
|
COMPLETE, INCOMPLETE,
|
||||||
|
SEEDING, LEECHING,
|
||||||
ACTIVE, IDLE,
|
ACTIVE, IDLE,
|
||||||
DONE, NOT_DONE,
|
|
||||||
N_FILTERS
|
N_FILTERS
|
||||||
};
|
};
|
||||||
|
|
|
@ -64,7 +64,7 @@ extern "C"
|
||||||
|
|
||||||
#include "foreach.h"
|
#include "foreach.h"
|
||||||
#include "speed-stats.h"
|
#include "speed-stats.h"
|
||||||
#include "torrent-filter.h"
|
#include "filter.h"
|
||||||
#include "torrent-list.h"
|
#include "torrent-list.h"
|
||||||
#include "torrent-stats.h"
|
#include "torrent-stats.h"
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ public:
|
||||||
void OnDeselectAll( wxCommandEvent& );
|
void OnDeselectAll( wxCommandEvent& );
|
||||||
void OnDeselectAllUpdate( wxUpdateUIEvent& );
|
void OnDeselectAllUpdate( wxUpdateUIEvent& );
|
||||||
|
|
||||||
void OnFilterToggled( wxCommandEvent& );
|
void OnFilterChanged( wxCommandEvent& );
|
||||||
|
|
||||||
void OnPulse( wxTimerEvent& );
|
void OnPulse( wxTimerEvent& );
|
||||||
|
|
||||||
|
@ -192,10 +192,10 @@ private:
|
||||||
SpeedStats * mySpeedStats;
|
SpeedStats * mySpeedStats;
|
||||||
torrents_v myTorrents;
|
torrents_v myTorrents;
|
||||||
torrents_v mySelectedTorrents;
|
torrents_v mySelectedTorrents;
|
||||||
int myFilterFlags;
|
int myFilter;
|
||||||
std::string mySavePath;
|
std::string mySavePath;
|
||||||
time_t myExitTime;
|
time_t myExitTime;
|
||||||
wxToggleButton * myFilterToggles[TorrentFilter::N_FILTERS];
|
wxToggleButton* myFilterButtons[TorrentFilter::N_FILTERS];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
@ -212,7 +212,7 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
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_MENU ( wxID_ABOUT, MyFrame::OnAbout )
|
||||||
EVT_TIMER ( ID_Pulse, MyFrame::OnPulse )
|
EVT_TIMER ( ID_Pulse, MyFrame::OnPulse )
|
||||||
EVT_MENU ( wxID_EXIT, MyFrame::OnExit )
|
EVT_MENU ( wxID_EXIT, MyFrame::OnExit )
|
||||||
|
@ -235,16 +235,21 @@ IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MyFrame :: OnFilterToggled( wxCommandEvent& e )
|
MyFrame :: OnFilterChanged( wxCommandEvent& e )
|
||||||
{
|
{
|
||||||
const int index = e.GetId() - ID_Filter;
|
static bool ignore = false;
|
||||||
int flags = 1<<index;
|
|
||||||
const bool active = myFilterToggles[index]->GetValue ( );
|
if( !ignore )
|
||||||
if( active )
|
{
|
||||||
myFilterFlags |= flags;
|
myFilter = e.GetId() - ID_Filter;
|
||||||
else
|
std::cerr << " OnFilterChanged, myFilter is now " << myFilter << std::endl;
|
||||||
myFilterFlags &= ~flags;
|
|
||||||
ApplyCurrentFilter ( );
|
ApplyCurrentFilter ( );
|
||||||
|
|
||||||
|
ignore = true;
|
||||||
|
for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
|
||||||
|
myFilterButtons[i]->SetValue( i==myFilter );
|
||||||
|
ignore = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -366,7 +371,7 @@ void MyFrame :: OnOpen( wxCommandEvent& WXUNUSED(event) )
|
||||||
tr_torrent_t * tor = tr_torrentInit( handle,
|
tr_torrent_t * tor = tr_torrentInit( handle,
|
||||||
filename.c_str(),
|
filename.c_str(),
|
||||||
mySavePath.c_str(),
|
mySavePath.c_str(),
|
||||||
0, NULL );
|
TR_FLAG_SAVE, NULL );
|
||||||
if( tor )
|
if( tor )
|
||||||
myTorrents.push_back( tor );
|
myTorrents.push_back( tor );
|
||||||
}
|
}
|
||||||
|
@ -421,14 +426,14 @@ MyFrame :: RefreshFilterCounts( )
|
||||||
int hits[ TorrentFilter :: N_FILTERS ];
|
int hits[ TorrentFilter :: N_FILTERS ];
|
||||||
TorrentFilter::CountHits( myTorrents, hits );
|
TorrentFilter::CountHits( myTorrents, hits );
|
||||||
for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
|
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
|
void
|
||||||
MyFrame :: ApplyCurrentFilter( )
|
MyFrame :: ApplyCurrentFilter( )
|
||||||
{
|
{
|
||||||
torrents_v tmp( myTorrents );
|
torrents_v tmp( myTorrents );
|
||||||
TorrentFilter :: RemoveFailures( myFilterFlags, tmp );
|
TorrentFilter :: RemoveFailures( myFilter, tmp );
|
||||||
myTorrentList->Assign( tmp );
|
myTorrentList->Assign( tmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +499,7 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
|
||||||
myLogoIcon( transmission_xpm ),
|
myLogoIcon( transmission_xpm ),
|
||||||
myTrayIconIcon( systray_xpm ),
|
myTrayIconIcon( systray_xpm ),
|
||||||
mySpeedStats( 0 ),
|
mySpeedStats( 0 ),
|
||||||
myFilterFlags( ~0 ),
|
myFilter( TorrentFilter::ALL ),
|
||||||
myExitTime( 0 )
|
myExitTime( 0 )
|
||||||
{
|
{
|
||||||
myTrayIcon = new wxTaskBarIcon;
|
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 );
|
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 ) {
|
for( int i=0; i<TorrentFilter::N_FILTERS; ++i ) {
|
||||||
wxToggleButton * tb = new wxToggleButton( panel_1, ID_Filter+i, TorrentFilter::GetName(i) );
|
wxToggleButton * b = new wxToggleButton( panel_1, ID_Filter+i, TorrentFilter::GetName(i), wxDefaultPosition, wxDefaultSize, (i==0)?wxRB_GROUP:0 );
|
||||||
tb->SetValue( true );
|
b->SetValue( i==0 );
|
||||||
myFilterToggles[i] = tb;
|
myFilterButtons[i] = b;
|
||||||
//buttonSizer->Add( tb, 0, wxRIGHT, rightButtonSpacing[i] );
|
buttonSizer->Add( b, 1, wxGROW, 0 );
|
||||||
buttonSizer->Add( tb, 1, wxEXPAND|wxRIGHT, rightButtonSpacing[i] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
myTorrentList = new TorrentListCtrl( handle, myConfig, panel_1 );
|
myTorrentList = new TorrentListCtrl( handle, myConfig, panel_1 );
|
||||||
myTorrentList->AddListener( this );
|
myTorrentList->AddListener( this );
|
||||||
|
|
||||||
wxBoxSizer * panelSizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer * panelSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
panelSizer->Add( new wxStaticLine( panel_1 ), 0, wxEXPAND, 0 );
|
panelSizer->Add( buttonSizer, 0, wxALL, 5 );
|
||||||
panelSizer->Add( buttonSizer, 0, 0, 0 );
|
panelSizer->Add( myTorrentList, 1, wxGROW|wxALL, 5 );
|
||||||
panelSizer->Add( myTorrentList, 1, wxEXPAND, 0 );
|
|
||||||
|
|
||||||
panel_1->SetSizer( panelSizer );
|
panel_1->SetSizer( panelSizer );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue