From 8d36f7c374f125b649e58bfeef04a40c6c585ac9 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Thu, 3 Mar 2005 21:27:27 +0000 Subject: [PATCH] Created a root ui. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@321 e378c898-3ddf-0310-93e7-cc216c733640 --- src/main.cc | 46 +++++++++++------------------------------- src/ui/Makefile.am | 4 +++- src/ui/download_list.h | 5 +++++ src/ui/root.cc | 37 +++++++++++++++++++++++++++++++++ src/ui/root.h | 33 ++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 src/ui/root.cc create mode 100644 src/ui/root.h diff --git a/src/main.cc b/src/main.cc index 3abb19b8..e72cbe60 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,17 +17,18 @@ #include "display/canvas.h" #include "display/window.h" #include "ui/control.h" -#include "ui/download_list.h" +#include "ui/root.h" #include "input/bindings.h" + #include "utils/timer.h" #include "utils/directory.h" +#include "utils/task_schedule.h" #include "signal_handler.h" #include "option_parser.h" int64_t utils::Timer::m_cache; -bool start_shutdown = false; bool is_shutting_down = false; void do_panic(int signum); @@ -46,11 +47,6 @@ is_resized() { return r; } -void -set_shutdown() { - start_shutdown = true; -} - void do_shutdown(ui::Control* c) { if (!is_shutting_down) { @@ -66,10 +62,7 @@ do_shutdown(ui::Control* c) { // a quick shutdown. std::for_each(c->get_core().get_download_list().begin(), c->get_core().get_download_list().end(), std::mem_fun(&core::Download::close)); - } - - start_shutdown = false; } int @@ -99,21 +92,6 @@ load_arg_torrents(ui::Control* c, char** begin, char** end) { std::for_each(begin, end, std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core())); } -void -register_signals(ui::Control* c) { - SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown)); - SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV)); - SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS)); -} - -void -register_main_keys(ui::Control* c, input::Bindings* b) { - c->get_input().push_back(b); - - (*b)[KEY_RESIZE] = sigc::mem_fun(c->get_display(), &display::Manager::adjust_layout); - (*b)['\x11'] = sigc::ptr_fun(&set_shutdown); -} - void initialize_core(ui::Control* c) { c->get_core().get_poll().slot_read_stdin(sigc::mem_fun(c->get_input(), &input::Manager::pressed)); @@ -125,25 +103,22 @@ initialize_core(ui::Control* c) { int main(int argc, char** argv) { ui::Control uiControl; - input::Bindings inputMain; + ui::Root uiRoot(&uiControl); utils::Timer::update(); try { - register_signals(&uiControl); + SignalHandler::set_handler(SIGINT, sigc::bind(sigc::mem_fun(uiRoot, &ui::Root::set_shutdown_received), true)); + SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV)); + SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS)); int firstArg = parse_options(&uiControl, argc, argv); display::Canvas::init(); display::Window::slot_adjust(sigc::mem_fun(uiControl.get_display(), &display::Manager::adjust_layout)); - ui::DownloadList uiDownloadList(&uiControl); - - uiDownloadList.activate(); - uiDownloadList.slot_open_uri(sigc::mem_fun(uiControl.get_core(), &core::Manager::insert)); - - register_main_keys(&uiControl, &inputMain); + uiRoot.init(); initialize_core(&uiControl); @@ -153,8 +128,10 @@ main(int argc, char** argv) { uiControl.get_display().adjust_layout(); while (!is_shutting_down || !torrent::get(torrent::SHUTDOWN_DONE)) { - if (start_shutdown) + if (uiRoot.get_shutdown_received()) { do_shutdown(&uiControl); + uiRoot.set_shutdown_received(false); + } utils::Timer::update(); utils::TaskSchedule::perform(utils::Timer::cache()); @@ -166,6 +143,7 @@ main(int argc, char** argv) { uiControl.get_core().get_poll().poll(utils::TaskSchedule::get_timeout()); } + uiRoot.cleanup(); display::Canvas::cleanup(); } catch (std::exception& e) { diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 21834afd..526b8e05 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -5,6 +5,8 @@ libsub_ui_a_SOURCES = \ download.cc \ download.h \ download_list.cc \ - download_list.h + download_list.h \ + root.cc \ + root.h INCLUDES = -I$(srcdir) -I$(srcdir)/.. -I$(top_srcdir) diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 5454bb1b..b89f0006 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -3,8 +3,13 @@ #include +#include "core/download_list.h" #include "utils/task.h" +namespace input { + class Bindings; +} + namespace display { class WindowDownloadList; class WindowHttpQueue; diff --git a/src/ui/root.cc b/src/ui/root.cc new file mode 100644 index 00000000..94762dd4 --- /dev/null +++ b/src/ui/root.cc @@ -0,0 +1,37 @@ +#include "config.h" + +#include + +#include "control.h" +#include "download_list.h" + +#include "root.h" + +namespace ui { + +void +Root::init() { + setup_keys(); + + m_downloadList = new DownloadList(m_control); + + m_downloadList->activate(); + m_downloadList->slot_open_uri(sigc::mem_fun(m_control->get_core(), &core::Manager::insert)); +} + +void +Root::cleanup() { + delete m_downloadList; + + m_control->get_input().erase(&m_bindings); +} + +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); +} + +} diff --git a/src/ui/root.h b/src/ui/root.h new file mode 100644 index 00000000..61990cba --- /dev/null +++ b/src/ui/root.h @@ -0,0 +1,33 @@ +#ifndef RTORRENT_UI_ROOT_H +#define RTORRENT_UI_ROOT_H + +#include "input/bindings.h" + +namespace ui { + +class DownloadList; + +class Root { +public: + Root(Control* c) : m_shutdownReceived(false), m_control(c), m_downloadList(NULL) {} + + void init(); + void cleanup(); + + bool get_shutdown_received() { return m_shutdownReceived; } + void set_shutdown_received(bool v) { m_shutdownReceived = v; } + +private: + void setup_keys(); + + bool m_shutdownReceived; + + Control* m_control; + DownloadList* m_downloadList; + + input::Bindings m_bindings; +}; + +} + +#endif