mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-15 13:46:17 +00:00
* Added view of blocks in transfer list view.
* Show chunks with only queued transfers with an underscore in chunks seen view. Patch by Josef Drexler, public domain. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@719 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -169,6 +169,24 @@ less(Type t, Ftor f) {
|
|||||||
return less_t<Type, Ftor>(t, f);
|
return less_t<Type, Ftor>(t, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename FtorA, typename FtorB>
|
||||||
|
struct less2_t : public std::binary_function<typename FtorA::argument_type, typename FtorB::argument_type, bool> {
|
||||||
|
less2_t(FtorA f_a, FtorB f_b) : m_f_a(f_a), m_f_b(f_b) {}
|
||||||
|
|
||||||
|
bool operator () (typename FtorA::argument_type a, typename FtorB::argument_type b) {
|
||||||
|
return m_f_a(a) < m_f_b(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
FtorA m_f_a;
|
||||||
|
FtorB m_f_b;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename FtorA, typename FtorB>
|
||||||
|
inline less2_t<FtorA, FtorB>
|
||||||
|
less2(FtorA f_a, FtorB f_b) {
|
||||||
|
return less2_t<FtorA,FtorB>(f_a,f_b);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Type, typename Ftor>
|
template <typename Type, typename Ftor>
|
||||||
struct _greater {
|
struct _greater {
|
||||||
typedef bool result_type;
|
typedef bool result_type;
|
||||||
|
|||||||
@@ -38,9 +38,11 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <rak/functional.h>
|
||||||
#include <rak/string_manip.h>
|
#include <rak/string_manip.h>
|
||||||
#include <torrent/bitfield.h>
|
#include <torrent/bitfield.h>
|
||||||
#include <torrent/transfer_list.h>
|
#include <torrent/transfer_list.h>
|
||||||
|
#include <torrent/block.h>
|
||||||
#include <torrent/block_list.h>
|
#include <torrent/block_list.h>
|
||||||
|
|
||||||
#include "core/download.h"
|
#include "core/download.h"
|
||||||
@@ -77,9 +79,10 @@ WindowDownloadChunksSeen::redraw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_download->is_done()) {
|
if (!m_download->is_done()) {
|
||||||
m_canvas->print(36, 0, "X downloaded missing downloading");
|
m_canvas->print(36, 0, "X downloaded missing queued downloading");
|
||||||
m_canvas->print_char(50, 0, 'X' | A_BOLD);
|
m_canvas->print_char(50, 0, 'X' | A_BOLD);
|
||||||
m_canvas->print_char(61, 0, 'X' | A_REVERSE);
|
m_canvas->print_char(61, 0, 'X' | A_BOLD | A_UNDERLINE);
|
||||||
|
m_canvas->print_char(71, 0, 'X' | A_REVERSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
*m_focus = std::min(*m_focus, max_focus());
|
*m_focus = std::min(*m_focus, max_focus());
|
||||||
@@ -89,12 +92,12 @@ WindowDownloadChunksSeen::redraw() {
|
|||||||
|
|
||||||
const torrent::Bitfield* bitfield = m_download->download()->bitfield();
|
const torrent::Bitfield* bitfield = m_download->download()->bitfield();
|
||||||
const torrent::TransferList* transfers = m_download->download()->transfer_list();
|
const torrent::TransferList* transfers = m_download->download()->transfer_list();
|
||||||
std::vector<uint32_t> transferChunks(transfers->size(), 0);
|
std::vector<torrent::BlockList*> transferChunks(transfers->size(), 0);
|
||||||
|
|
||||||
std::transform(transfers->begin(), transfers->end(), transferChunks.begin(), std::mem_fun(&torrent::BlockList::index));
|
std::copy(transfers->begin(), transfers->end(), transferChunks.begin());
|
||||||
std::sort(transferChunks.begin(), transferChunks.end());
|
std::sort(transferChunks.begin(), transferChunks.end(), rak::less2(std::mem_fun(&torrent::BlockList::index), std::mem_fun(&torrent::BlockList::index)));
|
||||||
|
|
||||||
std::vector<uint32_t>::const_iterator itrTransfer = transferChunks.begin();
|
std::vector<torrent::BlockList*>::const_iterator itrTransfer = transferChunks.begin();
|
||||||
|
|
||||||
for (int y = 1; y < m_canvas->get_height() && chunk < last; ++y) {
|
for (int y = 1; y < m_canvas->get_height() && chunk < last; ++y) {
|
||||||
m_canvas->print(0, y, "%5u ", (int)(chunk - seen));
|
m_canvas->print(0, y, "%5u ", (int)(chunk - seen));
|
||||||
@@ -104,8 +107,11 @@ WindowDownloadChunksSeen::redraw() {
|
|||||||
|
|
||||||
if (bitfield->get(chunk - seen)) {
|
if (bitfield->get(chunk - seen)) {
|
||||||
attr = A_NORMAL;
|
attr = A_NORMAL;
|
||||||
} else if (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) == *itrTransfer) {
|
} else if (itrTransfer != transferChunks.end() && (uint32_t)(chunk - seen) == (*itrTransfer)->index()) {
|
||||||
attr = A_REVERSE;
|
if (std::find_if((*itrTransfer)->begin(), (*itrTransfer)->end(), std::mem_fun_ref(&torrent::Block::is_transfering)) != (*itrTransfer)->end())
|
||||||
|
attr = A_REVERSE;
|
||||||
|
else
|
||||||
|
attr = A_BOLD | A_UNDERLINE;
|
||||||
itrTransfer++;
|
itrTransfer++;
|
||||||
} else {
|
} else {
|
||||||
attr = A_BOLD;
|
attr = A_BOLD;
|
||||||
|
|||||||
@@ -78,16 +78,31 @@ WindowDownloadTransferList::redraw() {
|
|||||||
|
|
||||||
// Handle window size.
|
// Handle window size.
|
||||||
for (torrent::BlockList::const_iterator bItr = (*itr)->begin(), bLast = (*itr)->end(); bItr != bLast; ++bItr) {
|
for (torrent::BlockList::const_iterator bItr = (*itr)->begin(), bLast = (*itr)->end(); bItr != bLast; ++bItr) {
|
||||||
chtype attr;
|
char id;
|
||||||
|
chtype attr = A_NORMAL;
|
||||||
|
|
||||||
// Add is_transfering.
|
if (bItr->transfers()->size() >= 1) {
|
||||||
|
|
||||||
if (bItr->is_finished())
|
|
||||||
attr = A_NORMAL;
|
|
||||||
else
|
|
||||||
attr = A_BOLD;
|
attr = A_BOLD;
|
||||||
|
id = key_id(bItr->transfers()->back()->const_peer_info());
|
||||||
|
|
||||||
m_canvas->print_char(attr | 'X');
|
if (bItr->transfers()->size() > 1)
|
||||||
|
id = std::tolower(id);
|
||||||
|
|
||||||
|
} else if (bItr->queued()->size() >= 1) {
|
||||||
|
id = key_id(bItr->queued()->back()->const_peer_info());
|
||||||
|
|
||||||
|
if (bItr->queued()->size() > 1)
|
||||||
|
id = std::tolower(id);
|
||||||
|
|
||||||
|
} else if (bItr->is_finished()) {
|
||||||
|
// Temporary until
|
||||||
|
id = '*';
|
||||||
|
|
||||||
|
} else {
|
||||||
|
id = '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
m_canvas->print_char(attr | id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,4 +116,38 @@ WindowDownloadTransferList::rows() const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char
|
||||||
|
WindowDownloadTransferList::key_id(torrent::BlockTransfer::key_type key) {
|
||||||
|
uint32_t oldestTime = cachedTime.seconds();
|
||||||
|
assigned_vector::iterator oldestItr = m_assigned.begin();
|
||||||
|
|
||||||
|
for (assigned_vector::iterator itr = m_assigned.begin(), last = m_assigned.end(); itr != last; ++itr) {
|
||||||
|
if (itr->m_key == key) {
|
||||||
|
itr->m_last = cachedTime.seconds();
|
||||||
|
return itr->m_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itr->m_last < oldestTime) {
|
||||||
|
oldestTime = itr->m_last;
|
||||||
|
oldestItr = itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldestItr == m_assigned.end() || cachedTime.seconds() - oldestTime <= 60) {
|
||||||
|
// We didn't find any previously used id's to take over.
|
||||||
|
|
||||||
|
// Return 'f' when we run out of characters.
|
||||||
|
if (m_assigned.size() >= ('Z' - 'A'))
|
||||||
|
return 'Z';
|
||||||
|
|
||||||
|
char id = 'A' + m_assigned.size();
|
||||||
|
|
||||||
|
m_assigned.push_back(assigned_type(key, cachedTime.seconds(), id));
|
||||||
|
return id;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return oldestItr->m_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,20 +50,30 @@ namespace display {
|
|||||||
|
|
||||||
class WindowDownloadTransferList : public Window {
|
class WindowDownloadTransferList : public Window {
|
||||||
public:
|
public:
|
||||||
|
struct assigned_type {
|
||||||
|
assigned_type(torrent::BlockTransfer::key_type key, uint32_t last, char id) : m_key(key), m_last(last), m_id(id) { }
|
||||||
|
|
||||||
|
torrent::BlockTransfer::key_type m_key;
|
||||||
|
uint32_t m_last;
|
||||||
|
char m_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<assigned_type> assigned_vector;
|
||||||
|
|
||||||
WindowDownloadTransferList(core::Download* d, unsigned int* focus);
|
WindowDownloadTransferList(core::Download* d, unsigned int* focus);
|
||||||
|
|
||||||
virtual void redraw();
|
virtual void redraw();
|
||||||
|
|
||||||
unsigned int rows() const;
|
unsigned int rows() const;
|
||||||
|
unsigned int max_focus() const { return std::max<int>(rows() - get_height() + 1, 0); }
|
||||||
unsigned int max_focus() const { return std::max<int>(rows() - get_height() + 1, 0); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char peer_id(torrent::BlockTransfer::key_type key);
|
char key_id(torrent::BlockTransfer::key_type key);
|
||||||
|
|
||||||
core::Download* m_download;
|
core::Download* m_download;
|
||||||
|
|
||||||
unsigned int* m_focus;
|
unsigned int* m_focus;
|
||||||
|
assigned_vector m_assigned;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user