From 728c6ac9bd05cab970cd30aced85c2af99b4116e Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 22 Jan 2008 15:50:48 +0000 Subject: [PATCH] * Added ^E for setting 'create/resize queued' on files in a torrent. * Minor cleanup of the API. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1030 e378c898-3ddf-0310-93e7-cc216c733640 --- src/command_file.cc | 51 ++++++++++++++++++++------------- src/command_helpers.h | 2 +- src/command_ui.cc | 18 ++++++++---- src/rpc/parse.cc | 5 ++++ src/ui/element_download_list.cc | 44 +++++++++++++++------------- src/ui/element_download_list.h | 5 ++-- src/ui/element_file_list.cc | 4 ++- 7 files changed, 78 insertions(+), 51 deletions(-) diff --git a/src/command_file.cc b/src/command_file.cc index 17acdf96..5730894b 100644 --- a/src/command_file.cc +++ b/src/command_file.cc @@ -106,7 +106,10 @@ apply_fi_filename_last(torrent::FileListIterator* itr) { rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); #define ADD_CF_VOID(key, slot) \ - ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_fn(slot), "i:", "") + ADD_CF_SLOT_PUBLIC("f." key, call_unknown, rpc::object_fn(slot), "i:", "") + +#define ADD_CF_VALUE(key, get) \ + ADD_CF_SLOT_PUBLIC("f." key, call_unknown, rpc::object_void_fn(get), "i:", "") #define ADD_CF_VALUE_UNI(key, get) \ ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") @@ -123,37 +126,45 @@ apply_fi_filename_last(torrent::FileListIterator* itr) { rpc::commands.insert_file_itr(key, commandFileItrSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); #define ADD_CFI_VOID(key, slot) \ - ADD_CFI_SLOT_PUBLIC("fi.get_" key, call_unknown, rpc::object_fn(slot), "i:", "") + ADD_CFI_SLOT_PUBLIC("fi." key, call_unknown, rpc::object_fn(slot), "i:", "") #define ADD_CFI_VALUE(key, get) \ ADD_CFI_SLOT_PUBLIC("fi." key, call_unknown, rpc::object_void_fn(get), "i:", "") void initialize_command_file() { - ADD_CF_VALUE_UNI("is_created", std::mem_fun(&torrent::File::is_created)); - ADD_CF_VALUE_UNI("is_open", std::mem_fun(&torrent::File::is_open)); + ADD_CF_VALUE("is_created", std::mem_fun(&torrent::File::is_created)); + ADD_CF_VALUE("is_open", std::mem_fun(&torrent::File::is_open)); - ADD_CF_VALUE_UNI("size_bytes", std::mem_fun(&torrent::File::size_bytes)); - ADD_CF_VALUE_UNI("size_chunks", std::mem_fun(&torrent::File::size_chunks)); - ADD_CF_VALUE_UNI("completed_chunks", std::mem_fun(&torrent::File::completed_chunks)); + ADD_CF_VALUE("is_create_queued", std::mem_fun(&torrent::File::is_create_queued)); + ADD_CF_VALUE("is_resize_queued", std::mem_fun(&torrent::File::is_resize_queued)); - ADD_CF_VALUE_UNI("offset", std::mem_fun(&torrent::File::offset)); - ADD_CF_VALUE_UNI("range_first", std::mem_fun(&torrent::File::range_first)); - ADD_CF_VALUE_UNI("range_second", std::mem_fun(&torrent::File::range_second)); + ADD_CF_VALUE("set_create_queued", std::bind2nd(std::mem_fun(&torrent::File::set_flags), (int)torrent::File::flag_create_queued)); + ADD_CF_VALUE("set_resize_queued", std::bind2nd(std::mem_fun(&torrent::File::set_flags), (int)torrent::File::flag_resize_queued)); + ADD_CF_VALUE("unset_create_queued", std::bind2nd(std::mem_fun(&torrent::File::unset_flags), (int)torrent::File::flag_create_queued)); + ADD_CF_VALUE("unset_resize_queued", std::bind2nd(std::mem_fun(&torrent::File::unset_flags), (int)torrent::File::flag_resize_queued)); - ADD_CF_VALUE_BI("priority", std::ptr_fun(&apply_f_set_priority), std::mem_fun(&torrent::File::priority)); + ADD_CF_VALUE_UNI("size_bytes", std::mem_fun(&torrent::File::size_bytes)); + ADD_CF_VALUE_UNI("size_chunks", std::mem_fun(&torrent::File::size_chunks)); + ADD_CF_VALUE_UNI("completed_chunks", std::mem_fun(&torrent::File::completed_chunks)); - ADD_CF_STRING_UNI("path", std::ptr_fun(&apply_f_path)); - ADD_CF_STRING_UNI("path_components", std::ptr_fun(&apply_f_path_components)); - ADD_CF_STRING_UNI("path_depth", std::ptr_fun(&apply_f_path_depth)); - ADD_CF_STRING_UNI("frozen_path", std::mem_fun(&torrent::File::frozen_path)); + ADD_CF_VALUE_UNI("offset", std::mem_fun(&torrent::File::offset)); + ADD_CF_VALUE_UNI("range_first", std::mem_fun(&torrent::File::range_first)); + ADD_CF_VALUE_UNI("range_second", std::mem_fun(&torrent::File::range_second)); - ADD_CF_VALUE_UNI("match_depth_prev", std::mem_fun(&torrent::File::match_depth_prev)); - ADD_CF_VALUE_UNI("match_depth_next", std::mem_fun(&torrent::File::match_depth_next)); + ADD_CF_VALUE_BI("priority", std::ptr_fun(&apply_f_set_priority), std::mem_fun(&torrent::File::priority)); - ADD_CF_VALUE_UNI("last_touched", std::mem_fun(&torrent::File::last_touched)); + ADD_CF_STRING_UNI("path", std::ptr_fun(&apply_f_path)); + ADD_CF_STRING_UNI("path_components", std::ptr_fun(&apply_f_path_components)); + ADD_CF_STRING_UNI("path_depth", std::ptr_fun(&apply_f_path_depth)); + ADD_CF_STRING_UNI("frozen_path", std::mem_fun(&torrent::File::frozen_path)); - ADD_CFI_VOID("filename_last", &apply_fi_filename_last); + ADD_CF_VALUE_UNI("match_depth_prev", std::mem_fun(&torrent::File::match_depth_prev)); + ADD_CF_VALUE_UNI("match_depth_next", std::mem_fun(&torrent::File::match_depth_next)); - ADD_CFI_VALUE("is_file", std::mem_fun(&torrent::FileListIterator::is_file)); + ADD_CF_VALUE_UNI("last_touched", std::mem_fun(&torrent::File::last_touched)); + + ADD_CFI_VOID("get_filename_last", &apply_fi_filename_last); + + ADD_CFI_VALUE("is_file", std::mem_fun(&torrent::FileListIterator::is_file)); } diff --git a/src/command_helpers.h b/src/command_helpers.h index 4a838807..8279083b 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -49,7 +49,7 @@ namespace rpc { #define COMMAND_SLOTS_SIZE 150 #define COMMAND_VARIABLES_SIZE 100 #define COMMAND_DOWNLOAD_SLOTS_SIZE 150 -#define COMMAND_FILE_SLOTS_SIZE 20 +#define COMMAND_FILE_SLOTS_SIZE 30 #define COMMAND_FILE_ITR_SLOTS_SIZE 10 #define COMMAND_PEER_SLOTS_SIZE 20 #define COMMAND_TRACKER_SLOTS_SIZE 15 diff --git a/src/command_ui.cc b/src/command_ui.cc index 1866062b..08773fc2 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -205,7 +205,7 @@ apply_to_xb(const torrent::Object& rawArgs) { // if (cond1) { branch1 } else if (cond2) { branch2 } else { branch3 } // ,,,, torrent::Object -apply_if(rpc::target_type target, const torrent::Object& rawArgs) { +apply_if(int flags, rpc::target_type target, const torrent::Object& rawArgs) { const torrent::Object::list_type& args = rawArgs.as_list(); torrent::Object::list_const_iterator itr = args.begin(); @@ -213,8 +213,8 @@ apply_if(rpc::target_type target, const torrent::Object& rawArgs) { torrent::Object tmp; const torrent::Object* conditional; - if (itr->is_string() && *itr->as_string().c_str() == '$') - conditional = &(tmp = rpc::parse_command(target, itr->as_string().c_str() + 1, itr->as_string().c_str() + itr->as_string().size()).first); + if (flags & 0x1 && itr->is_string()) + conditional = &(tmp = rpc::parse_command(target, itr->as_string().c_str(), itr->as_string().c_str() + itr->as_string().size()).first); else conditional = &*itr; @@ -245,8 +245,8 @@ apply_if(rpc::target_type target, const torrent::Object& rawArgs) { if (itr == args.end()) return torrent::Object(); - if (itr->is_string() && *itr->as_string().c_str() == '$') - return rpc::parse_command(target, itr->as_string().c_str() + 1, itr->as_string().c_str() + itr->as_string().size()).first; + if (flags & 0x1 && itr->is_string()) + return rpc::parse_command(target, itr->as_string().c_str(), itr->as_string().c_str() + itr->as_string().size()).first; else return *itr; } @@ -267,9 +267,15 @@ initialize_command_ui() { // ADD_COMMAND_LIST("view_sort_current", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_sort_current)); + // Move. + ADD_ANY_NONE("print", rak::ptr_fn(&apply_print)); ADD_ANY_NONE("cat", rak::ptr_fn(&apply_cat)); - ADD_ANY_NONE("if", rak::ptr_fn(&apply_if)); + ADD_ANY_NONE("if", rak::bind_ptr_fn(&apply_if, 0)); + + // A temporary command for handling stuff until we get proper + // support for seperation of commands and literals. + ADD_ANY_NONE("branch", rak::bind_ptr_fn(&apply_if, 1)); ADD_COMMAND_VALUE("to_date", rak::ptr_fn(&apply_to_date)); ADD_COMMAND_VALUE("to_time", rak::ptr_fn(&apply_to_time)); diff --git a/src/rpc/parse.cc b/src/rpc/parse.cc index 71b815d4..734145f8 100644 --- a/src/rpc/parse.cc +++ b/src/rpc/parse.cc @@ -371,6 +371,7 @@ print_object(char* first, char* last, const torrent::Object* src, int flags) { return first; } } + case torrent::Object::TYPE_VALUE: return std::max(first + snprintf(first, std::distance(first, last), "%lli", src->as_value()), last); @@ -384,6 +385,8 @@ print_object(char* first, char* last, const torrent::Object* src, int flags) { return first; + case torrent::Object::TYPE_NONE: + return first; default: throw torrent::input_error("Invalid type."); } @@ -421,6 +424,8 @@ print_object_std(std::string* dest, const torrent::Object* src, int flags) { return; + case torrent::Object::TYPE_NONE: + return; default: throw torrent::input_error("Invalid type."); } diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index 8614b429..0c12bdba 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -63,15 +63,22 @@ ElementDownloadList::ElementDownloadList() : if (m_view == NULL) throw torrent::internal_error("View \"main\" must be present to initialize the main display."); - m_bindings['\x13'] = sigc::mem_fun(*this, &ElementDownloadList::receive_start_download); + m_bindings['\x13'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.start="); m_bindings['\x04'] = sigc::mem_fun(*this, &ElementDownloadList::receive_stop_download); m_bindings['\x0B'] = sigc::mem_fun(*this, &ElementDownloadList::receive_close_download); - m_bindings['\x12'] = sigc::mem_fun(*this, &ElementDownloadList::receive_check_hash); +// m_bindings['\x04'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.stop="); +// m_bindings['\x0B'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.close="); + m_bindings['\x12'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.check_hash="); + + m_bindings['\x05'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), + "f.multicall=,f.set_create_queued=,f.set_resize_queued= ; print=\"Queued create/resize of files in torrent.\""); + m_bindings['+'] = sigc::mem_fun(*this, &ElementDownloadList::receive_next_priority); m_bindings['-'] = sigc::mem_fun(*this, &ElementDownloadList::receive_prev_priority); m_bindings['I'] = sigc::mem_fun(*this, &ElementDownloadList::receive_ignore_ratio); m_bindings['U'] = sigc::mem_fun(*this, &ElementDownloadList::receive_clear_tied); + // These should also be commands. m_bindings['1'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "main"); m_bindings['2'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "name"); m_bindings['3'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "started"); @@ -126,6 +133,21 @@ ElementDownloadList::set_view(core::View* l) { m_window->mark_dirty(); } +void +ElementDownloadList::receive_command(const char* cmd) { + try { + if (m_view->focus() == m_view->end_visible()) + rpc::parse_command_multiple(rpc::make_target(), cmd, cmd + strlen(cmd)); + else + rpc::parse_command_multiple(rpc::make_target(*m_view->focus()), cmd, cmd + strlen(cmd)); + + m_view->set_last_changed(); + + } catch (torrent::input_error& e) { + control->core()->push_log(e.what()); + } +} + void ElementDownloadList::receive_next() { m_view->next_focus(); @@ -138,15 +160,6 @@ ElementDownloadList::receive_prev() { m_view->set_last_changed(); } -void -ElementDownloadList::receive_start_download() { - if (m_view->focus() == m_view->end_visible()) - return; - - control->core()->download_list()->start_normal(*m_view->focus()); - m_view->set_last_changed(); -} - void ElementDownloadList::receive_stop_download() { if (m_view->focus() == m_view->end_visible()) @@ -192,15 +205,6 @@ ElementDownloadList::receive_prev_priority() { m_window->mark_dirty(); } -void -ElementDownloadList::receive_check_hash() { - if (m_view->focus() == m_view->end_visible()) - return; - - // Catch here? - control->core()->download_list()->check_hash(*m_view->focus()); -} - void ElementDownloadList::receive_ignore_ratio() { if (m_view->focus() == m_view->end_visible()) diff --git a/src/ui/element_download_list.h b/src/ui/element_download_list.h index 30d52acc..4a093550 100644 --- a/src/ui/element_download_list.h +++ b/src/ui/element_download_list.h @@ -62,18 +62,17 @@ public: core::View* view() { return m_view; } void set_view(core::View* l); + void receive_command(const char* cmd); + void receive_next(); void receive_prev(); - void receive_start_download(); void receive_stop_download(); void receive_close_download(); void receive_next_priority(); void receive_prev_priority(); - void receive_check_hash(); - void receive_ignore_ratio(); void receive_clear_tied(); diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index 948f6cfa..75ecec04 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -93,9 +93,11 @@ element_file_list_create_info() { element->push_back(""); element->push_column("Size:", te_command("if=$fi.is_file=,$to_xb=$f.get_size_bytes=,---")); - element->push_column("Chunks:", te_command("cat=$f.get_completed_chunks=,\" / \",$f.get_size_chunks=")); element->push_column("Range:", te_command("cat=$f.get_range_first=,\" - \",$f.get_range_second=")); + element->push_back(""); + + element->push_column("Queued:", te_command("cat=\"$if=$f.is_create_queued=,create\",\" \",\"$if=$f.is_resize_queued=,resize\"")); element->set_column_width(element->column_width() + 1);