* Got rid of some additional internal sigc++ calls.

* Changed print_hhmmss/ddmmyyyy to use a char buffer.

* Added error messages for failed torrent http/file downloads which
includes the url/filename.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@581 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-10-17 19:19:48 +00:00
parent c99cc03d19
commit 45781e8dbf
7 changed files with 68 additions and 30 deletions
+23
View File
@@ -393,6 +393,23 @@ private:
Function m_function;
};
template <typename Object, typename Ret, typename Arg1>
class const_mem_fn1 {
public:
typedef Ret (Object::*Function)(Arg1) const;
const_mem_fn1() : m_object(NULL) {}
const_mem_fn1(Object* o, Function f) : m_object(o), m_function(f) {}
bool is_valid() const { return m_object; }
Ret operator () (Arg1 a1) { return (m_object->*m_function)(a1); }
private:
Object* m_object;
Function m_function;
};
template <typename Object, typename Ret, typename Arg1, typename Arg2>
class mem_fn2 {
public:
@@ -445,6 +462,12 @@ make_mem_fn(Object* o, Ret (Object::*f)(Arg1)) {
return mem_fn1<Object, Ret, Arg1>(o, f);
}
template <typename Object, typename Ret, typename Arg1>
inline const_mem_fn1<Object, Ret, Arg1>
make_mem_fn(Object* o, Ret (Object::*f)(Arg1) const) {
return const_mem_fn1<Object, Ret, Arg1>(o, f);
}
template <typename Object, typename Ret, typename Arg1, typename Arg2>
inline mem_fn2<Object, Ret, Arg1, Arg2>
make_mem_fn(Object* o, Ret (Object::*f)(Arg1, Arg2)) {
+2
View File
@@ -160,6 +160,8 @@ DownloadFactory::receive_failed(const std::string& msg) {
throw std::logic_error("DownloadFactory::receive_success() called on an object with m_stream == NULL");
// Add message to log.
m_manager->get_log_important().push_front(msg + ": \"" + m_uri + "\"");
m_manager->get_log_complete().push_front(msg + ": \"" + m_uri + "\"");
m_slotFinished();
}
+20 -18
View File
@@ -36,6 +36,7 @@
#include "config.h"
#include <cstring>
#include <sstream>
#include <iomanip>
#include <torrent/rate.h>
@@ -48,6 +49,16 @@
namespace display {
char*
print_string(char* buf, unsigned int length, char* str) {
// We don't have any nice simple functions for copying strings that
// return the end address.
while (length-- != 0 && *str != '\0')
*(buf++) = *(str++);
return buf;
}
char*
print_download_title(char* buf, unsigned int length, core::Download* d) {
return buf + std::max(0, snprintf(buf, length, "%s",
@@ -102,37 +113,28 @@ print_download_status(char* buf, unsigned int length, core::Download* d) {
return buf;
}
std::string
print_hhmmss(utils::Timer t) {
time_t tv_sec = static_cast<time_t>(t.tval().tv_sec);
std::tm *u = std::localtime(&tv_sec);
char*
print_hhmmss(char* buf, unsigned int length, time_t t) {
std::tm *u = std::localtime(&t);
if (u == NULL)
return "inv_time";
std::stringstream str;
str.fill('0');
str << std::setw(2) << u->tm_hour << ':' << std::setw(2) << u->tm_min << ':' << std::setw(2) << u->tm_sec;
unsigned int s = snprintf(buf, length, "%02u:%02u:%02u", u->tm_hour, u->tm_min, u->tm_sec);
return str.str();
return buf + std::min(s, length);
}
std::string
print_ddmmyyyy(time_t t) {
char*
print_ddmmyyyy(char* buf, unsigned int length, time_t t) {
std::tm *u = std::gmtime(&t);
if (u == NULL)
return "inv_time";
std::stringstream str;
str.fill('0');
str << std::setw(2) << u->tm_mday << '/'
<< std::setw(2) << (u->tm_mon + 1) << '/'
<< std::setw(4) << (1900 + u->tm_year);
unsigned int s = snprintf(buf, length, "%02u/%02u/%04u", u->tm_mday, (u->tm_mon + 1), (1900 + u->tm_year));
return str.str();
return buf + std::min(s, length);
}
}
+4 -2
View File
@@ -50,12 +50,14 @@ namespace utils {
namespace display {
char* print_string(char* buf, unsigned int length, char* str);
char* print_download_title(char* buf, unsigned int length, core::Download* d);
char* print_download_info(char* buf, unsigned int length, core::Download* d);
char* print_download_status(char* buf, unsigned int length, core::Download* d);
std::string print_hhmmss(utils::Timer t);
std::string print_ddmmyyyy(time_t t);
char* print_hhmmss(char* buf, unsigned int length, time_t t);
char* print_ddmmyyyy(char* buf, unsigned int length, time_t t);
}
+6 -4
View File
@@ -69,10 +69,12 @@ WindowLog::redraw() {
int pos = 0;
for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr)
m_canvas->print(0, pos++, "(%s) %s",
print_hhmmss(itr->first).c_str(),
itr->second.c_str());
for (core::Log::iterator itr = m_log->begin(), end = find_older(); itr != end && pos < m_canvas->get_height(); ++itr) {
char buffer[16];
print_hhmmss(buffer, 16, static_cast<time_t>(itr->first.seconds()));
m_canvas->print(0, pos++, "(%s) %s", buffer, itr->second.c_str());
}
}
void
+6 -4
View File
@@ -69,10 +69,12 @@ WindowLogComplete::redraw() {
m_canvas->print(std::max(0, (int)m_canvas->get_width() / 2 - 5), pos++, "*** Log ***");
for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->get_height(); ++itr)
m_canvas->print(0, pos++, "(%s) %s",
print_hhmmss(itr->first).c_str(),
itr->second.c_str());
for (core::Log::iterator itr = m_log->begin(), e = m_log->end(); itr != e && pos < m_canvas->get_height(); ++itr) {
char buffer[16];
print_hhmmss(buffer, 16, static_cast<time_t>(itr->first.seconds()));
m_canvas->print(0, pos++, "(%s) %s", buffer, itr->second.c_str());
}
}
void
+7 -2
View File
@@ -69,8 +69,13 @@ WindowPeerInfo::redraw() {
d.get_chunks_done(),
d.get_chunks_total(),
d.get_chunks_size());
m_canvas->print(0, y++, "Created: %s",
print_ddmmyyyy(static_cast<time_t>(d.get_creation_date())).c_str());
char buffer[32], *position;
position = print_ddmmyyyy(buffer, 32, static_cast<time_t>(d.get_creation_date()));
position = print_string(position, buffer + 32 - position, " ");
position = print_hhmmss(position, buffer + 32 - position, static_cast<time_t>(d.get_creation_date()));
m_canvas->print(0, y++, "Created: %s", buffer);
y++;