diff --git a/src/Makefile.am b/src/Makefile.am index 4484d203..2404e006 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,8 @@ rtorrent_LDADD = \ rtorrent_SOURCES = \ main.cc \ + parse.cc \ + parse.h \ signal_handler.cc \ signal_handler.h \ timer.h diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index ee133e0b..428176fe 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -2,13 +2,17 @@ #include +#include "core/download.h" + +#include "parse.h" #include "canvas.h" #include "window_peer_info.h" namespace display { -WindowPeerInfo::WindowPeerInfo(PList* l, PList::iterator* f) : +WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f) : Window(new Canvas, true), + m_download(d), m_list(l), m_focus(f) { } @@ -21,12 +25,29 @@ WindowPeerInfo::redraw() { m_lastDraw = Timer::cache(); m_canvas->erase(); + int y = 0; + + m_canvas->print(0, y++, "Hash: %s", escape_string(m_download->get_download().get_hash()).c_str()); + m_canvas->print(0, y++, "Chunks: %u / %u * %u", + m_download->get_download().get_chunks_done(), + m_download->get_download().get_chunks_total(), + m_download->get_download().get_chunks_size()); + if (*m_focus == m_list->end()) - mvprintw(0, 0, "No focus"); - else - mvprintw(0, 0, "Focus on: %s:%i", - (*m_focus)->get_dns().c_str(), - (*m_focus)->get_port()); + return; + + y++; + + m_canvas->print(0, y++, "DNS: %s:%hu", (*m_focus)->get_dns().c_str(), (*m_focus)->get_port()); + m_canvas->print(0, y++, "Id: %s" , escape_string((*m_focus)->get_id()).c_str()); + m_canvas->print(0, y++, "Snubbed: %s", (*m_focus)->get_snubbed() ? "Yes" : "No"); + m_canvas->print(0, y++, "Done: %i%", (*m_focus)->get_chunks_done()); + + m_canvas->print(0, y++, "Rate: %5.1f/%5.1f KB Total: %.1f/%.1f MB", + (double)(*m_focus)->get_rate_up() / (double)(1 << 10), + (double)(*m_focus)->get_rate_down() / (double)(1 << 10), + (double)(*m_focus)->get_transfered_up() / (double)(1 << 20), + (double)(*m_focus)->get_transfered_down() / (double)(1 << 20)); } } diff --git a/src/display/window_peer_info.h b/src/display/window_peer_info.h index e90f5c98..2695ecc9 100644 --- a/src/display/window_peer_info.h +++ b/src/display/window_peer_info.h @@ -7,6 +7,10 @@ #include "window.h" +namespace core { + class Download; +} + namespace display { class WindowPeerInfo : public Window { @@ -14,13 +18,15 @@ public: typedef std::list PList; typedef sigc::slot0 SlotChunksTotal; - WindowPeerInfo(PList* l, PList::iterator* f); + WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f); void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; } virtual void redraw(); private: + core::Download* m_download; + PList* m_list; PList::iterator* m_focus; diff --git a/src/parse.cc b/src/parse.cc new file mode 100644 index 00000000..765b9988 --- /dev/null +++ b/src/parse.cc @@ -0,0 +1,24 @@ +#include "config.h" + +#include + +#include "parse.h" + +std::string +escape_string(const std::string& src) { + std::stringstream stream; + + // TODO: Correct would be to save the state. + stream << std::hex << std::uppercase; + + for (std::string::const_iterator itr = src.begin(); itr != src.end(); ++itr) + if ((*itr >= 'A' && *itr <= 'Z') || + (*itr >= 'a' && *itr <= 'z') || + (*itr >= '0' && *itr <= '9') || + *itr == '-') + stream << *itr; + else + stream << '%' << ((unsigned char)*itr >> 4) << ((unsigned char)*itr & 0xf); + + return stream.str(); +} diff --git a/src/parse.h b/src/parse.h new file mode 100644 index 00000000..6bad0a24 --- /dev/null +++ b/src/parse.h @@ -0,0 +1,10 @@ +#ifndef RTORRENT_PARSE_H +#define RTORRENT_PARSE_H + +#include + +// Various functinos for manipulating strings. + +std::string escape_string(const std::string& src); + +#endif diff --git a/src/ui/download.cc b/src/ui/download.cc index 24b57152..f4a2e001 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -93,7 +93,7 @@ Download::activate_display(Display d) { break; case DISPLAY_PEER: - *m_window = wpi = new WPeerInfo(&m_peers, &m_focus); + *m_window = wpi = new WPeerInfo(m_download, &m_peers, &m_focus); wpi->slot_chunks_total(sigc::mem_fun(m_download->get_download(), &torrent::Download::get_chunks_total));