4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
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/>.
25 * \brief Source: panel managing
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 */
40 #include "lib/strutil.h"
41 #include "lib/timefmt.h" /* file_date() */
43 #include "lib/widget.h"
45 #include "src/setup.h" /* panels_options */
47 #include "midnight.h" /* the_menubar */
49 #include "mountlist.h"
52 /*** global variables ****************************************************************************/
54 /*** file scope macro definitions ****************************************************************/
57 #define VERSION "undefined"
60 /*** file scope type declarations ****************************************************************/
68 /*** file scope variables ************************************************************************/
70 static struct my_statfs myfs_stats
;
72 /*** file scope functions ************************************************************************/
73 /* --------------------------------------------------------------------------------------------- */
76 info_box (WInfo
* info
)
78 Widget
*w
= WIDGET (info
);
80 const char *title
= _("Information");
81 const int len
= str_term_width1 (title
);
83 tty_set_normal_attrs ();
84 tty_setcolor (NORMAL_COLOR
);
86 draw_box (w
->owner
, w
->y
, w
->x
, w
->lines
, w
->cols
, FALSE
);
88 widget_move (w
, 0, (w
->cols
- len
- 2) / 2);
89 tty_printf (" %s ", title
);
91 widget_move (w
, 2, 0);
92 tty_print_alt_char (ACS_LTEE
, FALSE
);
93 widget_move (w
, 2, w
->cols
- 1);
94 tty_print_alt_char (ACS_RTEE
, FALSE
);
95 tty_draw_hline (w
->y
+ 2, w
->x
+ 1, ACS_HLINE
, w
->cols
- 2);
98 /* --------------------------------------------------------------------------------------------- */
101 info_show_info (WInfo
* info
)
103 Widget
*w
= WIDGET (info
);
104 static int i18n_adjust
= 0;
105 static const char *file_label
;
114 tty_setcolor (MARKED_COLOR
);
115 widget_move (w
, 1, 3);
116 tty_printf (_("Midnight Commander %s"), VERSION
);
121 if (get_current_type () != view_listing
)
127 cwd_str
= vfs_path_to_str (current_panel
->cwd_vpath
);
128 my_statfs (&myfs_stats
, cwd_str
);
132 st
= current_panel
->dir
.list
[current_panel
->selected
].st
;
134 /* Print only lines which fit */
136 if (i18n_adjust
== 0)
138 /* This printf pattern string is used as a reference for size */
139 file_label
= _("File: %s");
140 i18n_adjust
= str_term_width1 (file_label
) + 2;
143 tty_setcolor (NORMAL_COLOR
);
145 buff
= g_string_new ("");
147 switch (w
->lines
- 2)
149 /* Note: all cases are fall-throughs */
154 widget_move (w
, 16, 3);
155 if (myfs_stats
.nfree
== 0 && myfs_stats
.nodes
== 0)
156 tty_print_string (_("No node information"));
158 tty_printf ("%s %" PRIuMAX
"/%" PRIuMAX
" (%d%%)",
160 myfs_stats
.nfree
, myfs_stats
.nodes
,
161 myfs_stats
.nodes
== 0 ? 0 :
162 (int) (100 * (long double) myfs_stats
.nfree
/ myfs_stats
.nodes
));
165 widget_move (w
, 15, 3);
166 if (myfs_stats
.avail
== 0 && myfs_stats
.total
== 0)
167 tty_print_string (_("No space information"));
170 char buffer1
[6], buffer2
[6];
172 size_trunc_len (buffer1
, 5, myfs_stats
.avail
, 1, panels_options
.kilobyte_si
);
173 size_trunc_len (buffer2
, 5, myfs_stats
.total
, 1, panels_options
.kilobyte_si
);
174 tty_printf (_("Free space: %s/%s (%d%%)"), buffer1
, buffer2
,
175 myfs_stats
.total
== 0 ? 0 :
176 (int) (100 * (long double) myfs_stats
.avail
/ myfs_stats
.total
));
180 widget_move (w
, 14, 3);
181 tty_printf (_("Type: %s"),
182 myfs_stats
.typename
? myfs_stats
.typename
: _("non-local vfs"));
183 if (myfs_stats
.type
!= 0xffff && myfs_stats
.type
!= -1)
184 tty_printf (" (%Xh)", myfs_stats
.type
);
187 widget_move (w
, 13, 3);
188 str_printf (buff
, _("Device: %s"), str_trunc (myfs_stats
.device
, w
->cols
- i18n_adjust
));
189 tty_print_string (buff
->str
);
190 g_string_set_size (buff
, 0);
192 widget_move (w
, 12, 3);
193 str_printf (buff
, _("Filesystem: %s"),
194 str_trunc (myfs_stats
.mpoint
, w
->cols
- i18n_adjust
));
195 tty_print_string (buff
->str
);
196 g_string_set_size (buff
, 0);
198 widget_move (w
, 11, 3);
199 str_printf (buff
, _("Accessed: %s"), file_date (st
.st_atime
));
200 tty_print_string (buff
->str
);
201 g_string_set_size (buff
, 0);
203 widget_move (w
, 10, 3);
204 str_printf (buff
, _("Modified: %s"), file_date (st
.st_mtime
));
205 tty_print_string (buff
->str
);
206 g_string_set_size (buff
, 0);
208 widget_move (w
, 9, 3);
209 /* The field st_ctime is changed by writing or by setting inode
210 information (i.e., owner, group, link count, mode, etc.). */
211 /* TRANSLATORS: Time of last status change as in stat(2) man. */
212 str_printf (buff
, _("Changed: %s"), file_date (st
.st_ctime
));
213 tty_print_string (buff
->str
);
214 g_string_set_size (buff
, 0);
217 widget_move (w
, 8, 3);
218 #ifdef HAVE_STRUCT_STAT_ST_RDEV
219 if (S_ISCHR (st
.st_mode
) || S_ISBLK (st
.st_mode
))
220 tty_printf (_("Dev. type: major %lu, minor %lu"),
221 (unsigned long) major (st
.st_rdev
), (unsigned long) minor (st
.st_rdev
));
226 size_trunc_len (buffer
, 9, st
.st_size
, 0, panels_options
.kilobyte_si
);
227 tty_printf (_("Size: %s"), buffer
);
228 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
229 tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
230 (unsigned long) st
.st_blocks
), (unsigned long) st
.st_blocks
);
235 widget_move (w
, 7, 3);
236 tty_printf (_("Owner: %s/%s"), get_owner (st
.st_uid
), get_group (st
.st_gid
));
239 widget_move (w
, 6, 3);
240 tty_printf (_("Links: %d"), (int) st
.st_nlink
);
243 widget_move (w
, 5, 3);
244 tty_printf (_("Mode: %s (%04o)"),
245 string_perm (st
.st_mode
), (unsigned) st
.st_mode
& 07777);
248 widget_move (w
, 4, 3);
249 tty_printf (_("Location: %Xh:%Xh"), (int) st
.st_dev
, (int) st
.st_ino
);
255 widget_move (w
, 3, 2);
256 fname
= current_panel
->dir
.list
[current_panel
->selected
].fname
;
257 str_printf (buff
, file_label
, str_trunc (fname
, w
->cols
- i18n_adjust
));
258 tty_print_string (buff
->str
);
266 g_string_free (buff
, TRUE
);
269 /* --------------------------------------------------------------------------------------------- */
272 info_hook (void *data
)
274 struct WInfo
*info
= (struct WInfo
*) data
;
275 Widget
*other_widget
;
277 other_widget
= get_panel_widget (get_current_index ());
280 if (dlg_overlap (WIDGET (info
), other_widget
))
284 info_show_info (info
);
287 /* --------------------------------------------------------------------------------------------- */
290 info_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
292 struct WInfo
*info
= (struct WInfo
*) w
;
298 add_hook (&select_file_hook
, info_hook
, info
);
307 return MSG_NOT_HANDLED
;
310 delete_hook (&select_file_hook
, info_hook
);
315 return widget_default_callback (w
, sender
, msg
, parm
, data
);
319 /* --------------------------------------------------------------------------------------------- */
320 /*** public functions ****************************************************************************/
321 /* --------------------------------------------------------------------------------------------- */
324 info_new (int y
, int x
, int lines
, int cols
)
329 info
= g_new (struct WInfo
, 1);
331 init_widget (w
, y
, x
, lines
, cols
, info_callback
, NULL
);
332 /* We do not want the cursor */
333 widget_want_cursor (w
, FALSE
);
338 /* --------------------------------------------------------------------------------------------- */