diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index f395ecc8..37955f7e 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -147,6 +147,8 @@ DownloadFactory::receive_success() { } else { if (m_start) m_manager->start(*itr); + + m_manager->get_download_store().save(*itr); } m_slotFinished(); diff --git a/src/core/manager.cc b/src/core/manager.cc index 7e7b75ae..69e38607 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -69,7 +69,7 @@ Manager::initialize() { // opened or closed. m_downloadList.slot_map_insert().insert("0_initialize_bencode", sigc::mem_fun(*this, &Manager::initialize_bencode)); 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("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save)); + //m_downloadList.slot_map_insert().insert("4_store_save", sigc::mem_fun(m_downloadStore, &DownloadStore::save)); m_downloadList.slot_map_erase().insert("1_hash_queue_remove", sigc::mem_fun(m_hashQueue, &HashQueue::remove)); m_downloadList.slot_map_erase().insert("1_store_remove", sigc::mem_fun(m_downloadStore, &DownloadStore::remove)); @@ -149,7 +149,7 @@ Manager::start(Download* d) { if (d->get_download().is_hash_checked()) m_downloadList.start(d); else - // This can cause infinit loops. + // This can cause infinit loops? m_hashQueue.insert(d, sigc::bind(sigc::mem_fun(m_downloadList, &DownloadList::start), d)); } catch (torrent::local_error& e) { @@ -226,15 +226,13 @@ void Manager::initialize_bencode(Download* d) { torrent::Bencode& bencode = d->get_bencode(); - // TODO: Check that stuff are the right type, like state etc. - if (bencode.has_key("rtorrent") && - bencode["rtorrent"].is_map() && - bencode["rtorrent"].has_key("state") && - bencode["rtorrent"]["state"].is_string()) - return; - - bencode.insert_key("rtorrent", torrent::Bencode(torrent::Bencode::TYPE_MAP)); - bencode["rtorrent"].insert_key("state", "started"); + if (!bencode.has_key("rtorrent") || + !bencode["rtorrent"].is_map()) + bencode.insert_key("rtorrent", torrent::Bencode(torrent::Bencode::TYPE_MAP)); + + if (!bencode["rtorrent"].has_key("state") || + !bencode["rtorrent"]["state"].is_string()) + bencode["rtorrent"].insert_key("state", "started"); } void diff --git a/src/main.cc b/src/main.cc index b81867f7..1c9ce568 100644 --- a/src/main.cc +++ b/src/main.cc @@ -72,8 +72,6 @@ int64_t utils::Timer::m_cache; -bool is_shutting_down = false; - void do_panic(int signum); void print_help(); @@ -95,21 +93,6 @@ is_resized() { return r; } -void -do_shutdown(ui::Control* c) { - if (!is_shutting_down) { - is_shutting_down = true; - - torrent::listen_close(); - c->get_core().shutdown(false); - - } else { - // Close all torrents, this will stop all tracker connections and cause - // a quick shutdown. - c->get_core().shutdown(true); - } -} - int parse_options(ui::Control* c, OptionHandler* optionHandler, int argc, char** argv) { OptionParser optionParser; @@ -233,7 +216,7 @@ main(int argc, char** argv) { try { SignalHandler::set_ignore(SIGPIPE); - SignalHandler::set_handler(SIGINT, sigc::bind(sigc::mem_fun(uiControl, &ui::Control::set_shutdown_received), true)); + SignalHandler::set_handler(SIGINT, sigc::mem_fun(uiControl, &ui::Control::receive_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)); SignalHandler::set_handler(SIGFPE, sigc::bind(sigc::ptr_fun(&do_panic), SIGFPE)); @@ -256,13 +239,7 @@ main(int argc, char** argv) { uiControl.get_display().adjust_layout(); - while (!is_shutting_down || !torrent::is_inactive()) { - - if (uiControl.get_shutdown_received()) { - do_shutdown(&uiControl); - uiControl.set_shutdown_received(false); - } - + while (!uiControl.is_shutdown_completed()) { utils::Timer::update(); utils::taskScheduler.execute(utils::Timer::cache()); @@ -272,6 +249,7 @@ main(int argc, char** argv) { utils::displayScheduler.get_next_timeout() <= utils::Timer::cache()) uiControl.get_display().do_update(); + // Do shutdown check before poll, not after. uiControl.get_core().get_poll().poll(!utils::taskScheduler.empty() ? utils::taskScheduler.get_next_timeout() - utils::Timer::cache() : 60 * 1000000); diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 4dce0990..f68a852b 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -1,6 +1,7 @@ noinst_LIBRARIES = libsub_ui.a libsub_ui_a_SOURCES = \ + control.cc \ control.h \ download.cc \ download.h \ diff --git a/src/ui/control.cc b/src/ui/control.cc new file mode 100644 index 00000000..d524d175 --- /dev/null +++ b/src/ui/control.cc @@ -0,0 +1,54 @@ +// rTorrent - BitTorrent client +// Copyright (C) 2005, Jari Sundell +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// In addition, as a special exception, the copyright holders give +// permission to link the code of portions of this program with the +// OpenSSL library under certain conditions as described in each +// individual source file, and distribute linked combinations +// including the two. +// +// You must obey the GNU General Public License in all respects for +// all of the code used other than OpenSSL. If you modify file(s) +// with this exception, you may extend this exception to your version +// of the file(s), but you are not obligated to do so. If you do not +// wish to do so, delete this exception statement from your version. +// If you delete this exception statement from all source files in the +// program, then also delete it here. +// +// Contact: Jari Sundell +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#include "config.h" + +#include "control.h" + +namespace ui { + +// I think it should be safe to initiate the shutdown from anywhere, +// but if it isn't, use a delay task. +void +Control::receive_shutdown() { + if (!m_shutdownReceived) + torrent::listen_close(); + + m_core.shutdown(m_shutdownReceived); + m_shutdownReceived = true; +} + +} diff --git a/src/ui/control.h b/src/ui/control.h index 402fa59f..750d342b 100644 --- a/src/ui/control.h +++ b/src/ui/control.h @@ -37,6 +37,8 @@ #ifndef RTORRENT_UI_CONTROL_H #define RTORRENT_UI_CONTROL_H +#include + #include "core/manager.h" #include "display/manager.h" #include "input/manager.h" @@ -49,14 +51,16 @@ class Control { public: Control() : m_shutdownReceived(false) {} - bool get_shutdown_received() { return m_shutdownReceived; } - void set_shutdown_received(bool v) { m_shutdownReceived = v; } + bool is_shutdown_completed() { return m_shutdownReceived && torrent::is_inactive(); } + bool is_shutdown_received() { return m_shutdownReceived; } Root& get_ui() { return m_ui; } core::Manager& get_core() { return m_core; } display::Manager& get_display() { return m_display; } input::Manager& get_input() { return m_input; } + void receive_shutdown(); + private: Control(const Control&); void operator = (const Control&); diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 8bccc57e..d57f2cdd 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -275,6 +275,10 @@ DownloadList::receive_exit_input(bool useDefault) { m_bindings->erase('\n'); m_bindings->erase(KEY_ENTER); + // Urgh... this is ugly... + (*m_bindings)['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), false); + (*m_bindings)[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), false); + receive_change(DISPLAY_DOWNLOAD_LIST); } diff --git a/src/ui/root.cc b/src/ui/root.cc index a1f88e13..12dae285 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -107,7 +107,7 @@ Root::setup_keys() { 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(*m_control, &Control::set_shutdown_received), true); + m_bindings['\x11'] = sigc::mem_fun(*m_control, &Control::receive_shutdown); } void