From 874e46fc643cb2e2a20703f3af9d0d740795e66c Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 3 Apr 2005 16:36:19 +0000 Subject: [PATCH] Proper '/' on the end of directories in the find-file window. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@381 e378c898-3ddf-0310-93e7-cc216c733640 --- TODO | 8 +--- configure.ac | 2 +- src/core/hash_queue.cc | 1 - src/core/manager.cc | 1 + src/display/window_log.cc | 7 +--- src/display/window_string_list.cc | 12 +++++- src/display/window_string_list.h | 6 ++- src/input/path_input.cc | 42 ++++++++++++++++--- src/input/path_input.h | 7 +++- src/ui/download_list.cc | 4 ++ src/ui/element_string_list.cc | 10 +++++ src/ui/element_string_list.h | 2 + src/utils/Makefile.am | 2 + src/utils/file_stat.cc | 70 +++++++++++++++++++++++++++++++ src/utils/file_stat.h | 66 +++++++++++++++++++++++++++++ 15 files changed, 216 insertions(+), 24 deletions(-) create mode 100644 src/utils/file_stat.cc create mode 100644 src/utils/file_stat.h diff --git a/TODO b/TODO index c8c0eabd..537ababd 100644 --- a/TODO +++ b/TODO @@ -24,10 +24,6 @@ Make accumulate return the value, no refs please... > slow or broken or for various reasons you don't want to download it. -Const cast problems? +Make sure it gracefully handles torrents that fail to open files. -std::tm *u = std::localtime(&t.tval().tv_sec); - -Let us see the torrent comment. - -Why is the client lagging when downloading a http torrent? Looks like libcurl +Make throttle show off on 0 and up/down. diff --git a/configure.ac b/configure.ac index 2197fd9a..68df51b6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.1.4, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.1.5, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) diff --git a/src/core/hash_queue.cc b/src/core/hash_queue.cc index fc3941c7..fc89d5f6 100644 --- a/src/core/hash_queue.cc +++ b/src/core/hash_queue.cc @@ -77,7 +77,6 @@ HashQueue::receive_hash_done(Base::iterator itr) { Base::erase(itr); s(); - fill_queue(); } diff --git a/src/core/manager.cc b/src/core/manager.cc index 231050c9..97197241 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -94,6 +94,7 @@ Manager::start(Download* d) { if (d->get_download().is_hash_checked()) d->start(); else + // This can cause infinit loops. m_hashQueue.insert(d, sigc::mem_fun(d, &Download::start)); } diff --git a/src/display/window_log.cc b/src/display/window_log.cc index f78be18a..99367dec 100644 --- a/src/display/window_log.cc +++ b/src/display/window_log.cc @@ -57,9 +57,6 @@ WindowLog::redraw() { int pos = 0; - //m_canvas->print(std::max(0, (int)m_canvas->get_width() / 2 - 5), pos++, "*** Log ***"); - //m_canvas->print(0, 0, "___"); - for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr) m_canvas->print(0, pos++, "(%s) %s", print_hhmmss(itr->first).c_str(), @@ -69,9 +66,7 @@ WindowLog::redraw() { void WindowLog::receive_update() { iterator itr = find_older(); - - int h = std::min(std::distance(m_log->begin(), itr), - (std::iterator_traits::difference_type)10); + int h = std::min(std::distance(m_log->begin(), itr), (std::iterator_traits::difference_type)10); if (h != m_minHeight) { set_active(h != 0); diff --git a/src/display/window_string_list.cc b/src/display/window_string_list.cc index d98b2e4e..b7c427ff 100644 --- a/src/display/window_string_list.cc +++ b/src/display/window_string_list.cc @@ -45,14 +45,18 @@ WindowStringList::redraw() { size_t xpos = 1; size_t width = 0; - for (iterator itr = m_first; itr != m_last; ++itr) { + iterator itr = m_first; + + while (itr != m_last) { if (ypos == (size_t)m_canvas->get_height()) { ypos = 0; xpos += width + 2; - if (xpos >= (size_t)m_canvas->get_width()) + if (xpos + 20 >= (size_t)m_canvas->get_width()) break; + + width = 0; } width = std::max(itr->size(), width); @@ -61,7 +65,11 @@ WindowStringList::redraw() { m_canvas->print(xpos, ypos++, "%s", itr->c_str()); else m_canvas->print(xpos, ypos++, "%s", itr->substr(0, m_canvas->get_width() - xpos).c_str()); + + ++itr; } + + m_drawEnd = itr; } } diff --git a/src/display/window_string_list.h b/src/display/window_string_list.h index d3feff06..176bfe8b 100644 --- a/src/display/window_string_list.h +++ b/src/display/window_string_list.h @@ -37,13 +37,17 @@ public: WindowStringList(); ~WindowStringList(); - void set_range(iterator first, iterator last) { m_first = first; m_last = last; } + iterator get_draw_end() { return m_drawEnd; } + + void set_range(iterator first, iterator last) { m_first = m_drawEnd = first; m_last = last; } virtual void redraw(); private: iterator m_first; iterator m_last; + + iterator m_drawEnd; }; } diff --git a/src/input/path_input.cc b/src/input/path_input.cc index 4719c913..b6c0a1d0 100644 --- a/src/input/path_input.cc +++ b/src/input/path_input.cc @@ -26,22 +26,48 @@ #include #include "path_input.h" +#include "utils/file_stat.h" namespace input { -PathInput::PathInput() { +PathInput::PathInput() : + m_showNext(false) { } bool PathInput::pressed(int key) { - if (key == '\t') - receive_do_complete(); - else + if (key != '\t') { + m_showNext = false; return TextInput::pressed(key); + } else if (m_showNext) { + m_signalShowNext.emit(); + + } else { + receive_do_complete(); + + m_showNext = true; + } + return true; } +struct _transform_filename { + _transform_filename(const std::string& base) : m_base(base) {} + + void operator () (std::string& filename) { + utils::FileStat fs; + + if (fs.update((m_base + filename).c_str())) + return; + + else if (fs.is_directory()) + filename += '/'; + } + + const std::string& m_base; +}; + void PathInput::receive_do_complete() { size_type dirEnd = find_last_delim(); @@ -49,12 +75,13 @@ PathInput::receive_do_complete() { utils::Directory dir(dirEnd != 0 ? str().substr(0, dirEnd) : "./"); if (!dir.update() || dir.empty()) { - str() += "!"; mark_dirty(); return; } + std::for_each(dir.begin(), dir.end(), _transform_filename(str().substr(0, dirEnd))); + Range r = find_incomplete(dir, str().substr(dirEnd, get_pos())); if (r.first == r.second) @@ -71,7 +98,10 @@ PathInput::receive_do_complete() { set_pos(dirEnd + base.size()); mark_dirty(); - m_signalShowRange.emit(r.first, r.second); + + // Only emit if there are more than one option. + if (++utils::Directory::iterator(r.first) != r.second) + m_signalShowRange.emit(r.first, r.second); } PathInput::size_type diff --git a/src/input/path_input.h b/src/input/path_input.h index e009aa6c..2d777534 100644 --- a/src/input/path_input.h +++ b/src/input/path_input.h @@ -34,12 +34,14 @@ namespace input { class PathInput : public TextInput { public: typedef std::pair Range; + typedef sigc::signal0 Signal; typedef sigc::signal2 SignalShowRange; PathInput(); virtual ~PathInput() {} - SignalShowRange& signal_show_range() { return m_signalShowRange; } + Signal& signal_show_next() { return m_signalShowNext; } + SignalShowRange& signal_show_range() { return m_signalShowRange; } virtual bool pressed(int key); @@ -49,6 +51,9 @@ private: size_type find_last_delim(); Range find_incomplete(utils::Directory& d, const std::string& f); + bool m_showNext; + + Signal m_signalShowNext; SignalShowRange m_signalShowRange; }; diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 38cb2ea2..b62d6535 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -302,6 +302,10 @@ DownloadList::setup_input() { m_windowTextInput = new WInput(p); p->slot_dirty(sigc::mem_fun(*m_windowTextInput, &WInput::mark_dirty)); + + p->signal_show_next().connect(sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change), DISPLAY_STRING_LIST)); + p->signal_show_next().connect(sigc::mem_fun(*esl, &ElementStringList::next_screen)); + p->signal_show_range().connect(sigc::hide(sigc::hide(sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change), DISPLAY_STRING_LIST)))); p->signal_show_range().connect(sigc::mem_fun(*esl, &ElementStringList::set_range)); diff --git a/src/ui/element_string_list.cc b/src/ui/element_string_list.cc index e5641e55..6297159c 100644 --- a/src/ui/element_string_list.cc +++ b/src/ui/element_string_list.cc @@ -57,4 +57,14 @@ ElementStringList::disable(Control* c) { m_window = NULL; } +void +ElementStringList::next_screen() { + if (m_window->get_draw_end() != m_list.end()) + m_window->set_range(m_window->get_draw_end(), m_list.end()); + else + m_window->set_range(m_list.begin(), m_list.end()); + + m_window->mark_dirty(); +} + } diff --git a/src/ui/element_string_list.h b/src/ui/element_string_list.h index 77d9ca90..00fd0ef2 100644 --- a/src/ui/element_string_list.h +++ b/src/ui/element_string_list.h @@ -57,6 +57,8 @@ public: m_window->mark_dirty(); } + void next_screen(); + private: WStringList* m_window; List m_list; diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 9a0f9884..4b331975 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -3,6 +3,8 @@ noinst_LIBRARIES = libsub_utils.a libsub_utils_a_SOURCES = \ directory.cc \ directory.h \ + file_stat.cc \ + file_stat.h \ list_focus.h \ parse.cc \ parse.h \ diff --git a/src/utils/file_stat.cc b/src/utils/file_stat.cc new file mode 100644 index 00000000..2719e606 --- /dev/null +++ b/src/utils/file_stat.cc @@ -0,0 +1,70 @@ +// rTorrent - BitTorrent client +// Copyright (C) 2005, Jari Sundell +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Contact: Jari Sundell +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#include "config.h" + +#include + +#include "file_stat.h" + +namespace utils { + +void +FileStat::update_throws(int fd) { + int r = update(fd); + + if (r < 0) + throw std::runtime_error(error_string(r)); +} + +void +FileStat::update_throws(const char* filename) { + int r = update(filename); + + if (r < 0) + throw std::runtime_error(error_string(r)); +} + +std::string +FileStat::error_string(int err) { + switch (err) { + case 0: + return "Success"; + + case EBADF: + return "Bad file descriptor"; + + case ENOENT: + return "Filename does not exist"; + + case ENOTDIR: + return "Path not a directory"; + + case EACCES: + return "Permission denied"; + + default: + return "Unknown error"; + } +} + +} diff --git a/src/utils/file_stat.h b/src/utils/file_stat.h new file mode 100644 index 00000000..2a80b819 --- /dev/null +++ b/src/utils/file_stat.h @@ -0,0 +1,66 @@ +// libTorrent - BitTorrent library +// Copyright (C) 2005, Jari Sundell +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Contact: Jari Sundell +// +// Skomakerveien 33 +// 3185 Skoppum, NORWAY + +#ifndef RTORRENT_UTILS_FILE_STAT_H +#define RTORRENT_UTILS_FILE_STAT_H + +#include +#include +#include + +namespace utils { + +class FileStat { +public: + FileStat() {} + FileStat(const char* filename) { update_throws(filename); } + explicit FileStat(int fd) { update_throws(fd); } + + int update(int fd) { return fstat(fd, &m_stat); } + int update(const char* filename) { return stat(filename, &m_stat); } + + void update_throws(int fd); + void update_throws(const char* filename); + + bool is_regular() const { return S_ISREG(m_stat.st_mode); } + bool is_directory() const { return S_ISDIR(m_stat.st_mode); } + bool is_character() const { return S_ISCHR(m_stat.st_mode); } + bool is_block() const { return S_ISBLK(m_stat.st_mode); } + bool is_fifo() const { return S_ISFIFO(m_stat.st_mode); } + bool is_link() const { return S_ISLNK(m_stat.st_mode); } + bool is_sockt() const { return S_ISSOCK(m_stat.st_mode); } + + off_t get_size() const { return m_stat.st_size; } + + time_t get_atime() const { return m_stat.st_atime; } + time_t get_ctime() const { return m_stat.st_ctime; } + time_t get_mtime() const { return m_stat.st_mtime; } + + static std::string error_string(int err); + +private: + struct stat m_stat; +}; + +} + +#endif