mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-05 17:52:29 +00:00
Work on peer info display.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@260 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -9,6 +9,8 @@ libsub_display_a_SOURCES = \
|
||||
window.h \
|
||||
window_download_list.cc \
|
||||
window_download_list.h \
|
||||
window_peer_info.cc \
|
||||
window_peer_info.h \
|
||||
window_peer_list.cc \
|
||||
window_peer_list.h \
|
||||
window_statusbar.cc \
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "canvas.h"
|
||||
#include "window_peer_info.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
WindowPeerInfo::WindowPeerInfo(PList* l, PList::iterator* f) :
|
||||
Window(new Canvas, true),
|
||||
m_list(l),
|
||||
m_focus(f) {
|
||||
}
|
||||
|
||||
void
|
||||
WindowPeerInfo::redraw() {
|
||||
if (Timer::cache() - m_lastDraw < 1000000)
|
||||
return;
|
||||
|
||||
m_lastDraw = Timer::cache();
|
||||
m_canvas->erase();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef RTORRENT_DISPLAY_PEER_INFO_H
|
||||
#define RTORRENT_DISPLAY_PEER_INFO_H
|
||||
|
||||
#include <list>
|
||||
#include <sigc++/slot.h>
|
||||
#include <torrent/peer.h>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
class WindowPeerInfo : public Window {
|
||||
public:
|
||||
typedef std::list<torrent::Peer> PList;
|
||||
typedef sigc::slot0<uint32_t> SlotChunksTotal;
|
||||
|
||||
WindowPeerInfo(PList* l, PList::iterator* f);
|
||||
|
||||
void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; }
|
||||
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
PList* m_list;
|
||||
PList::iterator* m_focus;
|
||||
|
||||
SlotChunksTotal m_slotChunksTotal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,6 +14,8 @@ WindowStatusbar::WindowStatusbar() :
|
||||
|
||||
void
|
||||
WindowStatusbar::redraw() {
|
||||
m_counter++;
|
||||
|
||||
if (Timer::cache() - m_lastDraw < 10000000)
|
||||
return;
|
||||
|
||||
@@ -25,7 +27,7 @@ WindowStatusbar::redraw() {
|
||||
"",
|
||||
(int)torrent::get(torrent::LISTEN_PORT),
|
||||
(int)torrent::get(torrent::HANDSHAKES_TOTAL),
|
||||
++m_counter);
|
||||
m_counter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public:
|
||||
using Base::rend;
|
||||
using Base::find;
|
||||
|
||||
using Base::erase;
|
||||
|
||||
using Base::operator[];
|
||||
|
||||
Bindings() : m_active(true) {}
|
||||
|
||||
+6
-4
@@ -1,3 +1,5 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
@@ -92,6 +94,10 @@ int
|
||||
main(int argc, char** argv) {
|
||||
try {
|
||||
|
||||
SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown));
|
||||
SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV));
|
||||
SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS));
|
||||
|
||||
display::Canvas::init();
|
||||
core::CurlStack::init();
|
||||
|
||||
@@ -123,10 +129,6 @@ main(int argc, char** argv) {
|
||||
itr->hash_check();
|
||||
}
|
||||
|
||||
SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown));
|
||||
SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV));
|
||||
SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS));
|
||||
|
||||
uiControl.get_display().adjust_layout();
|
||||
|
||||
while (!is_shutting_down || !torrent::get(torrent::SHUTDOWN_DONE)) {
|
||||
|
||||
@@ -8,11 +8,15 @@ namespace ui {
|
||||
|
||||
class Control {
|
||||
public:
|
||||
Control() {}
|
||||
|
||||
display::Manager& get_display() { return m_display; }
|
||||
input::Manager& get_input() { return m_input; }
|
||||
|
||||
private:
|
||||
Control(const Control&);
|
||||
void operator = (const Control&);
|
||||
|
||||
display::Manager m_display;
|
||||
input::Manager m_input;
|
||||
};
|
||||
|
||||
+89
-7
@@ -4,9 +4,11 @@
|
||||
#include <sigc++/bind.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "core/download.h"
|
||||
#include "input/bindings.h"
|
||||
#include "display/window_title.h"
|
||||
#include "display/window_peer_list.h"
|
||||
#include "display/window_peer_info.h"
|
||||
#include "display/window_statusbar.h"
|
||||
|
||||
#include "control.h"
|
||||
@@ -16,6 +18,8 @@ namespace ui {
|
||||
|
||||
Download::Download(DPtr d, Control* c) :
|
||||
m_download(d),
|
||||
m_state(DISPLAY_NONE),
|
||||
m_window(c->get_display().end()),
|
||||
m_title(new WTitle(d->get_download().get_name())),
|
||||
m_status(new WStatus),
|
||||
m_control(c),
|
||||
@@ -23,9 +27,6 @@ Download::Download(DPtr d, Control* c) :
|
||||
|
||||
m_focus = m_peers.end();
|
||||
|
||||
m_window = new WPeerList(&m_peers, &m_focus);
|
||||
m_window->slot_chunks_total(sigc::mem_fun(m_download->get_download(), &torrent::Download::get_chunks_total));
|
||||
|
||||
bind_keys(m_bindings);
|
||||
|
||||
m_download->get_download().peer_list(m_peers);
|
||||
@@ -38,7 +39,6 @@ Download::~Download() {
|
||||
m_connPeerConnected.disconnect();
|
||||
m_connPeerDisconnected.disconnect();
|
||||
|
||||
delete m_window;
|
||||
delete m_title;
|
||||
delete m_status;
|
||||
delete m_bindings;
|
||||
@@ -46,18 +46,90 @@ Download::~Download() {
|
||||
|
||||
void
|
||||
Download::activate() {
|
||||
m_control->get_display().push_back(m_status);
|
||||
m_control->get_display().push_front(m_window);
|
||||
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_control->get_input().push_front(m_bindings);
|
||||
|
||||
activate_display(DISPLAY_MAIN);
|
||||
}
|
||||
|
||||
void
|
||||
Download::disable() {
|
||||
if (m_window == m_control->get_display().end())
|
||||
throw std::logic_error("ui::Download::disable() called on an already disabled object");
|
||||
|
||||
disable_display();
|
||||
|
||||
m_control->get_display().erase(m_window);
|
||||
m_control->get_display().erase(m_title);
|
||||
m_control->get_display().erase(m_status);
|
||||
|
||||
m_control->get_input().erase(m_bindings);
|
||||
|
||||
m_window = m_control->get_display().end();
|
||||
}
|
||||
|
||||
void
|
||||
Download::activate_display(Display d) {
|
||||
WPeerList* wpl;
|
||||
WPeerInfo* wpi;
|
||||
|
||||
if (m_window == m_control->get_display().end())
|
||||
throw std::logic_error("ui::Download::activate_display(...) could not find previous display iterator");
|
||||
|
||||
switch (d) {
|
||||
case DISPLAY_MAIN:
|
||||
*m_window = wpl = new WPeerList(&m_peers, &m_focus);
|
||||
|
||||
wpl->slot_chunks_total(sigc::mem_fun(m_download->get_download(), &torrent::Download::get_chunks_total));
|
||||
|
||||
(*m_bindings)[KEY_RIGHT] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_PEER);
|
||||
break;
|
||||
|
||||
case DISPLAY_PEER:
|
||||
*m_window = wpi = new WPeerInfo(&m_peers, &m_focus);
|
||||
|
||||
wpi->slot_chunks_total(sigc::mem_fun(m_download->get_download(), &torrent::Download::get_chunks_total));
|
||||
|
||||
(*m_bindings)[' '] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::logic_error("ui::Download::activate_display(...) got wrong state");
|
||||
}
|
||||
|
||||
m_state = d;
|
||||
|
||||
m_control->get_display().adjust_layout();
|
||||
}
|
||||
|
||||
// Does not delete disabled window.
|
||||
void
|
||||
Download::disable_display() {
|
||||
switch (m_state) {
|
||||
case DISPLAY_MAIN:
|
||||
m_bindings->erase(KEY_RIGHT);
|
||||
|
||||
break;
|
||||
|
||||
case DISPLAY_PEER:
|
||||
m_bindings->erase(' ');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
delete *m_window;
|
||||
|
||||
*m_window = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -105,6 +177,16 @@ Download::receive_throttle(int t) {
|
||||
torrent::set(torrent::THROTTLE_ROOT_CONST_RATE, torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) + t * 1024);
|
||||
}
|
||||
|
||||
void
|
||||
Download::receive_change(Display d) {
|
||||
if (d == m_state)
|
||||
return;
|
||||
|
||||
disable_display();
|
||||
|
||||
activate_display(d);
|
||||
}
|
||||
|
||||
void
|
||||
Download::bind_keys(input::Bindings* b) {
|
||||
(*b)['a'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 1);
|
||||
@@ -120,7 +202,7 @@ Download::bind_keys(input::Bindings* b) {
|
||||
|
||||
void
|
||||
Download::mark_dirty() {
|
||||
m_window->mark_dirty();
|
||||
(*m_window)->mark_dirty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+24
-5
@@ -5,36 +5,52 @@
|
||||
#include <torrent/peer.h>
|
||||
#include <sigc++/connection.h>
|
||||
|
||||
#include "core/download_list.h"
|
||||
|
||||
namespace display {
|
||||
class WindowTitle;
|
||||
class WindowPeerInfo;
|
||||
class WindowPeerList;
|
||||
class WindowStatusbar;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Control;
|
||||
|
||||
class Download {
|
||||
public:
|
||||
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::DownloadList::iterator DPtr;
|
||||
|
||||
typedef core::Download* DPtr;
|
||||
typedef std::list<torrent::Peer> PList;
|
||||
typedef display::Manager::iterator MItr;
|
||||
|
||||
// We own 'window'.
|
||||
Download(DPtr d, Control* c);
|
||||
~Download();
|
||||
|
||||
WPeerList& get_window() { return *m_window; }
|
||||
//WPeerList& get_window() { return *m_window; }
|
||||
input::Bindings& get_bindings() { return *m_bindings; }
|
||||
|
||||
void activate();
|
||||
void disable();
|
||||
|
||||
void activate_display(Display d);
|
||||
void disable_display();
|
||||
|
||||
private:
|
||||
Download(const Download&);
|
||||
void operator = (const Download&);
|
||||
@@ -46,6 +62,7 @@ private:
|
||||
void receive_peer_disconnected(torrent::Peer p);
|
||||
|
||||
void receive_throttle(int t);
|
||||
void receive_change(Display d);
|
||||
|
||||
void bind_keys(input::Bindings* b);
|
||||
|
||||
@@ -55,7 +72,9 @@ private:
|
||||
PList m_peers;
|
||||
PList::iterator m_focus;
|
||||
|
||||
WPeerList* m_window;
|
||||
Display m_state;
|
||||
MItr m_window;
|
||||
|
||||
WTitle* m_title;
|
||||
WStatus* m_status;
|
||||
|
||||
|
||||
@@ -77,14 +77,15 @@ DownloadList::receive_view_download() {
|
||||
if (m_focus == m_list->end())
|
||||
return;
|
||||
|
||||
if (m_download != NULL)
|
||||
throw std::logic_error("DownloadList::receive_view_download() called but m_download != NULL");
|
||||
|
||||
disable();
|
||||
|
||||
m_download = new Download(m_focus, m_control);
|
||||
m_download = new Download(&*m_focus, m_control);
|
||||
|
||||
m_download->get_bindings()[KEY_LEFT] = sigc::mem_fun(*this, &DownloadList::receive_exit_download);
|
||||
m_download->activate();
|
||||
|
||||
m_control->get_display().adjust_layout();
|
||||
m_download->get_bindings()[KEY_LEFT] = sigc::mem_fun(*this, &DownloadList::receive_exit_download);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user