Ticket #188: mc-show-free.patch

File mc-show-free.patch, 9.0 KB (added by andrew_b, 15 years ago)
  • src/layout.c

    diff --git a/src/layout.c b/src/layout.c
    index 8bd8e7e..9c14474 100644
    a b int message_visible = 1; 
    9797/* Set to show current working dir in xterm window title */ 
    9898int xterm_title = 1; 
    9999 
     100/* Set to show free space on device assigned to current directory */ 
     101int free_space = 1; 
     102 
    100103/* The starting line for the output of the subprogram */ 
    101104int output_start_y = 0; 
    102105 
    static int _command_prompt; 
    126129static int _keybar_visible; 
    127130static int _message_visible; 
    128131static int _xterm_title; 
     132static int _free_space; 
    129133static int _permission_mode; 
    130134static int _filetype_mode; 
    131135 
    static struct { 
    156160    int    *variable; 
    157161    WCheck *widget; 
    158162} check_options [] = { 
     163    { N_("show free sp&Ace"),  &free_space,      0 }, 
    159164    { N_("&Xterm window title"), &xterm_title,   0 }, 
    160165    { N_("h&Intbar visible"),  &message_visible, 0 }, 
    161166    { N_("&Keybar visible"),   &keybar_visible,  0 }, 
    static int b2left_cback (int action) 
    227232    if (_equal_split){ 
    228233        /* Turn equal split off */ 
    229234        _equal_split = 0; 
    230         check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL; 
    231         dlg_select_widget (check_options [6].widget); 
     235        check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL; 
     236        dlg_select_widget (check_options [7].widget); 
    232237        dlg_select_widget (bleft_widget); 
    233238    } 
    234239    _first_panel_size++; 
    static int b2right_cback (int action) 
    242247    if (_equal_split){ 
    243248        /* Turn equal split off */ 
    244249        _equal_split = 0; 
    245         check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL; 
    246         dlg_select_widget (check_options [6].widget); 
     250        check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL; 
     251        dlg_select_widget (check_options [7].widget); 
    247252        dlg_select_widget (bright_widget); 
    248253    } 
    249254    _first_panel_size--; 
    layout_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) 
    289294            if (old_output_lines != _output_lines){ 
    290295                old_output_lines = _output_lines; 
    291296                attrset (COLOR_NORMAL); 
    292                 dlg_move (h, 9, 16 + first_width); 
     297                dlg_move (h, 10, 16 + first_width); 
    293298                addstr (output_lines_label); 
    294                 dlg_move (h, 9, 10 + first_width); 
     299                dlg_move (h, 10, 10 + first_width); 
    295300                tty_printf ("%02d", _output_lines); 
    296301            } 
    297302        } 
    298303        return MSG_HANDLED; 
    299304 
    300305    case DLG_POST_KEY: 
    301         _filetype_mode = check_options [8].widget->state & C_BOOL; 
    302         _permission_mode = check_options [7].widget->state & C_BOOL; 
    303         _equal_split = check_options [6].widget->state & C_BOOL; 
    304         _menubar_visible = check_options [5].widget->state & C_BOOL; 
    305         _command_prompt = check_options [4].widget->state & C_BOOL; 
    306         _keybar_visible = check_options [2].widget->state & C_BOOL; 
    307         _message_visible = check_options [1].widget->state & C_BOOL; 
    308         _xterm_title = check_options [0].widget->state & C_BOOL; 
     306        _filetype_mode = check_options [9].widget->state & C_BOOL; 
     307        _permission_mode = check_options [8].widget->state & C_BOOL; 
     308        _equal_split = check_options [7].widget->state & C_BOOL; 
     309        _menubar_visible = check_options [6].widget->state & C_BOOL; 
     310        _command_prompt = check_options [5].widget->state & C_BOOL; 
     311        _keybar_visible = check_options [3].widget->state & C_BOOL; 
     312        _message_visible = check_options [2].widget->state & C_BOOL; 
     313        _xterm_title = check_options [1].widget->state & C_BOOL; 
     314        _free_space = check_options [0].widget->state & C_BOOL; 
    309315        if (console_flag){ 
    310316            int minimum; 
    311317            if (_output_lines < 0) 
    layout_callback (struct Dlg_head *h, dlg_msg_t msg, int parm) 
    333339            if (old_output_lines != _output_lines){ 
    334340                old_output_lines = _output_lines; 
    335341                attrset (COLOR_NORMAL); 
    336                 dlg_move (h, 9, 10 + first_width); 
     342                dlg_move (h, 10, 10 + first_width); 
    337343                tty_printf ("%02d", _output_lines); 
    338344            } 
    339345        } 
    init_layout (void) 
    356362    static const char *title1, *title2, *title3; 
    357363 
    358364    if (!i18n_layt_flag) { 
    359         register int l1; 
     365        register size_t l1; 
    360366 
    361367        first_width = 19;       /* length of line with '<' '>' buttons */ 
    362368 
    init_layout (void) 
    372378                first_width = l1; 
    373379        } 
    374380 
    375         for (i = 0; i <= 8; i++) { 
     381        for (i = 0; i <= 9; i++) { 
    376382            check_options[i].text = _(check_options[i].text); 
    377383            l1 = strlen (check_options[i].text) + 7; 
    378384            if (l1 > first_width) 
    init_layout (void) 
    389395 
    390396 
    391397        second_width = strlen (title3) + 1; 
    392         for (i = 0; i < 6; i++) { 
     398        for (i = 0; i < 7; i++) { 
    393399            check_options[i].text = _(check_options[i].text); 
    394400            l1 = strlen (check_options[i].text) + 7; 
    395401            if (l1 > second_width) 
    init_layout (void) 
    444450                            0)); 
    445451    if (console_flag) { 
    446452        add_widget (layout_dlg, 
    447                     button_new (9, 12 + first_width, B_MINUS, 
     453                    button_new (10, 12 + first_width, B_MINUS, 
    448454                                NARROW_BUTTON, "&-", bminus_cback)); 
    449455        add_widget (layout_dlg, 
    450                     button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON, 
     456                    button_new (10, 7 + first_width, B_PLUS, NARROW_BUTTON, 
    451457                                "&+", bplus_cback)); 
    452458    } 
    453459#define XTRACT(i) *check_options[i].variable, check_options[i].text 
    454460 
    455     for (i = 0; i < 6; i++) { 
     461    for (i = 0; i < 7; i++) { 
    456462        check_options[i].widget = 
    457             check_new (8 - i, 7 + first_width, XTRACT (i)); 
     463            check_new (9 - i, 7 + first_width, XTRACT (i)); 
    458464        add_widget (layout_dlg, check_options[i].widget); 
    459465    } 
    460     check_options[8].widget = check_new (10, 6, XTRACT (8)); 
     466    check_options[9].widget = check_new (10, 6, XTRACT (9)); 
     467    add_widget (layout_dlg, check_options[9].widget); 
     468    check_options[8].widget = check_new (9, 6, XTRACT (8)); 
    461469    add_widget (layout_dlg, check_options[8].widget); 
    462     check_options[7].widget = check_new (9, 6, XTRACT (7)); 
    463     add_widget (layout_dlg, check_options[7].widget); 
    464470 
    465471    _filetype_mode = filetype_mode; 
    466472    _permission_mode = permission_mode; 
    init_layout (void) 
    470476    _keybar_visible = keybar_visible; 
    471477    _message_visible = message_visible; 
    472478    _xterm_title = xterm_title; 
     479    _free_space = free_space; 
    473480    bright_widget = 
    474481        button_new (6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback); 
    475482    add_widget (layout_dlg, bright_widget); 
    476483    bleft_widget = 
    477484        button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback); 
    478485    add_widget (layout_dlg, bleft_widget); 
    479     check_options[6].widget = check_new (5, 6, XTRACT (6)); 
     486    check_options[7].widget = check_new (5, 6, XTRACT (7)); 
    480487    old_first_panel_size = -1; 
    481488    old_horizontal_split = -1; 
    482489    old_output_lines = -1; 
    483490 
    484491    _first_panel_size = first_panel_size; 
    485492    _output_lines = output_lines; 
    486     add_widget (layout_dlg, check_options[6].widget); 
     493    add_widget (layout_dlg, check_options[7].widget); 
    487494    radio_widget = radio_new (3, 6, 2, s_split_direction); 
    488495    add_widget (layout_dlg, radio_widget); 
    489496    radio_widget->sel = horizontal_split; 
  • src/layout.h

    diff --git a/src/layout.h b/src/layout.h
    index 6593a6f..86f4aac 100644
    a b extern int keybar_visible; 
    3939extern int output_start_y; 
    4040extern int message_visible; 
    4141extern int xterm_title; 
     42extern int free_space; 
    4243 
    4344extern int horizontal_split; 
    4445extern int nice_rotating_dash; 
  • src/screen.c

    diff --git a/src/screen.c b/src/screen.c
    index a1ae531..eb3d055 100644
    a b  
    5050#include "main-widgets.h" 
    5151#include "main.h"               /* the_menubar */ 
    5252#include "unixcompat.h" 
     53#include "mountlist.h"          /* my_statfs */ 
    5354 
    5455#define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) ) 
    5556 
    mini_info_separator (WPanel *panel) 
    765766} 
    766767 
    767768static void 
     769show_free_space (WPanel *panel) 
     770{ 
     771    /* Used to figure out how many free space we have */ 
     772    static struct my_statfs myfs_stats; 
     773    /* Old current working directory for displaying free space */ 
     774    static char *old_cwd = NULL; 
     775 
     776    /* Don't try to stat non-local fs */ 
     777    if (!vfs_file_is_local (panel->cwd) || !free_space) 
     778        return; 
     779 
     780    if (old_cwd == NULL || strcmp (old_cwd, panel->cwd) != 0) { 
     781        char rpath[PATH_MAX]; 
     782 
     783        init_my_statfs (); 
     784        g_free (old_cwd); 
     785        old_cwd = g_strdup (panel->cwd); 
     786 
     787        if (mc_realpath (panel->cwd, rpath) == NULL) 
     788            return; 
     789 
     790        my_statfs (&myfs_stats, rpath); 
     791    } 
     792 
     793    if (myfs_stats.avail > 0 || myfs_stats.total > 0) { 
     794        char buffer1 [6], buffer2[6], *tmp; 
     795        size_trunc_len (buffer1, 5, myfs_stats.avail, 1); 
     796        size_trunc_len (buffer2, 5, myfs_stats.total, 1); 
     797        tmp = g_strdup_printf (" %s/%s (%d%%) ", buffer1, buffer2, 
     798                                myfs_stats.total > 0 ? 
     799                                (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0); 
     800        widget_move (&panel->widget, panel->widget.lines - 1, 
     801                                     panel->widget.cols - 2 - strlen(tmp)); 
     802        addstr (tmp); 
     803        g_free (tmp); 
     804    } 
     805} 
     806 
     807static void 
    768808show_dir (WPanel *panel) 
    769809{ 
    770810    char *tmp; 
    show_dir (WPanel *panel) 
    806846    widget_move (&panel->widget, 0, panel->widget.cols - 3); 
    807847    addstr ("v"); 
    808848 
     849    attrset (NORMAL_COLOR); 
     850 
     851    show_free_space (panel); 
     852 
    809853    if (panel->active) 
    810854        standend (); 
    811855} 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index e806f10..25f6973 100644
    a b static const struct { 
    135135    { "show_mini_info", &show_mini_info }, 
    136136    { "permission_mode", &permission_mode }, 
    137137    { "filetype_mode", &filetype_mode }, 
     138    { "free_space", &free_space }, 
    138139    { 0, 0 } 
    139140}; 
    140141