* Changed function calls in torrent::Download to be const.

* Cleaned up the code that handles printing of download stats, uses a
char* for buffer for output more flexible concatenation. Closed
torrents are displayed correctly now.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@497 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2005-07-13 13:05:08 +00:00
parent 568dcc0b91
commit d02ded1d4c
5 changed files with 82 additions and 54 deletions
+1
View File
@@ -57,6 +57,7 @@ public:
void release_download();
torrent::Download& get_download() { return m_download; }
const torrent::Download& get_download() const { return m_download; }
std::string get_hash() { return m_download.get_hash(); }
torrent::Bencode& get_bencode() { return torrent::download_bencode(m_download.get_hash()); }
+45 -13
View File
@@ -38,6 +38,7 @@
#include <sstream>
#include <iomanip>
#include <torrent/rate.h>
#include "core/download.h"
#include "utils/timer.h"
@@ -46,23 +47,54 @@
namespace display {
std::string
print_download_status(core::Download* d) {
if (d->get_download().is_hash_checking()) {
return "Checking hash";
char*
print_download_title(char* buf, unsigned int length, core::Download* d) {
return buf + std::max(0, snprintf(buf, length, "%s",
d->get_download().get_name().c_str()));
}
} else if (d->get_download().is_tracker_busy()) {
return "Tracker: Connecting";
char*
print_download_info(char* buf, unsigned int length, core::Download* d) {
char* last = buf + length;
} else if (!d->get_download().is_active()) {
return "Inactive";
buf += std::max(0, snprintf(buf, last - buf, "Torrent: "));
} else if (!d->get_message().empty()) {
return d->get_message();
if (!d->get_download().is_open())
buf += std::max(0, snprintf(buf, last - buf, "closed "));
else if (d->is_done())
buf += std::max(0, snprintf(buf, last - buf, "done %10.1f MB",
(double)d->get_download().get_bytes_total() / (double)(1 << 20)));
else
buf += std::max(0, snprintf(buf, last - buf, "%6.1f / %6.1f MB",
(double)d->get_download().get_bytes_done() / (double)(1 << 20),
(double)d->get_download().get_bytes_total() / (double)(1 << 20)));
buf += std::max(0, snprintf(buf, last - buf, " Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
(double)d->get_download().get_write_rate().rate() / (1 << 10),
(double)d->get_download().get_read_rate().rate() / (1 << 10),
(double)d->get_download().get_write_rate().total() / (1 << 20)));
} else {
return "";
}
return buf;
}
char*
print_download_status(char* buf, unsigned int length, core::Download* d) {
if (d->get_download().is_hash_checking())
buf += std::max(0, snprintf(buf, length, "Checking hash"));
else if (d->get_download().is_tracker_busy())
buf += std::max(0, snprintf(buf, length, "Tracker: Connecting"));
else if (!d->get_download().is_active())
buf += std::max(0, snprintf(buf, length, "Inactive"));
else if (!d->get_message().empty())
buf += std::max(0, snprintf(buf, length, "%s", d->get_message().c_str()));
else
buf[0] = '\0';
return buf;
}
std::string
+3 -1
View File
@@ -50,7 +50,9 @@ namespace utils {
namespace display {
std::string print_download_status(core::Download* d);
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);
+11 -26
View File
@@ -36,8 +36,6 @@
#include "config.h"
#include <torrent/rate.h>
#include "core/download.h"
#include "rak/algorithm.h"
@@ -64,7 +62,7 @@ WindowDownloadList::redraw() {
m_canvas->erase();
if (m_list->base().empty())
if (m_list->base().empty() || m_canvas->get_width() < 5)
return;
typedef std::pair<DList::iterator, DList::iterator> Range;
@@ -83,31 +81,18 @@ WindowDownloadList::redraw() {
int pos = 0;
while (range.first != range.second) {
torrent::Download& d = (*range.first)->get_download();
char buffer[m_canvas->get_width() - 2];
char* position;
char* last = buffer + m_canvas->get_width() - 2;
m_canvas->print(0, pos++, "%c %s",
range.first == m_list->get_focus() ? '*' : ' ',
d.get_name().c_str());
if ((*range.first)->is_open() && (*range.first)->is_done())
m_canvas->print(0, pos++, "%c Torrent: Done %10.1f MiB Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
range.first == m_list->get_focus() ? '*' : ' ',
(double)d.get_bytes_total() / (double)(1 << 20),
(double)d.get_write_rate().rate() / 1024.0,
(double)d.get_read_rate().rate() / 1024.0,
(double)d.get_write_rate().total() / (double)(1 << 20));
else
m_canvas->print(0, pos++, "%c Torrent: %6.1f / %6.1f MiB Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
range.first == m_list->get_focus() ? '*' : ' ',
(double)d.get_bytes_done() / (double)(1 << 20),
(double)d.get_bytes_total() / (double)(1 << 20),
(double)d.get_write_rate().rate() / 1024.0,
(double)d.get_read_rate().rate() / 1024.0,
(double)d.get_write_rate().total() / (double)(1 << 20));
position = print_download_title(buffer, last - buffer, *range.first);
m_canvas->print(0, pos++, "%c %s", range.first == m_list->get_focus() ? '*' : ' ', buffer);
m_canvas->print(0, pos++, "%c %s",
range.first == m_list->get_focus() ? '*' : ' ',
print_download_status(*range.first).c_str());
position = print_download_info(buffer, last - buffer, *range.first);
m_canvas->print(0, pos++, "%c %s", range.first == m_list->get_focus() ? '*' : ' ', buffer);
position = print_download_status(buffer, last - buffer, *range.first);
m_canvas->print(0, pos++, "%c %s", range.first == m_list->get_focus() ? '*' : ' ', buffer);
++range.first;
}
+22 -14
View File
@@ -57,20 +57,27 @@ WindowDownloadStatusbar::redraw() {
m_canvas->erase();
if (m_download->get_download().get_chunks_done() != m_download->get_download().get_chunks_total() || !m_download->get_download().is_open())
m_canvas->print(0, 0, "Torrent: %.1f / %.1f MiB Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
(double)m_download->get_download().get_bytes_done() / (double)(1 << 20),
(double)m_download->get_download().get_bytes_total() / (double)(1 << 20),
(double)m_download->get_download().get_write_rate().rate() / 1024.0,
(double)m_download->get_download().get_read_rate().rate() / 1024.0,
(double)m_download->get_download().get_write_rate().total() / (double)(1 << 20));
char buffer[m_canvas->get_width() - 2];
char* position;
char* last = buffer + m_canvas->get_width() - 2;
position = print_download_info(buffer, last - buffer, m_download);
m_canvas->print(0, 0, "%s", buffer);
// if (m_download->get_download().get_chunks_done() != m_download->get_download().get_chunks_total() || !m_download->get_download().is_open())
// m_canvas->print(0, 0, "Torrent: %.1f / %.1f MiB Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
// (double)m_download->get_download().get_bytes_done() / (double)(1 << 20),
// (double)m_download->get_download().get_bytes_total() / (double)(1 << 20),
// (double)m_download->get_download().get_write_rate().rate() / 1024.0,
// (double)m_download->get_download().get_read_rate().rate() / 1024.0,
// (double)m_download->get_download().get_write_rate().total() / (double)(1 << 20));
else
m_canvas->print(0, 0, "Torrent: Done %.1f MiB Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
(double)m_download->get_download().get_bytes_total() / (double)(1 << 20),
(double)m_download->get_download().get_write_rate().rate() / 1024.0,
(double)m_download->get_download().get_read_rate().rate() / 1024.0,
(double)m_download->get_download().get_write_rate().total() / (double)(1 << 20));
// else
// m_canvas->print(0, 0, "Torrent: Done %.1f MiB Rate: %5.1f / %5.1f KiB Uploaded: %.1f MiB",
// (double)m_download->get_download().get_bytes_total() / (double)(1 << 20),
// (double)m_download->get_download().get_write_rate().rate() / 1024.0,
// (double)m_download->get_download().get_read_rate().rate() / 1024.0,
// (double)m_download->get_download().get_write_rate().total() / (double)(1 << 20));
m_canvas->print(0, 1, "Peers: %i(%i) Min/Max: %i/%i Uploads: %i",
(int)m_download->get_download().get_peers_connected(),
@@ -79,10 +86,11 @@ WindowDownloadStatusbar::redraw() {
(int)m_download->get_download().get_peers_max(),
(int)m_download->get_download().get_uploads_max());
position = print_download_status(buffer, last - buffer, m_download);
m_canvas->print(0, 2, "[%c:%i] %s",
m_download->get_download().is_tracker_busy() ? 'C' : ' ',
(int)(m_download->get_download().get_tracker_timeout() / 1000000),
print_download_status(m_download).c_str());
buffer);
}
}