src/find.c: Micro fix for 'Skip hidden' shortcut
[midnight-commander.git] / src / info.c
blob0a0d04affe7fe4f8846f6b414feb8a4a8ccf3db8
1 /* Panel managing.
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #include <config.h>
21 #include <stdio.h>
23 #include "global.h"
24 #include "tty.h"
25 #include "mouse.h" /* Gpm_Event */
26 #include "color.h"
27 #include "dialog.h"
28 #include "info.h"
29 #include "dir.h" /* required by panel */
30 #include "panel.h" /* for the panel structure */
31 #include "main.h" /* other_panel, current_panel definitions */
32 #include "util.h" /* size_trunc_len */
33 #include "layout.h"
34 #include "key.h" /* is_idle() */
35 #include "mountlist.h"
36 #include "unixcompat.h"
38 #ifndef VERSION
39 # define VERSION "undefined"
40 #endif
42 struct WInfo {
43 Widget widget;
44 int ready;
47 /* Have we called the init_my_statfs routine? */
48 static int initialized;
49 static struct my_statfs myfs_stats;
51 static void info_box (Dlg_head *h, struct WInfo *info)
53 standend ();
54 attrset (NORMAL_COLOR);
55 widget_erase (&info->widget);
56 draw_double_box (h, info->widget.y, info->widget.x,
57 info->widget.lines, info->widget.cols);
60 static void
61 info_show_info (struct WInfo *info)
63 static int i18n_adjust=0;
64 static const char *file_label;
66 struct stat st;
68 if (!is_idle ())
69 return;
71 info_box (info->widget.parent, info);
72 attrset (MARKED_COLOR);
73 widget_move (&info->widget, 1, 3);
74 tty_printf (_("Midnight Commander %s"), VERSION);
75 attrset (NORMAL_COLOR);
76 widget_move (&info->widget, 2, 1);
77 hline (ACS_HLINE|NORMAL_COLOR, info->widget.cols-2);
78 if (get_current_type () != view_listing)
79 return;
81 if (!info->ready)
82 return;
84 my_statfs (&myfs_stats, current_panel->cwd);
85 st = current_panel->dir.list [current_panel->selected].st;
87 /* Print only lines which fit */
89 if(!i18n_adjust) {
90 /* This printf pattern string is used as a reference for size */
91 file_label=_("File: %s");
92 i18n_adjust=strlen(file_label)+2;
95 switch (info->widget.lines-2){
96 /* Note: all cases are fall-throughs */
98 default:
100 case 16:
101 widget_move (&info->widget, 16, 3);
102 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
103 tty_printf (_("Free nodes: %d (%d%%) of %d"),
104 myfs_stats.nfree,
105 myfs_stats.total
106 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
107 myfs_stats.nodes);
108 else
109 addstr (_("No node information"));
111 case 15:
112 widget_move (&info->widget, 15, 3);
113 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
114 char buffer1 [6], buffer2[6];
115 size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
116 size_trunc_len (buffer2, 5, myfs_stats.total, 1);
117 tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
118 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0,
119 buffer2);
120 } else
121 addstr (_("No space information"));
123 case 14:
124 widget_move (&info->widget, 14, 3);
125 tty_printf (_("Type: %s "),
126 myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
127 if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
128 tty_printf (" (%Xh)", myfs_stats.type);
130 case 13:
131 widget_move (&info->widget, 13, 3);
132 tty_printf (_("Device: %s"),
133 name_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
134 case 12:
135 widget_move (&info->widget, 12, 3);
136 tty_printf (_("Filesystem: %s"),
137 name_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
139 case 11:
140 widget_move (&info->widget, 11, 3);
141 tty_printf (_("Accessed: %s"), file_date (st.st_atime));
143 case 10:
144 widget_move (&info->widget, 10, 3);
145 tty_printf (_("Modified: %s"), file_date (st.st_mtime));
147 case 9:
148 widget_move (&info->widget, 9, 3);
149 /* TRANSLATORS: "Status changed", like in the stat(2) man page */
150 printw (_("Status: %s"), file_date (st.st_ctime));
152 case 8:
153 widget_move (&info->widget, 8, 3);
154 #ifdef HAVE_STRUCT_STAT_ST_RDEV
155 if (S_ISCHR (st.st_mode) || S_ISBLK(st.st_mode))
156 tty_printf (_("Dev. type: major %lu, minor %lu"),
157 (unsigned long) major (st.st_rdev),
158 (unsigned long) minor (st.st_rdev));
159 else
160 #endif
162 char buffer[10];
163 size_trunc_len(buffer, 9, st.st_size, 0);
164 tty_printf (_("Size: %s"), buffer);
165 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
166 tty_printf (ngettext(" (%ld block)", " (%ld blocks)",
167 (unsigned long int) st.st_blocks),
168 (long int) st.st_blocks);
169 #endif
172 case 7:
173 widget_move (&info->widget, 7, 3);
174 tty_printf (_("Owner: %s/%s"),
175 get_owner (st.st_uid),
176 get_group (st.st_gid));
178 case 6:
179 widget_move (&info->widget, 6, 3);
180 tty_printf (_("Links: %d"), (int) st.st_nlink);
182 case 5:
183 widget_move (&info->widget, 5, 3);
184 tty_printf (_("Mode: %s (%04o)"),
185 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
187 case 4:
188 widget_move (&info->widget, 4, 3);
189 tty_printf (_("Location: %Xh:%Xh"), (int)st.st_dev, (int)st.st_ino);
191 case 3:
192 widget_move (&info->widget, 3, 2);
193 /* .ado: fname is invalid if selected == 0 && info called from current panel */
194 if (current_panel->selected){
195 tty_printf (file_label,
196 name_trunc (current_panel->dir.list [current_panel->selected].fname,
197 info->widget.cols - i18n_adjust));
198 } else
199 addstr (_("File: None"));
201 case 2:
202 case 1:
203 case 0:
205 } /* switch */
208 static void info_hook (void *data)
210 struct WInfo *info = (struct WInfo *) data;
211 Widget *other_widget;
213 other_widget = get_panel_widget (get_current_index ());
214 if (!other_widget)
215 return;
216 if (dlg_overlap (&info->widget, other_widget))
217 return;
219 info->ready = 1;
220 info_show_info (info);
223 static cb_ret_t
224 info_callback (Widget *w, widget_msg_t msg, int parm)
226 struct WInfo *info = (struct WInfo *) w;
228 switch (msg) {
230 case WIDGET_INIT:
231 add_hook (&select_file_hook, info_hook, info);
232 info->ready = 0;
233 return MSG_HANDLED;
235 case WIDGET_DRAW:
236 info_hook (info);
237 info_show_info (info);
238 return MSG_HANDLED;
240 case WIDGET_FOCUS:
241 return MSG_NOT_HANDLED;
243 case WIDGET_DESTROY:
244 delete_hook (&select_file_hook, info_hook);
245 return MSG_HANDLED;
247 default:
248 return default_proc (msg, parm);
252 struct WInfo *info_new ()
254 struct WInfo *info = g_new (struct WInfo, 1);
256 init_widget (&info->widget, 0, 0, 0, 0, info_callback, NULL);
258 /* We do not want the cursor */
259 widget_want_cursor (info->widget, 0);
261 if (!initialized){
262 initialized = 1;
263 init_my_statfs ();
266 return info;