1999-09-09 Federico Mena Quintero <federico@redhat.com>
[midnight-commander.git] / src / info.c
blob9b996c14656f0c4ee7c0b41f58ea24b4ca66c4ec
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #include <config.h>
20 #include <stdio.h>
21 #include "tty.h"
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <sys/param.h>
25 #include "global.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 "win.h" /* print_bytesize */
34 #include "layout.h"
35 #include "key.h" /* is_idle() */
36 #include "x.h"
38 #ifdef HAVE_TK
39 # include "tkmain.h"
40 # include "tkinfo.h"
41 #endif
43 #ifndef VERSION
44 # define VERSION "undefined"
45 #endif
47 /* Have we called the init_my_statfs routine? */
48 static int initialized;
49 struct my_statfs myfs_stats;
51 static int info_event (Gpm_Event *event, WInfo *info)
53 return 0;
56 #ifndef HAVE_X
57 static void info_box (Dlg_head *h, WInfo *info)
59 standend ();
60 if (hascolors)
61 attrset (NORMAL_COLOR);
62 widget_erase (&info->widget);
63 draw_double_box (h, info->widget.y, info->widget.x,
64 info->widget.lines, info->widget.cols);
66 #endif
68 static void
69 info_show_info (WInfo *info)
71 static int i18n_adjust=0;
72 static char *file_label;
74 struct stat buf;
76 #ifndef HAVE_X
77 if (!is_idle ())
78 return;
80 info_box (info->widget.parent, info);
81 attrset (MARKED_COLOR);
82 widget_move (&info->widget, 1, 3);
83 printw (_("Midnight Commander %s"), VERSION);
84 attrset (NORMAL_COLOR);
85 widget_move (&info->widget, 2, 1);
86 /* .ado: info->widget.x has wrong value (==0) on NT and OS/2, why? */
87 #if !defined(OS2_NT)
88 hline (ACS_HLINE|NORMAL_COLOR, info->widget.x-2);
89 #endif
90 #endif
91 if (get_current_type () != view_listing)
92 return;
94 if (!info->ready)
95 return;
97 my_statfs (&myfs_stats, cpanel->cwd);
98 buf = cpanel->dir.list [cpanel->selected].buf;
99 #ifdef OS2_NT
100 /* .ado: for OS/2 and NT, st_dev must > 0 */
101 if ((signed char) buf.st_dev < 0)
102 return;
103 #endif
105 #ifndef HAVE_X
106 /* Print only lines which fit */
108 if(!i18n_adjust) {
109 file_label=_("File: %s");
110 i18n_adjust=strlen(file_label)+2;
112 /*The printf pattern string is used as a reference for size*/
114 switch (info->widget.lines-2){
115 /* Note: all cases are fall-throughs */
117 default:
119 case 16:
120 widget_move (&info->widget, 16, 3);
121 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
122 printw (_("Free nodes %d (%d%%) of %d"),
123 myfs_stats.nfree,
124 myfs_stats.total
125 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
126 myfs_stats.nodes);
127 else
128 addstr (_("No node information"));
130 case 15:
131 widget_move (&info->widget, 15, 3);
132 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
133 addstr (_("Free space "));
134 print_bytesize (myfs_stats.avail, 1);
135 printw (_(" (%d%%) of "), myfs_stats.total
136 ? 100 * myfs_stats.avail / myfs_stats.total : 0);
137 print_bytesize (myfs_stats.total, 1);
138 } else
139 addstr (_("No space information"));
141 case 14:
142 widget_move (&info->widget, 14, 3);
143 printw (_("Type: %s "), myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
144 if (myfs_stats.type != 0xffff && myfs_stats.type != 0xffffffff)
145 printw (" (%Xh)", myfs_stats.type);
147 case 13:
148 widget_move (&info->widget, 13, 3);
149 printw (_("Device: %s"),
150 name_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
151 case 12:
152 widget_move (&info->widget, 12, 3);
153 printw (_("Filesystem: %s"),
154 name_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
156 case 11:
157 widget_move (&info->widget, 11, 3);
158 printw (_("Accessed: %s"), file_date (buf.st_atime));
160 case 10:
161 widget_move (&info->widget, 10, 3);
162 printw (_("Modified: %s"), file_date (buf.st_mtime));
164 case 9:
165 widget_move (&info->widget, 9, 3);
166 printw (_("Created: %s"), file_date (buf.st_ctime));
168 case 8:
169 widget_move (&info->widget, 8, 3);
170 #if 0
171 #ifdef HAVE_ST_RDEV
172 if (buf.st_rdev)
173 printw ("Inode dev: major: %d, minor: %d",
174 buf.st_rdev >> 8, buf.st_rdev & 0xff);
175 else
176 #endif
177 #endif
179 printw (_("Size: "));
180 print_bytesize (buf.st_size, 0);
181 #ifdef HAVE_ST_BLOCKS
182 printw (_(" (%d blocks)"), buf.st_blocks);
183 #endif
186 case 7:
187 widget_move (&info->widget, 7, 3);
188 printw (_("Owner: %s/%s"), get_owner (buf.st_uid),
189 get_group (buf.st_gid));
191 case 6:
192 widget_move (&info->widget, 6, 3);
193 printw (_("Links: %d"), buf.st_nlink);
195 case 5:
196 widget_move (&info->widget, 5, 3);
197 printw (_("Mode: %s (%04o)"),
198 string_perm (buf.st_mode), buf.st_mode & 07777);
200 case 4:
201 widget_move (&info->widget, 4, 3);
202 printw (_("Location: %Xh:%Xh"), (int)buf.st_dev, (int)buf.st_ino);
204 case 3:
205 widget_move (&info->widget, 3, 2);
206 /* .ado: fname is invalid if selected == 0 && ifno called from current panel */
207 if (cpanel->selected){
208 printw (file_label,
209 name_trunc (cpanel->dir.list [cpanel->selected].fname,
210 info->widget.cols - i18n_adjust));
211 } else
212 printw (_("File: None"));
214 case 2:
215 case 1:
216 case 0:
218 } /* switch */
219 #else /* HAVE_X */
220 x_show_info (info, &myfs_stats, &buf);
221 #endif
224 static void info_hook (void *data)
226 WInfo *info = (WInfo *) data;
227 Widget *other_widget;
229 other_widget = get_panel_widget (get_current_index ());
230 if (!other_widget)
231 return;
232 if (dlg_overlap (&info->widget, other_widget))
233 return;
235 info->ready = 1;
236 info_show_info (info);
239 static void info_destroy (WInfo *info)
241 delete_hook (&select_file_hook, info_hook);
244 static int info_callback (Dlg_head *h, WInfo *info, int msg, int par)
246 switch (msg){
248 case WIDGET_INIT:
249 add_hook (&select_file_hook, info_hook, info);
250 info->ready = 0;
251 #ifdef HAVE_X
252 x_create_info (h, h->wdata, info);
253 #endif
254 break;
256 #ifndef HAVE_X
257 case WIDGET_DRAW:
258 info_hook (info);
259 info_show_info (info);
260 return 1;
261 #endif
263 case WIDGET_FOCUS:
264 return 0;
266 return default_proc (h, msg, par);
269 WInfo *info_new ()
271 WInfo *info = g_new (WInfo, 1);
273 init_widget (&info->widget, 0, 0, 0, 0, (callback_fn)
274 info_callback, (destroy_fn) info_destroy,
275 (mouse_h) info_event, NULL);
277 /* We do not want the cursor */
278 widget_want_cursor (info->widget, 0);
280 if (!initialized){
281 initialized = 1;
282 init_my_statfs ();
285 return info;