mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 04:32:30 +00:00
* Optimized view filtering and sorting.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1213 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+39
-8
@@ -55,14 +55,28 @@ namespace core {
|
||||
|
||||
// Also add focus thingie here?
|
||||
struct view_downloads_compare : std::binary_function<Download*, Download*, bool> {
|
||||
view_downloads_compare(const std::string& cmd) : m_command(cmd) {}
|
||||
view_downloads_compare(const torrent::Object& cmd) : m_command(cmd) {}
|
||||
|
||||
bool operator () (Download* d1, Download* d2) const {
|
||||
try {
|
||||
if (m_command.empty())
|
||||
if (m_command.is_empty())
|
||||
return false;
|
||||
|
||||
return rpc::parse_command_single(rpc::make_target_pair(d1, d2), m_command).as_value();
|
||||
if (!m_command.is_dict_key())
|
||||
return rpc::parse_command_single(rpc::make_target_pair(d1, d2), m_command.as_string()).as_value();
|
||||
|
||||
// torrent::Object tmp_command = m_command;
|
||||
|
||||
// uint32_t flags = tmp_command.flags() & torrent::Object::mask_function;
|
||||
// tmp_command.unset_flags(torrent::Object::mask_function);
|
||||
// tmp_command.set_flags((flags >> 1) & torrent::Object::mask_function);
|
||||
|
||||
// rpc::parse_command_execute(rpc::make_target_pair(d1, d2), &tmp_command);
|
||||
// return rpc::commands.call_command(tmp_command.as_dict_key().c_str(), tmp_command.as_dict_obj(),
|
||||
// rpc::make_target_pair(d1, d2)).as_value();
|
||||
|
||||
return rpc::commands.call_command(m_command.as_dict_key().c_str(), m_command.as_dict_obj(),
|
||||
rpc::make_target_pair(d1, d2)).as_value();
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
control->core()->push_log(e.what());
|
||||
@@ -71,18 +85,35 @@ struct view_downloads_compare : std::binary_function<Download*, Download*, bool>
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& m_command;
|
||||
const torrent::Object& m_command;
|
||||
};
|
||||
|
||||
struct view_downloads_filter : std::unary_function<Download*, bool> {
|
||||
view_downloads_filter(const std::string& cmd) : m_command(cmd) {}
|
||||
view_downloads_filter(const torrent::Object& cmd) : m_command(cmd) {}
|
||||
|
||||
bool operator () (Download* d1) const {
|
||||
if (m_command.empty())
|
||||
if (m_command.is_empty())
|
||||
return true;
|
||||
|
||||
try {
|
||||
torrent::Object result = rpc::parse_command_single(rpc::make_target(d1), m_command);
|
||||
torrent::Object result;
|
||||
|
||||
if (m_command.is_dict_key()) {
|
||||
// torrent::Object tmp_command = m_command;
|
||||
|
||||
// uint32_t flags = tmp_command.flags() & torrent::Object::mask_function;
|
||||
// tmp_command.unset_flags(torrent::Object::mask_function);
|
||||
// tmp_command.set_flags((flags >> 1) & torrent::Object::mask_function);
|
||||
|
||||
// rpc::parse_command_execute(rpc::make_target(d1), &tmp_command);
|
||||
// result = rpc::commands.call_command(tmp_command.as_dict_key().c_str(), tmp_command.as_dict_obj(),
|
||||
// rpc::make_target(d1));
|
||||
|
||||
result = rpc::commands.call_command(m_command.as_dict_key().c_str(), m_command.as_dict_obj(), rpc::make_target(d1));
|
||||
|
||||
} else {
|
||||
result = rpc::parse_command_single(rpc::make_target(d1), m_command.as_string());
|
||||
}
|
||||
|
||||
switch (result.type()) {
|
||||
// case torrent::Object::TYPE_RAW_BENCODE: return !result.as_raw_bencode().empty();
|
||||
@@ -104,7 +135,7 @@ struct view_downloads_filter : std::unary_function<Download*, bool> {
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& m_command;
|
||||
const torrent::Object& m_command;
|
||||
};
|
||||
|
||||
inline void
|
||||
|
||||
+8
-7
@@ -54,6 +54,7 @@
|
||||
#include <vector>
|
||||
#include <rak/timer.h>
|
||||
#include <sigc++/signal.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
@@ -115,15 +116,15 @@ public:
|
||||
|
||||
void sort();
|
||||
|
||||
void set_sort_new(const std::string& s) { m_sortNew = s; }
|
||||
void set_sort_current(const std::string& s) { m_sortCurrent = s; }
|
||||
void set_sort_new(const torrent::Object& s) { m_sortNew = s; }
|
||||
void set_sort_current(const torrent::Object& s) { m_sortCurrent = s; }
|
||||
|
||||
// Need to explicity trigger filtering.
|
||||
void filter();
|
||||
void filter_download(core::Download* download);
|
||||
|
||||
const std::string& get_filter() const { return m_filter; }
|
||||
void set_filter(const std::string& s) { m_filter = s; }
|
||||
const torrent::Object& get_filter() const { return m_filter; }
|
||||
void set_filter(const torrent::Object& s) { m_filter = s; }
|
||||
void set_filter_on_event(const std::string& event);
|
||||
|
||||
void clear_filter_on();
|
||||
@@ -167,10 +168,10 @@ private:
|
||||
size_type m_focus;
|
||||
|
||||
// These should be replaced by a faster non-string command type.
|
||||
std::string m_sortNew;
|
||||
std::string m_sortCurrent;
|
||||
torrent::Object m_sortNew;
|
||||
torrent::Object m_sortCurrent;
|
||||
|
||||
std::string m_filter;
|
||||
torrent::Object m_filter;
|
||||
event_list_type m_events;
|
||||
|
||||
std::string m_eventAdded;
|
||||
|
||||
@@ -102,7 +102,7 @@ ViewManager::sort(const std::string& name, uint32_t timeout) {
|
||||
}
|
||||
|
||||
void
|
||||
ViewManager::set_filter(const std::string& name, const std::string& cmd) {
|
||||
ViewManager::set_filter(const std::string& name, const torrent::Object& cmd) {
|
||||
iterator viewItr = find_throw(name);
|
||||
|
||||
(*viewItr)->set_filter(cmd);
|
||||
|
||||
@@ -88,10 +88,10 @@ public:
|
||||
void sort(const std::string& name, uint32_t timeout = 0);
|
||||
|
||||
// These could be moved to where the command is implemented.
|
||||
void set_sort_new(const std::string& name, const std::string& cmd) { (*find_throw(name))->set_sort_new(cmd); }
|
||||
void set_sort_current(const std::string& name, const std::string& cmd) { (*find_throw(name))->set_sort_current(cmd); }
|
||||
void set_sort_new(const std::string& name, const torrent::Object& cmd) { (*find_throw(name))->set_sort_new(cmd); }
|
||||
void set_sort_current(const std::string& name, const torrent::Object& cmd) { (*find_throw(name))->set_sort_current(cmd); }
|
||||
|
||||
void set_filter(const std::string& name, const std::string& cmd);
|
||||
void set_filter(const std::string& name, const torrent::Object& cmd);
|
||||
void set_filter_on(const std::string& name, const filter_args& args);
|
||||
|
||||
void set_event_added(const std::string& name, const std::string& cmd) { (*find_throw(name))->set_event_added(cmd); }
|
||||
|
||||
Reference in New Issue
Block a user