mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-08 15:19:20 +00:00
* Fix TextElement* to use rpc::target_type.
* Moved most of src/ui/download.cc to use commands for TextElements. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@967 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "display/canvas.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
@@ -56,7 +57,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, char* last, Canvas::attributes_list* attributes, void* object) = 0;
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) = 0;
|
||||
|
||||
virtual extent_type max_length() = 0;
|
||||
|
||||
|
||||
@@ -50,11 +50,11 @@ public:
|
||||
m_slot(slot), m_branch1(branch1), m_branch2(branch2) {}
|
||||
~TextElementBranchVoid() { delete m_branch1; delete m_branch2; }
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
if (m_slot())
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, object) : first;
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, target) : first;
|
||||
else
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, object) : first;
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, target) : first;
|
||||
}
|
||||
|
||||
virtual extent_type max_length() {
|
||||
@@ -79,14 +79,14 @@ public:
|
||||
m_slot(slot), m_branch1(branch1), m_branch2(branch2) {}
|
||||
~TextElementBranch() { delete m_branch1; delete m_branch2; }
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
if (object == NULL)
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
if (target.second == NULL)
|
||||
return first;
|
||||
|
||||
if (m_slot(reinterpret_cast<arg1_type>(object)))
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, object) : first;
|
||||
if (m_slot(reinterpret_cast<arg1_type>(target.second)))
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, target) : first;
|
||||
else
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, object) : first;
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, target) : first;
|
||||
}
|
||||
|
||||
virtual extent_type max_length() {
|
||||
@@ -111,16 +111,16 @@ public:
|
||||
m_slot1(slot1), m_slot2(slot2), m_branch1(branch1), m_branch2(branch2), m_branch3(branch3) {}
|
||||
~TextElementBranch3() { delete m_branch1; delete m_branch2; delete m_branch3; }
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
if (object == NULL)
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
if (target.second == NULL)
|
||||
return first;
|
||||
|
||||
if (m_slot1(reinterpret_cast<arg1_type>(object)))
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, object) : first;
|
||||
else if (m_slot2(reinterpret_cast<arg1_type>(object)))
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, object) : first;
|
||||
if (m_slot1(reinterpret_cast<arg1_type>(target.second)))
|
||||
return m_branch1 != NULL ? m_branch1->print(first, last, attributes, target) : first;
|
||||
else if (m_slot2(reinterpret_cast<arg1_type>(target.second)))
|
||||
return m_branch2 != NULL ? m_branch2->print(first, last, attributes, target) : first;
|
||||
else
|
||||
return m_branch3 != NULL ? m_branch3->print(first, last, attributes, object) : first;
|
||||
return m_branch3 != NULL ? m_branch3->print(first, last, attributes, target) : first;
|
||||
}
|
||||
|
||||
virtual extent_type max_length() {
|
||||
|
||||
@@ -51,7 +51,7 @@ TextElementList::clear() {
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementList::print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
TextElementList::print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
int column = m_columnWidth != NULL ? m_column : 0;
|
||||
|
||||
// Call print for each element even if first == last so that any
|
||||
@@ -63,7 +63,7 @@ TextElementList::print(char* first, char* last, Canvas::attributes_list* attribu
|
||||
if (columnEnd < first || columnEnd > last)
|
||||
throw torrent::internal_error("TextElementList::print(...) columnEnd < first || columnEnd > last.");
|
||||
|
||||
first = (*itr)->print(first, columnEnd, attributes, object);
|
||||
first = (*itr)->print(first, columnEnd, attributes, target);
|
||||
|
||||
if (first > columnEnd)
|
||||
throw torrent::internal_error("TextElementList::print(...) first > columnEnd.");
|
||||
@@ -72,7 +72,7 @@ TextElementList::print(char* first, char* last, Canvas::attributes_list* attribu
|
||||
first = columnEnd;
|
||||
|
||||
} else {
|
||||
first = (*itr)->print(first, last, attributes, object);
|
||||
first = (*itr)->print(first, last, attributes, target);
|
||||
}
|
||||
|
||||
return first;
|
||||
|
||||
@@ -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, char* last, Canvas::attributes_list* attributes, void* object);
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target);
|
||||
|
||||
virtual extent_type max_length();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
namespace display {
|
||||
|
||||
char*
|
||||
TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
Attributes baseAttribute = attributes->back();
|
||||
push_attribute(attributes, Attributes(first, m_attributes, Attributes::color_invalid));
|
||||
|
||||
@@ -52,18 +52,18 @@ TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* a
|
||||
|
||||
if (m_flags & flag_escape_hex) {
|
||||
char buffer[last - first];
|
||||
char* bufferLast = copy_string(buffer, buffer + (last - first), object);
|
||||
char* bufferLast = copy_string(buffer, buffer + (last - first), target);
|
||||
|
||||
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);
|
||||
char* bufferLast = copy_string(buffer, buffer + (last - first), target);
|
||||
|
||||
first = rak::copy_escape_html(buffer, bufferLast, first, last);
|
||||
|
||||
} else {
|
||||
first = copy_string(first, last, object);
|
||||
first = copy_string(first, last, target);
|
||||
}
|
||||
|
||||
push_attribute(attributes, Attributes(first, baseAttribute));
|
||||
@@ -72,7 +72,7 @@ TextElementStringBase::print(char* first, char* last, Canvas::attributes_list* a
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementString::copy_string(char* first, char* last, void* object) {
|
||||
TextElementString::copy_string(char* first, char* last, rpc::target_type target) {
|
||||
extent_type length = std::min<extent_type>(last - first, m_string.size());
|
||||
|
||||
std::memcpy(first, m_string.c_str(), length);
|
||||
@@ -81,7 +81,7 @@ TextElementString::copy_string(char* first, char* last, void* object) {
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementCString::copy_string(char* first, char* last, void* object) {
|
||||
TextElementCString::copy_string(char* first, char* last, rpc::target_type target) {
|
||||
extent_type length = std::min<extent_type>(last - first, m_length);
|
||||
|
||||
std::memcpy(first, m_string, length);
|
||||
|
||||
@@ -59,10 +59,10 @@ public:
|
||||
int attributes() const { return m_attributes; }
|
||||
void set_attributes(int a) { m_attributes = a; }
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object);
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target);
|
||||
|
||||
protected:
|
||||
virtual char* copy_string(char* first, char* last, void* object) = 0;
|
||||
virtual char* copy_string(char* first, char* last, rpc::target_type target) = 0;
|
||||
|
||||
int m_flags;
|
||||
int m_attributes;
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
virtual extent_type max_length() { return m_string.size(); }
|
||||
|
||||
private:
|
||||
virtual char* copy_string(char* first, char* last, void* object);
|
||||
virtual char* copy_string(char* first, char* last, rpc::target_type target);
|
||||
|
||||
std::string m_string;
|
||||
};
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
virtual extent_type max_length() { return m_length; }
|
||||
|
||||
private:
|
||||
virtual char* copy_string(char* first, char* last, void* object);
|
||||
virtual char* copy_string(char* first, char* last, rpc::target_type target);
|
||||
|
||||
extent_type m_length;
|
||||
const char* m_string;
|
||||
@@ -116,11 +116,11 @@ public:
|
||||
virtual extent_type max_length() { return m_length; }
|
||||
|
||||
private:
|
||||
virtual char* copy_string(char* first, char* last, void* object) {
|
||||
if (object == NULL)
|
||||
virtual char* copy_string(char* first, char* last, rpc::target_type target) {
|
||||
if (target.second == NULL)
|
||||
return first;
|
||||
|
||||
result_type result = m_slot(reinterpret_cast<arg1_type>(object));
|
||||
result_type result = m_slot(reinterpret_cast<arg1_type>(target.second));
|
||||
extent_type length = std::min<extent_type>(result_length(&result), last - first);
|
||||
|
||||
std::memcpy(first, result_buffer(&result), length);
|
||||
|
||||
@@ -59,11 +59,11 @@ TextElement::push_attribute(Canvas::attributes_list* attributes, Attributes valu
|
||||
}
|
||||
|
||||
char*
|
||||
TextElementValueBase::print(char* first, char* last, Canvas::attributes_list* attributes, void* object) {
|
||||
TextElementValueBase::print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target) {
|
||||
Attributes baseAttribute = attributes->back();
|
||||
push_attribute(attributes, Attributes(first, m_attributes, Attributes::color_invalid));
|
||||
|
||||
int64_t val = value(object);
|
||||
int64_t val = value(target.second);
|
||||
|
||||
// Transform the value if needed.
|
||||
if (m_flags & flag_elapsed)
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
int attributes() const { return m_attributes; }
|
||||
void set_attributes(int a) { m_attributes = a; }
|
||||
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, void* object);
|
||||
virtual char* print(char* first, char* last, Canvas::attributes_list* attributes, rpc::target_type target);
|
||||
|
||||
protected:
|
||||
virtual int64_t value(void* object) = 0;
|
||||
|
||||
@@ -45,9 +45,9 @@
|
||||
|
||||
namespace display {
|
||||
|
||||
WindowText::WindowText(void* object, extent_type margin) :
|
||||
WindowText::WindowText(rpc::target_type target, extent_type margin) :
|
||||
Window(new Canvas, 0, 0, 0, extent_static, extent_static),
|
||||
m_object(object),
|
||||
m_target(target),
|
||||
m_margin(margin),
|
||||
m_interval(0) {
|
||||
}
|
||||
@@ -95,7 +95,7 @@ WindowText::redraw() {
|
||||
Canvas::attributes_list attributes;
|
||||
attributes.push_back(Attributes(buffer, Attributes::a_normal, Attributes::color_default));
|
||||
|
||||
char* last = (*itr)->print(buffer, buffer + m_canvas->width(), &attributes, m_object);
|
||||
char* last = (*itr)->print(buffer, buffer + m_canvas->width(), &attributes, m_target);
|
||||
|
||||
m_canvas->print_attributes(0, position, buffer, last, &attributes);
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ public:
|
||||
using base_type::rbegin;
|
||||
using base_type::rend;
|
||||
|
||||
WindowText(void* object = NULL, extent_type margin = 0);
|
||||
WindowText(rpc::target_type target = rpc::make_target(), extent_type margin = 0);
|
||||
~WindowText() { clear(); }
|
||||
|
||||
void clear();
|
||||
|
||||
void* object() const { return m_object; }
|
||||
void set_object(void* object) { m_object = object; }
|
||||
rpc::target_type target() const { return m_target; }
|
||||
void set_target(rpc::target_type target) { m_target = target; }
|
||||
|
||||
uint32_t interval() const { return m_interval; }
|
||||
void set_interval(uint32_t i) { m_interval = i; }
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
void* m_object;
|
||||
rpc::target_type m_target;
|
||||
|
||||
extent_type m_margin;
|
||||
uint32_t m_interval;
|
||||
|
||||
Reference in New Issue
Block a user