updated on Thu Jan 26 00:18:00 UTC 2012
[aur-mirror.git] / rtorrent-extended / ui_canvas_color.patch
blobbc7a460fc88fd8114eac23eb90449dbf42208530
1 diff --git a/src/command_network.cc b/src/command_network.cc
2 index 68f9395..a334926 100644
3 --- a/src/command_network.cc
4 +++ b/src/command_network.cc
5 @@ -572,4 +572,8 @@ initialize_command_network() {
6 // Not really network stuff:
7 ADD_VARIABLE_BOOL ("handshake_log", false);
8 ADD_VARIABLE_STRING("log.tracker", "");
9 + ADD_COMMAND_VALUE_TRI("done_fg_color", rak::make_mem_fun(control->ui(), &ui::Root::set_done_fg_color), rak::make_mem_fun(control->ui(), &ui::Root::get_done_fg_color));
10 + ADD_COMMAND_VALUE_TRI("done_bg_color", rak::make_mem_fun(control->ui(), &ui::Root::set_done_bg_color), rak::make_mem_fun(control->ui(), &ui::Root::get_done_bg_color));
11 + ADD_COMMAND_VALUE_TRI("active_fg_color", rak::make_mem_fun(control->ui(), &ui::Root::set_active_fg_color), rak::make_mem_fun(control->ui(), &ui::Root::get_active_fg_color));
12 + ADD_COMMAND_VALUE_TRI("active_bg_color", rak::make_mem_fun(control->ui(), &ui::Root::set_active_bg_color), rak::make_mem_fun(control->ui(), &ui::Root::get_active_bg_color));
14 diff --git a/src/display/canvas.cc b/src/display/canvas.cc
15 index 4e621df..0c97eea 100644
16 --- a/src/display/canvas.cc
17 +++ b/src/display/canvas.cc
18 @@ -92,6 +92,10 @@ Canvas::initialize() {
19 m_isInitialized = true;
21 initscr();
22 + start_color();
23 + use_default_colors();
24 + init_pair(2, -1, -1);
25 + init_pair(1, -1, -1);
26 raw();
27 noecho();
28 nodelay(stdscr, TRUE);
29 diff --git a/src/display/window_download_list.cc b/src/display/window_download_list.cc
30 index 71efec0..06e7cd4 100644
31 --- a/src/display/window_download_list.cc
32 +++ b/src/display/window_download_list.cc
33 @@ -37,6 +37,7 @@
34 #include "config.h"
36 #include <rak/algorithm.h>
37 +#include <torrent/rate.h>
39 #include "core/download.h"
40 #include "core/view.h"
41 @@ -96,12 +97,30 @@ WindowDownloadList::redraw() {
42 char* position;
43 char* last = buffer + m_canvas->width() - 2 + 1;
45 + if( pos >= m_canvas->height() ) break;
46 position = print_download_title(buffer, last, *range.first);
47 - m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
48 + m_canvas->print(0, pos, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
49 + if( (*range.first)->is_done() ) {
50 + if( (*range.first)->download()->up_rate()->rate() != 0 ) {
51 + m_canvas->set_attr(0, pos, m_canvas->width()-1, A_BOLD, 2);
52 + } else {
53 + m_canvas->set_attr(0, pos, m_canvas->width()-1, A_NORMAL, 2);
54 + }
55 + } else if( (*range.first)->download()->is_active() ) {
56 + if( (*range.first)->download()->down_rate()->rate() != 0 ) {
57 + m_canvas->set_attr(0, pos, m_canvas->width()-1, A_BOLD, 1);
58 + } else {
59 + m_canvas->set_attr(0, pos, m_canvas->width()-1, A_NORMAL, 1);
60 + }
61 + }
62 + pos++;
64 + if( pos >= m_canvas->height() ) break;
66 position = print_download_info(buffer, last, *range.first);
67 m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
69 + if( pos >= m_canvas->height() ) break;
70 position = print_download_status(buffer, last, *range.first);
71 m_canvas->print(0, pos++, "%c %s", range.first == m_view->focus() ? '*' : ' ', buffer);
73 @@ -109,4 +128,40 @@ WindowDownloadList::redraw() {
77 +void
78 +WindowDownloadList::set_done_fg_color(int64_t color) {
79 + short fg, bg;
80 + pair_content(2, &fg, &bg);
81 + if( color < 0 ) color = -1;
82 + color = color % 8;
83 + init_pair(2, (short)color, bg);
86 +void
87 +WindowDownloadList::set_done_bg_color(int64_t color) {
88 + short fg, bg;
89 + pair_content(2, &fg, &bg);
90 + if( color < 0 ) color = -1;
91 + color = color % 8;
92 + init_pair(2, fg, (short)color);
95 +void
96 +WindowDownloadList::set_active_fg_color(int64_t color) {
97 + short fg, bg;
98 + pair_content(1, &fg, &bg);
99 + if( color < 0 ) color = -1;
100 + color = color % 8;
101 + init_pair(1, (short)color, bg);
104 +void
105 +WindowDownloadList::set_active_bg_color(int64_t color) {
106 + short fg, bg;
107 + pair_content(1, &fg, &bg);
108 + if( color < 0 ) color = -1;
109 + color = color % 8;
110 + init_pair(1, fg, (short)color);
114 diff --git a/src/display/window_download_list.h b/src/display/window_download_list.h
115 index 4ce5ea1..313e87b 100644
116 --- a/src/display/window_download_list.h
117 +++ b/src/display/window_download_list.h
118 @@ -59,6 +59,10 @@ public:
119 virtual void redraw();
121 void set_view(core::View* l);
122 + void set_done_fg_color(int64_t color);
123 + void set_done_bg_color(int64_t color);
124 + void set_active_fg_color(int64_t color);
125 + void set_active_bg_color(int64_t color);
127 private:
128 core::View* m_view;
129 diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc
130 index b7d6983..e72bff6 100644
131 --- a/src/ui/download_list.cc
132 +++ b/src/ui/download_list.cc
133 @@ -137,6 +137,11 @@ DownloadList::unfocus_download(core::Download* d) {
134 current_view()->next_focus();
137 +display::WindowDownloadList*
138 +DownloadList::current_window_list() {
139 + return dynamic_cast<ElementDownloadList*>(m_uiArray[DISPLAY_DOWNLOAD_LIST])->window();
142 void
143 DownloadList::activate_display(Display displayType) {
144 if (!is_active())
145 diff --git a/src/ui/download_list.h b/src/ui/download_list.h
146 index dda1b34..11137fa 100644
147 --- a/src/ui/download_list.h
148 +++ b/src/ui/download_list.h
149 @@ -101,6 +101,7 @@ public:
150 void activate_display(Display d);
152 core::View* current_view();
153 + display::WindowDownloadList* current_window_list();
154 void set_current_view(const std::string& name);
156 void slot_open_uri(SlotOpenUri s) { m_slotOpenUri = s; }
157 diff --git a/src/ui/element_download_list.h b/src/ui/element_download_list.h
158 index ed5de30..7c0fb9d 100644
159 --- a/src/ui/element_download_list.h
160 +++ b/src/ui/element_download_list.h
161 @@ -60,6 +60,7 @@ public:
162 void disable();
164 core::View* view() { return m_view; }
165 + WDownloadList* window() { return m_window; }
166 void set_view(core::View* l);
168 void receive_command(const char* cmd);
169 diff --git a/src/ui/root.cc b/src/ui/root.cc
170 index b01f4ed..d344718 100644
171 --- a/src/ui/root.cc
172 +++ b/src/ui/root.cc
173 @@ -44,6 +44,7 @@
175 #include "core/manager.h"
176 #include "display/frame.h"
177 +#include "display/window_download_list.h"
178 #include "display/window_http_queue.h"
179 #include "display/window_title.h"
180 #include "display/window_input.h"
181 @@ -65,7 +66,11 @@ Root::Root() :
182 m_windowTitle(NULL),
183 m_windowHttpQueue(NULL),
184 m_windowInput(NULL),
185 - m_windowStatusbar(NULL) {
186 + m_windowStatusbar(NULL),
187 + done_fg_color(-1),
188 + done_bg_color(-1),
189 + active_fg_color(-1),
190 + active_bg_color(-1) {
193 void
194 @@ -97,6 +102,10 @@ Root::init(Control* c) {
195 setup_keys();
197 m_downloadList->activate(rootFrame->frame(1));
198 + m_downloadList->current_window_list()->set_done_fg_color(done_fg_color);
199 + m_downloadList->current_window_list()->set_done_bg_color(done_bg_color);
200 + m_downloadList->current_window_list()->set_active_fg_color(active_fg_color);
201 + m_downloadList->current_window_list()->set_active_bg_color(active_bg_color);
204 void
205 @@ -219,6 +228,46 @@ Root::set_up_throttle(unsigned int throttle) {
206 torrent::set_max_unchoked(maxUnchoked);
209 +int
210 +Root::get_done_fg_color() {
211 + return done_fg_color;
214 +void
215 +Root::set_done_fg_color(int64_t color) {
216 + done_fg_color = color;
219 +int
220 +Root::get_done_bg_color() {
221 + return done_bg_color;
224 +void
225 +Root::set_done_bg_color(int64_t color) {
226 + done_bg_color = color;
229 +int
230 +Root::get_active_fg_color() {
231 + return active_fg_color;
234 +void
235 +Root::set_active_fg_color(int64_t color) {
236 + active_fg_color = color;
239 +int
240 +Root::get_active_bg_color() {
241 + return active_bg_color;
244 +void
245 +Root::set_active_bg_color(int64_t color) {
246 + active_bg_color = color;
249 void
250 Root::adjust_down_throttle(int throttle) {
251 set_down_throttle(std::max<int>(torrent::down_throttle_global()->max_rate() / 1024 + throttle, 0));
252 diff --git a/src/ui/root.h b/src/ui/root.h
253 index e9a7907..4eef1df 100644
254 --- a/src/ui/root.h
255 +++ b/src/ui/root.h
256 @@ -83,6 +83,15 @@ public:
257 void set_down_throttle_i64(int64_t throttle) { set_down_throttle(throttle >> 10); }
258 void set_up_throttle_i64(int64_t throttle) { set_up_throttle(throttle >> 10); }
260 + int get_done_fg_color();
261 + void set_done_fg_color(int64_t color);
262 + int get_done_bg_color();
263 + void set_done_bg_color(int64_t color);
264 + int get_active_fg_color();
265 + void set_active_fg_color(int64_t color);
266 + int get_active_bg_color();
267 + void set_active_bg_color(int64_t color);
269 void adjust_down_throttle(int throttle);
270 void adjust_up_throttle(int throttle);
272 @@ -105,6 +114,10 @@ private:
273 WStatusbar* m_windowStatusbar;
275 input::Bindings m_bindings;
276 + int64_t done_fg_color;
277 + int64_t done_bg_color;
278 + int64_t active_fg_color;
279 + int64_t active_bg_color;