2007-07-23 15:20:47 +00:00
|
|
|
/*
|
2007-08-14 13:53:03 +00:00
|
|
|
* Xmission - a cross-platform bittorrent client
|
|
|
|
* Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
2007-07-23 15:20:47 +00:00
|
|
|
*
|
2007-08-14 13:53:03 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2007-08-18 17:19:49 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
2007-07-23 15:20:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __XMISSION_TORRENT_LIST_H__
|
|
|
|
#define __XMISSION_TORRENT_LIST_H__
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <wx/listctrl.h>
|
|
|
|
#include <wx/config.h>
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
|
|
|
|
class TorrentListCtrl: public wxListCtrl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TorrentListCtrl( tr_handle_t * handle,
|
|
|
|
wxConfig * config,
|
|
|
|
wxWindow * parent,
|
|
|
|
const wxPoint & pos = wxDefaultPosition,
|
|
|
|
const wxSize & size = wxDefaultSize );
|
|
|
|
virtual ~TorrentListCtrl();
|
|
|
|
|
2007-07-23 21:01:26 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum ShowMode
|
|
|
|
{
|
|
|
|
SHOW_ALL,
|
|
|
|
SHOW_DOWNLOADING,
|
|
|
|
SHOW_UPLOADING,
|
|
|
|
SHOW_COMPLETE,
|
|
|
|
SHOW_INCOMPLETE,
|
|
|
|
SHOW_ACTIVE,
|
|
|
|
SHOW_INACTIVE,
|
|
|
|
N_FILTERS
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetShowMode( ShowMode );
|
|
|
|
|
|
|
|
int GetShowModeCounts( ShowMode ) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
struct Listener
|
|
|
|
{
|
|
|
|
Listener() {}
|
|
|
|
|
|
|
|
virtual ~Listener() {}
|
|
|
|
|
|
|
|
virtual void OnTorrentListSelectionChanged(
|
|
|
|
TorrentListCtrl*,
|
2007-09-20 19:47:19 +00:00
|
|
|
const std::set<tr_torrent*>& ) = 0;
|
2007-07-23 21:01:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::set<Listener*> listeners_t;
|
|
|
|
listeners_t myListeners;
|
2007-09-20 19:47:19 +00:00
|
|
|
void fire_selection_changed( const std::set<tr_torrent*>& t ) {
|
2007-07-23 21:01:26 +00:00
|
|
|
for( listeners_t::iterator it(myListeners.begin()), end(myListeners.end()); it!=end; )
|
|
|
|
(*it++)->OnTorrentListSelectionChanged( this, t );
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
void AddListener( Listener* l ) { myListeners.insert(l); }
|
|
|
|
void RemoveListener( Listener* l ) { myListeners.erase(l); }
|
|
|
|
|
2007-07-23 15:20:47 +00:00
|
|
|
public:
|
|
|
|
void Rebuild ();
|
|
|
|
void Repopulate ();
|
|
|
|
void Refresh ();
|
2007-07-27 23:09:09 +00:00
|
|
|
void SelectAll ();
|
|
|
|
void DeselectAll ();
|
2007-07-23 15:20:47 +00:00
|
|
|
|
|
|
|
public:
|
2007-09-20 19:47:19 +00:00
|
|
|
typedef std::vector<tr_torrent*> torrents_v;
|
2007-07-23 23:59:13 +00:00
|
|
|
void Assign( const torrents_v& torrents );
|
2007-07-23 15:20:47 +00:00
|
|
|
|
|
|
|
private:
|
2007-08-03 20:46:02 +00:00
|
|
|
void Add( const torrents_v& torrents );
|
2007-07-23 15:20:47 +00:00
|
|
|
void Sort( int column );
|
|
|
|
void Resort( );
|
2007-09-20 19:47:19 +00:00
|
|
|
void RefreshTorrent( tr_torrent*, int, const std::vector<int>& );
|
|
|
|
void Remove( const std::set<tr_torrent*>& );
|
2007-08-02 21:58:34 +00:00
|
|
|
static int wxCALLBACK Compare( long, long, long );
|
2007-07-23 15:20:47 +00:00
|
|
|
|
|
|
|
/** torrent hash -> the torrent's row in myTorrentList */
|
|
|
|
typedef std::map<std::string,int> str2int_t;
|
2007-07-23 23:59:13 +00:00
|
|
|
str2int_t myHashToItem;
|
2007-07-23 15:20:47 +00:00
|
|
|
|
2007-08-03 20:46:02 +00:00
|
|
|
private:
|
|
|
|
void SetCell( int item, int col, const wxString& xstr );
|
|
|
|
|
2007-07-26 01:25:36 +00:00
|
|
|
private:
|
|
|
|
struct TorStat {
|
|
|
|
time_t time;
|
2007-09-20 19:47:19 +00:00
|
|
|
const tr_stat * stat;
|
2007-07-26 01:25:36 +00:00
|
|
|
TorStat(): time(0), stat(0) {}
|
|
|
|
};
|
|
|
|
typedef std::map<std::string,TorStat> hash2stat_t;
|
|
|
|
hash2stat_t myHashToStat;
|
2007-09-20 19:47:19 +00:00
|
|
|
const tr_stat* getStat( tr_torrent* );
|
2007-07-26 01:25:36 +00:00
|
|
|
|
2007-07-23 21:01:26 +00:00
|
|
|
private:
|
|
|
|
void OnSort( wxListEvent& );
|
|
|
|
void OnItemSelected( wxListEvent& );
|
|
|
|
void OnItemDeselected( wxListEvent& );
|
2007-08-23 19:21:42 +00:00
|
|
|
bool IsSorted( ) const;
|
2007-08-03 20:46:02 +00:00
|
|
|
|
2007-07-23 15:20:47 +00:00
|
|
|
private:
|
2007-09-20 19:47:19 +00:00
|
|
|
tr_handle * myHandle;
|
2007-07-23 15:20:47 +00:00
|
|
|
wxConfig * myConfig;
|
2007-07-23 23:59:13 +00:00
|
|
|
torrents_v myTorrents;
|
2007-07-23 15:20:47 +00:00
|
|
|
int prevSortCol;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|