mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 22:29:23 +00:00
* Replaced View sort code with commands.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1044 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+11
-11
@@ -92,7 +92,6 @@ View::next_focus() {
|
||||
return;
|
||||
|
||||
m_focus = (m_focus + 1) % (size() + 1);
|
||||
|
||||
m_signalChanged.emit();
|
||||
}
|
||||
|
||||
@@ -102,7 +101,6 @@ View::prev_focus() {
|
||||
return;
|
||||
|
||||
m_focus = (m_focus - 1 + size() + 1) % (size() + 1);
|
||||
|
||||
m_signalChanged.emit();
|
||||
}
|
||||
|
||||
@@ -111,21 +109,23 @@ View::prev_focus() {
|
||||
|
||||
// Also add focus thingie here?
|
||||
struct view_downloads_compare : std::binary_function<Download*, Download*, bool> {
|
||||
view_downloads_compare(const View::sort_list& s) : m_sort(s) {}
|
||||
view_downloads_compare(const std::string& cmd) : m_command(cmd) {}
|
||||
|
||||
bool operator () (Download* d1, Download* d2) const {
|
||||
for (View::sort_list::const_iterator itr = m_sort.begin(), last = m_sort.end(); itr != last; ++itr)
|
||||
if ((**itr)(d1, d2))
|
||||
return true;
|
||||
else if ((**itr)(d2, d1))
|
||||
try {
|
||||
if (m_command.empty())
|
||||
return false;
|
||||
|
||||
// Since we're testing equivalence, return false if we're
|
||||
// equal. This is a requirement for the stl sorting algorithms.
|
||||
return false;
|
||||
return rpc::parse_command_single(rpc::make_target_pair(d1, d2), m_command).as_value();
|
||||
|
||||
} catch (torrent::input_error& e) {
|
||||
// control->core()->push_log(e.what());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const View::sort_list& m_sort;
|
||||
const std::string& m_command;
|
||||
};
|
||||
|
||||
struct view_downloads_filter : std::unary_function<Download*, bool> {
|
||||
|
||||
+5
-15
@@ -61,13 +61,11 @@ namespace core {
|
||||
|
||||
class Download;
|
||||
class DownloadList;
|
||||
class ViewSort;
|
||||
|
||||
class View : private std::vector<Download*> {
|
||||
public:
|
||||
typedef std::vector<Download*> base_type;
|
||||
typedef sigc::signal0<void> signal_type;
|
||||
typedef std::vector<const ViewSort*> sort_list;
|
||||
|
||||
using base_type::iterator;
|
||||
using base_type::const_iterator;
|
||||
@@ -109,8 +107,8 @@ public:
|
||||
|
||||
void sort();
|
||||
|
||||
void set_sort_new(const sort_list& s) { m_sortNew = s; }
|
||||
void set_sort_current(const sort_list& s) { m_sortCurrent = s; }
|
||||
void set_sort_new(const std::string& s) { m_sortNew = s; }
|
||||
void set_sort_current(const std::string& s) { m_sortCurrent = s; }
|
||||
|
||||
// Need to explicity trigger filtering.
|
||||
void filter();
|
||||
@@ -118,7 +116,6 @@ public:
|
||||
void set_filter(const std::string& s) { m_filter = s; }
|
||||
void set_filter_on(int event);
|
||||
|
||||
|
||||
void clear_filter_on();
|
||||
|
||||
// The time of the last change to the view, semantics of this is
|
||||
@@ -156,23 +153,16 @@ private:
|
||||
size_type m_size;
|
||||
size_type m_focus;
|
||||
|
||||
sort_list m_sortNew;
|
||||
sort_list m_sortCurrent;
|
||||
// These should be replaced by a faster non-string command type.
|
||||
std::string m_sortNew;
|
||||
std::string m_sortCurrent;
|
||||
|
||||
// This should be replaced by a faster non-string command type.
|
||||
std::string m_filter;
|
||||
|
||||
rak::timer m_lastChanged;
|
||||
signal_type m_signalChanged;
|
||||
};
|
||||
|
||||
class ViewSort {
|
||||
public:
|
||||
virtual ~ViewSort() {}
|
||||
|
||||
virtual bool operator () (Download* d1, Download* d2) const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -53,87 +53,15 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
class ViewSortFalse : public ViewSort {
|
||||
public:
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
class ViewSortName : public ViewSort {
|
||||
public:
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return d1->download()->name() < d2->download()->name();
|
||||
}
|
||||
};
|
||||
|
||||
class ViewSortVariable : public ViewSort {
|
||||
public:
|
||||
ViewSortVariable(const char* name, const char* value) : m_name(name), m_value(value) {}
|
||||
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return
|
||||
rpc::call_command_string(m_name, rpc::make_target(d1)) == m_value &&
|
||||
rpc::call_command_string(m_name, rpc::make_target(d2)) != m_value;
|
||||
}
|
||||
|
||||
private:
|
||||
const char* m_name;
|
||||
const char* m_value;
|
||||
};
|
||||
|
||||
class ViewSortVariableValue : public ViewSort {
|
||||
public:
|
||||
ViewSortVariableValue(const char* name, bool reverse = false) : m_name(name), m_reverse(reverse) {}
|
||||
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
if (m_reverse)
|
||||
return rpc::call_command_value(m_name, rpc::make_target(d2)) < rpc::call_command_value(m_name, rpc::make_target(d1));
|
||||
else
|
||||
return rpc::call_command_value(m_name, rpc::make_target(d1)) < rpc::call_command_value(m_name, rpc::make_target(d2));
|
||||
}
|
||||
|
||||
private:
|
||||
const char* m_name;
|
||||
bool m_reverse;
|
||||
};
|
||||
|
||||
class ViewSortReverse : public ViewSort {
|
||||
public:
|
||||
ViewSortReverse(ViewSort* s) : m_sort(s) {}
|
||||
~ViewSortReverse() { delete m_sort; }
|
||||
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return (*m_sort)(d2, d1);
|
||||
}
|
||||
|
||||
private:
|
||||
ViewSort* m_sort;
|
||||
};
|
||||
|
||||
// Really need to implement a factory and allow options in the sort
|
||||
// statements.
|
||||
ViewManager::ViewManager(DownloadList* dl) :
|
||||
m_list(dl) {
|
||||
|
||||
// m_sort["first"] = new ViewSortNot(new ViewSort());
|
||||
m_sort["last"] = new ViewSortFalse();
|
||||
m_sort["name"] = new ViewSortName();
|
||||
m_sort["name_reverse"] = new ViewSortReverse(new ViewSortName());
|
||||
|
||||
m_sort["stopped"] = new ViewSortVariableValue("d.get_state");
|
||||
m_sort["started"] = new ViewSortVariableValue("d.get_state", true);
|
||||
m_sort["complete"] = new ViewSortVariableValue("d.get_complete");
|
||||
m_sort["incomplete"] = new ViewSortVariableValue("d.get_complete", true);
|
||||
|
||||
m_sort["state_changed"] = new ViewSortVariableValue("d.get_state_changed");
|
||||
m_sort["state_changed_reverse"] = new ViewSortVariableValue("d.get_state_changed", true);
|
||||
}
|
||||
|
||||
void
|
||||
ViewManager::clear() {
|
||||
std::for_each(begin(), end(), rak::call_delete<View>());
|
||||
std::for_each(m_sort.begin(), m_sort.end(), rak::on(rak::mem_ref(&sort_map::value_type::second), rak::call_delete<ViewSort>()));
|
||||
|
||||
base_type::clear();
|
||||
}
|
||||
@@ -164,23 +92,6 @@ ViewManager::find_throw(const std::string& name) {
|
||||
return itr;
|
||||
}
|
||||
|
||||
inline ViewManager::sort_list
|
||||
ViewManager::build_sort_list(const sort_args& args) {
|
||||
View::sort_list sortList;
|
||||
sortList.reserve(args.size());
|
||||
|
||||
for (sort_args::const_iterator itr = args.begin(), last = args.end(); itr != last; ++itr) {
|
||||
sort_map::const_iterator sortItr = m_sort.find(itr->c_str());
|
||||
|
||||
if (sortItr == m_sort.end())
|
||||
throw torrent::input_error("Invalid sorting identifier.");
|
||||
|
||||
sortList.push_back(sortItr->second);
|
||||
}
|
||||
|
||||
return sortList;
|
||||
}
|
||||
|
||||
void
|
||||
ViewManager::sort(const std::string& name, uint32_t timeout) {
|
||||
iterator viewItr = find_throw(name);
|
||||
@@ -190,22 +101,21 @@ ViewManager::sort(const std::string& name, uint32_t timeout) {
|
||||
|
||||
// Should we rename sort, or add a seperate function?
|
||||
(*viewItr)->filter();
|
||||
|
||||
(*viewItr)->sort();
|
||||
}
|
||||
|
||||
void
|
||||
ViewManager::set_sort_new(const std::string& name, const sort_args& sort) {
|
||||
ViewManager::set_sort_new(const std::string& name, const std::string& cmd) {
|
||||
iterator viewItr = find_throw(name);
|
||||
|
||||
(*viewItr)->set_sort_new(build_sort_list(sort));
|
||||
(*viewItr)->set_sort_new(cmd);
|
||||
}
|
||||
|
||||
void
|
||||
ViewManager::set_sort_current(const std::string& name, const sort_args& sort) {
|
||||
ViewManager::set_sort_current(const std::string& name, const std::string& cmd) {
|
||||
iterator viewItr = find_throw(name);
|
||||
|
||||
(*viewItr)->set_sort_current(build_sort_list(sort));
|
||||
(*viewItr)->set_sort_current(cmd);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+3
-20
@@ -37,8 +37,6 @@
|
||||
#ifndef RTORRENT_CORE_VIEW_MANAGER_H
|
||||
#define RTORRENT_CORE_VIEW_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <rak/unordered_vector.h>
|
||||
|
||||
@@ -46,21 +44,10 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
struct view_manager_comp : public std::binary_function<const char*, const char*, bool> {
|
||||
bool operator () (const char* arg1, const char* arg2) const { return std::strcmp(arg1, arg2) < 0; }
|
||||
};
|
||||
|
||||
class ViewSort;
|
||||
|
||||
class ViewManager : public rak::unordered_vector<View*> {
|
||||
public:
|
||||
typedef rak::unordered_vector<View*> base_type;
|
||||
|
||||
typedef std::map<const char*, ViewSort*, view_manager_comp> sort_map;
|
||||
typedef View::sort_list sort_list;
|
||||
typedef std::list<std::string> sort_args;
|
||||
|
||||
typedef std::list<std::string> filter_args;
|
||||
typedef std::list<std::string> filter_args;
|
||||
|
||||
using base_type::iterator;
|
||||
using base_type::const_iterator;
|
||||
@@ -100,18 +87,14 @@ public:
|
||||
// Find a better name for 'timeout'.
|
||||
void sort(const std::string& name, uint32_t timeout = 0);
|
||||
|
||||
void set_sort_new(const std::string& name, const sort_args& sort);
|
||||
void set_sort_current(const std::string& name, const sort_args& sort);
|
||||
void set_sort_new(const std::string& name, const std::string& cmd);
|
||||
void set_sort_current(const std::string& name, const std::string& cmd);
|
||||
|
||||
void set_filter(const std::string& name, const std::string& cmd);
|
||||
void set_filter_on(const std::string& name, const filter_args& args);
|
||||
|
||||
private:
|
||||
inline sort_list build_sort_list(const sort_args& args);
|
||||
|
||||
DownloadList* m_list;
|
||||
|
||||
sort_map m_sort;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user