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 | |
---|
75 | void saveSettings() |
---|
76 | { |
---|
77 | GetListViewDetails(); |
---|
78 | save_to_ini(); |
---|
79 | } |
---|
80 | |
---|
81 | bool SubclassWindow(HWND hwnd) |
---|
82 | { |
---|
83 | if(!listClass::SubclassWindow(hwnd)) |
---|
84 | return false; |
---|
85 | |
---|
86 | InitialSetup(); |
---|
87 | |
---|
88 | std::vector<wstring> names; |
---|
89 | wstring column_names = hal::app().res_wstr(LISTVIEW_ID_COLUMNNAMES); |
---|
90 | |
---|
91 | // "Peer;Country;Download;Upload;Type;Client,Status" |
---|
92 | boost::split(names, column_names, boost::is_any_of(L";")); |
---|
93 | |
---|
94 | array<int, 7> widths = {100,20,70,70,70,100,200}; |
---|
95 | array<int, 7> order = {0,1,2,3,4,5,6}; |
---|
96 | array<bool, 7> visible = {true,true,true,true,true,true,true}; |
---|
97 | |
---|
98 | for (int i=0, e=7; i < e; ++i) |
---|
99 | { |
---|
100 | AddColumn(names[i].c_str(), i, visible[i], widths[i]); |
---|
101 | } |
---|
102 | |
---|
103 | load_from_ini(); |
---|
104 | |
---|
105 | SetColumnSortType(2, WTL::LVCOLSORT_CUSTOM, new ColumnAdapters::SpeedDown()); |
---|
106 | SetColumnSortType(3, WTL::LVCOLSORT_CUSTOM, new ColumnAdapters::SpeedUp()); |
---|
107 | |
---|
108 | return true; |
---|
109 | } |
---|
110 | |
---|
111 | void OnDestroy() |
---|
112 | { |
---|
113 | saveSettings(); |
---|
114 | } |
---|
115 | |
---|
116 | friend class boost::serialization::access; |
---|
117 | template<class Archive> |
---|
118 | void serialize(Archive& ar, const unsigned int version) |
---|
119 | { |
---|
120 | ar & boost::serialization::make_nvp("listview", |
---|
121 | boost::serialization::base_object<listClass>(*this)); |
---|
122 | } |
---|
123 | |
---|
124 | pD CustomItemConversion(LVCompareParam* param, int iSortCol) |
---|
125 | { |
---|
126 | return peerDetails_[param->dwItemData]; |
---|
127 | } |
---|
128 | |
---|
129 | void uiUpdate(const hal::torrent_details_manager& tD); |
---|
130 | |
---|
131 | private: |
---|
132 | hal::PeerDetails peerDetails_; |
---|
133 | }; |
---|
134 | |
---|
135 | class AdvPeerDialog : |
---|
136 | public CHalTabPageImpl<AdvPeerDialog>, |
---|
137 | public CHaliteDialogBase<AdvPeerDialog>, |
---|
138 | public WTL::CDialogResize<AdvPeerDialog> |
---|
139 | { |
---|
140 | protected: |
---|
141 | typedef AdvPeerDialog thisClass; |
---|
142 | typedef CHalTabPageImpl<thisClass> baseClass; |
---|
143 | typedef WTL::CDialogResize<thisClass> resizeClass; |
---|
144 | typedef CHaliteDialogBase<AdvPeerDialog> dialogBaseClass; |
---|
145 | |
---|
146 | public: |
---|
147 | enum { IDD = HAL_ADVPEER }; |
---|
148 | |
---|
149 | AdvPeerDialog(HaliteWindow& halWindow) : |
---|
150 | dialogBaseClass(halWindow) |
---|
151 | {} |
---|
152 | |
---|
153 | BOOL PreTranslateMessage(MSG* pMsg) |
---|
154 | { |
---|
155 | return this->IsDialogMessage(pMsg); |
---|
156 | } |
---|
157 | |
---|
158 | BEGIN_MSG_MAP_EX(thisClass) |
---|
159 | MSG_WM_INITDIALOG(OnInitDialog) |
---|
160 | MSG_WM_CLOSE(OnClose) |
---|
161 | |
---|
162 | if (uMsg == WM_FORWARDMSG) |
---|
163 | if (PreTranslateMessage((LPMSG)lParam)) return TRUE; |
---|
164 | |
---|
165 | CHAIN_MSG_MAP(dialogBaseClass) |
---|
166 | CHAIN_MSG_MAP(resizeClass) |
---|
167 | CHAIN_MSG_MAP(baseClass) |
---|
168 | REFLECT_NOTIFICATIONS() |
---|
169 | END_MSG_MAP() |
---|
170 | |
---|
171 | BEGIN_DLGRESIZE_MAP(thisClass) |
---|
172 | DLGRESIZE_CONTROL(HAL_PEERLIST, DLSZ_SIZE_X|DLSZ_SIZE_Y) |
---|
173 | END_DLGRESIZE_MAP() |
---|
174 | |
---|
175 | LRESULT OnInitDialog(HWND, LPARAM); |
---|
176 | void OnClose(); |
---|
177 | |
---|
178 | void uiUpdate(const hal::torrent_details_manager& tD); |
---|
179 | |
---|
180 | protected: |
---|
181 | PeerListView peerList_; |
---|
182 | }; |
---|