* Added various TextElement flags and replaced WindowPeerInfo with a

WindowText.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@756 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-08-12 18:35:19 +00:00
parent da0d5dbf22
commit 34258bcfb2
22 changed files with 402 additions and 319 deletions
+18 -31
View File
@@ -50,8 +50,7 @@
#include "display/window_title.h"
#include "display/window_download_statusbar.h"
#include "display/text_element_string.h"
#include "display/text_element_value.h"
#include "display/text_element_helpers.h"
#include "control.h"
#include "download.h"
@@ -132,50 +131,38 @@ Download::create_menu() {
inline ElementBase*
Download::create_info() {
using namespace display::helpers;
ElementText* element = new ElementText(m_download);
element->set_column(1);
// Get these bindings with some kind of string map.
element->push_column("Name:", display::text_element_string_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::name))));
element->push_column("Local id:", display::text_element_string_slot(std::mem_fun(&core::Download::local_id_escaped)));
element->push_column("Info hash:", display::text_element_string_slot(std::mem_fun(&core::Download::info_hash_hex)));
element->push_column("Created:",
display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::creation_date)),
display::TextElementValueBase::flag_date), " ",
display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::creation_date)),
display::TextElementValueBase::flag_time));
element->push_column("Name:", te_string(&torrent::Download::name));
element->push_column("Local id:", te_string(&torrent::Download::local_id, string_base::flag_escape_html));
element->push_column("Info hash:", te_string(&torrent::Download::info_hash, string_base::flag_escape_hex));
element->push_column("Created:", te_value(&torrent::Download::creation_date, value_base::flag_date), " ", te_value(&torrent::Download::creation_date, value_base::flag_time));
element->push_back("");
element->push_column("Directory:", display::text_element_string_slot(rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(&torrent::FileList::root_dir))));
element->push_column("Tied to file:", display::text_element_string_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_string), "tied_to_file")));
element->push_column("Directory:", te_string(&torrent::FileList::root_dir));
element->push_column("Tied to file:", te_variable_string("tied_to_file"));
element->push_back("");
element->push_column("Chunks:",
display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::chunks_done))), " / ",
display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::chunks_total))), " * ",
display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::chunks_size))));
element->push_column("Priority:", display::text_element_value_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_value), "priority")));
element->push_column("Chunks:", te_value(&torrent::Download::chunks_done), " / ", te_value(&torrent::Download::chunks_total), " * ", te_value(&torrent::Download::chunks_size));
element->push_column("Priority:", te_variable_value("priority"));
element->push_column("State changed:", display::text_element_value_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_value), "state_changed"),
display::TextElementValueBase::flag_timer | display::TextElementValueBase::flag_elapsed));
element->push_column("State changed:", te_variable_value("state_changed", value_base::flag_timer | value_base::flag_elapsed));
element->push_back("");
element->push_column("Memory usage:", display::text_element_value_void(rak::make_mem_fun(torrent::chunk_manager(), &torrent::ChunkManager::memory_usage),
display::TextElementValueBase::flag_mb), " MB");
element->push_column("Max memory usage:", display::text_element_value_void(rak::make_mem_fun(torrent::chunk_manager(), &torrent::ChunkManager::max_memory_usage),
display::TextElementValueBase::flag_mb), " MB");
element->push_column("Free diskspace:", display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(&torrent::Download::free_diskspace)),
display::TextElementValueBase::flag_mb), " MB");
element->push_column("Safe diskspace:", display::text_element_value_void(rak::make_mem_fun(torrent::chunk_manager(), &torrent::ChunkManager::safe_free_diskspace),
display::TextElementValueBase::flag_mb), " MB");
element->push_column("Memory usage:", te_value(&torrent::ChunkManager::memory_usage, value_base::flag_mb), " MB");
element->push_column("Max memory usage:", te_value(&torrent::ChunkManager::max_memory_usage, value_base::flag_mb), " MB");
element->push_column("Free diskspace:", te_value(&torrent::Download::free_diskspace, value_base::flag_mb), " MB");
element->push_column("Safe diskspace:", te_value(&torrent::ChunkManager::safe_free_diskspace, value_base::flag_mb), " MB");
element->push_back("");
element->push_column("Send buffer:", display::text_element_value_void(rak::make_mem_fun(torrent::connection_manager(), &torrent::ConnectionManager::send_buffer_size),
display::TextElementValueBase::flag_kb), " KB");
element->push_column("Receive buffer:", display::text_element_value_void(rak::make_mem_fun(torrent::connection_manager(), &torrent::ConnectionManager::receive_buffer_size),
display::TextElementValueBase::flag_kb), " KB");
element->push_column("Send buffer:", te_value(&torrent::ConnectionManager::send_buffer_size, value_base::flag_kb), " KB");
element->push_column("Receive buffer:", te_value(&torrent::ConnectionManager::receive_buffer_size, value_base::flag_kb), " KB");
element->set_column_width(element->column_width() + 1);
+66 -22
View File
@@ -38,15 +38,18 @@
#include <sigc++/bind.h>
#include <torrent/exceptions.h>
#include <torrent/rate.h>
#include "display/client_info.h"
#include "display/frame.h"
#include "display/manager.h"
#include "display/window_peer_info.h"
#include "display/text_element_helpers.h"
#include "display/window_peer_list.h"
#include "input/manager.h"
#include "control.h"
#include "element_peer_list.h"
#include "element_text.h"
namespace ui {
@@ -61,16 +64,60 @@ ElementPeerList::ElementPeerList(core::Download* d) :
m_connPeerConnected = m_download->download()->signal_peer_connected(sigc::mem_fun(*this, &ElementPeerList::receive_peer_connected));
m_connPeerDisconnected = m_download->download()->signal_peer_disconnected(sigc::mem_fun(*this, &ElementPeerList::receive_peer_disconnected));
m_windowList = new display::WindowPeerList(m_download, &m_list, &m_listItr);
m_elementInfo = create_info();
m_elementInfo->slot_exit(sigc::bind(sigc::mem_fun(this, &ElementPeerList::activate_display), DISPLAY_LIST));
m_bindings['k'] = sigc::mem_fun(this, &ElementPeerList::receive_disconnect_peer);
m_bindings['*'] = sigc::mem_fun(this, &ElementPeerList::receive_snub_peer);
m_bindings[KEY_UP] = sigc::mem_fun(this, &ElementPeerList::receive_prev);
m_bindings[KEY_DOWN] = sigc::mem_fun(this, &ElementPeerList::receive_next);
m_bindings[KEY_LEFT] = sigc::mem_fun(&m_slotExit, &slot_type::operator());
m_bindings[KEY_RIGHT] = sigc::bind(sigc::mem_fun(this, &ElementPeerList::activate_display), DISPLAY_INFO);
}
ElementPeerList::~ElementPeerList() {
m_connPeerConnected.disconnect();
m_connPeerDisconnected.disconnect();
delete m_windowList;
delete m_elementInfo;
}
inline ElementText*
ElementPeerList::create_info() {
using namespace display::helpers;
ElementText* element = new ElementText(NULL);
element->set_column(1);
// Get these bindings with some kind of string map.
element->push_back("Peer info:");
element->push_back("");
element->push_column("Address:",
display::text_element_string_slot(rak::on(std::mem_fun(&torrent::Peer::address), std::ptr_fun(&te_address))), ":",
display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::address), std::ptr_fun(&te_port))));
element->push_column("Id:", display::text_element_string_slot(std::mem_fun(&torrent::Peer::id), string_base::flag_escape_html));
element->push_column("Client:", display::text_element_string_slot(rak::on(std::mem_fun(&torrent::Peer::id), rak::make_mem_fun(control->client_info(), &display::ClientInfo::str_str))));
element->push_column("Options:", display::text_element_string_slot(std::mem_fun(&torrent::Peer::options), string_base::flag_escape_hex | string_base::flag_fixed_width, 0, 8));
element->push_back("");
element->push_column("Done:", display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::bitfield), std::ptr_fun(&te_bitfield_percentage))));
element->push_column("Rate:",
display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::up_rate), std::mem_fun(&torrent::Rate::rate)), value_base::flag_kb), " / ",
display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::down_rate), std::mem_fun(&torrent::Rate::rate)), value_base::flag_kb), " KB");
element->push_column("Total:",
display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::up_rate), std::mem_fun(&torrent::Rate::total)), value_base::flag_mb), " / ",
display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::down_rate), std::mem_fun(&torrent::Rate::total)), value_base::flag_mb), " MB");
element->set_column_width(element->column_width() + 1);
return element;
}
void
@@ -84,9 +131,6 @@ ElementPeerList::activate(display::Frame* frame, bool focus) {
m_frame = frame;
m_focus = focus;
m_window[DISPLAY_LIST] = new display::WindowPeerList(m_download, &m_list, &m_listItr);
m_window[DISPLAY_INFO] = new display::WindowPeerInfo(m_download, &m_list, &m_listItr);
activate_display(DISPLAY_LIST);
}
@@ -101,8 +145,6 @@ ElementPeerList::disable() {
m_frame->clear();
m_frame = NULL;
std::for_each(m_window, m_window + DISPLAY_MAX_SIZE, rak::call_delete<display::Window>());
}
void
@@ -112,10 +154,11 @@ ElementPeerList::activate_display(Display display) {
switch (m_state) {
case DISPLAY_INFO:
case DISPLAY_LIST:
m_bindings.erase(KEY_LEFT);
m_elementInfo->disable();
break;
m_window[m_state]->set_active(false);
case DISPLAY_LIST:
m_windowList->set_active(false);
m_frame->clear();
break;
@@ -127,17 +170,12 @@ ElementPeerList::activate_display(Display display) {
switch (m_state) {
case DISPLAY_INFO:
m_bindings[KEY_LEFT] = sigc::bind(sigc::mem_fun(this, &ElementPeerList::activate_display), DISPLAY_LIST);
m_window[m_state]->set_active(true);
m_frame->initialize_window(m_window[m_state]);
m_elementInfo->activate(m_frame, true);
break;
case DISPLAY_LIST:
m_bindings[KEY_LEFT] = sigc::mem_fun(&m_slotExit, &slot_type::operator());
m_window[m_state]->set_active(true);
m_frame->initialize_window(m_window[m_state]);
m_windowList->set_active(true);
m_frame->initialize_window(m_windowList);
break;
case DISPLAY_MAX_SIZE:
@@ -154,7 +192,7 @@ ElementPeerList::receive_next() {
else
m_listItr = m_list.begin();
m_window[m_state]->mark_dirty();
updated_itr();
}
void
@@ -164,7 +202,7 @@ ElementPeerList::receive_prev() {
else
m_listItr = m_list.end();
m_window[m_state]->mark_dirty();
updated_itr();
}
void
@@ -173,8 +211,6 @@ ElementPeerList::receive_disconnect_peer() {
return;
m_download->download()->disconnect_peer(*m_listItr);
m_window[m_state]->mark_dirty();
}
void
@@ -193,6 +229,8 @@ ElementPeerList::receive_peer_disconnected(torrent::Peer p) {
m_listItr = m_list.erase(itr);
else
m_list.erase(itr);
updated_itr();
}
void
@@ -202,7 +240,13 @@ ElementPeerList::receive_snub_peer() {
m_listItr->set_snubbed(!m_listItr->is_snubbed());
m_window[m_state]->mark_dirty();
updated_itr();
}
inline void
ElementPeerList::updated_itr() {
m_windowList->mark_dirty();
m_elementInfo->set_object(m_listItr != m_list.end() ? &*m_listItr : NULL);
}
}
+9 -1
View File
@@ -43,6 +43,8 @@
namespace ui {
class ElementText;
class ElementPeerList : public ElementBase {
public:
typedef std::list<torrent::Peer> PList;
@@ -62,6 +64,8 @@ public:
void activate_display(Display display);
private:
inline ElementText* create_info();
void receive_next();
void receive_prev();
@@ -72,11 +76,15 @@ private:
void receive_snub_peer();
inline void updated_itr();
core::Download* m_download;
Display m_state;
display::Window* m_window[DISPLAY_MAX_SIZE];
display::Window* m_windowList;
ElementText* m_elementInfo;
PList m_list;
PList::iterator m_listItr;
+19
View File
@@ -150,6 +150,25 @@ ElementText::push_column(text_element_wrapper entry1, text_element_wrapper entry
push_back(list);
}
void
ElementText::push_column(text_element_wrapper entry1, text_element_wrapper entry2,
text_element_wrapper entry3, text_element_wrapper entry4,
text_element_wrapper entry5) {
m_columnWidth = std::max(entry1.m_element->max_length(), m_columnWidth);
display::TextElementList* list = new display::TextElementList;
list->set_column(m_column);
list->set_column_width(&m_columnWidth);
list->push_back(entry1.m_element);
list->push_back(entry2.m_element);
list->push_back(entry3.m_element);
list->push_back(entry4.m_element);
list->push_back(entry5.m_element);
push_back(list);
}
void
ElementText::push_column(text_element_wrapper entry1, text_element_wrapper entry2,
text_element_wrapper entry3, text_element_wrapper entry4,
+9 -2
View File
@@ -41,11 +41,11 @@
#include "core/download.h"
#include "display/text_element_string.h"
#include "display/window_text.h"
#include "element_base.h"
namespace display {
class WindowText;
class TextElement;
}
@@ -63,6 +63,9 @@ public:
ElementText(void *object);
~ElementText();
void* object() const { return m_window->object(); }
void set_object(void* object) { m_window->set_object(object); m_window->mark_dirty(); }
void activate(display::Frame* frame, bool focus = false);
void disable();
@@ -81,7 +84,11 @@ public:
void push_column(text_element_wrapper entry1, text_element_wrapper entry2,
text_element_wrapper entry3, text_element_wrapper entry4,
text_element_wrapper entry5, text_element_wrapper entry6a);
text_element_wrapper entry5);
void push_column(text_element_wrapper entry1, text_element_wrapper entry2,
text_element_wrapper entry3, text_element_wrapper entry4,
text_element_wrapper entry5, text_element_wrapper entry6);
void set_column(unsigned int column) { m_column = column; }