From f8bbf8bfadbeb9c12418f5372f0a19ab6a337f9f Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 9 Apr 2005 21:48:59 +0000 Subject: [PATCH] Added "-d" to change the default root dir. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@388 e378c898-3ddf-0310-93e7-cc216c733640 --- TODO | 3 --- src/core/download.cc | 10 +++++++++- src/core/download.h | 5 +++-- src/core/manager.cc | 3 +++ src/core/manager.h | 12 ++++++++++++ src/display/utils.cc | 16 ++++++---------- src/main.cc | 2 ++ 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index 76a849a1..e25821f7 100644 --- a/TODO +++ b/TODO @@ -31,6 +31,3 @@ Bug: Add the same torrent while it is hash checking. RELEASE: -Enable change of default download path. - -Make sure we show better messages for signal_storage_error. diff --git a/src/core/download.cc b/src/core/download.cc index 9b3fb8df..6cae0b64 100644 --- a/src/core/download.cc +++ b/src/core/download.cc @@ -48,7 +48,15 @@ Download::release_download() { void Download::receive_tracker_msg(std::string msg) { - m_trackerMsg = msg; + if (msg.empty()) + m_message = ""; + else + m_message = "Tracker: [" + msg + "]"; +} + +void +Download::receive_storage_error(std::string msg) { + m_message = "Storage error: [" + msg + "]"; } } diff --git a/src/core/download.h b/src/core/download.h index 4c861ff1..0300d03f 100644 --- a/src/core/download.h +++ b/src/core/download.h @@ -39,7 +39,7 @@ public: torrent::Download& get_download() { return m_download; } std::string get_hash() { return m_download.get_hash(); } - const std::string& get_tracker_msg() { return m_trackerMsg; } + const std::string& get_message() { return m_message; } void start() { m_download.start(); } void stop() { m_download.stop(); } @@ -51,10 +51,11 @@ public: private: void receive_tracker_msg(std::string msg); + void receive_storage_error(std::string msg); torrent::Download m_download; - std::string m_trackerMsg; + std::string m_message; sigc::connection m_connTrackerSucceded; sigc::connection m_connTrackerFailed; diff --git a/src/core/manager.cc b/src/core/manager.cc index 4c595cc9..c8d6ebd5 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -170,6 +170,9 @@ Manager::create_final(std::istream* s) { (*itr)->get_download().set_ip(m_dns); + if (!m_defaultRoot.empty()) + (*itr)->get_download().set_root_dir(m_defaultRoot + ((*itr)->get_download().get_entry_size() ? (*itr)->get_download().get_name() : "")); + start(*itr); m_downloadStore.save(*itr); diff --git a/src/core/manager.h b/src/core/manager.h index 6444ae20..f2fff943 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -68,6 +68,8 @@ public: void set_port_range(int a, int b) { m_portFirst = a; m_portLast = b; } void set_listen_ip(const std::string& ip) { m_listenIp = ip; } + void set_default_root(const std::string& path); + void debug_tracker() { m_debugTracker = 0; } private: @@ -95,9 +97,19 @@ private: int m_portLast; std::string m_listenIp; + std::string m_defaultRoot; + int m_debugTracker; }; +inline void +Manager::set_default_root(const std::string& path) { + m_defaultRoot = path; + + if (!m_defaultRoot.empty() && *m_defaultRoot.rbegin() != '/') + m_defaultRoot.push_back('/'); +} + } #endif diff --git a/src/display/utils.cc b/src/display/utils.cc index e42f4f45..c455ebd9 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -35,25 +35,21 @@ namespace display { std::string print_download_status(core::Download* d) { - std::stringstream str; - if (d->get_download().is_hash_checking()) { - str << "Checking hash"; + return "Checking hash"; } else if (d->get_download().is_tracker_busy()) { - str << "Tracker: Connecting"; + return "Tracker: Connecting"; } else if (!d->get_download().is_active()) { - str << "Inactive"; + return "Inactive"; - } else if (!d->get_tracker_msg().empty()) { - str << "Tracker: [" << d->get_tracker_msg() << ']'; + } else if (!d->get_message().empty()) { + return d->get_message(); } else { - //str << "---"; + return ""; } - - return str.str(); } std::string diff --git a/src/main.cc b/src/main.cc index 14a0728c..24856625 100644 --- a/src/main.cc +++ b/src/main.cc @@ -94,6 +94,7 @@ parse_options(ui::Control* c, int argc, char** argv) { optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); optionParser.insert_option('b', sigc::mem_fun(c->get_core(), &core::Manager::set_listen_ip)); + optionParser.insert_option('d', sigc::mem_fun(c->get_core(), &core::Manager::set_default_root)); optionParser.insert_option('i', sigc::mem_fun(c->get_core(), &core::Manager::set_dns)); optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair), @@ -230,6 +231,7 @@ print_help() { 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; + std::cout << " -d Save torrents to this directory by default" << std::endl; std::cout << " -s Set the session directory" << std::endl; std::cout << std::endl; std::cout << "Main view keys:" << std::endl;