diff --git a/Makefile.am b/Makefile.am index 2b32e79f..2dfbb58c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,8 +4,6 @@ SUBDIRS = \ EXTRA_DIST= \ autogen.sh \ - doc/rtorrent.1.txt \ - doc/rtorrent.rc \ rak/algorithm.h \ rak/functional.h \ scripts/checks.m4 \ diff --git a/configure.ac b/configure.ac index 67ab0510..d378ba96 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.2.6, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.2.7, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -20,7 +20,7 @@ TORRENT_CHECK_EXECINFO() TORRENT_CHECK_CURL() TORRENT_OTFD() -PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.6.6, +PKG_CHECK_MODULES(STUFF, sigc++-2.0 libtorrent >= 0.6.7, CXXFLAGS="$CXXFLAGS $STUFF_CFLAGS $CURL_CFLAGS"; LIBS="$LIBS $STUFF_LIBS $CURL_LIBS") diff --git a/doc/Makefile.am b/doc/Makefile.am index e04f1780..faa9719d 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1 +1,7 @@ man_MANS = rtorrent.1 + +EXTRA_DIST= \ + faq.xml \ + rtorrent.1 \ + rtorrent.1.xml \ + rtorrent.rc diff --git a/doc/rtorrent.1.xml b/doc/rtorrent.1.xml index fb7fe775..d41de58b 100644 --- a/doc/rtorrent.1.xml +++ b/doc/rtorrent.1.xml @@ -352,7 +352,7 @@ - port = a-b + port_range = a-b Try to open a listening port in the range a up to and including @@ -360,6 +360,13 @@ + + port_random = yes | no + + Open the listening port at a random position in the port range. + + + check_hash = yes | no diff --git a/doc/rtorrent.rc b/doc/rtorrent.rc index f61bef0e..21af8b37 100644 --- a/doc/rtorrent.rc +++ b/doc/rtorrent.rc @@ -34,7 +34,10 @@ #bind = 127.0.0.1 # Port range to use for listening. -#port = 6890-6999 +#port_range = 6890-6999 + +# Start opening ports at a random position within the port range. +#port_random = no # Check hash for finished torrents. Might be usefull until the bug is # fixed that causes lack of diskspace not to be properly reported. diff --git a/src/core/download.cc b/src/core/download.cc index ae9e428e..4ddf7eb6 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -22,12 +22,13 @@ #include "config.h" -#include "download.h" - +#include #include #include #include +#include "download.h" + namespace core { void diff --git a/src/core/download.h b/src/core/download.h index 53901816..07e93c9e 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -43,6 +43,8 @@ public: void set_root_directory(const std::string& d); + // Helper functions for calling functions in torrent::Download + // through sigc++. template void call() { (m_download.*func)(); } diff --git a/src/core/manager.cc b/src/core/manager.cc index 4d832123..7697483b 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -50,13 +50,11 @@ Manager::initialize() { m_httpQueue.slot_factory(m_poll.get_http_factory()); CurlStack::init(); - - if (!torrent::listen_open(m_portFirst, m_portLast)) - throw std::runtime_error("Could not open port for listening."); + listen_open(); // Register slots to be called when a download is inserted/erased, // opened or closed. - m_downloadList.slot_map_insert().insert("2_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front))); + m_downloadList.slot_map_insert().insert("1_connect_network_log", sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front))); m_downloadList.slot_map_insert().insert("3_manager_start", sigc::mem_fun(*this, &Manager::start)); m_downloadList.slot_map_insert().insert("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save)); @@ -76,6 +74,8 @@ Manager::initialize() { m_downloadList.slot_map_stop().insert("1_download_stop", sigc::mem_fun(&Download::call)); m_downloadList.slot_map_stop().insert("2_hash_resume_save", sigc::mem_fun(&Download::call)); m_downloadList.slot_map_stop().insert("3_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save)); + + m_downloadList.slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(*this, &Manager::receive_download_done), false)); } void @@ -145,16 +145,7 @@ Manager::check_hash(Download* d) { bool restart = d->get_download().is_active(); try { - m_downloadList.close(d); - d->get_download().hash_resume_clear(); - m_downloadList.open(d); - - if (d->get_download().is_hash_checking() || - d->get_download().is_hash_checked()) - throw std::logic_error("Manager::check_hash(...) closed the torrent but is_hash_check{ing,ed}() == true"); - - if (m_hashQueue.find(d) != m_hashQueue.end()) - throw std::logic_error("Manager::check_hash(...) closed the torrent but it was found in m_hashQueue"); + prepare_hash_check(d); if (restart) m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d)); @@ -167,6 +158,39 @@ Manager::check_hash(Download* d) { } } +void +Manager::receive_download_done(Download* d, bool check_hash) { + if (check_hash) { + // Start the hash checking, send completed to tracker after + // finishing. + prepare_hash_check(d); + + // TODO: Need to restart the torrent. + m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(*this, &Manager::receive_download_done_hash_checked), d)); + + } else { + receive_download_done_hash_checked(d); + } +} + +void +Manager::listen_open() { + if (m_portFirst > m_portLast) + throw std::runtime_error("Invalid port range for listening"); + + if (m_portRandom) { + int boundary = m_portFirst + random() % (m_portLast - m_portFirst + 1); + + if (!torrent::listen_open(boundary, m_portLast) && + !torrent::listen_open(m_portFirst, boundary)) + throw std::runtime_error("Could not open port for listening."); + + } else { + if (!torrent::listen_open(m_portFirst, m_portLast)) + throw std::runtime_error("Could not open port for listening."); + } +} + void Manager::create_http(const std::string& uri) { core::HttpQueue::iterator itr = m_httpQueue.insert(uri); @@ -188,10 +212,34 @@ Manager::create_final(std::istream* s) { } } +void +Manager::prepare_hash_check(Download* d) { + m_downloadList.close(d); + d->get_download().hash_resume_clear(); + m_downloadList.open(d); + + if (d->get_download().is_hash_checking() || + d->get_download().is_hash_checked()) + throw std::logic_error("Manager::check_hash(...) closed the torrent but is_hash_check{ing,ed}() == true"); + + if (m_hashQueue.find(d) != m_hashQueue.end()) + throw std::logic_error("Manager::check_hash(...) closed the torrent but it was found in m_hashQueue"); +} + void Manager::receive_http_failed(std::string msg) { m_logImportant.push_front("Http download error: \"" + msg + "\""); m_logComplete.push_front("Http download error: \"" + msg + "\""); } +void +Manager::receive_download_done_hash_checked(Download* d) { + if (!d->get_download().is_active()) + m_downloadList.start(d); + + // Don't send if we did a hash check and found incompelete chunks. + //if (d->is_done()) + d->get_download().tracker_send_completed(); +} + } diff --git a/src/core/manager.h b/src/core/manager.h index 93c4b8ca..cd0532c1 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -44,7 +44,7 @@ public: typedef sigc::slot1 SlotReady; typedef sigc::slot0 SlotFailed; - Manager() : m_portFirst(6890), m_portLast(6999) {} + Manager() : m_portRandom(false), m_portFirst(6890), m_portLast(6999) {} DownloadList& get_download_list() { return m_downloadList; } DownloadStore& get_download_store() { return m_downloadStore; } @@ -55,6 +55,9 @@ public: Log& get_log_important() { return m_logImportant; } Log& get_log_complete() { return m_logComplete; } + void set_port_random(bool v) { m_portRandom = v; } + void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; } + void initialize(); void cleanup(); @@ -66,14 +69,18 @@ public: void check_hash(Download* d); - void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; } + void receive_download_done(Download* d, bool check_hash); private: + void listen_open(); + void create_http(const std::string& uri); void create_final(std::istream* s); - void receive_debug_tracker(std::istream* s); + void prepare_hash_check(Download* d); + void receive_http_failed(std::string msg); + void receive_download_done_hash_checked(Download* d); DownloadList m_downloadList; DownloadStore m_downloadStore; @@ -84,6 +91,7 @@ private: Log m_logImportant; Log m_logComplete; + bool m_portRandom; int m_portFirst; int m_portLast; }; diff --git a/src/input/bindings.h b/src/input/bindings.h index e4ee50cb..3a4140d5 100644 --- a/src/input/bindings.h +++ b/src/input/bindings.h @@ -31,7 +31,8 @@ namespace input { class Bindings : private std::map > { public: - typedef std::map > Base; + typedef sigc::slot0 Slot; + typedef std::map Base; using Base::iterator; using Base::const_iterator; @@ -50,13 +51,15 @@ public: Bindings() : m_active(true) {} - void activate() { m_active = true; } - void disable() { m_active = false; } + void activate() { m_active = true; } + void disable() { m_active = false; } - bool pressed(int key); + bool pressed(int key); + + void ignore(int key) { (*this)[key] = Slot(); } private: - bool m_active; + bool m_active; }; } diff --git a/src/main.cc b/src/main.cc index 5bbe37a7..d8cd5018 100644 --- a/src/main.cc +++ b/src/main.cc @@ -107,7 +107,7 @@ parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** arg optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(*optionHandler, &OptionHandler::process), "bind")); optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(*optionHandler, &OptionHandler::process), "directory")); optionParser.insert_option('i', sigc::bind<0>(sigc::mem_fun(*optionHandler, &OptionHandler::process), "ip")); - optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(*optionHandler, &OptionHandler::process), "port")); + optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(*optionHandler, &OptionHandler::process), "port_range")); optionParser.insert_option('s', sigc::bind<0>(sigc::mem_fun(*optionHandler, &OptionHandler::process), "session")); optionParser.insert_option_list('o', sigc::mem_fun(*optionHandler, &OptionHandler::process)); @@ -126,7 +126,8 @@ initialize_option_handler(ui::Control* c, OptionHandler* optionHandler) { optionHandler->insert("bind", new OptionHandlerString(c, &apply_bind, &validate_ip)); optionHandler->insert("ip", new OptionHandlerString(c, &apply_ip, &validate_ip)); - optionHandler->insert("port", new OptionHandlerString(c, &apply_port_range, &validate_port_range)); + optionHandler->insert("port_range", new OptionHandlerString(c, &apply_port_range, &validate_port_range)); + optionHandler->insert("port_random", new OptionHandlerString(c, &apply_port_random, &validate_yes_no)); optionHandler->insert("check_hash", new OptionHandlerString(c, &apply_check_hash, &validate_yes_no)); optionHandler->insert("directory", new OptionHandlerString(c, &apply_download_directory, &validate_directory)); diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index 6156ccab..eefbcc61 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -144,6 +144,11 @@ apply_port_range(ui::Control* m, const std::string& arg) { m->get_core().set_port_range(a, b); } +void +apply_port_random(ui::Control* m, const std::string& arg) { + m->get_core().set_port_random(arg == "yes"); +} + void apply_tracker_dump(ui::Control* m, const std::string& arg) { if (arg == "yes") @@ -155,9 +160,9 @@ apply_tracker_dump(ui::Control* m, const std::string& arg) { void apply_check_hash(ui::Control* m, const std::string& arg) { if (arg == "yes") - m->get_core().get_download_list().slot_map_finished().insert("1_check_hash", sigc::mem_fun(m->get_core(), &core::Manager::check_hash)); + m->get_core().get_download_list().slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(m->get_core(), &core::Manager::receive_download_done), true)); else - m->get_core().get_download_list().slot_map_finished().erase("1_check_hash"); + m->get_core().get_download_list().slot_map_finished().insert("1_download_done", sigc::bind(sigc::mem_fun(m->get_core(), &core::Manager::receive_download_done), false)); } void diff --git a/src/option_handler_rules.h b/src/option_handler_rules.h index 109f3de2..26cd99fc 100644 --- a/src/option_handler_rules.h +++ b/src/option_handler_rules.h @@ -59,6 +59,7 @@ void apply_max_open_files(ui::Control* m, int arg); void apply_ip(ui::Control* m, const std::string& arg); void apply_bind(ui::Control* m, const std::string& arg); void apply_port_range(ui::Control* m, const std::string& arg); +void apply_port_random(ui::Control* m, const std::string& arg); void apply_tracker_dump(ui::Control* m, const std::string& arg); void apply_check_hash(ui::Control* m, const std::string& arg); diff --git a/src/ui/download.cc b/src/ui/download.cc index cb242465..ce3eeb2a 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -31,7 +31,6 @@ #include "input/bindings.h" #include "display/window_title.h" #include "display/window_download_statusbar.h" -#include "display/window_statusbar.h" #include "control.h" #include "download.h" @@ -48,7 +47,6 @@ Download::Download(DPtr d, Control* c) : m_windowTitle(new WTitle(d->get_download().get_name())), m_windowDownloadStatus(new WDownloadStatus(d)), - m_windowMainStatus(new WMainStatus(&c->get_core())), m_window(c->get_display().end()), @@ -83,7 +81,6 @@ Download::~Download() { delete m_windowTitle; delete m_windowDownloadStatus; - delete m_windowMainStatus; } void @@ -91,11 +88,9 @@ Download::activate() { if (m_window != m_control->get_display().end()) throw std::logic_error("ui::Download::activate() called on an already activated object"); + m_control->get_display().push_front(m_windowDownloadStatus); m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL); - - 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_display().push_front(m_windowTitle); m_control->get_input().push_front(m_bindings); @@ -112,7 +107,6 @@ Download::disable() { m_control->get_display().erase(m_window); m_control->get_display().erase(m_windowTitle); m_control->get_display().erase(m_windowDownloadStatus); - m_control->get_display().erase(m_windowMainStatus); m_window = m_control->get_display().end(); @@ -180,20 +174,6 @@ Download::receive_peer_disconnected(torrent::Peer p) { m_peers.erase(itr); } -void -Download::receive_read_throttle(int t) { - m_windowMainStatus->mark_dirty(); - - torrent::set_read_throttle(torrent::get_read_throttle() + t * 1024); -} - -void -Download::receive_write_throttle(int t) { - m_windowMainStatus->mark_dirty(); - - torrent::set_write_throttle(torrent::get_write_throttle() + t * 1024); -} - void Download::receive_max_uploads(int t) { m_windowDownloadStatus->mark_dirty(); @@ -236,20 +216,6 @@ Download::receive_snub_peer() { void Download::bind_keys() { - (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), 1); - (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), -1); - (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), 5); - (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), -5); - (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), 50); - (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_write_throttle), -50); - - (*m_bindings)['A'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), 1); - (*m_bindings)['Z'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), -1); - (*m_bindings)['S'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), 5); - (*m_bindings)['X'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), -5); - (*m_bindings)['D'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), 50); - (*m_bindings)['C'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_read_throttle), -50); - (*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); diff --git a/src/ui/download.h b/src/ui/download.h index 0e57a506..bdd43e8c 100644 --- a/src/ui/download.h +++ b/src/ui/download.h @@ -47,7 +47,6 @@ class ElementBase; class Download { public: typedef display::WindowTitle WTitle; - typedef display::WindowStatusbar WMainStatus; typedef display::WindowDownloadStatusbar WDownloadStatus; typedef core::Download* DPtr; @@ -83,8 +82,6 @@ private: void receive_peer_connected(torrent::Peer p); void receive_peer_disconnected(torrent::Peer p); - void receive_read_throttle(int t); - void receive_write_throttle(int t); void receive_max_uploads(int t); void receive_min_peers(int t); void receive_max_peers(int t); @@ -106,7 +103,6 @@ private: WTitle* m_windowTitle; WDownloadStatus* m_windowDownloadStatus; - WMainStatus* m_windowMainStatus; MItr m_window; diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 5d5a200c..474a9953 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -36,7 +36,6 @@ #include "display/window_http_queue.h" #include "display/window_input.h" #include "display/window_log.h" -#include "display/window_statusbar.h" #include "display/window_title.h" #include "control.h" @@ -54,7 +53,6 @@ DownloadList::DownloadList(Control* c) : m_window(c->get_display().end()), m_windowTitle(new WTitle("rTorrent " VERSION " - libTorrent " + torrent::get_version())), - m_windowStatus(new WStatus(&c->get_core())), m_windowHttpQueue(new WHttp(&c->get_core().get_http_queue())), m_uiDownload(NULL), @@ -82,7 +80,6 @@ DownloadList::~DownloadList() { std::for_each(m_uiArray, m_uiArray + DISPLAY_MAX_SIZE, rak::call_delete()); delete m_windowTitle; - delete m_windowStatus; delete m_bindings; delete m_windowLog; @@ -100,14 +97,12 @@ DownloadList::activate() { m_windowTextInput->set_active(false); + m_control->get_display().push_front(m_windowTextInput); + m_control->get_display().push_front(m_windowHttpQueue); + m_control->get_display().push_front(m_windowLog); m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL); m_control->get_display().push_front(m_windowTitle); - m_control->get_display().push_back(m_windowLog); - m_control->get_display().push_back(m_windowHttpQueue); - m_control->get_display().push_back(m_windowTextInput); - m_control->get_display().push_back(m_windowStatus); - m_control->get_input().push_front(m_bindings); activate_display(DISPLAY_DOWNLOAD_LIST); @@ -129,7 +124,6 @@ DownloadList::disable() { m_control->get_display().erase(m_window); m_control->get_display().erase(m_windowTitle); - m_control->get_display().erase(m_windowStatus); m_control->get_display().erase(m_windowTextInput); m_control->get_display().erase(m_windowLog); m_control->get_display().erase(m_windowHttpQueue); @@ -172,20 +166,6 @@ DownloadList::receive_prev() { m_downloadList.dec_focus(); } -void -DownloadList::receive_read_throttle(int t) { - m_windowStatus->mark_dirty(); - - torrent::set_read_throttle(torrent::get_read_throttle() + t * 1024); -} - -void -DownloadList::receive_write_throttle(int t) { - m_windowStatus->mark_dirty(); - - torrent::set_write_throttle(torrent::get_write_throttle() + t * 1024); -} - void DownloadList::receive_start_download() { if (m_downloadList.get_focus() == m_downloadList.end()) @@ -245,7 +225,7 @@ DownloadList::receive_check_hash() { void DownloadList::receive_view_input() { - m_windowStatus->set_active(false); + //m_windowStatus->set_active(false); m_windowTextInput->set_active(true); m_control->get_display().adjust_layout(); @@ -259,7 +239,7 @@ DownloadList::receive_view_input() { void DownloadList::receive_exit_input() { - m_windowStatus->set_active(true); + //m_windowStatus->set_active(true); m_windowTextInput->set_active(false); m_control->get_input().set_text_input(); @@ -293,20 +273,6 @@ DownloadList::task_update() { void DownloadList::setup_keys() { - (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), 1); - (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), -1); - (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), 5); - (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), -5); - (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), 50); - (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_write_throttle), -50); - - (*m_bindings)['A'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), 1); - (*m_bindings)['Z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), -1); - (*m_bindings)['S'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), 5); - (*m_bindings)['X'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), -5); - (*m_bindings)['D'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), 50); - (*m_bindings)['C'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_read_throttle), -50); - (*m_bindings)['\x13'] = sigc::mem_fun(*this, &DownloadList::receive_start_download); (*m_bindings)['\x04'] = sigc::mem_fun(*this, &DownloadList::receive_stop_download); (*m_bindings)['\x12'] = sigc::mem_fun(*this, &DownloadList::receive_check_hash); diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 1e1716ea..398005d6 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -39,7 +39,6 @@ namespace display { class WindowInput; class WindowLog; class WindowLogComplete; - class WindowStatusbar; class WindowTitle; } @@ -56,7 +55,6 @@ public: typedef display::WindowInput WInput; typedef display::WindowLog WLog; typedef display::WindowLogComplete WLogComplete; - typedef display::WindowStatusbar WStatus; typedef display::WindowTitle WTitle; typedef utils::ListFocus DList; @@ -94,9 +92,6 @@ private: void receive_next(); void receive_prev(); - void receive_read_throttle(int t); - void receive_write_throttle(int t); - void receive_start_download(); void receive_stop_download(); @@ -122,7 +117,6 @@ private: MItr m_window; WTitle* m_windowTitle; - WStatus* m_windowStatus; WLog* m_windowLog; WInput* m_windowTextInput; WHttp* m_windowHttpQueue; diff --git a/src/ui/element_tracker_list.cc b/src/ui/element_tracker_list.cc index b0eb8315..4f2ae555 100644 --- a/src/ui/element_tracker_list.cc +++ b/src/ui/element_tracker_list.cc @@ -97,7 +97,7 @@ ElementTrackerList::receive_cycle_group() { if (m_focus >= m_download->get_download().get_tracker_size()) throw std::logic_error("ui::ElementTrackerList::receive_group_cycle(...) called with an invalid focus"); - m_download->get_download().cycle_tracker_group(m_download->get_download().get_tracker(m_focus).get_group()); + m_download->get_download().tracker_cycle_group(m_download->get_download().get_tracker(m_focus).get_group()); m_window->mark_dirty(); } diff --git a/src/ui/root.cc b/src/ui/root.cc index 36eb4432..4a6e2190 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -22,21 +22,37 @@ #include "config.h" +#include #include +#include #include "control.h" #include "download_list.h" +#include "display/window_statusbar.h" #include "root.h" namespace ui { +Root::Root(Control* c) : + m_shutdownReceived(false), + m_control(c), + m_downloadList(NULL), + m_windowStatus(NULL) { +} + void Root::init() { + if (m_downloadList != NULL) + throw std::logic_error("Root::init() called twice on the same object"); + setup_keys(); + m_windowStatus = new WStatus(&m_control->get_core()); m_downloadList = new DownloadList(m_control); + m_control->get_display().push_back(m_windowStatus); + m_downloadList->activate(); m_downloadList->slot_open_uri(sigc::mem_fun(m_control->get_core(), &core::Manager::insert)); } @@ -46,7 +62,10 @@ Root::cleanup() { if (m_downloadList->is_active()) m_downloadList->disable(); + m_control->get_display().erase(m_windowStatus); + delete m_downloadList; + delete m_windowStatus; m_control->get_input().erase(&m_bindings); } @@ -55,8 +74,36 @@ void Root::setup_keys() { m_control->get_input().push_back(&m_bindings); - m_bindings[KEY_RESIZE] = sigc::mem_fun(m_control->get_display(), &display::Manager::adjust_layout); - m_bindings['\x11'] = sigc::bind(sigc::mem_fun(*this, &Root::set_shutdown_received), true); + m_bindings['a'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_write_throttle), 1); + m_bindings['z'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_write_throttle), -1); + m_bindings['s'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_write_throttle), 5); + m_bindings['x'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_write_throttle), -5); + m_bindings['d'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_write_throttle), 50); + m_bindings['c'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_write_throttle), -50); + + m_bindings['A'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), 1); + m_bindings['Z'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), -1); + m_bindings['S'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), 5); + m_bindings['X'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), -5); + m_bindings['D'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), 50); + m_bindings['C'] = sigc::bind(sigc::mem_fun(*this, &Root::receive_read_throttle), -50); + + m_bindings[KEY_RESIZE] = sigc::mem_fun(m_control->get_display(), &display::Manager::adjust_layout); + m_bindings['\x11'] = sigc::bind(sigc::mem_fun(*this, &Root::set_shutdown_received), true); +} + +void +Root::receive_read_throttle(int t) { + //m_downloadList->mark_dirty(); + + torrent::set_read_throttle(torrent::get_read_throttle() + t * 1024); +} + +void +Root::receive_write_throttle(int t) { + //m_downloadList->mark_dirty(); + + torrent::set_write_throttle(torrent::get_write_throttle() + t * 1024); } } diff --git a/src/ui/root.h b/src/ui/root.h index a17ee560..5736ce38 100644 --- a/src/ui/root.h +++ b/src/ui/root.h @@ -25,29 +25,40 @@ #include "input/bindings.h" +namespace display { + class WindowStatusbar; +} + namespace ui { class DownloadList; class Root { public: - Root(Control* c) : m_shutdownReceived(false), m_control(c), m_downloadList(NULL) {} + typedef display::WindowStatusbar WStatus; - void init(); - void cleanup(); + Root(Control* c); - bool get_shutdown_received() { return m_shutdownReceived; } - void set_shutdown_received(bool v) { m_shutdownReceived = v; } + void init(); + void cleanup(); + + bool get_shutdown_received() { return m_shutdownReceived; } + void set_shutdown_received(bool v) { m_shutdownReceived = v; } private: - void setup_keys(); + void setup_keys(); - bool m_shutdownReceived; + void receive_read_throttle(int t); + void receive_write_throttle(int t); - Control* m_control; - DownloadList* m_downloadList; + bool m_shutdownReceived; - input::Bindings m_bindings; + Control* m_control; + DownloadList* m_downloadList; + + WStatus* m_windowStatus; + + input::Bindings m_bindings; }; }