mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 20:52:30 +00:00
* Added torrent::FileList to the API.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@659 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
#include <rak/path.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/tracker.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
|
||||
#include "utils/variable_generic.h"
|
||||
@@ -53,6 +54,7 @@ namespace core {
|
||||
|
||||
Download::Download(torrent::Download d) :
|
||||
m_download(d),
|
||||
m_fileList(d.file_list()),
|
||||
|
||||
m_chunksFailed(0) {
|
||||
|
||||
@@ -69,8 +71,8 @@ Download::Download(torrent::Download d) :
|
||||
m_variables.insert("state", new utils::VariableObject(&m_download.bencode(), "rtorrent", "state", torrent::Object::TYPE_STRING));
|
||||
m_variables.insert("tied_to_file", new utils::VariableObject(&m_download.bencode(), "rtorrent", "tied_to_file", torrent::Object::TYPE_STRING));
|
||||
|
||||
m_variables.insert("directory", new utils::VariableSlotString<>(rak::mem_fn(&m_download, &torrent::Download::root_dir),
|
||||
rak::mem_fn(this, &Download::set_root_directory)));
|
||||
m_variables.insert("directory", new utils::VariableSlotString<const std::string&>(rak::mem_fn(&m_fileList, &torrent::FileList::root_dir),
|
||||
rak::mem_fn(this, &Download::set_root_directory)));
|
||||
|
||||
m_variables.insert("min_peers", new utils::VariableSlotValue<uint32_t, uint32_t>(rak::mem_fn(&m_download, &torrent::Download::peers_min),
|
||||
rak::mem_fn(&m_download, &torrent::Download::set_peers_min),
|
||||
@@ -251,14 +253,14 @@ Download::receive_chunk_failed(__UNUSED uint32_t idx) {
|
||||
void
|
||||
Download::set_root_directory(const std::string& path) {
|
||||
if (path.empty()) {
|
||||
m_download.set_root_dir("./" + (m_download.size_file_entries() > 1 ? m_download.name() : std::string()));
|
||||
m_fileList.set_root_dir("./" + (m_fileList.size() > 1 ? m_download.name() : std::string()));
|
||||
|
||||
} else {
|
||||
std::string fullPath = rak::path_expand(path);
|
||||
|
||||
m_download.set_root_dir(fullPath +
|
||||
m_fileList.set_root_dir(fullPath +
|
||||
(*fullPath.rbegin() != '/' ? "/" : "") +
|
||||
(m_download.size_file_entries() > 1 ? m_download.name() : ""));
|
||||
(m_fileList.size() > 1 ? m_download.name() : ""));
|
||||
}
|
||||
|
||||
m_download.bencode().get_key("rtorrent").insert_key("directory", path);
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include <sigc++/connection.h>
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/torrent.h>
|
||||
|
||||
#include "utils/variable_map.h"
|
||||
@@ -63,6 +64,8 @@ public:
|
||||
utils::VariableMap* variables() { return &m_variables; }
|
||||
std::string variable_string(const std::string& key) { return m_variables.get_string(key); }
|
||||
|
||||
torrent::FileList* file_list() { return &m_fileList; }
|
||||
|
||||
torrent::Download& get_download() { return m_download; }
|
||||
const torrent::Download& get_download() const { return m_download; }
|
||||
std::string get_hash() { return m_download.info_hash(); }
|
||||
@@ -111,7 +114,9 @@ private:
|
||||
|
||||
void set_root_directory(const std::string& path);
|
||||
|
||||
// Store the FileList instance so we can use slots etc on it.
|
||||
torrent::Download m_download;
|
||||
torrent::FileList m_fileList;
|
||||
|
||||
std::string m_message;
|
||||
uint32_t m_chunksFailed;
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
#include <stdexcept>
|
||||
#include <rak/algorithm.h>
|
||||
#include <torrent/file.h>
|
||||
#include <torrent/file_list.h>
|
||||
#include <torrent/path.h>
|
||||
|
||||
#include "core/download.h"
|
||||
@@ -74,8 +76,9 @@ WindowFileList::redraw() {
|
||||
m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(10)).round_seconds());
|
||||
m_canvas->erase();
|
||||
|
||||
if (m_download->get_download().size_file_entries() == 0 ||
|
||||
m_canvas->get_height() < 2)
|
||||
torrent::FileList fl = m_download->get_download().file_list();
|
||||
|
||||
if (fl.size() == 0 || m_canvas->get_height() < 2)
|
||||
return;
|
||||
|
||||
int pos = 0;
|
||||
@@ -89,16 +92,13 @@ WindowFileList::redraw() {
|
||||
|
||||
++pos;
|
||||
|
||||
if (*m_focus >= m_download->get_download().size_file_entries())
|
||||
if (*m_focus >= fl.size())
|
||||
throw std::logic_error("WindowFileList::redraw() called on an object with a bad focus value");
|
||||
|
||||
Range range = rak::advance_bidirectional<unsigned int>(0,
|
||||
*m_focus,
|
||||
m_download->get_download().size_file_entries(),
|
||||
m_canvas->get_height() - pos);
|
||||
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, fl.size(), m_canvas->get_height() - pos);
|
||||
|
||||
while (range.first != range.second) {
|
||||
torrent::Entry e = m_download->get_download().file_entry(range.first);
|
||||
torrent::File e = fl.get(range.first);
|
||||
|
||||
std::string path = e.path_str();
|
||||
|
||||
@@ -110,15 +110,15 @@ WindowFileList::redraw() {
|
||||
std::string priority;
|
||||
|
||||
switch (e.priority()) {
|
||||
case torrent::Entry::OFF:
|
||||
case torrent::File::OFF:
|
||||
priority = "off";
|
||||
break;
|
||||
|
||||
case torrent::Entry::NORMAL:
|
||||
case torrent::File::NORMAL:
|
||||
priority = " ";
|
||||
break;
|
||||
|
||||
case torrent::Entry::HIGH:
|
||||
case torrent::File::HIGH:
|
||||
priority = "hig";
|
||||
break;
|
||||
|
||||
@@ -146,7 +146,7 @@ WindowFileList::redraw() {
|
||||
}
|
||||
|
||||
int
|
||||
WindowFileList::done_percentage(torrent::Entry& e) {
|
||||
WindowFileList::done_percentage(torrent::File& e) {
|
||||
int chunks = e.chunk_end() - e.chunk_begin();
|
||||
|
||||
return chunks ? (e.completed_chunks() * 100) / chunks : 100;
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#include "window.h"
|
||||
|
||||
namespace torrent {
|
||||
class Entry;
|
||||
class File;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
int done_percentage(torrent::Entry& e);
|
||||
int done_percentage(torrent::File& e);
|
||||
|
||||
core::Download* m_download;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <stdexcept>
|
||||
#include <rak/algorithm.h>
|
||||
#include <rak/string_manip.h>
|
||||
#include <torrent/tracker.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <torrent/connection_manager.h>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/torrent.h>
|
||||
#include <torrent/tracker.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
+33
-24
@@ -36,7 +36,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/file_list.h>
|
||||
|
||||
#include "display/window_file_list.h"
|
||||
#include "input/manager.h"
|
||||
@@ -60,7 +61,7 @@ ElementFileList::ElementFileList(core::Download* d) :
|
||||
void
|
||||
ElementFileList::activate(Control* c, MItr mItr) {
|
||||
if (m_window != NULL)
|
||||
throw std::logic_error("ui::ElementFileList::activate(...) called on an object in the wrong state");
|
||||
throw torrent::internal_error("ui::ElementFileList::activate(...) called on an object in the wrong state");
|
||||
|
||||
c->input()->push_front(&m_bindings);
|
||||
|
||||
@@ -70,7 +71,7 @@ ElementFileList::activate(Control* c, MItr mItr) {
|
||||
void
|
||||
ElementFileList::disable(Control* c) {
|
||||
if (m_window == NULL)
|
||||
throw std::logic_error("ui::ElementFileList::disable(...) called on an object in the wrong state");
|
||||
throw torrent::internal_error("ui::ElementFileList::disable(...) called on an object in the wrong state");
|
||||
|
||||
c->input()->erase(&m_bindings);
|
||||
|
||||
@@ -81,9 +82,9 @@ ElementFileList::disable(Control* c) {
|
||||
void
|
||||
ElementFileList::receive_next() {
|
||||
if (m_window == NULL)
|
||||
throw std::logic_error("ui::ElementFileList::receive_next(...) called on a disabled object");
|
||||
throw torrent::internal_error("ui::ElementFileList::receive_next(...) called on a disabled object");
|
||||
|
||||
if (++m_focus >= m_download->get_download().size_file_entries())
|
||||
if (++m_focus >= m_download->get_download().file_list().size())
|
||||
m_focus = 0;
|
||||
|
||||
m_window->mark_dirty();
|
||||
@@ -92,15 +93,17 @@ ElementFileList::receive_next() {
|
||||
void
|
||||
ElementFileList::receive_prev() {
|
||||
if (m_window == NULL)
|
||||
throw std::logic_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
throw torrent::internal_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
|
||||
if (m_download->get_download().size_file_entries() == 0)
|
||||
torrent::FileList fl = m_download->get_download().file_list();
|
||||
|
||||
if (fl.size() == 0)
|
||||
return;
|
||||
|
||||
if (m_focus != 0)
|
||||
--m_focus;
|
||||
else
|
||||
m_focus = m_download->get_download().size_file_entries() - 1;
|
||||
m_focus = fl.size() - 1;
|
||||
|
||||
m_window->mark_dirty();
|
||||
}
|
||||
@@ -108,14 +111,16 @@ ElementFileList::receive_prev() {
|
||||
void
|
||||
ElementFileList::receive_priority() {
|
||||
if (m_window == NULL)
|
||||
throw std::logic_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
throw torrent::internal_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
|
||||
if (m_focus >= m_download->get_download().size_file_entries())
|
||||
torrent::FileList fl = m_download->get_download().file_list();
|
||||
|
||||
if (m_focus >= fl.size())
|
||||
return;
|
||||
|
||||
torrent::Entry e = m_download->get_download().file_entry(m_focus);
|
||||
torrent::File file = fl.get(m_focus);
|
||||
|
||||
e.set_priority(next_priority(e.priority()));
|
||||
file.set_priority(next_priority(file.priority()));
|
||||
|
||||
m_download->get_download().update_priorities();
|
||||
m_window->mark_dirty();
|
||||
@@ -124,15 +129,17 @@ ElementFileList::receive_priority() {
|
||||
void
|
||||
ElementFileList::receive_change_all() {
|
||||
if (m_window == NULL)
|
||||
throw std::logic_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
throw torrent::internal_error("ui::ElementFileList::receive_prev(...) called on a disabled object");
|
||||
|
||||
if (m_focus >= m_download->get_download().size_file_entries())
|
||||
torrent::FileList fl = m_download->get_download().file_list();
|
||||
|
||||
if (m_focus >= fl.size())
|
||||
return;
|
||||
|
||||
Priority p = next_priority(m_download->get_download().file_entry(m_focus).priority());
|
||||
Priority p = next_priority(fl.get(m_focus).priority());
|
||||
|
||||
for (int i = 0, e = m_download->get_download().size_file_entries(); i != e; ++i)
|
||||
m_download->get_download().file_entry(i).set_priority(p);
|
||||
for (int i = 0, last = fl.size(); i != last; ++i)
|
||||
fl.get(i).set_priority(p);
|
||||
|
||||
m_download->get_download().update_priorities();
|
||||
m_window->mark_dirty();
|
||||
@@ -140,18 +147,20 @@ ElementFileList::receive_change_all() {
|
||||
|
||||
ElementFileList::Priority
|
||||
ElementFileList::next_priority(Priority p) {
|
||||
// Ahh... do +1 modulo.
|
||||
|
||||
switch(p) {
|
||||
case torrent::Entry::OFF:
|
||||
return torrent::Entry::HIGH;
|
||||
case torrent::File::OFF:
|
||||
return torrent::File::HIGH;
|
||||
|
||||
case torrent::Entry::NORMAL:
|
||||
return torrent::Entry::OFF;
|
||||
case torrent::File::NORMAL:
|
||||
return torrent::File::OFF;
|
||||
|
||||
case torrent::Entry::HIGH:
|
||||
return torrent::Entry::NORMAL;
|
||||
case torrent::File::HIGH:
|
||||
return torrent::File::NORMAL;
|
||||
|
||||
default:
|
||||
return torrent::Entry::NORMAL;
|
||||
return torrent::File::NORMAL;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#ifndef RTORRENT_UI_ELEMENT_FILE_LIST_H
|
||||
#define RTORRENT_UI_ELEMENT_FILE_LIST_H
|
||||
|
||||
#include <torrent/file.h>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
#include "element_base.h"
|
||||
@@ -51,7 +53,7 @@ namespace ui {
|
||||
|
||||
class ElementFileList : public ElementBase {
|
||||
public:
|
||||
typedef torrent::Entry::Priority Priority;
|
||||
typedef torrent::File::Priority Priority;
|
||||
typedef display::WindowFileList WFileList;
|
||||
|
||||
ElementFileList(core::Download* d);
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <torrent/exceptions.h>
|
||||
#include <torrent/tracker.h>
|
||||
#include <torrent/tracker_list.h>
|
||||
|
||||
#include "display/window_tracker_list.h"
|
||||
|
||||
Reference in New Issue
Block a user