1 | |
---|
2 | // Copyright Eóin O'Callaghan 2006 - 2008. |
---|
3 | // Distributed under the Boost Software License, Version 1.0. |
---|
4 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #include "stdAfx.hpp" |
---|
10 | #include "Halite.hpp" |
---|
11 | |
---|
12 | #include "DdxEx.hpp" |
---|
13 | #include "global/string_conv.hpp" |
---|
14 | |
---|
15 | #include "../HaliteTabPage.hpp" |
---|
16 | #include "../HaliteDialogBase.hpp" |
---|
17 | #include "../HaliteListManager.hpp" |
---|
18 | |
---|
19 | class PeerListView : |
---|
20 | public CHaliteSortListViewCtrl<PeerListView, const hal::PeerDetail>, |
---|
21 | public hal::IniBase<PeerListView>, |
---|
22 | private boost::noncopyable |
---|
23 | { |
---|
24 | protected: |
---|
25 | typedef PeerListView thisClass; |
---|
26 | typedef hal::IniBase<thisClass> iniClass; |
---|
27 | typedef CHaliteSortListViewCtrl<thisClass, const hal::PeerDetail> listClass; |
---|
28 | typedef const hal::PeerDetail pD; |
---|
29 | |
---|
30 | friend class listClass; |
---|
31 | |
---|
32 | struct ColumnAdapters |
---|
33 | { |
---|
34 | |
---|
35 | typedef listClass::ColumnAdapter ColAdapter_t; |
---|
36 | |
---|
37 | struct SpeedDown : public ColAdapter_t |
---|
38 | { |
---|
39 | virtual int compare(pD& l, pD& r) { return hal::compare(l.speed.first, r.speed.first); } |
---|
40 | virtual std::wstring print(pD& p) |
---|
41 | { |
---|
42 | return (hal::wform(L"%1$.2fkb/s") % (p.speed.first/1024)).str(); |
---|
43 | } |
---|
44 | }; |
---|
45 | |
---|
46 | struct SpeedUp : public ColAdapter_t |
---|
47 | { |
---|
48 | virtual int compare(pD& l, pD& r) { return hal::compare(l.speed.second, r.speed.second); } |
---|
49 | virtual std::wstring print(pD& p) |
---|
50 | { |
---|
51 | return (hal::wform(L"%1$.2fkb/s") % (p.speed.second/1024)).str(); |
---|
52 | } |
---|
53 | }; |
---|
54 | |
---|
55 | }; |
---|
56 | |
---|
57 | public: |
---|
58 | enum { |
---|
59 | LISTVIEW_ID_MENU = 0, |
---|
60 | LISTVIEW_ID_COLUMNNAMES = HAL_DIALOGPEER_LISTVIEW_ADV, |
---|
61 | LISTVIEW_ID_COLUMNWIDTHS = 0 |
---|
62 | }; |
---|
63 | |
---|
64 | BEGIN_MSG_MAP_EX(thisClass) |
---|
65 | MSG_WM_DESTROY(OnDestroy) |
---|
66 | |
---|
67 | CHAIN_MSG_MAP(listClass) |
---|
68 | DEFAULT_REFLECTION_HANDLER() |
---|
69 | END_MSG_MAP() |
---|
70 | |
---|
71 | thisClass() : |
---|
72 | iniClass("listviews/advPeers", "PeerListView") |
---|
73 | { |
---|
74 | std::vector<wstring> names; |
---|
75 | wstring column_names = hal::app().res_wstr(LISTVIEW_ID_COLUMNNAMES); |
---|
76 | |
---|
77 | // "Peer;Country;Download;Upload;Type;Client,Status" |
---|
78 | boost::split(names, column_names, boost::is_any_of(L";")); |
---|
79 | |
---|
80 | array<int, 7> widths = {100,20,70,70,70,100,200}; |
---|
81 | array<int, 7> order = {0,1,2,3,4,5,6}; |
---|
82 | array<bool, 7> visible = {true,true,true,true,true,true,true}; |
---|
83 | |
---|
84 | SetDefaults(names, widths, order, visible, true); |
---|
85 | load_from_ini(); |
---|
86 | } |
---|
87 | |
---|
88 | void saveSettings() |
---|
89 | { |
---|
90 | GetListViewDetails(); |
---|
91 | save_to_ini(); |
---|
92 | } |
---|
93 | |
---|
94 | bool SubclassWindow(HWND hwnd) |
---|
95 | { |
---|
96 | if(!listClass::SubclassWindow(hwnd)) |
---|
97 | return false; |
---|
98 | |
---|
99 | ApplyDetails(); |
---|
100 | |
---|
101 | SetColumnSortType(2, LVCOLSORT_CUSTOM, new ColumnAdapters::SpeedDown()); |
---|
102 | SetColumnSortType(3, LVCOLSORT_CUSTOM, new ColumnAdapters::SpeedUp()); |
---|
103 | |
---|
104 | return true; |
---|
105 | } |
---|
106 | |
---|
107 | void OnDestroy() |
---|
108 | { |
---|
109 | saveSettings(); |
---|
110 | } |
---|
111 | |
---|
112 | friend class boost::serialization::access; |
---|
113 | template<class Archive> |
---|
114 | void serialize(Archive& ar, const unsigned int version) |
---|
115 | { |
---|
116 | ar & boost::serialization::make_nvp("listview", |
---|
117 | boost::serialization::base_object<listClass>(*this)); |
---|
118 | } |
---|
119 | |
---|
120 | pD CustomItemConversion(LVCompareParam* param, int iSortCol) |
---|
121 | { |
---|
122 | return peerDetails_[param->dwItemData]; |
---|
123 | } |
---|
124 | |
---|
125 | void uiUpdate(const hal::TorrentDetails& tD); |
---|
126 | |
---|
127 | private: |
---|
128 | hal::PeerDetails peerDetails_; |
---|
129 | }; |
---|
130 | |
---|
131 | class AdvPeerDialog : |
---|
132 | public CHalTabPageImpl<AdvPeerDialog>, |
---|
133 | public CHaliteDialogBase<AdvPeerDialog>, |
---|
134 | public CDialogResize<AdvPeerDialog> |
---|
135 | { |
---|
136 | protected: |
---|
137 | typedef AdvPeerDialog thisClass; |
---|
138 | typedef CHalTabPageImpl<thisClass> baseClass; |
---|
139 | typedef CDialogResize<thisClass> resizeClass; |
---|
140 | typedef CHaliteDialogBase<AdvPeerDialog> dialogBaseClass; |
---|
141 | |
---|
142 | public: |
---|
143 | enum { IDD = IDD_ADVPEER }; |
---|
144 | |
---|
145 | AdvPeerDialog(HaliteWindow& halWindow) : |
---|
146 | dialogBaseClass(halWindow) |
---|
147 | {} |
---|
148 | |
---|
149 | BOOL PreTranslateMessage(MSG* pMsg) |
---|
150 | { |
---|
151 | return this->IsDialogMessage(pMsg); |
---|
152 | } |
---|
153 | |
---|
154 | BEGIN_MSG_MAP_EX(thisClass) |
---|
155 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
156 | MSG_WM_CLOSE(OnClose) |
---|
157 | |
---|
158 | if (uMsg == WM_FORWARDMSG) |
---|
159 | if (PreTranslateMessage((LPMSG)lParam)) return TRUE; |
---|
160 | |
---|
161 | CHAIN_MSG_MAP(dialogBaseClass) |
---|
162 | CHAIN_MSG_MAP(resizeClass) |
---|
163 | CHAIN_MSG_MAP(baseClass) |
---|
164 | REFLECT_NOTIFICATIONS() |
---|
165 | END_MSG_MAP() |
---|
166 | |
---|
167 | BEGIN_DLGRESIZE_MAP(thisClass) |
---|
168 | DLGRESIZE_CONTROL(IDC_PEERLIST, DLSZ_SIZE_X|DLSZ_SIZE_Y) |
---|
169 | END_DLGRESIZE_MAP() |
---|
170 | |
---|
171 | LRESULT OnInitDialog(HWND, LPARAM); |
---|
172 | void OnClose(); |
---|
173 | |
---|
174 | void uiUpdate(const hal::TorrentDetails& tD); |
---|
175 | |
---|
176 | protected: |
---|
177 | PeerListView peerList_; |
---|
178 | }; |
---|