Changeset 2913
- Timestamp:
- Aug 23, 2007, 7:02:33 PM (15 years ago)
- Location:
- trunk/wx
- Files:
-
- 2 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/wx/Makefile.am
r2762 r2913 12 12 Xmission_SOURCES = \ 13 13 speed-stats.cc \ 14 torrent-filter.cc \14 filter.cc \ 15 15 torrent-list.cc \ 16 16 torrent-stats.cc \ -
trunk/wx/filter.cc
r2911 r2913 20 20 21 21 #include "foreach.h" 22 #include " torrent-filter.h"22 #include "filter.h" 23 23 24 24 int … … 30 30 switch( s->status ) 31 31 { 32 case TR_STATUS_STOPPING:33 case TR_STATUS_STOPPED:34 case TR_STATUS_CHECK:35 case TR_STATUS_CHECK_WAIT:36 flags |= FLAG_STOPPED;37 break;38 39 32 case TR_STATUS_DOWNLOAD: 40 33 flags |= FLAG_LEECHING; … … 45 38 flags |= FLAG_SEEDING; 46 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; 47 46 } 48 47 … … 52 51 53 52 flags |= s->left 54 ? FLAG_DONE 55 : FLAG_NOT_DONE; 53 ? FLAG_INCOMPLETE 54 : FLAG_COMPLETE; 55 56 flags |= FLAG_ALL; 56 57 57 58 return flags; … … 65 66 foreach_const( torrents_v, torrents, it ) { 66 67 const int flags = GetFlags( *it ); 67 if( flags & FLAG_ STOPPED ) ++counts[STOPPED];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_ DONE ) ++counts[DONE];73 if( flags & FLAG_ NOT_DONE ) ++counts[NOT_DONE];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]; 74 75 } 75 76 } … … 78 79 TorrentFilter :: GetName( int show, int count ) 79 80 { 80 wxString xstr; 81 static const wxString names[N_FILTERS] = { 82 _("&All"), 83 _("&Complete"), 84 _("&Incomplete"), 85 _("&Seeding"), 86 _("&Leeching"), 87 _("Acti&ve"), 88 _("I&dle") 89 }; 81 90 82 switch( show ) 83 { 84 case SEEDING: xstr = _("&Seeds"); break; 85 case LEECHING: xstr = _("&Leeches"); break; 86 case STOPPED: xstr = _("Sto&pped"); break; 87 case ACTIVE: xstr = _("&Active"); break; 88 case IDLE: xstr = _("&Idle"); break; 89 case DONE: xstr = _("&Done"); break; 90 case NOT_DONE: xstr = _("&Not Done"); break; 91 default: assert(0); 92 } 91 assert( 0<=show && show<N_FILTERS ); 93 92 94 xstr += wxString::Format(_T(" (%d)"), count ); 95 93 wxString xstr = names[show]; 94 if( count ) 95 xstr += wxString::Format(_T(" (%d)"), count ); 96 96 return xstr; 97 97 } 98 98 99 100 99 void 101 TorrentFilter :: RemoveFailures( int flags, torrents_v& torrents ) 100 TorrentFilter :: RemoveFailures( int show, 101 torrents_v & torrents ) 102 102 { 103 103 torrents_v tmp; 104 104 105 for( torrents_v::iterator it(torrents.begin()), end(torrents.end()); it!=end; ++it ) 106 if( flags & GetFlags ( *it ) ) 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 ) ) ) 107 114 tmp.push_back( *it ); 115 } 108 116 109 117 torrents.swap( tmp ); -
trunk/wx/filter.h
r2911 r2913 28 28 class TorrentFilter 29 29 { 30 private: 31 32 enum ShowFlags 33 { 34 FLAG_ALL = (1<<0), 35 FLAG_COMPLETE = (1<<1), 36 FLAG_INCOMPLETE = (1<<2), 37 FLAG_SEEDING = (1<<3), 38 FLAG_LEECHING = (1<<4), 39 FLAG_ACTIVE = (1<<5), 40 FLAG_IDLE = (1<<6) 41 }; 42 30 43 public: 31 44 32 45 typedef std::vector<tr_torrent_t*> torrents_v; 33 46 34 enum ShowFlags35 {36 FLAG_SEEDING = (1<<0),37 FLAG_LEECHING = (1<<1),38 FLAG_STOPPED = (1<<2),39 40 FLAG_ACTIVE = (1<<3),41 FLAG_IDLE = (1<<4),42 43 FLAG_DONE = (1<<5),44 FLAG_NOT_DONE = (1<<6)45 };46 47 47 enum Show { 48 SEEDING, LEECHING, STOPPED, 48 ALL, 49 COMPLETE, INCOMPLETE, 50 SEEDING, LEECHING, 49 51 ACTIVE, IDLE, 50 DONE, NOT_DONE,51 52 N_FILTERS 52 53 }; -
trunk/wx/xmission.cc
r2912 r2913 65 65 #include "foreach.h" 66 66 #include "speed-stats.h" 67 #include " torrent-filter.h"67 #include "filter.h" 68 68 #include "torrent-list.h" 69 69 #include "torrent-stats.h" … … 169 169 void OnDeselectAllUpdate( wxUpdateUIEvent& ); 170 170 171 void OnFilter Toggled( wxCommandEvent& );171 void OnFilterChanged( wxCommandEvent& ); 172 172 173 173 void OnPulse( wxTimerEvent& ); … … 193 193 torrents_v myTorrents; 194 194 torrents_v mySelectedTorrents; 195 int myFilter Flags;195 int myFilter; 196 196 std::string mySavePath; 197 197 time_t myExitTime; 198 wxToggleButton * myFilterToggles[TorrentFilter::N_FILTERS];198 wxToggleButton* myFilterButtons[TorrentFilter::N_FILTERS]; 199 199 200 200 private: … … 213 213 214 214 BEGIN_EVENT_TABLE(MyFrame, wxFrame) 215 EVT_COMMAND_RANGE( ID_Filter, ID_Filter+TorrentFilter::N_FILTERS, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, MyFrame::OnFilter Toggled )215 EVT_COMMAND_RANGE( ID_Filter, ID_Filter+TorrentFilter::N_FILTERS, wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, MyFrame::OnFilterChanged ) 216 216 EVT_MENU ( wxID_ABOUT, MyFrame::OnAbout ) 217 217 EVT_TIMER ( ID_Pulse, MyFrame::OnPulse ) … … 236 236 237 237 void 238 MyFrame :: OnFilterToggled( wxCommandEvent& e ) 239 { 240 const int index = e.GetId() - ID_Filter; 241 int flags = 1<<index; 242 const bool active = myFilterToggles[index]->GetValue ( ); 243 if( active ) 244 myFilterFlags |= flags; 245 else 246 myFilterFlags &= ~flags; 247 ApplyCurrentFilter ( ); 238 MyFrame :: OnFilterChanged( wxCommandEvent& e ) 239 { 240 static bool ignore = false; 241 242 if( !ignore ) 243 { 244 myFilter = e.GetId() - ID_Filter; 245 std::cerr << " OnFilterChanged, myFilter is now " << myFilter << std::endl; 246 ApplyCurrentFilter ( ); 247 248 ignore = true; 249 for( int i=0; i<TorrentFilter::N_FILTERS; ++i ) 250 myFilterButtons[i]->SetValue( i==myFilter ); 251 ignore = false; 252 } 248 253 } 249 254 … … 367 372 filename.c_str(), 368 373 mySavePath.c_str(), 369 0, NULL );374 TR_FLAG_SAVE, NULL ); 370 375 if( tor ) 371 376 myTorrents.push_back( tor ); … … 422 427 TorrentFilter::CountHits( myTorrents, hits ); 423 428 for( int i=0; i<TorrentFilter::N_FILTERS; ++i ) 424 myFilter Toggles[i]->SetLabel( TorrentFilter::GetName( i, hits[i] ) );429 myFilterButtons[i]->SetLabel( TorrentFilter::GetName( i, hits[i] ) ); 425 430 } 426 431 … … 429 434 { 430 435 torrents_v tmp( myTorrents ); 431 TorrentFilter :: RemoveFailures( myFilter Flags, tmp );436 TorrentFilter :: RemoveFailures( myFilter, tmp ); 432 437 myTorrentList->Assign( tmp ); 433 438 } … … 495 500 myTrayIconIcon( systray_xpm ), 496 501 mySpeedStats( 0 ), 497 myFilter Flags( ~0),502 myFilter( TorrentFilter::ALL ), 498 503 myExitTime( 0 ) 499 504 { … … 612 617 wxPanel * panel_1 = new wxPanel( hsplit, wxID_ANY ); 613 618 614 wxBoxSizer * buttonSizer = new wxBoxSizer( wxHORIZONTAL ); 615 616 wxStaticText * text = new wxStaticText( panel_1, wxID_ANY, _("Show:") ); 617 buttonSizer->Add( text, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 3 ); 618 619 int rightButtonSpacing[TorrentFilter::N_FILTERS] = { 0, 0, 10, 0, 10, 0, 0 }; 619 wxBoxSizer * buttonSizer = new wxBoxSizer( wxVERTICAL ); 620 620 621 for( int i=0; i<TorrentFilter::N_FILTERS; ++i ) { 621 wxToggleButton * tb = new wxToggleButton( panel_1, ID_Filter+i, TorrentFilter::GetName(i) ); 622 tb->SetValue( true ); 623 myFilterToggles[i] = tb; 624 //buttonSizer->Add( tb, 0, wxRIGHT, rightButtonSpacing[i] ); 625 buttonSizer->Add( tb, 1, wxEXPAND|wxRIGHT, rightButtonSpacing[i] ); 622 wxToggleButton * b = new wxToggleButton( panel_1, ID_Filter+i, TorrentFilter::GetName(i), wxDefaultPosition, wxDefaultSize, (i==0)?wxRB_GROUP:0 ); 623 b->SetValue( i==0 ); 624 myFilterButtons[i] = b; 625 buttonSizer->Add( b, 1, wxGROW, 0 ); 626 626 } 627 627 … … 629 629 myTorrentList->AddListener( this ); 630 630 631 wxBoxSizer * panelSizer = new wxBoxSizer( wxVERTICAL ); 632 panelSizer->Add( new wxStaticLine( panel_1 ), 0, wxEXPAND, 0 ); 633 panelSizer->Add( buttonSizer, 0, 0, 0 ); 634 panelSizer->Add( myTorrentList, 1, wxEXPAND, 0 ); 631 wxBoxSizer * panelSizer = new wxBoxSizer( wxHORIZONTAL ); 632 panelSizer->Add( buttonSizer, 0, wxALL, 5 ); 633 panelSizer->Add( myTorrentList, 1, wxGROW|wxALL, 5 ); 635 634 636 635 panel_1->SetSizer( panelSizer );
Note: See TracChangeset
for help on using the changeset viewer.