|
|
@ -10,32 +10,43 @@ |
|
|
|
|
|
|
|
namespace display { |
|
|
|
|
|
|
|
// TODO: Large downloads result in rtorrent not quiting on ^Q.
|
|
|
|
|
|
|
|
WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) : |
|
|
|
Window(new Canvas, 0, 0, 1, extent_full, 1), |
|
|
|
m_queue(q) { |
|
|
|
|
|
|
|
set_active(false); |
|
|
|
m_connInsert = m_queue->signal_insert().insert(m_queue->signal_insert().end(), |
|
|
|
std::bind(&WindowHttpQueue::receive_insert, |
|
|
|
this, |
|
|
|
std::placeholders::_1)); |
|
|
|
m_connErase = m_queue->signal_erase().insert(m_queue->signal_insert().end(), |
|
|
|
std::bind(&WindowHttpQueue::receive_erase, |
|
|
|
this, |
|
|
|
std::placeholders::_1)); |
|
|
|
m_conn_insert = m_queue->signal_insert().insert(m_queue->signal_insert().end(), [this](auto* h) { receive_insert(h); }); |
|
|
|
m_conn_erase = m_queue->signal_erase().insert(m_queue->signal_insert().end(), [this](auto* h) { receive_erase(h); }); |
|
|
|
|
|
|
|
m_task_deactivate.slot() = [this] { |
|
|
|
if (!m_container.empty()) |
|
|
|
return; |
|
|
|
|
|
|
|
set_active(false); |
|
|
|
m_slot_adjust(); |
|
|
|
|
|
|
|
mark_dirty(); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
WindowHttpQueue::~WindowHttpQueue() { |
|
|
|
m_queue->signal_insert().erase(m_conn_insert); |
|
|
|
m_queue->signal_erase().erase(m_conn_erase); |
|
|
|
|
|
|
|
torrent::this_thread::scheduler()->erase(&m_task_deactivate); |
|
|
|
} |
|
|
|
|
|
|
|
void |
|
|
|
WindowHttpQueue::redraw() { |
|
|
|
bool is_empty = m_container.empty(); |
|
|
|
|
|
|
|
schedule_update(); |
|
|
|
cleanup_list(); |
|
|
|
|
|
|
|
if (m_container.empty()) { |
|
|
|
set_active(false); |
|
|
|
m_slot_adjust(); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
if (!is_empty && m_container.empty()) |
|
|
|
torrent::this_thread::scheduler()->update_wait_for(&m_task_deactivate, 5s); |
|
|
|
|
|
|
|
m_canvas->erase(); |
|
|
|
m_canvas->print(0, 0, "Http [%i]", m_queue->size()); |
|
|
@ -43,15 +54,15 @@ WindowHttpQueue::redraw() { |
|
|
|
unsigned int pos = 10; |
|
|
|
Container::iterator itr = m_container.begin(); |
|
|
|
|
|
|
|
while (itr != m_container.end() && pos + 20 < m_canvas->width()) { |
|
|
|
while (itr != m_container.end() && pos + 10 < m_canvas->width()) { |
|
|
|
if (itr->m_http == NULL) |
|
|
|
m_canvas->print(pos, 0, "%s done", itr->m_name.c_str()); |
|
|
|
m_canvas->print(pos, 0, "[%s done]", itr->m_name.c_str()); |
|
|
|
|
|
|
|
else if (itr->m_http->size_total() == 0) |
|
|
|
m_canvas->print(pos, 0, "%s ---%%", itr->m_name.c_str()); |
|
|
|
m_canvas->print(pos, 0, "[%s ---%%]", itr->m_name.c_str()); |
|
|
|
|
|
|
|
else |
|
|
|
m_canvas->print(pos, 0, "%s %3i%%", itr->m_name.c_str(), (int)(100.0 * itr->m_http->size_done() / itr->m_http->size_total())); |
|
|
|
m_canvas->print(pos, 0, "[%s %3i%%]", itr->m_name.c_str(), (int)(100.0 * itr->m_http->size_done() / itr->m_http->size_total())); |
|
|
|
|
|
|
|
pos += itr->m_name.size() + 6; |
|
|
|
++itr; |
|
|
@ -60,14 +71,14 @@ WindowHttpQueue::redraw() { |
|
|
|
|
|
|
|
void |
|
|
|
WindowHttpQueue::cleanup_list() { |
|
|
|
for (Container::iterator itr = m_container.begin(); itr != m_container.end();) |
|
|
|
if (itr->m_http == NULL && itr->m_timer < torrent::this_thread::cached_time()) |
|
|
|
for (Container::iterator itr = m_container.begin(); itr != m_container.end(); ) { |
|
|
|
if (itr->m_http == nullptr && itr->m_timer < torrent::this_thread::cached_time()) { |
|
|
|
itr = m_container.erase(itr); |
|
|
|
else |
|
|
|
++itr; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Bad, can't have this here as it is called from redraw().
|
|
|
|
// mark_dirty();
|
|
|
|
++itr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::string |
|
|
@ -87,8 +98,8 @@ WindowHttpQueue::create_name(core::CurlGet* h) { |
|
|
|
n.substr(n.size() - 8) == ".TORRENT")) |
|
|
|
n = n.substr(0, n.size() - 8); |
|
|
|
|
|
|
|
if (n.size() > 30) |
|
|
|
n = n.substr(0, 30); |
|
|
|
if (n.size() > 20) |
|
|
|
n = n.substr(0, 20); |
|
|
|
|
|
|
|
return n; |
|
|
|
} |
|
|
@ -107,13 +118,13 @@ WindowHttpQueue::receive_insert(core::CurlGet* h) { |
|
|
|
|
|
|
|
void |
|
|
|
WindowHttpQueue::receive_erase(core::CurlGet* h) { |
|
|
|
Container::iterator itr = std::find_if(m_container.begin(), m_container.end(), [h](Node n) { return h == n.get_http(); }); |
|
|
|
Container::iterator itr = std::find_if(m_container.begin(), m_container.end(), [h](Node& n) { return h == n.m_http; }); |
|
|
|
|
|
|
|
if (itr == m_container.end()) |
|
|
|
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have"); |
|
|
|
|
|
|
|
itr->m_http = NULL; |
|
|
|
itr->m_timer = torrent::this_thread::cached_time() + 1s; |
|
|
|
itr->m_http = nullptr; |
|
|
|
itr->m_timer = torrent::this_thread::cached_time() + 4s; |
|
|
|
|
|
|
|
mark_dirty(); |
|
|
|
} |
|
|
|