Adding view of tracker list.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@338 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-03-10 18:59:24 +00:00
parent a4dbdffcb8
commit f664e1ce0c
12 changed files with 240 additions and 10 deletions
+2
View File
@@ -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
+2 -2
View File
@@ -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")
+3 -1
View File
@@ -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)
+2 -2
View File
@@ -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),
+55
View File
@@ -0,0 +1,55 @@
#include "config.h"
#include <stdexcept>
#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<unsigned int, unsigned int> Range;
Range range = rak::advance_bidirectional<unsigned int>(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;
}
}
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef RTORRENT_DISPLAY_TRACKER_LIST_H
#define RTORRENT_DISPLAY_TRACKER_LIST_H
#include <list>
#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
+2
View File
@@ -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 <jaris@ifi.uio.no>." << std::endl;
+3 -1
View File
@@ -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)
+21 -3
View File
@@ -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;
}
+4 -1
View File
@@ -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;
+70
View File
@@ -0,0 +1,70 @@
#include "config.h"
#include <stdexcept>
#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();
}
}
+44
View File
@@ -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