* 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
This commit is contained in:
rakshasa
2008-01-22 15:50:48 +00:00
parent c19af8f389
commit 728c6ac9bd
7 changed files with 78 additions and 51 deletions
+31 -20
View File
@@ -106,7 +106,10 @@ apply_fi_filename_last(torrent::FileListIterator* itr) {
rpc::commands.insert_file(key, commandFileSlotsItr++, &rpc::CommandSlot<torrent::File*>::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<torrent::File*>(get), "i:", "")
#define ADD_CF_VALUE_UNI(key, get) \
ADD_CF_SLOT_PUBLIC("f.get_" key, call_unknown, rpc::object_void_fn<torrent::File*>(get), "i:", "")
@@ -123,37 +126,45 @@ apply_fi_filename_last(torrent::FileListIterator* itr) {
rpc::commands.insert_file_itr(key, commandFileItrSlotsItr++, &rpc::CommandSlot<torrent::FileListIterator*>::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<torrent::FileListIterator*>(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));
}
+1 -1
View File
@@ -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
+12 -6
View File
@@ -205,7 +205,7 @@ apply_to_xb(const torrent::Object& rawArgs) {
// if (cond1) { branch1 } else if (cond2) { branch2 } else { branch3 }
// <cond1>,<branch1>,<cond2>,<branch2>,<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));
+5
View File
@@ -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.");
}
+24 -20
View File
@@ -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())
+2 -3
View File
@@ -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();
+3 -1
View File
@@ -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);