Focus iterators moved out of Window*.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@254 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-02-05 20:36:22 +00:00
parent e02974571a
commit ecb2fc7d57
12 changed files with 122 additions and 59 deletions
+25 -9
View File
@@ -6,6 +6,7 @@
#include "input/bindings.h"
#include "display/window_title.h"
#include "display/window_peer_list.h"
#include "display/window_statusbar.h"
#include "control.h"
#include "download.h"
@@ -15,10 +16,13 @@ namespace ui {
Download::Download(DPtr d, Control* c) :
m_download(d),
m_title(new WTitle(d->get_download().get_name())),
m_status(new WStatus),
m_control(c),
m_bindings(new input::Bindings) {
m_window = new WPeerList(&m_peers);
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));
(*m_bindings)[KEY_UP] = sigc::mem_fun(*this, &Download::receive_prev);
@@ -36,11 +40,13 @@ Download::~Download() {
delete m_window;
delete m_title;
delete m_status;
delete m_bindings;
}
void
Download::activate() {
m_control->get_display().push_back(m_status);
m_control->get_display().push_front(m_window);
m_control->get_display().push_front(m_title);
m_control->get_input().push_front(m_bindings);
@@ -50,23 +56,28 @@ void
Download::disable() {
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);
}
void
Download::receive_next() {
if (m_window->get_focus() == m_window->get_list().end())
m_window->set_focus(m_window->get_list().begin());
if (m_focus != m_peers.end())
++m_focus;
else
m_window->set_focus(++m_window->get_focus());
m_focus = m_peers.begin();
mark_dirty();
}
void
Download::receive_prev() {
if (m_window->get_focus() == m_window->get_list().begin())
m_window->set_focus(m_window->get_list().end());
if (m_focus != m_peers.begin())
--m_focus;
else
m_window->set_focus(--m_window->get_focus());
m_focus = m_peers.end();
mark_dirty();
}
void
@@ -81,10 +92,15 @@ Download::receive_peer_disconnected(torrent::Peer p) {
if (itr == m_peers.end())
throw std::logic_error("Download::receive_peer_disconnected(...) received a peer we don't have in our list");
if (itr == m_window->get_focus())
m_window->set_focus(m_peers.erase(itr));
if (itr == m_focus)
m_focus = m_peers.erase(itr);
else
m_peers.erase(itr);
}
void
Download::mark_dirty() {
m_window->mark_dirty();
}
}
+6
View File
@@ -10,6 +10,7 @@
namespace display {
class WindowTitle;
class WindowPeerList;
class WindowStatusbar;
}
namespace ui {
@@ -20,6 +21,7 @@ class Download {
public:
typedef display::WindowPeerList WPeerList;
typedef display::WindowTitle WTitle;
typedef display::WindowStatusbar WStatus;
typedef core::DownloadList::iterator DPtr;
typedef std::list<torrent::Peer> PList;
@@ -40,11 +42,15 @@ private:
void receive_peer_connected(torrent::Peer p);
void receive_peer_disconnected(torrent::Peer p);
void mark_dirty();
DPtr m_download;
PList m_peers;
PList::iterator m_focus;
WPeerList* m_window;
WTitle* m_title;
WStatus* m_status;
Control* m_control;
input::Bindings* m_bindings;
+41 -9
View File
@@ -2,10 +2,12 @@
#include <stdexcept>
#include <torrent/torrent.h>
#include <sigc++/bind.h>
#include "input/bindings.h"
#include "display/window_title.h"
#include "display/window_download_list.h"
#include "display/window_statusbar.h"
#include "control.h"
#include "download.h"
@@ -14,25 +16,38 @@
namespace ui {
DownloadList::DownloadList(core::DownloadList* l, Control* c) :
m_window(new WList(l)),
m_title(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))),
m_status(new WStatus),
m_download(NULL),
m_list(l),
m_focus(l->end()),
m_control(c),
m_bindings(new input::Bindings) {
m_window = new WList(m_list, &m_focus);
(*m_bindings)[KEY_UP] = sigc::mem_fun(*this, &DownloadList::receive_prev);
(*m_bindings)[KEY_DOWN] = sigc::mem_fun(*this, &DownloadList::receive_next);
(*m_bindings)[KEY_RIGHT] = sigc::mem_fun(*this, &DownloadList::receive_view_download);
(*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 1);
(*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -1);
(*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 5);
(*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -5);
(*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 50);
(*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -50);
}
DownloadList::~DownloadList() {
delete m_window;
delete m_title;
delete m_status;
delete m_bindings;
}
void
DownloadList::activate() {
m_control->get_display().push_back(m_status);
m_control->get_display().push_front(m_window);
m_control->get_display().push_front(m_title);
m_control->get_input().push_front(m_bindings);
@@ -42,33 +57,38 @@ void
DownloadList::disable() {
m_control->get_display().erase(m_title);
m_control->get_display().erase(m_window);
m_control->get_display().erase(m_status);
m_control->get_input().erase(m_bindings);
}
void
DownloadList::receive_next() {
if (m_window->get_focus() == m_window->get_list().end())
m_window->set_focus(m_window->get_list().begin());
if (m_focus != m_list->end())
++m_focus;
else
m_window->set_focus(++m_window->get_focus());
m_focus = m_list->begin();
mark_dirty();
}
void
DownloadList::receive_prev() {
if (m_window->get_focus() == m_window->get_list().begin())
m_window->set_focus(m_window->get_list().end());
if (m_focus != m_list->begin())
--m_focus;
else
m_window->set_focus(--m_window->get_focus());
m_focus = m_list->end();
mark_dirty();
}
void
DownloadList::receive_view_download() {
if (m_window->get_focus() == m_window->get_list().end())
if (m_focus == m_list->end())
return;
disable();
m_download = new Download(m_window->get_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();
@@ -90,4 +110,16 @@ DownloadList::receive_exit_download() {
m_control->get_display().adjust_layout();
}
void
DownloadList::receive_throttle(int t) {
m_status->mark_dirty();
torrent::set(torrent::THROTTLE_ROOT_CONST_RATE, torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) + t * 1024);
}
void
DownloadList::mark_dirty() {
m_window->mark_dirty();
}
}
+12 -1
View File
@@ -4,6 +4,7 @@
namespace display {
class WindowTitle;
class WindowDownloadList;
class WindowStatusbar;
}
namespace ui {
@@ -15,9 +16,11 @@ class DownloadList {
public:
typedef display::WindowDownloadList WList;
typedef display::WindowTitle WTitle;
typedef display::WindowStatusbar WStatus;
typedef core::DownloadList DList;
// We own 'window'.
DownloadList(core::DownloadList* l, Control* c);
DownloadList(DList* l, Control* c);
~DownloadList();
WList& get_window() { return *m_window; }
@@ -33,11 +36,19 @@ private:
void receive_view_download();
void receive_exit_download();
void receive_throttle(int t);
void mark_dirty();
WList* m_window;
WTitle* m_title;
WStatus* m_status;
Download* m_download;
DList* m_list;
DList::iterator m_focus;
Control* m_control;
input::Bindings* m_bindings;
};