Re: [RFE][PATCH] Display free space on device in panels



Hello,

On Mon, 2006-01-02 at 14:41 +0100, Jindrich Novy wrote:
> thanks for your comments, attaching the patch better matching the mc
> coding style.

I modified the patch so that it can be switched on/off in the
Options/Layout dialog to display free space on device.

termshot(TM) is attached:
┌<─~──────────────────────v>┐┌<─~/CVS/mc/devel──────────v>┐
│   Name   │Size│  MTime    ││   Name   │Size │  MTime    │
│/..       │UP--│           ▲│/..       │UP--D│           ▲
│/.Azureus │4096│Dec 29 15: ●│/CVS      │ 4096│Jan 25 13: ●
│/.TeXmacs │4096│Oct  6 10: ▒│/i386     │ 4096│Feb  1 07: ▒
│/.Trash   │4096│Jan  8 22: ▒│/mc-4.6.1a│ 4096│Feb  1 07: ▒
│/.aMule   │4096│Nov 26 21: ▒│ .cvs~nore│   18│Dec  6 13: ▒
│/.amaya   │4096│Jan 10 14: ▒│ Makefile │  175│Sep  9  20 ▒
│/.anjuta  │4096│Dec 30 15: ▒│ mc-2~atch│  501│Jan 31 12: ▒
│/.cam~erts│4096│Aug 20 21: ▒│ mc-4~.rpm│2950K│Jan 25 16: ▒
│/.cdd~lave│4096│Jan  1 01: ▒│ mc-4~.rpm│2951K│Feb  1 07: ▒
│/.comments│4096│Jan 15 21: ▒│ mc-4~.bz2│2862K│Nov 29 22: ▒
│/.ddd     │4096│Jan 28 14: ▒│ mc-4~.new│2863K│Jan 29 19: ▒
├────────2787M (12%) of 21G─▼├─────────2787M (12%) of 21G─▼
│/..       │UP--│drwxr-xr-x ││/..       │UP--D│drwxr-xr-x │
└───────────────────────────┘└────────────────────────────┘
enigma:~/CVS/mc/devel$                                  [^]

what shows how the free space on device is displayed.

ChangeLog:
2006-02-01  Jindrich Novy  <jnovy redhat com>

        * screen.c: Add new function show_free_space() to display free
        space on device. Add calls so that show_free_space() is called
        when panels are drawn.
        * layout.c (struct check_options, b2left_cback, b2right_cback
        layout_callback, init_layout): Add configuration option to
        Options/Layout dialog.

Regards,
Jindrich
-- 
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
(o_                                                           _o)
//\      The worst evil in the world is refusal to think.     //\
V_/_                                                         _\_V

--- mc-4.6.1a/src/screen.c.showfree	2006-01-31 21:59:12.000000000 +0100
+++ mc-4.6.1a/src/screen.c	2006-01-31 21:59:12.000000000 +0100
@@ -49,6 +49,7 @@
 #define WANT_WIDGETS
 #include "main.h"		/* the_menubar */
 #include "unixcompat.h"
+#include "mountlist.h"		/* my_statfs */
 
 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
 
@@ -106,6 +107,12 @@ int filetype_mode = 1;
 /* The hook list for the select file function */
 Hook *select_file_hook = 0;
 
+/* Old current working directory for displaying free space */
+char *old_cwd = NULL;
+
+/* Used to figure out how many free space we have */
+struct my_statfs myfs_stats;
+
 static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
 static int panel_event (Gpm_Event *event, void *);
 static void paint_frame (WPanel *panel);
@@ -851,6 +858,41 @@ paint_dir (WPanel *panel)
     standend ();
 }
 
+
+static void
+show_free_space(WPanel *panel)
+{
+    struct stat st;
+
+    /* Don't try to stat non-local fs */
+    if (!vfs_file_is_local(panel->cwd))
+	return;
+
+    if (old_cwd == NULL || strcmp(old_cwd, panel->cwd) == 0) {
+	init_my_statfs();
+	g_free(old_cwd);
+	old_cwd = g_strdup(panel->cwd);
+    }
+
+    my_statfs (&myfs_stats, panel->cwd);
+    st = panel->dir.list [panel->selected].st;
+	
+    if (myfs_stats.avail > 0 || myfs_stats.total > 0) {
+	char buffer1 [6], buffer2[6], *tmp;
+	size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
+	size_trunc_len (buffer2, 5, myfs_stats.total, 1);
+	tmp = g_strdup_printf (_("%s (%d%%) of %s"), buffer1, myfs_stats.total > 0 ?
+			       (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0,
+			       buffer2);
+	widget_move (&panel->widget, panel->widget.lines-3, panel->widget.cols-2-strlen(tmp));
+	if (panel->active)
+	    attrset (REVERSE_COLOR);
+	addstr (tmp);
+	attrset (NORMAL_COLOR);
+	g_free (tmp);
+    }
+}
+
 static void
 mini_info_separator (WPanel *panel)
 {
@@ -866,6 +908,7 @@ mini_info_separator (WPanel *panel)
     hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
 	   panel->widget.cols - 2);
 #endif				/* !HAVE_SLANG */
+    if (free_space) show_free_space (panel);
 }
 
 static void
@@ -929,6 +972,8 @@ show_dir (WPanel *panel)
     widget_move (&panel->widget, 0, panel->widget.cols - 3);
     addstr ("v");
 
+    mini_info_separator (panel);
+
     if (panel->active)
 	standend ();
 }
--- mc-4.6.1a/src/layout.c.showfree	2006-01-31 21:59:12.000000000 +0100
+++ mc-4.6.1a/src/layout.c	2006-01-31 22:02:28.000000000 +0100
@@ -99,6 +99,9 @@ int message_visible = 1;
 /* Set to show current working dir in xterm window title */
 int xterm_title = 1;
 
+/* Set to show free space on device assigned to current directory */
+int free_space = 1;
+
 /* The starting line for the output of the subprogram */
 int output_start_y = 0;
 
@@ -128,6 +131,7 @@ static int _command_prompt;
 static int _keybar_visible;
 static int _message_visible;
 static int _xterm_title;
+static int _free_space;
 static int _permission_mode;
 static int _filetype_mode;
 
@@ -158,6 +162,7 @@ static struct {
     int    *variable;
     WCheck *widget;
 } check_options [] = {
+    { N_("show free &Space"),  &free_space,      0 },
     { N_("&Xterm window title"), &xterm_title,   0 },
     { N_("h&Intbar visible"),  &message_visible, 0 },
     { N_("&Keybar visible"),   &keybar_visible,  0 },
@@ -229,8 +234,8 @@ static int b2left_cback (int action)
     if (_equal_split){
 	/* Turn equal split off */
 	_equal_split = 0;
-	check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
-	dlg_select_widget (check_options [6].widget);
+	check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL;
+	dlg_select_widget (check_options [7].widget);
 	dlg_select_widget (bleft_widget);
     }
     _first_panel_size++;
@@ -244,8 +249,8 @@ static int b2right_cback (int action)
     if (_equal_split){
 	/* Turn equal split off */
 	_equal_split = 0;
-	check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
-	dlg_select_widget (check_options [6].widget);
+	check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL;
+	dlg_select_widget (check_options [7].widget);
 	dlg_select_widget (bright_widget);
     }
     _first_panel_size--;
@@ -300,14 +305,15 @@ layout_callback (struct Dlg_head *h, dlg
 	return MSG_HANDLED;
 
     case DLG_POST_KEY:
-	_filetype_mode = check_options [8].widget->state & C_BOOL;
-	_permission_mode = check_options [7].widget->state & C_BOOL;
-	_equal_split = check_options [6].widget->state & C_BOOL;
-	_menubar_visible = check_options [5].widget->state & C_BOOL;
-	_command_prompt = check_options [4].widget->state & C_BOOL;
-	_keybar_visible = check_options [2].widget->state & C_BOOL;
-	_message_visible = check_options [1].widget->state & C_BOOL;
-	_xterm_title = check_options [0].widget->state & C_BOOL;
+	_filetype_mode = check_options [9].widget->state & C_BOOL;
+	_permission_mode = check_options [8].widget->state & C_BOOL;
+	_equal_split = check_options [7].widget->state & C_BOOL;
+	_menubar_visible = check_options [6].widget->state & C_BOOL;
+	_command_prompt = check_options [5].widget->state & C_BOOL;
+	_keybar_visible = check_options [3].widget->state & C_BOOL;
+	_message_visible = check_options [2].widget->state & C_BOOL;
+	_xterm_title = check_options [1].widget->state & C_BOOL;
+	_free_space = check_options [0].widget->state & C_BOOL;
 	if (console_flag){
 	    int minimum;
 	    if (_output_lines < 0)
@@ -374,7 +380,7 @@ init_layout (void)
 		first_width = l1;
 	}
 
-	for (i = 0; i <= 8; i++) {
+	for (i = 0; i <= 9; i++) {
 	    check_options[i].text = _(check_options[i].text);
 	    l1 = mbstrlen (check_options[i].text) + 7;
 	    if (l1 > first_width)
@@ -391,7 +397,7 @@ init_layout (void)
 
 
 	second_width = mbstrlen (title3) + 1;
-	for (i = 0; i < 6; i++) {
+	for (i = 0; i < 7; i++) {
 	    check_options[i].text = _(check_options[i].text);
 	    l1 = mbstrlen (check_options[i].text) + 7;
 	    if (l1 > second_width)
@@ -454,15 +460,15 @@ init_layout (void)
     }
 #define XTRACT(i) *check_options[i].variable, check_options[i].text
 
-    for (i = 0; i < 6; i++) {
+    for (i = 0; i < 7; i++) {
 	check_options[i].widget =
-	    check_new (8 - i, 7 + first_width, XTRACT (i));
+	    check_new (9 - i, 7 + first_width, XTRACT (i));
 	add_widget (layout_dlg, check_options[i].widget);
     }
-    check_options[8].widget = check_new (10, 6, XTRACT (8));
+    check_options[9].widget = check_new (10, 6, XTRACT (9));
+    add_widget (layout_dlg, check_options[9].widget);
+    check_options[8].widget = check_new (9, 6, XTRACT (8));
     add_widget (layout_dlg, check_options[8].widget);
-    check_options[7].widget = check_new (9, 6, XTRACT (7));
-    add_widget (layout_dlg, check_options[7].widget);
 
     _filetype_mode = filetype_mode;
     _permission_mode = permission_mode;
@@ -472,20 +478,21 @@ init_layout (void)
     _keybar_visible = keybar_visible;
     _message_visible = message_visible;
     _xterm_title = xterm_title;
+    _free_space = free_space;
     bright_widget =
 	button_new (6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback);
     add_widget (layout_dlg, bright_widget);
     bleft_widget =
 	button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback);
     add_widget (layout_dlg, bleft_widget);
-    check_options[6].widget = check_new (5, 6, XTRACT (6));
+    check_options[7].widget = check_new (5, 6, XTRACT (7));
     old_first_panel_size = -1;
     old_horizontal_split = -1;
     old_output_lines = -1;
 
     _first_panel_size = first_panel_size;
     _output_lines = output_lines;
-    add_widget (layout_dlg, check_options[6].widget);
+    add_widget (layout_dlg, check_options[7].widget);
     radio_widget = radio_new (3, 6, 2, s_split_direction, 1);
     add_widget (layout_dlg, radio_widget);
     radio_widget->sel = horizontal_split;
--- mc-4.6.1a/src/layout.h.showfree	2004-12-03 20:17:47.000000000 +0100
+++ mc-4.6.1a/src/layout.h	2006-01-31 21:59:12.000000000 +0100
@@ -39,6 +39,7 @@ extern int keybar_visible;
 extern int output_start_y;
 extern int message_visible;
 extern int xterm_title;
+extern int free_space;
 
 extern int horizontal_split;
 extern int nice_rotating_dash;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]