diff --git a/configure.ac b/configure.ac index 629ae467..1d1cb4ab 100644 --- a/configure.ac +++ b/configure.ac @@ -47,7 +47,7 @@ AC_DEFINE(HAVE_CONFIG_H, 1, true if config.h was included) AC_OUTPUT([ Makefile src/Makefile + src/core/Makefile src/display/Makefile - src/engine/Makefile src/input/Makefile ]) diff --git a/src/Makefile.am b/src/Makefile.am index 1caa0d15..c730a4f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,13 +1,13 @@ SUBDIRS = \ + core \ display \ - engine \ input bin_PROGRAMS = rtorrent rtorrent_LDADD = \ + $(top_srcdir)/src/core/libsub_core.a \ $(top_srcdir)/src/display/libsub_display.a \ - $(top_srcdir)/src/engine/libsub_engine.a \ $(top_srcdir)/src/input/libsub_input.a rtorrent_SOURCES = \ diff --git a/src/engine/Makefile.am b/src/core/Makefile.am similarity index 75% rename from src/engine/Makefile.am rename to src/core/Makefile.am index 686bb44f..6475469a 100644 --- a/src/engine/Makefile.am +++ b/src/core/Makefile.am @@ -1,6 +1,6 @@ -noinst_LIBRARIES = libsub_engine.a +noinst_LIBRARIES = libsub_core.a -libsub_engine_a_SOURCES = \ +libsub_core_a_SOURCES = \ curl_get.cc \ curl_get.h \ curl_stack.cc \ diff --git a/src/engine/curl_get.cc b/src/core/curl_get.cc similarity index 99% rename from src/engine/curl_get.cc rename to src/core/curl_get.cc index 6301c9ef..d14f775b 100644 --- a/src/engine/curl_get.cc +++ b/src/core/curl_get.cc @@ -8,7 +8,7 @@ #include "curl_get.h" #include "curl_stack.h" -namespace engine { +namespace core { CurlGet::~CurlGet() { close(); diff --git a/src/engine/curl_get.h b/src/core/curl_get.h similarity index 93% rename from src/engine/curl_get.h rename to src/core/curl_get.h index d89e0a14..03736d5e 100644 --- a/src/engine/curl_get.h +++ b/src/core/curl_get.h @@ -1,5 +1,5 @@ -#ifndef RTORRENT_ENGINE_CURL_GET_H -#define RTORRENT_ENGINE_CURL_GET_H +#ifndef RTORRENT_CORE_CURL_GET_H +#define RTORRENT_CORE_CURL_GET_H #include #include @@ -9,7 +9,7 @@ struct CURLMsg; -namespace engine { +namespace core { class CurlGet : public torrent::Http { public: diff --git a/src/engine/curl_stack.cc b/src/core/curl_stack.cc similarity index 99% rename from src/engine/curl_stack.cc rename to src/core/curl_stack.cc index 32f40889..3f6f5c51 100644 --- a/src/engine/curl_stack.cc +++ b/src/core/curl_stack.cc @@ -8,7 +8,7 @@ #include "curl_get.h" #include "curl_stack.h" -namespace engine { +namespace core { template struct _equal { diff --git a/src/engine/curl_stack.h b/src/core/curl_stack.h similarity index 87% rename from src/engine/curl_stack.h rename to src/core/curl_stack.h index 7efeb25f..640edf0e 100644 --- a/src/engine/curl_stack.h +++ b/src/core/curl_stack.h @@ -1,9 +1,9 @@ -#ifndef RTORRENT_ENGINE_CURL_STACK_H -#define RTORRENT_ENGINE_CURL_STACK_H +#ifndef RTORRENT_CORE_CURL_STACK_H +#define RTORRENT_CORE_CURL_STACK_H #include -namespace engine { +namespace core { class CurlStack { public: diff --git a/src/engine/download.h b/src/core/download.h similarity index 89% rename from src/engine/download.h rename to src/core/download.h index 4a0d6221..e9d80bff 100644 --- a/src/engine/download.h +++ b/src/core/download.h @@ -1,10 +1,10 @@ -#ifndef RTORRENT_ENGINE_DOWNLOAD_H -#define RTORRENT_ENGINE_DOWNLOAD_H +#ifndef RTORRENT_CORE_DOWNLOAD_H +#define RTORRENT_CORE_DOWNLOAD_H #include #include -namespace engine { +namespace core { class Download { public: diff --git a/src/engine/download_list.cc b/src/core/download_list.cc similarity index 97% rename from src/engine/download_list.cc rename to src/core/download_list.cc index e7d5456f..fb288b91 100644 --- a/src/engine/download_list.cc +++ b/src/core/download_list.cc @@ -7,7 +7,7 @@ #include "download_list.h" -namespace engine { +namespace core { DownloadList::iterator DownloadList::create(std::istream& str) { diff --git a/src/engine/download_list.h b/src/core/download_list.h similarity index 83% rename from src/engine/download_list.h rename to src/core/download_list.h index d316c99e..c44e778b 100644 --- a/src/engine/download_list.h +++ b/src/core/download_list.h @@ -1,11 +1,11 @@ -#ifndef RTORRENT_ENGINE_DOWNLOAD_LIST_H -#define RTORRENT_ENGINE_DOWNLOAD_LIST_H +#ifndef RTORRENT_CORE_DOWNLOAD_LIST_H +#define RTORRENT_CORE_DOWNLOAD_LIST_H #include #include "download.h" -namespace engine { +namespace core { class DownloadList : private std::list { public: diff --git a/src/core/downloads.cc b/src/core/downloads.cc new file mode 100644 index 00000000..dcaf9526 --- /dev/null +++ b/src/core/downloads.cc @@ -0,0 +1,23 @@ +#include "config.h" + +#include + +#include "downloads.h" + +namespace engine { + +void +Downloads::create(std::istream& str) { + torrent::Download d = torrent::download_create(str); + + Base::push_back(d); +} + +void +Downloads::erase(iterator itr) { + torrent::download_remove(itr->get_hash()); + + Base::erase(itr); +} + +} diff --git a/src/core/downloads.h b/src/core/downloads.h new file mode 100644 index 00000000..03ffa34c --- /dev/null +++ b/src/core/downloads.h @@ -0,0 +1,29 @@ +#ifndef RTORRENT_ENGINE_DOWNLOADS_H +#define RTORRENT_ENGINE_DOWNLOADS_H + +#include +#include + +namespace engine { + +class Downloads : private std::list { +public: + typedef std::list Base; + + using Base::iterator; + using Base::const_iterator; + using Base::reverse_iterator; + using Base::const_reverse_iterator; + + using Base::begin; + using Base::end; + using Base::rbegin; + using Base::rend; + + void create(std::istream& str); + void erase(iterator itr); +}; + +} + +#endif diff --git a/src/engine/poll.cc b/src/core/poll.cc similarity index 90% rename from src/engine/poll.cc rename to src/core/poll.cc index f5ec033d..532bbfae 100644 --- a/src/engine/poll.cc +++ b/src/core/poll.cc @@ -8,7 +8,7 @@ #include "poll.h" #include "curl_get.h" -namespace engine { +namespace core { void Poll::poll() { @@ -57,7 +57,7 @@ Poll::work() { void Poll::register_http() { - torrent::Http::set_factory(sigc::bind(sigc::ptr_fun(&engine::CurlGet::new_object), &m_curlStack)); + torrent::Http::set_factory(sigc::bind(sigc::ptr_fun(&core::CurlGet::new_object), &m_curlStack)); } } diff --git a/src/engine/poll.h b/src/core/poll.h similarity index 88% rename from src/engine/poll.h rename to src/core/poll.h index 8cc7579a..383f1a33 100644 --- a/src/engine/poll.h +++ b/src/core/poll.h @@ -1,12 +1,12 @@ -#ifndef RTORRENT_ENGINE_POLL_H -#define RTORRENT_ENGINE_POLL_H +#ifndef RTORRENT_CORE_POLL_H +#define RTORRENT_CORE_POLL_H #include #include #include "curl_stack.h" -namespace engine { +namespace core { class Poll { public: diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index a992fb8f..82276c91 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -3,13 +3,14 @@ #include "canvas.h" #include "window_download_list.h" -#include "engine/download_list.h" - namespace display { -WindowDownloadList::WindowDownloadList(engine::DownloadList* d) : +WindowDownloadList::WindowDownloadList(List* d) : Window(new Canvas, true), m_downloads(d) { + + if (m_downloads) + m_focus = m_downloads->end(); } void @@ -21,14 +22,14 @@ WindowDownloadList::redraw() { // Remember to check for end of screen too. - for (engine::DownloadList::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr) { + for (List::iterator itr = m_downloads->begin(); itr != m_downloads->end(); ++itr) { m_canvas->print(0, pos++, "%c %s", - false ? '*' : ' ', + 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", - false ? '*' : ' ', + 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, @@ -37,14 +38,14 @@ WindowDownloadList::redraw() { else m_canvas->print(0, pos++, "%c Torrent: Done %.1f MiB Rate:%5.1f /%5.1f KiB Uploaded: %.1f MiB", - false ? '*' : ' ', + 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", - false ? '*' : ' ', + itr == m_focus ? '*' : ' ', itr->get_download().is_tracker_busy() ? 'C' : ' ', (int)(itr->get_download().get_tracker_timeout() / 1000000), ""); diff --git a/src/display/window_download_list.h b/src/display/window_download_list.h index 8bba82ef..8e8c323b 100644 --- a/src/display/window_download_list.h +++ b/src/display/window_download_list.h @@ -2,21 +2,24 @@ #define RTORRENT_DISPLAY_WINDOW_DOWNLOAD_LIST_H #include "window.h" - -namespace engine { - class DownloadList; -} +#include "core/download_list.h" namespace display { class WindowDownloadList : public Window { public: - WindowDownloadList(engine::DownloadList* d); + typedef core::DownloadList List; - virtual void redraw(); + WindowDownloadList(List* d); + + List::iterator get_focus() { return m_focus; } + void set_focus(core::DownloadList::iterator itr) { m_focus = itr; } + + virtual void redraw(); private: - engine::DownloadList* m_downloads; + List* m_downloads; + List::iterator m_focus; }; } diff --git a/src/main.cc b/src/main.cc index a44b8efa..f9914276 100644 --- a/src/main.cc +++ b/src/main.cc @@ -10,8 +10,8 @@ #include "display/window_title.h" #include "display/window_download_list.h" -#include "engine/poll.h" -#include "engine/download_list.h" +#include "core/poll.h" +#include "core/download_list.h" #include "input/bindings.h" #include "input/manager.h" @@ -21,8 +21,8 @@ bool start_shutdown = false; bool is_shutting_down = false; -engine::Poll poll; -engine::DownloadList downloads; +core::Poll poll; +core::DownloadList downloads; display::Manager displayManager; input::Manager inputManager; @@ -42,7 +42,7 @@ do_shutdown() { torrent::listen_close(); - std::for_each(downloads.begin(), downloads.end(), std::mem_fun_ref(&engine::Download::stop)); + std::for_each(downloads.begin(), downloads.end(), std::mem_fun_ref(&core::Download::stop)); } int @@ -56,8 +56,10 @@ main(int argc, char** argv) { poll.slot_read_stdin(sigc::mem_fun(inputManager, &input::Manager::pressed)); poll.register_http(); + display::WindowDownloadList* wdl = new display::WindowDownloadList(&downloads); + displayManager.push_back(new display::WindowTitle); - displayManager.push_back(new display::WindowDownloadList(&downloads)); + displayManager.push_back(wdl); torrent::initialize(); torrent::listen_open(6880, 6999); @@ -65,10 +67,12 @@ main(int argc, char** argv) { for (int i = 1; i < argc; ++i) { std::fstream f(argv[i], std::ios::in); - engine::DownloadList::iterator itr = downloads.create(f); + core::DownloadList::iterator itr = downloads.create(f); itr->open(); itr->hash_check(); + + wdl->set_focus(itr); } SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown));