diff --git a/src/display/Makefile.am b/src/display/Makefile.am index d69a5276..1dbe7c1f 100644 --- a/src/display/Makefile.am +++ b/src/display/Makefile.am @@ -29,6 +29,8 @@ libsub_display_a_SOURCES = \ window_peer_list.h \ window_statusbar.cc \ window_statusbar.h \ + window_string_list.cc \ + window_string_list.h \ window_title.cc \ window_title.h \ window_tracker_list.cc \ diff --git a/src/display/window_string_list.cc b/src/display/window_string_list.cc new file mode 100644 index 00000000..d98b2e4e --- /dev/null +++ b/src/display/window_string_list.cc @@ -0,0 +1,67 @@ +// 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 "canvas.h" +#include "utils.h" +#include "window_string_list.h" + +namespace display { + +WindowStringList::WindowStringList() : + Window(new Canvas, true) { +} + +WindowStringList::~WindowStringList() { +} + +void +WindowStringList::redraw() { + m_nextDraw = utils::Timer::max(); + + m_canvas->erase(); + + size_t ypos = 0; + size_t xpos = 1; + size_t width = 0; + + for (iterator itr = m_first; itr != m_last; ++itr) { + + if (ypos == (size_t)m_canvas->get_height()) { + ypos = 0; + xpos += width + 2; + + if (xpos >= (size_t)m_canvas->get_width()) + break; + } + + width = std::max(itr->size(), width); + + if (xpos + itr->size() <= (size_t)m_canvas->get_width()) + 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()); + } +} + +} diff --git a/src/display/window_string_list.h b/src/display/window_string_list.h new file mode 100644 index 00000000..d3feff06 --- /dev/null +++ b/src/display/window_string_list.h @@ -0,0 +1,51 @@ +// 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 + +#ifndef RTORRENT_DISPLAY_WINDOW_STRING_LIST_H +#define RTORRENT_DISPLAY_WINDOW_STRING_LIST_H + +#include +#include + +#include "window.h" + +namespace display { + +class WindowStringList : public Window { +public: + typedef std::list::iterator iterator; + + WindowStringList(); + ~WindowStringList(); + + void set_range(iterator first, iterator last) { m_first = first; m_last = last; } + + virtual void redraw(); + +private: + iterator m_first; + iterator m_last; +}; + +} + +#endif diff --git a/src/input/path_input.cc b/src/input/path_input.cc index 5076697b..4719c913 100644 --- a/src/input/path_input.cc +++ b/src/input/path_input.cc @@ -71,6 +71,7 @@ PathInput::receive_do_complete() { set_pos(dirEnd + base.size()); mark_dirty(); + 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 8075a213..e009aa6c 100644 --- a/src/input/path_input.h +++ b/src/input/path_input.h @@ -23,6 +23,8 @@ #ifndef RTORRENT_INPUT_PATH_INPUT_H #define RTORRENT_INPUT_PATH_INPUT_H +#include + #include "utils/directory.h" #include "text_input.h" @@ -31,11 +33,14 @@ namespace input { class PathInput : public TextInput { public: - typedef std::pair Range; + typedef std::pair Range; + typedef sigc::signal2 SignalShowRange; PathInput(); virtual ~PathInput() {} + SignalShowRange& signal_show_range() { return m_signalShowRange; } + virtual bool pressed(int key); private: @@ -43,6 +48,8 @@ private: size_type find_last_delim(); Range find_incomplete(utils::Directory& d, const std::string& f); + + SignalShowRange m_signalShowRange; }; } diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 4390be3b..00863520 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -17,6 +17,8 @@ libsub_ui_a_SOURCES = \ element_peer_info.h \ element_peer_list.cc \ element_peer_list.h \ + element_string_list.cc \ + element_string_list.h \ element_tracker_list.cc \ element_tracker_list.h \ root.cc \ diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index fc89957f..38cb2ea2 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "core/download.h" @@ -43,6 +44,7 @@ #include "download_list.h" #include "element_download_list.h" #include "element_log_complete.h" +#include "element_string_list.h" namespace ui { @@ -53,7 +55,6 @@ DownloadList::DownloadList(Control* c) : m_windowTitle(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))), m_windowStatus(new WStatus(&c->get_core())), - m_windowTextInput(new WInput(new input::PathInput)), m_windowHttpQueue(new WHttp(&c->get_core().get_http_queue())), m_taskUpdate(sigc::mem_fun(*this, &DownloadList::task_update)), @@ -69,9 +70,8 @@ DownloadList::DownloadList(Control* c) : m_windowLog = new WLog(&m_control->get_core().get_log_important()); - bind_keys(); - - m_windowTextInput->get_input()->slot_dirty(sigc::mem_fun(*m_windowTextInput, &WInput::mark_dirty)); + setup_keys(); + setup_input(); } DownloadList::~DownloadList() { @@ -242,7 +242,6 @@ void DownloadList::receive_exit_input() { m_windowStatus->set_active(true); m_windowTextInput->set_active(false); - m_control->get_display().adjust_layout(); m_control->get_input().set_text_input(); @@ -253,6 +252,8 @@ DownloadList::receive_exit_input() { m_bindings->erase('\n'); m_bindings->erase(KEY_ENTER); + + receive_change(DISPLAY_DOWNLOAD_LIST); } void @@ -272,7 +273,7 @@ DownloadList::task_update() { } void -DownloadList::bind_keys() { +DownloadList::setup_keys() { (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 1); (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -1); (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 5); @@ -294,4 +295,17 @@ DownloadList::bind_keys() { m_uiArray[DISPLAY_LOG]->get_bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change), DISPLAY_DOWNLOAD_LIST); } +void +DownloadList::setup_input() { + input::PathInput* p = new input::PathInput; + ElementStringList* esl = new ElementStringList(); + m_windowTextInput = new WInput(p); + + p->slot_dirty(sigc::mem_fun(*m_windowTextInput, &WInput::mark_dirty)); + 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)); + + m_uiArray[DISPLAY_STRING_LIST] = esl; +} + } diff --git a/src/ui/download_list.h b/src/ui/download_list.h index 722c7d00..a570d784 100644 --- a/src/ui/download_list.h +++ b/src/ui/download_list.h @@ -68,6 +68,7 @@ public: typedef enum { DISPLAY_DOWNLOAD_LIST, DISPLAY_LOG, + DISPLAY_STRING_LIST, DISPLAY_MAX_SIZE } Display; @@ -105,7 +106,9 @@ private: void receive_change(Display d); void task_update(); - void bind_keys(); + + void setup_keys(); + void setup_input(); Display m_state; diff --git a/src/ui/element_string_list.cc b/src/ui/element_string_list.cc new file mode 100644 index 00000000..e5641e55 --- /dev/null +++ b/src/ui/element_string_list.cc @@ -0,0 +1,60 @@ +// 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 "control.h" +#include "element_string_list.h" + +namespace ui { + +ElementStringList::ElementStringList() { + m_list.push_back("Test string 1"); + m_list.push_back("Test string 2"); +} + +void +ElementStringList::activate(Control* c, MItr mItr) { + if (m_window != NULL) + throw std::logic_error("ui::ElementStringList::activate(...) called on an object in the wrong state"); + + c->get_input().push_front(&m_bindings); + + *mItr = m_window = new WStringList(); + + m_window->set_range(m_list.begin(), m_list.end()); +} + +void +ElementStringList::disable(Control* c) { + if (m_window == NULL) + throw std::logic_error("ui::ElementStringList::disable(...) called on an object in the wrong state"); + + c->get_input().erase(&m_bindings); + + delete m_window; + m_window = NULL; +} + +} diff --git a/src/ui/element_string_list.h b/src/ui/element_string_list.h new file mode 100644 index 00000000..77d9ca90 --- /dev/null +++ b/src/ui/element_string_list.h @@ -0,0 +1,67 @@ +// 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 + +#ifndef RTORRENT_UI_ELEMENT_STRING_LIST_H +#define RTORRENT_UI_ELEMENT_STRING_LIST_H + +#include +#include +#include +#include + +#include "element_base.h" + +#include "display/window_string_list.h" + +namespace ui { + +class Control; + +class ElementStringList : public ElementBase { +public: + typedef display::WindowStringList WStringList; + typedef std::list List; + + ElementStringList(); + + void activate(Control* c, MItr mItr); + void disable(Control* c); + + template + void set_range(InputIter first, InputIter last) { + m_list.clear(); + + while (first != last) + m_list.push_back(*(first++)); + + m_window->set_range(m_list.begin(), m_list.end()); + m_window->mark_dirty(); + } + +private: + WStringList* m_window; + List m_list; +}; + +} + +#endif