Adding some tracker msg related stuff, download status bar.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@262 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-08 22:06:57 +00:00
parent b01cd17a72
commit f7144a333f
12 changed files with 197 additions and 38 deletions
+1
View File
@@ -5,6 +5,7 @@ libsub_core_a_SOURCES = \
curl_get.h \
curl_stack.cc \
curl_stack.h \
download.cc \
download.h \
download_list.cc \
download_list.h \
+29
View File
@@ -0,0 +1,29 @@
#include "config.h"
#include "download.h"
#include <sigc++/bind.h>
#include <sigc++/signal.h>
namespace core {
void
Download::set_download(torrent::Download d) {
m_download = d;
m_connTrackerSucceded = m_download.signal_tracker_succeded(sigc::bind(sigc::mem_fun(*this, &Download::receive_tracker_msg), "^_^"));
m_connTrackerFailed = m_download.signal_tracker_failed(sigc::mem_fun(*this, &Download::receive_tracker_msg));
}
void
Download::release_download() {
m_connTrackerSucceded.disconnect();
m_connTrackerFailed.disconnect();
}
void
Download::receive_tracker_msg(std::string msg) {
m_trackerMsg = msg;
}
}
+13 -3
View File
@@ -8,10 +8,13 @@ namespace core {
class Download {
public:
Download(torrent::Download d) : m_download(d) {}
std::string get_hash() { return m_download.get_hash(); }
void set_download(torrent::Download d);
void release_download();
torrent::Download& get_download() { return m_download; }
std::string get_hash() { return m_download.get_hash(); }
const std::string& get_tracker_msg() { return m_trackerMsg; }
void open() { m_download.open(); }
void close() { m_download.close(); }
@@ -23,7 +26,14 @@ public:
bool operator == (const std::string& str) { return str == m_download.get_hash(); }
private:
void receive_tracker_msg(std::string msg);
torrent::Download m_download;
std::string m_trackerMsg;
sigc::connection m_connTrackerSucceded;
sigc::connection m_connTrackerFailed;
};
}
+6 -1
View File
@@ -11,8 +11,11 @@ namespace core {
DownloadList::iterator
DownloadList::create(std::istream& str) {
iterator itr = Base::insert(end(), torrent::download_create(str));
torrent::Download d = torrent::download_create(str);
iterator itr = Base::insert(end(), Download());
itr->set_download(d);
itr->get_download().signal_hash_done(sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_hash_done),
itr->get_hash()));
@@ -21,6 +24,8 @@ DownloadList::create(std::istream& str) {
void
DownloadList::erase(iterator itr) {
itr->release_download();
torrent::download_remove(itr->get_hash());
Base::erase(itr);
+3
View File
@@ -21,6 +21,9 @@ public:
using Base::rbegin;
using Base::rend;
using Base::empty;
using Base::size;
iterator create(std::istream& str);
void erase(iterator itr);
+2
View File
@@ -7,6 +7,8 @@ libsub_display_a_SOURCES = \
manager.h \
window.cc \
window.h \
window_download_statusbar.cc \
window_download_statusbar.h \
window_download_list.cc \
window_download_list.h \
window_peer_info.cc \
+31 -7
View File
@@ -20,11 +20,35 @@ WindowDownloadList::redraw() {
m_canvas->erase();
int pos = 0;
if (m_list->empty())
return;
// Remember to check for end of screen too.
DList::iterator itr, last;
int pos = 0, y = 0;
for (DList::iterator itr = m_list->begin(); itr != m_list->end(); ++itr) {
if (*m_focus != m_list->end()) {
int i = 0;
itr = last = *m_focus;
while (i < m_canvas->get_height() - y && !(itr == m_list->begin() && last == m_list->end())) {
if (last != m_list->end()) {
++last;
i += 3;
}
if (itr != m_list->begin() && i < m_canvas->get_height() - y) {
--itr;
i += 3;
}
}
} else {
itr = m_list->begin();
last = m_list->end();
}
while (itr != m_list->end() && y < m_canvas->get_height()) {
m_canvas->print(0, pos++, "%c %s",
itr == *m_focus ? '*' : ' ',
itr->get_download().get_name().c_str());
@@ -46,11 +70,11 @@ WindowDownloadList::redraw() {
(double)itr->get_download().get_rate_down() / 1024.0,
(double)itr->get_download().get_bytes_up() / (double)(1 << 20));
m_canvas->print(0, pos++, "%c Tracker: [%c:%i] %s",
m_canvas->print(0, pos++, "%c Tracker: %s",
itr == *m_focus ? '*' : ' ',
itr->get_download().is_tracker_busy() ? 'C' : ' ',
(int)(itr->get_download().get_tracker_timeout() / 1000000),
"");
itr->get_download().is_tracker_busy() ? "Connecting" : itr->get_tracker_msg().c_str());
++itr;
}
}
+45
View File
@@ -0,0 +1,45 @@
#include "config.h"
#include "canvas.h"
#include "window_download_statusbar.h"
#include "core/download.h"
namespace display {
WindowDownloadStatusbar::WindowDownloadStatusbar(core::Download* d) :
Window(new Canvas, false, 2),
m_download(d) {
}
void
WindowDownloadStatusbar::redraw() {
if (Timer::cache() - m_lastDraw < 1000000)
return;
m_lastDraw = Timer::cache();
m_canvas->erase();
if (m_download->get_download().get_chunks_done() != m_download->get_download().get_chunks_total() || !m_download->get_download().is_open())
m_canvas->print(0, 0, "Torrent: %.1f / %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB",
(double)m_download->get_download().get_bytes_done() / (double)(1 << 20),
(double)m_download->get_download().get_bytes_total() / (double)(1 << 20),
(double)m_download->get_download().get_rate_up() / 1024.0,
(double)m_download->get_download().get_rate_down() / 1024.0,
(double)m_download->get_download().get_bytes_up() / (double)(1 << 20));
else
m_canvas->print(0, 0, "Torrent: Done %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB",
(double)m_download->get_download().get_bytes_total() / (double)(1 << 20),
(double)m_download->get_download().get_rate_up() / 1024.0,
(double)m_download->get_download().get_rate_down() / 1024.0,
(double)m_download->get_download().get_bytes_up() / (double)(1 << 20));
m_canvas->print(0, 1, "Tracker: [%c:%i] %s",
m_download->get_download().is_tracker_busy() ? 'C' : ' ',
(int)(m_download->get_download().get_tracker_timeout() / 1000000),
m_download->get_tracker_msg().c_str());
}
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef RTORRENT_WINDOW_DOWNLOAD_STATUSBAR_H
#define RTORRENT_WINDOW_DOWNLOAD_STATUSBAR_H
#include "window.h"
namespace core {
class Download;
}
namespace display {
class WindowDownloadStatusbar : public Window {
public:
WindowDownloadStatusbar(core::Download* d);
virtual void redraw();
private:
core::Download* m_download;
};
}
#endif
+4 -1
View File
@@ -33,8 +33,11 @@ WindowPeerInfo::redraw() {
m_download->get_download().get_chunks_total(),
m_download->get_download().get_chunks_size());
if (*m_focus == m_list->end())
if (*m_focus == m_list->end()) {
m_canvas->print(0, y++, "No peer in focus");
return;
}
y++;
+23 -13
View File
@@ -9,6 +9,7 @@
#include "display/window_title.h"
#include "display/window_peer_list.h"
#include "display/window_peer_info.h"
#include "display/window_download_statusbar.h"
#include "display/window_statusbar.h"
#include "control.h"
@@ -19,9 +20,12 @@ namespace ui {
Download::Download(DPtr d, Control* c) :
m_download(d),
m_state(DISPLAY_NONE),
m_title(c->get_display().end()),
m_window(c->get_display().end()),
m_title(new WTitle(d->get_download().get_name())),
m_status(new WStatus),
m_downloadStatus(c->get_display().end()),
m_status(c->get_display().end()),
m_control(c),
m_bindings(new input::Bindings) {
@@ -36,12 +40,11 @@ Download::Download(DPtr d, Control* c) :
}
Download::~Download() {
if (m_window != m_control->get_display().end())
throw std::logic_error("ui::Download::~Download() called on an active object");
m_connPeerConnected.disconnect();
m_connPeerDisconnected.disconnect();
delete m_title;
delete m_status;
delete m_bindings;
}
void
@@ -49,10 +52,10 @@ Download::activate() {
if (m_window != m_control->get_display().end())
throw std::logic_error("ui::Download::activate() called on an already activated object");
m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL);
m_control->get_display().push_front(m_title);
m_control->get_display().push_back(m_status);
m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL);
m_title = m_control->get_display().insert(m_control->get_display().begin(), new WTitle(m_download->get_download().get_name()));
m_downloadStatus = m_control->get_display().insert(m_control->get_display().end(), new WDownloadStatus(m_download));
m_status = m_control->get_display().insert(m_control->get_display().end(), new WStatus);
m_control->get_input().push_front(m_bindings);
@@ -66,13 +69,18 @@ Download::disable() {
disable_display();
delete *m_title;
delete *m_downloadStatus;
delete *m_status;
m_control->get_display().erase(m_window);
m_control->get_display().erase(m_title);
m_control->get_display().erase(m_downloadStatus);
m_control->get_display().erase(m_status);
m_control->get_input().erase(m_bindings);
m_window = m_title = m_downloadStatus = m_status = m_control->get_display().end();
m_window = m_control->get_display().end();
m_control->get_input().erase(m_bindings);
}
void
@@ -172,7 +180,7 @@ Download::receive_peer_disconnected(torrent::Peer p) {
void
Download::receive_throttle(int t) {
m_status->mark_dirty();
(*m_status)->mark_dirty();
torrent::set(torrent::THROTTLE_ROOT_CONST_RATE, torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) + t * 1024);
}
@@ -196,6 +204,8 @@ Download::bind_keys(input::Bindings* b) {
(*b)['d'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 50);
(*b)['c'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -50);
(*b)['t'] = sigc::bind(sigc::mem_fun(m_download->get_download(), &torrent::Download::set_tracker_timeout), 2 * 1000000);
(*b)[KEY_UP] = sigc::mem_fun(*this, &Download::receive_prev);
(*b)[KEY_DOWN] = sigc::mem_fun(*this, &Download::receive_next);
}
+16 -13
View File
@@ -10,6 +10,7 @@ namespace display {
class WindowPeerInfo;
class WindowPeerList;
class WindowStatusbar;
class WindowDownloadStatusbar;
}
namespace core {
@@ -22,22 +23,23 @@ class Control;
class Download {
public:
typedef display::Window Window;
typedef display::WindowPeerInfo WPeerInfo;
typedef display::WindowPeerList WPeerList;
typedef display::WindowTitle WTitle;
typedef display::WindowStatusbar WStatus;
typedef display::WindowDownloadStatusbar WDownloadStatus;
typedef core::Download* DPtr;
typedef std::list<torrent::Peer> PList;
typedef display::Manager::iterator MItr;
typedef enum {
DISPLAY_NONE,
DISPLAY_MAIN,
DISPLAY_PEER
} Display;
typedef display::Window Window;
typedef display::WindowPeerInfo WPeerInfo;
typedef display::WindowPeerList WPeerList;
typedef display::WindowTitle WTitle;
typedef display::WindowStatusbar WStatus;
typedef core::Download* DPtr;
typedef std::list<torrent::Peer> PList;
typedef display::Manager::iterator MItr;
// We own 'window'.
Download(DPtr d, Control* c);
~Download();
@@ -73,10 +75,11 @@ private:
PList::iterator m_focus;
Display m_state;
MItr m_window;
WTitle* m_title;
WStatus* m_status;
MItr m_title;
MItr m_window;
MItr m_downloadStatus;
MItr m_status;
Control* m_control;
input::Bindings* m_bindings;