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