mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-06 14:19:21 +00:00
* Added FileListIterator to the API, which allows the client to
iterate through FileList as if it consisted of directories. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@831 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+33
-46
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <rak/algorithm.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/data/file.h>
|
||||
#include <torrent/data/file_list.h>
|
||||
@@ -53,7 +54,7 @@ namespace ui {
|
||||
ElementFileList::ElementFileList(core::Download* d) :
|
||||
m_download(d),
|
||||
m_window(NULL),
|
||||
m_focus(0) {
|
||||
m_focus(iterator(d->download()->file_list()->begin())) {
|
||||
|
||||
m_bindings[KEY_LEFT] = m_bindings['B' - '@'] = sigc::mem_fun(&m_slotExit, &slot_type::operator());
|
||||
|
||||
@@ -104,47 +105,38 @@ ElementFileList::window() {
|
||||
|
||||
void
|
||||
ElementFileList::receive_next() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::internal_error("ui::ElementFileList::receive_next(...) called on a disabled object");
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (++m_focus >= m_download->download()->file_list()->size_files())
|
||||
m_focus = 0;
|
||||
if (m_focus == iterator(fl->end()) || ++m_focus == iterator(fl->end()))
|
||||
m_focus = iterator(fl->begin());
|
||||
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
|
||||
void
|
||||
ElementFileList::receive_prev() {
|
||||
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();
|
||||
|
||||
if (fl->size_files() == 0)
|
||||
return;
|
||||
|
||||
if (m_focus != 0)
|
||||
--m_focus;
|
||||
else
|
||||
m_focus = fl->size_files() - 1;
|
||||
if (m_focus == iterator(fl->begin()))
|
||||
m_focus = iterator(fl->end());
|
||||
|
||||
m_focus--;
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
|
||||
void
|
||||
ElementFileList::receive_pagenext() {
|
||||
if (m_window == NULL)
|
||||
throw torrent::internal_error("ui::ElementFileList::receive_pagenext(...) called on a disabled object");
|
||||
|
||||
unsigned int count = (m_window->height() - 1) / 2;
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (m_focus + count < fl->size_files())
|
||||
m_focus += count;
|
||||
else if (m_focus == fl->size_files() - 1)
|
||||
m_focus = 0;
|
||||
else
|
||||
m_focus = fl->size_files() - 1;
|
||||
if (m_focus == --iterator(fl->end())) {
|
||||
m_focus = iterator(fl->begin());
|
||||
|
||||
} else {
|
||||
m_focus = rak::advance_forward(m_focus, iterator(fl->end()), (m_window->height() - 1) / 2);
|
||||
|
||||
if (m_focus == iterator(fl->end()))
|
||||
m_focus = --iterator(fl->end());
|
||||
}
|
||||
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
@@ -156,17 +148,10 @@ ElementFileList::receive_pageprev() {
|
||||
|
||||
torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (fl->size_files() == 0)
|
||||
return;
|
||||
|
||||
unsigned int count = (m_window->height() - 1) / 2;
|
||||
|
||||
if (m_focus > count)
|
||||
m_focus -= count;
|
||||
else if (m_focus == 0)
|
||||
m_focus = fl->size_files() - 1;
|
||||
if (m_focus == iterator(fl->begin()))
|
||||
m_focus = --iterator(fl->end());
|
||||
else
|
||||
m_focus = 0;
|
||||
m_focus = rak::advance_backward(m_focus, iterator(fl->begin()), (m_window->height() - 1) / 2);
|
||||
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
@@ -176,14 +161,16 @@ ElementFileList::receive_priority() {
|
||||
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();
|
||||
// Fix priorities.
|
||||
|
||||
if (m_focus >= fl->size_files())
|
||||
return;
|
||||
// torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
torrent::File* file = *(fl->begin() + m_focus);
|
||||
// if (m_focus >= fl->size_files())
|
||||
// return;
|
||||
|
||||
file->set_priority(next_priority(file->priority()));
|
||||
// torrent::File* file = *(fl->begin() + m_focus);
|
||||
|
||||
// file->set_priority(next_priority(file->priority()));
|
||||
|
||||
m_download->download()->update_priorities();
|
||||
m_window->mark_dirty();
|
||||
@@ -194,15 +181,15 @@ 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();
|
||||
// torrent::FileList* fl = m_download->download()->file_list();
|
||||
|
||||
if (m_focus >= fl->size_files())
|
||||
return;
|
||||
// if (m_focus >= fl->size_files())
|
||||
// return;
|
||||
|
||||
Priority p = next_priority((*(fl->begin() + m_focus))->priority());
|
||||
// Priority p = next_priority((*(fl->begin() + m_focus))->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();
|
||||
m_window->mark_dirty();
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#define RTORRENT_UI_ELEMENT_FILE_LIST_H
|
||||
|
||||
#include <torrent/common.h>
|
||||
#include <torrent/data/file_list_iterator.h>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
@@ -56,6 +57,8 @@ public:
|
||||
typedef torrent::priority_t Priority;
|
||||
typedef display::WindowFileList WFileList;
|
||||
|
||||
typedef torrent::FileListIterator iterator;
|
||||
|
||||
ElementFileList(core::Download* d);
|
||||
|
||||
void activate(display::Frame* frame, bool focus = true);
|
||||
@@ -78,7 +81,7 @@ private:
|
||||
WFileList* m_window;
|
||||
|
||||
// Change to unsigned, please.
|
||||
unsigned int m_focus;
|
||||
iterator m_focus;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user