* Added some missing includes.

* Changed more key bindings in ElementDownloadList to commands.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1038 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2008-02-03 14:30:58 +00:00
parent 1b96bd6016
commit afe1312eb6
9 changed files with 73 additions and 84 deletions
+36 -2
View File
@@ -42,6 +42,8 @@
#include "core/manager.h"
#include "core/view_manager.h"
#include "ui/root.h"
#include "ui/download_list.h"
#include "rpc/command_slot.h"
#include "rpc/command_variable.h"
#include "rpc/parse.h"
@@ -107,6 +109,24 @@ apply_view_list(const torrent::Object&) {
return rawResult;
}
torrent::Object
apply_view_set(const torrent::Object& rawArgs) {
const torrent::Object::list_type& args = rawArgs.as_list();
if (args.size() != 2)
throw torrent::input_error("Wrong argument count.");
core::ViewManager::iterator itr = control->view_manager()->find(args.back().as_string());
if (itr == control->view_manager()->end())
throw torrent::input_error("Could not find view \"" + args.back().as_string() + "\".");
// if (args.front().as_string() == "main")
// control->ui()->download_list()->set_view(*itr);
// else
throw torrent::input_error("No such target.");
}
torrent::Object
apply_print(rpc::target_type target, const torrent::Object& rawArgs) {
char buffer[1024];
@@ -245,10 +265,23 @@ apply_if(int flags, rpc::target_type target, const torrent::Object& rawArgs) {
if (itr == args.end())
return torrent::Object();
if (flags & 0x1 && itr->is_string())
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
} else if (flags & 0x1 && itr->is_list()) {
// Move this into a special function or something. Also, might be
// nice to have a parse_command function that takes list
// iterator...
for (torrent::Object::list_type::const_iterator cmdItr = itr->as_list().begin(), last = itr->as_list().end(); cmdItr != last; cmdItr++)
if (cmdItr->is_string())
rpc::parse_command(target, cmdItr->as_string().c_str(), cmdItr->as_string().c_str() + cmdItr->as_string().size());
return torrent::Object();
} else {
return *itr;
}
}
void
@@ -257,6 +290,7 @@ initialize_command_ui() {
ADD_COMMAND_STRING("view_add", rpc::object_string_fn(rak::make_mem_fun(control->view_manager(), &core::ViewManager::insert_throw)));
ADD_COMMAND_NONE_L("view_list", rak::ptr_fn(&apply_view_list));
ADD_COMMAND_NONE_L("view_set", rak::ptr_fn(&apply_view_set));
ADD_COMMAND_LIST("view_filter", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_filter));
ADD_COMMAND_LIST("view_filter_on", rak::bind_ptr_fn(&apply_view_filter, &core::ViewManager::set_filter_on));
+1 -2
View File
@@ -98,8 +98,7 @@ Download::priority() {
void
Download::set_priority(uint32_t p) {
if (p >= 4)
throw torrent::input_error("Priority out of range.");
p %= 4;
// Seeding torrents get half the priority of unfinished torrents.
if (!is_done())
+4 -4
View File
@@ -171,7 +171,7 @@ const char*
parse_object(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char)) {
if (*first == '{') {
*dest = torrent::Object::create_list();
first = parse_list(first + 1, last, dest, &parse_is_delim_list);
first = parse_list(first + 1, last, dest, &parse_is_delim_block);
first = parse_skip_wspace(first, last);
if (first == last || *first != '}')
@@ -210,9 +210,9 @@ parse_list(const char* first, const char* last, torrent::Object* dest, bool (*de
}
const char*
parse_whole_list(const char* first, const char* last, torrent::Object* dest) {
parse_whole_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char)) {
first = parse_skip_wspace(first, last);
first = parse_object(first, last, dest);
first = parse_object(first, last, dest, delim);
first = parse_skip_wspace(first, last);
if (first != last && parse_is_seperator(*first)) {
@@ -220,7 +220,7 @@ parse_whole_list(const char* first, const char* last, torrent::Object* dest) {
tmp.swap(*dest);
dest->as_list().push_back(tmp);
first = parse_list(++first, last, dest);
first = parse_list(++first, last, dest, delim);
}
return first;
+11 -3
View File
@@ -38,6 +38,7 @@
#define RTORRENT_RPC_PARSE_H
#include <string>
#include <cctype>
#include <torrent/object.h>
namespace rpc {
@@ -54,8 +55,15 @@ inline bool parse_is_escape(const char c) { return c == '\\'; }
inline bool parse_is_seperator(const char c) { return c == ','; }
inline bool parse_is_space(const char c) { return c == ' ' || c == '\t'; }
// The block delim is used in {} blocks to contain code. Since it
// doesn't check for isspace, it will include useless characters but
// that is the price for sane syntax.
inline bool parse_is_delim_default(const char c) { return parse_is_seperator(c) || std::isspace(c); }
inline bool parse_is_delim_list(const char c) { return parse_is_seperator(c) || c == '}' || std::isspace(c); }
inline bool parse_is_delim_command(const char c) { return parse_is_seperator(c) || c == ';' || std::isspace(c); }
// inline bool parse_is_delim_block(const char c) { return c == ';' || c == '}'; }
inline bool parse_is_delim_block(const char c) { return parse_is_seperator(c) || c == '}'; }
const char* parse_skip_wspace(const char* first);
const char* parse_skip_wspace(const char* first, const char* last);
@@ -69,9 +77,9 @@ const char* parse_value_nothrow(const char* src, int64_t* value, int base = 0, i
void parse_whole_value(const char* src, int64_t* value, int base = 0, int unit = 1);
bool parse_whole_value_nothrow(const char* src, int64_t* value, int base = 0, int unit = 1);
const char* parse_object(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
const char* parse_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
const char* parse_whole_list(const char* first, const char* last, torrent::Object* dest);
const char* parse_object (const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
const char* parse_list (const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
const char* parse_whole_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
std::string convert_list_to_string(const torrent::Object& src);
std::string convert_list_to_string(torrent::Object::list_const_iterator first, torrent::Object::list_const_iterator last);
+1 -1
View File
@@ -117,7 +117,7 @@ parse_command(target_type target, const char* first, const char* last) {
throw torrent::input_error("Could not find '='.");
torrent::Object args;
first = parse_whole_list(first + 1, last, &args);
first = parse_whole_list(first + 1, last, &args, &parse_is_delim_command);
// Find the last character that is part of this command, skipping
// the whitespace at the end. This ensures us that the caller
+17 -69
View File
@@ -63,20 +63,21 @@ ElementDownloadList::ElementDownloadList() :
if (m_view == NULL)
throw torrent::internal_error("View \"main\" must be present to initialize the main display.");
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['\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['\x13'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.start=");
m_bindings['\x04'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "branch=d.get_state=,d.stop=,d.erase=");
m_bindings['\x0B'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.set_ignore_commands=1; d.stop=; 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['\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::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command),
"branch=d.get_ignore_commands=,"
"{d.set_ignore_commands=0, print=\"Torrent set to heed commands.\"},"
"{d.set_ignore_commands=1, print=\"Torrent set to ignore commands.\"}");
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);
m_bindings['U'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "d.delete_tied=; print=\"Cleared tied to file association for the selected download.\"");
// These should also be commands.
m_bindings['1'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "main");
@@ -87,6 +88,7 @@ ElementDownloadList::ElementDownloadList() :
m_bindings['6'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "incomplete");
m_bindings['7'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "hashing");
m_bindings['8'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_change_view), "seeding");
// m_bindings['8'] = sigc::bind(sigc::mem_fun(*this, &ElementDownloadList::receive_command), "view_set=main,seeding", (const char*)NULL);
m_bindings[KEY_UP] = m_bindings['P' - '@'] = sigc::mem_fun(*this, &ElementDownloadList::receive_prev);
m_bindings[KEY_DOWN] = m_bindings['N' - '@'] = sigc::mem_fun(*this, &ElementDownloadList::receive_next);
@@ -145,6 +147,7 @@ ElementDownloadList::receive_command(const char* cmd) {
} catch (torrent::input_error& e) {
control->core()->push_log(e.what());
return;
}
}
@@ -160,39 +163,12 @@ ElementDownloadList::receive_prev() {
m_view->set_last_changed();
}
void
ElementDownloadList::receive_stop_download() {
if (m_view->focus() == m_view->end_visible())
return;
if (rpc::call_command_value("d.get_state", rpc::make_target(*m_view->focus())) == 1)
control->core()->download_list()->stop_normal(*m_view->focus());
else
control->core()->download_list()->erase_ptr(*m_view->focus());
m_view->set_last_changed();
}
void
ElementDownloadList::receive_close_download() {
if (m_view->focus() == m_view->end_visible())
return;
core::Download* download = *m_view->focus();
rpc::call_command("d.set_ignore_commands", (int64_t)1, rpc::make_target(download));
control->core()->download_list()->stop_normal(download);
control->core()->download_list()->close(download);
m_view->set_last_changed();
}
void
ElementDownloadList::receive_next_priority() {
if (m_view->focus() == m_view->end_visible())
return;
(*m_view->focus())->set_priority(((*m_view->focus())->priority() + 1) % 4);
(*m_view->focus())->set_priority((*m_view->focus())->priority() + 1);
m_window->mark_dirty();
}
@@ -201,38 +177,10 @@ ElementDownloadList::receive_prev_priority() {
if (m_view->focus() == m_view->end_visible())
return;
(*m_view->focus())->set_priority(((*m_view->focus())->priority() - 1) % 4);
(*m_view->focus())->set_priority((*m_view->focus())->priority() - 1);
m_window->mark_dirty();
}
void
ElementDownloadList::receive_ignore_ratio() {
if (m_view->focus() == m_view->end_visible())
return;
if (rpc::call_command_value("d.get_ignore_commands", rpc::make_target(*m_view->focus())) != 0) {
rpc::call_command_set_value("d.set_ignore_commands", (int64_t)0, rpc::make_target(*m_view->focus()));
control->core()->push_log("Torrent set to heed commands.");
} else {
rpc::call_command_set_value("d.set_ignore_commands", (int64_t)1, rpc::make_target(*m_view->focus()));
control->core()->push_log("Torrent set to ignore commands.");
}
}
void
ElementDownloadList::receive_clear_tied() {
if (m_view->focus() == m_view->end_visible())
return;
const std::string& tiedFile = rpc::call_command_string("d.get_tied_to_file", rpc::make_target(*m_view->focus()));
if (!tiedFile.empty()) {
rpc::call_command_void("d.delete_tied", rpc::make_target(*m_view->focus()));
control->core()->push_log("Cleared tied to file association for the selected download.");
}
}
void
ElementDownloadList::receive_change_view(const std::string& name) {
core::ViewManager::iterator itr = control->view_manager()->find(name);
-3
View File
@@ -73,9 +73,6 @@ public:
void receive_next_priority();
void receive_prev_priority();
void receive_ignore_ratio();
void receive_clear_tied();
void receive_change_view(const std::string& name);
private:
+2
View File
@@ -74,6 +74,8 @@ public:
WStatusbar* window_statusbar() { return m_windowStatusbar; }
WInput* window_input() { return m_windowInput; }
DownloadList* download_list() { return m_downloadList; }
void set_down_throttle(unsigned int throttle);
void set_up_throttle(unsigned int throttle);
+1
View File
@@ -39,6 +39,7 @@
#include <string>
#include <vector>
#include <inttypes.h>
namespace utils {