mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-12 13:12:32 +00:00
Added file view.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@322 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -13,6 +13,8 @@ libsub_display_a_SOURCES = \
|
||||
window_download_list.h \
|
||||
window_download_statusbar.cc \
|
||||
window_download_statusbar.h \
|
||||
window_file_list.cc \
|
||||
window_file_list.h \
|
||||
window_http_queue.cc \
|
||||
window_http_queue.h \
|
||||
window_input.cc \
|
||||
|
||||
+11
-7
@@ -34,28 +34,32 @@ public:
|
||||
chtype tl, chtype tr,
|
||||
chtype bl, chtype br) { wborder(m_window, ls, rs, ts, bs, tl, tr, bl, br); }
|
||||
|
||||
void print(int x, int y, const char* str) { mvwprintw(m_window, y, x, str); }
|
||||
// The format string is non-const, but that will not be a problem
|
||||
// since the string shall always be a C string choosen at
|
||||
// compiletime. Might cause extra copying of the string?
|
||||
|
||||
void print(int x, int y, char* str) { mvwprintw(m_window, y, x, str); }
|
||||
|
||||
template <typename A1>
|
||||
void print(int x, int y, const char* str, A1 a1) { mvwprintw(m_window, y, x, str, a1); }
|
||||
void print(int x, int y, char* str, A1 a1) { mvwprintw(m_window, y, x, str, a1); }
|
||||
|
||||
template <typename A1, typename A2>
|
||||
void print(int x, int y, const char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); }
|
||||
void print(int x, int y, char* str, A1 a1, A2 a2) { mvwprintw(m_window, y, x, str, a1, a2); }
|
||||
|
||||
template <typename A1, typename A2, typename A3>
|
||||
void print(int x, int y, const char* str,
|
||||
void print(int x, int y, char* str,
|
||||
A1 a1, A2 a2, A3 a3) { mvwprintw(m_window, y, x, str, a1, a2, a3); }
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4>
|
||||
void print(int x, int y, const char* str,
|
||||
void print(int x, int y, char* str,
|
||||
A1 a1, A2 a2, A3 a3, A4 a4) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4); }
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
void print(int x, int y, const char* str,
|
||||
void print(int x, int y, char* str,
|
||||
A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5); }
|
||||
|
||||
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
|
||||
void print(int x, int y, const char* str,
|
||||
void print(int x, int y, char* str,
|
||||
A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { mvwprintw(m_window, y, x, str, a1, a2, a3, a4, a5, a6); }
|
||||
|
||||
void set_attr(int x, int y, int n, int attr, int color) { mvwchgat(m_window, y, x, n, attr, color, NULL); }
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
#include "window_file_list.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
WindowFileList::WindowFileList(core::Download* d, int* focus) :
|
||||
Window(new Canvas, true),
|
||||
m_download(d),
|
||||
m_focus(focus) {
|
||||
}
|
||||
|
||||
void
|
||||
WindowFileList::redraw() {
|
||||
m_nextDraw = utils::Timer::cache().round_seconds() + 10 * 1000000;
|
||||
m_canvas->erase();
|
||||
|
||||
int y1 = 0;
|
||||
int y2 = m_canvas->get_height();
|
||||
|
||||
m_canvas->print( 2, y1, "File");
|
||||
m_canvas->print(55, y1, "Size");
|
||||
m_canvas->print(62, y1, "Pri");
|
||||
m_canvas->print(67, y1, "Cmpl");
|
||||
|
||||
++y1;
|
||||
|
||||
int files = m_download->get_download().get_entry_size();
|
||||
int index = std::min<unsigned>(std::max<signed>(*m_focus - (y2 - y1) / 2, 0), files - (y2 - y1));
|
||||
|
||||
while (index < files && y1 < y2) {
|
||||
torrent::Entry e = m_download->get_download().get_entry(index);
|
||||
|
||||
std::string path = e.get_path();
|
||||
|
||||
if (path.length() <= 50)
|
||||
path = path + std::string(50 - path.length(), ' ');
|
||||
else
|
||||
path = path.substr(0, 50);
|
||||
|
||||
std::string priority;
|
||||
|
||||
switch (e.get_priority()) {
|
||||
case torrent::Entry::STOPPED:
|
||||
priority = "off";
|
||||
break;
|
||||
|
||||
case torrent::Entry::NORMAL:
|
||||
priority = " ";
|
||||
break;
|
||||
|
||||
case torrent::Entry::HIGH:
|
||||
priority = "hig";
|
||||
break;
|
||||
|
||||
default:
|
||||
priority = "BUG";
|
||||
break;
|
||||
};
|
||||
|
||||
m_canvas->print(0, y1, "%c %s %5.1f %s %3d",
|
||||
index == *m_focus ? '*' : ' ',
|
||||
path.c_str(),
|
||||
(double)e.get_size() / (double)(1 << 20),
|
||||
priority.c_str(),
|
||||
done_percentage(e));
|
||||
|
||||
++index;
|
||||
++y1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
WindowFileList::done_percentage(torrent::Entry& e) {
|
||||
int chunks = e.get_chunk_end() - e.get_chunk_begin();
|
||||
|
||||
return chunks ? (e.get_completed() * 100) / chunks : 100;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef RTORRENT_DISPLAY_FILE_LIST_H
|
||||
#define RTORRENT_DISPLAY_FILE_LIST_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
namespace torrent {
|
||||
class Entry;
|
||||
}
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace display {
|
||||
|
||||
class WindowFileList : public Window {
|
||||
public:
|
||||
WindowFileList(core::Download* d, int* focus);
|
||||
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
int done_percentage(torrent::Entry& e);
|
||||
|
||||
core::Download* m_download;
|
||||
|
||||
int* m_focus;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -23,12 +23,13 @@ WindowPeerInfo::redraw() {
|
||||
m_canvas->erase();
|
||||
|
||||
int y = 0;
|
||||
torrent::Download d = m_download->get_download();
|
||||
|
||||
m_canvas->print(0, y++, "Hash: %s", utils::string_to_hex(m_download->get_download().get_hash()).c_str());
|
||||
m_canvas->print(0, y++, "Hash: %s", utils::string_to_hex(d.get_hash()).c_str());
|
||||
m_canvas->print(0, y++, "Chunks: %u / %u * %u",
|
||||
m_download->get_download().get_chunks_done(),
|
||||
m_download->get_download().get_chunks_total(),
|
||||
m_download->get_download().get_chunks_size());
|
||||
d.get_chunks_done(),
|
||||
d.get_chunks_total(),
|
||||
d.get_chunks_size());
|
||||
|
||||
y++;
|
||||
|
||||
@@ -41,7 +42,8 @@ WindowPeerInfo::redraw() {
|
||||
m_canvas->print(0, y++, "DNS: %s:%hu", (*m_focus)->get_dns().c_str(), (*m_focus)->get_port());
|
||||
m_canvas->print(0, y++, "Id: %s" , utils::escape_string((*m_focus)->get_id()).c_str());
|
||||
m_canvas->print(0, y++, "Snubbed: %s", (*m_focus)->get_snubbed() ? "Yes" : "No");
|
||||
m_canvas->print(0, y++, "Done: %i%", (*m_focus)->get_chunks_done());
|
||||
|
||||
m_canvas->print(0, y++, "Done: %i%", d.get_chunks_total() ? (*m_focus)->get_chunks_done() / d.get_chunks_total() : 0);
|
||||
|
||||
m_canvas->print(0, y++, "Rate: %5.1f/%5.1f KB Total: %.1f/%.1f MB",
|
||||
(double)(*m_focus)->get_rate_up() / (double)(1 << 10),
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define RTORRENT_DISPLAY_PEER_INFO_H
|
||||
|
||||
#include <list>
|
||||
#include <sigc++/slot.h>
|
||||
#include <torrent/peer.h>
|
||||
|
||||
#include "window.h"
|
||||
@@ -16,12 +15,9 @@ namespace display {
|
||||
class WindowPeerInfo : public Window {
|
||||
public:
|
||||
typedef std::list<torrent::Peer> PList;
|
||||
typedef sigc::slot0<uint32_t> SlotChunksTotal;
|
||||
|
||||
WindowPeerInfo(core::Download* d, PList* l, PList::iterator* f);
|
||||
|
||||
void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; }
|
||||
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
@@ -29,8 +25,6 @@ private:
|
||||
|
||||
PList* m_list;
|
||||
PList::iterator* m_focus;
|
||||
|
||||
SlotChunksTotal m_slotChunksTotal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "core/download.h"
|
||||
|
||||
#include "canvas.h"
|
||||
#include "window_peer_list.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
WindowPeerList::WindowPeerList(PList* l, PList::iterator* f) :
|
||||
WindowPeerList::WindowPeerList(core::Download* d, PList* l, PList::iterator* f) :
|
||||
Window(new Canvas, true),
|
||||
m_download(d),
|
||||
m_list(l),
|
||||
m_focus(f) {
|
||||
}
|
||||
@@ -59,9 +62,7 @@ WindowPeerList::redraw() {
|
||||
last = m_list->end();
|
||||
}
|
||||
|
||||
uint32_t chunksTotal = m_slotChunksTotal();
|
||||
|
||||
if (chunksTotal <= 0)
|
||||
if (m_download->get_download().get_chunks_total() <= 0)
|
||||
throw std::logic_error("WindowPeerList::redraw() m_slotChunksTotal() returned invalid value");
|
||||
|
||||
while (itr != m_list->end() && y < m_canvas->get_height()) {
|
||||
@@ -97,7 +98,7 @@ WindowPeerList::redraw() {
|
||||
itr->get_incoming_queue_size());
|
||||
x += 6;
|
||||
|
||||
m_canvas->print(x, y, "%3i", (itr->get_chunks_done() * 100) / chunksTotal);
|
||||
m_canvas->print(x, y, "%3i", (itr->get_chunks_done() * 100) / m_download->get_download().get_chunks_total());
|
||||
x += 6;
|
||||
|
||||
if (itr->get_incoming_queue_size())
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
#define RTORRENT_DISPLAY_PEER_LIST_H
|
||||
|
||||
#include <list>
|
||||
#include <sigc++/slot.h>
|
||||
#include <torrent/peer.h>
|
||||
|
||||
#include "window.h"
|
||||
|
||||
namespace core {
|
||||
class Download;
|
||||
}
|
||||
|
||||
namespace display {
|
||||
|
||||
class WindowPeerList : public Window {
|
||||
public:
|
||||
typedef std::list<torrent::Peer> PList;
|
||||
typedef sigc::slot0<uint32_t> SlotChunksTotal;
|
||||
|
||||
WindowPeerList(PList* l, PList::iterator* f);
|
||||
|
||||
void slot_chunks_total(SlotChunksTotal s) { m_slotChunksTotal = s; }
|
||||
WindowPeerList(core::Download* d, PList* l, PList::iterator* f);
|
||||
|
||||
virtual void redraw();
|
||||
|
||||
private:
|
||||
core::Download* m_download;
|
||||
|
||||
PList* m_list;
|
||||
PList::iterator* m_focus;
|
||||
|
||||
SlotChunksTotal m_slotChunksTotal;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user