mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-07 18:52:30 +00:00
Refactored peer info screen out into its own ui class.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@355 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -8,6 +8,8 @@ libsub_ui_a_SOURCES = \
|
||||
download_list.h \
|
||||
file_list.cc \
|
||||
file_list.h \
|
||||
peer_info.cc \
|
||||
peer_info.h \
|
||||
root.cc \
|
||||
root.h \
|
||||
tracker_list.cc \
|
||||
|
||||
+59
-60
@@ -37,6 +37,7 @@
|
||||
#include "control.h"
|
||||
#include "download.h"
|
||||
#include "file_list.h"
|
||||
#include "peer_info.h"
|
||||
#include "tracker_list.h"
|
||||
|
||||
namespace ui {
|
||||
@@ -45,20 +46,22 @@ Download::Download(DPtr d, Control* c) :
|
||||
m_download(d),
|
||||
m_state(DISPLAY_NONE),
|
||||
|
||||
m_uiFileList(NULL),
|
||||
m_uiTrackerList(NULL),
|
||||
m_uiFileList(new FileList(c, d)),
|
||||
m_uiPeerInfo(new PeerInfo(d, &m_peers, &m_focus)),
|
||||
m_uiTrackerList(new TrackerList(c, d)),
|
||||
|
||||
m_windowTitle(new WTitle(d->get_download().get_name())),
|
||||
m_windowDownloadStatus(new WDownloadStatus(d)),
|
||||
m_windowMainStatus(new WMainStatus(&c->get_core())),
|
||||
|
||||
m_title(c->get_display().end()),
|
||||
m_window(c->get_display().end()),
|
||||
m_downloadStatus(c->get_display().end()),
|
||||
m_mainStatus(c->get_display().end()),
|
||||
|
||||
m_control(c),
|
||||
m_bindings(new input::Bindings) {
|
||||
|
||||
m_focus = m_peers.end();
|
||||
|
||||
bind_keys(m_bindings);
|
||||
bind_keys();
|
||||
|
||||
m_download->get_download().peer_list(m_peers);
|
||||
|
||||
@@ -70,6 +73,14 @@ Download::~Download() {
|
||||
if (m_window != m_control->get_display().end())
|
||||
throw std::logic_error("ui::Download::~Download() called on an active object");
|
||||
|
||||
delete m_uiFileList;
|
||||
delete m_uiPeerInfo;
|
||||
delete m_uiTrackerList;
|
||||
|
||||
delete m_windowTitle;
|
||||
delete m_windowDownloadStatus;
|
||||
delete m_windowMainStatus;
|
||||
|
||||
m_connPeerConnected.disconnect();
|
||||
m_connPeerDisconnected.disconnect();
|
||||
}
|
||||
@@ -80,12 +91,10 @@ Download::activate() {
|
||||
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_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_mainStatus = m_control->get_display().insert(m_control->get_display().end(), new WMainStatus(&m_control->get_core()));
|
||||
|
||||
m_uiFileList = new FileList(m_control, m_download);
|
||||
m_uiTrackerList = new TrackerList(m_control, m_download);
|
||||
m_control->get_display().insert(m_control->get_display().begin(), m_windowTitle);
|
||||
m_control->get_display().insert(m_control->get_display().end(), m_windowDownloadStatus);
|
||||
m_control->get_display().insert(m_control->get_display().end(), m_windowMainStatus);
|
||||
|
||||
m_control->get_input().push_front(m_bindings);
|
||||
|
||||
@@ -100,21 +109,11 @@ Download::disable() {
|
||||
disable_display();
|
||||
|
||||
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_mainStatus);
|
||||
m_control->get_display().erase(m_windowTitle);
|
||||
m_control->get_display().erase(m_windowDownloadStatus);
|
||||
m_control->get_display().erase(m_windowMainStatus);
|
||||
|
||||
delete *m_title;
|
||||
delete *m_downloadStatus;
|
||||
delete *m_mainStatus;
|
||||
|
||||
delete m_uiFileList;
|
||||
delete m_uiTrackerList;
|
||||
|
||||
m_uiFileList = NULL;
|
||||
m_uiTrackerList = NULL;
|
||||
|
||||
m_window = m_title = m_downloadStatus = m_mainStatus = m_control->get_display().end();
|
||||
m_window = m_control->get_display().end();
|
||||
|
||||
m_control->get_input().erase(m_bindings);
|
||||
}
|
||||
@@ -122,7 +121,6 @@ Download::disable() {
|
||||
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");
|
||||
@@ -131,27 +129,19 @@ Download::activate_display(Display d) {
|
||||
case DISPLAY_MAIN:
|
||||
*m_window = wpl = new WPeerList(m_download, &m_peers, &m_focus);
|
||||
|
||||
(*m_bindings)['p'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_PEER);
|
||||
(*m_bindings)[KEY_RIGHT] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_FILE_LIST);
|
||||
(*m_bindings)['o'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_TRACKER_LIST);
|
||||
break;
|
||||
|
||||
case DISPLAY_PEER:
|
||||
*m_window = wpi = new WPeerInfo(m_download, &m_peers, &m_focus);
|
||||
|
||||
(*m_bindings)[' '] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
m_uiPeerInfo->activate(m_control, m_window);
|
||||
break;
|
||||
|
||||
case DISPLAY_FILE_LIST:
|
||||
m_uiFileList->activate(m_window);
|
||||
m_uiFileList->get_bindings()[KEY_LEFT] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
|
||||
break;
|
||||
|
||||
case DISPLAY_TRACKER_LIST:
|
||||
m_uiTrackerList->activate(m_window);
|
||||
m_uiTrackerList->get_bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -168,14 +158,15 @@ void
|
||||
Download::disable_display() {
|
||||
switch (m_state) {
|
||||
case DISPLAY_MAIN:
|
||||
//m_bindings->erase(KEY_RIGHT);
|
||||
m_bindings->erase(KEY_RIGHT);
|
||||
|
||||
break;
|
||||
|
||||
case DISPLAY_PEER:
|
||||
m_bindings->erase(' ');
|
||||
|
||||
break;
|
||||
m_uiPeerInfo->disable(m_control);
|
||||
*m_window = NULL;
|
||||
|
||||
return;
|
||||
|
||||
case DISPLAY_FILE_LIST:
|
||||
m_uiFileList->disable();
|
||||
@@ -190,7 +181,7 @@ Download::disable_display() {
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
throw std::logic_error("ui::Download::disable_display() is in an invalid state");
|
||||
}
|
||||
|
||||
// urgh, get ui's for the rest too.
|
||||
@@ -239,28 +230,28 @@ Download::receive_peer_disconnected(torrent::Peer p) {
|
||||
|
||||
void
|
||||
Download::receive_throttle(int t) {
|
||||
(*m_mainStatus)->mark_dirty();
|
||||
m_windowMainStatus->mark_dirty();
|
||||
|
||||
torrent::set(torrent::THROTTLE_ROOT_CONST_RATE, torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) + t * 1024);
|
||||
}
|
||||
|
||||
void
|
||||
Download::receive_max_uploads(int t) {
|
||||
(*m_downloadStatus)->mark_dirty();
|
||||
m_windowDownloadStatus->mark_dirty();
|
||||
|
||||
m_download->get_download().set_uploads_max(std::max(m_download->get_download().get_uploads_max() + t, (uint32_t)2));
|
||||
}
|
||||
|
||||
void
|
||||
Download::receive_min_peers(int t) {
|
||||
(*m_downloadStatus)->mark_dirty();
|
||||
m_windowDownloadStatus->mark_dirty();
|
||||
|
||||
m_download->get_download().set_peers_min(std::max(m_download->get_download().get_peers_min() + t, (uint32_t)5));
|
||||
}
|
||||
|
||||
void
|
||||
Download::receive_max_peers(int t) {
|
||||
(*m_downloadStatus)->mark_dirty();
|
||||
m_windowDownloadStatus->mark_dirty();
|
||||
|
||||
m_download->get_download().set_peers_max(std::max(m_download->get_download().get_peers_max() + t, (uint32_t)5));
|
||||
}
|
||||
@@ -276,25 +267,33 @@ Download::receive_change(Display d) {
|
||||
}
|
||||
|
||||
void
|
||||
Download::bind_keys(input::Bindings* b) {
|
||||
(*b)['a'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 1);
|
||||
(*b)['z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -1);
|
||||
(*b)['s'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 5);
|
||||
(*b)['x'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -5);
|
||||
(*b)['d'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 50);
|
||||
(*b)['c'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -50);
|
||||
Download::bind_keys() {
|
||||
(*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 1);
|
||||
(*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -1);
|
||||
(*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 5);
|
||||
(*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -5);
|
||||
(*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), 50);
|
||||
(*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_throttle), -50);
|
||||
|
||||
(*b)['1'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), -1);
|
||||
(*b)['2'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), 1);
|
||||
(*b)['3'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_min_peers), -5);
|
||||
(*b)['4'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_min_peers), 5);
|
||||
(*b)['5'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_peers), -5);
|
||||
(*b)['6'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_peers), 5);
|
||||
(*m_bindings)['1'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), -1);
|
||||
(*m_bindings)['2'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), 1);
|
||||
(*m_bindings)['3'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_min_peers), -5);
|
||||
(*m_bindings)['4'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_min_peers), 5);
|
||||
(*m_bindings)['5'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_peers), -5);
|
||||
(*m_bindings)['6'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_peers), 5);
|
||||
|
||||
(*b)['t'] = sigc::bind(sigc::mem_fun(m_download->get_download(), &torrent::Download::set_tracker_timeout), 2 * 1000000);
|
||||
(*m_bindings)['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);
|
||||
(*m_bindings)['p'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_PEER);
|
||||
(*m_bindings)['o'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_TRACKER_LIST);
|
||||
|
||||
(*m_bindings)[KEY_UP] = sigc::mem_fun(*this, &Download::receive_prev);
|
||||
(*m_bindings)[KEY_DOWN] = sigc::mem_fun(*this, &Download::receive_next);
|
||||
|
||||
// Key bindings for sub-ui's.
|
||||
m_uiFileList->get_bindings()[KEY_LEFT] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
m_uiPeerInfo->get_bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
m_uiTrackerList->get_bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &Download::receive_change), DISPLAY_MAIN);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+33
-33
@@ -29,7 +29,6 @@
|
||||
|
||||
namespace display {
|
||||
class WindowTitle;
|
||||
class WindowPeerInfo;
|
||||
class WindowStatusbar;
|
||||
class WindowPeerList;
|
||||
class WindowDownloadStatusbar;
|
||||
@@ -43,12 +42,12 @@ namespace ui {
|
||||
|
||||
class Control;
|
||||
class FileList;
|
||||
class PeerInfo;
|
||||
class TrackerList;
|
||||
|
||||
class Download {
|
||||
public:
|
||||
typedef display::Window Window;
|
||||
typedef display::WindowPeerInfo WPeerInfo;
|
||||
typedef display::WindowPeerList WPeerList;
|
||||
typedef display::WindowTitle WTitle;
|
||||
typedef display::WindowStatusbar WMainStatus;
|
||||
@@ -70,54 +69,55 @@ public:
|
||||
Download(DPtr d, Control* c);
|
||||
~Download();
|
||||
|
||||
//WPeerList& get_window() { return *m_window; }
|
||||
input::Bindings& get_bindings() { return *m_bindings; }
|
||||
input::Bindings& get_bindings() { return *m_bindings; }
|
||||
|
||||
void activate();
|
||||
void disable();
|
||||
void activate();
|
||||
void disable();
|
||||
|
||||
void activate_display(Display d);
|
||||
void disable_display();
|
||||
void activate_display(Display d);
|
||||
void disable_display();
|
||||
|
||||
private:
|
||||
Download(const Download&);
|
||||
void operator = (const Download&);
|
||||
|
||||
void receive_next();
|
||||
void receive_prev();
|
||||
void receive_next();
|
||||
void receive_prev();
|
||||
|
||||
void receive_peer_connected(torrent::Peer p);
|
||||
void receive_peer_disconnected(torrent::Peer p);
|
||||
void receive_peer_connected(torrent::Peer p);
|
||||
void receive_peer_disconnected(torrent::Peer p);
|
||||
|
||||
void receive_throttle(int t);
|
||||
void receive_max_uploads(int t);
|
||||
void receive_min_peers(int t);
|
||||
void receive_max_peers(int t);
|
||||
void receive_change(Display d);
|
||||
void receive_throttle(int t);
|
||||
void receive_max_uploads(int t);
|
||||
void receive_min_peers(int t);
|
||||
void receive_max_peers(int t);
|
||||
void receive_change(Display d);
|
||||
|
||||
void bind_keys(input::Bindings* b);
|
||||
void bind_keys();
|
||||
|
||||
void mark_dirty();
|
||||
void mark_dirty();
|
||||
|
||||
DPtr m_download;
|
||||
PList m_peers;
|
||||
PList::iterator m_focus;
|
||||
DPtr m_download;
|
||||
PList m_peers;
|
||||
PList::iterator m_focus;
|
||||
|
||||
Display m_state;
|
||||
Display m_state;
|
||||
|
||||
FileList* m_uiFileList;
|
||||
TrackerList* m_uiTrackerList;
|
||||
FileList* m_uiFileList;
|
||||
PeerInfo* m_uiPeerInfo;
|
||||
TrackerList* m_uiTrackerList;
|
||||
|
||||
MItr m_title;
|
||||
MItr m_window;
|
||||
MItr m_downloadStatus;
|
||||
MItr m_mainStatus;
|
||||
WTitle* m_windowTitle;
|
||||
WDownloadStatus* m_windowDownloadStatus;
|
||||
WMainStatus* m_windowMainStatus;
|
||||
|
||||
Control* m_control;
|
||||
input::Bindings* m_bindings;
|
||||
MItr m_window;
|
||||
|
||||
sigc::connection m_connPeerConnected;
|
||||
sigc::connection m_connPeerDisconnected;
|
||||
Control* m_control;
|
||||
input::Bindings* m_bindings;
|
||||
|
||||
sigc::connection m_connPeerConnected;
|
||||
sigc::connection m_connPeerDisconnected;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "display/window_peer_info.h"
|
||||
|
||||
#include "control.h"
|
||||
#include "peer_info.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
PeerInfo::PeerInfo(core::Download* d, PList* l, PList::iterator* f) :
|
||||
m_download(d),
|
||||
m_window(NULL),
|
||||
m_list(l),
|
||||
m_focus(f) {
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
PeerInfo::activate(Control* c, MItr mItr) {
|
||||
if (m_window != NULL)
|
||||
throw std::logic_error("ui::PeerInfo::activate(...) called on an object in the wrong state");
|
||||
|
||||
c->get_input().push_front(&m_bindings);
|
||||
|
||||
*mItr = m_window = new WPeerInfo(m_download, m_list, m_focus);
|
||||
}
|
||||
|
||||
void
|
||||
PeerInfo::disable(Control* c) {
|
||||
if (m_window == NULL)
|
||||
throw std::logic_error("ui::PeerInfo::disable(...) called on an object in the wrong state");
|
||||
|
||||
c->get_input().erase(&m_bindings);
|
||||
|
||||
delete m_window;
|
||||
m_window = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_UI_PEER_INFO_H
|
||||
#define RTORRENT_UI_PEER_INFO_H
|
||||
|
||||
#include "core/download.h"
|
||||
#include "display/manager.h"
|
||||
#include "input/bindings.h"
|
||||
|
||||
namespace display {
|
||||
class WindowPeerInfo;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Control;
|
||||
|
||||
class PeerInfo {
|
||||
public:
|
||||
typedef display::WindowPeerInfo WPeerInfo;
|
||||
typedef display::Manager::iterator MItr;
|
||||
typedef std::list<torrent::Peer> PList;
|
||||
|
||||
PeerInfo(core::Download* d, PList* l, PList::iterator* f);
|
||||
|
||||
void activate(Control* c, MItr mItr);
|
||||
void disable(Control* c);
|
||||
|
||||
input::Bindings& get_bindings() { return m_bindings; }
|
||||
|
||||
private:
|
||||
core::Download* m_download;
|
||||
WPeerInfo* m_window;
|
||||
|
||||
input::Bindings m_bindings;
|
||||
|
||||
PList* m_list;
|
||||
PList::iterator* m_focus;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user