* The curl bind address was being set by set_local_address(...), urgh.

* Made IPv6 stuff configurable.

* Improved the view stuff.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@672 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-04-23 23:17:05 +00:00
parent 11c842308a
commit 598455a5df
8 changed files with 141 additions and 56 deletions
-2
View File
@@ -291,8 +291,6 @@ Manager::set_local_address(const std::string& addr) {
torrent::connection_manager()->set_local_address(ai->address()->c_sockaddr());
rak::address_info::free_address_info(ai);
m_pollManager->get_http_stack()->set_bind_address(addr);
} catch (torrent::input_error& e) {
rak::address_info::free_address_info(ai);
throw e;
+16 -7
View File
@@ -75,10 +75,10 @@ ViewDownloads::initialize(const std::string& name, core::DownloadList* list) {
m_list = list;
m_focus = 0;
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);
m_list->slot_map_erase()[key] = sigc::mem_fun(this, &ViewDownloads::received_erase);
// Add from download, do various stuff to them.
}
void
@@ -101,11 +101,22 @@ ViewDownloads::prev_focus() {
m_signalChanged.emit();
}
// Also add focus thingie here.
struct view_downloads_compare : std::binary_function<Download*, Download*, bool> {
view_downloads_compare(const ViewSort* s) : m_sort(s) {}
bool operator () (Download* d1, Download* d2) const {
return m_sort->compare(d1, d2);
}
const ViewSort* m_sort;
};
void
ViewDownloads::sort(sort_slot s) {
ViewDownloads::sort(const ViewSort* s) {
Download* curFocus = focus() != end() ? *focus() : NULL;
std::sort(begin(), end(), std::ptr_fun(s));
std::sort(begin(), end(), view_downloads_compare(s));
m_focus = position(std::find(begin(), end(), curFocus));
m_signalChanged.emit();
@@ -113,9 +124,7 @@ ViewDownloads::sort(sort_slot s) {
void
ViewDownloads::received_insert(core::Download* d) {
iterator itr = m_sortNew != NULL ?
std::find_if(begin(), end(), std::bind1st(std::ptr_fun(m_sortNew), d)) :
end();
iterator itr = std::find_if(begin(), end(), std::bind1st(view_downloads_compare(m_sortNew), d));
if (m_focus >= position(itr))
m_focus++;
+21 -9
View File
@@ -46,6 +46,7 @@
#ifndef RTORRENT_CORE_VIEW_DOWNLOADS_H
#define RTORRENT_CORE_VIEW_DOWNLOADS_H
#include <memory>
#include <string>
#include <vector>
#include <sigc++/signal.h>
@@ -54,18 +55,13 @@ namespace core {
class Download;
class DownloadList;
class ViewSort;
class ViewDownloads : public std::vector<core::Download*> {
public:
typedef std::vector<core::Download*> base_type;
typedef sigc::signal0<void> signal_type;
// Switch with a base class that defines some function. We might
// want to include some parameters etc.
//
// Also, it should be possible to check the focus index etc.
typedef bool (*sort_slot)(core::Download* d1, core::Download* d2);
using base_type::iterator;
using base_type::const_iterator;
using base_type::reverse_iterator;
@@ -95,10 +91,14 @@ public:
void next_focus();
void prev_focus();
void sort(sort_slot s);
void sort(const ViewSort* s);
void set_sort_new(sort_slot s) { m_sortNew = s; }
// This is set to ViewNone by default by ViewManager before
// initialize is called.
void set_sort_new(const ViewSort* s) { m_sortNew = s; }
// 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; }
private:
@@ -117,13 +117,25 @@ private:
core::DownloadList* m_list;
size_type m_focus;
sort_slot m_sortNew;
const ViewSort* m_sortNew;
// Timer, last changed.
signal_type m_signalChanged;
};
class ViewSort {
public:
virtual ~ViewSort() {}
// Add various extra stuff here, like bool flags for can sort new,
// normal etc.
// How to take focus into account?
virtual bool compare(Download* d1, Download* d2) const = 0;
};
}
#endif
+82 -33
View File
@@ -46,13 +46,83 @@
namespace core {
class ViewSortFirst : public ViewSort {
public:
virtual bool compare(Download* d1, Download* d2) const {
return true;
}
};
class ViewSortName : public ViewSort {
public:
virtual bool compare(Download* d1, Download* d2) const {
return d1->download()->name() < d2->download()->name();
}
};
class ViewSortVariable : public ViewSort {
public:
ViewSortVariable(const std::string& name, const std::string& value) :
m_name(name), m_value(value) {}
virtual bool compare(Download* d1, Download* d2) const {
return
d1->variable()->get_string(m_name) == m_value ||
d2->variable()->get_string(m_name) != m_value;
}
private:
std::string m_name;
std::string m_value;
};
class ViewSortReverse : public ViewSort {
public:
ViewSortReverse(ViewSort* s) : m_sort(s) {}
~ViewSortReverse() { delete m_sort; }
virtual bool compare(Download* d1, Download* d2) const {
return m_sort->compare(d2, d1);
}
private:
ViewSort* m_sort;
};
// Hmm, use a list in ViewDownloads instead?
class ViewSortAnd : public ViewSort {
public:
ViewSortAnd(ViewSort* s1, ViewSort* s2) : m_sort1(s1), m_sort2(s2) {}
~ViewSortAnd() { delete m_sort1; delete m_sort2; }
virtual bool compare(Download* d1, Download* d2) const {
return m_sort1->compare(d1, d2) && m_sort2->compare(d1, d2);
}
private:
ViewSort* m_sort1;
ViewSort* m_sort2;
};
ViewManager::ViewManager(DownloadList* dl) :
m_list(dl) {
m_sort["first"] = new ViewSortFirst();
m_sort["last"] = new ViewSortReverse(new ViewSortFirst());
m_sort["name"] = new ViewSortName();
m_sort["name_reverse"] = new ViewSortReverse(new ViewSortName());
m_sort["started"] = new ViewSortVariable("state", "started");
m_sort["started_name"] = new ViewSortAnd(new ViewSortVariable("state", "started"), new ViewSortName());
m_sort["stopped"] = new ViewSortVariable("state", "stopped");
m_sort["stopped_name"] = new ViewSortAnd(new ViewSortVariable("state", "stopped"), new ViewSortName());
}
void
ViewManager::clear() {
std::for_each(begin(), end(), rak::call_delete<ViewDownloads>());
std::for_each(m_sort.begin(), m_sort.end(), rak::on(rak::mem_ptr_ref(&sort_map::value_type::second), rak::call_delete<ViewSort>()));
base_type::clear();
}
@@ -63,6 +133,8 @@ ViewManager::insert(const std::string& name) {
throw torrent::internal_error("ViewManager::insert(...) name already inserted.");
ViewDownloads* view = new ViewDownloads();
view->set_sort_new(m_sort["last"]);
view->initialize(name, m_list);
return base_type::insert(end(), view);
@@ -83,51 +155,28 @@ ViewManager::find_throw(const std::string& name) {
return itr;
}
// Put this somewhere else.
bool
view_sort_name(core::Download* d1, core::Download* d2) {
return d1->download()->name() < d2->download()->name();
}
bool
view_sort_name_reverse(core::Download* d1, core::Download* d2) {
return d1->download()->name() > d2->download()->name();
}
void
ViewManager::sort(const std::string& name, const std::string& sort) {
iterator itr = find_throw(name);
iterator viewItr = find_throw(name);
// Quick and dirty hack.
if (sort == "none")
(*itr)->sort(NULL);
sort_map::const_iterator sortItr = m_sort.find(sort);
else if (sort == "name")
(*itr)->sort(&view_sort_name);
else if (sort == "name_reverse")
(*itr)->sort(&view_sort_name_reverse);
else
if (sortItr == m_sort.end())
throw torrent::input_error("Invalid sorting identifier.");
(*viewItr)->sort(sortItr->second);
}
void
ViewManager::set_sort_new(const std::string& name, const std::string& sort) {
iterator itr = find_throw(name);
iterator viewItr = find_throw(name);
// Quick and dirty hack.
if (sort == "none")
(*itr)->set_sort_new(NULL);
sort_map::const_iterator sortItr = m_sort.find(sort);
else if (sort == "name")
(*itr)->set_sort_new(&view_sort_name);
else if (sort == "name_reverse")
(*itr)->set_sort_new(&view_sort_name_reverse);
else
if (sortItr == m_sort.end())
throw torrent::input_error("Invalid sorting identifier.");
(*viewItr)->set_sort_new(sortItr->second);
}
}
+6
View File
@@ -37,15 +37,19 @@
#ifndef RTORRENT_CORE_VIEW_MANAGER_H
#define RTORRENT_CORE_VIEW_MANAGER_H
#include <map>
#include <string>
#include <rak/unordered_vector.h>
namespace core {
class ViewDownloads;
class ViewSort;
class ViewManager : public rak::unordered_vector<ViewDownloads*> {
public:
typedef rak::unordered_vector<ViewDownloads*> base_type;
typedef std::map<std::string, ViewSort*> sort_map;
using base_type::iterator;
using base_type::const_iterator;
@@ -86,6 +90,8 @@ public:
private:
DownloadList* m_list;
sort_map m_sort;
};
}