* Added an info screen to the file list and added more information to

the list.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@833 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-12-25 18:26:40 +00:00
parent 25702ea4b7
commit eabbf33a76
6 changed files with 152 additions and 36 deletions
+6 -4
View File
@@ -82,12 +82,14 @@ TextElementValueBase::print(char* first, char* last, Canvas::attributes_list* at
} else if (m_flags & flag_xb) {
if (val < (int64_t(1) << 30))
first += std::max(snprintf(first, last - first + 1, "%5.1f MB", (double)val / (int64_t(1) << 20)), 0);
if (val < (int64_t(1) << 20))
first += std::max(snprintf(first, last - first + 1, "%5.1f Kb", (double)val / (int64_t(1) << 10)), 0);
else if (val < (int64_t(1) << 30))
first += std::max(snprintf(first, last - first + 1, "%5.1f Mb", (double)val / (int64_t(1) << 20)), 0);
else if (val < (int64_t(1) << 40))
first += std::max(snprintf(first, last - first + 1, "%5.1f GB", (double)val / (int64_t(1) << 30)), 0);
first += std::max(snprintf(first, last - first + 1, "%5.1f Gb", (double)val / (int64_t(1) << 30)), 0);
else
first += std::max(snprintf(first, last - first + 1, "%5.1f TB", (double)val / (int64_t(1) << 40)), 0);
first += std::max(snprintf(first, last - first + 1, "%5.1f Tb", (double)val / (int64_t(1) << 40)), 0);
} else if (m_flags & flag_timer) {
if (val == 0)
+23 -12
View File
@@ -97,19 +97,19 @@ WindowFileList::redraw() {
while (pos != m_canvas->height() && itr != iterator(fl->end())) {
if (itr.is_empty()) {
m_canvas->print(0, pos, "EMPTY");
m_canvas->print(12, pos, "EMPTY");
} else if (itr.is_entering()) {
m_canvas->print(itr.depth(), pos, "\\ %s",
m_canvas->print(12 + 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(itr.depth(), pos, "/");
m_canvas->print(12 + itr.depth() - 1, pos, "/");
} else if (itr.is_file()) {
torrent::File* e = *itr;
std::string priority;
const char* priority;
switch (e->priority()) {
case torrent::PRIORITY_OFF:
@@ -129,7 +129,18 @@ WindowFileList::redraw() {
break;
};
m_canvas->print(itr.depth(), pos, "| %s",
m_canvas->print(0, pos, "%3d", done_percentage(e));
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));
else if (val < (int64_t(1) << 40))
m_canvas->print(4, 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(12 + itr.depth(), pos, "| %s",
itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN");
// %6.1f %s %3d %9s",
@@ -138,13 +149,13 @@ WindowFileList::redraw() {
// done_percentage(e),
// e->path()->encoding().c_str());
m_canvas->print(104, pos, "%i - %i %c%c %u %u",
e->range().first,
e->range().first != e->range().second ? (e->range().second - 1) : e->range().second,
e->is_created() ? 'E' : 'M',
e->is_correct_size() ? 'C' : 'W',
e->match_depth_prev(),
e->match_depth_next());
// m_canvas->print(104, pos, "%i - %i %c%c %u %u",
// e->range().first,
// e->range().first != e->range().second ? (e->range().second - 1) : e->range().second,
// e->is_created() ? 'E' : 'M',
// e->is_correct_size() ? 'C' : 'W',
// e->match_depth_prev(),
// e->match_depth_next());
} else {
m_canvas->print(0, pos, "BORK BORK");
+103 -13
View File
@@ -36,6 +36,7 @@
#include "config.h"
#include <sigc++/bind.h>
#include <rak/algorithm.h>
#include <torrent/exceptions.h>
#include <torrent/data/file.h>
@@ -43,20 +44,28 @@
#include "display/frame.h"
#include "display/manager.h"
#include "display/text_element_helpers.h"
#include "display/text_element_lambda.h"
#include "display/window_file_list.h"
#include "input/manager.h"
#include "control.h"
#include "element_file_list.h"
#include "element_text.h"
namespace ui {
ElementFileList::ElementFileList(core::Download* d) :
m_download(d),
m_state(DISPLAY_MAX_SIZE),
m_window(NULL),
m_elementInfo(NULL),
m_selected(iterator(d->download()->file_list()->begin())) {
m_bindings[KEY_LEFT] = m_bindings['B' - '@'] = sigc::mem_fun(&m_slotExit, &slot_type::operator());
m_bindings[KEY_LEFT] = m_bindings['B' - '@'] = sigc::mem_fun(&m_slotExit, &slot_type::operator());
m_bindings[KEY_RIGHT] = m_bindings['F' - '@'] = sigc::bind(sigc::mem_fun(this, &ElementFileList::activate_display), DISPLAY_INFO);
m_bindings[' '] = sigc::mem_fun(*this, &ElementFileList::receive_priority);
m_bindings['*'] = sigc::mem_fun(*this, &ElementFileList::receive_change_all);
@@ -67,6 +76,42 @@ ElementFileList::ElementFileList(core::Download* d) :
m_bindings[KEY_UP] = m_bindings['P' - '@'] = sigc::mem_fun(*this, &ElementFileList::receive_prev);
}
const char*
element_file_list_filename(const torrent::File* file) {
if (file->path()->empty())
return "EMPTY";
return file->path()->rbegin()->c_str();
}
inline ElementText*
element_file_list_create_info() {
using namespace display::helpers;
ElementText* element = new ElementText(NULL);
element->set_column(1);
element->set_interval(1);
element->push_back("File info:");
element->push_back("");
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->set_column_width(element->column_width() + 1);
return element;
}
void
ElementFileList::activate(display::Frame* frame, bool focus) {
if (m_window != NULL)
@@ -79,10 +124,11 @@ ElementFileList::activate(display::Frame* frame, bool focus) {
m_window->set_active(true);
m_window->set_focused(focus);
m_frame = frame;
m_frame->initialize_window(m_window);
m_elementInfo = element_file_list_create_info();
m_elementInfo->slot_exit(sigc::bind(sigc::mem_fun(this, &ElementFileList::activate_display), DISPLAY_LIST));
// control->display()->adjust_layout();
m_frame = frame;
activate_display(DISPLAY_LIST);
}
void
@@ -92,16 +138,54 @@ ElementFileList::disable() {
control->input()->erase(&m_bindings);
activate_display(DISPLAY_MAX_SIZE);
m_frame->clear();
m_frame = NULL;
delete m_window;
m_window = NULL;
delete m_elementInfo;
m_elementInfo = NULL;
}
display::Window*
ElementFileList::window() {
return m_window;
void
ElementFileList::activate_display(Display display) {
if (display == m_state)
return;
switch (m_state) {
case DISPLAY_INFO:
m_elementInfo->disable();
break;
case DISPLAY_LIST:
m_window->set_active(false);
m_frame->clear();
break;
case DISPLAY_MAX_SIZE:
break;
}
m_state = display;
switch (m_state) {
case DISPLAY_INFO:
m_elementInfo->activate(m_frame, true);
break;
case DISPLAY_LIST:
m_window->set_active(true);
m_frame->initialize_window(m_window);
break;
case DISPLAY_MAX_SIZE:
break;
}
control->display()->adjust_layout();
}
void
@@ -111,7 +195,7 @@ ElementFileList::receive_next() {
if (m_selected == iterator(fl->end()) || ++m_selected == iterator(fl->end()))
m_selected = iterator(fl->begin());
m_window->mark_dirty();
update_itr();
}
void
@@ -122,7 +206,7 @@ ElementFileList::receive_prev() {
m_selected = iterator(fl->end());
m_selected--;
m_window->mark_dirty();
update_itr();
}
void
@@ -139,7 +223,7 @@ ElementFileList::receive_pagenext() {
m_selected = --iterator(fl->end());
}
m_window->mark_dirty();
update_itr();
}
void
@@ -154,7 +238,7 @@ ElementFileList::receive_pageprev() {
else
m_selected = rak::advance_backward(m_selected, iterator(fl->begin()), (m_window->height() - 1) / 2);
m_window->mark_dirty();
update_itr();
}
void
@@ -174,7 +258,7 @@ ElementFileList::receive_priority() {
// file->set_priority(next_priority(file->priority()));
m_download->download()->update_priorities();
m_window->mark_dirty();
update_itr();
}
void
@@ -193,7 +277,7 @@ ElementFileList::receive_change_all() {
// (*itr)->set_priority(p);
m_download->download()->update_priorities();
m_window->mark_dirty();
update_itr();
}
ElementFileList::Priority
@@ -215,4 +299,10 @@ ElementFileList::next_priority(Priority p) {
};
}
void
ElementFileList::update_itr() {
m_window->mark_dirty();
m_elementInfo->set_object(*m_selected.base());
}
}
+14 -1
View File
@@ -52,6 +52,8 @@ namespace display {
namespace ui {
class ElementText;
class ElementFileList : public ElementBase {
public:
typedef torrent::priority_t Priority;
@@ -59,12 +61,18 @@ public:
typedef torrent::FileListIterator iterator;
typedef enum {
DISPLAY_LIST,
DISPLAY_INFO,
DISPLAY_MAX_SIZE
} Display;
ElementFileList(core::Download* d);
void activate(display::Frame* frame, bool focus = true);
void disable();
display::Window* window();
void activate_display(Display display);
private:
void receive_next();
@@ -77,8 +85,13 @@ private:
Priority next_priority(Priority p);
void update_itr();
core::Download* m_download;
Display m_state;
WFileList* m_window;
ElementText* m_elementInfo;
// Change to unsigned, please.
iterator m_selected;
+5 -5
View File
@@ -209,7 +209,7 @@ ElementPeerList::receive_next() {
else
m_listItr = m_list.begin();
updated_itr();
update_itr();
}
void
@@ -219,7 +219,7 @@ ElementPeerList::receive_prev() {
else
m_listItr = m_list.end();
updated_itr();
update_itr();
}
void
@@ -247,7 +247,7 @@ ElementPeerList::receive_peer_disconnected(torrent::Peer p) {
else
m_list.erase(itr);
updated_itr();
update_itr();
}
void
@@ -257,11 +257,11 @@ ElementPeerList::receive_snub_peer() {
m_listItr->set_snubbed(!m_listItr->is_snubbed());
updated_itr();
update_itr();
}
void
ElementPeerList::updated_itr() {
ElementPeerList::update_itr() {
m_windowList->mark_dirty();
m_elementInfo->set_object(m_listItr != m_list.end() ? &*m_listItr : NULL);
}
+1 -1
View File
@@ -76,7 +76,7 @@ private:
void receive_snub_peer();
void updated_itr();
void update_itr();
core::Download* m_download;