From 305e3bdf2bee24d930d00f0cd00100a7677184a5 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 24 Jan 2006 20:05:36 +0000 Subject: [PATCH] * ChunkSelector selected from outside the priority ranges due to ~(char)0 giving an inverted integer rather than char. * Fixed a segfault due to too small screen size, snprintf returns the number of bytes that could have been written rather than how much actually was. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@626 e378c898-3ddf-0310-93e7-cc216c733640 --- configure.ac | 2 +- src/core/download.cc | 2 +- src/display/utils.cc | 226 ++++++++++++++++------- src/display/utils.h | 25 ++- src/display/window_download_list.cc | 6 +- src/display/window_download_statusbar.cc | 12 +- src/display/window_log.cc | 2 +- src/display/window_log_complete.cc | 2 +- src/display/window_peer_info.cc | 6 +- src/display/window_statusbar.cc | 73 ++++---- src/main.cc | 2 +- src/ui/download.cc | 6 + src/ui/download.h | 5 +- src/ui/download_list.cc | 18 ++ src/ui/download_list.h | 3 + 15 files changed, 263 insertions(+), 127 deletions(-) diff --git a/configure.ac b/configure.ac index 0da3372b..e31d9769 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.4.3, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.4.4, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) diff --git a/src/core/download.cc b/src/core/download.cc index b342e4d4..e75f176c 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -126,7 +126,7 @@ Download::set_priority(uint32_t p) { if (p >= 4) throw torrent::input_error("Priority out of range."); - torrent::download_set_priority(m_download, p * 2); + torrent::download_set_priority(m_download, p * p); get_bencode().get_key("rtorrent").insert_key("priority", (int64_t)p); } diff --git a/src/display/utils.cc b/src/display/utils.cc index b75e7821..7453f18d 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -49,133 +50,224 @@ namespace display { -char* -print_string(char* buf, unsigned int length, char* str) { - // We don't have any nice simple functions for copying strings that - // return the end address. - while (length-- != 0 && *str != '\0') - *(buf++) = *(str++); +inline char* +print_buffer(char* first, char* last, const char* format) { + if (first >= last) + return first; - return buf; + int s = snprintf(first, last - first, format); + + if (s < 0) + return first; + else + return std::min(first + s, last); +} + +template +inline char* +print_buffer(char* first, char* last, const char* format, const Arg1& arg1) { + if (first >= last) + return first; + + int s = snprintf(first, last - first, format, arg1); + + if (s < 0) + return first; + else + return std::min(first + s, last); +} + +template +inline char* +print_buffer(char* first, char* last, const char* format, const Arg1& arg1, const Arg2& arg2) { + if (first >= last) + return first; + + int s = snprintf(first, last - first, format, arg1, arg2); + + if (s < 0) + return first; + else + return std::min(first + s, last); +} + +template +inline char* +print_buffer(char* first, char* last, const char* format, const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) { + if (first >= last) + return first; + + int s = snprintf(first, last - first, format, arg1, arg2, arg3); + + if (s < 0) + return first; + else + return std::min(first + s, last); } char* -print_hhmmss(char* buf, unsigned int length, time_t t) { +print_string(char* first, char* last, char* str) { + // We don't have any nice simple functions for copying strings that + // return the end address. + while (first != last && *str != '\0') + *(first++) = *(str++); + + return first; +} + +char* +print_hhmmss(char* first, char* last, time_t t) { std::tm *u = std::localtime(&t); if (u == NULL) - return "inv_time"; + //return "inv_time"; + throw torrent::internal_error("print_hhmmss(...) failed."); - int s = snprintf(buf, length, "%2u:%02u:%02u", u->tm_hour, u->tm_min, u->tm_sec); - - return buf + std::max(s, 0); + return print_buffer(first, last, "%2u:%02u:%02u", u->tm_hour, u->tm_min, u->tm_sec); } char* -print_ddhhmm(char* buf, unsigned int length, time_t t) { - int s; - +print_ddhhmm(char* first, char* last, time_t t) { if (t / (24 * 3600) < 100) - s = snprintf(buf, length, "%2i:%02i:%02i", (int)t / (24 * 3600), ((int)t / 3600) % 24, ((int)t / 60) % 60); + return print_buffer(first, last, "%2i:%02i:%02i", (int)t / (24 * 3600), ((int)t / 3600) % 24, ((int)t / 60) % 60); else - s = snprintf(buf, length, "--:--:--"); - - return buf + std::max(s, 0); + return print_buffer(first, last, "--:--:--"); } char* -print_ddmmyyyy(char* buf, unsigned int length, time_t t) { +print_ddmmyyyy(char* first, char* last, time_t t) { std::tm *u = std::gmtime(&t); if (u == NULL) - return "inv_time"; + //return "inv_time"; + throw torrent::internal_error("print_ddmmyyyy(...) failed."); - int s = snprintf(buf, length, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year)); - - return buf + std::max(s, 0); + return print_buffer(first, last, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year)); } char* -print_download_title(char* buf, unsigned int length, core::Download* d) { - return buf + std::max(snprintf(buf, length, "%s", d->get_download().name().c_str()), 0); +print_download_title(char* first, char* last, core::Download* d) { + return print_buffer(first, last, "%s", d->get_download().name().c_str()); } char* -print_download_info(char* buf, unsigned int length, core::Download* d) { - char* last = buf + length; - - buf += std::max(snprintf(buf, last - buf, "Torrent: "), 0); +print_download_info(char* first, char* last, core::Download* d) { + first = print_buffer(first, last, "Torrent: "); if (!d->get_download().is_open()) - buf += std::max(snprintf(buf, last - buf, "closed "), 0); + first = print_buffer(first, last, "closed "); + else if (d->is_done()) - buf += std::max(snprintf(buf, last - buf, "done %10.1f MB", - (double)d->get_download().bytes_total() / (double)(1 << 20)), 0); + first = print_buffer(first, last, "done %10.1f MB", (double)d->get_download().bytes_total() / (double)(1 << 20)); else - buf += std::max(snprintf(buf, last - buf, "%6.1f / %6.1f MB", - (double)d->get_download().bytes_done() / (double)(1 << 20), - (double)d->get_download().bytes_total() / (double)(1 << 20)), 0); + first = print_buffer(first, last, "%6.1f / %6.1f MB", + (double)d->get_download().bytes_done() / (double)(1 << 20), + (double)d->get_download().bytes_total() / (double)(1 << 20)); - buf += std::max(snprintf(buf, last - buf, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB ", - (double)d->get_download().up_rate()->rate() / (1 << 10), - (double)d->get_download().down_rate()->rate() / (1 << 10), - (double)d->get_download().up_rate()->total() / (1 << 20)), 0); + first = print_buffer(first, last, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB ", + (double)d->get_download().up_rate()->rate() / (1 << 10), + (double)d->get_download().down_rate()->rate() / (1 << 10), + (double)d->get_download().up_rate()->total() / (1 << 20)); - buf = print_download_time_left(buf, last - buf, d); + first = print_download_time_left(first, last, d); - *buf = '\0'; + if (d->priority() != 2) + first = print_buffer(first, last, " [%s]", core::Download::priority_to_string(d->priority())); - return buf; + if (first > last) + throw torrent::internal_error("print_download_info(...) wrote past end of the buffer."); + + return first; } char* -print_download_status(char* buf, unsigned int length, core::Download* d) { - char* last = buf + length; - +print_download_status(char* first, char* last, core::Download* d) { if (!d->get_download().is_active()) - buf += std::max(snprintf(buf, last - buf, "Inactive: "), 0); + first = print_buffer(first, last, "Inactive: "); if (d->get_download().is_hash_checking()) - buf += std::max(snprintf(buf, last - buf, "Checking hash [%2i%%]", - (d->get_download().chunks_hashed() * 100) / d->get_download().chunks_total()), 0); + first = print_buffer(first, last, "Checking hash [%2i%%]", + (d->get_download().chunks_hashed() * 100) / d->get_download().chunks_total()); else if (d->get_download().is_tracker_busy() && d->get_download().tracker_focus() < d->get_download().size_trackers()) - buf += std::max(snprintf(buf, last - buf, "Tracker[%i:%i]: Connecting to %s", - d->get_download().tracker(d->get_download().tracker_focus()).group(), - d->get_download().tracker_focus(), - d->get_download().tracker(d->get_download().tracker_focus()).url().c_str()), 0); + first = print_buffer(first, last, "Tracker[%i:%i]: Connecting to %s", + d->get_download().tracker(d->get_download().tracker_focus()).group(), + d->get_download().tracker_focus(), + d->get_download().tracker(d->get_download().tracker_focus()).url().c_str()); else if (!d->get_message().empty()) - buf += std::max(snprintf(buf, last - buf, "%s", d->get_message().c_str()), 0); + first = print_buffer(first, last, "%s", d->get_message().c_str()); else - buf[0] = '\0'; + *first = '\0'; - return buf; + if (first > last) + throw torrent::internal_error("print_download_status(...) wrote past end of the buffer."); + + return first; } char* -print_download_time_left(char* buf, unsigned int length, core::Download* d) { +print_download_time_left(char* first, char* last, core::Download* d) { uint32_t rate; if (!d->get_download().is_active() || - (rate = d->get_download().down_rate()->rate()) < 512) { - buf += std::max(snprintf(buf, length, "--:--:--"), 0); - return buf; - } + (rate = d->get_download().down_rate()->rate()) < 512) + return print_buffer(first, last, "--:--:--"); time_t remaining = (d->get_download().bytes_total() - d->get_download().bytes_done()) / (rate & ~(uint32_t)(512 - 1)); - return print_ddhhmm(buf, length, remaining); + return print_ddhhmm(first, last, remaining); } -// char* -// print_entry_tags(char* buf, unsigned int length) { +char* +print_status_info(char* first, char* last) { + if (torrent::up_throttle() == 0) + first = print_buffer(first, last, "[Throttle off"); + else + first = print_buffer(first, last, "[Throttle %3i", torrent::up_throttle() / 1024); + + if (torrent::down_throttle() == 0) + first = print_buffer(first, last, "/off KB]"); + else + first = print_buffer(first, last, "/%3i KB]", torrent::down_throttle() / 1024); -// } + first = print_buffer(first, last, " [Rate %5.1f/%5.1f KB]", + (double)torrent::up_rate()->rate() / 1024.0, + (double)torrent::down_rate()->rate() / 1024.0); -// char* -// print_entry_file(char* buf, unsigned int length, const torrent::Entry& entry); + first = print_buffer(first, last, " [Listen %s:%u]", + torrent::local_address().c_str(), + (unsigned int)torrent::listen_port()); + + if (first > last) + throw torrent::internal_error("print_status_info(...) wrote past end of the buffer."); + + std::string bindAddress = torrent::bind_address(); + + if (!bindAddress.empty()) + first = print_buffer(first, last, " [Bind %s]", bindAddress.c_str()); + + return first; +} + +char* +print_status_extra(char* first, char* last, Control* c) { + first = print_buffer(first, last, " [U %i/%i]", + torrent::currently_unchoked(), + torrent::max_unchoked()); + + first = print_buffer(first, last, " [S %i/%i/%i]", + torrent::total_handshakes(), + torrent::open_sockets(), + torrent::max_open_sockets()); + + first = print_buffer(first, last, " [F %i/%i]", + torrent::open_files(), + torrent::max_open_files()); + + return first; +} } diff --git a/src/display/utils.h b/src/display/utils.h index c598e115..37f555af 100644 --- a/src/display/utils.h +++ b/src/display/utils.h @@ -52,21 +52,26 @@ namespace torrent { class Entry; } +class Control; + namespace display { -char* print_string(char* buf, unsigned int length, char* str); +char* print_string(char* first, char* last, char* str); -char* print_hhmmss(char* buf, unsigned int length, time_t t); -char* print_ddhhmm(char* buf, unsigned int length, time_t t); -char* print_ddmmyyyy(char* buf, unsigned int length, time_t t); +char* print_hhmmss(char* first, char* last, time_t t); +char* print_ddhhmm(char* first, char* last, time_t t); +char* print_ddmmyyyy(char* first, char* last, time_t t); -char* print_download_title(char* buf, unsigned int length, core::Download* d); -char* print_download_info(char* buf, unsigned int length, core::Download* d); -char* print_download_status(char* buf, unsigned int length, core::Download* d); -char* print_download_time_left(char* buf, unsigned int length, core::Download* d); +char* print_download_title(char* first, char* last, core::Download* d); +char* print_download_info(char* first, char* last, core::Download* d); +char* print_download_status(char* first, char* last, core::Download* d); +char* print_download_time_left(char* first, char* last, core::Download* d); -char* print_entry_tags(char* buf, unsigned int length); -char* print_entry_file(char* buf, unsigned int length, const torrent::Entry& entry); +char* print_entry_tags(char* first, char* last); +char* print_entry_file(char* first, char* last, const torrent::Entry& entry); + +char* print_status_info(char* first, char* last); +char* print_status_extra(char* first, char* last, Control* c); } diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index af117653..4e5f293e 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -87,13 +87,13 @@ WindowDownloadList::redraw() { char* position; char* last = buffer + m_canvas->get_width() - 2; - position = print_download_title(buffer, last - buffer, *range.first); + position = print_download_title(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_list->get_focus() ? '*' : ' ', buffer); - position = print_download_info(buffer, last - buffer, *range.first); + position = print_download_info(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_list->get_focus() ? '*' : ' ', buffer); - position = print_download_status(buffer, last - buffer, *range.first); + position = print_download_status(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_list->get_focus() ? '*' : ' ', buffer); ++range.first; diff --git a/src/display/window_download_statusbar.cc b/src/display/window_download_statusbar.cc index 18cecab2..2db1db58 100644 --- a/src/display/window_download_statusbar.cc +++ b/src/display/window_download_statusbar.cc @@ -58,11 +58,11 @@ WindowDownloadStatusbar::redraw() { m_canvas->erase(); - char buffer[m_canvas->get_width() - 2]; + char buffer[m_canvas->get_width()]; char* position; char* last = buffer + m_canvas->get_width() - 2; - position = print_download_info(buffer, last - buffer, m_download); + position = print_download_info(buffer, last, m_download); m_canvas->print(0, 0, "%s", buffer); position = buffer + std::max(snprintf(buffer, last - buffer, "Peers: %i(%i) Min/Max: %i/%i Uploads: %i U/I: %i/%i Failed: %i", @@ -75,12 +75,12 @@ WindowDownloadStatusbar::redraw() { (int)m_download->get_download().peers_currently_interested(), (int)m_download->chunks_failed()), 0); - position = buffer + std::max(snprintf(position, last - buffer, " Priority: %s", - core::Download::priority_to_string(m_download->variables()->get("priority").as_value())), - 0); +// position = buffer + std::max(snprintf(position, last - buffer, " Priority: %s", +// core::Download::priority_to_string(m_download->variables()->get("priority").as_value())), +// 0); m_canvas->print(0, 1, "%s", buffer); - position = print_download_status(buffer, last - buffer, m_download); + position = print_download_status(buffer, last, m_download); m_canvas->print(0, 2, "[%c:%i] %s", m_download->get_download().is_tracker_busy() ? 'C' : ' ', (int)(m_download->get_download().tracker_timeout() / 1000000), diff --git a/src/display/window_log.cc b/src/display/window_log.cc index dc596547..562ecea3 100644 --- a/src/display/window_log.cc +++ b/src/display/window_log.cc @@ -71,7 +71,7 @@ WindowLog::redraw() { for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr) { char buffer[16]; - print_hhmmss(buffer, 16, static_cast(itr->first.seconds())); + print_hhmmss(buffer, buffer + 16, static_cast(itr->first.seconds())); m_canvas->print(0, pos++, "(%s) %s", buffer, itr->second.c_str()); } diff --git a/src/display/window_log_complete.cc b/src/display/window_log_complete.cc index e6025bf0..2ffb64a4 100644 --- a/src/display/window_log_complete.cc +++ b/src/display/window_log_complete.cc @@ -71,7 +71,7 @@ WindowLogComplete::redraw() { for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->get_height(); ++itr) { char buffer[16]; - print_hhmmss(buffer, 16, static_cast(itr->first.seconds())); + print_hhmmss(buffer, buffer + 16, static_cast(itr->first.seconds())); m_canvas->print(0, pos++, "(%s) %s", buffer, itr->second.c_str()); } diff --git a/src/display/window_peer_info.cc b/src/display/window_peer_info.cc index e9dbe9da..7e3b1d73 100644 --- a/src/display/window_peer_info.cc +++ b/src/display/window_peer_info.cc @@ -71,9 +71,9 @@ WindowPeerInfo::redraw() { d.chunks_size()); char buffer[32], *position; - position = print_ddmmyyyy(buffer, 32, static_cast(d.creation_date())); - position = print_string(position, buffer + 32 - position, " "); - position = print_hhmmss(position, buffer + 32 - position, static_cast(d.creation_date())); + position = print_ddmmyyyy(buffer, buffer + 32, static_cast(d.creation_date())); + position = print_string(position, buffer + 32, " "); + position = print_hhmmss(position, buffer + 32, static_cast(d.creation_date())); m_canvas->print(0, y++, "Created: %s", buffer); diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index fb9acd18..50bceacc 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -41,6 +41,7 @@ #include "control.h" #include "canvas.h" +#include "utils.h" #include "window_statusbar.h" namespace display { @@ -58,42 +59,52 @@ WindowStatusbar::redraw() { m_canvas->erase(); // TODO: Make a buffer with size = get_width? - int pos = 0; - char buf[128]; + char buffer[m_canvas->get_width() + 1]; + char* position; + char* last = buffer + m_canvas->get_width(); - if (torrent::up_throttle() == 0) - pos = snprintf(buf, 128, "off/"); - else - pos = snprintf(buf, 128, "%3i/", torrent::up_throttle() / 1024); +// if (torrent::up_throttle() == 0) +// position = std::max(snprintf(buffer, 128, "off/"), 0); +// else +// position = std::max(snprintf(buffer, 128, "%3i/", torrent::up_throttle() / 1024), 0); - if (torrent::down_throttle() == 0) - pos = snprintf(buf + pos, 128 - pos, "off"); - else - pos = snprintf(buf + pos, 128 - pos, "%-3i", torrent::down_throttle() / 1024); +// if (torrent::down_throttle() == 0) +// pos = snprintf(buf + pos, 128 - pos, "off"); +// else +// pos = snprintf(buf + pos, 128 - pos, "%-3i", torrent::down_throttle() / 1024); - m_canvas->print(0, 0, "Throttle U/D: %s Rate: %5.1f / %5.1f KB Listen: %s:%i%s", - buf, - (double)torrent::up_rate()->rate() / 1024.0, - (double)torrent::down_rate()->rate() / 1024.0, - !torrent::local_address().empty() ? torrent::local_address().c_str() : "", - (int)torrent::listen_port(), - !torrent::bind_address().empty() ? (" Bind: " + torrent::bind_address()).c_str() : ""); +// m_canvas->print(0, 0, "Throttle U/D: %s Rate: %5.1f / %5.1f KB Listen: %s:%i%s", +// buf, +// (double)torrent::up_rate()->rate() / 1024.0, +// (double)torrent::down_rate()->rate() / 1024.0, +// !torrent::local_address().empty() ? torrent::local_address().c_str() : "", +// (int)torrent::listen_port(), +// !torrent::bind_address().empty() ? (" Bind: " + torrent::bind_address()).c_str() : ""); -#ifndef USE_EXTRA_DEBUG - pos = snprintf(buf, 128, "[U %i/%i][S %i/%i/%i][F %i/%i]", -#else - pos = snprintf(buf, 128, "%i [U %i/%i][S %i/%i/%i][F %i/%i]", - (int)(m_control->tick() - m_lastTick), -#endif - torrent::currently_unchoked(), - torrent::max_unchoked(), - torrent::total_handshakes(), - torrent::open_sockets(), - torrent::max_open_sockets(), - torrent::open_files(), - torrent::max_open_files()); +// #ifndef USE_EXTRA_DEBUG +// pos = snprintf(buf, 128, "[U %i/%i][S %i/%i/%i][F %i/%i]", +// #else +// pos = snprintf(buf, 128, "%i [U %i/%i][S %i/%i/%i][F %i/%i]", +// (int)(m_control->tick() - m_lastTick), +// #endif +// torrent::currently_unchoked(), +// torrent::max_unchoked(), +// torrent::total_handshakes(), +// torrent::open_sockets(), +// torrent::max_open_sockets(), +// torrent::open_files(), +// torrent::max_open_files()); + + position = print_status_info(buffer, last); + m_canvas->print(0, 0, "%s", buffer); + + last = last - (position - buffer); + + if (last > buffer) { + position = print_status_extra(buffer, last, m_control); + m_canvas->print(m_canvas->get_width() - (position - buffer), 0, "%s", buffer); + } - m_canvas->print(m_canvas->get_width() - pos, 0, "%s", buf); m_lastTick = m_control->tick(); } diff --git a/src/main.cc b/src/main.cc index c09bd264..d9e0c8c9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -158,7 +158,7 @@ main(int argc, char** argv) { try { // Temporary. - setlocale(LC_ALL, ""); + //setlocale(LC_ALL, ""); cachedTime = rak::timer::current(); diff --git a/src/ui/download.cc b/src/ui/download.cc index 93e97b57..0b0370d4 100644 --- a/src/ui/download.cc +++ b/src/ui/download.cc @@ -234,6 +234,11 @@ Download::receive_next_priority() { m_download->set_priority((m_download->priority() + 1) % 4); } +void +Download::receive_prev_priority() { + m_download->set_priority((m_download->priority() - 1) % 4); +} + void Download::bind_keys() { (*m_bindings)['1'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_uploads), -1); @@ -243,6 +248,7 @@ Download::bind_keys() { (*m_bindings)['5'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_peers), -5); (*m_bindings)['6'] = sigc::bind(sigc::mem_fun(*this, &Download::receive_max_peers), 5); (*m_bindings)['+'] = sigc::mem_fun(*this, &Download::receive_next_priority); + (*m_bindings)['-'] = sigc::mem_fun(*this, &Download::receive_prev_priority); (*m_bindings)['t'] = sigc::bind(sigc::mem_fun(m_download->get_download(), &torrent::Download::tracker_manual_request), false); (*m_bindings)['T'] = sigc::bind(sigc::mem_fun(m_download->get_download(), &torrent::Download::tracker_manual_request), true); diff --git a/src/ui/download.h b/src/ui/download.h index 12487467..fdbbd1b7 100644 --- a/src/ui/download.h +++ b/src/ui/download.h @@ -88,6 +88,9 @@ public: void activate_display(Display d); void disable_display(); + void receive_next_priority(); + void receive_prev_priority(); + private: Download(const Download&); void operator = (const Download&); @@ -105,8 +108,6 @@ private: void receive_snub_peer(); - void receive_next_priority(); - void bind_keys(); void mark_dirty(); diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 1142c4fe..ebcf1357 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -233,6 +233,22 @@ DownloadList::receive_exit_download() { m_control->display()->adjust_layout(); } +void +DownloadList::receive_next_priority() { + if (m_downloadList.get_focus() == m_downloadList.end()) + return; + + (*m_downloadList.get_focus())->set_priority(((*m_downloadList.get_focus())->priority() + 1) % 4); +} + +void +DownloadList::receive_prev_priority() { + if (m_downloadList.get_focus() == m_downloadList.end()) + return; + + (*m_downloadList.get_focus())->set_priority(((*m_downloadList.get_focus())->priority() - 1) % 4); +} + void DownloadList::receive_check_hash() { if (m_downloadList.get_focus() == m_downloadList.end()) @@ -304,6 +320,8 @@ DownloadList::setup_keys() { (*m_bindings)['\x13'] = sigc::mem_fun(*this, &DownloadList::receive_start_download); (*m_bindings)['\x04'] = sigc::mem_fun(*this, &DownloadList::receive_stop_download); (*m_bindings)['\x12'] = sigc::mem_fun(*this, &DownloadList::receive_check_hash); + (*m_bindings)['+'] = sigc::mem_fun(*this, &DownloadList::receive_next_priority); + (*m_bindings)['-'] = sigc::mem_fun(*this, &DownloadList::receive_prev_priority); (*m_bindings)['\x7f'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), true); (*m_bindings)[KEY_BACKSPACE] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_view_input), true); diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 17417ffc..1a06a859 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -115,6 +115,9 @@ private: void receive_view_download(); void receive_exit_download(); + void receive_next_priority(); + void receive_prev_priority(); + void receive_check_hash(); void receive_view_input(bool useDefault);