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
)
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 */
145 widget_move (&info
->widget
, 16, 3);
146 if (myfs_stats
.nfree
== 0 && myfs_stats
.nodes
== 0)
147 tty_print_string (_("No node information"));
149 tty_printf ("%s %" PRIuMAX
"/%" PRIuMAX
" (%d%%)",
151 myfs_stats
.nfree
, myfs_stats
.nodes
,
152 myfs_stats
.nodes
== 0 ? 0 :
153 (int) (100 * (long double) myfs_stats
.nfree
/ myfs_stats
.nodes
));
156 widget_move (&info
->widget
, 15, 3);
157 if (myfs_stats
.avail
== 0 && myfs_stats
.total
== 0)
158 tty_print_string (_("No space information"));
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
));
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
);
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);
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);
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);
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);
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);
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
));
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
);
227 widget_move (&info
->widget
, 7, 3);
228 tty_printf (_("Owner: %s/%s"), get_owner (st
.st_uid
), get_group (st
.st_gid
));
231 widget_move (&info
->widget
, 6, 3);
232 tty_printf (_("Links: %d"), (int) st
.st_nlink
);
235 widget_move (&info
->widget
, 5, 3);
236 tty_printf (_("Mode: %s (%04o)"),
237 string_perm (st
.st_mode
), (unsigned) st
.st_mode
& 07777);
240 widget_move (&info
->widget
, 4, 3);
241 tty_printf (_("Location: %Xh:%Xh"), (int) st
.st_dev
, (int) st
.st_ino
);
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
);
258 g_string_free (buff
, TRUE
);
261 /* --------------------------------------------------------------------------------------------- */
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 ());
272 if (dlg_overlap (&info
->widget
, other_widget
))
276 info_show_info (info
);
279 /* --------------------------------------------------------------------------------------------- */
282 info_callback (Widget
* w
, widget_msg_t msg
, int parm
)
284 struct WInfo
*info
= (struct WInfo
*) w
;
291 add_hook (&select_file_hook
, info_hook
, info
);
300 return MSG_NOT_HANDLED
;
303 delete_hook (&select_file_hook
, info_hook
);
308 return default_proc (msg
, parm
);
312 /* --------------------------------------------------------------------------------------------- */
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
)
323 return the_menubar
->widget
.mouse (event
, the_menubar
);
329 /* --------------------------------------------------------------------------------------------- */
330 /*** public functions ****************************************************************************/
331 /* --------------------------------------------------------------------------------------------- */
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);
346 /* --------------------------------------------------------------------------------------------- */