diff --git a/doc/rtorrent.rc b/doc/rtorrent.rc index 78186a79..9c940ebe 100644 --- a/doc/rtorrent.rc +++ b/doc/rtorrent.rc @@ -98,6 +98,6 @@ # #protocol.pex.set = yes -# Set downlad list layout style (default - 0, compact - 1) +# Set downlad list layout style. ("full", "compact") # -#download_list_layout = 1 +#torrent_list_layout = "full" diff --git a/src/command_ui.cc b/src/command_ui.cc index 88a2f873..69ee2f54 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -523,8 +523,6 @@ void initialize_command_ui() { CMD2_VAR_STRING("keys.layout", "qwerty"); - CMD2_VAR_VALUE("download.list.layout", 0); - CMD2_ANY_STRING("view.add", object_convert_void(std::bind(&core::ViewManager::insert_throw, control->view_manager(), std::placeholders::_2))); CMD2_ANY_L ("view.list", std::bind(&apply_view_list)); @@ -557,6 +555,9 @@ initialize_command_ui() { CMD2_ANY ("ui.current_view", std::bind(&cmd_ui_current_view)); CMD2_ANY_STRING("ui.current_view.set", std::bind(&cmd_ui_set_view, std::placeholders::_2)); + // TODO: Add 'option_string' for rtorrent-specific options. + CMD2_VAR_STRING("ui.torrent_list.layout", "full"); + // Move. CMD2_ANY("print", &apply_print); CMD2_ANY("cat", &apply_cat); diff --git a/src/display/utils.cc b/src/display/utils.cc index 640a7226..93011e82 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -133,7 +133,7 @@ print_download_title(char* first, char* last, core::Download* d) { } char* -print_download_info(char* first, char* last, core::Download* d) { +print_download_info_full(char* first, char* last, core::Download* d) { if (!d->download()->info()->is_open()) first = print_buffer(first, last, "[CLOSED] "); else if (!d->download()->info()->is_active()) @@ -177,111 +177,7 @@ print_download_info(char* first, char* last, core::Download* d) { first = print_buffer(first, last , "]"); if (first > last) - throw torrent::internal_error("print_download_info(...) wrote past end of the buffer."); - - return first; -} - -char* -print_download_info2(char* first, char* last, core::Download* d) { - //Name - std::string name = "Name"; - if(d) name = d->info()->name(); - name.resize(64,' '); - first = print_buffer(first, last, " %s", name.c_str()); - - //Status - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Status "); - else if (!d->download()->info()->is_open()) - first = print_buffer(first, last, " CLOSED "); - else if (!d->download()->info()->is_active()) - first = print_buffer(first, last, " OPEN "); - else - first = print_buffer(first, last, " "); - - //Downloaded - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Downloaded "); - else - first = print_buffer(first, last, " %7.1f MB ", (double)d->download()->bytes_done() / (double)(1 << 20)); - - //Size - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Size "); - else - first = print_buffer(first, last, " %7.1f MB ", (double)d->download()->file_list()->size_bytes() / (double)(1 << 20)); - - //Done - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Done "); - else if (d->is_done()) - first = print_buffer(first, last, " 100%% "); - else if (d->is_open()) - first = print_buffer(first, last, " %2u%% ",(d->download()->file_list()->completed_chunks() * 100) / d->download()->file_list()->size_chunks()); - else - first = print_buffer(first, last, " "); - - //Rate Up - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Up Rate "); - else - first = print_buffer(first, last, " %6.1f KB ", (double)d->info()->up_rate()->rate() / (1 << 10)); - - //Rate Down - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Down Rate "); - else - first = print_buffer(first, last, " %6.1f KB ", (double)d->info()->down_rate()->rate() / (1 << 10)); - - //Uploaded - first = print_buffer(first, last, "|"); - if (!d) - first = print_buffer(first, last, " Uploaded "); - else - first = print_buffer(first, last, " %7.1f MB ", (double)d->info()->up_rate()->total() / (1 << 20)); - - //ETA - first = print_buffer(first, last, "| "); - if (!d) - first = print_buffer(first, last, " ETA "); - else if (d->download()->info()->is_active() && !d->is_done()) - first = print_download_time_left(first, last, d); - else - first = print_buffer(first, last, " "); - - //Ratio - first = print_buffer(first, last, " |"); - if (!d) - first = print_buffer(first, last, " Ratio"); - else - first = print_buffer(first, last, " %4.2f ", (double)rpc::call_command_value("d.ratio", rpc::make_target(d)) / 1000.0); - - //Misc - first = print_buffer(first, last, "|"); - if (!d) { - first = print_buffer(first, last, " Misc "); - } else { - first = print_buffer(first, last, " %c%c", - rpc::call_command_string("d.tied_to_file", rpc::make_target(d)).empty() ? ' ' : 'T', - rpc::call_command_value("d.ignore_commands", rpc::make_target(d)) == 0 ? ' ' : 'I', - (double)rpc::call_command_value("d.ratio", rpc::make_target(d)) / 1000.0); - - if (d->priority() != 2) - first = print_buffer(first, last, " %s", rpc::call_command_string("d.priority_str", rpc::make_target(d)).c_str()); - - if (!d->bencode()->get_key("rtorrent").get_key_string("throttle_name").empty()) - first = print_buffer(first, last , " %s", rpc::call_command_string("d.throttle_name", rpc::make_target(d)).c_str()); - } - - if (first > last) - throw torrent::internal_error("print_download_info(...) wrote past end of the buffer."); + throw torrent::internal_error("print_download_info_full(...) wrote past end of the buffer."); return first; } @@ -322,6 +218,68 @@ print_download_status(char* first, char* last, core::Download* d) { return first; } +char* +print_download_column_compact(char* first, char* last) { + first = print_buffer(first, last, " %-64.64s", "Name"); + first = print_buffer(first, last, "| Status | Downloaded | Size | Done | Up Rate | Down Rate | Uploaded | ETA | Ratio| Misc "); + + if (first > last) + throw torrent::internal_error("print_download_column_compact(...) wrote past end of the buffer."); + + return first; +} + +char* +print_download_info_compact(char* first, char* last, core::Download* d) { + first = print_buffer(first, last, " %-64.64s", d->info()->name().c_str()); + first = print_buffer(first, last, "|"); + + if (!d->download()->info()->is_open()) + first = print_buffer(first, last, " CLOSED "); + else if (!d->download()->info()->is_active()) + first = print_buffer(first, last, " OPEN "); + else + first = print_buffer(first, last, " "); + + first = print_buffer(first, last, "| %7.1f MB ", (double)d->download()->bytes_done() / (double)(1 << 20)); + first = print_buffer(first, last, "| %7.1f MB ", (double)d->download()->file_list()->size_bytes() / (double)(1 << 20)); + first = print_buffer(first, last, "|"); + + if (d->is_done()) + first = print_buffer(first, last, " 100%% "); + else if (d->is_open()) + first = print_buffer(first, last, " %2u%% ",(d->download()->file_list()->completed_chunks() * 100) / d->download()->file_list()->size_chunks()); + else + first = print_buffer(first, last, " "); + + first = print_buffer(first, last, "| %6.1f KB ", (double)d->info()->up_rate()->rate() / (1 << 10)); + first = print_buffer(first, last, "| %6.1f KB ", (double)d->info()->down_rate()->rate() / (1 << 10)); + first = print_buffer(first, last, "| %7.1f MB ", (double)d->info()->up_rate()->total() / (1 << 20)); + first = print_buffer(first, last, "| "); + + if (d->download()->info()->is_active() && !d->is_done()) + first = print_download_time_left(first, last, d); + else + first = print_buffer(first, last, " "); + + first = print_buffer(first, last, "| %4.2f ", (double)rpc::call_command_value("d.ratio", rpc::make_target(d)) / 1000.0); + first = print_buffer(first, last, "| %c%c", + rpc::call_command_string("d.tied_to_file", rpc::make_target(d)).empty() ? ' ' : 'T', + rpc::call_command_value("d.ignore_commands", rpc::make_target(d)) == 0 ? ' ' : 'I', + (double)rpc::call_command_value("d.ratio", rpc::make_target(d)) / 1000.0); + + if (d->priority() != 2) + first = print_buffer(first, last, " %s", rpc::call_command_string("d.priority_str", rpc::make_target(d)).c_str()); + + if (!d->bencode()->get_key("rtorrent").get_key_string("throttle_name").empty()) + first = print_buffer(first, last , " %s", rpc::call_command_string("d.throttle_name", rpc::make_target(d)).c_str()); + + if (first > last) + throw torrent::internal_error("print_download_info_compact(...) wrote past end of the buffer."); + + return first; +} + char* print_download_time_left(char* first, char* last, core::Download* d) { uint32_t rate = d->info()->down_rate()->rate(); diff --git a/src/display/utils.h b/src/display/utils.h index ccb392d1..eb2daf8e 100644 --- a/src/display/utils.h +++ b/src/display/utils.h @@ -66,9 +66,12 @@ 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* first, char* last, core::Download* d); -char* print_download_info(char* first, char* last, core::Download* d); -char* print_download_info2(char* first, char* last, core::Download* d); +char* print_download_info_full(char* first, char* last, core::Download* d); char* print_download_status(char* first, char* last, core::Download* d); + +char* print_download_column_compact(char* first, char* last); +char* print_download_info_compact(char* first, char* last, core::Download* d); + char* print_download_time_left(char* first, char* last, core::Download* d); char* print_download_percentage_done(char* first, char* last, core::Download* d); diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc index b490c557..74911555 100644 --- a/src/display/window_download_list.cc +++ b/src/display/window_download_list.cc @@ -74,8 +74,6 @@ WindowDownloadList::set_view(core::View* l) { void WindowDownloadList::redraw() { - const int layout = rpc::call_command_value("download.list.layout"); - m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(1)).round_seconds()); m_canvas->erase(); @@ -88,12 +86,24 @@ WindowDownloadList::redraw() { if (m_view->empty_visible() || m_canvas->width() < 5 || m_canvas->height() < 2) return; + int layout_height; + const std::string layout_name = rpc::call_command_string("ui.torrent_list.layout"); + + if (layout_name == "full") { + layout_height = 3; + } else if (layout_name == "compact") { + layout_height = 1; + } else { + m_canvas->print(0, 0, "INVALID ui.torrent_list.layout '%s'", layout_name.c_str()); + return; + } + typedef std::pair Range; Range range = rak::advance_bidirectional(m_view->begin_visible(), m_view->focus() != m_view->end_visible() ? m_view->focus() : m_view->begin_visible(), m_view->end_visible(), - m_canvas->height()/(layout ? 1 : 3)); + m_canvas->height() / layout_height); // Make sure we properly fill out the last lines so it looks like // there are more torrents, yet don't hide it if we got the last one @@ -105,29 +115,35 @@ WindowDownloadList::redraw() { char buffer[m_canvas->width() + 1]; char* last = buffer + m_canvas->width() - 2 + 1; - if(layout) { - print_download_info2(buffer, last, NULL); + // Add a proper 'column info' method. + if (layout_name == "compact") { + print_download_column_compact(buffer, last); + m_canvas->set_default_attributes(A_BOLD); m_canvas->print(0, pos++, " %s", buffer); } - while (range.first != range.second) { - if(layout) { - print_download_info2(buffer, last, *range.first); - m_canvas->set_default_attributes(range.first == m_view->focus() ? A_REVERSE : A_NORMAL); - m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer); - } else { + if (layout_name == "full") { + while (range.first != range.second) { print_download_title(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer); - - print_download_info(buffer, last, *range.first); + print_download_info_full(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer); - print_download_status(buffer, last, *range.first); m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer); + + range.first++; } - ++range.first; - } + + } else { + while (range.first != range.second) { + print_download_info_compact(buffer, last, *range.first); + m_canvas->set_default_attributes(range.first == m_view->focus() ? A_REVERSE : A_NORMAL); + m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer); + + range.first++; + } + } } } diff --git a/src/display/window_download_statusbar.cc b/src/display/window_download_statusbar.cc index bbf0379f..284b8b54 100644 --- a/src/display/window_download_statusbar.cc +++ b/src/display/window_download_statusbar.cc @@ -66,7 +66,7 @@ WindowDownloadStatusbar::redraw() { char buffer[m_canvas->width()]; char* last = buffer + m_canvas->width() - 2; - print_download_info(buffer, last, m_download); + print_download_info_full(buffer, last, m_download); m_canvas->print(0, 0, "%s", buffer); snprintf(buffer, last - buffer, "Peers: %i(%i) Min/Max: %i/%i Slots: U:%i/%i D:%i/%i U/I/C/A: %i/%i/%i/%i Unchoked: %u/%u Failed: %i", diff --git a/src/main.cc b/src/main.cc index 2735dc84..58d31a23 100644 --- a/src/main.cc +++ b/src/main.cc @@ -416,10 +416,7 @@ main(int argc, char** argv) { CMD2_REDIRECT_GENERIC("to_xb", "convert.xb"); CMD2_REDIRECT_GENERIC("to_throttle", "convert.throttle"); - // TODO: Rename to something with 'ui.fooobar.....' and put - // together with the other ui options. In fact, add redirect for - // that other new ui option. - CMD2_REDIRECT ("download_list_layout", "download.list.layout.set"); + CMD2_REDIRECT ("torrent_list_layout", "ui.torrent_list.layout.set"); // Deprecated commands. Don't use these anymore.