Convert some representative files

This commit is contained in:
kannibalox
2024-11-10 09:17:12 -05:00
parent c85f9d6318
commit af23ca8032
3 changed files with 189 additions and 171 deletions
+29 -27
View File
@@ -5,12 +5,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -43,12 +43,12 @@
#include <torrent/download.h>
#include <torrent/exceptions.h>
#include "rpc/parse_commands.h"
#include "rpc/object_storage.h"
#include "control.h"
#include "download.h"
#include "download_list.h"
#include "manager.h"
#include "rpc/object_storage.h"
#include "rpc/parse_commands.h"
#include "view.h"
namespace core {
@@ -57,7 +57,7 @@ namespace core {
struct view_downloads_compare : std::binary_function<Download*, Download*, bool> {
view_downloads_compare(const torrent::Object& cmd) : m_command(cmd) {}
bool operator () (Download* d1, Download* d2) const {
bool operator()(Download* d1, Download* d2) const {
try {
if (m_command.is_empty())
return false;
@@ -75,8 +75,8 @@ struct view_downloads_compare : std::binary_function<Download*, Download*, bool>
// 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();
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());
@@ -91,9 +91,7 @@ struct view_downloads_compare : std::binary_function<Download*, Download*, bool>
struct view_downloads_filter : std::unary_function<Download*, bool> {
view_downloads_filter(const torrent::Object& cmd, const torrent::Object& cmd2) : m_command(cmd), m_command2(cmd2) {}
bool operator () (Download* d1) const {
return this->evalCmd(m_command, d1) && this->evalCmd(m_command2, d1);
}
bool operator()(Download* d1) const { return this->evalCmd(m_command, d1) && this->evalCmd(m_command2, d1); }
bool evalCmd(const torrent::Object& cmd, Download* d1) const {
if (cmd.is_empty())
@@ -121,11 +119,16 @@ struct view_downloads_filter : std::unary_function<Download*, bool> {
switch (result.type()) {
// case torrent::Object::TYPE_RAW_BENCODE: return !result.as_raw_bencode().empty();
case torrent::Object::TYPE_VALUE: return result.as_value();
case torrent::Object::TYPE_STRING: return !result.as_string().empty();
case torrent::Object::TYPE_LIST: return !result.as_list().empty();
case torrent::Object::TYPE_MAP: return !result.as_map().empty();
default: return false;
case torrent::Object::TYPE_VALUE:
return result.as_value();
case torrent::Object::TYPE_STRING:
return !result.as_string().empty();
case torrent::Object::TYPE_LIST:
return !result.as_list().empty();
case torrent::Object::TYPE_MAP:
return !result.as_map().empty();
default:
return false;
}
// The default filter action is to return true, to not filter
@@ -139,8 +142,8 @@ struct view_downloads_filter : std::unary_function<Download*, bool> {
}
}
const torrent::Object& m_command;
const torrent::Object& m_command2;
const torrent::Object& m_command;
const torrent::Object& m_command2;
};
void
@@ -177,7 +180,7 @@ View::initialize(const std::string& name) {
// Urgh, wrong. No filtering being done.
std::for_each(dlist->begin(), dlist->end(), rak::bind1st(std::mem_fun(&View::push_back), this));
m_size = base_type::size();
m_size = base_type::size();
m_focus = 0;
set_last_changed(rak::timer());
@@ -266,12 +269,13 @@ View::filter() {
return;
// Parition the list in two steps so we know which elements changed.
iterator splitVisible = std::stable_partition(begin_visible(), end_visible(), view_downloads_filter(m_filter, m_temp_filter));
iterator splitFiltered = std::stable_partition(begin_filtered(), end_filtered(), view_downloads_filter(m_filter, m_temp_filter));
iterator splitVisible = std::stable_partition(begin_visible(), end_visible(), view_downloads_filter(m_filter, m_temp_filter));
iterator splitFiltered =
std::stable_partition(begin_filtered(), end_filtered(), view_downloads_filter(m_filter, m_temp_filter));
base_type changed(splitVisible, splitFiltered);
iterator splitChanged = changed.begin() + std::distance(splitVisible, end_visible());
iterator splitChanged = changed.begin() + std::distance(splitVisible, end_visible());
m_size = std::distance(begin(), std::copy(splitChanged, changed.end(), splitVisible));
std::copy(changed.begin(), splitChanged, begin_filtered());
@@ -289,12 +293,10 @@ View::filter() {
// set the elements to NULL as we trigger commands on them. Or
// perhaps always clear them, thus not throwing anything.
if (!m_event_removed.is_empty())
std::for_each(changed.begin(), splitChanged,
std::bind(&rpc::call_object_d_nothrow, m_event_removed, std::placeholders::_1));
std::for_each(changed.begin(), splitChanged, std::bind(&rpc::call_object_d_nothrow, m_event_removed, std::placeholders::_1));
if (!m_event_added.is_empty())
std::for_each(changed.begin(), splitChanged,
std::bind(&rpc::call_object_d_nothrow, m_event_added, std::placeholders::_1));
std::for_each(changed.begin(), splitChanged, std::bind(&rpc::call_object_d_nothrow, m_event_added, std::placeholders::_1));
emit_changed();
}
@@ -376,4 +378,4 @@ View::erase_internal(iterator itr) {
base_type::erase(itr);
}
}
} // namespace core
+70 -67
View File
@@ -5,12 +5,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -64,77 +64,80 @@ class Download;
class View : private std::vector<Download*> {
public:
typedef std::vector<Download*> base_type;
typedef std::function<void ()> slot_void;
typedef std::list<slot_void> signal_void;
typedef std::vector<Download*> base_type;
typedef std::function<void()> slot_void;
typedef std::list<slot_void> signal_void;
using base_type::iterator;
using base_type::const_iterator;
using base_type::reverse_iterator;
using base_type::const_reverse_iterator;
using base_type::iterator;
using base_type::reverse_iterator;
using base_type::size_type;
View() {}
~View();
void initialize(const std::string& name);
void initialize(const std::string& name);
const std::string& name() const { return m_name; }
const std::string& name() const { return m_name; }
bool empty_visible() const { return m_size == 0; }
bool empty_visible() const { return m_size == 0; }
size_type size() const { return m_size; }
size_type size_visible() const { return m_size; }
size_type size_not_visible() const { return base_type::size() - m_size; }
size_type size() const { return m_size; }
size_type size_visible() const { return m_size; }
size_type size_not_visible() const { return base_type::size() - m_size; }
// Perhaps this should be renamed?
iterator begin_visible() { return begin(); }
const_iterator begin_visible() const { return begin(); }
iterator begin_visible() { return begin(); }
const_iterator begin_visible() const { return begin(); }
iterator end_visible() { return begin() + m_size; }
const_iterator end_visible() const { return begin() + m_size; }
iterator end_visible() { return begin() + m_size; }
const_iterator end_visible() const { return begin() + m_size; }
iterator begin_filtered() { return begin() + m_size; }
const_iterator begin_filtered() const { return begin() + m_size; }
iterator begin_filtered() { return begin() + m_size; }
const_iterator begin_filtered() const { return begin() + m_size; }
iterator end_filtered() { return base_type::end(); }
const_iterator end_filtered() const { return base_type::end(); }
iterator end_filtered() { return base_type::end(); }
const_iterator end_filtered() const { return base_type::end(); }
iterator focus() { return begin() + m_focus; }
const_iterator focus() const { return begin() + m_focus; }
void set_focus(iterator itr) { m_focus = position(itr); emit_changed(); }
iterator focus() { return begin() + m_focus; }
const_iterator focus() const { return begin() + m_focus; }
void set_focus(iterator itr) {
m_focus = position(itr);
emit_changed();
}
void insert(Download* download) { base_type::push_back(download); }
void erase(Download* download);
void insert(Download* download) { base_type::push_back(download); }
void erase(Download* download);
void set_visible(Download* download);
void set_not_visible(Download* download);
void set_visible(Download* download);
void set_not_visible(Download* download);
void next_focus();
void prev_focus();
void next_focus();
void prev_focus();
void sort();
void sort();
void set_sort_new(const torrent::Object& s) { m_sortNew = s; }
void set_sort_current(const torrent::Object& 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_by(const torrent::Object& condition, base_type& result);
void filter_download(core::Download* download);
void filter();
void filter_by(const torrent::Object& condition, base_type& result);
void filter_download(core::Download* download);
const torrent::Object& get_filter() const { return m_filter; }
void set_filter(const torrent::Object& s) { m_filter = s; }
void set_filter(const torrent::Object& s) { m_filter = s; }
const torrent::Object& get_filter_temp() const { return m_temp_filter; }
void set_filter_temp(const torrent::Object& s) { m_temp_filter = s; }
void set_filter_on_event(const std::string& event);
void set_filter_temp(const torrent::Object& s) { m_temp_filter = s; }
void set_filter_on_event(const std::string& event);
void clear_filter_on();
void clear_filter_on();
const torrent::Object& event_added() const { return m_event_added; }
const torrent::Object& event_removed() const { return m_event_removed; }
void set_event_added(const torrent::Object& cmd) { m_event_added = cmd; }
const torrent::Object& event_added() const { return m_event_added; }
const torrent::Object& event_removed() const { return m_event_removed; }
void set_event_added(const torrent::Object& cmd) { m_event_added = cmd; }
void set_event_removed(const torrent::Object& cmd) { m_event_removed = cmd; }
// The time of the last change to the view, semantics of this is
@@ -143,50 +146,50 @@ public:
//
// Currently initialized to rak::timer(), though perhaps we should
// use cachedTimer.
rak::timer last_changed() const { return m_lastChanged; }
void set_last_changed(const rak::timer& t = ::cachedTime) { m_lastChanged = t; }
rak::timer last_changed() const { return m_lastChanged; }
void set_last_changed(const rak::timer& t = ::cachedTime) { m_lastChanged = t; }
// Don't connect any slots until after initialize else it get's
// triggered when adding the Download's in DownloadList.
signal_void& signal_changed() { return m_signal_changed; }
signal_void& signal_changed() { return m_signal_changed; }
private:
View(const View&);
void operator = (const View&);
void operator=(const View&);
void push_back(Download* d) { base_type::push_back(d); }
void push_back(Download* d) { base_type::push_back(d); }
inline void insert_visible(Download* d);
inline void erase_internal(iterator itr);
inline void insert_visible(Download* d);
inline void erase_internal(iterator itr);
void emit_changed();
void emit_changed_now();
void emit_changed();
void emit_changed_now();
size_type position(const_iterator itr) const { return itr - begin(); }
size_type position(const_iterator itr) const { return itr - begin(); }
// An received thing for changed status so we can sort and filter.
std::string m_name;
std::string m_name;
size_type m_size;
size_type m_focus;
size_type m_size;
size_type m_focus;
// These should be replaced by a faster non-string command type.
torrent::Object m_sortNew;
torrent::Object m_sortCurrent;
torrent::Object m_sortNew;
torrent::Object m_sortCurrent;
torrent::Object m_filter;
torrent::Object m_temp_filter; // Temporary view filter (eg: name based filter)
torrent::Object m_filter;
torrent::Object m_temp_filter; // Temporary view filter (eg: name based filter)
torrent::Object m_event_added;
torrent::Object m_event_removed;
torrent::Object m_event_added;
torrent::Object m_event_removed;
rak::timer m_lastChanged;
rak::timer m_lastChanged;
signal_void m_signal_changed;
rak::priority_item m_delayChanged;
signal_void m_signal_changed;
rak::priority_item m_delayChanged;
};
}
} // namespace core
#endif