From a851264787d73a25f4e17502585396dc6587f06e Mon Sep 17 00:00:00 2001 From: rakshasa Date: Tue, 9 May 2006 20:50:07 +0000 Subject: [PATCH] * Added '-n' flag that disables loading of ~/.rtorrent.rc. * Re-added priority change when a download finishes. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@686 e378c898-3ddf-0310-93e7-cc216c733640 --- doc/rtorrent.1.xml | 10 ++++++++++ src/core/download_list.cc | 5 ++--- src/core/view.cc | 20 +++++++++++++------- src/core/view.h | 2 ++ src/core/view_manager.cc | 34 +++++++++++++++++----------------- src/main.cc | 7 ++++++- src/option_parser.cc | 16 ++++++++++++++++ src/option_parser.h | 2 ++ 8 files changed, 68 insertions(+), 28 deletions(-) diff --git a/doc/rtorrent.1.xml b/doc/rtorrent.1.xml index 901e2c60..f8bf8439 100644 --- a/doc/rtorrent.1.xml +++ b/doc/rtorrent.1.xml @@ -22,6 +22,7 @@ rtorrent -h + -n -o key1=opt1,... -O key=opt URL | FILE @@ -332,6 +333,15 @@ Set the address reported to the tracker. + + -n + + +Don't load ~/.rtorrent.rc on startup. + + + + -o key1=opt1,... -O key=opt diff --git a/src/core/download_list.cc b/src/core/download_list.cc index c92a872e..47223b61 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -453,11 +453,10 @@ void DownloadList::confirm_finished(Download* download) { check_contains(download); - // FIXME - //torrent::download_set_priority(m_download, 2); - download->variable()->set("complete", (int64_t)1); + download->set_connection_type(download->variable()->get_string("connection_seed")); + download->set_priority(download->priority()); download->download()->tracker_list().send_completed(); diff --git a/src/core/view.cc b/src/core/view.cc index 9038ce4d..6a7e2ad3 100644 --- a/src/core/view.cc +++ b/src/core/view.cc @@ -53,7 +53,8 @@ View::~View() { if (m_name.empty()) return; - std::for_each(m_list->slot_map_begin(), m_list->slot_map_end(), rak::bind2nd(std::ptr_fun(&DownloadList::erase_key), "0_view_" + m_name)); + std::for_each(m_list->slot_map_begin(), m_list->slot_map_end(), + rak::bind2nd(std::ptr_fun(&DownloadList::erase_key), "0_view_" + m_name)); } void @@ -171,6 +172,14 @@ View::set_filter_on(int event) { m_list->slots(event)["0_view_" + m_name] = sigc::bind(sigc::mem_fun(this, &View::received), event); } +void +View::clear_filter_on() { + // Don't clear insert and erase as these are required to keep the + // View up-to-date with the available downloads. + std::for_each(m_list->slot_map_begin() + DownloadList::SLOTS_OPEN, m_list->slot_map_end(), + rak::bind2nd(std::ptr_fun(&DownloadList::erase_key), "0_view_" + m_name)); +} + inline void View::insert_visible(Download* d) { iterator itr = std::find_if(begin_visible(), end_visible(), std::bind1st(view_downloads_compare(m_sortNew), d)); @@ -222,12 +231,9 @@ View::received(core::Download* download, int event) { if (view_downloads_filter(m_filter)(download)) { - if (itr < end_visible()) - return; - - // Use base_type::erase as we don't need to modify m_size nor - // m_focus. - base_type::erase(itr); + // Erase even if it is in visible so that the download is + // re-sorted. + erase(itr); insert_visible(download); } else { diff --git a/src/core/view.h b/src/core/view.h index e40dfe46..60de88e6 100644 --- a/src/core/view.h +++ b/src/core/view.h @@ -119,6 +119,8 @@ public: void set_filter(const filter_list& s) { m_filter = s; } void set_filter_on(int event); + void clear_filter_on(); + // The time of the last change to the view, semantics of this is // user-dependent. Used by f.ex. ViewManager to decide if it should // sort and/or filter a view. diff --git a/src/core/view_manager.cc b/src/core/view_manager.cc index 2e399fdf..36f43f87 100644 --- a/src/core/view_manager.cc +++ b/src/core/view_manager.cc @@ -83,15 +83,19 @@ private: class ViewSortVariableValue : public ViewSort { public: - ViewSortVariableValue(const std::string& name) : + ViewSortVariableValue(const std::string& name, bool reverse = false) : m_name(name) {} virtual bool operator () (Download* d1, Download* d2) const { - return d1->variable()->get_value(m_name) < d2->variable()->get_value(m_name); + if (m_reverse) + return d2->variable()->get_value(m_name) < d1->variable()->get_value(m_name); + else + return d1->variable()->get_value(m_name) < d2->variable()->get_value(m_name); } private: std::string m_name; + bool m_reverse; }; class ViewSortReverse : public ViewSort { @@ -109,23 +113,17 @@ private: class ViewFilterVariableValue : public ViewFilter { public: - ViewFilterVariableValue(const std::string& name, torrent::Object::value_type v) : - m_name(name), m_value(v) {} + ViewFilterVariableValue(const std::string& name, torrent::Object::value_type v, bool inverse = false) : + m_name(name), m_value(v), m_inverse(inverse) {} virtual bool operator () (Download* d1) const { - return d1->variable()->get_value(m_name) == m_value; + return (d1->variable()->get_value(m_name) == m_value) != m_inverse; } private: std::string m_name; torrent::Object::value_type m_value; -}; - -class ViewFilterHashing : public ViewFilter { -public: - virtual bool operator () (Download* d1) const { - return control->core()->hash_queue()->is_queued(d1); - } + bool m_inverse; }; // Really need to implement a factory and allow options in the sort @@ -139,18 +137,18 @@ ViewManager::ViewManager(DownloadList* dl) : m_sort["name_reverse"] = new ViewSortReverse(new ViewSortName()); m_sort["stopped"] = new ViewSortVariableValue("state"); - m_sort["started"] = new ViewSortReverse(new ViewSortVariableValue("state")); + m_sort["started"] = new ViewSortVariableValue("state", true); m_sort["complete"] = new ViewSortVariableValue("complete"); - m_sort["incomplete"] = new ViewSortReverse(new ViewSortVariableValue("complete")); + m_sort["incomplete"] = new ViewSortVariableValue("complete", true); m_sort["state_changed"] = new ViewSortVariableValue("state_changed"); - m_sort["state_changed_reverse"] = new ViewSortReverse(new ViewSortVariableValue("state_changed")); + m_sort["state_changed_reverse"] = new ViewSortVariableValue("state_changed", true); m_filter["started"] = new ViewFilterVariableValue("state", 1); m_filter["stopped"] = new ViewFilterVariableValue("state", 0); - m_filter["complete"] = new ViewFilterVariableValue("complete", 1); + m_filter["complete"] = new ViewFilterVariableValue("complete", 0, false); m_filter["incomplete"] = new ViewFilterVariableValue("complete", 0); - m_filter["hashing"] = new ViewFilterHashing(); + m_filter["hashing"] = new ViewFilterVariableValue("hashing", 0, true); } void @@ -259,6 +257,8 @@ void ViewManager::set_filter_on(const std::string& name, const filter_args& args) { iterator viewItr = find_throw(name); + (*viewItr)->clear_filter_on(); + for (filter_args::const_iterator itr = args.begin(); itr != args.end(); ++itr) { if (*itr == "start") diff --git a/src/main.cc b/src/main.cc index 731fd7d7..5608b3f8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -78,6 +78,7 @@ parse_options(Control* c, int argc, char** argv) { // Converted. optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); + optionParser.insert_flag('n', OptionParser::Slot()); optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "bind")); optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "directory")); @@ -218,7 +219,10 @@ main(int argc, char** argv) { // control->variable()->process_command("schedule = scheduler,10,10,download_scheduler="); - control->variable()->process_command("try_import = ~/.rtorrent.rc"); + if (OptionParser::has_flag('n', argc, argv)) + control->core()->push_log("Ignoring ~/.rtorrent.rc."); + else + control->variable()->process_command("try_import = ~/.rtorrent.rc"); int firstArg = parse_options(control, argc, argv); @@ -305,6 +309,7 @@ print_help() { std::cout << std::endl; std::cout << "Usage: rtorrent [OPTIONS]... [FILE]... [URL]..." << std::endl; std::cout << " -h Display this very helpful text" << std::endl; + std::cout << " -n Don't try to load ~/.rtorrent.rc on startup" << std::endl; std::cout << " -b Bind the listening socket to this IP" << std::endl; std::cout << " -i Change the IP that is sent to the tracker" << std::endl; std::cout << " -p - Set port range for incoming connections" << std::endl; diff --git a/src/option_parser.cc b/src/option_parser.cc index eb54f735..67c31143 100644 --- a/src/option_parser.cc +++ b/src/option_parser.cc @@ -74,6 +74,7 @@ OptionParser::process(int argc, char** argv) { int c; std::string optString = create_optstring(); + optind = 0; opterr = 0; while ((c = getopt(argc, argv, optString.c_str())) != -1) @@ -85,6 +86,21 @@ OptionParser::process(int argc, char** argv) { return optind; } +bool +OptionParser::has_flag(char flag, int argc, char** argv) { + int result; + char options[2] = { flag, '\0' }; + + optind = 0; + opterr = 0; + + while ((result = getopt(argc, argv, options)) != -1) + if (result == flag) + return true; + + return false; +} + std::string OptionParser::create_optstring() { std::string s; diff --git a/src/option_parser.h b/src/option_parser.h index b165e1de..9d313db5 100644 --- a/src/option_parser.h +++ b/src/option_parser.h @@ -61,6 +61,8 @@ public: // Returns the index of the first non-option argument. int process(int argc, char** argv); + static bool has_flag(char flag, int argc, char** argv); + private: std::string create_optstring();