Peer info properly displays data, added parse.* with escape_string(...).

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@261 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-08 17:07:22 +00:00
parent b657554236
commit b01cd17a72
6 changed files with 71 additions and 8 deletions
+2
View File
@@ -14,6 +14,8 @@ rtorrent_LDADD = \
rtorrent_SOURCES = \
main.cc \
parse.cc \
parse.h \
signal_handler.cc \
signal_handler.h \
timer.h
+27 -6
View File
@@ -2,13 +2,17 @@
#include <stdexcept>
#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));
}
}
+7 -1
View File
@@ -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<torrent::Peer> PList;
typedef sigc::slot0<uint32_t> 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;
+24
View File
@@ -0,0 +1,24 @@
#include "config.h"
#include <sstream>
#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();
}
+10
View File
@@ -0,0 +1,10 @@
#ifndef RTORRENT_PARSE_H
#define RTORRENT_PARSE_H
#include <string>
// Various functinos for manipulating strings.
std::string escape_string(const std::string& src);
#endif
+1 -1
View File
@@ -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));