updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / rtorrent-extended / ui_karabaja_mod.patch
blobc8893129095de1400d7b7441766322bb3a6444ef
1 diff --git a/src/display/canvas.cc b/src/display/canvas.cc
2 index 4e621df..35244eb 100644
3 --- a/src/display/canvas.cc
4 +++ b/src/display/canvas.cc
5 @@ -92,6 +92,14 @@ Canvas::initialize() {
6 m_isInitialized = true;
8 initscr();
9 +
10 + //colors
11 + start_color();
12 + use_default_colors();
13 + init_pair(1, COLOR_RED, -1);
14 + init_pair(2, COLOR_YELLOW, -1);
15 + init_pair(3, COLOR_GREEN, -1);
17 raw();
18 noecho();
19 nodelay(stdscr, TRUE);
20 diff --git a/src/display/utils.cc b/src/display/utils.cc
21 index d2f1af4..400b940 100644
22 --- a/src/display/utils.cc
23 +++ b/src/display/utils.cc
24 @@ -34,6 +34,9 @@
25 // Skomakerveien 33
26 // 3185 Skoppum, NORWAY
28 +// interface modifications by karabaja4
29 +// <karabaja4@archlinux.us>
31 #include "config.h"
33 #include <cstring>
34 @@ -52,6 +55,10 @@
35 #include <torrent/data/file_list.h>
36 #include <torrent/peer/client_info.h>
38 +//peers
39 +#include <torrent/peer/connection_list.h>
40 +#include <torrent/peer/peer_list.h>
42 #include "core/download.h"
43 #include "core/manager.h"
44 #include "rpc/parse_commands.h"
45 @@ -96,9 +103,9 @@ print_hhmmss_local(char* first, char* last, time_t t) {
46 char*
47 print_ddhhmm(char* first, char* last, time_t t) {
48 if (t / (24 * 3600) < 100)
49 - return print_buffer(first, last, "%2id %2i:%02i", (int)t / (24 * 3600), ((int)t / 3600) % 24, ((int)t / 60) % 60);
50 + return print_buffer(first, last, "%id:%ih:%im", (int)t / (24 * 3600), ((int)t / 3600) % 24, ((int)t / 60) % 60);
51 else
52 - return print_buffer(first, last, "--d --:--");
53 + return print_buffer(first, last, "--d:--h:--m");
56 char*
57 @@ -127,91 +134,121 @@ print_address(char* first, char* last, const sockaddr* sa) {
59 char*
60 print_download_title(char* first, char* last, core::Download* d) {
61 - return print_buffer(first, last, " %s", d->download()->name().c_str());
63 + first = print_buffer(first, last, " %s", d->download()->name().c_str());
65 + if (first > last)
66 + throw torrent::internal_error("print_download_status(...) wrote past end of the buffer.");
68 + return first;
72 char*
73 -print_download_info(char* first, char* last, core::Download* d) {
74 - if (!d->download()->is_open())
75 - first = print_buffer(first, last, "[CLOSED] ");
76 - else if (!d->download()->is_active())
77 - first = print_buffer(first, last, "[OPEN] ");
78 - else
79 - first = print_buffer(first, last, " ");
80 +print_download_title_extra(char* first, char* last, core::Download* d) {
82 + if (d->is_hash_checking()) {
83 + first = print_buffer(first, last, " | Checking hash [%2i%%]",
84 + (d->download()->chunks_hashed() * 100) / d->download()->file_list()->size_chunks());
85 + }
86 + else if (d->tracker_list()->has_active() && d->tracker_list()->focus() < d->tracker_list()->end()) {
88 + torrent::TrackerList* tl = d->tracker_list();
89 + char status[128];
91 + (*tl->focus())->get_status(status, sizeof(status));
92 + first = print_buffer(first, last, " | Tracker[%i:%i]: Connecting to %s %s",
93 + (*tl->focus())->group(), tl->focus_index(), (*tl->focus())->url().c_str(), status);
94 + }
95 + else if (!d->message().empty()) {
96 + first = print_buffer(first, last, " | %s", d->message().c_str());
97 + }
98 + else {
99 + *first = '\0';
102 + if (first > last)
103 + throw torrent::internal_error("print_download_status(...) wrote past end of the buffer.");
105 + return first;
109 - if (d->is_done())
110 - first = print_buffer(first, last, "done %10.1f MB", (double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
111 - else
112 - first = print_buffer(first, last, "%6.1f / %6.1f MB",
113 - (double)d->download()->bytes_done() / (double)(1 << 20),
114 - (double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
116 - first = print_buffer(first, last, " Rate: %5.1f / %5.1f KB Uploaded: %7.1f MB",
117 - (double)d->download()->up_rate()->rate() / (1 << 10),
118 - (double)d->download()->down_rate()->rate() / (1 << 10),
119 - (double)d->download()->up_rate()->total() / (1 << 20));
121 - if (d->download()->is_active() && !d->is_done()) {
122 - first = print_buffer(first, last, " ");
123 - first = print_download_percentage_done(first, last, d);
125 - first = print_buffer(first, last, " ");
126 - first = print_download_time_left(first, last, d);
127 - } else {
128 - first = print_buffer(first, last, " ");
130 +char*
131 +print_download_info(char* first, char* last, core::Download* d) {
133 + if (!d->download()->is_open()) {
134 + first = print_buffer(first, last, " CLOSED |");
136 + else if (!d->download()->is_active()) {
137 + first = print_buffer(first, last, " PAUSED |");
139 + else {
140 + first = print_buffer(first, last, " ACTIVE |");
143 + if (d->is_done()) {
144 + first = print_buffer(first, last, " finished %.1f MB [100%%] |", (double)d->download()->file_list()->size_bytes() / (double)(1 << 20));
146 + else {
147 + first = print_buffer(first, last, " %.1f / %.1f MB [%i%%] |",
148 + (double)d->download()->bytes_done() / (double)(1 << 20),
149 + (double)d->download()->file_list()->size_bytes() / (double)(1 << 20),
150 + (int)(((double)d->download()->bytes_done() / (double)d->download()->file_list()->size_bytes()) * 100));
153 + //speed
154 + first = print_buffer(first, last, " Speed: %.1f / %.1f KB",
155 + (double)d->download()->down_rate()->rate() / (1 << 10),
156 + (double)d->download()->up_rate()->rate() / (1 << 10));
158 + if (d->download()->is_active() && !d->is_done()) {
160 + //peers
161 + first = print_buffer(first, last, " | Peers: %i(%i)",
162 + (int)d->download()->connection_list()->size(),
163 + (int)d->download()->peer_list()->available_list_size());
165 + //eta
166 + first = print_buffer(first, last, " | ETA: ");
167 + first = print_download_time_left(first, last, d);
171 + if (first > last)
172 + throw torrent::internal_error("print_download_info(...) wrote past end of the buffer.");
174 + return first;
177 - first = print_buffer(first, last, " [%c%c R: %4.2f",
178 - rpc::call_command_string("d.get_tied_to_file", rpc::make_target(d)).empty() ? ' ' : 'T',
179 - rpc::call_command_value("d.get_ignore_commands", rpc::make_target(d)) == 0 ? ' ' : 'I',
180 - (double)rpc::call_command_value("d.get_ratio", rpc::make_target(d)) / 1000.0);
181 +char*
182 +print_download_info_extra(char* first, char* last, core::Download* d) {
184 + first = print_buffer(first, last, "[%c%c R: %4.2f",
185 + rpc::call_command_string("d.get_tied_to_file", rpc::make_target(d)).empty() ? ' ' : 'T',
186 + rpc::call_command_value("d.get_ignore_commands", rpc::make_target(d)) == 0 ? ' ' : 'I',
187 + (double)rpc::call_command_value("d.get_ratio", rpc::make_target(d)) / 1000.0);
189 - if (d->priority() != 2)
190 - first = print_buffer(first, last, " %s", rpc::call_command_string("d.get_priority_str", rpc::make_target(d)).c_str());
191 + if (d->priority() != 2)
192 + first = print_buffer(first, last, " %s", rpc::call_command_string("d.get_priority_str", rpc::make_target(d)).c_str());
194 - if (!d->bencode()->get_key("rtorrent").get_key_string("throttle_name").empty())
195 - first = print_buffer(first, last , " %s", rpc::call_command_string("d.get_throttle_name", rpc::make_target(d)).c_str());
196 + if (!d->bencode()->get_key("rtorrent").get_key_string("throttle_name").empty())
197 + first = print_buffer(first, last , " %s", rpc::call_command_string("d.get_throttle_name", rpc::make_target(d)).c_str());
199 - first = print_buffer(first, last , "]");
200 + first = print_buffer(first, last , "]");
202 - if (first > last)
203 - throw torrent::internal_error("print_download_info(...) wrote past end of the buffer.");
204 + if (first > last)
205 + throw torrent::internal_error("print_download_info(...) wrote past end of the buffer.");
207 - return first;
208 + return first;
211 char*
212 print_download_status(char* first, char* last, core::Download* d) {
213 - if (d->is_active())
215 - else if (rpc::call_command_value("d.get_hashing", rpc::make_target(d)) != 0)
216 - first = print_buffer(first, last, "Hashing: ");
217 - else if (!d->is_active())
218 - first = print_buffer(first, last, "Inactive: ");
220 - if (d->is_hash_checking()) {
221 - first = print_buffer(first, last, "Checking hash [%2i%%]",
222 - (d->download()->chunks_hashed() * 100) / d->download()->file_list()->size_chunks());
224 - } else if (d->tracker_list()->has_active() && d->tracker_list()->focus() < d->tracker_list()->end()) {
225 - torrent::TrackerList* tl = d->tracker_list();
226 - char status[128];
228 - (*tl->focus())->get_status(status, sizeof(status));
229 - first = print_buffer(first, last, "Tracker[%i:%i]: Connecting to %s %s",
230 - (*tl->focus())->group(), tl->focus_index(), (*tl->focus())->url().c_str(), status);
232 - } else if (!d->message().empty()) {
233 - first = print_buffer(first, last, "%s", d->message().c_str());
235 - } else {
236 - *first = '\0';
239 - if (first > last)
240 - throw torrent::internal_error("print_download_status(...) wrote past end of the buffer.");
242 + *first = '\0';
243 return first;
247 char*
248 @@ -219,7 +256,7 @@ print_download_time_left(char* first, char* last, core::Download* d) {
249 uint32_t rate = d->download()->down_rate()->rate();
251 if (rate < 512)
252 - return print_buffer(first, last, "--d --:--");
253 + return print_buffer(first, last, "--d:--h:--m");
255 time_t remaining = (d->download()->file_list()->size_bytes() - d->download()->bytes_done()) / (rate & ~(uint32_t)(512 - 1));
257 @@ -230,9 +267,9 @@ char*
258 print_download_percentage_done(char* first, char* last, core::Download* d) {
259 if (!d->is_open() || d->is_done())
260 //return print_buffer(first, last, "[--%%]");
261 - return print_buffer(first, last, " ");
262 + return print_buffer(first, last, " ");
263 else
264 - return print_buffer(first, last, "[%2u%%]", (d->download()->file_list()->completed_chunks() * 100) / d->download()->file_list()->size_chunks());
265 + return print_buffer(first, last, "%u%%", (d->download()->file_list()->completed_chunks() * 100) / d->download()->file_list()->size_chunks());
268 char*
269 @@ -255,19 +292,19 @@ print_client_version(char* first, char* last, const torrent::ClientInfo& clientI
271 char*
272 print_status_info(char* first, char* last) {
273 - if (!torrent::up_throttle_global()->is_throttled())
274 + if (!torrent::down_throttle_global()->is_throttled())
275 first = print_buffer(first, last, "[Throttle off");
276 else
277 - first = print_buffer(first, last, "[Throttle %3i", torrent::up_throttle_global()->max_rate() / 1024);
278 + first = print_buffer(first, last, "[Throttle %3i", torrent::down_throttle_global()->max_rate() / 1024);
280 - if (!torrent::down_throttle_global()->is_throttled())
281 + if (!torrent::up_throttle_global()->is_throttled())
282 first = print_buffer(first, last, "/off KB]");
283 else
284 - first = print_buffer(first, last, "/%3i KB]", torrent::down_throttle_global()->max_rate() / 1024);
285 + first = print_buffer(first, last, "/%3i KB]", torrent::up_throttle_global()->max_rate() / 1024);
287 first = print_buffer(first, last, " [Rate %5.1f/%5.1f KB]",
288 - (double)torrent::up_rate()->rate() / 1024.0,
289 - (double)torrent::down_rate()->rate() / 1024.0);
290 + (double)torrent::down_rate()->rate() / 1024.0,
291 + (double)torrent::up_rate()->rate() / 1024.0);
293 first = print_buffer(first, last, " [Port: %i]", (unsigned int)torrent::connection_manager()->listen_port());
295 diff --git a/src/display/utils.h b/src/display/utils.h
296 index 3d69021..c9145dd 100644
297 --- a/src/display/utils.h
298 +++ b/src/display/utils.h
299 @@ -66,7 +66,9 @@ char* print_ddhhmm(char* first, char* last, time_t t);
300 char* print_ddmmyyyy(char* first, char* last, time_t t);
302 char* print_download_title(char* first, char* last, core::Download* d);
303 +char* print_download_title_extra(char* first, char* last, core::Download* d);
304 char* print_download_info(char* first, char* last, core::Download* d);
305 +char* print_download_info_extra(char* first, char* last, core::Download* d);
306 char* print_download_status(char* first, char* last, core::Download* d);
307 char* print_download_time_left(char* first, char* last, core::Download* d);
308 char* print_download_percentage_done(char* first, char* last, core::Download* d);
309 diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc
310 index 71efec0..353f6b5 100644
311 --- a/src/display/window_download_list.cc
312 +++ b/src/display/window_download_list.cc
313 @@ -34,6 +34,9 @@
314 // Skomakerveien 33
315 // 3185 Skoppum, NORWAY
317 +// interface modifications by karabaja4
318 +// <karabaja4@archlinux.us>
320 #include "config.h"
322 #include <rak/algorithm.h>
323 @@ -81,30 +84,90 @@ WindowDownloadList::redraw() {
324 Range range = rak::advance_bidirectional(m_view->begin_visible(),
325 m_view->focus() != m_view->end_visible() ? m_view->focus() : m_view->begin_visible(),
326 m_view->end_visible(),
327 - m_canvas->height() / 3);
328 + (m_canvas->height() - 1) / 3);
330 // Make sure we properly fill out the last lines so it looks like
331 // there are more torrents, yet don't hide it if we got the last one
332 // in focus.
333 if (range.second != m_view->end_visible())
334 - ++range.second;
335 + ++range.second;
337 - int pos = 1;
338 + int pos = 2;
340 while (range.first != range.second) {
341 char buffer[m_canvas->width() + 1];
342 char* position;
343 char* last = buffer + m_canvas->width() - 2 + 1;
345 + int title_length;
347 + //1 = red
348 + //2 = yellow
349 + //3 = green
351 + //do not print on last lines if cannot show whole torrent
352 + if (pos >= (m_canvas->height() - 1))
353 + break;
355 + //print title
356 position = print_download_title(buffer, last, *range.first);
357 - m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
358 + title_length = strlen(buffer);
359 + m_canvas->print(0, pos, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
361 + //title color
362 + if ((*range.first)->is_done()) {
363 + //finished
364 + m_canvas->set_attr(3, pos, (title_length - 1), A_NORMAL, 3);
366 + else {
367 + //not finished
368 + m_canvas->set_attr(3, pos, (title_length - 1), A_NORMAL, 2);
371 + //print title extra
372 + position = print_download_title_extra(buffer, last, *range.first);
374 + //do not let title extra get off screen
375 + buffer[m_canvas->width() - title_length - 2] = '\0';
377 + m_canvas->print((title_length + 2), pos++, "%s", buffer);
379 + //print info
380 position = print_download_info(buffer, last, *range.first);
381 - m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
383 - position = print_download_status(buffer, last, *range.first);
384 - m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
386 + m_canvas->print(0, pos, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
388 + //info color
389 + if (!(*range.first)->download()->is_open()) {
390 + //closed
391 + m_canvas->set_attr(3, pos, 6, A_NORMAL, 1);
393 + else if (!(*range.first)->download()->is_active()) {
394 + //paused
395 + m_canvas->set_attr(3, pos, 6, A_NORMAL, 2);
397 + else {
398 + //active
399 + m_canvas->set_attr(3, pos, 6, A_NORMAL, 3);
402 + if ((*range.first)->is_done()) {
403 + //finished
404 + m_canvas->set_attr(12, pos, 8, A_NORMAL, 3);
407 + //do not print info extra if it collides with info
408 + if ((strlen(buffer) + 2) <= (m_canvas->width() - 16)) {
410 + //print info extra
411 + position = print_download_info_extra(buffer, last, *range.first);
412 + m_canvas->print((m_canvas->width() - 17), pos++, "%s", buffer);
415 + else {
416 + pos++;
419 + //skip one line
420 + pos++;
421 ++range.first;
424 diff --git a/src/display/window_title.cc b/src/display/window_title.cc
425 index 300f655..c0e7fe5 100644
426 --- a/src/display/window_title.cc
427 +++ b/src/display/window_title.cc
428 @@ -48,6 +48,10 @@ WindowTitle::redraw() {
430 m_canvas->print(std::max(0, ((int)m_canvas->width() - (int)m_title.size()) / 2 - 4), 0,
431 "*** %s ***", m_title.c_str());
433 + //set color in title
434 + m_canvas->set_attr((((int)m_canvas->width() - (int)m_title.size()) / 2 - 4), 0, 3, A_NORMAL, 2);
435 + m_canvas->set_attr( ((((int)m_canvas->width() - (int)m_title.size()) / 2) + (int)m_title.size() + 1), 0, 3, A_NORMAL, 2);