Forgot to remove some more .s strings and do a rename in order to prevent compiler...
[midnight-commander.git] / src / info.c
blob7d5a57864f8cc955cd0f53737c28e0ece0488857
1 /* Panel managing.
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2007 Free Software Foundation, Inc.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 #include <config.h>
21 #include <stdio.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
26 #include "global.h"
27 #include "tty.h"
28 #include "mouse.h" /* Gpm_Event */
29 #include "color.h"
30 #include "dialog.h"
31 #include "info.h"
32 #include "dir.h" /* required by panel */
33 #include "panel.h" /* for the panel structure */
34 #include "main.h" /* other_panel, current_panel definitions */
35 #include "util.h" /* size_trunc_len */
36 #include "layout.h"
37 #include "key.h" /* is_idle() */
38 #include "mountlist.h"
39 #include "unixcompat.h"
41 #ifndef VERSION
42 # define VERSION "undefined"
43 #endif
45 struct WInfo {
46 Widget widget;
47 int ready;
50 /* Have we called the init_my_statfs routine? */
51 static int initialized;
52 static struct my_statfs myfs_stats;
54 static void info_box (Dlg_head *h, struct WInfo *info)
56 standend ();
57 attrset (NORMAL_COLOR);
58 widget_erase (&info->widget);
59 draw_double_box (h, info->widget.y, info->widget.x,
60 info->widget.lines, info->widget.cols);
63 static void
64 info_show_info (struct WInfo *info)
66 static int i18n_adjust=0;
67 static const char *file_label;
69 struct stat st;
71 if (!is_idle ())
72 return;
74 info_box (info->widget.parent, info);
75 attrset (MARKED_COLOR);
76 widget_move (&info->widget, 1, 3);
77 tty_printf (_("Midnight Commander %s"), VERSION);
78 attrset (NORMAL_COLOR);
79 widget_move (&info->widget, 2, 1);
80 hline (ACS_HLINE|NORMAL_COLOR, info->widget.cols-2);
81 if (get_current_type () != view_listing)
82 return;
84 if (!info->ready)
85 return;
87 my_statfs (&myfs_stats, current_panel->cwd);
88 st = current_panel->dir.list [current_panel->selected].st;
90 /* Print only lines which fit */
92 if(!i18n_adjust) {
93 /* This printf pattern string is used as a reference for size */
94 file_label=_("File: %s");
95 i18n_adjust=strlen(file_label)+2;
98 switch (info->widget.lines-2){
99 /* Note: all cases are fall-throughs */
101 default:
103 case 16:
104 widget_move (&info->widget, 16, 3);
105 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
106 tty_printf (_("Free nodes: %d (%d%%) of %d"),
107 myfs_stats.nfree,
108 myfs_stats.total
109 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
110 myfs_stats.nodes);
111 else
112 addstr (_("No node information"));
114 case 15:
115 widget_move (&info->widget, 15, 3);
116 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
117 char buffer1 [6], buffer2[6];
118 size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
119 size_trunc_len (buffer2, 5, myfs_stats.total, 1);
120 tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
121 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0,
122 buffer2);
123 } else
124 addstr (_("No space information"));
126 case 14:
127 widget_move (&info->widget, 14, 3);
128 tty_printf (_("Type: %s "),
129 myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
130 if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
131 tty_printf (" (%Xh)", myfs_stats.type);
133 case 13:
134 widget_move (&info->widget, 13, 3);
135 tty_printf (_("Device: %s"),
136 name_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
137 case 12:
138 widget_move (&info->widget, 12, 3);
139 tty_printf (_("Filesystem: %s"),
140 name_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
142 case 11:
143 widget_move (&info->widget, 11, 3);
144 tty_printf (_("Accessed: %s"), file_date (st.st_atime));
146 case 10:
147 widget_move (&info->widget, 10, 3);
148 tty_printf (_("Modified: %s"), file_date (st.st_mtime));
150 case 9:
151 widget_move (&info->widget, 9, 3);
152 /* TRANSLATORS: "Status changed", like in the stat(2) man page */
153 printw (_("Status: %s"), file_date (st.st_ctime));
155 case 8:
156 widget_move (&info->widget, 8, 3);
157 #ifdef HAVE_STRUCT_STAT_ST_RDEV
158 if (S_ISCHR (st.st_mode) || S_ISBLK(st.st_mode))
159 tty_printf (_("Dev. type: major %lu, minor %lu"),
160 (unsigned long) major (st.st_rdev),
161 (unsigned long) minor (st.st_rdev));
162 else
163 #endif
165 char buffer[10];
166 size_trunc_len(buffer, 9, st.st_size, 0);
167 tty_printf (_("Size: %s"), buffer);
168 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
169 tty_printf (ngettext(" (%ld block)", " (%ld blocks)",
170 (unsigned long int) st.st_blocks),
171 (long int) st.st_blocks);
172 #endif
175 case 7:
176 widget_move (&info->widget, 7, 3);
177 tty_printf (_("Owner: %s/%s"),
178 get_owner (st.st_uid),
179 get_group (st.st_gid));
181 case 6:
182 widget_move (&info->widget, 6, 3);
183 tty_printf (_("Links: %d"), (int) st.st_nlink);
185 case 5:
186 widget_move (&info->widget, 5, 3);
187 tty_printf (_("Mode: %s (%04o)"),
188 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
190 case 4:
191 widget_move (&info->widget, 4, 3);
192 tty_printf (_("Location: %Xh:%Xh"), (int)st.st_dev, (int)st.st_ino);
194 case 3:
195 widget_move (&info->widget, 3, 2);
196 /* .ado: fname is invalid if selected == 0 && info called from current panel */
197 if (current_panel->selected){
198 tty_printf (file_label,
199 name_trunc (current_panel->dir.list [current_panel->selected].fname,
200 info->widget.cols - i18n_adjust));
201 } else
202 addstr (_("File: None"));
204 case 2:
205 case 1:
206 case 0:
208 } /* switch */
211 static void info_hook (void *data)
213 struct WInfo *info = (struct WInfo *) data;
214 Widget *other_widget;
216 other_widget = get_panel_widget (get_current_index ());
217 if (!other_widget)
218 return;
219 if (dlg_overlap (&info->widget, other_widget))
220 return;
222 info->ready = 1;
223 info_show_info (info);
226 static cb_ret_t
227 info_callback (Widget *w, widget_msg_t msg, int parm)
229 struct WInfo *info = (struct WInfo *) w;
231 switch (msg) {
233 case WIDGET_INIT:
234 add_hook (&select_file_hook, info_hook, info);
235 info->ready = 0;
236 return MSG_HANDLED;
238 case WIDGET_DRAW:
239 info_hook (info);
240 info_show_info (info);
241 return MSG_HANDLED;
243 case WIDGET_FOCUS:
244 return MSG_NOT_HANDLED;
246 case WIDGET_DESTROY:
247 delete_hook (&select_file_hook, info_hook);
248 return MSG_HANDLED;
250 default:
251 return default_proc (msg, parm);
255 struct WInfo *info_new ()
257 struct WInfo *info = g_new (struct WInfo, 1);
259 init_widget (&info->widget, 0, 0, 0, 0, info_callback, NULL);
261 /* We do not want the cursor */
262 widget_want_cursor (info->widget, 0);
264 if (!initialized){
265 initialized = 1;
266 init_my_statfs ();
269 return info;