diff --git a/src/control.cc b/src/control.cc index 52ba83b5..1d8e3e4a 100644 --- a/src/control.cc +++ b/src/control.cc @@ -61,7 +61,9 @@ Control::Control() : m_inputStdin(new input::InputEvent(STDIN_FILENO)), m_commandScheduler(new CommandScheduler()), - m_optionHandler(new OptionHandler()) { + m_optionHandler(new OptionHandler()), + + m_tick(0) { m_inputStdin->slot_pressed(sigc::mem_fun(m_input, &input::Manager::pressed)); diff --git a/src/control.h b/src/control.h index 175c485e..42f2512c 100644 --- a/src/control.h +++ b/src/control.h @@ -37,6 +37,7 @@ #ifndef RTORRENT_CONTROL_H #define RTORRENT_CONTROL_H +#include #include #include "globals.h" @@ -83,6 +84,9 @@ public: CommandScheduler* command_scheduler() { return m_commandScheduler; } OptionHandler* option_handler() { return m_optionHandler; } + uint64_t tick() const { return m_tick; } + void inc_tick() { m_tick++; } + private: Control(const Control&); void operator = (const Control&); @@ -98,6 +102,8 @@ private: CommandScheduler* m_commandScheduler; OptionHandler* m_optionHandler; + uint64_t m_tick; + rak::priority_item m_taskShutdown; }; diff --git a/src/core/manager.cc b/src/core/manager.cc index 032fe511..d32afa68 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -74,6 +74,15 @@ connect_signal_storage_log(Download* d, torrent::Download::SlotString s) { d->get_download().signal_storage_error(s); } +// Hmm... find some better place for all this. +static void +delete_tied(Download* d) { + // This should be configurable, need to wait for the variable + // thingie to be implemented. + if (!d->tied_to_file().empty()) + ::unlink(d->tied_to_file().c_str()); +} + Manager::Manager() : m_pollManager(NULL), m_portRandom(false), @@ -112,6 +121,7 @@ Manager::initialize_second() { m_downloadList.slot_map_erase()["1_hash_queue_remove"] = sigc::mem_fun(m_hashQueue, &HashQueue::remove); m_downloadList.slot_map_erase()["1_store_remove"] = sigc::mem_fun(m_downloadStore, &DownloadStore::remove); + m_downloadList.slot_map_erase()["1_delete_tied"] = sigc::ptr_fun(&delete_tied); m_downloadList.slot_map_open()["1_download_open"] = sigc::mem_fun(&Download::call); @@ -350,8 +360,12 @@ path_expand(std::vector* paths, const std::string& pattern) { if (r.pattern().empty()) continue; + // Special case for ".."? + for (std::vector::iterator itr = currentCache.begin(); itr != currentCache.end(); ++itr) { - itr->update(false); + // Only include filenames starting with '.' if the pattern + // starts with the same. + itr->update(r.pattern()[0] != '.'); itr->erase(std::remove_if(itr->begin(), itr->end(), std::not1(r)), itr->end()); std::transform(itr->begin(), itr->end(), std::back_inserter(nextCache), std::bind1st(std::plus(), itr->get_path() + "/")); @@ -371,6 +385,14 @@ Manager::try_create_download_expand(const std::string& uri, bool start, bool pri path_expand(&paths, uri); + if (tied) + for (std::vector::iterator itr = paths.begin(); itr != paths.end(); ) + if (std::find_if(m_downloadList.begin(), m_downloadList.end(), + rak::equal(*itr, std::mem_fun(&Download::tied_to_file))) != m_downloadList.end()) + itr = paths.erase(itr); + else + itr++; + if (!paths.empty()) for (std::vector::iterator itr = paths.begin(); itr != paths.end(); ++itr) try_create_download(*itr, start, printLog, tied); diff --git a/src/display/manager.cc b/src/display/manager.cc index 926569a6..98a4d826 100644 --- a/src/display/manager.cc +++ b/src/display/manager.cc @@ -152,7 +152,7 @@ Manager::schedule_update() { if (!m_taskUpdate.is_queued() || m_taskUpdate.time() > m_scheduler.top()->time()) { rak::priority_queue_erase(&taskScheduler, &m_taskUpdate); rak::priority_queue_insert(&taskScheduler, &m_taskUpdate, - std::max(m_scheduler.top()->time(), m_timeLastUpdate + 100000)); + std::max(m_scheduler.top()->time(), m_timeLastUpdate + 50000)); } } diff --git a/src/display/window_statusbar.cc b/src/display/window_statusbar.cc index 2ab101c1..6b081e58 100644 --- a/src/display/window_statusbar.cc +++ b/src/display/window_statusbar.cc @@ -39,19 +39,16 @@ #include #include -#include "core/manager.h" - +#include "control.h" #include "canvas.h" #include "window_statusbar.h" -extern uint32_t countTicks; - namespace display { -WindowStatusbar::WindowStatusbar(core::Manager* c) : +WindowStatusbar::WindowStatusbar(Control* c) : Window(new Canvas, false, 1), - m_counter(0), - m_core(c) { + m_lastTick(0), + m_control(c) { } void @@ -86,7 +83,7 @@ WindowStatusbar::redraw() { pos = snprintf(buf, 128, "[U %i/%i][S %i/%i/%i][F %i/%i]", #else pos = snprintf(buf, 128, "%i [U %i/%i][S %i/%i/%i][F %i/%i]", - countTicks, + (int)(m_control->tick() - m_lastTick), #endif torrent::currently_unchoked(), torrent::max_unchoked(), @@ -96,9 +93,9 @@ WindowStatusbar::redraw() { torrent::open_files(), torrent::max_open_files()); - countTicks = 0; - m_canvas->print(m_canvas->get_width() - pos, 0, "%s", buf); + + m_lastTick = m_control->tick(); } } diff --git a/src/display/window_statusbar.h b/src/display/window_statusbar.h index eb6771bf..26de7729 100644 --- a/src/display/window_statusbar.h +++ b/src/display/window_statusbar.h @@ -37,23 +37,23 @@ #ifndef RTORRENT_DISPLAY_WINDOW_STATUSBAR_H #define RTORRENT_DISPLAY_WINDOW_STATUSBAR_H +#include + #include "window.h" -namespace core { - class Manager; -} +class Control; namespace display { class WindowStatusbar : public Window { public: - WindowStatusbar(core::Manager* c); + WindowStatusbar(Control* c); - virtual void redraw(); + virtual void redraw(); private: - int m_counter; - core::Manager* m_core; + uint64_t m_lastTick; + Control* m_control; }; } diff --git a/src/main.cc b/src/main.cc index 601cda84..0a8a57cc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -74,8 +74,6 @@ #include "command_scheduler.h" #include "command_scheduler_item.h" -uint32_t countTicks = 0; - void do_panic(int signum); void print_help(); @@ -202,7 +200,7 @@ main(int argc, char** argv) { control.display()->adjust_layout(); while (!control.is_shutdown_completed()) { - countTicks++; + control.inc_tick(); cachedTime = rak::timer::current(); rak::priority_queue_perform(&taskScheduler, cachedTime); diff --git a/src/ui/root.cc b/src/ui/root.cc index 2a86ab6b..505eb290 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -64,7 +64,7 @@ Root::init(Control* c) { m_control = c; setup_keys(); - m_windowStatusbar = new WStatusbar(m_control->core()); + m_windowStatusbar = new WStatusbar(m_control); m_downloadList = new DownloadList(m_control); m_control->display()->push_back(m_windowStatusbar);