torrent filters work now... we finally have a working feature! ;)
This commit is contained in:
parent
d07439f793
commit
243772f194
|
@ -301,8 +301,8 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor,
|
|||
// if the torrent's in the list already, update that row.
|
||||
// otherwise, add a new row.
|
||||
if( row < 0 ) {
|
||||
str2int_t::const_iterator it = myHashToRow.find( info->hashString );
|
||||
if( it != myHashToRow.end() ) {
|
||||
str2int_t::const_iterator it = myHashToItem.find( info->hashString );
|
||||
if( it != myHashToItem.end() ) {
|
||||
row = it->second;
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor,
|
|||
else {
|
||||
row = InsertItem( GetItemCount(), xstr );
|
||||
col = 1;
|
||||
myHashToRow[info->hashString] = row;
|
||||
myHashToItem[info->hashString] = row;
|
||||
SetItemData( row, myTorrents_index );
|
||||
}
|
||||
}
|
||||
|
@ -479,7 +479,7 @@ TorrentListCtrl :: Resort( )
|
|||
const tr_info_t* info = tr_torrentInfo( myTorrents[idx] );
|
||||
tmp[info->hashString] = i;
|
||||
}
|
||||
myHashToRow.swap( tmp );
|
||||
myHashToItem.swap( tmp );
|
||||
uglyHack = NULL;
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,7 @@ void
|
|||
TorrentListCtrl :: Repopulate ()
|
||||
{
|
||||
DeleteAllItems();
|
||||
myHashToRow.clear ();
|
||||
myHashToItem.clear ();
|
||||
|
||||
const int_v cols = getTorrentColumns( myConfig );
|
||||
int i = 0;
|
||||
|
@ -519,7 +519,7 @@ void
|
|||
TorrentListCtrl :: Rebuild()
|
||||
{
|
||||
ClearAll( );
|
||||
myHashToRow.clear ();
|
||||
myHashToItem.clear ();
|
||||
|
||||
int i = 0;
|
||||
const int_v cols = getTorrentColumns( myConfig );
|
||||
|
@ -557,11 +557,56 @@ TorrentListCtrl :: Rebuild()
|
|||
Repopulate ();
|
||||
}
|
||||
|
||||
typedef std::set<tr_torrent_t*> torrent_set;
|
||||
|
||||
void
|
||||
TorrentListCtrl :: Add( const torrents_t& add )
|
||||
TorrentListCtrl :: Assign( const torrents_t& torrents )
|
||||
{
|
||||
myTorrents.insert( myTorrents.end(), add.begin(), add.end() );
|
||||
Repopulate ();
|
||||
torrent_set prev, cur, removed;
|
||||
torrents_v added;
|
||||
prev.insert( myTorrents.begin(), myTorrents.end() );
|
||||
cur.insert( torrents.begin(), torrents.end() );
|
||||
std::set_difference (prev.begin(), prev.end(), cur.begin(), cur.end(), inserter(removed, removed.begin()));
|
||||
std::set_difference (cur.begin(), cur.end(), prev.begin(), prev.end(), inserter(added, added.begin()));
|
||||
Remove( removed );
|
||||
Add( added );
|
||||
Refresh ();
|
||||
}
|
||||
|
||||
void
|
||||
TorrentListCtrl :: Add( const torrents_v& add )
|
||||
{
|
||||
const int_v cols = getTorrentColumns( myConfig );
|
||||
int i = myTorrents.size();
|
||||
myTorrents.insert( myTorrents.end(), add.begin(), add.end() );
|
||||
for( torrents_v::const_iterator it(add.begin()), end(add.end()); it!=end; ++it )
|
||||
RefreshTorrent( *it, i++, cols );
|
||||
Resort( );
|
||||
}
|
||||
|
||||
void
|
||||
TorrentListCtrl :: Remove( const torrent_set& remove )
|
||||
{
|
||||
torrents_v vtmp;
|
||||
str2int_t htmp;
|
||||
|
||||
for( int item=0; item<GetItemCount(); )
|
||||
{
|
||||
tr_torrent_t * tor = myTorrents[GetItemData(item)];
|
||||
const tr_info_t* info = tr_torrentInfo( tor );
|
||||
|
||||
if( remove.count( tor ) )
|
||||
{
|
||||
DeleteItem( item );
|
||||
continue;
|
||||
}
|
||||
|
||||
vtmp.push_back( tor );
|
||||
SetItemData( item, vtmp.size()-1 );
|
||||
htmp[ info->hashString ] = item;
|
||||
++item;
|
||||
}
|
||||
|
||||
myHashToItem.swap( htmp );
|
||||
myTorrents.swap( vtmp );
|
||||
}
|
||||
|
|
|
@ -76,18 +76,20 @@ class TorrentListCtrl: public wxListCtrl
|
|||
void Refresh ();
|
||||
|
||||
public:
|
||||
typedef std::vector<tr_torrent_t*> torrents_t;
|
||||
void Add( const torrents_t& add );
|
||||
typedef std::vector<tr_torrent_t*> torrents_v;
|
||||
void Add( const torrents_v& torrents );
|
||||
void Assign( const torrents_v& torrents );
|
||||
|
||||
private:
|
||||
void Sort( int column );
|
||||
void Resort( );
|
||||
void RefreshTorrent( tr_torrent_t*, int, const std::vector<int>& );
|
||||
void Remove( const std::set<tr_torrent_t*>& );
|
||||
static int Compare( long, long, long );
|
||||
|
||||
/** torrent hash -> the torrent's row in myTorrentList */
|
||||
typedef std::map<std::string,int> str2int_t;
|
||||
str2int_t myHashToRow;
|
||||
str2int_t myHashToItem;
|
||||
|
||||
private:
|
||||
void OnSort( wxListEvent& );
|
||||
|
@ -97,7 +99,7 @@ class TorrentListCtrl: public wxListCtrl
|
|||
private:
|
||||
tr_handle_t * myHandle;
|
||||
wxConfig * myConfig;
|
||||
torrents_t myTorrents;
|
||||
torrents_v myTorrents;
|
||||
int prevSortCol;
|
||||
|
||||
private:
|
||||
|
|
|
@ -51,8 +51,6 @@ class MyApp : public wxApp
|
|||
virtual bool OnInit();
|
||||
};
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
namespace
|
||||
{
|
||||
tr_handle_t * handle = NULL;
|
||||
|
@ -71,6 +69,7 @@ public:
|
|||
void OnAbout( wxCommandEvent& );
|
||||
void OnOpen( wxCommandEvent& );
|
||||
void OnTimer( wxTimerEvent& );
|
||||
void OnItemSelected( wxListEvent& );
|
||||
|
||||
private:
|
||||
void RefreshFilterCounts( );
|
||||
|
@ -86,6 +85,9 @@ private:
|
|||
wxIcon * myLogoIcon;
|
||||
wxIcon * myTrayLogo;
|
||||
torrents_v myTorrents;
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -99,9 +101,16 @@ enum
|
|||
ID_SHOW_DEBUG_WINDOW,
|
||||
ID_ABOUT,
|
||||
ID_Pulse,
|
||||
ID_Filter,
|
||||
N_IDS
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_LIST_ITEM_SELECTED( ID_Filter, MyFrame::OnItemSelected )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
IMPLEMENT_APP(MyApp)
|
||||
|
||||
void MyFrame :: OnOpen( wxCommandEvent& event )
|
||||
{
|
||||
const wxString key = _T("prev-directory");
|
||||
|
@ -201,6 +210,15 @@ MyFrame :: RefreshFilterCounts( )
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
MyFrame :: OnItemSelected( wxListEvent& event )
|
||||
{
|
||||
const int item = event.GetIndex ();
|
||||
torrents_v tmp( myTorrents );
|
||||
TorrentFilter :: RemoveFailures( item, tmp );
|
||||
myTorrentList->Assign( tmp );
|
||||
}
|
||||
|
||||
void
|
||||
MyFrame :: OnTimer(wxTimerEvent& event)
|
||||
{
|
||||
|
@ -310,7 +328,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size):
|
|||
|
||||
/* Filters */
|
||||
|
||||
myFilters = new wxListCtrl( row1, wxID_ANY, wxDefaultPosition, wxSize(120,-1),
|
||||
myFilters = new wxListCtrl( row1, ID_Filter, wxDefaultPosition, wxSize(120,-1),
|
||||
wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_NO_HEADER );
|
||||
myFilters->InsertColumn( wxLIST_FORMAT_LEFT, _("Filters"), wxLIST_FORMAT_LEFT, 120 );
|
||||
for( int i=0; i<TorrentFilter::N_FILTERS; ++i )
|
||||
|
@ -367,6 +385,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size):
|
|||
myTorrents.insert( myTorrents.end(), torrents, torrents+count );
|
||||
myTorrentList->Add( myTorrents );
|
||||
tr_free( torrents );
|
||||
|
||||
wxTimerEvent dummy;
|
||||
OnTimer( dummy );
|
||||
}
|
||||
|
||||
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
|
|
Loading…
Reference in New Issue