* 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
This commit is contained in:
rakshasa
2006-05-09 20:50:07 +00:00
parent 6d07bf3540
commit a851264787
8 changed files with 68 additions and 28 deletions
+10
View File
@@ -22,6 +22,7 @@
<cmdsynopsis>
<command>rtorrent</command>
<arg choice="opt">-h</arg>
<arg choice="opt">-n</arg>
<arg choice="opt">-o key1=opt1,...</arg>
<arg choice="opt">-O key=opt</arg>
<arg choice="opt" rep="repeat">URL | FILE</arg>
@@ -332,6 +333,15 @@ Set the address reported to the tracker.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-n</term>
<listitem><para>
Don't load ~/.rtorrent.rc on startup.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-o key1=opt1,...</term>
<term>-O key=opt</term>
+2 -3
View File
@@ -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();
+13 -7
View File
@@ -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 {
+2
View File
@@ -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.
+17 -17
View File
@@ -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")
+6 -1
View File
@@ -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 <a.b.c.d> Bind the listening socket to this IP" << std::endl;
std::cout << " -i <a.b.c.d> Change the IP that is sent to the tracker" << std::endl;
std::cout << " -p <int>-<int> Set port range for incoming connections" << std::endl;
+16
View File
@@ -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;
+2
View File
@@ -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();