4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 The Free Software Foundation, Inc.
9 Slava Zanko <slavazanko@gmail.com>, 2013
10 Andrew Borodin <aborodin@vmail.ru>, 2013
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * \brief Source: panel managing
36 #include <inttypes.h> /* PRIuMAX */
38 #include "lib/global.h"
39 #include "lib/unixcompat.h"
40 #include "lib/tty/tty.h"
41 #include "lib/tty/key.h" /* is_idle() */
42 #include "lib/tty/mouse.h" /* Gpm_Event */
44 #include "lib/strutil.h"
45 #include "lib/timefmt.h" /* file_date() */
47 #include "lib/widget.h"
49 #include "src/setup.h" /* panels_options */
51 #include "midnight.h" /* the_menubar */
53 #include "mountlist.h"
56 /*** global variables ****************************************************************************/
58 /*** file scope macro definitions ****************************************************************/
61 #define VERSION "undefined"
64 /*** file scope type declarations ****************************************************************/
72 /*** file scope variables ************************************************************************/
74 static struct my_statfs myfs_stats
;
76 /*** file scope functions ************************************************************************/
77 /* --------------------------------------------------------------------------------------------- */
80 info_box (WInfo
* info
)
82 Widget
*w
= WIDGET (info
);
84 const char *title
= _("Information");
85 const int len
= str_term_width1 (title
);
87 tty_set_normal_attrs ();
88 tty_setcolor (NORMAL_COLOR
);
90 tty_draw_box (w
->y
, w
->x
, w
->lines
, w
->cols
, FALSE
);
92 widget_move (w
, 0, (w
->cols
- len
- 2) / 2);
93 tty_printf (" %s ", title
);
95 widget_move (w
, 2, 0);
96 tty_print_alt_char (ACS_LTEE
, FALSE
);
97 widget_move (w
, 2, w
->cols
- 1);
98 tty_print_alt_char (ACS_RTEE
, FALSE
);
99 tty_draw_hline (w
->y
+ 2, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
102 /* --------------------------------------------------------------------------------------------- */
105 info_show_info (WInfo
* info
)
107 Widget
*w
= WIDGET (info
);
108 static int i18n_adjust
= 0;
109 static const char *file_label
;
118 tty_setcolor (MARKED_COLOR
);
119 widget_move (w
, 1, 3);
120 tty_printf (_("Midnight Commander %s"), VERSION
);
125 if (get_current_type () != view_listing
)
128 my_statfs (&myfs_stats
, vfs_path_as_str (current_panel
->cwd_vpath
));
130 st
= current_panel
->dir
.list
[current_panel
->selected
].st
;
132 /* Print only lines which fit */
134 if (i18n_adjust
== 0)
136 /* This printf pattern string is used as a reference for size */
137 file_label
= _("File: %s");
138 i18n_adjust
= str_term_width1 (file_label
) + 2;
141 tty_setcolor (NORMAL_COLOR
);
143 buff
= g_string_new ("");
145 switch (w
->lines
- 2)
147 /* Note: all cases are fall-throughs */
152 widget_move (w
, 16, 3);
153 if (myfs_stats
.nfree
== 0 && myfs_stats
.nodes
== 0)
154 tty_print_string (_("No node information"));
156 tty_printf ("%s %" PRIuMAX
"/%" PRIuMAX
" (%d%%)",
158 myfs_stats
.nfree
, myfs_stats
.nodes
,
159 myfs_stats
.nodes
== 0 ? 0 :
160 (int) (100 * (long double) myfs_stats
.nfree
/ myfs_stats
.nodes
));
163 widget_move (w
, 15, 3);
164 if (myfs_stats
.avail
== 0 && myfs_stats
.total
== 0)
165 tty_print_string (_("No space information"));
168 char buffer1
[6], buffer2
[6];
170 size_trunc_len (buffer1
, 5, myfs_stats
.avail
, 1, panels_options
.kilobyte_si
);
171 size_trunc_len (buffer2
, 5, myfs_stats
.total
, 1, panels_options
.kilobyte_si
);
172 tty_printf (_("Free space: %s/%s (%d%%)"), buffer1
, buffer2
,
173 myfs_stats
.total
== 0 ? 0 :
174 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
178 widget_move (w
, 14, 3);
179 tty_printf (_("Type: %s"),
180 myfs_stats
.typename
? myfs_stats
.typename
: _("non-local vfs"));
181 if (myfs_stats
.type
!= 0xffff && myfs_stats
.type
!= -1)
182 tty_printf (" (%Xh)", myfs_stats
.type
);
185 widget_move (w
, 13, 3);
186 str_printf (buff
, _("Device: %s"), str_trunc (myfs_stats
.device
, w
->cols
- i18n_adjust
));
187 tty_print_string (buff
->str
);
188 g_string_set_size (buff
, 0);
190 widget_move (w
, 12, 3);
191 str_printf (buff
, _("Filesystem: %s"),
192 str_trunc (myfs_stats
.mpoint
, w
->cols
- i18n_adjust
));
193 tty_print_string (buff
->str
);
194 g_string_set_size (buff
, 0);
196 widget_move (w
, 11, 3);
197 str_printf (buff
, _("Accessed: %s"), file_date (st
.st_atime
));
198 tty_print_string (buff
->str
);
199 g_string_set_size (buff
, 0);
201 widget_move (w
, 10, 3);
202 str_printf (buff
, _("Modified: %s"), file_date (st
.st_mtime
));
203 tty_print_string (buff
->str
);
204 g_string_set_size (buff
, 0);
206 widget_move (w
, 9, 3);
207 /* The field st_ctime is changed by writing or by setting inode
208 information (i.e., owner, group, link count, mode, etc.). */
209 /* TRANSLATORS: Time of last status change as in stat(2) man. */
210 str_printf (buff
, _("Changed: %s"), file_date (st
.st_ctime
));
211 tty_print_string (buff
->str
);
212 g_string_set_size (buff
, 0);
215 widget_move (w
, 8, 3);
216 #ifdef HAVE_STRUCT_STAT_ST_RDEV
217 if (S_ISCHR (st
.st_mode
) || S_ISBLK (st
.st_mode
))
218 tty_printf (_("Dev. type: major %lu, minor %lu"),
219 (unsigned long) major (st
.st_rdev
), (unsigned long) minor (st
.st_rdev
));
224 size_trunc_len (buffer
, 9, st
.st_size
, 0, panels_options
.kilobyte_si
);
225 tty_printf (_("Size: %s"), buffer
);
226 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
227 tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
228 (unsigned long) st
.st_blocks
), (unsigned long) st
.st_blocks
);
233 widget_move (w
, 7, 3);
234 tty_printf (_("Owner: %s/%s"), get_owner (st
.st_uid
), get_group (st
.st_gid
));
237 widget_move (w
, 6, 3);
238 tty_printf (_("Links: %d"), (int) st
.st_nlink
);
241 widget_move (w
, 5, 3);
242 tty_printf (_("Mode: %s (%04o)"),
243 string_perm (st
.st_mode
), (unsigned) st
.st_mode
& 07777);
246 widget_move (w
, 4, 3);
247 tty_printf (_("Location: %Xh:%Xh"), (int) st
.st_dev
, (int) st
.st_ino
);
253 widget_move (w
, 3, 2);
254 fname
= current_panel
->dir
.list
[current_panel
->selected
].fname
;
255 str_printf (buff
, file_label
, str_trunc (fname
, w
->cols
- i18n_adjust
));
256 tty_print_string (buff
->str
);
264 g_string_free (buff
, TRUE
);
267 /* --------------------------------------------------------------------------------------------- */
270 info_hook (void *data
)
272 struct WInfo
*info
= (struct WInfo
*) data
;
273 Widget
*other_widget
;
275 other_widget
= get_panel_widget (get_current_index ());
278 if (widget_overlapped (WIDGET (info
), other_widget
))
282 info_show_info (info
);
285 /* --------------------------------------------------------------------------------------------- */
288 info_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
290 struct WInfo
*info
= (struct WInfo
*) w
;
296 add_hook (&select_file_hook
, info_hook
, info
);
305 return MSG_NOT_HANDLED
;
308 delete_hook (&select_file_hook
, info_hook
);
313 return widget_default_callback (w
, sender
, msg
, parm
, data
);
317 /* --------------------------------------------------------------------------------------------- */
318 /*** public functions ****************************************************************************/
319 /* --------------------------------------------------------------------------------------------- */
322 info_new (int y
, int x
, int lines
, int cols
)
327 info
= g_new (struct WInfo
, 1);
329 init_widget (w
, y
, x
, lines
, cols
, info_callback
, NULL
);
330 /* We do not want the cursor */
331 widget_want_cursor (w
, FALSE
);
336 /* --------------------------------------------------------------------------------------------- */