mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-07 06:39:23 +00:00
* Added TextElementValue*.
* The curl perform loop wasn't properly checking the returned pointer, which caused a segfault with libcurl 7.15.5. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@754 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -17,6 +17,8 @@ libsub_display_a_SOURCES = \
|
||||
text_element_list.h \
|
||||
text_element_string.cc \
|
||||
text_element_string.h \
|
||||
text_element_value.cc \
|
||||
text_element_value.h \
|
||||
window.cc \
|
||||
window.h \
|
||||
window_download_chunks_seen.cc \
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <rak/functional.h>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
#include "text_element_list.h"
|
||||
|
||||
@@ -59,8 +60,14 @@ TextElementList::print(char* first, const char* last, Canvas::attributes_list* a
|
||||
if (column-- > 0) {
|
||||
const char* columnEnd = std::min<const char*>(last, first + *m_columnWidth);
|
||||
|
||||
if (columnEnd < first || columnEnd > last)
|
||||
throw torrent::client_error("TextElementList::print(...) columnEnd < first || columnEnd > last.");
|
||||
|
||||
first = (*itr)->print(first, columnEnd, attributes, object);
|
||||
|
||||
if (first > columnEnd)
|
||||
throw torrent::client_error("TextElementList::print(...) first > columnEnd.");
|
||||
|
||||
std::memset(first, ' ', columnEnd - first);
|
||||
first += columnEnd - first;
|
||||
|
||||
|
||||
@@ -70,19 +70,18 @@ char*
|
||||
TextElementString::copy_string(char* first, const char* last, void* object) {
|
||||
extent_type length = std::min<extent_type>(last - first, m_string.size());
|
||||
|
||||
if (length == 0)
|
||||
return first;
|
||||
|
||||
std::memcpy(first, m_string.c_str(), std::min<extent_type>(length, last - first));
|
||||
std::memcpy(first, m_string.c_str(), length);
|
||||
|
||||
return first + length;
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementCString::copy_string(char* first, const char* last, void* object) {
|
||||
std::memcpy(first, m_string, std::min<extent_type>(m_length, last - first));
|
||||
extent_type length = std::min<extent_type>(last - first, m_length);
|
||||
|
||||
return first + m_length;
|
||||
std::memcpy(first, m_string, length);
|
||||
|
||||
return first + length;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_DISPLAY_TEXT_ELEMENT_LIST_H
|
||||
#define RTORRENT_DISPLAY_TEXT_ELEMENT_LIST_H
|
||||
#ifndef RTORRENT_DISPLAY_TEXT_ELEMENT_STRING_H
|
||||
#define RTORRENT_DISPLAY_TEXT_ELEMENT_STRING_H
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// 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 "text_element_value.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
char*
|
||||
TextElementValueBase::print(char* first, const 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);
|
||||
|
||||
if (current.attributes() == Attributes::a_invalid)
|
||||
current.set_attributes(base.attributes());
|
||||
else if (current.attributes() != base.attributes())
|
||||
current.set_position(first);
|
||||
|
||||
if (current.colors() == Attributes::color_invalid)
|
||||
current.set_colors(base.colors());
|
||||
else if (current.colors() != base.colors())
|
||||
current.set_position(first);
|
||||
|
||||
// first += std::max(snprintf(first, last - first + 1, m_format, value(object)), 0);
|
||||
first += std::max(snprintf(first, last - first, "%lld", value(object)), 0);
|
||||
|
||||
if (current.position() != NULL) {
|
||||
attributes->push_back(current);
|
||||
attributes->push_back(Attributes(first, base.attributes(), base.colors()));
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// 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_VALUE_H
|
||||
#define RTORRENT_DISPLAY_TEXT_ELEMENT_VALUE_H
|
||||
|
||||
#include <cstring>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "text_element.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
class TextElementValueBase : public TextElement {
|
||||
public:
|
||||
static const extent_type max_format_length = 12;
|
||||
|
||||
int attributes() const { return m_attributes; }
|
||||
void set_attributes(int a) { m_attributes = a; }
|
||||
|
||||
void set_format(const char* f);
|
||||
|
||||
virtual char* print(char* first, const char* last, Canvas::attributes_list* attributes, void* object);
|
||||
|
||||
protected:
|
||||
virtual int64_t value(void* object) = 0;
|
||||
|
||||
int m_attributes;
|
||||
char m_format[max_format_length];
|
||||
};
|
||||
|
||||
inline void
|
||||
TextElementValueBase::set_format(const char* f) {
|
||||
std::strncpy(m_format, f, max_format_length);
|
||||
m_format[max_format_length - 1] = '\0';
|
||||
}
|
||||
|
||||
class TextElementValue : public TextElementValueBase {
|
||||
public:
|
||||
TextElementValue(int64_t value, int attributes = Attributes::a_invalid) : m_value(value) {
|
||||
m_attributes = attributes;
|
||||
set_format("%lld");
|
||||
}
|
||||
|
||||
int64_t value() const { return m_value; }
|
||||
void set_value(int64_t v) { m_value = v; }
|
||||
|
||||
private:
|
||||
virtual extent_type max_length() { return 12; }
|
||||
|
||||
virtual int64_t value(void* object) { return m_value; }
|
||||
|
||||
int64_t m_value;
|
||||
};
|
||||
|
||||
template <typename slot_type>
|
||||
class TextElementValueSlot : public TextElementValueBase {
|
||||
public:
|
||||
typedef typename slot_type::argument_type arg1_type;
|
||||
typedef typename slot_type::result_type result_type;
|
||||
|
||||
TextElementValueSlot(const slot_type& slot, int attributes = Attributes::a_invalid) : m_slot(slot) {
|
||||
m_attributes = attributes;
|
||||
set_format("%lld");
|
||||
}
|
||||
|
||||
private:
|
||||
virtual extent_type max_length() { return 12; }
|
||||
|
||||
virtual int64_t value(void* object) {
|
||||
arg1_type arg1 = reinterpret_cast<arg1_type>(object);
|
||||
|
||||
if (arg1 == NULL)
|
||||
return 0;
|
||||
|
||||
return m_slot(arg1);
|
||||
}
|
||||
|
||||
slot_type m_slot;
|
||||
};
|
||||
|
||||
template <typename slot_type>
|
||||
inline TextElementValueSlot<slot_type>*
|
||||
text_element_value_slot(const slot_type& slot, int attributes = Attributes::a_invalid) {
|
||||
return new TextElementValueSlot<slot_type>(slot, attributes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -75,6 +75,7 @@ WindowText::redraw() {
|
||||
m_canvas->erase();
|
||||
|
||||
unsigned int position = 0;
|
||||
Canvas::attributes_list attributes;
|
||||
|
||||
for (iterator itr = begin(); itr != end() && position < m_canvas->height(); ++itr, ++position) {
|
||||
if (*itr == NULL)
|
||||
@@ -83,7 +84,7 @@ WindowText::redraw() {
|
||||
char buffer[m_canvas->width() + 1];
|
||||
|
||||
// Add a print function that sets up attributes etc?
|
||||
Canvas::attributes_list attributes;
|
||||
attributes.clear();
|
||||
attributes.push_back(Attributes(buffer, Attributes::a_normal, Attributes::color_default));
|
||||
|
||||
char* last = (*itr)->print(buffer, buffer + m_canvas->width(), &attributes, m_object);
|
||||
|
||||
Reference in New Issue
Block a user