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 (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 /* --------------------------------------------------------------------------------------------- */
100 info_show_info (struct WInfo
*info
)
102 static int i18n_adjust
= 0;
103 static const char *file_label
;
112 tty_setcolor (MARKED_COLOR
);
113 widget_move (&info
->widget
, 1, 3);
114 tty_printf (_("Midnight Commander %s"), VERSION
);
119 if (get_current_type () != view_listing
)
125 cwd_str
= vfs_path_to_str (current_panel
->cwd_vpath
);
126 my_statfs (&myfs_stats
, cwd_str
);
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 (info
->widget
.lines
- 2)
147 /* Note: all cases are fall-throughs */
152 widget_move (&info
->widget
, 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 (&info
->widget
, 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 (&info
->widget
, 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 (&info
->widget
, 13, 3);
186 str_printf (buff
, _("Device: %s"),
187 str_trunc (myfs_stats
.device
, info
->widget
.cols
- i18n_adjust
));
188 tty_print_string (buff
->str
);
189 g_string_set_size (buff
, 0);
191 widget_move (&info
->widget
, 12, 3);
192 str_printf (buff
, _("Filesystem: %s"),
193 str_trunc (myfs_stats
.mpoint
, info
->widget
.cols
- i18n_adjust
));
194 tty_print_string (buff
->str
);
195 g_string_set_size (buff
, 0);
197 widget_move (&info
->widget
, 11, 3);
198 str_printf (buff
, _("Accessed: %s"), file_date (st
.st_atime
));
199 tty_print_string (buff
->str
);
200 g_string_set_size (buff
, 0);
202 widget_move (&info
->widget
, 10, 3);
203 str_printf (buff
, _("Modified: %s"), file_date (st
.st_mtime
));
204 tty_print_string (buff
->str
);
205 g_string_set_size (buff
, 0);
207 widget_move (&info
->widget
, 9, 3);
208 /* The field st_ctime is changed by writing or by setting inode
209 information (i.e., owner, group, link count, mode, etc.). */
210 /* TRANSLATORS: Time of last status change as in stat(2) man. */
211 str_printf (buff
, _("Changed: %s"), file_date (st
.st_ctime
));
212 tty_print_string (buff
->str
);
213 g_string_set_size (buff
, 0);
216 widget_move (&info
->widget
, 8, 3);
217 #ifdef HAVE_STRUCT_STAT_ST_RDEV
218 if (S_ISCHR (st
.st_mode
) || S_ISBLK (st
.st_mode
))
219 tty_printf (_("Dev. type: major %lu, minor %lu"),
220 (unsigned long) major (st
.st_rdev
), (unsigned long) minor (st
.st_rdev
));
225 size_trunc_len (buffer
, 9, st
.st_size
, 0, panels_options
.kilobyte_si
);
226 tty_printf (_("Size: %s"), buffer
);
227 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
228 tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
229 (unsigned long) st
.st_blocks
), (unsigned long) st
.st_blocks
);
234 widget_move (&info
->widget
, 7, 3);
235 tty_printf (_("Owner: %s/%s"), get_owner (st
.st_uid
), get_group (st
.st_gid
));
238 widget_move (&info
->widget
, 6, 3);
239 tty_printf (_("Links: %d"), (int) st
.st_nlink
);
242 widget_move (&info
->widget
, 5, 3);
243 tty_printf (_("Mode: %s (%04o)"),
244 string_perm (st
.st_mode
), (unsigned) st
.st_mode
& 07777);
247 widget_move (&info
->widget
, 4, 3);
248 tty_printf (_("Location: %Xh:%Xh"), (int) st
.st_dev
, (int) st
.st_ino
);
254 widget_move (&info
->widget
, 3, 2);
255 fname
= current_panel
->dir
.list
[current_panel
->selected
].fname
;
256 str_printf (buff
, file_label
, str_trunc (fname
, info
->widget
.cols
- i18n_adjust
));
257 tty_print_string (buff
->str
);
265 g_string_free (buff
, TRUE
);
268 /* --------------------------------------------------------------------------------------------- */
271 info_hook (void *data
)
273 struct WInfo
*info
= (struct WInfo
*) data
;
274 Widget
*other_widget
;
276 other_widget
= get_panel_widget (get_current_index ());
279 if (dlg_overlap (&info
->widget
, other_widget
))
283 info_show_info (info
);
286 /* --------------------------------------------------------------------------------------------- */
289 info_callback (Widget
* w
, widget_msg_t msg
, int parm
)
291 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 default_proc (msg
, parm
);
319 /* --------------------------------------------------------------------------------------------- */
322 info_event (Gpm_Event
* event
, void *data
)
324 Widget
*w
= (Widget
*) data
;
327 if (!mouse_global_in_widget (event
, w
))
328 return MOU_UNHANDLED
;
330 local
= mouse_get_local (event
, w
);
332 /* rest of the upper frame, the menu is invisible - call menu */
333 if ((local
.type
& GPM_DOWN
) != 0 && local
.y
== 1 && !menubar_visible
)
334 return the_menubar
->widget
.mouse (event
, the_menubar
);
339 /* --------------------------------------------------------------------------------------------- */
340 /*** public functions ****************************************************************************/
341 /* --------------------------------------------------------------------------------------------- */
344 info_new (int y
, int x
, int lines
, int cols
)
346 struct WInfo
*info
= g_new (struct WInfo
, 1);
348 init_widget (&info
->widget
, y
, x
, lines
, cols
, info_callback
, info_event
);
350 /* We do not want the cursor */
351 widget_want_cursor (info
->widget
, 0);
356 /* --------------------------------------------------------------------------------------------- */