From 2bc52d3bfec63bfec0a73b48275792e87b8d3c4c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 23 Aug 2007 19:02:33 +0000 Subject: [PATCH] * simplify the filters a bit. * fix a bug in filtering complete/incomplete. * when adding torrents, save a copy in transmission's torrents directory. --- wx/Makefile.am | 2 +- wx/{torrent-filter.cc => filter.cc} | 78 ++++++++++++++++------------- wx/{torrent-filter.h => filter.h} | 31 ++++++------ wx/xmission.cc | 63 ++++++++++++----------- 4 files changed, 91 insertions(+), 83 deletions(-) rename wx/{torrent-filter.cc => filter.cc} (55%) rename wx/{torrent-filter.h => filter.h} (81%) diff --git a/wx/Makefile.am b/wx/Makefile.am index 9dfcdc07c..0d8ef3e4e 100644 --- a/wx/Makefile.am +++ b/wx/Makefile.am @@ -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 diff --git a/wx/torrent-filter.cc b/wx/filter.cc similarity index 55% rename from wx/torrent-filter.cc rename to wx/filter.cc index 510bc761f..a3f6649e9 100644 --- a/wx/torrent-filter.cc +++ b/wx/filter.cc @@ -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 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 }; diff --git a/wx/xmission.cc b/wx/xmission.cc index 6a0f85fdf..59be850f6 100755 --- a/wx/xmission.cc +++ b/wx/xmission.cc @@ -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<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; iSetValue( 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; iSetLabel( 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; iSetValue( 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 );