diff --git a/src/core/download.cc b/src/core/download.cc index 4fd0df2b..50f0a70d 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -43,6 +43,7 @@ #include #include #include +#include #include #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(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(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); diff --git a/src/core/download.h b/src/core/download.h index 60a83eba..706c1cb5 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -39,6 +39,7 @@ #include #include +#include #include #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; diff --git a/src/display/window_file_list.cc b/src/display/window_file_list.cc index c68008a0..5efd8d76 100644 --- a/src/display/window_file_list.cc +++ b/src/display/window_file_list.cc @@ -38,6 +38,8 @@ #include #include +#include +#include #include #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(0, - *m_focus, - m_download->get_download().size_file_entries(), - m_canvas->get_height() - pos); + Range range = rak::advance_bidirectional(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; diff --git a/src/display/window_file_list.h b/src/display/window_file_list.h index 610954d8..e59d929c 100644 --- a/src/display/window_file_list.h +++ b/src/display/window_file_list.h @@ -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; diff --git a/src/display/window_tracker_list.cc b/src/display/window_tracker_list.cc index 50594551..906367fa 100644 --- a/src/display/window_tracker_list.cc +++ b/src/display/window_tracker_list.cc @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "core/download.h" diff --git a/src/option_handler_rules.cc b/src/option_handler_rules.cc index 39b9a015..13d13745 100644 --- a/src/option_handler_rules.cc +++ b/src/option_handler_rules.cc @@ -48,6 +48,7 @@ #include #include #include +#include #include #include "core/download.h" diff --git a/src/ui/element_file_list.cc b/src/ui/element_file_list.cc index 0e38fe3f..df006039 100644 --- a/src/ui/element_file_list.cc +++ b/src/ui/element_file_list.cc @@ -36,7 +36,8 @@ #include "config.h" -#include +#include +#include #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; }; } diff --git a/src/ui/element_file_list.h b/src/ui/element_file_list.h index 9f809b0a..f28c94cc 100644 --- a/src/ui/element_file_list.h +++ b/src/ui/element_file_list.h @@ -37,6 +37,8 @@ #ifndef RTORRENT_UI_ELEMENT_FILE_LIST_H #define RTORRENT_UI_ELEMENT_FILE_LIST_H +#include + #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); diff --git a/src/ui/element_tracker_list.cc b/src/ui/element_tracker_list.cc index 3b9e7f60..967d9bc5 100644 --- a/src/ui/element_tracker_list.cc +++ b/src/ui/element_tracker_list.cc @@ -37,6 +37,7 @@ #include "config.h" #include +#include #include #include "display/window_tracker_list.h"