mc_fhl_init_from_standard_files(): fixed logic and file read order for config files
[midnight-commander.git] / src / info.c
blobbc1d3174c6c4312b579b7c7314e62fad7300c055
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 /** \file info.c
20 * \brief Source: panel managing
23 #include <config.h>
25 #include <stdio.h>
26 #include <sys/stat.h>
28 #include "lib/global.h"
29 #include "lib/unixcompat.h"
30 #include "lib/tty/tty.h"
31 #include "lib/tty/key.h" /* is_idle() */
32 #include "lib/tty/mouse.h" /* Gpm_Event */
33 #include "lib/skin.h"
34 #include "lib/strutil.h"
36 #include "dialog.h"
37 #include "widget.h" /* default_proc */
38 #include "main-widgets.h" /* the_menubar */
39 #include "panel.h" /* for the panel structure */
40 #include "menu.h" /* menubar_visible */
41 #include "layout.h"
42 #include "mountlist.h"
43 #include "setup.h" /* panels_options */
44 #include "info.h"
46 #ifndef VERSION
47 # define VERSION "undefined"
48 #endif
50 struct WInfo
52 Widget widget;
53 int ready;
56 static struct my_statfs myfs_stats;
58 static void
59 info_box (struct WInfo *info)
61 const char *title = _("Information");
62 const int len = str_term_width1 (title);
64 tty_set_normal_attrs ();
65 tty_setcolor (NORMAL_COLOR);
66 widget_erase (&info->widget);
67 draw_box (info->widget.owner, info->widget.y, info->widget.x,
68 info->widget.lines, info->widget.cols, FALSE);
70 widget_move (&info->widget, 0, (info->widget.cols - len - 2)/2);
71 tty_printf (" %s ", title);
73 widget_move (&info->widget, 2, 0);
74 tty_print_alt_char (ACS_LTEE, FALSE);
75 widget_move (&info->widget, 2, info->widget.cols - 1);
76 tty_print_alt_char (ACS_RTEE, FALSE);
77 tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2);
80 static void
81 info_show_info (struct WInfo *info)
83 static int i18n_adjust = 0;
84 static const char *file_label;
85 GString *buff;
86 struct stat st;
88 if (!is_idle ())
89 return;
91 info_box (info);
93 tty_setcolor (MARKED_COLOR);
94 widget_move (&info->widget, 1, 3);
95 tty_printf (_("Midnight Commander %s"), VERSION);
97 if (!info->ready)
98 return;
100 if (get_current_type () != view_listing)
101 return;
103 my_statfs (&myfs_stats, current_panel->cwd);
104 st = current_panel->dir.list[current_panel->selected].st;
106 /* Print only lines which fit */
108 if (i18n_adjust == 0)
110 /* This printf pattern string is used as a reference for size */
111 file_label = _("File: %s");
112 i18n_adjust = str_term_width1 (file_label) + 2;
115 tty_setcolor (NORMAL_COLOR);
117 buff = g_string_new ("");
119 switch (info->widget.lines - 2)
121 /* Note: all cases are fall-throughs */
123 default:
125 case 16:
126 widget_move (&info->widget, 16, 3);
127 if (myfs_stats.nfree > 0 || myfs_stats.nodes > 0)
128 tty_printf (_("Free nodes: %ld (%ld%%) of %ld"),
129 (size_t) myfs_stats.nfree,
130 myfs_stats.nodes != 0
131 ? 100 * (size_t) myfs_stats.nfree / (size_t) myfs_stats.nodes : 0,
132 (size_t) myfs_stats.nodes);
133 else
134 tty_print_string (_("No node information"));
136 case 15:
137 widget_move (&info->widget, 15, 3);
138 if (myfs_stats.avail > 0 || myfs_stats.total > 0)
140 char buffer1[6], buffer2[6];
141 size_trunc_len (buffer1, 5, myfs_stats.avail, 1, panels_options.kilobyte_si);
142 size_trunc_len (buffer2, 5, myfs_stats.total, 1, panels_options.kilobyte_si);
143 tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
144 (int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0, buffer2);
146 else
147 tty_print_string (_("No space information"));
149 case 14:
150 widget_move (&info->widget, 14, 3);
151 tty_printf (_("Type: %s"),
152 myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
153 if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
154 tty_printf (" (%Xh)", myfs_stats.type);
156 case 13:
157 widget_move (&info->widget, 13, 3);
158 str_printf (buff, _("Device: %s"),
159 str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
160 tty_print_string (buff->str);
161 g_string_set_size (buff, 0);
162 case 12:
163 widget_move (&info->widget, 12, 3);
164 str_printf (buff, _("Filesystem: %s"),
165 str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
166 tty_print_string (buff->str);
167 g_string_set_size (buff, 0);
168 case 11:
169 widget_move (&info->widget, 11, 3);
170 str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
171 tty_print_string (buff->str);
172 g_string_set_size (buff, 0);
173 case 10:
174 widget_move (&info->widget, 10, 3);
175 str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
176 tty_print_string (buff->str);
177 g_string_set_size (buff, 0);
178 case 9:
179 widget_move (&info->widget, 9, 3);
180 /* The field st_ctime is changed by writing or by setting inode
181 information (i.e., owner, group, link count, mode, etc.). */
182 /* TRANSLATORS: Time of last status change as in stat(2) man. */
183 str_printf (buff, _("Changed: %s"), file_date (st.st_ctime));
184 tty_print_string (buff->str);
185 g_string_set_size (buff, 0);
187 case 8:
188 widget_move (&info->widget, 8, 3);
189 #ifdef HAVE_STRUCT_STAT_ST_RDEV
190 if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode))
191 tty_printf (_("Dev. type: major %lu, minor %lu"),
192 (unsigned long) major (st.st_rdev), (unsigned long) minor (st.st_rdev));
193 else
194 #endif
196 char buffer[10];
197 size_trunc_len (buffer, 9, st.st_size, 0, panels_options.kilobyte_si);
198 tty_printf (_("Size: %s"), buffer);
199 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
200 tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
201 (unsigned long int) st.st_blocks), (long int) st.st_blocks);
202 #endif
205 case 7:
206 widget_move (&info->widget, 7, 3);
207 tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid));
209 case 6:
210 widget_move (&info->widget, 6, 3);
211 tty_printf (_("Links: %d"), (int) st.st_nlink);
213 case 5:
214 widget_move (&info->widget, 5, 3);
215 tty_printf (_("Mode: %s (%04o)"),
216 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
218 case 4:
219 widget_move (&info->widget, 4, 3);
220 tty_printf (_("Location: %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino);
222 case 3:
224 const char *fname;
226 widget_move (&info->widget, 3, 2);
227 fname = current_panel->dir.list[current_panel->selected].fname;
228 str_printf (buff, file_label, str_trunc (fname, info->widget.cols - i18n_adjust));
229 tty_print_string (buff->str);
232 case 2:
233 case 1:
234 case 0:
236 } /* switch */
237 g_string_free (buff, TRUE);
240 static void
241 info_hook (void *data)
243 struct WInfo *info = (struct WInfo *) data;
244 Widget *other_widget;
246 other_widget = get_panel_widget (get_current_index ());
247 if (!other_widget)
248 return;
249 if (dlg_overlap (&info->widget, other_widget))
250 return;
252 info->ready = 1;
253 info_show_info (info);
256 static cb_ret_t
257 info_callback (Widget * w, widget_msg_t msg, int parm)
259 struct WInfo *info = (struct WInfo *) w;
261 switch (msg)
264 case WIDGET_INIT:
265 init_my_statfs ();
266 add_hook (&select_file_hook, info_hook, info);
267 info->ready = 0;
268 return MSG_HANDLED;
270 case WIDGET_DRAW:
271 info_hook (info);
272 return MSG_HANDLED;
274 case WIDGET_FOCUS:
275 return MSG_NOT_HANDLED;
277 case WIDGET_DESTROY:
278 delete_hook (&select_file_hook, info_hook);
279 free_my_statfs ();
280 return MSG_HANDLED;
282 default:
283 return default_proc (msg, parm);
287 static int
288 info_event (Gpm_Event * event, void *data)
290 Widget *w = &((WInfo *) data)->widget;
292 /* rest of the upper frame, the menu is invisible - call menu */
293 if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible)
295 event->x += w->x;
296 return the_menubar->widget.mouse (event, the_menubar);
299 return MOU_NORMAL;
302 WInfo *
303 info_new (int y, int x, int lines, int cols)
305 struct WInfo *info = g_new (struct WInfo, 1);
307 init_widget (&info->widget, y, x, lines, cols, info_callback, info_event);
309 /* We do not want the cursor */
310 widget_want_cursor (info->widget, 0);
312 return info;