From f664e1ce0c279855b8da28dca21f193e4bb0e70f Mon Sep 17 00:00:00 2001 From: rakshasa Date: Thu, 10 Mar 2005 18:59:24 +0000 Subject: [PATCH] Adding view of tracker list. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@338 e378c898-3ddf-0310-93e7-cc216c733640 --- README | 2 + configure.ac | 4 +- src/display/Makefile.am | 4 +- src/display/window_download_list.cc | 4 +- src/display/window_tracker_list.cc | 55 +++++++++++++++++++++++ src/display/window_tracker_list.h | 32 +++++++++++++ src/main.cc | 2 + src/ui/Makefile.am | 4 +- src/ui/download.cc | 24 ++++++++-- src/ui/download.h | 5 ++- src/ui/tracker_list.cc | 70 +++++++++++++++++++++++++++++ src/ui/tracker_list.h | 44 ++++++++++++++++++ 12 files changed, 240 insertions(+), 10 deletions(-) create mode 100644 src/display/window_tracker_list.cc create mode 100644 src/display/window_tracker_list.h create mode 100644 src/ui/tracker_list.cc create mode 100644 src/ui/tracker_list.h diff --git a/README b/README index 78367c1e..826b8bc0 100644 --- a/README +++ b/README @@ -41,6 +41,8 @@ In torrent view: Left - Back to main Right - View files + P - View peer + O - View trackers 1 - Decrease max uploads 2 - Increase max uploads diff --git a/configure.ac b/configure.ac index 7f7b289f..b3e30bfd 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.1.2, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.1.3, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -39,7 +39,7 @@ TORRENT_CHECK_EXECINFO() TORRENT_CHECK_CURL() TORRENT_OTFD() -PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.5.1, +PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.5.2, CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS $CURL_CFLAGS"; LIBS="$LIBS $STUFF_LIBS $CURL_LIBS") diff --git a/src/display/Makefile.am b/src/display/Makefile.am index 68eca0b3..008c09ec 100644 --- a/src/display/Makefile.am +++ b/src/display/Makefile.am @@ -28,6 +28,8 @@ libsub_display_a_SOURCES = \ window_statusbar.cc \ window_statusbar.h \ window_title.cc \ - window_title.h + window_title.h \ + window_tracker_list.cc \ + window_tracker_list.h INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir) diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index b87e1ee7..81c1b37f 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -47,14 +47,14 @@ WindowDownloadList::redraw() { d.get_name().c_str()); if ((*range.first)->is_open() && (*range.first)->is_done()) - m_canvas->print(0, pos++, "%c Torrent: Done %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB", + m_canvas->print(0, pos++, "%c Torrent: Done %10.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB", range.first == *m_focus ? '*' : ' ', (double)d.get_bytes_total() / (double)(1 << 20), (double)d.get_rate_up() / 1024.0, (double)d.get_rate_down() / 1024.0, (double)d.get_bytes_up() / (double)(1 << 20)); else - m_canvas->print(0, pos++, "%c Torrent: %.1f / %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB", + m_canvas->print(0, pos++, "%c Torrent: %6.1f / %6.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB", range.first == *m_focus ? '*' : ' ', (double)d.get_bytes_done() / (double)(1 << 20), (double)d.get_bytes_total() / (double)(1 << 20), diff --git a/src/display/window_tracker_list.cc b/src/display/window_tracker_list.cc new file mode 100644 index 00000000..aff450ce --- /dev/null +++ b/src/display/window_tracker_list.cc @@ -0,0 +1,55 @@ +#include "config.h" + +#include + +#include "core/download.h" +#include "rak/algorithm.h" + +#include "window_tracker_list.h" + +namespace display { + +WindowTrackerList::WindowTrackerList(core::Download* d, unsigned int* focus) : + Window(new Canvas, true), + m_download(d), + m_focus(focus) { +} + +void +WindowTrackerList::redraw() { + // TODO: Make this depend on tracker signal. + m_nextDraw = utils::Timer::cache().round_seconds() + 10 * 1000000; + m_canvas->erase(); + + int pos = 0; + + m_canvas->print( 2, pos, "Trackers:"); + + ++pos; + + if (m_download->get_download().get_tracker_size() == 0) + return; + + if (*m_focus >= m_download->get_download().get_tracker_size()) + throw std::logic_error("WindowTrackerList::redraw() called on an object with a bad focus value"); + + typedef std::pair Range; + + Range range = rak::advance_bidirectional(0, + *m_focus, + m_download->get_download().get_tracker_size(), + m_canvas->get_height()); + + while (range.first != range.second) { + torrent::Tracker t = m_download->get_download().get_tracker(range.first); + + m_canvas->print(0, pos, "%c %s", + range.first == *m_focus ? '*' : ' ', + t.get_url().c_str()); + + ++range.first; + ++pos; + } +} + +} diff --git a/src/display/window_tracker_list.h b/src/display/window_tracker_list.h new file mode 100644 index 00000000..22b079c0 --- /dev/null +++ b/src/display/window_tracker_list.h @@ -0,0 +1,32 @@ +#ifndef RTORRENT_DISPLAY_TRACKER_LIST_H +#define RTORRENT_DISPLAY_TRACKER_LIST_H + +#include + +#include "window.h" + +namespace torrent { + class Tracker; +} + +namespace core { + class Download; +} + +namespace display { + +class WindowTrackerList : public Window { +public: + WindowTrackerList(core::Download* d, unsigned int* focus); + + virtual void redraw(); + +private: + core::Download* m_download; + + unsigned int* m_focus; +}; + +} + +#endif diff --git a/src/main.cc b/src/main.cc index 372baee2..f7248360 100644 --- a/src/main.cc +++ b/src/main.cc @@ -214,7 +214,9 @@ print_help() { std::cout << " 1,2 Adjust max uploads" << std::endl; std::cout << " 3,4,5,6 Adjust min/max connected peers" << std::endl; std::cout << " t Query tracker for more peers" << std::endl; + std::cout << " right View files" << std::endl; std::cout << " p View peer information" << std::endl; + std::cout << " o View trackers" << std::endl; std::cout << std::endl; std::cout << "Report bugs to ." << std::endl; diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 3b2bc95d..4e034954 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -9,6 +9,8 @@ libsub_ui_a_SOURCES = \ file_list.cc \ file_list.h \ root.cc \ - root.h + root.h \ + tracker_list.cc \ + tracker_list.h INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir) diff --git a/src/ui/download.cc b/src/ui/download.cc index af48464e..4649b267 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -15,6 +15,7 @@ #include "control.h" #include "download.h" #include "file_list.h" +#include "tracker_list.h" namespace ui { @@ -23,6 +24,7 @@ Download::Download(DPtr d, Control* c) : m_state(DISPLAY_NONE), m_uiFileList(NULL), + m_uiTrackerList(NULL), m_title(c->get_display().end()), m_window(c->get_display().end()), @@ -60,7 +62,8 @@ Download::activate() { 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_uiFileList = new FileList(m_control, m_download); + m_uiTrackerList = new TrackerList(m_control, m_download); m_control->get_input().push_front(m_bindings); @@ -84,8 +87,10 @@ Download::disable() { 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(); @@ -104,8 +109,9 @@ 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)['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: @@ -120,6 +126,12 @@ Download::activate_display(Display d) { 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: throw std::logic_error("ui::Download::activate_display(...) got wrong state"); } @@ -134,7 +146,7 @@ void Download::disable_display() { switch (m_state) { case DISPLAY_MAIN: - m_bindings->erase(KEY_RIGHT); + //m_bindings->erase(KEY_RIGHT); break; @@ -149,6 +161,12 @@ Download::disable_display() { return; + case DISPLAY_TRACKER_LIST: + m_uiTrackerList->disable(); + *m_window = NULL; + + return; + default: break; } diff --git a/src/ui/download.h b/src/ui/download.h index 625c67b3..5a20e00c 100644 --- a/src/ui/download.h +++ b/src/ui/download.h @@ -21,6 +21,7 @@ namespace ui { class Control; class FileList; +class TrackerList; class Download { public: @@ -39,7 +40,8 @@ public: DISPLAY_NONE, DISPLAY_MAIN, DISPLAY_PEER, - DISPLAY_FILE_LIST + DISPLAY_FILE_LIST, + DISPLAY_TRACKER_LIST } Display; // We own 'window'. @@ -82,6 +84,7 @@ private: Display m_state; FileList* m_uiFileList; + TrackerList* m_uiTrackerList; MItr m_title; MItr m_window; diff --git a/src/ui/tracker_list.cc b/src/ui/tracker_list.cc new file mode 100644 index 00000000..6de85ae3 --- /dev/null +++ b/src/ui/tracker_list.cc @@ -0,0 +1,70 @@ +#include "config.h" + +#include + +#include "display/window_tracker_list.h" + +#include "control.h" +#include "tracker_list.h" + +namespace ui { + +TrackerList::TrackerList(Control* c, core::Download* d) : + m_download(d), + m_window(NULL), + m_control(c), + m_focus(0) { + + m_bindings[KEY_DOWN] = sigc::mem_fun(*this, &TrackerList::receive_next); + m_bindings[KEY_UP] = sigc::mem_fun(*this, &TrackerList::receive_prev); +} + +void +TrackerList::activate(MItr mItr) { + if (m_window != NULL) + throw std::logic_error("ui::TrackerList::activate(...) called on an object in the wrong state"); + + m_control->get_input().push_front(&m_bindings); + + *mItr = m_window = new WTrackerList(m_download, &m_focus); +} + +void +TrackerList::disable() { + if (m_window == NULL) + throw std::logic_error("ui::TrackerList::disable(...) called on an object in the wrong state"); + + m_control->get_input().erase(&m_bindings); + + delete m_window; + m_window = NULL; +} + +void +TrackerList::receive_next() { + if (m_window == NULL) + throw std::logic_error("ui::TrackerList::receive_next(...) called on a disabled object"); + + if (++m_focus >= m_download->get_download().get_tracker_size()) + m_focus = 0; + + m_window->mark_dirty(); +} + +void +TrackerList::receive_prev() { + if (m_window == NULL) + throw std::logic_error("ui::TrackerList::receive_prev(...) called on a disabled object"); + + if (m_download->get_download().get_tracker_size() == 0) + return; + + if (m_focus != 0) + --m_focus; + else + m_focus = m_download->get_download().get_tracker_size() - 1; + + m_window->mark_dirty(); +} + +} diff --git a/src/ui/tracker_list.h b/src/ui/tracker_list.h new file mode 100644 index 00000000..6b4b30a9 --- /dev/null +++ b/src/ui/tracker_list.h @@ -0,0 +1,44 @@ +#ifndef RTORRENT_UI_TRACKER_LIST_H +#define RTORRENT_UI_TRACKER_LIST_H + +#include "core/download.h" +#include "display/manager.h" +#include "input/bindings.h" + +namespace display { + class WindowTrackerList; +} + +namespace ui { + +class Control; + +class TrackerList { +public: + typedef display::WindowTrackerList WTrackerList; + typedef display::Manager::iterator MItr; + + TrackerList(Control* c, core::Download* d); + + void activate(MItr mItr); + void disable(); + + input::Bindings& get_bindings() { return m_bindings; } + +private: + void receive_next(); + void receive_prev(); + + core::Download* m_download; + WTrackerList* m_window; + + Control* m_control; + input::Bindings m_bindings; + + // Change to unsigned, please. + unsigned int m_focus; +}; + +} + +#endif