8
8
9
9
#include < rak/algorithm.h>
10
10
11
- #include " rpc/command_variable.h"
12
11
#include " core/view.h"
13
12
#include " core/manager.h"
14
13
#include " core/download.h"
23
22
#include " control.h"
24
23
#include " command_helpers.h"
25
24
25
+ #if defined(CMD2_ANY)
26
+ #define D_INFO (item ) (item->info ())
27
+ #include " rpc/object_storage.h"
28
+ #else
29
+ #define D_INFO (item ) (item)
30
+ #include " rpc/command_variable.h"
31
+ #endif
26
32
27
33
// from command_pyroscope.cc
28
34
extern torrent::Tracker* get_active_tracker (torrent::Download* item);
@@ -284,20 +290,24 @@ static int row_offset(core::View* view, Range& range) {
284
290
285
291
static void decorate_download_title (Window* window, display::Canvas* canvas, core::View* view, int pos, Range& range) {
286
292
int offset = row_offset (view, range);
293
+ #if defined(CMD2_ANY)
294
+ core::Download* item = *range.first ;
295
+ #else
287
296
torrent::Download* item = (*range.first )->download ();
297
+ #endif
288
298
bool active = item->is_open () && item->is_active ();
289
299
290
300
// download title color
291
301
int title_col;
292
302
unsigned long focus_attr = range.first == view->focus () ? attr_map[ps::COL_FOCUS] : 0 ;
293
303
if ((*range.first )->is_done ())
294
- title_col = (active ? item->up_rate ()->rate () ? ps::COL_SEEDING : ps::COL_COMPLETE : ps::COL_STOPPED) + offset;
304
+ title_col = (active ? D_INFO ( item) ->up_rate ()->rate () ? ps::COL_SEEDING : ps::COL_COMPLETE : ps::COL_STOPPED) + offset;
295
305
else
296
- title_col = (active ? item->down_rate ()->rate () ? ps::COL_LEECHING : ps::COL_INCOMPLETE : ps::COL_QUEUED) + offset;
306
+ title_col = (active ? D_INFO ( item) ->down_rate ()->rate () ? ps::COL_LEECHING : ps::COL_INCOMPLETE : ps::COL_QUEUED) + offset;
297
307
canvas->set_attr (2 , pos, -1 , attr_map[title_col] | focus_attr, title_col);
298
308
299
309
// show label for tracker in focus
300
- std::string url = get_active_tracker_domain (item );
310
+ std::string url = get_active_tracker_domain ((*range. first )-> download () );
301
311
if (!url.empty ()) {
302
312
// shorten label if too long
303
313
int len = url.length ();
@@ -395,10 +405,10 @@ void ui_pyroscope_download_list_redraw_item(Window* window, display::Canvas* can
395
405
canvas->set_attr (93 , pos+1 , 6 , attr_map[rcol + offset], rcol + offset);
396
406
397
407
// mark active up / down ("focus", plus "seeding" or "leeching"), and dim inactive numbers (i.e. 0)
398
- canvas->set_attr (36 , pos+1 , 6 , attr_map[ps::COL_SEEDING + offset] | (item->up_rate ()->rate () ? attr_map[ps::COL_FOCUS] : 0 ),
399
- (item->up_rate ()->rate () ? ps::COL_SEEDING : ps::COL_LABEL) + offset);
400
- canvas->set_attr (44 , pos+1 , 6 , attr_map[ps::COL_LEECHING + offset] | (item->down_rate ()->rate () ? attr_map[ps::COL_FOCUS] : 0 ),
401
- (item->down_rate ()->rate () ? ps::COL_LEECHING : ps::COL_LABEL) + offset);
408
+ canvas->set_attr (36 , pos+1 , 6 , attr_map[ps::COL_SEEDING + offset] | (D_INFO ( item) ->up_rate ()->rate () ? attr_map[ps::COL_FOCUS] : 0 ),
409
+ (D_INFO ( item) ->up_rate ()->rate () ? ps::COL_SEEDING : ps::COL_LABEL) + offset);
410
+ canvas->set_attr (44 , pos+1 , 6 , attr_map[ps::COL_LEECHING + offset] | (D_INFO ( item) ->down_rate ()->rate () ? attr_map[ps::COL_FOCUS] : 0 ),
411
+ (D_INFO ( item) ->down_rate ()->rate () ? ps::COL_LEECHING : ps::COL_LABEL) + offset);
402
412
403
413
// mark non-trivial messages
404
414
if (!(*range.first )->message ().empty () && (*range.first )->message ().find (" Tried all trackers" ) == std::string::npos) {
@@ -446,8 +456,12 @@ bool ui_pyroscope_download_list_redraw(Window* window, display::Canvas* canvas,
446
456
447
457
while (range.first != range.second ) {
448
458
core::Download* d = *range.first ;
459
+ #if defined(CMD2_ANY)
460
+ core::Download* item = d;
461
+ #else
449
462
torrent::Download* item = d->download ();
450
- torrent::Tracker* tracker = get_active_tracker (item);
463
+ #endif
464
+ torrent::Tracker* tracker = get_active_tracker ((*range.first )->download ());
451
465
int ratio = rpc::call_command_value (" d.get_ratio" , rpc::make_target (d));
452
466
bool has_msg = !d->message ().empty ();
453
467
bool has_alert = has_msg && d->message ().find (" Tried all trackers" ) == std::string::npos;
@@ -476,18 +490,18 @@ bool ui_pyroscope_download_list_redraw(Window* window, display::Canvas* canvas,
476
490
d->is_done () ? " ✔ " : progress[
477
491
item->file_list ()->completed_chunks () * progress_steps
478
492
/ item->file_list ()->size_chunks ()],
479
- item->down_rate ()->rate () ?
480
- (item->up_rate ()->rate () ? " ⇅ " : " ↡ " ) :
481
- (item->up_rate ()->rate () ? " ↟ " : " " ),
493
+ D_INFO ( item) ->down_rate ()->rate () ?
494
+ (D_INFO ( item) ->up_rate ()->rate () ? " ⇅ " : " ↡ " ) :
495
+ (D_INFO ( item) ->up_rate ()->rate () ? " ↟ " : " " ),
482
496
ratio >= 11000 ? " ⊛ " : ying_yang[ratio / 1000 ],
483
497
has_msg ? has_alert ? " ⚠ " : " ♺ " : " " ,
484
498
tracker ? num2 (tracker->scrape_downloaded ()).c_str () : " " ,
485
499
tracker ? num2 (tracker->scrape_complete ()).c_str () : " " ,
486
500
tracker ? num2 (tracker->scrape_incomplete ()).c_str () : " " ,
487
- human_size (item->up_rate ()->rate (), 2 | 8 ).c_str (),
501
+ human_size (D_INFO ( item) ->up_rate ()->rate (), 2 | 8 ).c_str (),
488
502
d->is_done () ? " " : " " ,
489
503
d->is_done () ? elapsed_time (get_completion_time (d)).c_str ()
490
- : human_size (item->down_rate ()->rate (), 2 | 8 ).c_str (),
504
+ : human_size (D_INFO ( item) ->down_rate ()->rate (), 2 | 8 ).c_str (),
491
505
human_size (item->file_list ()->size_bytes (), 2 ).c_str (),
492
506
buffer
493
507
);
@@ -549,11 +563,12 @@ void ui_pyroscope_statusbar_redraw(Window* window, display::Canvas* canvas) {
549
563
550
564
551
565
#if defined(CMD2_ANY)
552
- torrent::Object cmd_view_collapsed_toggle (rpc::target_type target, const torrent::Object& rawArgs) {
566
+ torrent::Object cmd_view_collapsed_toggle (const torrent::Object::string_type& args) {
567
+ std::string view_name = args;
553
568
#else
554
569
torrent::Object cmd_view_collapsed_toggle (__UNUSED rpc::target_type target, const torrent::Object& rawArgs) {
555
- #endif
556
570
std::string view_name = rawArgs.as_string ();
571
+ #endif
557
572
558
573
if (view_name.empty ()) {
559
574
view_name = control->ui ()->download_list ()->current_view ()->name ();
@@ -565,53 +580,71 @@ torrent::Object cmd_view_collapsed_toggle(__UNUSED rpc::target_type target, cons
565
580
}
566
581
567
582
583
+ #if defined(CMD2_ANY)
584
+ // implementation of method we patched into rpc::object_storage
585
+ const torrent::Object& rpc::object_storage::set_color_string (const torrent::raw_string& key, const std::string& object) {
586
+ const torrent::Object& result = rpc::object_storage::set_string (key, object);
587
+ display::ui_pyroscope_colormap_init ();
588
+ return result;
589
+ }
590
+ #else
568
591
// implementation of method we patched into rpc::CommandVariable
569
592
const torrent::Object rpc::CommandVariable::set_color_string (Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) {
570
- rpc::CommandVariable::set_string (rawCommand, target, rawArgs);
593
+ const torrent::Object result = rpc::CommandVariable::set_string (rawCommand, target, rawArgs);
571
594
display::ui_pyroscope_colormap_init ();
595
+ return result;
572
596
}
597
+ #endif
573
598
574
599
575
600
// register our commands
576
601
void initialize_command_ui_pyroscope () {
577
602
#if defined(CMD2_ANY)
603
+ #define PS_VARIABLE_COLOR (key, value ) \
604
+ control->object_storage ()->insert_c_str (key, value, rpc::object_storage::flag_string_type); \
605
+ CMD2_ANY (key, std::bind (&rpc::object_storage::get, control->object_storage (), \
606
+ torrent::raw_string::from_c_str (key))); \
607
+ CMD2_ANY_STRING (key " .set" , std::bind (&rpc::object_storage::set_color_string, control->object_storage (), \
608
+ torrent::raw_string::from_c_str (key), std::placeholders::_2));
609
+
610
+ #define PS_CMD_ANY_FUN (key, func ) \
611
+ CMD2_ANY (key, std::bind (&func))
612
+
613
+ CMD2_ANY_STRING (" view.collapsed.toggle" , std::bind (&cmd_view_collapsed_toggle, std::placeholders::_2));
578
614
#else
579
- #define NEW_VARIABLE_COLOR (key, defaultValue ) \
615
+ #define PS_VARIABLE_COLOR (key, defaultValue ) \
580
616
add_variable (key, key " .set" , 0 , \
581
617
&rpc::CommandVariable::get_string, &rpc::CommandVariable::set_color_string, std::string (defaultValue));
582
618
583
- NEW_VARIABLE_COLOR (" ui.color.progress0" , " red" );
584
- NEW_VARIABLE_COLOR (" ui.color.progress20" , " bold bright red" );
585
- NEW_VARIABLE_COLOR (" ui.color.progress40" , " bold bright magenta" );
586
- NEW_VARIABLE_COLOR (" ui.color.progress60" , " yellow" );
587
- NEW_VARIABLE_COLOR (" ui.color.progress80" , " bold bright yellow" );
588
- NEW_VARIABLE_COLOR (" ui.color.progress100" , " green" );
589
- NEW_VARIABLE_COLOR (" ui.color.progress120" , " bold bright green" );
590
- NEW_VARIABLE_COLOR (" ui.color.complete" , " bright green" );
591
- NEW_VARIABLE_COLOR (" ui.color.seeding" , " bold bright green" );
592
- NEW_VARIABLE_COLOR (" ui.color.stopped" , " blue" );
593
- NEW_VARIABLE_COLOR (" ui.color.queued" , " magenta" );
594
- NEW_VARIABLE_COLOR (" ui.color.incomplete" , " yellow" );
595
- NEW_VARIABLE_COLOR (" ui.color.leeching" , " bold bright yellow" );
596
- NEW_VARIABLE_COLOR (" ui.color.alarm" , " bold white on red" );
597
- NEW_VARIABLE_COLOR (" ui.color.title" , " bold bright white on blue" );
598
- NEW_VARIABLE_COLOR (" ui.color.footer" , " bold bright cyan on blue" );
599
- NEW_VARIABLE_COLOR (" ui.color.label" , " gray" );
600
- NEW_VARIABLE_COLOR (" ui.color.odd" , " " );
601
- NEW_VARIABLE_COLOR (" ui.color.even" , " " );
602
- NEW_VARIABLE_COLOR (" ui.color.info" , " white" );
603
- NEW_VARIABLE_COLOR (" ui.color.focus" , " reverse" );
604
-
605
- ADD_COMMAND_VOID (" system.colors.max" , rak::ptr_fun (&display::get_colors));
606
- ADD_COMMAND_VOID (" system.colors.enabled" , rak::ptr_fun (&has_colors));
607
- ADD_COMMAND_VOID (" system.colors.rgb" , rak::ptr_fun (&can_change_color));
608
-
609
- CMD_N_STRING (" view.collapsed.toggle" , rak::ptr_fn (&cmd_view_collapsed_toggle));
610
-
611
- // macros mostly compatible to 0.8.8 syntax
612
- #define CMD2_VAR_BOOL (key, defaultValue ) \
613
- add_variable (key, key " .set" , 0 , &rpc::CommandVariable::get_bool, &rpc::CommandVariable::set_bool, (int64_t )defaultValue);
619
+ #define PS_CMD_ANY_FUN (key, func ) \
620
+ ADD_COMMAND_VOID (key, rak::ptr_fun (&func))
621
+
622
+ CMD_N_STRING (" view.collapsed.toggle" , rak::ptr_fn (&cmd_view_collapsed_toggle));
614
623
#endif
615
624
616
- // CMD2_VAR_BOOL("", false);
625
+ PS_VARIABLE_COLOR (" ui.color.progress0" , " red" );
626
+ PS_VARIABLE_COLOR (" ui.color.progress20" , " bold bright red" );
627
+ PS_VARIABLE_COLOR (" ui.color.progress40" , " bold bright magenta" );
628
+ PS_VARIABLE_COLOR (" ui.color.progress60" , " yellow" );
629
+ PS_VARIABLE_COLOR (" ui.color.progress80" , " bold bright yellow" );
630
+ PS_VARIABLE_COLOR (" ui.color.progress100" , " green" );
631
+ PS_VARIABLE_COLOR (" ui.color.progress120" , " bold bright green" );
632
+ PS_VARIABLE_COLOR (" ui.color.complete" , " bright green" );
633
+ PS_VARIABLE_COLOR (" ui.color.seeding" , " bold bright green" );
634
+ PS_VARIABLE_COLOR (" ui.color.stopped" , " blue" );
635
+ PS_VARIABLE_COLOR (" ui.color.queued" , " magenta" );
636
+ PS_VARIABLE_COLOR (" ui.color.incomplete" , " yellow" );
637
+ PS_VARIABLE_COLOR (" ui.color.leeching" , " bold bright yellow" );
638
+ PS_VARIABLE_COLOR (" ui.color.alarm" , " bold white on red" );
639
+ PS_VARIABLE_COLOR (" ui.color.title" , " bold bright white on blue" );
640
+ PS_VARIABLE_COLOR (" ui.color.footer" , " bold bright cyan on blue" );
641
+ PS_VARIABLE_COLOR (" ui.color.label" , " gray" );
642
+ PS_VARIABLE_COLOR (" ui.color.odd" , " " );
643
+ PS_VARIABLE_COLOR (" ui.color.even" , " " );
644
+ PS_VARIABLE_COLOR (" ui.color.info" , " white" );
645
+ PS_VARIABLE_COLOR (" ui.color.focus" , " reverse" );
646
+
647
+ PS_CMD_ANY_FUN (" system.colors.max" , display::get_colors);
648
+ PS_CMD_ANY_FUN (" system.colors.enabled" , has_colors);
649
+ PS_CMD_ANY_FUN (" system.colors.rgb" , can_change_color);
617
650
}
0 commit comments