Added new fnction for manipulate vpath objects:
[midnight-commander.git] / src / filemanager / info.c
blobad0283bec7993b0c789fbdbeea9f2ad947df67a7
1 /*
2 Panel managing.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2007, 2011
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** \file info.c
25 * \brief Source: panel managing
28 #include <config.h>
30 #include <stdio.h>
31 #include <sys/stat.h>
32 #include <inttypes.h> /* PRIuMAX */
34 #include "lib/global.h"
35 #include "lib/unixcompat.h"
36 #include "lib/tty/tty.h"
37 #include "lib/tty/key.h" /* is_idle() */
38 #include "lib/tty/mouse.h" /* Gpm_Event */
39 #include "lib/skin.h"
40 #include "lib/strutil.h"
41 #include "lib/timefmt.h" /* file_date() */
42 #include "lib/util.h"
43 #include "lib/widget.h"
45 #include "src/setup.h" /* panels_options */
47 #include "midnight.h" /* the_menubar */
48 #include "layout.h"
49 #include "mountlist.h"
50 #include "info.h"
52 /*** global variables ****************************************************************************/
54 /*** file scope macro definitions ****************************************************************/
56 #ifndef VERSION
57 #define VERSION "undefined"
58 #endif
60 /*** file scope type declarations ****************************************************************/
62 struct WInfo
64 Widget widget;
65 int ready;
68 /*** file scope variables ************************************************************************/
70 static struct my_statfs myfs_stats;
72 /*** file scope functions ************************************************************************/
73 /* --------------------------------------------------------------------------------------------- */
75 static void
76 info_box (struct WInfo *info)
78 const char *title = _("Information");
79 const int len = str_term_width1 (title);
81 tty_set_normal_attrs ();
82 tty_setcolor (NORMAL_COLOR);
83 widget_erase (&info->widget);
84 draw_box (info->widget.owner, info->widget.y, info->widget.x,
85 info->widget.lines, info->widget.cols, FALSE);
87 widget_move (&info->widget, 0, (info->widget.cols - len - 2) / 2);
88 tty_printf (" %s ", title);
90 widget_move (&info->widget, 2, 0);
91 tty_print_alt_char (ACS_LTEE, FALSE);
92 widget_move (&info->widget, 2, info->widget.cols - 1);
93 tty_print_alt_char (ACS_RTEE, FALSE);
94 tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2);
97 /* --------------------------------------------------------------------------------------------- */
99 static void
100 info_show_info (struct WInfo *info)
102 static int i18n_adjust = 0;
103 static const char *file_label;
104 GString *buff;
105 struct stat st;
107 if (!is_idle ())
108 return;
110 info_box (info);
112 tty_setcolor (MARKED_COLOR);
113 widget_move (&info->widget, 1, 3);
114 tty_printf (_("Midnight Commander %s"), VERSION);
116 if (!info->ready)
117 return;
119 if (get_current_type () != view_listing)
120 return;
122 my_statfs (&myfs_stats, current_panel->cwd);
123 st = current_panel->dir.list[current_panel->selected].st;
125 /* Print only lines which fit */
127 if (i18n_adjust == 0)
129 /* This printf pattern string is used as a reference for size */
130 file_label = _("File: %s");
131 i18n_adjust = str_term_width1 (file_label) + 2;
134 tty_setcolor (NORMAL_COLOR);
136 buff = g_string_new ("");
138 switch (info->widget.lines - 2)
140 /* Note: all cases are fall-throughs */
142 default:
144 case 16:
145 widget_move (&info->widget, 16, 3);
146 if (myfs_stats.nfree == 0 && myfs_stats.nodes == 0)
147 tty_print_string (_("No node information"));
148 else
149 tty_printf ("%s %" PRIuMAX "/%" PRIuMAX " (%d%%)",
150 _("Free nodes:"),
151 myfs_stats.nfree, myfs_stats.nodes,
152 myfs_stats.nodes == 0 ? 0 :
153 (int) (100 * (long double) myfs_stats.nfree / myfs_stats.nodes));
155 case 15:
156 widget_move (&info->widget, 15, 3);
157 if (myfs_stats.avail == 0 && myfs_stats.total == 0)
158 tty_print_string (_("No space information"));
159 else
161 char buffer1[6], buffer2[6];
163 size_trunc_len (buffer1, 5, myfs_stats.avail, 1, panels_options.kilobyte_si);
164 size_trunc_len (buffer2, 5, myfs_stats.total, 1, panels_options.kilobyte_si);
165 tty_printf (_("Free space: %s/%s (%d%%)"), buffer1, buffer2,
166 myfs_stats.total == 0 ? 0 :
167 (int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
170 case 14:
171 widget_move (&info->widget, 14, 3);
172 tty_printf (_("Type: %s"),
173 myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
174 if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
175 tty_printf (" (%Xh)", myfs_stats.type);
177 case 13:
178 widget_move (&info->widget, 13, 3);
179 str_printf (buff, _("Device: %s"),
180 str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
181 tty_print_string (buff->str);
182 g_string_set_size (buff, 0);
183 case 12:
184 widget_move (&info->widget, 12, 3);
185 str_printf (buff, _("Filesystem: %s"),
186 str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
187 tty_print_string (buff->str);
188 g_string_set_size (buff, 0);
189 case 11:
190 widget_move (&info->widget, 11, 3);
191 str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
192 tty_print_string (buff->str);
193 g_string_set_size (buff, 0);
194 case 10:
195 widget_move (&info->widget, 10, 3);
196 str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
197 tty_print_string (buff->str);
198 g_string_set_size (buff, 0);
199 case 9:
200 widget_move (&info->widget, 9, 3);
201 /* The field st_ctime is changed by writing or by setting inode
202 information (i.e., owner, group, link count, mode, etc.). */
203 /* TRANSLATORS: Time of last status change as in stat(2) man. */
204 str_printf (buff, _("Changed: %s"), file_date (st.st_ctime));
205 tty_print_string (buff->str);
206 g_string_set_size (buff, 0);
208 case 8:
209 widget_move (&info->widget, 8, 3);
210 #ifdef HAVE_STRUCT_STAT_ST_RDEV
211 if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode))
212 tty_printf (_("Dev. type: major %lu, minor %lu"),
213 (unsigned long) major (st.st_rdev), (unsigned long) minor (st.st_rdev));
214 else
215 #endif
217 char buffer[10];
218 size_trunc_len (buffer, 9, st.st_size, 0, panels_options.kilobyte_si);
219 tty_printf (_("Size: %s"), buffer);
220 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
221 tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
222 (unsigned long) st.st_blocks), (unsigned long) st.st_blocks);
223 #endif
226 case 7:
227 widget_move (&info->widget, 7, 3);
228 tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid));
230 case 6:
231 widget_move (&info->widget, 6, 3);
232 tty_printf (_("Links: %d"), (int) st.st_nlink);
234 case 5:
235 widget_move (&info->widget, 5, 3);
236 tty_printf (_("Mode: %s (%04o)"),
237 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
239 case 4:
240 widget_move (&info->widget, 4, 3);
241 tty_printf (_("Location: %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino);
243 case 3:
245 const char *fname;
247 widget_move (&info->widget, 3, 2);
248 fname = current_panel->dir.list[current_panel->selected].fname;
249 str_printf (buff, file_label, str_trunc (fname, info->widget.cols - i18n_adjust));
250 tty_print_string (buff->str);
253 case 2:
254 case 1:
255 case 0:
257 } /* switch */
258 g_string_free (buff, TRUE);
261 /* --------------------------------------------------------------------------------------------- */
263 static void
264 info_hook (void *data)
266 struct WInfo *info = (struct WInfo *) data;
267 Widget *other_widget;
269 other_widget = get_panel_widget (get_current_index ());
270 if (!other_widget)
271 return;
272 if (dlg_overlap (&info->widget, other_widget))
273 return;
275 info->ready = 1;
276 info_show_info (info);
279 /* --------------------------------------------------------------------------------------------- */
281 static cb_ret_t
282 info_callback (Widget * w, widget_msg_t msg, int parm)
284 struct WInfo *info = (struct WInfo *) w;
286 switch (msg)
289 case WIDGET_INIT:
290 init_my_statfs ();
291 add_hook (&select_file_hook, info_hook, info);
292 info->ready = 0;
293 return MSG_HANDLED;
295 case WIDGET_DRAW:
296 info_hook (info);
297 return MSG_HANDLED;
299 case WIDGET_FOCUS:
300 return MSG_NOT_HANDLED;
302 case WIDGET_DESTROY:
303 delete_hook (&select_file_hook, info_hook);
304 free_my_statfs ();
305 return MSG_HANDLED;
307 default:
308 return default_proc (msg, parm);
312 /* --------------------------------------------------------------------------------------------- */
314 static int
315 info_event (Gpm_Event * event, void *data)
317 Widget *w = &((WInfo *) data)->widget;
319 /* rest of the upper frame, the menu is invisible - call menu */
320 if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible)
322 event->x += w->x;
323 return the_menubar->widget.mouse (event, the_menubar);
326 return MOU_NORMAL;
329 /* --------------------------------------------------------------------------------------------- */
330 /*** public functions ****************************************************************************/
331 /* --------------------------------------------------------------------------------------------- */
333 WInfo *
334 info_new (int y, int x, int lines, int cols)
336 struct WInfo *info = g_new (struct WInfo, 1);
338 init_widget (&info->widget, y, x, lines, cols, info_callback, info_event);
340 /* We do not want the cursor */
341 widget_want_cursor (info->widget, 0);
343 return info;
346 /* --------------------------------------------------------------------------------------------- */