mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-12 05:02:31 +00:00
* Make DownloadStore::save(...) validate the new file by loading the
bencoded data. * Make it safe to remove torrents that are selected. * Delete the rtorrent and libtorrent sections when loading non-session torrents. * Added ^O to change a torrent's root dir, ^P to set a variable. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@628 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -224,49 +224,49 @@ private:
|
||||
Arg1 m_arg1;
|
||||
};
|
||||
|
||||
template <typename Object, typename Result>
|
||||
template <typename Result, typename Object>
|
||||
function_base0<Result>*
|
||||
mem_fn(Object* object, Result (Object::*func)()) {
|
||||
return new mem_fn0_t<Object, Result>(object, func);
|
||||
}
|
||||
|
||||
template <typename Object, typename Result, typename Arg1>
|
||||
template <typename Arg1, typename Result, typename Object>
|
||||
function_base1<Result, Arg1>*
|
||||
mem_fn(Object* object, Result (Object::*func)(Arg1)) {
|
||||
return new mem_fn1_t<Object, Result, Arg1>(object, func);
|
||||
}
|
||||
|
||||
template <typename Object, typename Result>
|
||||
template <typename Result, typename Object>
|
||||
function_base0<Result>*
|
||||
mem_fn(const Object* object, Result (Object::*func)() const) {
|
||||
return new const_mem_fn0_t<Object, Result>(object, func);
|
||||
}
|
||||
|
||||
template <typename Object, typename Result, typename Arg1>
|
||||
template <typename Arg1, typename Result, typename Object>
|
||||
function_base1<Result, Arg1>*
|
||||
mem_fn(const Object* object, Result (Object::*func)(Arg1) const) {
|
||||
return new const_mem_fn1_t<Object, Result, Arg1>(object, func);
|
||||
}
|
||||
|
||||
template <typename Object, typename Result, typename Arg1>
|
||||
template <typename Arg1, typename Result, typename Object>
|
||||
function_base0<Result>*
|
||||
bind_mem_fn(Object* object, Result (Object::*func)(Arg1), const Arg1 arg1) {
|
||||
return new mem_fn0_b1_t<Object, Result, Arg1>(object, func, arg1);
|
||||
}
|
||||
|
||||
template <typename Result, typename Arg1>
|
||||
template <typename Arg1, typename Result>
|
||||
function_base1<Result, Arg1>*
|
||||
ptr_fn(Result (*func)(Arg1)) {
|
||||
return new ptr_fn1_t<Result, Arg1>(func);
|
||||
}
|
||||
|
||||
template <typename Result, typename Arg1>
|
||||
template <typename Arg1, typename Result>
|
||||
function_base0<Result>*
|
||||
bind_ptr_fn(Result (*func)(Arg1), const Arg1 arg1) {
|
||||
return new ptr_fn0_b1_t<Result, Arg1>(func, arg1);
|
||||
}
|
||||
|
||||
template <typename Result, typename Arg1, typename Arg2>
|
||||
template <typename Arg1, typename Arg2, typename Result>
|
||||
function_base1<Result, Arg2>*
|
||||
bind_ptr_fn(Result (*func)(Arg1, Arg2), const Arg1 arg1) {
|
||||
return new ptr_fn1_b1_t<Result, Arg1, Arg2>(func, arg1);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <time.h>
|
||||
#include <rak/functional.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
@@ -117,12 +118,24 @@ uint32_t
|
||||
CommandScheduler::parse_absolute(const char* str) {
|
||||
Time result = parse_time(str);
|
||||
|
||||
// Do the local time thing.
|
||||
struct tm local;
|
||||
|
||||
switch (result.first) {
|
||||
case 1:
|
||||
return result.second;
|
||||
|
||||
case 2:
|
||||
return (result.second - cachedTime.seconds() % 3600) % 3600;
|
||||
if (localtime_r(&cachedTime.tval().tv_sec, &local) == NULL)
|
||||
throw torrent::input_error("Could not convert unix time to local time.");
|
||||
|
||||
return (result.second + 3600 - 60 * local.tm_min - local.tm_sec) % 3600;
|
||||
|
||||
case 3:
|
||||
if (localtime_r(&cachedTime.tval().tv_sec, &local) == NULL)
|
||||
throw torrent::input_error("Could not convert unix time to local time.");
|
||||
|
||||
return (result.second + 24 * 3600 - 3600 * local.tm_hour - 60 * local.tm_min - local.tm_sec) % (24 * 3600);
|
||||
|
||||
case 0:
|
||||
default:
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
// safe to call erase on end().
|
||||
iterator insert(const std::string& key);
|
||||
void erase(iterator itr);
|
||||
void erase(const std::string& key) { erase(find(key)); }
|
||||
|
||||
static uint32_t parse_absolute(const char* str);
|
||||
static uint32_t parse_interval(const char* str);
|
||||
|
||||
@@ -64,9 +64,11 @@ Download::Download(torrent::Download d) :
|
||||
rak::mem_fn(this, &Download::set_connection_current)));
|
||||
m_variables.insert("connection_leech", new utils::VariableAny(connection_type_to_string(torrent::Download::CONNECTION_LEECH)));
|
||||
m_variables.insert("connection_seed", new utils::VariableAny(connection_type_to_string(torrent::Download::CONNECTION_SEED)));
|
||||
m_variables.insert("directory", new utils::VariableSlotString<std::string, const std::string&>(NULL,
|
||||
rak::mem_fn(this, &Download::set_root_directory)));
|
||||
m_variables.insert("tied_to_file", new utils::VariableBencode(&m_download.bencode(), "tied_to_file", torrent::Bencode::TYPE_STRING));
|
||||
m_variables.insert("state", new utils::VariableBencode(&m_download.bencode(), "rtorrent", "state", torrent::Bencode::TYPE_STRING));
|
||||
m_variables.insert("tied_to_file", new utils::VariableBencode(&m_download.bencode(), "rtorrent", "tied_to_file", torrent::Bencode::TYPE_STRING));
|
||||
|
||||
m_variables.insert("directory", new utils::VariableSlotString<>(rak::mem_fn(&m_download, &torrent::Download::root_dir),
|
||||
rak::mem_fn(this, &Download::set_root_directory)));
|
||||
|
||||
m_variables.insert("min_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_min),
|
||||
rak::mem_fn(&m_download, &torrent::Download::set_peers_min),
|
||||
@@ -217,6 +219,8 @@ Download::set_root_directory(const std::string& d) {
|
||||
m_download.set_root_dir(d +
|
||||
(*d.rbegin() != '/' ? "/" : "") +
|
||||
(m_download.size_file_entries() > 1 ? m_download.name() : ""));
|
||||
|
||||
m_download.bencode().get_key("rtorrent").insert_key("directory", d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -146,38 +146,62 @@ DownloadFactory::receive_success() {
|
||||
return;
|
||||
}
|
||||
|
||||
torrent::Bencode& root = (*itr)->get_bencode();
|
||||
|
||||
if (!m_session) {
|
||||
// We only allow session torrents to keep their
|
||||
// 'rtorrent/libtorrent' sections.
|
||||
root.erase_key("rtorrent");
|
||||
root.erase_key("libtorrent");
|
||||
}
|
||||
|
||||
if (!root.has_key("rtorrent") ||
|
||||
!root.get_key("rtorrent").is_map())
|
||||
root.insert_key("rtorrent", torrent::Bencode(torrent::Bencode::TYPE_MAP));
|
||||
|
||||
torrent::Bencode& rtorrent = root.get_key("rtorrent");
|
||||
|
||||
if (!rtorrent.has_key("state") ||
|
||||
!rtorrent.get_key("state").is_string() ||
|
||||
(rtorrent.get_key("state").as_string() != "stopped" &&
|
||||
rtorrent.get_key("state").as_string() != "started"))
|
||||
rtorrent.insert_key("state", "stopped");
|
||||
|
||||
if (!rtorrent.has_key("tied_to_file") ||
|
||||
!rtorrent.get_key("tied_to_file").is_string())
|
||||
rtorrent.insert_key("tied_to_file", std::string());
|
||||
|
||||
if (rtorrent.has_key("priority") &&
|
||||
rtorrent.get_key("priority").is_value())
|
||||
(*itr)->variables()->set("priority", rtorrent.get_key("priority").as_value() % 4);
|
||||
else
|
||||
(*itr)->variables()->set("priority", (int64_t)2);
|
||||
|
||||
// Move to 'rtorrent'.
|
||||
(*itr)->variables()->set("connection_leech", m_variables.get("connection_leech"));
|
||||
(*itr)->variables()->set("connection_seed", m_variables.get("connection_seed"));
|
||||
(*itr)->variables()->set("directory", m_variables.get("directory"));
|
||||
(*itr)->variables()->set("min_peers", control->variables()->get("min_peers"));
|
||||
(*itr)->variables()->set("max_peers", control->variables()->get("max_peers"));
|
||||
(*itr)->variables()->set("max_uploads", control->variables()->get("max_uploads"));
|
||||
|
||||
if ((*itr)->get_bencode().get_key("rtorrent").has_key("priority") &&
|
||||
(*itr)->get_bencode().get_key("rtorrent").get_key("priority").is_value())
|
||||
(*itr)->variables()->set("priority", (*itr)->get_bencode().get_key("rtorrent").get_key("priority").as_value() % 4);
|
||||
else
|
||||
(*itr)->variables()->set("priority", (int64_t)2);
|
||||
|
||||
|
||||
torrent::Bencode& bencode = (*itr)->get_bencode();
|
||||
if (control->variables()->get("use_udp_trackers").as_string() == "no")
|
||||
(*itr)->enable_udp_trackers(false);
|
||||
|
||||
if (m_session) {
|
||||
// Hmm... this safe?
|
||||
if (bencode.get_key("rtorrent").get_key("state").as_string() == "started")
|
||||
if (!rtorrent.has_key("directory") ||
|
||||
!rtorrent.get_key("directory").is_string())
|
||||
(*itr)->variables()->set("directory", m_variables.get("directory"));
|
||||
else
|
||||
(*itr)->variables()->set("directory", rtorrent.get_key("directory"));
|
||||
|
||||
if ((*itr)->variables()->get_string("state") == "started")
|
||||
m_manager->start(*itr, m_printLog);
|
||||
|
||||
// Consider adding an empty 'tied_to_file' here if not present.
|
||||
|
||||
} else {
|
||||
// Remove the settings if this isn't a session torrent.
|
||||
//bencode.erase_key("rtorrent");
|
||||
(*itr)->variables()->set("directory", m_variables.get("directory"));
|
||||
|
||||
if (m_variables.get("tied_to_file").as_value())
|
||||
(*itr)->variables()->set("tied_to_file", m_uri);
|
||||
else
|
||||
(*itr)->variables()->set("tied_to_file", std::string());
|
||||
|
||||
if (m_start)
|
||||
m_manager->start(*itr, m_printLog);
|
||||
|
||||
@@ -71,7 +71,18 @@ DownloadStore::save(Download* d) {
|
||||
|
||||
f << d->get_bencode();
|
||||
|
||||
if (f.fail())
|
||||
if (!f.good())
|
||||
return;
|
||||
|
||||
f.close();
|
||||
|
||||
// Test the new file, to ensure it is a valid bencode string.
|
||||
f.open((create_filename(d) + ".new").c_str(), std::ios::in);
|
||||
|
||||
torrent::Bencode tmp;
|
||||
f >> tmp;
|
||||
|
||||
if (!f.good())
|
||||
return;
|
||||
|
||||
f.close();
|
||||
|
||||
+4
-17
@@ -116,7 +116,7 @@ Manager::initialize_second() {
|
||||
|
||||
// Register slots to be called when a download is inserted/erased,
|
||||
// opened or closed.
|
||||
m_downloadList.slot_map_insert()["0_initialize_bencode"] = sigc::mem_fun(*this, &Manager::initialize_bencode);
|
||||
// m_downloadList.slot_map_insert()["0_initialize_bencode"] = sigc::mem_fun(*this, &Manager::initialize_bencode);
|
||||
m_downloadList.slot_map_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()["1_connect_tracker_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_tracker_log), sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
m_downloadList.slot_map_insert()["1_connect_storage_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_storage_log), sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
@@ -193,7 +193,7 @@ Manager::erase(DListItr itr) {
|
||||
void
|
||||
Manager::start(Download* d, bool printLog) {
|
||||
try {
|
||||
d->get_bencode().get_key("rtorrent").insert_key("state", "started");
|
||||
d->variables()->set("state", "started");
|
||||
|
||||
if (d->get_download().is_active())
|
||||
return;
|
||||
@@ -218,7 +218,7 @@ Manager::start(Download* d, bool printLog) {
|
||||
void
|
||||
Manager::stop(Download* d) {
|
||||
try {
|
||||
d->get_bencode().get_key("rtorrent").insert_key("state", "stopped");
|
||||
d->variables()->set("state", "stopped");
|
||||
|
||||
m_downloadList.stop(d);
|
||||
|
||||
@@ -294,19 +294,6 @@ Manager::bind(const std::string& addr) {
|
||||
m_pollManager->get_http_stack()->set_bind_address(torrent::bind_address());
|
||||
}
|
||||
|
||||
void
|
||||
Manager::initialize_bencode(Download* d) {
|
||||
torrent::Bencode& bencode = d->get_bencode();
|
||||
|
||||
if (!bencode.has_key("rtorrent") ||
|
||||
!bencode.get_key("rtorrent").is_map())
|
||||
bencode.insert_key("rtorrent", torrent::Bencode(torrent::Bencode::TYPE_MAP));
|
||||
|
||||
if (!bencode.get_key("rtorrent").has_key("state") ||
|
||||
!bencode.get_key("rtorrent").get_key("state").is_string())
|
||||
bencode.get_key("rtorrent").insert_key("state", "stopped");
|
||||
}
|
||||
|
||||
void
|
||||
Manager::prepare_hash_check(Download* d) {
|
||||
m_downloadList.close(d);
|
||||
@@ -334,7 +321,7 @@ Manager::receive_download_done_hash_checked(Download* d) {
|
||||
|
||||
// Don't send if we did a hash check and found incompelete chunks.
|
||||
//if (d->is_done())
|
||||
d->get_download().tracker_send_completed();
|
||||
d->get_download().tracker_send_completed();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -84,6 +84,7 @@ WindowPeerInfo::redraw() {
|
||||
m_download->variables()->get("connection_seed").as_string().c_str(),
|
||||
m_download->variables()->get("connection_leech").as_string().c_str());
|
||||
|
||||
m_canvas->print(0, y++, "Directory: %s", m_download->variable_string("directory").c_str());
|
||||
m_canvas->print(0, y++, "Tied to file: %s", m_download->variable_string("tied_to_file").c_str());
|
||||
|
||||
y++;
|
||||
|
||||
@@ -188,12 +188,6 @@ main(int argc, char** argv) {
|
||||
|
||||
control->initialize();
|
||||
|
||||
// Just to make sure we did all the stuff on the queue before
|
||||
// loading any torrents.
|
||||
//
|
||||
// Remove this?
|
||||
//rak::priority_queue_perform(&taskScheduler, cachedTime);
|
||||
|
||||
// Load session torrents and perform scheduled tasks to ensure
|
||||
// session torrents are loaded before arg torrents.
|
||||
load_session_torrents(control);
|
||||
|
||||
@@ -68,29 +68,3 @@ OptionFile::process_file(const std::string& filename) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// void
|
||||
// OptionFile::parse_line(const char* line) {
|
||||
//const char* last = std::find(line, line + max_size_line, '\0');
|
||||
|
||||
// if (line[0] == '#')
|
||||
// return;
|
||||
|
||||
// int result;
|
||||
// char key[64];
|
||||
// char opt[512];
|
||||
|
||||
// opt[0] = '\0';
|
||||
|
||||
// // Check for empty lines, and options within "abc".
|
||||
// if ((result = std::sscanf(line, "%63s = \"%511[^\"]", key, opt)) != 2 &&
|
||||
// (result = std::sscanf(line, "%63s = %511s", key, opt)) != 2 &&
|
||||
// result == 1)
|
||||
// throw torrent::input_error("Error parseing option file.");
|
||||
|
||||
// if (opt[0] == '"' && opt[1] == '"')
|
||||
// opt[0] = '\0';
|
||||
|
||||
// if (result >= 1)
|
||||
// m_slotOption(key, opt);
|
||||
// }
|
||||
|
||||
+24
-52
@@ -61,32 +61,30 @@
|
||||
#include "command_scheduler.h"
|
||||
#include "command_scheduler_item.h"
|
||||
|
||||
void receive_tracker_dump(std::istream* s);
|
||||
// void
|
||||
// OptionHandlerInt::process(const std::string& key, const std::string& arg) {
|
||||
// int a;
|
||||
|
||||
// if (std::sscanf(arg.c_str(), "%i", &a) != 1)
|
||||
// throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\", must be an integer.");
|
||||
|
||||
// m_apply(m_control, a);
|
||||
// }
|
||||
|
||||
void
|
||||
OptionHandlerInt::process(const std::string& key, const std::string& arg) {
|
||||
int a;
|
||||
// void
|
||||
// OptionHandlerOctal::process(const std::string& key, const std::string& arg) {
|
||||
// int a;
|
||||
|
||||
if (std::sscanf(arg.c_str(), "%i", &a) != 1)
|
||||
throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\", must be an integer.");
|
||||
// if (std::sscanf(arg.c_str(), "%o", &a) != 1)
|
||||
// throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\", must be an octal.");
|
||||
|
||||
m_apply(m_control, a);
|
||||
}
|
||||
// m_apply(m_control, a);
|
||||
// }
|
||||
|
||||
void
|
||||
OptionHandlerOctal::process(const std::string& key, const std::string& arg) {
|
||||
int a;
|
||||
|
||||
if (std::sscanf(arg.c_str(), "%o", &a) != 1)
|
||||
throw torrent::input_error("Invalid argument for \"" + key + "\": \"" + arg + "\", must be an octal.");
|
||||
|
||||
m_apply(m_control, a);
|
||||
}
|
||||
|
||||
void
|
||||
OptionHandlerString::process(const std::string& key, const std::string& arg) {
|
||||
m_apply(m_control, arg);
|
||||
}
|
||||
// void
|
||||
// OptionHandlerString::process(const std::string& key, const std::string& arg) {
|
||||
// m_apply(m_control, arg);
|
||||
// }
|
||||
|
||||
void
|
||||
apply_umask(int arg) {
|
||||
@@ -114,22 +112,6 @@ apply_port_range(Control* m, const std::string& arg) {
|
||||
m->core()->set_port_range(a, b);
|
||||
}
|
||||
|
||||
void
|
||||
apply_tracker_dump(Control* m, const std::string& arg) {
|
||||
if (arg == "yes")
|
||||
m->core()->get_download_list().slot_map_insert()["1_tracker_dump"] = sigc::bind(sigc::mem_fun(&core::Download::call<sigc::connection, torrent::Download::SlotIStream, &torrent::Download::signal_tracker_dump>), sigc::ptr_fun(&receive_tracker_dump));
|
||||
else
|
||||
m->core()->get_download_list().slot_map_insert().erase("1_tracker_dump");
|
||||
}
|
||||
|
||||
void
|
||||
apply_use_udp_trackers(Control* m, const std::string& arg) {
|
||||
if (arg == "yes")
|
||||
m->core()->get_download_list().slot_map_insert().erase("1_use_udp_trackers");
|
||||
else
|
||||
m->core()->get_download_list().slot_map_insert()["1_use_udp_trackers"] = sigc::bind(sigc::mem_fun(&core::Download::enable_udp_trackers), false);
|
||||
}
|
||||
|
||||
void
|
||||
apply_http_proxy(Control* m, const std::string& arg) {
|
||||
m->core()->get_poll_manager()->get_http_stack()->set_http_proxy(arg);
|
||||
@@ -185,11 +167,6 @@ apply_remove_untied(Control* m, const std::string& arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
apply_session_directory(Control* m, const std::string& arg) {
|
||||
m->core()->get_download_store().use(arg);
|
||||
}
|
||||
|
||||
void
|
||||
apply_encoding_list(Control* m, const std::string& arg) {
|
||||
torrent::encoding_list()->push_back(arg);
|
||||
@@ -216,24 +193,20 @@ apply_schedule(Control* m, const std::string& arg) {
|
||||
item->enable((cachedTime + rak::timer(absolute) * 1000000).round_seconds());
|
||||
}
|
||||
|
||||
void
|
||||
apply_schedule_remove(Control* m, const std::string& arg) {
|
||||
m->command_scheduler()->erase(m->command_scheduler()->find(rak::trim(arg)));
|
||||
}
|
||||
|
||||
void
|
||||
initialize_option_handler(Control* c) {
|
||||
utils::VariableMap* variables = control->variables();
|
||||
|
||||
// Cleaned up.
|
||||
variables->insert("check_hash", new utils::VariableAny("yes"));
|
||||
variables->insert("use_udp_trackers", new utils::VariableAny("yes"));
|
||||
variables->insert("port_random", new utils::VariableAny("yes"));
|
||||
variables->insert("session", new utils::VariableSlotString<>(NULL, rak::mem_fn(&control->core()->get_download_store(), &core::DownloadStore::use)));
|
||||
|
||||
variables->insert("connection_leech", new utils::VariableAny("leech"));
|
||||
variables->insert("connection_seed", new utils::VariableAny("seed"));
|
||||
|
||||
variables->insert("directory", new utils::VariableAny(std::string()));
|
||||
variables->insert("directory", new utils::VariableAny("./"));
|
||||
variables->insert("ip", new utils::VariableSlotString<>(NULL, rak::ptr_fn(&torrent::set_local_address)));
|
||||
variables->insert("bind", new utils::VariableSlotString<>(NULL, rak::mem_fn(control->core(), &core::Manager::bind)));
|
||||
|
||||
@@ -250,6 +223,8 @@ initialize_option_handler(Control* c) {
|
||||
|
||||
variables->insert("print", new utils::VariableSlotString<>(NULL, rak::mem_fn(control->core(), &core::Manager::push_log)));
|
||||
|
||||
variables->insert("schedule_remove", new utils::VariableSlotString<>(NULL, rak::mem_fn<const std::string&>(c->command_scheduler(), &CommandScheduler::erase)));
|
||||
|
||||
// Old.
|
||||
variables->insert("port_range", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_port_range, c)));
|
||||
|
||||
@@ -264,10 +239,7 @@ initialize_option_handler(Control* c) {
|
||||
variables->insert("remove_untied", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_remove_untied, c)));
|
||||
|
||||
variables->insert("encoding_list", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_encoding_list, c)));
|
||||
variables->insert("tracker_dump", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_tracker_dump, c)));
|
||||
variables->insert("use_udp_trackers", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_use_udp_trackers, c)));
|
||||
|
||||
variables->insert("http_proxy", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_http_proxy, c)));
|
||||
variables->insert("schedule", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_schedule, c)));
|
||||
variables->insert("schedule_remove", new utils::VariableSlotString<>(NULL, rak::bind_ptr_fn(&apply_schedule_remove, c)));
|
||||
}
|
||||
|
||||
+61
-12
@@ -41,6 +41,7 @@
|
||||
#include <rak/string_manip.h>
|
||||
#include <sigc++/bind.h>
|
||||
#include <sigc++/hide.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "core/download.h"
|
||||
@@ -123,6 +124,8 @@ DownloadList::activate() {
|
||||
|
||||
m_control->input()->push_front(m_bindings);
|
||||
|
||||
m_control->core()->get_download_list().slot_map_erase().insert("0_download_list", sigc::mem_fun(this, &DownloadList::receive_download_erased));
|
||||
|
||||
activate_display(DISPLAY_DOWNLOAD_LIST);
|
||||
}
|
||||
|
||||
@@ -133,7 +136,7 @@ DownloadList::disable() {
|
||||
|
||||
if (m_windowTextInput->is_active()) {
|
||||
m_windowTextInput->get_input()->clear();
|
||||
receive_exit_input(true);
|
||||
receive_exit_input(INPUT_NONE);
|
||||
}
|
||||
|
||||
disable_display();
|
||||
@@ -258,7 +261,7 @@ DownloadList::receive_check_hash() {
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::receive_view_input(bool useDefault) {
|
||||
DownloadList::receive_view_input(Input type) {
|
||||
if (m_windowTextInput->get_active())
|
||||
return;
|
||||
|
||||
@@ -270,20 +273,52 @@ DownloadList::receive_view_input(bool useDefault) {
|
||||
|
||||
m_windowTextInput->set_focus(true);
|
||||
|
||||
(*m_bindings)['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), useDefault);
|
||||
(*m_bindings)[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), useDefault);
|
||||
if (type == INPUT_CHANGE_DIRECTORY) {
|
||||
m_windowTextInput->get_input()->str() = m_control->variables()->get_string("directory");
|
||||
m_windowTextInput->get_input()->set_pos(m_windowTextInput->get_input()->str().length());
|
||||
}
|
||||
|
||||
(*m_bindings)['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type);
|
||||
(*m_bindings)[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), type);
|
||||
(*m_bindings)['\x07'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_exit_input), INPUT_NONE);
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::receive_exit_input(bool useDefault) {
|
||||
DownloadList::receive_exit_input(Input type) {
|
||||
if (!m_windowTextInput->get_active())
|
||||
return;
|
||||
|
||||
m_control->ui()->window_statusbar()->set_active(true);
|
||||
m_windowTextInput->set_active(false);
|
||||
m_control->input()->set_text_input();
|
||||
|
||||
try {
|
||||
|
||||
m_control->core()->try_create_download_expand(m_windowTextInput->get_input()->str(), useDefault);
|
||||
switch (type) {
|
||||
case INPUT_NONE:
|
||||
break;
|
||||
|
||||
case INPUT_LOAD_DEFAULT:
|
||||
case INPUT_LOAD_MODIFIED:
|
||||
m_control->core()->try_create_download_expand(m_windowTextInput->get_input()->str(), type == INPUT_LOAD_DEFAULT);
|
||||
break;
|
||||
|
||||
case INPUT_CHANGE_DIRECTORY:
|
||||
if (m_downloadList.get_focus() == m_downloadList.end())
|
||||
throw torrent::input_error("No download in focus to change root directory.");
|
||||
|
||||
(*m_downloadList.get_focus())->variables()->set("directory", rak::trim(m_windowTextInput->get_input()->str()));
|
||||
m_control->core()->push_log("New root dir \"" + (*m_downloadList.get_focus())->variables()->get_string("directory") + "\"");
|
||||
break;
|
||||
|
||||
case INPUT_COMMAND:
|
||||
m_control->variables()->process_command(m_windowTextInput->get_input()->str());
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
m_control->core()->push_log(e.what());
|
||||
}
|
||||
|
||||
// Clean up.
|
||||
m_windowTextInput->get_input()->clear();
|
||||
@@ -293,8 +328,8 @@ DownloadList::receive_exit_input(bool useDefault) {
|
||||
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);
|
||||
(*m_bindings)['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED);
|
||||
(*m_bindings)[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED);
|
||||
|
||||
receive_change(DISPLAY_DOWNLOAD_LIST);
|
||||
}
|
||||
@@ -308,6 +343,18 @@ DownloadList::receive_change(Display d) {
|
||||
activate_display(d);
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::receive_download_erased(core::Download* d) {
|
||||
if (m_downloadList.get_focus() == m_downloadList.end() ||
|
||||
*m_downloadList.get_focus() != d)
|
||||
return;
|
||||
|
||||
if (m_uiDownload != NULL)
|
||||
receive_exit_download();
|
||||
|
||||
receive_next();
|
||||
}
|
||||
|
||||
void
|
||||
DownloadList::task_update() {
|
||||
m_windowLog->receive_update();
|
||||
@@ -323,10 +370,12 @@ DownloadList::setup_keys() {
|
||||
(*m_bindings)['+'] = sigc::mem_fun(*this, &DownloadList::receive_next_priority);
|
||||
(*m_bindings)['-'] = sigc::mem_fun(*this, &DownloadList::receive_prev_priority);
|
||||
|
||||
(*m_bindings)['\x7f'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), true);
|
||||
(*m_bindings)[KEY_BACKSPACE] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), true);
|
||||
(*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);
|
||||
(*m_bindings)['\x7f'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_DEFAULT);
|
||||
(*m_bindings)[KEY_BACKSPACE] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_DEFAULT);
|
||||
(*m_bindings)['\n'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED);
|
||||
(*m_bindings)[KEY_ENTER] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_LOAD_MODIFIED);
|
||||
(*m_bindings)['\x0F'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_CHANGE_DIRECTORY);
|
||||
(*m_bindings)['\x10'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), INPUT_COMMAND);
|
||||
|
||||
(*m_bindings)[KEY_UP] = sigc::mem_fun(*this, &DownloadList::receive_prev);
|
||||
(*m_bindings)[KEY_DOWN] = sigc::mem_fun(*this, &DownloadList::receive_next);
|
||||
|
||||
+12
-2
@@ -87,6 +87,14 @@ public:
|
||||
DISPLAY_MAX_SIZE
|
||||
} Display;
|
||||
|
||||
typedef enum {
|
||||
INPUT_NONE,
|
||||
INPUT_LOAD_DEFAULT,
|
||||
INPUT_LOAD_MODIFIED,
|
||||
INPUT_CHANGE_DIRECTORY,
|
||||
INPUT_COMMAND
|
||||
} Input;
|
||||
|
||||
DownloadList(Control* c);
|
||||
~DownloadList();
|
||||
|
||||
@@ -120,11 +128,13 @@ private:
|
||||
|
||||
void receive_check_hash();
|
||||
|
||||
void receive_view_input(bool useDefault);
|
||||
void receive_exit_input(bool useDefault);
|
||||
void receive_view_input(Input type);
|
||||
void receive_exit_input(Input type);
|
||||
|
||||
void receive_change(Display d);
|
||||
|
||||
void receive_download_erased(core::Download* d);
|
||||
|
||||
void task_update();
|
||||
|
||||
void setup_keys();
|
||||
|
||||
@@ -129,21 +129,30 @@ VariableBencode::~VariableBencode() {
|
||||
|
||||
const torrent::Bencode&
|
||||
VariableBencode::get() {
|
||||
return m_bencode->get_key(m_key);
|
||||
if (m_root.empty())
|
||||
return m_bencode->get_key(m_key);
|
||||
else
|
||||
return m_bencode->get_key(m_root).get_key(m_key);
|
||||
}
|
||||
|
||||
void
|
||||
VariableBencode::set(const torrent::Bencode& arg) {
|
||||
// Consider removing if TYPE_NONE.
|
||||
torrent::Bencode* root;
|
||||
|
||||
if (m_root.empty())
|
||||
root = m_bencode;
|
||||
else
|
||||
root = &m_bencode->get_key(m_root);
|
||||
|
||||
switch (m_type) {
|
||||
case torrent::Bencode::TYPE_NONE:
|
||||
m_bencode->insert_key(m_key, arg);
|
||||
root->insert_key(m_key, arg);
|
||||
break;
|
||||
|
||||
case torrent::Bencode::TYPE_STRING:
|
||||
if (arg.get_type() == torrent::Bencode::TYPE_STRING)
|
||||
m_bencode->insert_key(m_key, arg);
|
||||
root->insert_key(m_key, arg);
|
||||
else
|
||||
throw torrent::input_error("VariableBencode could not convert to string.");
|
||||
|
||||
|
||||
@@ -91,8 +91,11 @@ class VariableBencode : public Variable {
|
||||
public:
|
||||
typedef torrent::Bencode::Type Type;
|
||||
|
||||
VariableBencode(torrent::Bencode* b, const std::string& key, Type t = torrent::Bencode::TYPE_NONE) :
|
||||
m_bencode(b), m_key(key), m_type(t) {}
|
||||
VariableBencode(torrent::Bencode* b,
|
||||
const std::string& root,
|
||||
const std::string& key,
|
||||
Type t = torrent::Bencode::TYPE_NONE) :
|
||||
m_bencode(b), m_root(root), m_key(key), m_type(t) {}
|
||||
virtual ~VariableBencode();
|
||||
|
||||
virtual const torrent::Bencode& get();
|
||||
@@ -100,6 +103,7 @@ public:
|
||||
|
||||
private:
|
||||
torrent::Bencode* m_bencode;
|
||||
std::string m_root;
|
||||
std::string m_key;
|
||||
Type m_type;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user