Just a little correction at the it.po file.
[midnight-commander.git] / src / info.c
blob524d3aee1b14ffbf21b0665d25c876c689ae05f3
1 /* Panel managing.
2 Copyright (C) 1994, 1995 Janne Kukonlehto
3 Copyright (C) 1995 Miguel de Icaza
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #include <config.h>
20 #include <stdio.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
24 #include "global.h"
25 #include "tty.h"
26 #include "mouse.h" /* Gpm_Event */
27 #include "color.h"
28 #include "dlg.h"
29 #include "info.h"
30 #include "dir.h" /* required by panel */
31 #include "panel.h" /* for the panel structure */
32 #include "main.h" /* opanel, cpanel definitions */
33 #include "util.h" /* size_trunc_len */
34 #include "layout.h"
35 #include "key.h" /* is_idle() */
36 #include "mountlist.h"
38 #ifndef VERSION
39 # define VERSION "undefined"
40 #endif
42 /* Have we called the init_my_statfs routine? */
43 static int initialized;
44 static struct my_statfs myfs_stats;
46 static int info_event (Gpm_Event *event, WInfo *info)
48 return 0;
51 static void info_box (Dlg_head *h, WInfo *info)
53 standend ();
54 attrset (NORMAL_COLOR);
55 widget_erase (&info->widget);
56 draw_double_box (h, info->widget.y, info->widget.x,
57 info->widget.lines, info->widget.cols);
60 static void
61 info_show_info (WInfo *info)
63 static int i18n_adjust=0;
64 static char *file_label;
66 struct stat buf;
68 if (!is_idle ())
69 return;
71 info_box (info->widget.parent, info);
72 attrset (MARKED_COLOR);
73 widget_move (&info->widget, 1, 3);
74 printw (_("Midnight Commander %s"), VERSION);
75 attrset (NORMAL_COLOR);
76 widget_move (&info->widget, 2, 1);
77 /* .ado: info->widget.x has wrong value (==0) on Win32, why? */
78 #ifndef NATIVE_WIN32
79 hline (ACS_HLINE|NORMAL_COLOR, info->widget.x-2);
80 #endif
81 if (get_current_type () != view_listing)
82 return;
84 if (!info->ready)
85 return;
87 my_statfs (&myfs_stats, cpanel->cwd);
88 buf = cpanel->dir.list [cpanel->selected].buf;
89 #ifdef NATIVE_WIN32
90 /* .ado: for Win32, st_dev must > 0 */
91 if ((signed char) buf.st_dev < 0)
92 return;
93 #endif
95 /* Print only lines which fit */
97 if(!i18n_adjust) {
98 /* This printf pattern string is used as a reference for size */
99 file_label=_("File: %s");
100 i18n_adjust=strlen(file_label)+2;
103 switch (info->widget.lines-2){
104 /* Note: all cases are fall-throughs */
106 default:
108 case 16:
109 widget_move (&info->widget, 16, 3);
110 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
111 printw (_("Free nodes: %d (%d%%) of %d"),
112 myfs_stats.nfree,
113 myfs_stats.total
114 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
115 myfs_stats.nodes);
116 else
117 addstr (_("No node information"));
119 case 15:
120 widget_move (&info->widget, 15, 3);
121 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
122 char buffer1 [6], buffer2[6];
123 size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
124 size_trunc_len (buffer2, 5, myfs_stats.total, 1);
125 printw (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
126 100 * myfs_stats.avail / myfs_stats.total : 0, buffer2);
127 } else
128 addstr (_("No space information"));
130 case 14:
131 widget_move (&info->widget, 14, 3);
132 printw (_("Type: %s "), myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
133 if (myfs_stats.type != 0xffff && myfs_stats.type != 0xffffffff)
134 printw (" (%Xh)", myfs_stats.type);
136 case 13:
137 widget_move (&info->widget, 13, 3);
138 printw (_("Device: %s"),
139 name_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
140 case 12:
141 widget_move (&info->widget, 12, 3);
142 printw (_("Filesystem: %s"),
143 name_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
145 case 11:
146 widget_move (&info->widget, 11, 3);
147 printw (_("Accessed: %s"), file_date (buf.st_atime));
149 case 10:
150 widget_move (&info->widget, 10, 3);
151 printw (_("Modified: %s"), file_date (buf.st_mtime));
153 case 9:
154 widget_move (&info->widget, 9, 3);
155 printw (_("Created: %s"), file_date (buf.st_ctime));
157 case 8:
158 widget_move (&info->widget, 8, 3);
159 #if 0
160 #ifdef HAVE_ST_RDEV
161 if (buf.st_rdev)
162 printw ("Inode dev: major: %d, minor: %d",
163 buf.st_rdev >> 8, buf.st_rdev & 0xff);
164 else
165 #endif
166 #endif
168 char buffer[10];
169 size_trunc_len(buffer, 9, buf.st_size, 0);
170 printw (_("Size: %s"), buffer);
171 #ifdef HAVE_ST_BLOCKS
172 printw ((buf.st_blocks==1) ?
173 _(" (%d block)") : _(" (%d blocks)"), buf.st_blocks);
174 #endif
177 case 7:
178 widget_move (&info->widget, 7, 3);
179 printw (_("Owner: %s/%s"), get_owner (buf.st_uid),
180 get_group (buf.st_gid));
182 case 6:
183 widget_move (&info->widget, 6, 3);
184 printw (_("Links: %d"), (int) buf.st_nlink);
186 case 5:
187 widget_move (&info->widget, 5, 3);
188 printw (_("Mode: %s (%04o)"),
189 string_perm (buf.st_mode), buf.st_mode & 07777);
191 case 4:
192 widget_move (&info->widget, 4, 3);
193 printw (_("Location: %Xh:%Xh"), (int)buf.st_dev, (int)buf.st_ino);
195 case 3:
196 widget_move (&info->widget, 3, 2);
197 /* .ado: fname is invalid if selected == 0 && info called from current panel */
198 if (cpanel->selected){
199 printw (file_label,
200 name_trunc (cpanel->dir.list [cpanel->selected].fname,
201 info->widget.cols - i18n_adjust));
202 } else
203 printw (_("File: None"));
205 case 2:
206 case 1:
207 case 0:
209 } /* switch */
212 static void info_hook (void *data)
214 WInfo *info = (WInfo *) data;
215 Widget *other_widget;
217 other_widget = get_panel_widget (get_current_index ());
218 if (!other_widget)
219 return;
220 if (dlg_overlap (&info->widget, other_widget))
221 return;
223 info->ready = 1;
224 info_show_info (info);
227 static void info_destroy (WInfo *info)
229 delete_hook (&select_file_hook, info_hook);
232 static int info_callback (WInfo *info, int msg, int par)
234 switch (msg){
236 case WIDGET_INIT:
237 add_hook (&select_file_hook, info_hook, info);
238 info->ready = 0;
239 break;
241 case WIDGET_DRAW:
242 info_hook (info);
243 info_show_info (info);
244 return 1;
246 case WIDGET_FOCUS:
247 return 0;
249 return default_proc (msg, par);
252 WInfo *info_new ()
254 WInfo *info = g_new (WInfo, 1);
256 init_widget (&info->widget, 0, 0, 0, 0, (callback_fn)
257 info_callback, (destroy_fn) info_destroy,
258 (mouse_h) info_event, NULL);
260 /* We do not want the cursor */
261 widget_want_cursor (info->widget, 0);
263 if (!initialized){
264 initialized = 1;
265 init_my_statfs ();
268 return info;