From 75ef138118a2f6adc9c3b2e036763f1478179394 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 20 Feb 2005 18:02:32 +0000 Subject: [PATCH] Cleaning up main.cc and adding help text. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@296 e378c898-3ddf-0310-93e7-cc216c733640 --- README | 2 ++ src/main.cc | 70 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/README b/README index 8b2bc1a9..8a43b55b 100644 --- a/README +++ b/README @@ -2,6 +2,8 @@ Options and flags: -p Open a port in the range a to b. + -s Use as the session directory. The torrents will be + saved with the info-hash in hex as the filename. All: diff --git a/src/main.cc b/src/main.cc index 04323229..46ba1c30 100644 --- a/src/main.cc +++ b/src/main.cc @@ -85,6 +85,17 @@ test_dir(const std::string& s) { exit(0); } +int +parse_options(ui::Control* c, int argc, char** argv) { + OptionParser optionParser; + optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); + optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair), + sigc::mem_fun(c->get_core(), &core::Manager::set_port_range))); + optionParser.insert_option('s', sigc::mem_fun(c->get_core().get_download_store(), &core::DownloadStore::activate)); + + return optionParser.process(argc, argv); +} + void load_session_torrents(ui::Control* c) { // Load session torrents. @@ -98,23 +109,31 @@ load_arg_torrents(ui::Control* c, char** begin, char** end) { std::for_each(begin, end, std::bind1st(std::mem_fun(&core::Manager::insert), &c->get_core())); } -int -main(int argc, char** argv) { - ui::Control uiControl; - - try { - +void +register_signals(ui::Control* c) { SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown)); SignalHandler::set_handler(SIGSEGV, sigc::bind(sigc::ptr_fun(&do_panic), SIGSEGV)); SignalHandler::set_handler(SIGBUS, sigc::bind(sigc::ptr_fun(&do_panic), SIGBUS)); +} - OptionParser optionParser; - optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); - optionParser.insert_option('p', sigc::bind(sigc::ptr_fun(OptionParser::call_int_pair), - sigc::mem_fun(uiControl.get_core(), &core::Manager::set_port_range))); - optionParser.insert_option('s', sigc::mem_fun(uiControl.get_core().get_download_store(), &core::DownloadStore::activate)); +void +register_main_keys(ui::Control* c, input::Bindings* b) { + c->get_input().push_back(b); - int firstArg = optionParser.process(argc, argv); + (*b)[KEY_RESIZE] = sigc::mem_fun(c->get_display(), &display::Manager::adjust_layout); + (*b)['\x11'] = sigc::ptr_fun(&set_shutdown); +} + +int +main(int argc, char** argv) { + ui::Control uiControl; + input::Bindings inputMain; + + try { + + register_signals(&uiControl); + + int firstArg = parse_options(&uiControl, argc, argv); display::Canvas::init(); @@ -123,12 +142,7 @@ main(int argc, char** argv) { uiDownloadList.activate(); uiDownloadList.slot_open_uri(sigc::mem_fun(uiControl.get_core(), &core::Manager::insert)); - // Register main key events. - input::Bindings inputMain; - uiControl.get_input().push_back(&inputMain); - - inputMain[KEY_RESIZE] = sigc::mem_fun(uiControl.get_display(), &display::Manager::adjust_layout); - inputMain['\x11'] = sigc::ptr_fun(&set_shutdown); + register_main_keys(&uiControl, &inputMain); uiControl.get_core().get_poll().slot_read_stdin(sigc::mem_fun(uiControl.get_input(), &input::Manager::pressed)); uiControl.get_core().get_poll().slot_select_interrupted(sigc::ptr_fun(display::Canvas::do_update)); @@ -193,12 +207,26 @@ do_panic(int signum) { void print_help() { - std::cout << "Rakshasa's Torrent client. Neko-Mimi Mode-o!" << std::endl; + std::cout << "Rakshasa's Torrent client. " << std::endl; + std::cout << std::endl; std::cout << "Usage: rtorrent [OPTIONS]... [FILE]... [URL]..." << std::endl; - std::cout << std::endl; - std::cout << " -h Display this very helpfull text" << std::endl; + std::cout << " -h Display this very helpful text" << std::endl; std::cout << " -p - Set port range for incoming connections" << std::endl; + std::cout << " -s Set the session directory" << std::endl; std::cout << std::endl; + std::cout << "Main view keys:" << std::endl; + std::cout << " backspace Add a torrent url or path" << std::endl; + std::cout << " ^s Start torrent" << std::endl; + std::cout << " ^d Stop torrent or delete a stopped torrent" << std::endl; + std::cout << " ^q Initiate shutdown or skip shutdown process" << std::endl; + std::cout << " a,s,d,z,x,c Adjust throttle" << std::endl; + std::cout << std::endl; + std::cout << "Download view keys:" << std::endl; + std::cout << " 1,2 Adjust max uploads" << std::endl; + std::cout << " 3,4,5,6 Adjust min/max connected peers" << std::endl; + std::cout << " t Query tracker for more peers" << std::endl; + std::cout << std::endl; + std::cout << "Report bugs to ." << std::endl; exit(0);