mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 06:39:23 +00:00
* Refactoring to change the DownloadList events to commands.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1046 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -54,6 +54,8 @@
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
#include "manager.h"
|
||||
#include "view.h"
|
||||
#include "view_manager.h"
|
||||
|
||||
#include "dht_manager.h"
|
||||
#include "download.h"
|
||||
@@ -315,6 +317,9 @@ DownloadList::start_normal(Download* download) {
|
||||
download->set_hash_failed(false);
|
||||
rpc::call_command("d.set_state", (int64_t)1, rpc::make_target(download));
|
||||
|
||||
(*control->view_manager()->find_throw("stopped"))->set_not_visible(download);
|
||||
(*control->view_manager()->find_throw("started"))->set_visible(download);
|
||||
|
||||
resume(download);
|
||||
}
|
||||
|
||||
@@ -332,6 +337,9 @@ DownloadList::start_try(Download* download) {
|
||||
// etc.
|
||||
rpc::call_command("d.set_state", (int64_t)1, rpc::make_target(download));
|
||||
|
||||
(*control->view_manager()->find_throw("stopped"))->set_not_visible(download);
|
||||
(*control->view_manager()->find_throw("started"))->set_visible(download);
|
||||
|
||||
resume(download);
|
||||
return true;
|
||||
}
|
||||
@@ -342,6 +350,9 @@ DownloadList::stop_normal(Download* download) {
|
||||
|
||||
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
|
||||
|
||||
(*control->view_manager()->find_throw("started"))->set_not_visible(download);
|
||||
(*control->view_manager()->find_throw("stopped"))->set_visible(download);
|
||||
|
||||
pause(download);
|
||||
}
|
||||
|
||||
@@ -354,6 +365,9 @@ DownloadList::stop_try(Download* download) {
|
||||
|
||||
rpc::call_command("d.set_state", (int64_t)0, rpc::make_target(download));
|
||||
|
||||
(*control->view_manager()->find_throw("started"))->set_not_visible(download);
|
||||
(*control->view_manager()->find_throw("stopped"))->set_visible(download);
|
||||
|
||||
pause(download);
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-23
@@ -74,24 +74,7 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
static void
|
||||
connect_signal_network_log(Download* d, torrent::Download::slot_string_type s) {
|
||||
d->download()->signal_network_log(s);
|
||||
}
|
||||
|
||||
static void
|
||||
connect_signal_storage_log(Download* d, torrent::Download::slot_string_type s) {
|
||||
d->download()->signal_storage_error(s);
|
||||
}
|
||||
|
||||
// Need a proper logging class for this.
|
||||
static void
|
||||
connect_signal_tracker_dump(Download* d, torrent::Download::slot_dump_type s) {
|
||||
if (!rpc::call_command_string("get_tracker_dump").empty())
|
||||
d->download()->signal_tracker_dump(s);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
receive_tracker_dump(const std::string& url, const char* data, size_t size) {
|
||||
const std::string& filename = rpc::call_command_string("get_tracker_dump");
|
||||
|
||||
@@ -229,11 +212,8 @@ Manager::initialize_second() {
|
||||
|
||||
// Register slots to be called when a download is inserted/erased,
|
||||
// opened or closed.
|
||||
m_downloadList->slot_map_insert()["1_connect_network_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_network_log), sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
m_downloadList->slot_map_insert()["1_connect_storage_log"] = sigc::bind(sigc::ptr_fun(&connect_signal_storage_log), sigc::mem_fun(m_logComplete, &Log::push_front));
|
||||
m_downloadList->slot_map_insert()["1_connect_tracker_dump"] = sigc::bind(sigc::ptr_fun(&connect_signal_tracker_dump), sigc::ptr_fun(&receive_tracker_dump));
|
||||
|
||||
m_downloadList->slot_map_erase()["9_delete_tied"] = sigc::bind<0>(&rpc::call_command_d_v_void, "d.delete_tied");
|
||||
m_downloadList->slot_map_insert()["1_connect_logs"] = sigc::bind(&rpc::parse_command_d_single_std, "d.initialize_logs=");
|
||||
m_downloadList->slot_map_erase()["9_delete_tied"] = sigc::bind(&rpc::parse_command_d_single_std, "d.delete_tied=");
|
||||
|
||||
torrent::connection_manager()->set_signal_handshake_log(sigc::mem_fun(this, &Manager::handshake_log));
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
|
||||
void push_log(const char* msg);
|
||||
void push_log_std(const std::string& msg) { m_logImportant.push_front(msg); m_logComplete.push_front(msg); }
|
||||
void push_log_complete(const std::string& msg) { m_logComplete.push_front(msg); }
|
||||
|
||||
void handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash);
|
||||
|
||||
@@ -139,6 +140,9 @@ private:
|
||||
Log m_logComplete;
|
||||
};
|
||||
|
||||
// Meh, cleanup.
|
||||
extern void receive_tracker_dump(const std::string& url, const char* data, size_t size);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+38
-5
@@ -86,6 +86,36 @@ View::initialize(const std::string& name, core::DownloadList* dlist) {
|
||||
set_last_changed(rak::timer());
|
||||
}
|
||||
|
||||
void
|
||||
View::set_visible(Download* download) {
|
||||
iterator itr = std::find(begin_filtered(), end_filtered(), download);
|
||||
|
||||
if (itr == end_filtered())
|
||||
return;
|
||||
|
||||
// Don't optimize erase since we want to keep the order of the
|
||||
// non-visible elements.
|
||||
base_type::erase(itr);
|
||||
insert_visible(download);
|
||||
|
||||
rpc::parse_command_multiple_d_nothrow(download, m_eventAdded);
|
||||
}
|
||||
|
||||
void
|
||||
View::set_not_visible(Download* download) {
|
||||
iterator itr = std::find(begin_visible(), end_visible(), download);
|
||||
|
||||
if (itr == end_visible())
|
||||
return;
|
||||
|
||||
// Don't optimize erase since we want to keep the order of the
|
||||
// non-visible elements.
|
||||
base_type::erase(itr);
|
||||
base_type::push_back(download);
|
||||
|
||||
rpc::parse_command_multiple_d_nothrow(download, m_eventRemoved);
|
||||
}
|
||||
|
||||
void
|
||||
View::next_focus() {
|
||||
if (empty())
|
||||
@@ -253,6 +283,7 @@ View::received(core::Download* download, int event) {
|
||||
|
||||
} else {
|
||||
base_type::insert(end_filtered(), download);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_focus > m_size)
|
||||
@@ -261,6 +292,11 @@ View::received(core::Download* download, int event) {
|
||||
break;
|
||||
|
||||
case DownloadList::SLOTS_ERASE:
|
||||
if (itr >= end_visible()) {
|
||||
erase(itr);
|
||||
return;
|
||||
}
|
||||
|
||||
erase(itr);
|
||||
rpc::parse_command_multiple_d_nothrow(download, m_eventRemoved);
|
||||
|
||||
@@ -273,17 +309,14 @@ View::received(core::Download* download, int event) {
|
||||
if (view_downloads_filter(m_filter)(download)) {
|
||||
|
||||
if (itr >= end_visible()) {
|
||||
// Erase even if it is in visible so that the download is
|
||||
// re-sorted.
|
||||
//
|
||||
// This isn't the best solution...
|
||||
erase(itr);
|
||||
insert_visible(download);
|
||||
|
||||
rpc::parse_command_multiple_d_nothrow(download, m_eventAdded);
|
||||
|
||||
} else {
|
||||
// Should we really sort it here, or just return?
|
||||
// This makes sure the download is sorted even if it is
|
||||
// already visible.
|
||||
erase(itr);
|
||||
insert_visible(download);
|
||||
}
|
||||
|
||||
@@ -102,6 +102,9 @@ public:
|
||||
const_iterator focus() const { return begin() + m_focus; }
|
||||
void set_focus(iterator itr) { m_focus = position(itr); m_signalChanged.emit(); }
|
||||
|
||||
void set_visible(Download* download);
|
||||
void set_not_visible(Download* download);
|
||||
|
||||
void next_focus();
|
||||
void prev_focus();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user