1 | |
---|
2 | // Copyright Eóin O'Callaghan 2006 - 2007. |
---|
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 | #include "stdAfx.hpp" |
---|
8 | |
---|
9 | #include <algorithm> |
---|
10 | #include <boost/format.hpp> |
---|
11 | #include <boost/array.hpp> |
---|
12 | |
---|
13 | #include "../HaliteWindow.hpp" |
---|
14 | #include "../HaliteListViewCtrl.hpp" |
---|
15 | |
---|
16 | #include "Torrent.hpp" |
---|
17 | |
---|
18 | LRESULT AdvTorrentDialog::onInitDialog(HWND, LPARAM) |
---|
19 | { |
---|
20 | dialogBaseClass::InitializeHalDialogBase(); |
---|
21 | |
---|
22 | m_prog.Attach(GetDlgItem(TORRENTPROG)); |
---|
23 | m_prog.SetRange(0, 100); |
---|
24 | |
---|
25 | totalConnections_.Attach(GetDlgItem(IDC_EDITNCD)); |
---|
26 | uploadConnections_.Attach(GetDlgItem(IDC_EDITNCU)); |
---|
27 | downloadRate_.Attach(GetDlgItem(IDC_EDITTLD)); |
---|
28 | uploadRate_.Attach(GetDlgItem(IDC_EDITTLU)); |
---|
29 | ratio_.Attach(GetDlgItem(IDC_EDITRATIO)); |
---|
30 | |
---|
31 | totalConnections_ = -1; |
---|
32 | uploadConnections_ = -1; |
---|
33 | downloadRate_ = -1; |
---|
34 | uploadRate_ = -1; |
---|
35 | ratio_ = -1; |
---|
36 | |
---|
37 | DoDataExchange(false); |
---|
38 | return 0; |
---|
39 | } |
---|
40 | |
---|
41 | AdvTorrentDialog::CWindowMapStruct* AdvTorrentDialog::GetWindowMap() |
---|
42 | { |
---|
43 | #define TORRENT_LIMITS_LAYOUT \ |
---|
44 | WMB_HEAD(WMB_COL(_exp|20), WMB_COL(_exp|30), WMB_COL(_exp|20), WMB_COL(_exp|30)), \ |
---|
45 | WMB_ROW(10, IDC_TL, _r, _r, _r), \ |
---|
46 | WMB_ROW(11, IDC_TLD, IDC_EDITTLD, IDC_TLU, IDC_EDITTLU), \ |
---|
47 | WMB_ROW(10, IDC_NC, _r, _r, _r), \ |
---|
48 | WMB_ROW(11, IDC_NCD, IDC_EDITNCD, IDC_NCU, IDC_EDITNCU), \ |
---|
49 | WMB_ROW(11, IDC_RATIOESTATIC, _r, _r, IDC_EDITRATIO), \ |
---|
50 | WMB_END() |
---|
51 | |
---|
52 | #define TORRENT_STATUS_LAYOUT \ |
---|
53 | WMB_HEAD(WMB_COL(45), WMB_COLNOMIN(_exp|150), WMB_COL(_eq|0), WMB_COL(_exp|100)), \ |
---|
54 | WMB_ROW(10, IDC_NAME_STATUS_LABEL, IDC_NAME_STATUS, _r, _r), \ |
---|
55 | WMB_ROW(10, IDC_PEERS_LABEL, IDC_PEERS, IDC_SEEDS_LABEL, IDC_SEEDS), \ |
---|
56 | WMB_ROW(10, IDC_TRANSFERED_LABEL, IDC_TRANSFERED, IDC_OVERHEAD_LABEL, IDC_OVERHEAD), \ |
---|
57 | WMB_ROW(10, IDC_REMAINING_LABEL, IDC_REMAINING, IDC_ETA_LABEL, IDC_ETA), \ |
---|
58 | WMB_ROW(10, IDC_RATE_LABEL, IDC_RATE, IDC_RATIO_LABEL, IDC_RATIO), \ |
---|
59 | WMB_END() |
---|
60 | |
---|
61 | #define TORRENT_REANNOUNCE_LAYOUT \ |
---|
62 | WMB_HEAD(WMB_COL(50), WMB_COLNOMIN(_exp)), \ |
---|
63 | WMB_ROW(10, IDC_UPDATESTAT, IDC_UPDATE), \ |
---|
64 | WMB_END() |
---|
65 | |
---|
66 | BEGIN_WINDOW_MAP_INLINE(AdvTorrentDialog, 6, 6, 3, 3) |
---|
67 | WMB_HEAD(WMB_COL(_gap), WMB_COL(_exp), WMB_COL(120), WMB_COL(_gap)), |
---|
68 | WMB_ROW(_gap|3, IDC_GROUP_TORRENT, _r, _r, _r), |
---|
69 | WMB_ROW(_auto, _d, TORRENT_STATUS_LAYOUT, TORRENT_LIMITS_LAYOUT), |
---|
70 | WMB_ROW(_auto, _d, TORRENTPROG, _r), |
---|
71 | WMB_ROW(_gap, _d), |
---|
72 | WMB_ROW(_gap|3, IDC_GROUP_TRACKER, _r, _r, _r), |
---|
73 | WMB_ROW(_auto, _d, IDC_TRACKER, TORRENT_REANNOUNCE_LAYOUT), |
---|
74 | WMB_ROW(_gap, _d), |
---|
75 | WMB_END() |
---|
76 | END_WINDOW_MAP_INLINE() |
---|
77 | } |
---|
78 | |
---|
79 | void AdvTorrentDialog::onClose() |
---|
80 | { |
---|
81 | if(::IsWindow(m_hWnd)) |
---|
82 | { |
---|
83 | ::DestroyWindow(m_hWnd); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | LRESULT AdvTorrentDialog::OnHalEditChanged(UINT uMsg, WPARAM wParam, LPARAM lParam) |
---|
88 | { |
---|
89 | if (hal::bit::torrent t = hal::bittorrent().get(focusedTorrent())) |
---|
90 | { |
---|
91 | t.rate_limits = std::pair<float, float>(downloadRate_, uploadRate_); |
---|
92 | t.connection_limits = std::pair<int, int>(totalConnections_, uploadConnections_); |
---|
93 | t.ratio = ratio_; |
---|
94 | } |
---|
95 | |
---|
96 | return 0; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | void AdvTorrentDialog::focusChanged(const hal::TorrentDetail_ptr pT) |
---|
101 | { |
---|
102 | std::pair<float, float> tranLimit(-1.0, -1.0); |
---|
103 | std::pair<int, int> connLimit(-1, -1); |
---|
104 | float ratio = 0; |
---|
105 | |
---|
106 | if (hal::bit::torrent t = hal::bittorrent().get(focusedTorrent())) |
---|
107 | { |
---|
108 | tranLimit = t.rate_limits; |
---|
109 | connLimit = t.connection_limits; |
---|
110 | ratio = t.ratio; |
---|
111 | |
---|
112 | ::EnableWindow(GetDlgItem(IDC_EDITTLD), true); |
---|
113 | ::EnableWindow(GetDlgItem(IDC_EDITTLU), true); |
---|
114 | ::EnableWindow(GetDlgItem(IDC_EDITNCD), true); |
---|
115 | ::EnableWindow(GetDlgItem(IDC_EDITNCU), true); |
---|
116 | ::EnableWindow(GetDlgItem(IDC_EDITRATIO), true); |
---|
117 | } |
---|
118 | else |
---|
119 | { |
---|
120 | SetDlgItemText(IDC_NAME_STATUS, hal::app().res_wstr(HAL_NA).c_str()); |
---|
121 | SetDlgItemText(IDC_PEERS, hal::app().res_wstr(HAL_NA).c_str()); |
---|
122 | SetDlgItemText(IDC_SEEDS, hal::app().res_wstr(HAL_NA).c_str()); |
---|
123 | SetDlgItemText(IDC_TRANSFERED, hal::app().res_wstr(HAL_NA).c_str()); |
---|
124 | SetDlgItemText(IDC_OVERHEAD, hal::app().res_wstr(HAL_NA).c_str()); |
---|
125 | SetDlgItemText(IDC_REMAINING, hal::app().res_wstr(HAL_NA).c_str()); |
---|
126 | SetDlgItemText(IDC_ETA, hal::app().res_wstr(HAL_NA).c_str()); |
---|
127 | SetDlgItemText(IDC_RATE, hal::app().res_wstr(HAL_NA).c_str()); |
---|
128 | SetDlgItemText(IDC_RATIO, hal::app().res_wstr(HAL_NA).c_str()); |
---|
129 | SetDlgItemText(IDC_TRACKER, hal::app().res_wstr(HAL_NA).c_str()); |
---|
130 | SetDlgItemText(IDC_UPDATE, hal::app().res_wstr(HAL_NA).c_str()); |
---|
131 | |
---|
132 | m_prog.SetPos(0); |
---|
133 | |
---|
134 | ::EnableWindow(GetDlgItem(IDC_EDITTLD), false); |
---|
135 | ::EnableWindow(GetDlgItem(IDC_EDITTLU), false); |
---|
136 | ::EnableWindow(GetDlgItem(IDC_EDITNCD), false); |
---|
137 | ::EnableWindow(GetDlgItem(IDC_EDITNCU), false); |
---|
138 | ::EnableWindow(GetDlgItem(IDC_EDITRATIO), false); |
---|
139 | } |
---|
140 | |
---|
141 | totalConnections_ = connLimit.first; |
---|
142 | uploadConnections_ = connLimit.second; |
---|
143 | downloadRate_ = tranLimit.first; |
---|
144 | uploadRate_ = tranLimit.second; |
---|
145 | ratio_ = ratio; |
---|
146 | |
---|
147 | DoDataExchange(false); |
---|
148 | } |
---|
149 | |
---|
150 | void AdvTorrentDialog::uiUpdate(const hal::TorrentDetails& tD) |
---|
151 | { |
---|
152 | if (hal::TorrentDetail_ptr torrent = tD.focusedTorrent()) |
---|
153 | { |
---|
154 | uiUpdateSingle(torrent); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | void AdvTorrentDialog::uiUpdateSingle(const hal::TorrentDetail_ptr& torrent) |
---|
159 | { |
---|
160 | if (torrent) |
---|
161 | { |
---|
162 | /* HAL_NAME_STATUS "Name: %1%, %2%." |
---|
163 | HAL_SECOND "Peers %1% (%2%). Seeds %3% (%4%)." |
---|
164 | HAL_TRANSFERED "Transfered (Overhead): %1$.2fMB (%2$.2fMB) Down, %3$.2fMB (%4$.2fMB) Up." |
---|
165 | HAL_REMAINING "Remaining: %1$.2fMB of %2$.2fMB, ETA %3%." |
---|
166 | HAL_RATE "Downloading at %1$.2fkb/s, Uploading at %2$.2fkb/s, Ratio %3$.2f." |
---|
167 | */ |
---|
168 | SetDlgItemInfo(IDC_NAME_STATUS, |
---|
169 | wformat(hal::app().res_wstr(HAL_NAME_STATUS)) |
---|
170 | % torrent->name() |
---|
171 | % torrent->state()); |
---|
172 | |
---|
173 | SetDlgItemInfo(IDC_PEERS, |
---|
174 | wformat(L"%1% (%2%)") |
---|
175 | % torrent->peersConnected() |
---|
176 | % torrent->peers()); |
---|
177 | |
---|
178 | SetDlgItemInfo(IDC_SEEDS, |
---|
179 | wformat(L"%1% (%2%)") |
---|
180 | % torrent->seedsConnected() |
---|
181 | % torrent->seeds()); |
---|
182 | |
---|
183 | SetDlgItemInfo(IDC_TRANSFERED, |
---|
184 | wformat(hal::app().res_wstr(HAL_TRANSFERED)) |
---|
185 | % (static_cast<float>(torrent->totalPayloadDownloaded())/(1024*1024)) |
---|
186 | % (static_cast<float>(torrent->totalPayloadUploaded())/(1024*1024))); |
---|
187 | |
---|
188 | SetDlgItemInfo(IDC_OVERHEAD, |
---|
189 | wformat(L"%1$.2fMB - %2$.2fMB") |
---|
190 | % (static_cast<float>(torrent->totalDownloaded() - torrent->totalPayloadDownloaded())/(1024*1024)) |
---|
191 | % (static_cast<float>(torrent->totalUploaded() - torrent->totalPayloadUploaded())/(1024*1024))); |
---|
192 | |
---|
193 | SetDlgItemInfo(IDC_REMAINING, |
---|
194 | wformat(hal::app().res_wstr(HAL_REMAINING)) |
---|
195 | % (static_cast<float>(torrent->totalWanted()-torrent->totalWantedDone())/(1024*1024)) |
---|
196 | % (static_cast<float>(torrent->totalWanted())/(1024*1024))); |
---|
197 | |
---|
198 | wstring eta = hal::app().res_wstr(HAL_INF); |
---|
199 | if (!torrent->estimatedTimeLeft().is_special()) |
---|
200 | eta = hal::from_utf8(boost::posix_time::to_simple_string(torrent->estimatedTimeLeft())); |
---|
201 | |
---|
202 | SetDlgItemInfo(IDC_ETA, eta); |
---|
203 | |
---|
204 | SetDlgItemInfo(IDC_RATE, |
---|
205 | wformat(hal::app().res_wstr(HAL_RATE)) |
---|
206 | % (torrent->speed().first/1024) |
---|
207 | % (torrent->speed().second/1024)); |
---|
208 | |
---|
209 | float ratio = (torrent->totalPayloadDownloaded()) |
---|
210 | ? static_cast<float>(torrent->totalPayloadUploaded()) |
---|
211 | / static_cast<float>(torrent->totalPayloadDownloaded()) |
---|
212 | : 0; |
---|
213 | |
---|
214 | SetDlgItemInfo(IDC_RATIO, |
---|
215 | wformat(L"%1$.2f") % ratio); |
---|
216 | |
---|
217 | m_prog.SetPos(static_cast<int>(torrent->completion()*100)); |
---|
218 | |
---|
219 | SetDlgItemText(IDC_TRACKER, torrent->currentTracker().c_str()); |
---|
220 | |
---|
221 | if (!torrent->updateTrackerIn().is_special()) |
---|
222 | { |
---|
223 | SetDlgItemText(IDC_UPDATE, |
---|
224 | (hal::from_utf8(boost::posix_time::to_simple_string(torrent->updateTrackerIn())).c_str())); |
---|
225 | } |
---|
226 | else SetDlgItemText(IDC_UPDATE, hal::app().res_wstr(HAL_NA).c_str()); |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | void AdvTorrentDialog::uiUpdateMultiple(const hal::TorrentDetail_vec& torrents) |
---|
231 | {} |
---|
232 | |
---|
233 | void AdvTorrentDialog::uiUpdateNone() |
---|
234 | {} |
---|