From e3a0730b33c54699e2cb75fac07e1ba7ae78cadd Mon Sep 17 00:00:00 2001 From: rakshasa Date: Wed, 16 Feb 2005 20:03:40 +0000 Subject: [PATCH] Hide/show input and status bar depending on whetever input has focus. Added removal of downloads. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@283 e378c898-3ddf-0310-93e7-cc216c733640 --- src/core/download_list.cc | 2 -- src/core/manager.cc | 12 ++++++++++ src/core/manager.h | 1 + src/input/text_input.cc | 19 ++++++++-------- src/main.cc | 19 +++++++++------- src/ui/download_list.cc | 46 ++++++++++++++++++++++++++------------- src/ui/download_list.h | 4 +--- 7 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 72a37adb..ee22a869 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -15,7 +15,6 @@ DownloadList::insert(std::istream* str) { torrent::Download d = torrent::download_create(str); iterator itr = Base::insert(end(), Download()); - itr->set_download(d); return itr; @@ -26,7 +25,6 @@ DownloadList::erase(iterator itr) { itr->release_download(); torrent::download_remove(itr->get_hash()); - Base::erase(itr); } diff --git a/src/core/manager.cc b/src/core/manager.cc index dcfe0524..6b495b17 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -1,5 +1,6 @@ #include "config.h" +#include #include #include #include @@ -37,6 +38,17 @@ Manager::insert(const std::string& uri) { create_http(uri); } +void +Manager::erase(DownloadList::iterator itr) { + if (itr->get_download().is_active()) + throw std::logic_error("core::Manager::erase(...) called on an active download"); + + if (itr->get_download().is_open()) + itr->close(); + + m_downloadList.erase(itr); +} + void Manager::start(Download* d) { if (d->get_download().is_active()) diff --git a/src/core/manager.h b/src/core/manager.h index 5145b179..5744117c 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -23,6 +23,7 @@ public: void cleanup(); void insert(const std::string& uri); + void erase(DownloadList::iterator itr); void start(Download* d); void stop(Download* d); diff --git a/src/input/text_input.cc b/src/input/text_input.cc index e4a51729..3c1b65a8 100644 --- a/src/input/text_input.cc +++ b/src/input/text_input.cc @@ -1,15 +1,15 @@ #include "config.h" +#include #include #include "text_input.h" -#include namespace input { bool TextInput::pressed(int key) { - std::stringstream str; + //std::stringstream str; if (m_alt) { m_alt = false; @@ -32,6 +32,7 @@ TextInput::pressed(int key) { } else { switch (key) { + case 0x08: case KEY_BACKSPACE: if (m_pos != 0) Base::erase(--m_pos, 1); @@ -64,19 +65,19 @@ TextInput::pressed(int key) { break; default: - //return false; + return false; // Testcode. - if (key == KEY_ENTER || key == '\n') - return false; +// if (key == KEY_ENTER || key == '\n') +// return false; - str << "\\x" << std::hex << key; +// str << "\\x" << std::hex << key; - Base::insert(m_pos, str.str()); +// Base::insert(m_pos, str.str()); - m_pos += str.str().length(); +// m_pos += str.str().length(); - return true; +// return true; } } diff --git a/src/main.cc b/src/main.cc index 9bc602cc..955608ee 100644 --- a/src/main.cc +++ b/src/main.cc @@ -46,18 +46,21 @@ set_shutdown() { void do_shutdown(ui::Control* c) { - if (is_shutting_down) - // Be quick about it... - return; + if (!is_shutting_down) { + is_shutting_down = true; - is_shutting_down = true; + torrent::listen_close(); - torrent::listen_close(); + std::for_each(c->get_core().get_download_list().begin(), c->get_core().get_download_list().end(), + std::mem_fun_ref(&core::Download::stop)); - // TODO: Set display to a safe mode. + } else { + // Close all torrents, this will stop all tracker connections and cause + // a quick shutdown. + std::for_each(c->get_core().get_download_list().begin(), c->get_core().get_download_list().end(), + std::mem_fun_ref(&core::Download::close)); - std::for_each(c->get_core().get_download_list().begin(), c->get_core().get_download_list().end(), - std::mem_fun_ref(&core::Download::stop)); + } } void diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 193ff2c5..af7f8de5 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -20,17 +20,17 @@ namespace ui { DownloadList::DownloadList(Control* c) : m_title(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))), m_status(new WStatus), + m_textInput(new WInput(new input::TextInput)), m_download(NULL), m_focus(c->get_core().get_download_list().end()), m_control(c), - m_bindings(new input::Bindings), - m_windowInput(new WInput(new input::TextInput)) { + m_bindings(new input::Bindings) { m_window = new WList(&m_control->get_core().get_download_list(), &m_focus); bind_keys(m_bindings); - m_windowInput->get_input()->slot_dirty(sigc::mem_fun(*m_windowInput, &WInput::mark_dirty)); + m_textInput->get_input()->slot_dirty(sigc::mem_fun(*m_textInput, &WInput::mark_dirty)); } DownloadList::~DownloadList() { @@ -39,26 +39,31 @@ DownloadList::~DownloadList() { delete m_status; delete m_bindings; - delete m_windowInput->get_input(); - delete m_windowInput; + delete m_textInput->get_input(); + delete m_textInput; } void DownloadList::activate() { - m_control->get_display().push_back(m_windowInput); + m_control->get_input().push_front(m_bindings); + m_control->get_display().push_back(m_status); m_control->get_display().push_front(m_window); m_control->get_display().push_front(m_title); - m_control->get_input().push_front(m_bindings); } void DownloadList::disable() { - m_control->get_display().erase(m_windowInput); + if (m_textInput->get_focus()) { + m_textInput->get_input()->clear(); + receive_exit_input(); + } + + m_control->get_input().erase(m_bindings); + m_control->get_display().erase(m_title); m_control->get_display().erase(m_window); m_control->get_display().erase(m_status); - m_control->get_input().erase(m_bindings); } void @@ -101,7 +106,10 @@ DownloadList::receive_stop_download() { if (m_focus == m_control->get_core().get_download_list().end()) return; - m_control->get_core().stop(&*m_focus); + if (m_focus->get_download().is_active()) + m_control->get_core().stop(&*m_focus); + else + m_control->get_core().erase(m_focus); } void @@ -136,9 +144,13 @@ DownloadList::receive_exit_download() { void DownloadList::receive_view_input() { - m_control->get_input().set_text_input(m_windowInput->get_input()); + m_control->get_display().erase(m_status); + m_control->get_display().push_back(m_textInput); + m_control->get_display().adjust_layout(); - m_windowInput->set_focus(true); + m_control->get_input().set_text_input(m_textInput->get_input()); + + m_textInput->set_focus(true); (*m_bindings)['\n'] = sigc::mem_fun(*this, &DownloadList::receive_exit_input); (*m_bindings)[KEY_ENTER] = sigc::mem_fun(*this, &DownloadList::receive_exit_input); @@ -146,12 +158,16 @@ DownloadList::receive_view_input() { void DownloadList::receive_exit_input() { + m_control->get_display().erase(m_textInput); + m_control->get_display().push_back(m_status); + m_control->get_display().adjust_layout(); + m_control->get_input().set_text_input(); - m_slotOpenUri(m_windowInput->get_input()->str()); + m_slotOpenUri(m_textInput->get_input()->str()); - m_windowInput->get_input()->clear(); - m_windowInput->set_focus(false); + m_textInput->get_input()->clear(); + m_textInput->set_focus(false); m_bindings->erase('\n'); m_bindings->erase(KEY_ENTER); diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 7a55c0c9..c26f6e94 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -62,6 +62,7 @@ private: WList* m_window; WTitle* m_title; WStatus* m_status; + WInput* m_textInput; Download* m_download; @@ -72,9 +73,6 @@ private: input::Bindings* m_bindings; SlotOpenUri m_slotOpenUri; - - // Test - WInput* m_windowInput; }; }