mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-15 06:32:31 +00:00
* Changed ViewSort::less(...) to operator().
* Added a "last changed" paramter to ViewManager::sort(...) which is checked, if the ViewDownloads's last_changed timer was poked withing that timeframe it won't update. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@676 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -76,6 +76,8 @@ ViewDownloads::initialize(const std::string& name, core::DownloadList* list) {
|
||||
m_size = 0;
|
||||
m_focus = 0;
|
||||
|
||||
set_last_changed(rak::timer());
|
||||
|
||||
std::for_each(m_list->begin(), m_list->end(), std::bind1st(std::mem_fun(&ViewDownloads::received_insert), this));
|
||||
|
||||
m_list->slot_map_insert()[key] = sigc::mem_fun(this, &ViewDownloads::received_insert);
|
||||
@@ -111,9 +113,9 @@ struct view_downloads_compare : std::binary_function<Download*, Download*, bool>
|
||||
|
||||
bool operator () (Download* d1, Download* d2) const {
|
||||
for (ViewDownloads::sort_list::const_iterator itr = m_sort.begin(), last = m_sort.end(); itr != last; ++itr)
|
||||
if ((*itr)->less(d1, d2))
|
||||
if ((**itr)(d1, d2))
|
||||
return true;
|
||||
else if ((*itr)->less(d2, d1))
|
||||
else if ((**itr)(d2, d1))
|
||||
return false;
|
||||
|
||||
// Since we're testing equivalence, return false if we're
|
||||
|
||||
@@ -37,11 +37,9 @@
|
||||
// Provides a filtered and sorted list of downloads that can be
|
||||
// updated auto-magically.
|
||||
//
|
||||
// We don't worry about std::vector's insert/erase performance as it
|
||||
// get's called so often, better with cache locality.
|
||||
//
|
||||
// Do we want to be able to modify the underlying DownloadList from
|
||||
// here?
|
||||
// We don't worry about std::vector's insert/erase performance as the
|
||||
// elements get accessed often but not modified, better with cache
|
||||
// locality.
|
||||
//
|
||||
// ViewDownloads::m_size indicates the number of Download's that
|
||||
// remain visible, e.g. has not been filtered out. The Download's that
|
||||
@@ -54,9 +52,11 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
//#include <rak/timer.h>
|
||||
#include <rak/timer.h>
|
||||
#include <sigc++/signal.h>
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
class Download;
|
||||
@@ -116,6 +116,15 @@ public:
|
||||
void filter();
|
||||
void set_filter(const filter_list& s) { m_filter = s; }
|
||||
|
||||
// The time of the last change to the view, semantics of this is
|
||||
// user-dependent. Used by f.ex. ViewManager to decide if it should
|
||||
// sort and/or filter a view.
|
||||
//
|
||||
// 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; }
|
||||
|
||||
// Don't connect any slots until after initialize else it get's
|
||||
// triggered when adding the Download's in DownloadList.
|
||||
signal_type& signal_changed() { return m_signalChanged; }
|
||||
@@ -143,8 +152,7 @@ private:
|
||||
|
||||
filter_list m_filter;
|
||||
|
||||
// Timer, last changed.
|
||||
|
||||
rak::timer m_lastChanged;
|
||||
signal_type m_signalChanged;
|
||||
};
|
||||
|
||||
@@ -152,7 +160,7 @@ class ViewSort {
|
||||
public:
|
||||
virtual ~ViewSort() {}
|
||||
|
||||
virtual bool less(Download* d1, Download* d2) const = 0;
|
||||
virtual bool operator () (Download* d1, Download* d2) const = 0;
|
||||
};
|
||||
|
||||
class ViewFilter {
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include <rak/functional.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
#include "download.h"
|
||||
#include "view_downloads.h"
|
||||
#include "view_manager.h"
|
||||
@@ -48,7 +50,7 @@ namespace core {
|
||||
|
||||
class ViewSortName : public ViewSort {
|
||||
public:
|
||||
virtual bool less(Download* d1, Download* d2) const {
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return d1->download()->name() < d2->download()->name();
|
||||
}
|
||||
};
|
||||
@@ -58,7 +60,7 @@ public:
|
||||
ViewSortVariable(const std::string& name, const std::string& value) :
|
||||
m_name(name), m_value(value) {}
|
||||
|
||||
virtual bool less(Download* d1, Download* d2) const {
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return
|
||||
d1->variable()->get_string(m_name) == m_value &&
|
||||
d2->variable()->get_string(m_name) != m_value;
|
||||
@@ -74,7 +76,7 @@ public:
|
||||
ViewSortVariableValue(const std::string& name) :
|
||||
m_name(name) {}
|
||||
|
||||
virtual bool less(Download* d1, Download* d2) const {
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return d1->variable()->get_value(m_name) < d2->variable()->get_value(m_name);
|
||||
}
|
||||
|
||||
@@ -87,8 +89,8 @@ public:
|
||||
ViewSortReverse(ViewSort* s) : m_sort(s) {}
|
||||
~ViewSortReverse() { delete m_sort; }
|
||||
|
||||
virtual bool less(Download* d1, Download* d2) const {
|
||||
return m_sort->less(d2, d1);
|
||||
virtual bool operator () (Download* d1, Download* d2) const {
|
||||
return (*m_sort)(d2, d1);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -126,6 +128,7 @@ ViewManager::ViewManager(DownloadList* dl) :
|
||||
m_sort["state_changed_reverse"] = new ViewSortReverse(new ViewSortVariableValue("state_changed"));
|
||||
|
||||
m_filter["started"] = new ViewFilterVariableValue("state", 1);
|
||||
m_filter["stopped"] = new ViewFilterVariableValue("state", 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -180,9 +183,12 @@ ViewManager::build_sort_list(const sort_args& args) {
|
||||
}
|
||||
|
||||
void
|
||||
ViewManager::sort(const std::string& name) {
|
||||
ViewManager::sort(const std::string& name, uint32_t timeout) {
|
||||
iterator viewItr = find_throw(name);
|
||||
|
||||
if ((*viewItr)->last_changed() + rak::timer::from_seconds(timeout) > cachedTime)
|
||||
return;
|
||||
|
||||
// Should we rename sort, or add a seperate function?
|
||||
(*viewItr)->filter();
|
||||
|
||||
|
||||
@@ -92,7 +92,11 @@ public:
|
||||
iterator find(const std::string& name);
|
||||
iterator find_throw(const std::string& name);
|
||||
|
||||
void sort(const std::string& name);
|
||||
// If ViewDownloads::last_changed() is less than 'timeout' seconds
|
||||
// ago, don't sort.
|
||||
//
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user