33442ae
--- mc-4.6.1a/src/setup.c.showfree	2006-02-23 16:32:18.000000000 +0100
b3faad5
+++ mc-4.6.1a/src/setup.c	2006-07-10 12:44:43.000000000 +0200
33442ae
@@ -134,6 +134,7 @@
4567fd4
     { "show_mini_info", &show_mini_info },
4567fd4
     { "permission_mode", &permission_mode },
4567fd4
     { "filetype_mode", &filetype_mode },
4567fd4
+    { "free_space", &free_space },
4567fd4
     { 0, 0 }
4567fd4
 };
4567fd4
 
b3faad5
--- mc-4.6.1a/src/main.c.showfree	2006-07-10 12:44:43.000000000 +0200
b3faad5
+++ mc-4.6.1a/src/main.c	2006-07-10 14:09:24.000000000 +0200
b8a906e
@@ -61,6 +61,7 @@
b8a906e
 #include "listmode.h"
b8a906e
 #include "execute.h"
b8a906e
 #include "ext.h"		/* For flush_extension_file() */
ead0eea
+#include "mountlist.h"		/* my_statfs */
ead0eea
 
b8a906e
 /* Listbox for the command history feature */
b8a906e
 #include "widget.h"
b8a906e
@@ -231,6 +232,12 @@
b8a906e
 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
b8a906e
 int update_prompt = 0;
b750860
 
b750860
+/* Old current working directory for displaying free space */
b750860
+char *old_cwd = NULL;
b750860
+
b750860
+/* Used to figure out how many free space we have */
b750860
+struct my_statfs myfs_stats;
b750860
+
b8a906e
 /* The home directory */
b8a906e
 const char *home_dir = NULL;
ead0eea
 
b8a906e
@@ -402,6 +409,8 @@
b8a906e
     int reload_other = !(force_update & UP_ONLY_CURRENT);
b8a906e
     WPanel *panel;
b8a906e
 
b8a906e
+    show_free_space(current_panel);
b750860
+
b8a906e
     update_one_panel (get_current_index (), force_update, current_file);
b8a906e
     if (reload_other)
b8a906e
 	update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
b3faad5
@@ -467,6 +476,48 @@
b8a906e
     }
b8a906e
 }
b8a906e
 
b8a906e
+void
b750860
+show_free_space(WPanel *panel)
b750860
+{
b750860
+    /* Don't try to stat non-local fs */
b8a906e
+    if (!vfs_file_is_local(panel->cwd) || !free_space)
b750860
+	return;
b8a906e
+   
b8a906e
+    if (old_cwd == NULL || strcmp(old_cwd, panel->cwd) != 0) {
b3faad5
+    	struct stat st;
b3faad5
+    
b750860
+	init_my_statfs();
33ba53c
+	g_free(old_cwd);
b750860
+	old_cwd = g_strdup(panel->cwd);
b3faad5
+	
b3faad5
+	if ( mc_lstat (panel->cwd, &st) )
b3faad5
+	    return;
b3faad5
+
b3faad5
+	if ( !S_ISLNK (st.st_mode) ) {
b3faad5
+	    my_statfs (&myfs_stats, panel->cwd);
b3faad5
+	} else
b3faad5
+	{
b3faad5
+	    char buf[MC_MAXPATHLEN];
b3faad5
+	    memset (buf, 0, sizeof(buf));
b3faad5
+	    if ( mc_readlink (panel->cwd, buf, sizeof(buf)-1) <= 0 )
b3faad5
+	    	return;
b3faad5
+	    my_statfs (&myfs_stats, buf);
b3faad5
+	}
b750860
+    }
b8a906e
+   
b750860
+    if (myfs_stats.avail > 0 || myfs_stats.total > 0) {
b750860
+	char buffer1 [6], buffer2[6], *tmp;
b750860
+	size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
b750860
+	size_trunc_len (buffer2, 5, myfs_stats.total, 1);
33ba53c
+	tmp = g_strdup_printf (_("%s (%d%%) of %s"), buffer1, myfs_stats.total > 0 ?
b750860
+			       (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0,
b750860
+			       buffer2);
6b7b426
+	widget_move (&panel->widget, panel->widget.lines-1, panel->widget.cols-2-strlen(tmp));
b750860
+	addstr (tmp);
b750860
+	g_free (tmp);
b750860
+    }
b750860
+}
b8a906e
+                                                                                                                                                                                                                                 
b8a906e
 static int
b8a906e
 quit_cmd_internal (int quiet)
ead0eea
 {
b3faad5
--- mc-4.6.1a/src/main.h.showfree	2006-07-10 12:44:43.000000000 +0200
b3faad5
+++ mc-4.6.1a/src/main.h	2006-07-10 12:44:43.000000000 +0200
b8a906e
@@ -55,6 +55,7 @@
b8a906e
 extern int show_all_if_ambiguous;
b8a906e
 extern int slow_terminal;
b8a906e
 extern int update_prompt;	/* To comunicate with subshell */
b8a906e
+extern char *old_cwd;
b8a906e
 extern int safe_delete;
b8a906e
 extern int confirm_delete;
b8a906e
 extern int confirm_directory_hotlist_delete;
b8a906e
@@ -102,6 +103,7 @@
b8a906e
 int load_prompt     (int, void *);
b8a906e
 void save_cwds_stat (void);
b8a906e
 void quiet_quit_cmd (void);	/* For cmd.c and command.c */
b8a906e
+void show_free_space(WPanel *panel);
b8a906e
 
b8a906e
 void touch_bar      (void);
b8a906e
 void update_xterm_title_path (void);
b3faad5
--- mc-4.6.1a/src/screen.c.showfree	2006-07-10 12:44:43.000000000 +0200
b3faad5
+++ mc-4.6.1a/src/screen.c	2006-07-10 12:44:43.000000000 +0200
b8a906e
@@ -47,7 +47,7 @@
b8a906e
 #include "widget.h"
b8a906e
 #include "menu.h"		/* menubar_visible */
b8a906e
 #define WANT_WIDGETS
b8a906e
-#include "main.h"		/* the_menubar */
b8a906e
+#include "main.h"		/* the_menubar, show_free_space() */
b8a906e
 #include "unixcompat.h"
b8a906e
 
b8a906e
 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
b8a906e
@@ -866,6 +866,7 @@
ead0eea
     hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
ead0eea
 	   panel->widget.cols - 2);
ead0eea
 #endif				/* !HAVE_SLANG */
b8a906e
+    show_free_space (panel);
ead0eea
 }
ead0eea
 
ead0eea
 static void
b8a906e
@@ -929,6 +930,8 @@
ead0eea
     widget_move (&panel->widget, 0, panel->widget.cols - 3);
ead0eea
     addstr ("v");
ead0eea
 
ead0eea
+    mini_info_separator (panel);
ead0eea
+
ead0eea
     if (panel->active)
ead0eea
 	standend ();
ead0eea
 }
b3faad5
--- mc-4.6.1a/src/layout.c.showfree	2006-07-10 12:44:43.000000000 +0200
b3faad5
+++ mc-4.6.1a/src/layout.c	2006-07-10 12:44:43.000000000 +0200
33442ae
@@ -99,6 +99,9 @@
beabfeb
 /* Set to show current working dir in xterm window title */
beabfeb
 int xterm_title = 1;
beabfeb
 
beabfeb
+/* Set to show free space on device assigned to current directory */
beabfeb
+int free_space = 1;
beabfeb
+
beabfeb
 /* The starting line for the output of the subprogram */
beabfeb
 int output_start_y = 0;
beabfeb
 
33442ae
@@ -128,6 +131,7 @@
beabfeb
 static int _keybar_visible;
beabfeb
 static int _message_visible;
beabfeb
 static int _xterm_title;
beabfeb
+static int _free_space;
beabfeb
 static int _permission_mode;
beabfeb
 static int _filetype_mode;
beabfeb
 
33442ae
@@ -158,6 +162,7 @@
beabfeb
     int    *variable;
beabfeb
     WCheck *widget;
beabfeb
 } check_options [] = {
4567fd4
+    { N_("show free sp&Ace"),  &free_space,      0 },
beabfeb
     { N_("&Xterm window title"), &xterm_title,   0 },
beabfeb
     { N_("h&Intbar visible"),  &message_visible, 0 },
beabfeb
     { N_("&Keybar visible"),   &keybar_visible,  0 },
33442ae
@@ -229,8 +234,8 @@
beabfeb
     if (_equal_split){
beabfeb
 	/* Turn equal split off */
beabfeb
 	_equal_split = 0;
beabfeb
-	check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
beabfeb
-	dlg_select_widget (check_options [6].widget);
beabfeb
+	check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL;
beabfeb
+	dlg_select_widget (check_options [7].widget);
beabfeb
 	dlg_select_widget (bleft_widget);
beabfeb
     }
beabfeb
     _first_panel_size++;
33442ae
@@ -244,8 +249,8 @@
beabfeb
     if (_equal_split){
beabfeb
 	/* Turn equal split off */
beabfeb
 	_equal_split = 0;
beabfeb
-	check_options [6].widget->state = check_options [6].widget->state & ~C_BOOL;
beabfeb
-	dlg_select_widget (check_options [6].widget);
beabfeb
+	check_options [7].widget->state = check_options [7].widget->state & ~C_BOOL;
beabfeb
+	dlg_select_widget (check_options [7].widget);
beabfeb
 	dlg_select_widget (bright_widget);
beabfeb
     }
beabfeb
     _first_panel_size--;
33442ae
@@ -291,23 +296,24 @@
33442ae
 	    if (old_output_lines != _output_lines){
33442ae
 		old_output_lines = _output_lines;
33442ae
 		attrset (COLOR_NORMAL);
33442ae
-		dlg_move (h, 9, 16 + first_width);
33442ae
+		dlg_move (h, 10, 16 + first_width);
33442ae
 		addstr (output_lines_label);
33442ae
-		dlg_move (h, 9, 10 + first_width);
33442ae
+		dlg_move (h, 10, 10 + first_width);
33442ae
 		tty_printf ("%02d", _output_lines);
33442ae
 	    }
33442ae
 	}
beabfeb
 	return MSG_HANDLED;
beabfeb
 
beabfeb
     case DLG_POST_KEY:
beabfeb
-	_filetype_mode = check_options [8].widget->state & C_BOOL;
beabfeb
-	_permission_mode = check_options [7].widget->state & C_BOOL;
beabfeb
-	_equal_split = check_options [6].widget->state & C_BOOL;
beabfeb
-	_menubar_visible = check_options [5].widget->state & C_BOOL;
beabfeb
-	_command_prompt = check_options [4].widget->state & C_BOOL;
beabfeb
-	_keybar_visible = check_options [2].widget->state & C_BOOL;
beabfeb
-	_message_visible = check_options [1].widget->state & C_BOOL;
beabfeb
-	_xterm_title = check_options [0].widget->state & C_BOOL;
beabfeb
+	_filetype_mode = check_options [9].widget->state & C_BOOL;
beabfeb
+	_permission_mode = check_options [8].widget->state & C_BOOL;
beabfeb
+	_equal_split = check_options [7].widget->state & C_BOOL;
beabfeb
+	_menubar_visible = check_options [6].widget->state & C_BOOL;
beabfeb
+	_command_prompt = check_options [5].widget->state & C_BOOL;
beabfeb
+	_keybar_visible = check_options [3].widget->state & C_BOOL;
beabfeb
+	_message_visible = check_options [2].widget->state & C_BOOL;
beabfeb
+	_xterm_title = check_options [1].widget->state & C_BOOL;
beabfeb
+	_free_space = check_options [0].widget->state & C_BOOL;
beabfeb
 	if (console_flag){
beabfeb
 	    int minimum;
beabfeb
 	    if (_output_lines < 0)
33442ae
@@ -335,7 +341,7 @@
33442ae
 	    if (old_output_lines != _output_lines){
33442ae
 		old_output_lines = _output_lines;
33442ae
 		attrset (COLOR_NORMAL);
33442ae
-		dlg_move (h, 9, 10 + first_width);
33442ae
+		dlg_move (h, 10, 10 + first_width);
33442ae
 		tty_printf ("%02d", _output_lines);
33442ae
 	    }
33442ae
 	}
33442ae
@@ -374,7 +380,7 @@
beabfeb
 		first_width = l1;
beabfeb
 	}
beabfeb
 
beabfeb
-	for (i = 0; i <= 8; i++) {
beabfeb
+	for (i = 0; i <= 9; i++) {
beabfeb
 	    check_options[i].text = _(check_options[i].text);
beabfeb
 	    l1 = mbstrlen (check_options[i].text) + 7;
beabfeb
 	    if (l1 > first_width)
33442ae
@@ -391,7 +397,7 @@
beabfeb
 
beabfeb
 
beabfeb
 	second_width = mbstrlen (title3) + 1;
beabfeb
-	for (i = 0; i < 6; i++) {
beabfeb
+	for (i = 0; i < 7; i++) {
beabfeb
 	    check_options[i].text = _(check_options[i].text);
beabfeb
 	    l1 = mbstrlen (check_options[i].text) + 7;
beabfeb
 	    if (l1 > second_width)
33442ae
@@ -446,23 +452,23 @@
33442ae
 			    0));
33442ae
     if (console_flag) {
33442ae
 	add_widget (layout_dlg,
33442ae
-		    button_new (9, 12 + first_width, B_MINUS,
33442ae
+		    button_new (10, 12 + first_width, B_MINUS,
33442ae
 				NARROW_BUTTON, "&-", bminus_cback));
33442ae
 	add_widget (layout_dlg,
33442ae
-		    button_new (9, 7 + first_width, B_PLUS, NARROW_BUTTON,
33442ae
+		    button_new (10, 7 + first_width, B_PLUS, NARROW_BUTTON,
33442ae
 				"&+", bplus_cback));
beabfeb
     }
beabfeb
 #define XTRACT(i) *check_options[i].variable, check_options[i].text
beabfeb
 
beabfeb
-    for (i = 0; i < 6; i++) {
beabfeb
+    for (i = 0; i < 7; i++) {
beabfeb
 	check_options[i].widget =
beabfeb
-	    check_new (8 - i, 7 + first_width, XTRACT (i));
beabfeb
+	    check_new (9 - i, 7 + first_width, XTRACT (i));
beabfeb
 	add_widget (layout_dlg, check_options[i].widget);
beabfeb
     }
beabfeb
-    check_options[8].widget = check_new (10, 6, XTRACT (8));
beabfeb
+    check_options[9].widget = check_new (10, 6, XTRACT (9));
beabfeb
+    add_widget (layout_dlg, check_options[9].widget);
beabfeb
+    check_options[8].widget = check_new (9, 6, XTRACT (8));
beabfeb
     add_widget (layout_dlg, check_options[8].widget);
beabfeb
-    check_options[7].widget = check_new (9, 6, XTRACT (7));
beabfeb
-    add_widget (layout_dlg, check_options[7].widget);
beabfeb
 
beabfeb
     _filetype_mode = filetype_mode;
beabfeb
     _permission_mode = permission_mode;
33442ae
@@ -472,20 +478,21 @@
beabfeb
     _keybar_visible = keybar_visible;
beabfeb
     _message_visible = message_visible;
beabfeb
     _xterm_title = xterm_title;
beabfeb
+    _free_space = free_space;
beabfeb
     bright_widget =
beabfeb
 	button_new (6, 15, B_2RIGHT, NARROW_BUTTON, "&>", b2right_cback);
beabfeb
     add_widget (layout_dlg, bright_widget);
beabfeb
     bleft_widget =
beabfeb
 	button_new (6, 9, B_2LEFT, NARROW_BUTTON, "&<", b2left_cback);
beabfeb
     add_widget (layout_dlg, bleft_widget);
beabfeb
-    check_options[6].widget = check_new (5, 6, XTRACT (6));
beabfeb
+    check_options[7].widget = check_new (5, 6, XTRACT (7));
beabfeb
     old_first_panel_size = -1;
beabfeb
     old_horizontal_split = -1;
beabfeb
     old_output_lines = -1;
beabfeb
 
beabfeb
     _first_panel_size = first_panel_size;
beabfeb
     _output_lines = output_lines;
beabfeb
-    add_widget (layout_dlg, check_options[6].widget);
beabfeb
+    add_widget (layout_dlg, check_options[7].widget);
33442ae
     radio_widget = radio_new (3, 6, 2, s_split_direction);
beabfeb
     add_widget (layout_dlg, radio_widget);
beabfeb
     radio_widget->sel = horizontal_split;
beabfeb
--- mc-4.6.1a/src/layout.h.showfree	2004-12-03 20:17:47.000000000 +0100
b3faad5
+++ mc-4.6.1a/src/layout.h	2006-07-10 12:44:43.000000000 +0200
33442ae
@@ -39,6 +39,7 @@
beabfeb
 extern int output_start_y;
beabfeb
 extern int message_visible;
beabfeb
 extern int xterm_title;
beabfeb
+extern int free_space;
beabfeb
 
beabfeb
 extern int horizontal_split;
beabfeb
 extern int nice_rotating_dash;