* Finished FileListIterator and basic navigation of the file list.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@832 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-12-25 13:19:45 +00:00
parent c453565e8f
commit 25702ea4b7
6 changed files with 48 additions and 48 deletions
+1
View File
@@ -93,6 +93,7 @@ public:
void print_char(const chtype ch) { waddch(m_window, ch); }
void print_char(unsigned int x, unsigned int y, const chtype ch) { mvwaddch(m_window, y, x, ch); }
void set_attr(int attr, int color) { wattr_set(m_window, attr, color, NULL); }
void set_attr(unsigned int x, unsigned int y, unsigned int n, int attr, int color) { mvwchgat(m_window, y, x, n, attr, color, NULL); }
// Initialize stdscr.
+6 -2
View File
@@ -58,8 +58,9 @@ public:
static const int flag_active = (1 << 0);
static const int flag_offscreen = (1 << 1);
static const int flag_left = (1 << 2);
static const int flag_bottom = (1 << 3);
static const int flag_focused = (1 << 2);
static const int flag_left = (1 << 3);
static const int flag_bottom = (1 << 4);
static const extent_type extent_static = extent_type();
static const extent_type extent_full = ~extent_type();
@@ -76,6 +77,9 @@ public:
bool is_offscreen() const { return m_flags & flag_offscreen; }
void set_offscreen(bool state) { if (state) m_flags |= flag_offscreen; else m_flags &= ~flag_offscreen; }
bool is_focused() const { return m_flags & flag_focused; }
void set_focused(bool state) { if (state) m_flags |= flag_focused; else m_flags &= ~flag_focused; }
bool is_left() const { return m_flags & flag_left; }
void set_left(bool state) { if (state) m_flags |= flag_left; else m_flags &= ~flag_left; }
+18 -24
View File
@@ -49,10 +49,10 @@
namespace display {
WindowFileList::WindowFileList(core::Download* d, iterator* focus) :
WindowFileList::WindowFileList(core::Download* d, iterator* selected) :
Window(new Canvas, 0, 0, 0, extent_full, extent_full),
m_download(d),
m_focus(focus) {
m_selected(selected) {
}
/*
@@ -93,30 +93,21 @@ WindowFileList::redraw() {
++pos;
// if (m_focus->first >= fl->size_files() || m_focus->second >= (*(fl->begin() + m_focus->first))->path()->size())
// throw torrent::internal_error("WindowFileList::redraw() called on an object with a bad focus value.");
iterator itr = rak::advance_bidirectional<iterator>(iterator(fl->begin()), *m_selected, iterator(fl->end()), m_canvas->height() - pos).first;
// std::pair<unsigned int, unsigned int> range = rak::advance_bidirectional<unsigned int>(0, *m_focus, fl->size_files(), m_canvas->height() - pos);
// iterator first(fl->begin() + range.first, (*(fl->begin() + range.first))->match_depth_prev());
// iterator last(fl->end());
std::pair<iterator, iterator> range =
rak::advance_bidirectional<iterator>(iterator(fl->begin()), *m_focus, iterator(fl->end()), m_canvas->height() - pos);
while (pos != m_canvas->height() && range.first != range.second) {
if (range.first.is_empty()) {
while (pos != m_canvas->height() && itr != iterator(fl->end())) {
if (itr.is_empty()) {
m_canvas->print(0, pos, "EMPTY");
} else if (range.first.is_entering()) {
m_canvas->print(range.first.depth(), pos, "\\ %s",
range.first.depth() < (*range.first)->path()->size() ? (*range.first)->path()->at(range.first.depth()).c_str() : "UNKNOWN");
} else if (itr.is_entering()) {
m_canvas->print(itr.depth(), pos, "\\ %s",
itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN");
} else if (range.first.is_leaving()) {
m_canvas->print(range.first.depth(), pos, "/");
} else if (itr.is_leaving()) {
m_canvas->print(itr.depth(), pos, "/");
} else if (range.first.is_file()) {
torrent::File* e = *range.first;
} else if (itr.is_file()) {
torrent::File* e = *itr;
std::string priority;
@@ -138,8 +129,8 @@ WindowFileList::redraw() {
break;
};
m_canvas->print(range.first.depth(), pos, "| %s",
range.first.depth() < (*range.first)->path()->size() ? (*range.first)->path()->at(range.first.depth()).c_str() : "UNKNOWN");
m_canvas->print(itr.depth(), pos, "| %s",
itr.depth() < (*itr)->path()->size() ? (*itr)->path()->at(itr.depth()).c_str() : "UNKNOWN");
// %6.1f %s %3d %9s",
// (double)e->size_bytes() / (double)(1 << 20),
@@ -159,7 +150,10 @@ WindowFileList::redraw() {
m_canvas->print(0, pos, "BORK BORK");
}
++range.first;
if (itr == *m_selected)
m_canvas->set_attr(0, pos, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0));
++itr;
++pos;
}
}
+2 -2
View File
@@ -56,7 +56,7 @@ class WindowFileList : public Window {
public:
typedef torrent::FileListIterator iterator;
WindowFileList(core::Download* d, iterator* focus);
WindowFileList(core::Download* d, iterator* selected);
virtual void redraw();
@@ -64,7 +64,7 @@ private:
int done_percentage(torrent::File* e);
core::Download* m_download;
iterator* m_focus;
iterator* m_selected;
};
}
+20 -19
View File
@@ -54,7 +54,7 @@ namespace ui {
ElementFileList::ElementFileList(core::Download* d) :
m_download(d),
m_window(NULL),
m_focus(iterator(d->download()->file_list()->begin())) {
m_selected(iterator(d->download()->file_list()->begin())) {
m_bindings[KEY_LEFT] = m_bindings['B' - '@'] = sigc::mem_fun(&m_slotExit, &slot_type::operator());
@@ -75,8 +75,9 @@ ElementFileList::activate(display::Frame* frame, bool focus) {
if (focus)
control->input()->push_back(&m_bindings);
m_window = new WFileList(m_download, &m_focus);
m_window = new WFileList(m_download, &m_selected);
m_window->set_active(true);
m_window->set_focused(focus);
m_frame = frame;
m_frame->initialize_window(m_window);
@@ -107,8 +108,8 @@ void
ElementFileList::receive_next() {
torrent::FileList* fl = m_download->download()->file_list();
if (m_focus == iterator(fl->end()) || ++m_focus == iterator(fl->end()))
m_focus = iterator(fl->begin());
if (m_selected == iterator(fl->end()) || ++m_selected == iterator(fl->end()))
m_selected = iterator(fl->begin());
m_window->mark_dirty();
}
@@ -117,10 +118,10 @@ void
ElementFileList::receive_prev() {
torrent::FileList* fl = m_download->download()->file_list();
if (m_focus == iterator(fl->begin()))
m_focus = iterator(fl->end());
if (m_selected == iterator(fl->begin()))
m_selected = iterator(fl->end());
m_focus--;
m_selected--;
m_window->mark_dirty();
}
@@ -128,14 +129,14 @@ void
ElementFileList::receive_pagenext() {
torrent::FileList* fl = m_download->download()->file_list();
if (m_focus == --iterator(fl->end())) {
m_focus = iterator(fl->begin());
if (m_selected == --iterator(fl->end())) {
m_selected = iterator(fl->begin());
} else {
m_focus = rak::advance_forward(m_focus, iterator(fl->end()), (m_window->height() - 1) / 2);
m_selected = rak::advance_forward(m_selected, iterator(fl->end()), (m_window->height() - 1) / 2);
if (m_focus == iterator(fl->end()))
m_focus = --iterator(fl->end());
if (m_selected == iterator(fl->end()))
m_selected = --iterator(fl->end());
}
m_window->mark_dirty();
@@ -148,10 +149,10 @@ ElementFileList::receive_pageprev() {
torrent::FileList* fl = m_download->download()->file_list();
if (m_focus == iterator(fl->begin()))
m_focus = --iterator(fl->end());
if (m_selected == iterator(fl->begin()))
m_selected = --iterator(fl->end());
else
m_focus = rak::advance_backward(m_focus, iterator(fl->begin()), (m_window->height() - 1) / 2);
m_selected = rak::advance_backward(m_selected, iterator(fl->begin()), (m_window->height() - 1) / 2);
m_window->mark_dirty();
}
@@ -165,10 +166,10 @@ ElementFileList::receive_priority() {
// torrent::FileList* fl = m_download->download()->file_list();
// if (m_focus >= fl->size_files())
// if (m_selected >= fl->size_files())
// return;
// torrent::File* file = *(fl->begin() + m_focus);
// torrent::File* file = *(fl->begin() + m_selected);
// file->set_priority(next_priority(file->priority()));
@@ -183,10 +184,10 @@ ElementFileList::receive_change_all() {
// torrent::FileList* fl = m_download->download()->file_list();
// if (m_focus >= fl->size_files())
// if (m_selected >= fl->size_files())
// return;
// Priority p = next_priority((*(fl->begin() + m_focus))->priority());
// 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);
+1 -1
View File
@@ -81,7 +81,7 @@ private:
WFileList* m_window;
// Change to unsigned, please.
iterator m_focus;
iterator m_selected;
};
}