mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-08 19:22:29 +00:00
* 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:
@@ -13,6 +13,7 @@ libsub_display_a_SOURCES = \
|
||||
utils.cc \
|
||||
utils.h \
|
||||
text_element.h \
|
||||
text_element_helpers.h \
|
||||
text_element_list.cc \
|
||||
text_element_list.h \
|
||||
text_element_string.cc \
|
||||
@@ -39,8 +40,6 @@ libsub_display_a_SOURCES = \
|
||||
window_log.h \
|
||||
window_log_complete.cc \
|
||||
window_log_complete.h \
|
||||
window_peer_info.cc \
|
||||
window_peer_info.h \
|
||||
window_peer_list.cc \
|
||||
window_peer_list.h \
|
||||
window_statusbar.cc \
|
||||
|
||||
+25
-17
@@ -125,55 +125,55 @@ ClientInfo::insert(Type t, const char* key, const char* name) {
|
||||
}
|
||||
|
||||
char*
|
||||
ClientInfo::print(char* first, char* last, const char* id) {
|
||||
ClientInfo::print(char* first, char* last, const char* id) const {
|
||||
|
||||
if (id[0] == '-' && id[7] == '-' &&
|
||||
std::isalpha(id[1]) && std::isalpha(id[2]) &&
|
||||
std::isxdigit(id[3]) && std::isxdigit(id[4]) && std::isxdigit(id[5]) && std::isxdigit(id[6])) {
|
||||
// TYPE_AZUREUS.
|
||||
|
||||
iterator itr = std::find_if(m_containers[TYPE_AZUREUS].begin(), m_containers[TYPE_AZUREUS].end(),
|
||||
client_info_equal(id + 1, sizeof_key(TYPE_AZUREUS)));
|
||||
const_iterator itr = std::find_if(m_containers[TYPE_AZUREUS].begin(), m_containers[TYPE_AZUREUS].end(),
|
||||
client_info_equal(id + 1, sizeof_key(TYPE_AZUREUS)));
|
||||
|
||||
if (itr != m_containers[TYPE_AZUREUS].end())
|
||||
first = print_buffer(first, last, "%s %hhu.%hhu.%hhu.%hhu", itr->second,
|
||||
rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[4]),
|
||||
rak::hexchar_to_value(id[5]), rak::hexchar_to_value(id[6]));
|
||||
rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[4]),
|
||||
rak::hexchar_to_value(id[5]), rak::hexchar_to_value(id[6]));
|
||||
|
||||
else
|
||||
first = print_buffer(first, last, "unknown %c%c %hhu.%hhu.%hhu.%hhu", id[1], id[2],
|
||||
rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[4]),
|
||||
rak::hexchar_to_value(id[5]), rak::hexchar_to_value(id[6]));
|
||||
rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[4]),
|
||||
rak::hexchar_to_value(id[5]), rak::hexchar_to_value(id[6]));
|
||||
|
||||
} else if (std::isalpha(id[0]) && id[4] == '-' &&
|
||||
std::isxdigit(id[1]) && std::isxdigit(id[2]) && std::isxdigit(id[3])) {
|
||||
std::isxdigit(id[1]) && std::isxdigit(id[2]) && std::isxdigit(id[3])) {
|
||||
// TYPE_THREE_COMPACT.
|
||||
|
||||
iterator itr = std::find_if(m_containers[TYPE_COMPACT].begin(), m_containers[TYPE_COMPACT].end(),
|
||||
client_info_equal(id, sizeof_key(TYPE_COMPACT)));
|
||||
const_iterator itr = std::find_if(m_containers[TYPE_COMPACT].begin(), m_containers[TYPE_COMPACT].end(),
|
||||
client_info_equal(id, sizeof_key(TYPE_COMPACT)));
|
||||
|
||||
if (itr != m_containers[TYPE_COMPACT].end())
|
||||
first = print_buffer(first, last, "%s %hhu.%hhu.%hhu", itr->second,
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[2]), rak::hexchar_to_value(id[3]));
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[2]), rak::hexchar_to_value(id[3]));
|
||||
|
||||
else
|
||||
first = print_buffer(first, last, "unknown %c %hhu.%hhu.%hhu", id[0],
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[2]), rak::hexchar_to_value(id[3]));
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[2]), rak::hexchar_to_value(id[3]));
|
||||
|
||||
} else if (std::isalpha(id[0]) && id[2] == '-' && id[4] == '-' && id[6] == '-' &&
|
||||
std::isxdigit(id[1]) && std::isxdigit(id[3]) && std::isxdigit(id[5])) {
|
||||
std::isxdigit(id[1]) && std::isxdigit(id[3]) && std::isxdigit(id[5])) {
|
||||
// TYPE_THREE_SPARSE.
|
||||
|
||||
iterator itr = std::find_if(m_containers[TYPE_MAINLINE].begin(), m_containers[TYPE_MAINLINE].end(),
|
||||
client_info_equal(id, sizeof_key(TYPE_MAINLINE)));
|
||||
const_iterator itr = std::find_if(m_containers[TYPE_MAINLINE].begin(), m_containers[TYPE_MAINLINE].end(),
|
||||
client_info_equal(id, sizeof_key(TYPE_MAINLINE)));
|
||||
|
||||
if (itr != m_containers[TYPE_MAINLINE].end())
|
||||
first = print_buffer(first, last, "%s %hhu.%hhu.%hhu", itr->second,
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[5]));
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[5]));
|
||||
|
||||
else
|
||||
first = print_buffer(first, last, "unknown %c %hhu.%hhu.%hhu", id[0],
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[5]));
|
||||
rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[5]));
|
||||
|
||||
|
||||
// And then the incompatible idiots that make life difficult for us
|
||||
@@ -189,4 +189,12 @@ ClientInfo::print(char* first, char* last, const char* id) {
|
||||
return first;
|
||||
}
|
||||
|
||||
std::string
|
||||
ClientInfo::str(const char* id) const {
|
||||
char buf[128];
|
||||
print(buf, buf + 127, id);
|
||||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
typedef std::pair<char[key_size], const char*> value_type;
|
||||
typedef std::vector<value_type> container_type;
|
||||
typedef container_type::iterator iterator;
|
||||
typedef container_type::const_iterator const_iterator;
|
||||
|
||||
typedef enum {
|
||||
TYPE_AZUREUS,
|
||||
@@ -64,9 +65,13 @@ public:
|
||||
|
||||
void insert(Type t, const char* key, const char* name);
|
||||
|
||||
char* print(char* first, char* last, const char* id);
|
||||
char* print(char* first, char* last, const char* id) const;
|
||||
|
||||
size_type sizeof_key(Type t) {
|
||||
// Fix this...
|
||||
std::string str(const char* id) const;
|
||||
std::string str_str(const std::string& id) const { return str(id.c_str()); }
|
||||
|
||||
size_type sizeof_key(Type t) const {
|
||||
switch (t) {
|
||||
case TYPE_AZUREUS: return 2;
|
||||
case TYPE_COMPACT: return 1;
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
// The last element must point to a valid memory location into which
|
||||
// the caller must write a '\0' to terminate the c string. The
|
||||
// attributes must contain at least one attribute.
|
||||
virtual char* print(char* first, const char* last, Canvas::attributes_list* attributes, void* object) = 0;
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object) = 0;
|
||||
|
||||
virtual extent_type max_length() = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2006, 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
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_DISPLAY_TEXT_ELEMENT_HELPERS_H
|
||||
#define RTORRENT_DISPLAY_TEXT_ELEMENT_HELPERS_H
|
||||
|
||||
#include <rak/functional.h>
|
||||
#include <rak/socket_address.h>
|
||||
#include <torrent/bitfield.h>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
#include "text_element_string.h"
|
||||
#include "text_element_value.h"
|
||||
|
||||
namespace display { namespace helpers {
|
||||
|
||||
typedef TextElementStringBase string_base;
|
||||
typedef TextElementValueBase value_base;
|
||||
|
||||
// String stuff:
|
||||
|
||||
// template <typename Object, typename Return>
|
||||
// inline TextElementStringBase*
|
||||
// te_string(Return (Object::*fptr)() const, const Object* object, int attributes = Attributes::a_invalid) {
|
||||
// return display::text_element_string_void(rak::make_mem_fun(object, fptr), attributes);
|
||||
// }
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementStringBase*
|
||||
te_string(Return (core::Download::*fptr)() const, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_string_slot(std::mem_fun(fptr), flags, attributes);
|
||||
}
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementStringBase*
|
||||
te_string(Return (torrent::Download::*fptr)() const, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_string_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(fptr)), flags, attributes);
|
||||
}
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementStringBase*
|
||||
te_string(Return (torrent::FileList::*fptr)() const, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_string_slot(rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(fptr)), flags, attributes);
|
||||
}
|
||||
|
||||
inline TextElementStringBase*
|
||||
te_variable_string(const std::string& variable, int flags = TextElementStringBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_string_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_string), variable), flags, attributes);
|
||||
}
|
||||
|
||||
// Value stuff:
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementValueBase*
|
||||
te_value(Return (torrent::Download::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_value_slot(rak::on(std::mem_fun(&core::Download::c_download), std::mem_fun(fptr)), flags, attributes);
|
||||
}
|
||||
|
||||
inline TextElementValueBase*
|
||||
te_variable_value(const std::string& variable, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_value_slot(rak::bind2nd(std::mem_fun(&core::Download::variable_value), variable), flags, attributes);
|
||||
}
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementValueBase*
|
||||
te_value(Return (torrent::ChunkManager::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_value_void(rak::make_mem_fun(torrent::chunk_manager(), fptr), flags, attributes);
|
||||
}
|
||||
|
||||
template <typename Return>
|
||||
inline TextElementValueBase*
|
||||
te_value(Return (torrent::ConnectionManager::*fptr)() const, int flags = TextElementValueBase::flag_normal, int attributes = Attributes::a_invalid) {
|
||||
return display::text_element_value_void(rak::make_mem_fun(torrent::connection_manager(), fptr), flags, attributes);
|
||||
}
|
||||
|
||||
// Various:
|
||||
|
||||
inline unsigned int
|
||||
te_bitfield_percentage(const torrent::Bitfield* bitfield) {
|
||||
return bitfield != NULL ? (100 * bitfield->size_set()) / bitfield->size_bits() : 0;
|
||||
}
|
||||
|
||||
inline std::string
|
||||
te_address(const ::sockaddr* address) {
|
||||
return rak::socket_address::cast_from(address)->address_str();
|
||||
}
|
||||
|
||||
inline unsigned int
|
||||
te_port(const ::sockaddr* address) {
|
||||
return rak::socket_address::cast_from(address)->port();
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
@@ -51,14 +51,14 @@ TextElementList::clear() {
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementList::print(char* first, const char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
TextElementList::print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
int column = m_columnWidth != NULL ? m_column : 0;
|
||||
|
||||
// Call print for each element even if first == last so that any
|
||||
// attributes gets added to the list.
|
||||
for (iterator itr = begin(); itr != end(); ++itr)
|
||||
if (column-- > 0) {
|
||||
const char* columnEnd = std::min<const char*>(last, first + *m_columnWidth);
|
||||
char* columnEnd = std::min(last, first + *m_columnWidth);
|
||||
|
||||
if (columnEnd < first || columnEnd > last)
|
||||
throw torrent::client_error("TextElementList::print(...) columnEnd < first || columnEnd > last.");
|
||||
@@ -69,7 +69,7 @@ TextElementList::print(char* first, const char* last, Canvas::attributes_list* a
|
||||
throw torrent::client_error("TextElementList::print(...) first > columnEnd.");
|
||||
|
||||
std::memset(first, ' ', columnEnd - first);
|
||||
first += columnEnd - first;
|
||||
first = columnEnd;
|
||||
|
||||
} else {
|
||||
first = (*itr)->print(first, last, attributes, object);
|
||||
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
void set_column(unsigned int column) { m_column = column; }
|
||||
void set_column_width(extent_type* width) { m_columnWidth = width; }
|
||||
|
||||
virtual char* print(char* first, const char* last, Canvas::attributes_list* attributes, void* object);
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object);
|
||||
|
||||
virtual extent_type max_length();
|
||||
|
||||
|
||||
@@ -36,12 +36,14 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <rak/string_manip.h>
|
||||
|
||||
#include "text_element_string.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
char*
|
||||
TextElementStringBase::print(char* first, const char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
// Move this stuff into a function in TextElement.
|
||||
Attributes base = attributes->back();
|
||||
Attributes current(NULL, m_attributes, Attributes::color_invalid);
|
||||
@@ -56,7 +58,24 @@ TextElementStringBase::print(char* first, const char* last, Canvas::attributes_l
|
||||
else if (current.colors() != base.colors())
|
||||
current.set_position(first);
|
||||
|
||||
first = copy_string(first, last, object);
|
||||
if (first == last) {
|
||||
// Do nothing, but ensure that the last attributes are set.
|
||||
|
||||
} else if (m_flags & flag_escape_hex) {
|
||||
char buffer[last - first];
|
||||
char* bufferLast = copy_string(buffer, buffer + (last - first), object);
|
||||
|
||||
first = rak::transform_hex(buffer, bufferLast, first, last);
|
||||
|
||||
} else if (m_flags & flag_escape_html) {
|
||||
char buffer[last - first];
|
||||
char* bufferLast = copy_string(buffer, buffer + (last - first), object);
|
||||
|
||||
first = rak::copy_escape_html(buffer, bufferLast, first, last);
|
||||
|
||||
} else {
|
||||
first = copy_string(first, last, object);
|
||||
}
|
||||
|
||||
if (current.position() != NULL) {
|
||||
attributes->push_back(current);
|
||||
@@ -67,7 +86,7 @@ TextElementStringBase::print(char* first, const char* last, Canvas::attributes_l
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementString::copy_string(char* first, const char* last, void* object) {
|
||||
TextElementString::copy_string(char* first, char* last, void* object) {
|
||||
extent_type length = std::min<extent_type>(last - first, m_string.size());
|
||||
|
||||
std::memcpy(first, m_string.c_str(), length);
|
||||
@@ -76,7 +95,7 @@ TextElementString::copy_string(char* first, const char* last, void* object) {
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementCString::copy_string(char* first, const char* last, void* object) {
|
||||
TextElementCString::copy_string(char* first, char* last, void* object) {
|
||||
extent_type length = std::min<extent_type>(last - first, m_length);
|
||||
|
||||
std::memcpy(first, m_string, length);
|
||||
|
||||
@@ -47,21 +47,33 @@ namespace display {
|
||||
|
||||
class TextElementStringBase : public TextElement {
|
||||
public:
|
||||
static const int flag_normal = 0;
|
||||
static const int flag_escape_hex = (1 << 0);
|
||||
static const int flag_escape_html = (1 << 1);
|
||||
|
||||
static const int flag_fixed_width = (1 << 8);
|
||||
|
||||
int flags() const { return m_flags; }
|
||||
void set_flags(int flags) { m_flags = flags; }
|
||||
|
||||
int attributes() const { return m_attributes; }
|
||||
void set_attributes(int a) { m_attributes = a; }
|
||||
|
||||
virtual char* print(char* first, const char* last, Canvas::attributes_list* attributes, void* object);
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object);
|
||||
|
||||
protected:
|
||||
virtual char* copy_string(char* first, const char* last, void* object) = 0;
|
||||
virtual char* copy_string(char* first, char* last, void* object) = 0;
|
||||
|
||||
int m_flags;
|
||||
int m_attributes;
|
||||
};
|
||||
|
||||
class TextElementString : public TextElementStringBase {
|
||||
public:
|
||||
TextElementString(const std::string& s, int attributes = Attributes::a_invalid) :
|
||||
m_string(s) { m_attributes = attributes; }
|
||||
TextElementString(const std::string& s, int flags = flag_normal, int attributes = Attributes::a_invalid) : m_string(s) {
|
||||
m_flags = flags;
|
||||
m_attributes = attributes;
|
||||
}
|
||||
|
||||
const std::string& str() const { return m_string; }
|
||||
void set_str(const std::string& s) { m_string = s; }
|
||||
@@ -69,22 +81,22 @@ public:
|
||||
private:
|
||||
virtual extent_type max_length() { return m_string.size(); }
|
||||
|
||||
virtual char* copy_string(char* first, const char* last, void* object);
|
||||
virtual char* copy_string(char* first, char* last, void* object);
|
||||
|
||||
std::string m_string;
|
||||
};
|
||||
|
||||
class TextElementCString : public TextElementStringBase {
|
||||
public:
|
||||
TextElementCString(const char* s, int attributes = Attributes::a_invalid) :
|
||||
m_length(std::strlen(s)), m_string(s) {
|
||||
TextElementCString(const char* s, int flags = flag_normal, int attributes = Attributes::a_invalid) : m_length(std::strlen(s)), m_string(s) {
|
||||
m_flags = flags;
|
||||
m_attributes = attributes;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual extent_type max_length() { return m_length; }
|
||||
|
||||
virtual char* copy_string(char* first, const char* last, void* object);
|
||||
virtual char* copy_string(char* first, char* last, void* object);
|
||||
|
||||
extent_type m_length;
|
||||
const char* m_string;
|
||||
@@ -96,15 +108,15 @@ public:
|
||||
typedef typename slot_type::argument_type arg1_type;
|
||||
typedef typename slot_type::result_type result_type;
|
||||
|
||||
TextElementStringSlot(const slot_type& slot, int attributes = Attributes::a_invalid) :
|
||||
m_length(extent_full), m_slot(slot) {
|
||||
TextElementStringSlot(const slot_type& slot, int flags, int attributes, extent_type length) : m_length(length), m_slot(slot) {
|
||||
m_flags = flags;
|
||||
m_attributes = attributes;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual extent_type max_length() { return m_length; }
|
||||
|
||||
virtual char* copy_string(char* first, const char* last, void* object) {
|
||||
virtual char* copy_string(char* first, char* last, void* object) {
|
||||
arg1_type arg1 = reinterpret_cast<arg1_type>(object);
|
||||
|
||||
if (arg1 == NULL)
|
||||
@@ -119,8 +131,14 @@ private:
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
extent_type result_length(Result* result) { return result->size(); }
|
||||
extent_type result_length(const char** result) { return std::strlen(*result); }
|
||||
extent_type result_length(Result* result) { return std::min<extent_type>(result->size(), m_length); }
|
||||
|
||||
extent_type result_length(const char** result) {
|
||||
if (m_flags & flag_fixed_width)
|
||||
return m_length;
|
||||
else
|
||||
return std::min<extent_type>(std::strlen(*result), m_length);
|
||||
}
|
||||
|
||||
template <typename Result>
|
||||
const char* result_buffer(Result* result) { return result->c_str(); }
|
||||
@@ -132,8 +150,11 @@ private:
|
||||
|
||||
template <typename slot_type>
|
||||
inline TextElementStringSlot<slot_type>*
|
||||
text_element_string_slot(const slot_type& slot, int attributes = Attributes::a_invalid) {
|
||||
return new TextElementStringSlot<slot_type>(slot, attributes);
|
||||
text_element_string_slot(const slot_type& slot,
|
||||
int flags = TextElementStringBase::flag_normal,
|
||||
int attributes = Attributes::a_invalid,
|
||||
TextElement::extent_type length = TextElement::extent_full) {
|
||||
return new TextElementStringSlot<slot_type>(slot, flags, attributes, length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
namespace display {
|
||||
|
||||
char*
|
||||
TextElementValueBase::print(char* first, const char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
TextElementValueBase::print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
// Move this stuff into a function in TextElement.
|
||||
Attributes base = attributes->back();
|
||||
Attributes current(NULL, m_attributes, Attributes::color_invalid);
|
||||
@@ -59,6 +59,7 @@ TextElementValueBase::print(char* first, const char* last, Canvas::attributes_li
|
||||
|
||||
int64_t val = value(object);
|
||||
|
||||
// Transform the value if needed.
|
||||
if (m_flags & flag_elapsed)
|
||||
val = cachedTime.seconds() - val;
|
||||
else if (m_flags & flag_remaining)
|
||||
@@ -67,7 +68,11 @@ TextElementValueBase::print(char* first, const char* last, Canvas::attributes_li
|
||||
if (m_flags & flag_usec)
|
||||
val = rak::timer(val).seconds();
|
||||
|
||||
if (m_flags & flag_timer) {
|
||||
// Print the value.
|
||||
if (first == last) {
|
||||
// Do nothing, but ensure that the last attributes are set.
|
||||
|
||||
} else if (m_flags & flag_timer) {
|
||||
if (val == 0)
|
||||
first += std::max(snprintf(first, last - first + 1, "--:--:--"), 0);
|
||||
else
|
||||
|
||||
@@ -46,13 +46,13 @@ namespace display {
|
||||
|
||||
class TextElementValueBase : public TextElement {
|
||||
public:
|
||||
static const int flag_normal = (1 << 0);
|
||||
static const int flag_timer = (1 << 1);
|
||||
static const int flag_date = (1 << 2);
|
||||
static const int flag_time = (1 << 3);
|
||||
static const int flag_normal = 0;
|
||||
static const int flag_timer = (1 << 0);
|
||||
static const int flag_date = (1 << 1);
|
||||
static const int flag_time = (1 << 2);
|
||||
|
||||
static const int flag_kb = (1 << 4);
|
||||
static const int flag_mb = (1 << 5);
|
||||
static const int flag_kb = (1 << 3);
|
||||
static const int flag_mb = (1 << 4);
|
||||
|
||||
static const int flag_elapsed = (1 << 8);
|
||||
static const int flag_remaining = (1 << 9);
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
int attributes() const { return m_attributes; }
|
||||
void set_attributes(int a) { m_attributes = a; }
|
||||
|
||||
virtual char* print(char* first, const char* last, Canvas::attributes_list* attributes, void* object);
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object);
|
||||
|
||||
protected:
|
||||
virtual int64_t value(void* object) = 0;
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2006, 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
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <rak/socket_address.h>
|
||||
#include <rak/string_manip.h>
|
||||
#include <torrent/rate.h>
|
||||
#include <torrent/chunk_manager.h>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
#include "canvas.h"
|
||||
#include "client_info.h"
|
||||
#include "utils.h"
|
||||
#include "window_peer_info.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
WindowPeerInfo::WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f) :
|
||||
Window(new Canvas, 0, 0, 0, extent_full, extent_full),
|
||||
m_download(d),
|
||||
m_list(l),
|
||||
m_focus(f) {
|
||||
}
|
||||
|
||||
void
|
||||
WindowPeerInfo::redraw() {
|
||||
m_slotSchedule(this, (cachedTime + rak::timer::from_seconds(1)).round_seconds());
|
||||
m_canvas->erase();
|
||||
|
||||
int y = 0;
|
||||
|
||||
if (*m_focus == m_list->end()) {
|
||||
m_canvas->print(0, y++, "No peer in focus");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_canvas->print(0, y++, "*** Peer Info ***");
|
||||
|
||||
m_canvas->print(0, y++, "IP: %s:%hu",
|
||||
rak::socket_address::cast_from((*m_focus)->address())->address_str().c_str(),
|
||||
rak::socket_address::cast_from((*m_focus)->address())->port());
|
||||
|
||||
m_canvas->print(0, y++, "ID: %s" , rak::copy_escape_html((*m_focus)->id()).c_str());
|
||||
|
||||
char buf[128];
|
||||
control->client_info()->print(buf, buf + 128, (*m_focus)->id().c_str());
|
||||
|
||||
m_canvas->print(0, y++, "Client: %s" , buf);
|
||||
|
||||
m_canvas->print(0, y++, "Options: %s" , rak::transform_hex(std::string((*m_focus)->options(), 8)).c_str());
|
||||
m_canvas->print(0, y++, "Snubbed: %s", (*m_focus)->is_snubbed() ? "yes" : "no");
|
||||
m_canvas->print(0, y++, "Connected: %s", (*m_focus)->is_incoming() ? "remote" : "local");
|
||||
|
||||
m_canvas->print(0, y++, "Done: %i%", done_percentage(**m_focus));
|
||||
|
||||
m_canvas->print(0, y++, "Rate: %5.1f/%5.1f KB Total: %.1f/%.1f MB",
|
||||
(double)(*m_focus)->up_rate()->rate() / (double)(1 << 10),
|
||||
(double)(*m_focus)->down_rate()->rate() / (double)(1 << 10),
|
||||
(double)(*m_focus)->up_rate()->total() / (double)(1 << 20),
|
||||
(double)(*m_focus)->down_rate()->total() / (double)(1 << 20));
|
||||
}
|
||||
|
||||
int
|
||||
WindowPeerInfo::done_percentage(torrent::Peer& p) {
|
||||
int chunks = m_download->download()->chunks_total();
|
||||
|
||||
return chunks ? (100 * p.chunks_done()) / chunks : 0;
|
||||
}
|
||||
|
||||
char*
|
||||
WindowPeerInfo::print_date(char* buf, char* end, time_t t) {
|
||||
buf = print_ddmmyyyy(buf, end, t);
|
||||
buf = print_string(buf, end, " ");
|
||||
buf = print_hhmmss_local(buf, end, t);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
char*
|
||||
WindowPeerInfo::print_timer(char* buf, char* end, time_t t) {
|
||||
if (t == 0)
|
||||
return print_string(buf, end, "--:--:--");
|
||||
else
|
||||
return print_hhmmss(buf, end, cachedTime.seconds() - t);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2006, 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
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_DISPLAY_PEER_INFO_H
|
||||
#define RTORRENT_DISPLAY_PEER_INFO_H
|
||||
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
#include <torrent/peer.h>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace display {
|
||||
|
||||
class WindowPeerInfo : public Window {
|
||||
public:
|
||||
typedef std::list<torrent::Peer> PList;
|
||||
|
||||
WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f);
|
||||
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
int done_percentage(torrent::Peer& p);
|
||||
|
||||
char* print_date(char* buf, char* end, time_t t);
|
||||
char* print_timer(char* buf, char* end, time_t t);
|
||||
|
||||
core::Download* m_download;
|
||||
|
||||
PList* m_list;
|
||||
PList::iterator* m_focus;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -68,6 +68,9 @@ public:
|
||||
|
||||
void clear();
|
||||
|
||||
void* object() const { return m_object; }
|
||||
void set_object(void* object) { m_object = object; }
|
||||
|
||||
void push_back(TextElement* element);
|
||||
|
||||
virtual void redraw();
|
||||
|
||||
Reference in New Issue
Block a user