1 | /* |
---|
2 | * Xmission - a cross-platform bittorrent client |
---|
3 | * Copyright (C) 2007 Charles Kerr <charles@transmissionbt.com> |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; version 2 of the License. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * $Id: torrent-list.h 7404 2008-12-16 00:20:44Z charles $ |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef __XMISSION_TORRENT_LIST_H__ |
---|
22 | #define __XMISSION_TORRENT_LIST_H__ |
---|
23 | |
---|
24 | #include <set> |
---|
25 | #include <map> |
---|
26 | #include <vector> |
---|
27 | #include <wx/listctrl.h> |
---|
28 | #include <wx/config.h> |
---|
29 | #include <libtransmission/transmission.h> |
---|
30 | |
---|
31 | class TorrentListCtrl: public wxListCtrl |
---|
32 | { |
---|
33 | public: |
---|
34 | TorrentListCtrl( tr_handle * handle, |
---|
35 | wxConfig * config, |
---|
36 | wxWindow * parent, |
---|
37 | const wxPoint & pos = wxDefaultPosition, |
---|
38 | const wxSize & size = wxDefaultSize ); |
---|
39 | virtual ~TorrentListCtrl(); |
---|
40 | |
---|
41 | public: |
---|
42 | |
---|
43 | enum ShowMode |
---|
44 | { |
---|
45 | SHOW_ALL, |
---|
46 | SHOW_DOWNLOADING, |
---|
47 | SHOW_UPLOADING, |
---|
48 | SHOW_COMPLETE, |
---|
49 | SHOW_INCOMPLETE, |
---|
50 | SHOW_ACTIVE, |
---|
51 | SHOW_INACTIVE, |
---|
52 | N_FILTERS |
---|
53 | }; |
---|
54 | |
---|
55 | void SetShowMode( ShowMode ); |
---|
56 | |
---|
57 | int GetShowModeCounts( ShowMode ) const; |
---|
58 | |
---|
59 | public: |
---|
60 | |
---|
61 | struct Listener |
---|
62 | { |
---|
63 | Listener() {} |
---|
64 | |
---|
65 | virtual ~Listener() {} |
---|
66 | |
---|
67 | virtual void OnTorrentListSelectionChanged( |
---|
68 | TorrentListCtrl*, |
---|
69 | const std::set<tr_torrent*>& ) = 0; |
---|
70 | }; |
---|
71 | |
---|
72 | private: |
---|
73 | typedef std::set<Listener*> listeners_t; |
---|
74 | listeners_t myListeners; |
---|
75 | void fire_selection_changed( const std::set<tr_torrent*>& t ) { |
---|
76 | for( listeners_t::iterator it(myListeners.begin()), end(myListeners.end()); it!=end; ) |
---|
77 | (*it++)->OnTorrentListSelectionChanged( this, t ); |
---|
78 | } |
---|
79 | public: |
---|
80 | void AddListener( Listener* l ) { myListeners.insert(l); } |
---|
81 | void RemoveListener( Listener* l ) { myListeners.erase(l); } |
---|
82 | |
---|
83 | public: |
---|
84 | void Rebuild (); |
---|
85 | void Repopulate (); |
---|
86 | void Refresh (); |
---|
87 | void SelectAll (); |
---|
88 | void DeselectAll (); |
---|
89 | |
---|
90 | public: |
---|
91 | typedef std::vector<tr_torrent*> torrents_v; |
---|
92 | void Assign( const torrents_v& torrents ); |
---|
93 | |
---|
94 | private: |
---|
95 | void Add( const torrents_v& torrents ); |
---|
96 | void Sort( int column ); |
---|
97 | void Resort( ); |
---|
98 | void RefreshTorrent( tr_torrent*, int, const std::vector<int>& ); |
---|
99 | void Remove( const std::set<tr_torrent*>& ); |
---|
100 | static int wxCALLBACK Compare( long, long, long ); |
---|
101 | |
---|
102 | /** torrent hash -> the torrent's row in myTorrentList */ |
---|
103 | typedef std::map<std::string,int> str2int_t; |
---|
104 | str2int_t myHashToItem; |
---|
105 | |
---|
106 | private: |
---|
107 | void SetCell( int item, int col, const wxString& xstr ); |
---|
108 | |
---|
109 | private: |
---|
110 | struct TorStat { |
---|
111 | time_t time; |
---|
112 | const tr_stat * stat; |
---|
113 | TorStat(): time(0), stat(0) {} |
---|
114 | }; |
---|
115 | typedef std::map<std::string,TorStat> hash2stat_t; |
---|
116 | hash2stat_t myHashToStat; |
---|
117 | const tr_stat* getStat( tr_torrent* ); |
---|
118 | |
---|
119 | private: |
---|
120 | void OnSort( wxListEvent& ); |
---|
121 | void OnItemSelected( wxListEvent& ); |
---|
122 | void OnItemDeselected( wxListEvent& ); |
---|
123 | bool IsSorted( ) const; |
---|
124 | |
---|
125 | private: |
---|
126 | tr_handle * myHandle; |
---|
127 | wxConfig * myConfig; |
---|
128 | torrents_v myTorrents; |
---|
129 | int prevSortCol; |
---|
130 | |
---|
131 | private: |
---|
132 | DECLARE_EVENT_TABLE() |
---|
133 | }; |
---|
134 | |
---|
135 | |
---|
136 | #endif |
---|