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
+2
View File
@@ -14,6 +14,8 @@ public:
virtual ~Window() {}
bool is_dynamic() { return m_dynamic; }
bool is_dirty() { return m_lastDraw == 0; }
int get_min_height() { return m_minHeight; }
void refresh();
+8 -10
View File
@@ -5,12 +5,10 @@
namespace display {
WindowDownloadList::WindowDownloadList(DList* d) :
WindowDownloadList::WindowDownloadList(DList* l, DList::iterator* f) :
Window(new Canvas, true),
m_downloads(d) {
if (m_downloads)
m_focus = m_downloads->end();
m_list(l),
m_focus(f) {
}
void
@@ -26,14 +24,14 @@ WindowDownloadList::redraw() {
// Remember to check for end of screen too.
for (DList::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr) {
for (DList::iterator itr = m_list->begin(); itr != m_list->end(); ++itr) {
m_canvas->print(0, pos++, "%c %s",
itr == m_focus ? '*' : ' ',
itr == *m_focus ? '*' : ' ',
itr->get_download().get_name().c_str());
if (itr->get_download().get_chunks_done() != itr->get_download().get_chunks_total() || !itr->get_download().is_open())
m_canvas->print(0, pos++, "%c Torrent: %.1f / %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB",
itr == m_focus ? '*' : ' ',
itr == *m_focus ? '*' : ' ',
(double)itr->get_download().get_bytes_done() / (double)(1 << 20),
(double)itr->get_download().get_bytes_total() / (double)(1 << 20),
(double)itr->get_download().get_rate_up() / 1024.0,
@@ -42,14 +40,14 @@ WindowDownloadList::redraw() {
else
m_canvas->print(0, pos++, "%c Torrent: Done %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB",
itr == m_focus ? '*' : ' ',
itr == *m_focus ? '*' : ' ',
(double)itr->get_download().get_bytes_total() / (double)(1 << 20),
(double)itr->get_download().get_rate_up() / 1024.0,
(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",
itr == m_focus ? '*' : ' ',
itr == *m_focus ? '*' : ' ',
itr->get_download().is_tracker_busy() ? 'C' : ' ',
(int)(itr->get_download().get_tracker_timeout() / 1000000),
"");
+4 -9
View File
@@ -10,18 +10,13 @@ class WindowDownloadList : public Window {
public:
typedef core::DownloadList DList;
WindowDownloadList(DList* d);
WindowDownloadList(DList* l, DList::iterator* focus);
DList& get_list() { return *m_downloads; }
DList::iterator get_focus() { return m_focus; }
void set_focus(DList::iterator itr) { m_focus = itr; mark_dirty(); }
virtual void redraw();
virtual void redraw();
private:
DList* m_downloads;
DList::iterator m_focus;
DList* m_list;
DList::iterator* m_focus;
};
}
+5 -5
View File
@@ -7,10 +7,10 @@
namespace display {
WindowPeerList::WindowPeerList(PList* l) :
WindowPeerList::WindowPeerList(PList* l, PList::iterator* f) :
Window(new Canvas, true),
m_list(l),
m_focus(l->end()) {
m_focus(f) {
}
void
@@ -41,9 +41,9 @@ WindowPeerList::redraw() {
PList::iterator itr, last;
if (m_focus != m_list->end()) {
if (*m_focus != m_list->end()) {
int i = 0;
itr = last = m_focus;
itr = last = *m_focus;
while (i < m_canvas->get_height() - y && !(itr == m_list->begin() && last == m_list->end())) {
if (itr != m_list->begin()) {
@@ -71,7 +71,7 @@ WindowPeerList::redraw() {
x = 0;
m_canvas->print(x, y, "%c %s",
itr == m_focus ? '*' : ' ',
itr == *m_focus ? '*' : ' ',
itr->get_dns().c_str());
x += 18;
+6 -11
View File
@@ -14,22 +14,17 @@ public:
typedef std::list<torrent::Peer> PList;
typedef sigc::slot0<uint32_t> SlotChunksTotal;
WindowPeerList(PList* l);
WindowPeerList(PList* l, PList::iterator* f);
PList& get_list() { return *m_list; }
void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; }
PList::iterator get_focus() { return m_focus; }
void set_focus(PList::iterator itr) { m_focus = itr; mark_dirty(); }
void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; }
virtual void redraw();
virtual void redraw();
private:
PList* m_list;
PList::iterator m_focus;
PList* m_list;
PList::iterator* m_focus;
SlotChunksTotal m_slotChunksTotal;
SlotChunksTotal m_slotChunksTotal;
};
}
+11 -1
View File
@@ -14,8 +14,18 @@ WindowStatusbar::WindowStatusbar() :
void
WindowStatusbar::redraw() {
if (Timer::cache() - m_lastDraw < 10000000)
return;
m_lastDraw = Timer::cache();
m_canvas->erase();
m_canvas->print(0, 0, "Loop: %i", ++m_counter);
m_canvas->print(0, 0, "Throttle: %i Listen: %s:%i Handshakes: %i Select: %u",
(int)torrent::get(torrent::THROTTLE_ROOT_CONST_RATE) / 1024,
"",
(int)torrent::get(torrent::LISTEN_PORT),
(int)torrent::get(torrent::HANDSHAKES_TOTAL),
++m_counter);
}
}
+1 -4
View File
@@ -6,7 +6,6 @@
#include <sigc++/bind.h>
#include "display/canvas.h"
#include "display/window_statusbar.h"
#include "core/poll.h"
#include "core/curl_stack.h"
@@ -69,8 +68,6 @@ main(int argc, char** argv) {
ui::Control uiControl;
ui::DownloadList uiDownloadList(&downloads, &uiControl);
uiControl.get_display().push_front(new display::WindowStatusbar);
uiDownloadList.activate();
// Register main key events.
@@ -102,7 +99,7 @@ main(int argc, char** argv) {
if (is_resized())
uiControl.get_display().adjust_layout();
uiControl.get_display().do_update();
poll.poll();
+1
View File
@@ -44,6 +44,7 @@ class Timer {
bool operator > (const Timer& t) const { return m_time > t.m_time; }
bool operator <= (const Timer& t) const { return m_time <= t.m_time; }
bool operator >= (const Timer& t) const { return m_time >= t.m_time; }
bool operator == (const Timer& t) const { return m_time == t.m_time; }
private:
int64_t m_time;
+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;
};