mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 06:39:23 +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:
+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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user