* 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
+36 -2
View File
@@ -191,8 +191,8 @@ OutputIterator
copy_escape_html(InputIterator first, InputIterator last, OutputIterator dest) {
while (first != last) {
if (std::isalpha(*first, std::locale::classic()) ||
std::isdigit(*first, std::locale::classic()) ||
*first == '-') {
std::isdigit(*first, std::locale::classic()) ||
*first == '-') {
*(dest++) = *first;
} else {
@@ -207,6 +207,27 @@ copy_escape_html(InputIterator first, InputIterator last, OutputIterator dest) {
return dest;
}
template <typename InputIterator, typename OutputIterator>
OutputIterator
copy_escape_html(InputIterator first1, InputIterator last1, OutputIterator first2, OutputIterator last2) {
while (first1 != last1) {
if (std::isalpha(*first1, std::locale::classic()) ||
std::isdigit(*first1, std::locale::classic()) ||
*first1 == '-') {
if (first2 == last2) break; else *(first2++) = *first1;
} else {
if (first2 == last2) break; else *(first2++) = '%';
if (first2 == last2) break; else *(first2++) = value_to_hexchar<1>(*first1);
if (first2 == last2) break; else *(first2++) = value_to_hexchar<0>(*first1);
}
++first1;
}
return first2;
}
template <typename Sequence>
Sequence
copy_escape_html(const Sequence& src) {
@@ -230,6 +251,19 @@ transform_hex(InputIterator first, InputIterator last, OutputIterator dest) {
return dest;
}
template <typename InputIterator, typename OutputIterator>
OutputIterator
transform_hex(InputIterator first1, InputIterator last1, OutputIterator first2, OutputIterator last2) {
while (first1 != last1) {
if (first2 == last2) break; else *(first2++) = value_to_hexchar<1>(*first1);
if (first2 == last2) break; else *(first2++) = value_to_hexchar<0>(*first1);
++first1;
}
return first2;
}
template <typename Sequence>
Sequence
transform_hex(const Sequence& src) {
-5
View File
@@ -90,11 +90,6 @@ public:
file_list_type* file_list() { return &m_fileList; }
tracker_list_type* tracker_list() { return &m_trackerList; }
const std::string& info_hash() const { return m_download.info_hash(); }
std::string info_hash_hex() const { return rak::transform_hex(m_download.info_hash()); }
std::string local_id_escaped() const { return rak::copy_escape_html(m_download.local_id()); }
const std::string& message() const { return m_message; }
void set_message(const std::string& msg) { m_message = msg; }
+2 -2
View File
@@ -166,7 +166,7 @@ DownloadStore::is_correct_format(std::string f) {
for (std::string::const_iterator itr = f.begin(); itr != f.end() - 8; ++itr)
if (!(*itr >= '0' && *itr <= '9') &&
!(*itr >= 'A' && *itr <= 'F'))
!(*itr >= 'A' && *itr <= 'F'))
return false;
return true;
@@ -174,7 +174,7 @@ DownloadStore::is_correct_format(std::string f) {
std::string
DownloadStore::create_filename(Download* d) {
return m_path + rak::transform_hex(d->info_hash()) + ".torrent";
return m_path + rak::transform_hex(d->download()->info_hash()) + ".torrent";
}
}
+1 -2
View File
@@ -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
View File
@@ -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);
}
}
+7 -2
View File
@@ -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;
+1 -1
View File
@@ -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;
};
+129
View File
@@ -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
+3 -3
View File
@@ -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);
+1 -1
View File
@@ -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();
+23 -4
View File
@@ -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);
+36 -15
View File
@@ -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);
}
}
+7 -2
View File
@@ -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
+7 -7
View File
@@ -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;
-126
View File
@@ -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);
}
}
-74
View File
@@ -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
+3
View File
@@ -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();
+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; }