This source file includes following definitions.
- info_box
- info_show_info
- info_hook
- info_callback
- info_new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <config.h>
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <sys/stat.h>
36 #include <inttypes.h>
37 #ifdef ENABLE_EXT2FS_ATTR
38 #include <e2p/e2p.h>
39 #endif
40
41 #include "lib/global.h"
42 #include "lib/unixcompat.h"
43 #include "lib/tty/tty.h"
44 #include "lib/tty/key.h"
45 #include "lib/skin.h"
46 #include "lib/strutil.h"
47 #include "lib/timefmt.h"
48 #include "lib/util.h"
49 #include "lib/widget.h"
50
51 #include "src/setup.h"
52
53 #include "filemanager.h"
54 #include "layout.h"
55 #include "mountlist.h"
56 #ifdef ENABLE_EXT2FS_ATTR
57 #include "cmd.h"
58 #endif
59
60 #include "info.h"
61
62
63
64
65
66
67
68 struct WInfo
69 {
70 Widget widget;
71 gboolean ready;
72 };
73
74
75
76 static struct my_statfs myfs_stats;
77
78
79
80
81 static void
82 info_box (WInfo * info)
83 {
84 Widget *w = WIDGET (info);
85
86 const char *title = _("Information");
87 const int len = str_term_width1 (title);
88
89 tty_set_normal_attrs ();
90 tty_setcolor (NORMAL_COLOR);
91 widget_erase (w);
92 tty_draw_box (w->y, w->x, w->lines, w->cols, FALSE);
93
94 widget_gotoyx (w, 0, (w->cols - len - 2) / 2);
95 tty_printf (" %s ", title);
96
97 widget_gotoyx (w, 2, 0);
98 tty_print_alt_char (ACS_LTEE, FALSE);
99 widget_gotoyx (w, 2, w->cols - 1);
100 tty_print_alt_char (ACS_RTEE, FALSE);
101 tty_draw_hline (w->y + 2, w->x + 1, ACS_HLINE, w->cols - 2);
102 }
103
104
105
106 static void
107 info_show_info (WInfo * info)
108 {
109 Widget *w = WIDGET (info);
110 static int i18n_adjust = 0;
111 static const char *file_label;
112 GString *buff;
113 struct stat st;
114 char rp_cwd[PATH_MAX];
115 const char *p_rp_cwd;
116
117 if (!is_idle ())
118 return;
119
120 info_box (info);
121
122 tty_setcolor (MARKED_COLOR);
123 widget_gotoyx (w, 1, 3);
124 tty_printf (_("Midnight Commander %s"), mc_global.mc_version);
125
126 if (!info->ready)
127 return;
128
129 if (get_current_type () != view_listing)
130 return;
131
132
133 p_rp_cwd = mc_realpath (vfs_path_as_str (current_panel->cwd_vpath), rp_cwd);
134 if (p_rp_cwd == NULL)
135 p_rp_cwd = vfs_path_as_str (current_panel->cwd_vpath);
136
137 my_statfs (&myfs_stats, p_rp_cwd);
138
139 st = current_panel->dir.list[current_panel->selected].st;
140
141
142
143 if (i18n_adjust == 0)
144 {
145
146 file_label = _("File: %s");
147 i18n_adjust = str_term_width1 (file_label) + 2;
148 }
149
150 tty_setcolor (NORMAL_COLOR);
151
152 buff = g_string_new ("");
153
154 switch (w->lines - 2)
155 {
156
157
158 default:
159 MC_FALLTHROUGH;
160 case 17:
161 widget_gotoyx (w, 17, 3);
162 if ((myfs_stats.nfree == 0 && myfs_stats.nodes == 0) ||
163 (myfs_stats.nfree == (uintmax_t) (-1) && myfs_stats.nodes == (uintmax_t) (-1)))
164 tty_print_string (_("No node information"));
165 else if (myfs_stats.nfree == (uintmax_t) (-1))
166 tty_printf ("%s -/%" PRIuMAX, _("Free nodes:"), myfs_stats.nodes);
167 else if (myfs_stats.nodes == (uintmax_t) (-1))
168 tty_printf ("%s %" PRIuMAX "/-", _("Free nodes:"), myfs_stats.nfree);
169 else
170 tty_printf ("%s %" PRIuMAX "/%" PRIuMAX " (%d%%)",
171 _("Free nodes:"),
172 myfs_stats.nfree, myfs_stats.nodes,
173 myfs_stats.nodes == 0 ? 0 :
174 (int) (100 * (long double) myfs_stats.nfree / myfs_stats.nodes));
175 MC_FALLTHROUGH;
176 case 16:
177 widget_gotoyx (w, 16, 3);
178 if (myfs_stats.avail == 0 && myfs_stats.total == 0)
179 tty_print_string (_("No space information"));
180 else
181 {
182 char buffer1[6], buffer2[6];
183
184 size_trunc_len (buffer1, 5, myfs_stats.avail, 1, panels_options.kilobyte_si);
185 size_trunc_len (buffer2, 5, myfs_stats.total, 1, panels_options.kilobyte_si);
186 tty_printf (_("Free space: %s/%s (%d%%)"), buffer1, buffer2,
187 myfs_stats.total == 0 ? 0 :
188 (int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
189 }
190 MC_FALLTHROUGH;
191 case 15:
192 widget_gotoyx (w, 15, 3);
193 tty_printf (_("Type: %s"),
194 myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
195 if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
196 tty_printf (" (%Xh)", (unsigned int) myfs_stats.type);
197 MC_FALLTHROUGH;
198 case 14:
199 widget_gotoyx (w, 14, 3);
200 str_printf (buff, _("Device: %s"),
201 str_trunc (myfs_stats.device, w->cols - i18n_adjust));
202 tty_print_string (buff->str);
203 g_string_set_size (buff, 0);
204 MC_FALLTHROUGH;
205 case 13:
206 widget_gotoyx (w, 13, 3);
207 str_printf (buff, _("Filesystem: %s"),
208 str_trunc (myfs_stats.mpoint, w->cols - i18n_adjust));
209 tty_print_string (buff->str);
210 g_string_set_size (buff, 0);
211 MC_FALLTHROUGH;
212 case 12:
213 widget_gotoyx (w, 12, 3);
214 str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
215 tty_print_string (buff->str);
216 g_string_set_size (buff, 0);
217 MC_FALLTHROUGH;
218 case 11:
219 widget_gotoyx (w, 11, 3);
220 str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
221 tty_print_string (buff->str);
222 g_string_set_size (buff, 0);
223 MC_FALLTHROUGH;
224 case 10:
225 widget_gotoyx (w, 10, 3);
226
227
228
229 str_printf (buff, _("Changed: %s"), file_date (st.st_ctime));
230 tty_print_string (buff->str);
231 g_string_set_size (buff, 0);
232 MC_FALLTHROUGH;
233 case 9:
234 widget_gotoyx (w, 9, 3);
235 #ifdef HAVE_STRUCT_STAT_ST_RDEV
236 if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode))
237 tty_printf (_("Dev. type: major %lu, minor %lu"),
238 (unsigned long) major (st.st_rdev), (unsigned long) minor (st.st_rdev));
239 else
240 #endif
241 {
242 char buffer[10];
243 size_trunc_len (buffer, 9, st.st_size, 0, panels_options.kilobyte_si);
244 tty_printf (_("Size: %s"), buffer);
245 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
246 tty_printf (ngettext (" (%lu block)", " (%lu blocks)",
247 (unsigned long) st.st_blocks), (unsigned long) st.st_blocks);
248 #endif
249 }
250 MC_FALLTHROUGH;
251 case 8:
252 widget_gotoyx (w, 8, 3);
253 tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid));
254 MC_FALLTHROUGH;
255 case 7:
256 widget_gotoyx (w, 7, 3);
257 tty_printf (_("Links: %d"), (int) st.st_nlink);
258 MC_FALLTHROUGH;
259 case 6:
260 widget_gotoyx (w, 6, 3);
261 #ifdef ENABLE_EXT2FS_ATTR
262 if (!vfs_current_is_local ())
263 tty_print_string (_("Attributes: not supported"));
264 else
265 {
266 vfs_path_t *vpath;
267 unsigned long attr;
268
269 vpath = vfs_path_from_str (current_panel->dir.list[current_panel->selected].fname->str);
270
271 if (fgetflags (vfs_path_as_str (vpath), &attr) == 0)
272 tty_printf (_("Attributes: %s"), chattr_get_as_str (attr));
273 else
274 tty_print_string (_("Attributes: unavailable"));
275
276 vfs_path_free (vpath, TRUE);
277 }
278 #else
279 tty_print_string (_("Attributes: not supported"));
280 #endif
281 MC_FALLTHROUGH;
282 case 5:
283 widget_gotoyx (w, 5, 3);
284 tty_printf (_("Mode: %s (%04o)"),
285 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
286 MC_FALLTHROUGH;
287 case 4:
288 widget_gotoyx (w, 4, 3);
289 tty_printf (_("Location: %Xh:%Xh"), (unsigned int) st.st_dev, (unsigned int) st.st_ino);
290 MC_FALLTHROUGH;
291 case 3:
292 {
293 const char *fname;
294
295 widget_gotoyx (w, 3, 2);
296 fname = current_panel->dir.list[current_panel->selected].fname->str;
297 str_printf (buff, file_label, str_trunc (fname, w->cols - i18n_adjust));
298 tty_print_string (buff->str);
299 }
300 MC_FALLTHROUGH;
301 case 2:
302 MC_FALLTHROUGH;
303 case 1:
304 MC_FALLTHROUGH;
305 case 0:
306 ;
307 }
308 g_string_free (buff, TRUE);
309 }
310
311
312
313 static void
314 info_hook (void *data)
315 {
316 WInfo *info = (WInfo *) data;
317 Widget *other_widget;
318
319 other_widget = get_panel_widget (get_current_index ());
320 if (!other_widget)
321 return;
322 if (widget_overlapped (WIDGET (info), other_widget))
323 return;
324
325 info->ready = TRUE;
326 info_show_info (info);
327 }
328
329
330
331 static cb_ret_t
332 info_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
333 {
334 WInfo *info = (WInfo *) w;
335
336 switch (msg)
337 {
338 case MSG_INIT:
339 init_my_statfs ();
340 add_hook (&select_file_hook, info_hook, info);
341 info->ready = FALSE;
342 return MSG_HANDLED;
343
344 case MSG_DRAW:
345 info_hook (info);
346 return MSG_HANDLED;
347
348 case MSG_DESTROY:
349 delete_hook (&select_file_hook, info_hook);
350 free_my_statfs ();
351 return MSG_HANDLED;
352
353 default:
354 return widget_default_callback (w, sender, msg, parm, data);
355 }
356 }
357
358
359
360
361
362 WInfo *
363 info_new (int y, int x, int lines, int cols)
364 {
365 WInfo *info;
366 Widget *w;
367
368 info = g_new (struct WInfo, 1);
369 w = WIDGET (info);
370 widget_init (w, y, x, lines, cols, info_callback, NULL);
371
372 return info;
373 }
374
375