1
// rTorrent - BitTorrent client
2
// Copyright (C) 2005-2007, Jari Sundell
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2 of the License, or
7
// (at your option) any later version.
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.
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
18
// In addition, as a special exception, the copyright holders give
19
// permission to link the code of portions of this program with the
20
// OpenSSL library under certain conditions as described in each
21
// individual source file, and distribute linked combinations
24
// You must obey the GNU General Public License in all respects for
25
// all of the code used other than OpenSSL. If you modify file(s)
26
// with this exception, you may extend this exception to your version
27
// of the file(s), but you are not obligated to do so. If you do not
28
// wish to do so, delete this exception statement from your version.
29
// If you delete this exception statement from all source files in the
30
// program, then also delete it here.
32
// Contact: Jari Sundell <jaris@ifi.uio.no>
35
// 3185 Skoppum, NORWAY
41
#include <rak/functional.h>
42
#include <rak/string_manip.h>
43
#include <torrent/bitfield.h>
44
#include <torrent/data/block.h>
45
#include <torrent/data/block_list.h>
46
#include <torrent/data/transfer_list.h>
48
#include "core/download.h"
50
#include "window_download_chunks_seen.h"
54
WindowDownloadChunksSeen::WindowDownloadChunksSeen(core::Download* d, unsigned int *focus) :
55
Window(new Canvas, 0, 0, 0, extent_full, extent_full),
61
WindowDownloadChunksSeen::redraw() {
62
// TODO: Make this depend on tracker signal.
63
m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(10)).round_seconds());
66
if (m_canvas->height() < 3 || m_canvas->width() < 18)
69
m_canvas->print(2, 0, "Chunks seen: [C/A/D %i/%i/%.2f]",
70
(int)m_download->download()->peers_complete(),
71
(int)m_download->download()->peers_accounted(),
72
std::floor(m_download->distributed_copies() * 100.0f) / 100.0f);
74
const uint8_t* seen = m_download->download()->chunks_seen();
76
if (seen == NULL || m_download->download()->file_list()->bitfield()->empty()) {
77
m_canvas->print(2, 2, "Not available.");
81
if (!m_download->is_done()) {
82
m_canvas->print(36, 0, "X downloaded missing queued downloading");
83
m_canvas->print_char(50, 0, 'X' | A_BOLD);
84
m_canvas->print_char(61, 0, 'X' | A_BOLD | A_UNDERLINE);
85
m_canvas->print_char(71, 0, 'X' | A_REVERSE);
88
*m_focus = std::min(*m_focus, max_focus());
90
const uint8_t* chunk = seen + *m_focus * chunks_per_row();
91
const uint8_t* last = seen + m_download->download()->file_list()->size_chunks();
93
const torrent::Bitfield* bitfield = m_download->download()->file_list()->bitfield();
94
const torrent::TransferList* transfers = m_download->download()->transfer_list();
95
std::vector<torrent::BlockList*> transferChunks(transfers->size(), 0);
97
std::copy(transfers->begin(), transfers->end(), transferChunks.begin());
98
std::sort(transferChunks.begin(), transferChunks.end(), rak::less2(std::mem_fun(&torrent::BlockList::index), std::mem_fun(&torrent::BlockList::index)));
100
std::vector<torrent::BlockList*>::const_iterator itrTransfer = transferChunks.begin();
102
while (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) > (*itrTransfer)->index())
105
for (unsigned int y = 1; y < m_canvas->height() && chunk < last; ++y) {
106
m_canvas->print(0, y, "%5u ", (int)(chunk - seen));
108
while (chunk < last) {
111
if (bitfield->get(chunk - seen)) {
113
} else if (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) == (*itrTransfer)->index()) {
114
if (std::find_if((*itrTransfer)->begin(), (*itrTransfer)->end(), std::mem_fun_ref(&torrent::Block::is_transfering)) != (*itrTransfer)->end())
117
attr = A_BOLD | A_UNDERLINE;
123
m_canvas->print_char(attr | rak::value_to_hexchar<0>(std::min<uint8_t>(*chunk, 0xF)));
126
if ((chunk - seen) % 10 == 0) {
127
if (m_canvas->get_x() + 12 > m_canvas->width())
130
m_canvas->print_char(' ');
137
WindowDownloadChunksSeen::rows() const {
138
if (m_canvas->width() < 18)
141
return (m_download->download()->file_list()->size_chunks() + chunks_per_row() - 1) / chunks_per_row();