diff --git a/src/command_download.cc b/src/command_download.cc index 6067234c..7d7ccbdf 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -52,6 +52,7 @@ #include #include "core/download.h" +#include "core/download_store.h" #include "core/manager.h" #include "rpc/command_variable.h" @@ -488,6 +489,8 @@ initialize_command_download() { ADD_CD_F_VOID("erase", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::erase_ptr)); ADD_CD_F_VOID("check_hash", rak::make_mem_fun(control->core()->download_list(), &core::DownloadList::check_hash)); + ADD_CD_F_VOID("save_session", rak::make_mem_fun(control->core()->download_store(), &core::DownloadStore::save)); + ADD_CD_F_VOID("update_priorities", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::update_priorities))); ADD_CD_STRING("add_peer", std::ptr_fun(&apply_d_add_peer)); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index 92466c4c..78e92b41 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -257,27 +257,11 @@ DownloadFactory::receive_success() { if (m_manager->download_list()->find(infohash) == m_manager->download_list()->end()) throw torrent::input_error("The newly created download was removed."); - // When a download scheduler is implemented, this is handled by - // the above insertion into download list. - if (m_session) { - // This torrent was queued for hashing or hashing when the - // session file was saved. Or it was in a started state. - if (//rpc::call_command_value("d.get_hashing", rpc::make_target(download)) != Download::variable_hashing_stopped || - rpc::call_command_value("d.get_state", rpc::make_target(download)) != 0) -// m_manager->download_list()->resume(download); - rpc::parse_command_single(rpc::make_target(download), "view.set_visible=started"); - else - rpc::parse_command_single(rpc::make_target(download), "view.set_visible=stopped"); + if (!m_session) + rpc::call_command("d.set_state", (int64_t)m_start, rpc::make_target(download)); - } else { - // Use the state thingie here, move below. - if (m_start) - rpc::parse_command_single(rpc::make_target(download), "d.start="); - else - rpc::parse_command_single(rpc::make_target(download), "view.set_visible=stopped"); - - m_manager->download_store()->save(download); - } + rpc::commands.call_catch(m_session ? "event.download.inserted_session" : "event.download.inserted_new", + rpc::make_target(download), torrent::Object(), "Download event action failed: "); } catch (torrent::input_error& e) { std::string msg = "Command on torrent creation failed: " + std::string(e.what()); diff --git a/src/core/manager.cc b/src/core/manager.cc index 06001b3d..e1d7a9f5 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -211,11 +211,6 @@ Manager::initialize_second() { CurlStack::global_init(); - // Register slots to be called when a download is inserted/erased, - // opened or closed. - rpc::parse_command_single(rpc::make_target(), "system.method.set_key = event.download.inserted, 1_connect_logs, d.initialize_logs="); - rpc::parse_command_single(rpc::make_target(), "system.method.set_key = event.download.erased, 9_delete_tied, d.delete_tied="); - torrent::connection_manager()->set_signal_handshake_log(sigc::mem_fun(this, &Manager::handshake_log)); } diff --git a/src/main.cc b/src/main.cc index 996a643b..d1e1808c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -174,17 +174,26 @@ main(int argc, char** argv) { rpc::parse_command_multiple (rpc::make_target(), "system.method.insert = event.download.inserted,list\n" + "system.method.insert = event.download.inserted_new,list\n" + "system.method.insert = event.download.inserted_session,list\n" "system.method.insert = event.download.erased,list\n" "system.method.insert = event.download.opened,list\n" "system.method.insert = event.download.closed,list\n" "system.method.insert = event.download.resumed,list\n" "system.method.insert = event.download.paused,list\n" - + "system.method.insert = event.download.finished,list\n" "system.method.insert = event.download.hash_done,list\n" "system.method.insert = event.download.hash_removed,list\n" "system.method.insert = event.download.hash_queued,list\n" + "system.method.set_key = event.download.inserted, 1_connect_logs, d.initialize_logs=\n" + "system.method.set_key = event.download.inserted_new, 1_prepare, \"branch=d.get_state=,view.set_visible=started,view.set_visible=stopped ;d.save_session=\"\n" + "system.method.set_key = event.download.inserted_session, 1_prepare, \"branch=d.get_state=,view.set_visible=started,view.set_visible=stopped\"\n" + + "system.method.set_key = event.download.erased, 0_download_list, ui.unfocus_download=\n" + "system.method.set_key = event.download.erased, 9_delete_tied, d.delete_tied=\n" + "set_name = \"$cat=$system.hostname=,:,$system.pid=\"\n" // Currently not doing any sorting on main. diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 8685a86a..21a4653b 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -98,7 +98,6 @@ DownloadList::activate(display::Frame* frame, bool focus) { m_frame = frame; control->input()->push_back(&m_bindings); - rpc::commands.call("system.method.set_key", rpc::make_target(), rpc::create_object_list("event.download.erased", "0_download_list", "ui.unfocus_download=")); activate_display(DISPLAY_DOWNLOAD_LIST); }