* 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
+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