Made log complete an element.

git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@360 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-03-17 23:16:43 +00:00
parent 73fb55ae42
commit 2eb534e423
11 changed files with 350 additions and 112 deletions
+2
View File
@@ -11,6 +11,8 @@ libsub_ui_a_SOURCES = \
element_download_list.h \ element_download_list.h \
element_file_list.cc \ element_file_list.cc \
element_file_list.h \ element_file_list.h \
element_log_complete.cc \
element_log_complete.h \
element_peer_info.cc \ element_peer_info.cc \
element_peer_info.h \ element_peer_info.h \
element_peer_list.cc \ element_peer_list.cc \
+1 -2
View File
@@ -91,7 +91,7 @@ Download::activate() {
if (m_window != m_control->get_display().end()) if (m_window != m_control->get_display().end())
throw std::logic_error("ui::Download::activate() called on an already activated object"); throw std::logic_error("ui::Download::activate() called on an already activated object");
m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL); m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL);
m_control->get_display().insert(m_control->get_display().begin(), m_windowTitle); m_control->get_display().insert(m_control->get_display().begin(), m_windowTitle);
m_control->get_display().insert(m_control->get_display().end(), m_windowDownloadStatus); m_control->get_display().insert(m_control->get_display().end(), m_windowDownloadStatus);
@@ -214,7 +214,6 @@ Download::receive_change(Display d) {
return; return;
disable_display(); disable_display();
activate_display(d); activate_display(d);
} }
+2 -1
View File
@@ -27,6 +27,8 @@
#include <torrent/peer.h> #include <torrent/peer.h>
#include <sigc++/connection.h> #include <sigc++/connection.h>
#include "utils/list_focus.h"
namespace display { namespace display {
class WindowTitle; class WindowTitle;
class WindowStatusbar; class WindowStatusbar;
@@ -60,7 +62,6 @@ public:
DISPLAY_MAX_SIZE DISPLAY_MAX_SIZE
} Display; } Display;
// We own 'window'.
Download(DPtr d, Control* c); Download(DPtr d, Control* c);
~Download(); ~Download();
+80 -59
View File
@@ -23,29 +23,34 @@
#include "config.h" #include "config.h"
#include <stdexcept> #include <stdexcept>
#include <torrent/torrent.h> #include <rak/functional.h>
#include <sigc++/bind.h> #include <sigc++/bind.h>
#include <torrent/torrent.h>
#include "core/download.h" #include "core/download.h"
#include "input/bindings.h" #include "input/bindings.h"
#include "input/path_input.h" #include "input/path_input.h"
#include "display/window_download_list.h"
#include "display/window_http_queue.h" #include "display/window_http_queue.h"
#include "display/window_input.h" #include "display/window_input.h"
#include "display/window_log.h" #include "display/window_log.h"
#include "display/window_log_complete.h"
#include "display/window_statusbar.h" #include "display/window_statusbar.h"
#include "display/window_title.h" #include "display/window_title.h"
#include "control.h" #include "control.h"
#include "download.h" #include "download.h"
#include "download_list.h" #include "download_list.h"
#include "element_download_list.h"
#include "element_log_complete.h"
namespace ui { namespace ui {
DownloadList::DownloadList(Control* c) : DownloadList::DownloadList(Control* c) :
m_state(DISPLAY_MAX_SIZE),
m_window(c->get_display().end()),
m_windowTitle(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))), m_windowTitle(new WTitle("rtorrent " VERSION " - " + torrent::get(torrent::LIBRARY_NAME))),
m_windowStatus(new WStatus(&c->get_core())), m_windowStatus(new WStatus(&c->get_core())),
m_windowTextInput(new WInput(new input::PathInput)), m_windowTextInput(new WInput(new input::PathInput)),
@@ -57,17 +62,19 @@ DownloadList::DownloadList(Control* c) :
m_control(c), m_control(c),
m_bindings(new input::Bindings) { m_bindings(new input::Bindings) {
m_windowDownloadList = new WList(&m_control->get_core().get_download_list(), &m_focus); m_uiArray[DISPLAY_DOWNLOAD_LIST] = new ElementDownloadList(&m_control->get_core().get_download_list(), &m_focus);
m_windowLog = new WLog(&m_control->get_core().get_log_important()); m_uiArray[DISPLAY_LOG] = new ElementLogComplete(&m_control->get_core().get_log_complete());
m_windowLogComplete = NULL;
bind_keys(m_bindings); 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)); m_windowTextInput->get_input()->slot_dirty(sigc::mem_fun(*m_windowTextInput, &WInput::mark_dirty));
} }
DownloadList::~DownloadList() { DownloadList::~DownloadList() {
delete m_windowDownloadList; std::for_each(m_uiArray, m_uiArray + DISPLAY_MAX_SIZE, rak::call_delete<ElementBase>());
delete m_windowTitle; delete m_windowTitle;
delete m_windowStatus; delete m_windowStatus;
delete m_bindings; delete m_bindings;
@@ -80,22 +87,33 @@ DownloadList::~DownloadList() {
void void
DownloadList::activate() { DownloadList::activate() {
if (m_window != m_control->get_display().end())
throw std::logic_error("ui::Download::activate() called on an already activated object");
m_taskUpdate.insert(utils::Timer::cache() + 1000000); m_taskUpdate.insert(utils::Timer::cache() + 1000000);
m_windowTextInput->set_active(false); m_windowTextInput->set_active(false);
m_control->get_input().push_front(m_bindings); m_window = m_control->get_display().insert(m_control->get_display().begin(), NULL);
m_control->get_display().push_front(m_windowTitle);
m_control->get_display().push_back(m_windowLog); m_control->get_display().push_back(m_windowLog);
m_control->get_display().push_back(m_windowHttpQueue); m_control->get_display().push_back(m_windowHttpQueue);
m_control->get_display().push_back(m_windowTextInput); m_control->get_display().push_back(m_windowTextInput);
m_control->get_display().push_back(m_windowStatus); m_control->get_display().push_back(m_windowStatus);
m_control->get_display().push_front(m_windowDownloadList);
m_control->get_display().push_front(m_windowTitle); m_control->get_input().push_front(m_bindings);
activate_display(DISPLAY_DOWNLOAD_LIST);
} }
void void
DownloadList::disable() { DownloadList::disable() {
if (m_window == m_control->get_display().end())
throw std::logic_error("ui::Download::disable() called on an already disabled object");
disable_display();
m_taskUpdate.remove(); m_taskUpdate.remove();
if (m_windowTextInput->is_active()) { if (m_windowTextInput->is_active()) {
@@ -103,17 +121,39 @@ DownloadList::disable() {
receive_exit_input(); receive_exit_input();
} }
if (m_windowLogComplete != NULL) m_control->get_display().erase(m_window);
receive_toggle_log();
m_control->get_input().erase(m_bindings);
m_control->get_display().erase(m_windowTitle); m_control->get_display().erase(m_windowTitle);
m_control->get_display().erase(m_windowDownloadList);
m_control->get_display().erase(m_windowStatus); m_control->get_display().erase(m_windowStatus);
m_control->get_display().erase(m_windowTextInput); m_control->get_display().erase(m_windowTextInput);
m_control->get_display().erase(m_windowLog); m_control->get_display().erase(m_windowLog);
m_control->get_display().erase(m_windowHttpQueue); m_control->get_display().erase(m_windowHttpQueue);
m_window = m_control->get_display().end();
m_control->get_input().erase(m_bindings);
}
void
DownloadList::activate_display(Display d) {
if (m_window == m_control->get_display().end())
throw std::logic_error("ui::DownloadList::activate_display(...) could not find previous display iterator");
if (d >= DISPLAY_MAX_SIZE)
throw std::logic_error("ui::DownloadList::activate_display(...) out of bounds");
m_state = d;
m_uiArray[d]->activate(m_control, m_window);
m_control->get_display().adjust_layout();
}
// Does not delete disabled window.
void
DownloadList::disable_display() {
m_uiArray[m_state]->disable(m_control);
m_state = DISPLAY_MAX_SIZE;
*m_window = NULL;
} }
void void
@@ -123,7 +163,7 @@ DownloadList::receive_next() {
else else
m_focus = m_control->get_core().get_download_list().begin(); m_focus = m_control->get_core().get_download_list().begin();
mark_dirty(); //mark_dirty();
} }
void void
@@ -133,7 +173,7 @@ DownloadList::receive_prev() {
else else
m_focus = m_control->get_core().get_download_list().end(); m_focus = m_control->get_core().get_download_list().end();
mark_dirty(); //mark_dirty();
} }
void void
@@ -224,28 +264,12 @@ DownloadList::receive_exit_input() {
} }
void void
DownloadList::receive_toggle_log() { DownloadList::receive_change(Display d) {
if (m_windowLogComplete == NULL) { if (d == m_state)
display::Manager::iterator itr = m_control->get_display().find(m_windowDownloadList); return;
if (itr == m_control->get_display().end()) disable_display();
throw std::logic_error("ui::DownloadList::receive_toggle_log() could not find download list"); activate_display(d);
*itr = m_windowLogComplete = new WLogComplete(&m_control->get_core().get_log_complete());
} else {
display::Manager::iterator itr = m_control->get_display().find(m_windowLogComplete);
if (itr == m_control->get_display().end())
throw std::logic_error("ui::DownloadList::receive_toggle_log() could not find download list");
*itr = m_windowDownloadList;
delete m_windowLogComplete;
m_windowLogComplete = NULL;
}
m_control->get_display().adjust_layout();
} }
void void
@@ -256,29 +280,26 @@ DownloadList::task_update() {
} }
void void
DownloadList::bind_keys(input::Bindings* b) { DownloadList::bind_keys() {
(*b)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 1); (*m_bindings)['a'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 1);
(*b)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -1); (*m_bindings)['z'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -1);
(*b)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 5); (*m_bindings)['s'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 5);
(*b)['x'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -5); (*m_bindings)['x'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -5);
(*b)['d'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 50); (*m_bindings)['d'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), 50);
(*b)['c'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -50); (*m_bindings)['c'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_throttle), -50);
(*b)['\x13'] = sigc::mem_fun(*this, &DownloadList::receive_start_download); (*m_bindings)['\x13'] = sigc::mem_fun(*this, &DownloadList::receive_start_download);
(*b)['\x04'] = sigc::mem_fun(*this, &DownloadList::receive_stop_download); (*m_bindings)['\x04'] = sigc::mem_fun(*this, &DownloadList::receive_stop_download);
(*b)[KEY_UP] = sigc::mem_fun(*this, &DownloadList::receive_prev); (*m_bindings)['\x7f'] = sigc::mem_fun(*this, &DownloadList::receive_view_input);
(*b)[KEY_DOWN] = sigc::mem_fun(*this, &DownloadList::receive_next); (*m_bindings)[KEY_BACKSPACE] = sigc::mem_fun(*this, &DownloadList::receive_view_input);
(*b)[KEY_RIGHT] = sigc::mem_fun(*this, &DownloadList::receive_view_download);
(*b)['l'] = sigc::mem_fun(*this, &DownloadList::receive_toggle_log);
(*b)['\x7f'] = sigc::mem_fun(*this, &DownloadList::receive_view_input); (*m_bindings)[KEY_UP] = sigc::mem_fun(*this, &DownloadList::receive_prev);
(*b)[KEY_BACKSPACE] = sigc::mem_fun(*this, &DownloadList::receive_view_input); (*m_bindings)[KEY_DOWN] = sigc::mem_fun(*this, &DownloadList::receive_next);
} (*m_bindings)[KEY_RIGHT] = sigc::mem_fun(*this, &DownloadList::receive_view_download);
(*m_bindings)['l'] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change), DISPLAY_LOG);
void m_uiArray[DISPLAY_LOG]->get_bindings()[' '] = sigc::bind(sigc::mem_fun(*this, &DownloadList::receive_change), DISPLAY_DOWNLOAD_LIST);
DownloadList::mark_dirty() {
m_windowDownloadList->mark_dirty();
} }
} }
+52 -42
View File
@@ -46,79 +46,89 @@ namespace ui {
class Control; class Control;
class Download; class Download;
class ElementBase;
class DownloadList { class DownloadList {
public: public:
typedef display::WindowDownloadList WList; typedef display::WindowDownloadList WList;
typedef display::WindowHttpQueue WHttp; typedef display::WindowHttpQueue WHttp;
typedef display::WindowInput WInput; typedef display::WindowInput WInput;
typedef display::WindowLog WLog; typedef display::WindowLog WLog;
typedef display::WindowLogComplete WLogComplete; typedef display::WindowLogComplete WLogComplete;
typedef display::WindowStatusbar WStatus; typedef display::WindowStatusbar WStatus;
typedef display::WindowTitle WTitle; typedef display::WindowTitle WTitle;
typedef core::DownloadList DList; typedef core::DownloadList DList;
typedef sigc::slot1<void, const std::string&> SlotOpenUri; typedef sigc::slot1<void, const std::string&> SlotOpenUri;
typedef display::Manager::iterator MItr;
typedef enum {
DISPLAY_DOWNLOAD_LIST,
DISPLAY_LOG,
DISPLAY_MAX_SIZE
} Display;
// We own 'window'.
DownloadList(Control* c); DownloadList(Control* c);
~DownloadList(); ~DownloadList();
WList& get_window_download_list() { return *m_windowDownloadList; } input::Bindings& get_bindings() { return *m_bindings; }
input::Bindings& get_bindings() { return *m_bindings; }
void activate(); void activate();
void disable(); void disable();
void slot_open_uri(SlotOpenUri s) { m_slotOpenUri = s; } void activate_display(Display d);
void disable_display();
void slot_open_uri(SlotOpenUri s) { m_slotOpenUri = s; }
private: private:
DownloadList(const DownloadList&); DownloadList(const DownloadList&);
void operator = (const DownloadList&); void operator = (const DownloadList&);
void receive_next(); void receive_next();
void receive_prev(); void receive_prev();
void receive_throttle(int t); void receive_throttle(int t);
void receive_start_download(); void receive_start_download();
void receive_stop_download(); void receive_stop_download();
void receive_view_download(); void receive_view_download();
void receive_exit_download(); void receive_exit_download();
void receive_view_input(); void receive_view_input();
void receive_exit_input(); void receive_exit_input();
void receive_toggle_log(); void receive_change(Display d);
void task_update(); void task_update();
void bind_keys();
void bind_keys(input::Bindings* b); Display m_state;
void mark_dirty(); ElementBase* m_uiArray[DISPLAY_MAX_SIZE];
WList* m_windowDownloadList; MItr m_window;
WTitle* m_windowTitle;
WStatus* m_windowStatus;
WLog* m_windowLog;
WInput* m_windowTextInput;
WHttp* m_windowHttpQueue;
WLogComplete* m_windowLogComplete; WTitle* m_windowTitle;
WStatus* m_windowStatus;
WLog* m_windowLog;
WInput* m_windowTextInput;
WHttp* m_windowHttpQueue;
utils::Task m_taskUpdate; utils::Task m_taskUpdate;
Download* m_uiDownload; Download* m_uiDownload;
DList* m_list; DList* m_list;
DList::iterator m_focus; DList::iterator m_focus;
Control* m_control; Control* m_control;
input::Bindings* m_bindings; input::Bindings* m_bindings;
SlotOpenUri m_slotOpenUri; SlotOpenUri m_slotOpenUri;
}; };
} }
+6 -6
View File
@@ -24,7 +24,7 @@
#include <stdexcept> #include <stdexcept>
#include "display/window_peer_list.h" #include "display/window_download_list.h"
#include "control.h" #include "control.h"
#include "element_download_list.h" #include "element_download_list.h"
@@ -43,9 +43,9 @@ ElementDownloadList::activate(Control* c, MItr mItr) {
if (m_window != NULL) if (m_window != NULL)
throw std::logic_error("ui::ElementDownloadList::activate(...) called on an object in the wrong state"); throw std::logic_error("ui::ElementDownloadList::activate(...) called on an object in the wrong state");
// c->get_input().push_front(&m_bindings); c->get_input().push_front(&m_bindings);
// *mItr = m_window = new WDownloadList(m_download, m_list, m_focus); *mItr = m_window = new WDownloadList(m_list, m_focus);
} }
void void
@@ -53,10 +53,10 @@ ElementDownloadList::disable(Control* c) {
if (m_window == NULL) if (m_window == NULL)
throw std::logic_error("ui::ElementDownloadList::disable(...) called on an object in the wrong state"); throw std::logic_error("ui::ElementDownloadList::disable(...) called on an object in the wrong state");
// c->get_input().erase(&m_bindings); c->get_input().erase(&m_bindings);
// delete m_window; delete m_window;
// m_window = NULL; m_window = NULL;
} }
} }
+61
View File
@@ -0,0 +1,61 @@
// 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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <stdexcept>
#include "display/window_log_complete.h"
#include "control.h"
#include "element_log_complete.h"
namespace ui {
ElementLogComplete::ElementLogComplete(core::Log* l) :
m_window(NULL),
m_log(l) {
}
void
ElementLogComplete::activate(Control* c, MItr mItr) {
if (m_window != NULL)
throw std::logic_error("ui::ElementLogComplete::activate(...) called on an object in the wrong state");
c->get_input().push_front(&m_bindings);
*mItr = m_window = new WLogComplete(m_log);
}
void
ElementLogComplete::disable(Control* c) {
if (m_window == NULL)
throw std::logic_error("ui::ElementLogComplete::disable(...) called on an object in the wrong state");
c->get_input().erase(&m_bindings);
delete m_window;
m_window = NULL;
}
}
+55
View File
@@ -0,0 +1,55 @@
// 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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_UI_ELEMENT_LOG_COMPLETE_H
#define RTORRENT_UI_ELEMENT_LOG_COMPLETE_H
#include "core/log.h"
#include "element_base.h"
namespace display {
class WindowLogComplete;
}
namespace ui {
class Control;
class ElementLogComplete : public ElementBase {
public:
typedef display::WindowLogComplete WLogComplete;
ElementLogComplete(core::Log* l);
void activate(Control* c, MItr mItr);
void disable(Control* c);
private:
WLogComplete* m_window;
core::Log* m_log;
};
}
#endif
+1
View File
@@ -3,6 +3,7 @@ noinst_LIBRARIES = libsub_utils.a
libsub_utils_a_SOURCES = \ libsub_utils_a_SOURCES = \
directory.cc \ directory.cc \
directory.h \ directory.h \
list_focus.h \
parse.cc \ parse.cc \
parse.h \ parse.h \
task.h \ task.h \
+88
View File
@@ -0,0 +1,88 @@
// 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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_UTILS_LIST_FOCUS_H
#define RTORRENT_UTILS_LIST_FOCUS_H
#include <sigc++/signal.h>
namespace utils {
template <typename Base>
class ListFocus : private Base {
public:
using Base::iterator;
using Base::const_iterator;
using Base::reverse_iterator;
using Base::const_reverse_iterator;
using Base::value_type;
using Base::begin;
using Base::end;
using Base::rbegin;
using Base::rend;
using Base::insert;
using Base::push_back;
using Base::push_front;
ListFocus() : m_focus(end()) {}
// Don't do erase on this object.
Base& get_list() { return m_list; }
typename iterator& get_focus() { return m_focus; }
typename iterator erase(typename iterator itr);
void remove(typename const value_type& v);
// Be careful with copying signals.
private:
typename iterator m_focus;
};
template <typename Base>
typename ListFocus<Base>::iterator
ListFocus<Base>::erase(typename iterator itr) {
if (itr == m_focus)
return m_focus = Base::erase(itr);
else
return Base::erase(itr);
}
template <typename Base>
void
ListFocus<Base>::remove(typename const value_type& v) {
typename iterator first = begin();
typename iterator last = end();
while (first != last)
if (*first == v)
first = erase(first);
else
++first;
}
}
#endif
+2 -2
View File
@@ -20,8 +20,8 @@
// Skomakerveien 33 // Skomakerveien 33
// 3185 Skoppum, NORWAY // 3185 Skoppum, NORWAY
#ifndef LIBTORRENT_TIMER_H #ifndef RTORRENT_UTILS_TIMER_H
#define LIBTORRENT_TIMER_H #define RTORRENT_UTILS_TIMER_H
#include <limits> #include <limits>
#include <inttypes.h> #include <inttypes.h>