* Makefile.am: Remove definition of CONFDIR, it's not used.
[midnight-commander.git] / src / info.c
blobecadfe261d2aac0ad307ee22397ed33e4269e96d
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 if (hascolors)
55 attrset (NORMAL_COLOR);
56 widget_erase (&info->widget);
57 draw_double_box (h, info->widget.y, info->widget.x,
58 info->widget.lines, info->widget.cols);
61 static void
62 info_show_info (WInfo *info)
64 static int i18n_adjust=0;
65 static char *file_label;
67 struct stat buf;
69 if (!is_idle ())
70 return;
72 info_box (info->widget.parent, info);
73 attrset (MARKED_COLOR);
74 widget_move (&info->widget, 1, 3);
75 printw (_("Midnight Commander %s"), VERSION);
76 attrset (NORMAL_COLOR);
77 widget_move (&info->widget, 2, 1);
78 /* .ado: info->widget.x has wrong value (==0) on NT and OS/2, why? */
79 #ifndef OS2_NT
80 hline (ACS_HLINE|NORMAL_COLOR, info->widget.x-2);
81 #endif
82 if (get_current_type () != view_listing)
83 return;
85 if (!info->ready)
86 return;
88 my_statfs (&myfs_stats, cpanel->cwd);
89 buf = cpanel->dir.list [cpanel->selected].buf;
90 #ifdef OS2_NT
91 /* .ado: for OS/2 and NT, st_dev must > 0 */
92 if ((signed char) buf.st_dev < 0)
93 return;
94 #endif
96 /* Print only lines which fit */
98 if(!i18n_adjust) {
99 /* This printf pattern string is used as a reference for size */
100 file_label=_("File: %s");
101 i18n_adjust=strlen(file_label)+2;
104 switch (info->widget.lines-2){
105 /* Note: all cases are fall-throughs */
107 default:
109 case 16:
110 widget_move (&info->widget, 16, 3);
111 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
112 printw (_("Free nodes: %d (%d%%) of %d"),
113 myfs_stats.nfree,
114 myfs_stats.total
115 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
116 myfs_stats.nodes);
117 else
118 addstr (_("No node information"));
120 case 15:
121 widget_move (&info->widget, 15, 3);
122 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
123 char buffer1 [6], buffer2[6];
124 size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
125 size_trunc_len (buffer2, 5, myfs_stats.total, 1);
126 printw (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
127 100 * myfs_stats.avail / myfs_stats.total : 0, buffer2);
128 } else
129 addstr (_("No space information"));
131 case 14:
132 widget_move (&info->widget, 14, 3);
133 printw (_("Type: %s "), myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
134 if (myfs_stats.type != 0xffff && myfs_stats.type != 0xffffffff)
135 printw (" (%Xh)", myfs_stats.type);
137 case 13:
138 widget_move (&info->widget, 13, 3);
139 printw (_("Device: %s"),
140 name_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
141 case 12:
142 widget_move (&info->widget, 12, 3);
143 printw (_("Filesystem: %s"),
144 name_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
146 case 11:
147 widget_move (&info->widget, 11, 3);
148 printw (_("Accessed: %s"), file_date (buf.st_atime));
150 case 10:
151 widget_move (&info->widget, 10, 3);
152 printw (_("Modified: %s"), file_date (buf.st_mtime));
154 case 9:
155 widget_move (&info->widget, 9, 3);
156 printw (_("Created: %s"), file_date (buf.st_ctime));
158 case 8:
159 widget_move (&info->widget, 8, 3);
160 #if 0
161 #ifdef HAVE_ST_RDEV
162 if (buf.st_rdev)
163 printw ("Inode dev: major: %d, minor: %d",
164 buf.st_rdev >> 8, buf.st_rdev & 0xff);
165 else
166 #endif
167 #endif
169 char buffer[10];
170 size_trunc_len(buffer, 9, buf.st_size, 0);
171 printw (_("Size: %s"), buffer);
172 #ifdef HAVE_ST_BLOCKS
173 printw ((buf.st_blocks==1) ?
174 _(" (%d block)") : _(" (%d blocks)"), buf.st_blocks);
175 #endif
178 case 7:
179 widget_move (&info->widget, 7, 3);
180 printw (_("Owner: %s/%s"), get_owner (buf.st_uid),
181 get_group (buf.st_gid));
183 case 6:
184 widget_move (&info->widget, 6, 3);
185 printw (_("Links: %d"), buf.st_nlink);
187 case 5:
188 widget_move (&info->widget, 5, 3);
189 printw (_("Mode: %s (%04o)"),
190 string_perm (buf.st_mode), buf.st_mode & 07777);
192 case 4:
193 widget_move (&info->widget, 4, 3);
194 printw (_("Location: %Xh:%Xh"), (int)buf.st_dev, (int)buf.st_ino);
196 case 3:
197 widget_move (&info->widget, 3, 2);
198 /* .ado: fname is invalid if selected == 0 && info called from current panel */
199 if (cpanel->selected){
200 printw (file_label,
201 name_trunc (cpanel->dir.list [cpanel->selected].fname,
202 info->widget.cols - i18n_adjust));
203 } else
204 printw (_("File: None"));
206 case 2:
207 case 1:
208 case 0:
210 } /* switch */
213 static void info_hook (void *data)
215 WInfo *info = (WInfo *) data;
216 Widget *other_widget;
218 other_widget = get_panel_widget (get_current_index ());
219 if (!other_widget)
220 return;
221 if (dlg_overlap (&info->widget, other_widget))
222 return;
224 info->ready = 1;
225 info_show_info (info);
228 static void info_destroy (WInfo *info)
230 delete_hook (&select_file_hook, info_hook);
233 static int info_callback (Dlg_head *h, WInfo *info, int msg, int par)
235 switch (msg){
237 case WIDGET_INIT:
238 add_hook (&select_file_hook, info_hook, info);
239 info->ready = 0;
240 break;
242 case WIDGET_DRAW:
243 info_hook (info);
244 info_show_info (info);
245 return 1;
247 case WIDGET_FOCUS:
248 return 0;
250 return default_proc (h, msg, par);
253 WInfo *info_new ()
255 WInfo *info = g_new (WInfo, 1);
257 init_widget (&info->widget, 0, 0, 0, 0, (callback_fn)
258 info_callback, (destroy_fn) info_destroy,
259 (mouse_h) info_event, 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;