From 06dad41ff872617ba2642ad8489411191a873f4d Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 26 Dec 2006 10:05:44 +0000 Subject: [PATCH] * Cleanup of the file list. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@834 e378c898-3ddf-0310-93e7-cc216c733640 --- src/display/text_element_helpers.h | 7 +++++ src/display/window_file_list.cc | 47 +++++++++--------------------- src/ui/element_file_list.cc | 46 ++++++++++++----------------- src/ui/element_text.h | 2 ++ 4 files changed, 41 insertions(+), 61 deletions(-) diff --git a/src/display/text_element_helpers.h b/src/display/text_element_helpers.h index 71605b05..3908a1aa 100644 --- a/src/display/text_element_helpers.h +++ b/src/display/text_element_helpers.h @@ -41,6 +41,7 @@ #include #include #include +#include #include "core/download.h" @@ -102,6 +103,12 @@ te_value(Return (torrent::FileList::*fptr)() const, int flags = TextElementValue return display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_file_list), std::mem_fun(fptr)), flags, attributes); } +template +inline TextElementValueBase* +te_value(Return (torrent::File::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) { + return display::text_element_value_slot(rak::on(std::mem_fun(&torrent::FileListIterator::file), std::mem_fun(fptr)), flags, attributes); +} + inline TextElementValueBase* te_variable_value(const std::string& variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) { return display::text_element_value_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_value), variable), flags, attributes); diff --git a/src/display/window_file_list.cc b/src/display/window_file_list.cc index f12ee00a..21be126b 100644 --- a/src/display/window_file_list.cc +++ b/src/display/window_file_list.cc @@ -83,28 +83,20 @@ WindowFileList::redraw() { return; unsigned int pos = 0; + iterator itr = rak::advance_bidirectional(iterator(fl->begin()), *m_selected, iterator(fl->end()), m_canvas->height() - 1).first; - m_canvas->print( 2, pos, "File"); - m_canvas->print(55, pos, "Size"); - m_canvas->print(63, pos, "Pri"); - m_canvas->print(68, pos, "Cmpl"); - m_canvas->print(74, pos, "Encoding"); - m_canvas->print(84, pos, "Chunks"); - - ++pos; - - iterator itr = rak::advance_bidirectional(iterator(fl->begin()), *m_selected, iterator(fl->end()), m_canvas->height() - pos).first; + m_canvas->print(0, pos++, "Cmp Pri Size Filename"); while (pos != m_canvas->height() && itr != iterator(fl->end())) { if (itr.is_empty()) { - m_canvas->print(12, pos, "EMPTY"); + m_canvas->print(16, pos, "EMPTY"); } else if (itr.is_entering()) { - m_canvas->print(12 + itr.depth(), pos, "\\ %s", + m_canvas->print(16 + itr.depth(), pos, "\\ %s", itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN"); } else if (itr.is_leaving()) { - m_canvas->print(12 + itr.depth() - 1, pos, "/"); + m_canvas->print(16 + itr.depth() - 1, pos, "/"); } else if (itr.is_file()) { torrent::File* e = *itr; @@ -112,35 +104,24 @@ WindowFileList::redraw() { const char* priority; switch (e->priority()) { - case torrent::PRIORITY_OFF: - priority = "off"; - break; - - case torrent::PRIORITY_NORMAL: - priority = " "; - break; - - case torrent::PRIORITY_HIGH: - priority = "hig"; - break; - - default: - priority = "BUG"; - break; + case torrent::PRIORITY_OFF: priority = "off"; break; + case torrent::PRIORITY_NORMAL: priority = " "; break; + case torrent::PRIORITY_HIGH: priority = "hig"; break; + default: priority = "BUG"; break; }; - m_canvas->print(0, pos, "%3d", done_percentage(e)); + m_canvas->print(0, pos, "%3d %s", done_percentage(e), priority); int64_t val = e->size_bytes(); if (val < (int64_t(1) << 30)) - m_canvas->print(4, pos, "%5.1fMb", (double)val / (int64_t(1) << 20)); + m_canvas->print(8, pos, "%5.1fMb", (double)val / (int64_t(1) << 20)); else if (val < (int64_t(1) << 40)) - m_canvas->print(4, pos, "%5.1fGb", (double)val / (int64_t(1) << 30)); + m_canvas->print(8, pos, "%5.1fGb", (double)val / (int64_t(1) << 30)); else - m_canvas->print(4, pos, "%5.1fTb", (double)val / (int64_t(1) << 40)); + m_canvas->print(8, pos, "%5.1fTb", (double)val / (int64_t(1) << 40)); - m_canvas->print(12 + itr.depth(), pos, "| %s", + m_canvas->print(16 + itr.depth(), pos, "| %s", itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN"); // %6.1f %s %3d %9s", diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index 315d8dc5..e53924aa 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -77,11 +77,14 @@ ElementFileList::ElementFileList(core::Download* d) : } const char* -element_file_list_filename(const torrent::File* file) { - if (file->path()->empty()) +element_file_list_filename(const torrent::FileListIterator* itr) { + if ((**itr)->path()->empty()) return "EMPTY"; - return file->path()->rbegin()->c_str(); + if (itr->depth() >= (**itr)->path()->size()) + return "ERROR"; + + return (**itr)->path()->at(itr->depth()).c_str(); } inline ElementText* @@ -99,13 +102,9 @@ element_file_list_create_info() { element->push_column("Filename:", display::text_element_string_slot(std::ptr_fun(&element_file_list_filename))); element->push_back(""); - element->push_column("Size:", display::text_element_value_slot(std::mem_fun(&torrent::File::size_bytes), value_base::flag_xb)); - element->push_column("Chunks:", - display::text_element_value_slot(std::mem_fun(&torrent::File::completed_chunks)), " / ", - display::text_element_value_slot(std::mem_fun(&torrent::File::size_chunks))); - element->push_column("Range:", - display::text_element_value_slot(std::mem_fun(&torrent::File::range_first)), " - ", - display::text_element_value_slot(std::mem_fun(&torrent::File::range_second))); + element->push_column("Size:", te_value(&torrent::File::size_bytes, value_base::flag_xb)); + element->push_column("Chunks:", te_value(&torrent::File::completed_chunks), " / ", te_value(&torrent::File::size_chunks)); + element->push_column("Range:", te_value(&torrent::File::range_first), " - ", te_value(&torrent::File::range_second)); element->set_column_width(element->column_width() + 1); @@ -126,8 +125,10 @@ ElementFileList::activate(display::Frame* frame, bool focus) { m_elementInfo = element_file_list_create_info(); m_elementInfo->slot_exit(sigc::bind(sigc::mem_fun(this, &ElementFileList::activate_display), DISPLAY_LIST)); + m_elementInfo->set_object(&m_selected); m_frame = frame; + activate_display(DISPLAY_LIST); } @@ -246,16 +247,9 @@ ElementFileList::receive_priority() { if (m_window == NULL) throw torrent::internal_error("ui::ElementFileList::receive_prev(...) called on a disabled object"); - // Fix priorities. + // Check if we're focused on a directory. -// torrent::FileList* fl = m_download->download()->file_list(); - -// if (m_selected >= fl->size_files()) -// return; - -// torrent::File* file = *(fl->begin() + m_selected); - -// file->set_priority(next_priority(file->priority())); + m_selected.file()->set_priority(next_priority(m_selected.file()->priority())); m_download->download()->update_priorities(); update_itr(); @@ -266,15 +260,11 @@ ElementFileList::receive_change_all() { if (m_window == NULL) throw torrent::internal_error("ui::ElementFileList::receive_prev(...) called on a disabled object"); -// torrent::FileList* fl = m_download->download()->file_list(); + Priority p = next_priority(m_selected.file()->priority()); + torrent::FileList* fl = m_download->download()->file_list(); -// if (m_selected >= fl->size_files()) -// return; - -// Priority p = next_priority((*(fl->begin() + m_selected))->priority()); - -// for (torrent::FileList::iterator itr = fl->begin(), last = fl->end(); itr != last; ++itr) -// (*itr)->set_priority(p); + for (torrent::FileList::iterator itr = fl->begin(), last = fl->end(); itr != last; ++itr) + (*itr)->set_priority(p); m_download->download()->update_priorities(); update_itr(); @@ -302,7 +292,7 @@ ElementFileList::next_priority(Priority p) { void ElementFileList::update_itr() { m_window->mark_dirty(); - m_elementInfo->set_object(*m_selected.base()); + m_elementInfo->mark_dirty(); } } diff --git a/src/ui/element_text.h b/src/ui/element_text.h index 1813bd31..0ea9d966 100644 --- a/src/ui/element_text.h +++ b/src/ui/element_text.h @@ -72,6 +72,8 @@ public: void activate(display::Frame* frame, bool focus = false); void disable(); + void mark_dirty() { m_window->mark_dirty(); } + // Consider returning a pointer that can be used to manipulate // entries, f.ex disabling them.