- converted 1st stage setup stub from message box style to property sheet style
[reactos.git] / rosapps / applications / mc / src / info.c
1 /* Panel managing.
2 Copyright (C) 1994, 1995 Janne Kukonlehto
3 Copyright (C) 1995 Miguel de Icaza
4
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.
9
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.
14
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. */
18
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 <malloc.h>
26 #include "mad.h"
27 #include "util.h" /* statfs calls */
28 #include "mouse.h" /* Gpm_Event */
29 #include "color.h"
30 #include "dlg.h"
31 #include "info.h"
32 #include "dir.h" /* required by panel */
33 #include "panel.h" /* for the panel structure */
34 #include "main.h" /* opanel, cpanel definitions */
35 #include "win.h" /* print_bytesize */
36 #include "layout.h"
37 #include "key.h" /* is_idle() */
38
39 #ifdef HAVE_TK
40 # include "tkmain.h"
41 # include "tkinfo.h"
42 #endif
43
44 /* Have we called the init_my_statfs routine? */
45 static int initialized;
46 struct my_statfs myfs_stats;
47
48 static int info_event (Gpm_Event *event, WInfo *info)
49 {
50 return 0;
51 }
52
53 static void info_box (Dlg_head *h, WInfo *info)
54 {
55 standend ();
56 if (hascolors)
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);
61 }
62
63 #ifndef VERSION
64 # define VERSION "undefined"
65 #endif
66
67 void info_show_info (WInfo *info)
68 {
69 struct stat buf;
70
71 #ifndef HAVE_X
72 if (!is_idle ())
73 return;
74
75 info_box (info->widget.parent, info);
76 attrset (MARKED_COLOR);
77 widget_move (&info->widget, 1, 3);
78 printw (_("Midnight Commander %s"), VERSION);
79 attrset (NORMAL_COLOR);
80 widget_move (&info->widget, 2, 1);
81 /* .ado: info->widget.x has wrong value (==0) on NT and OS/2, why? */
82 #if !defined(OS2_NT)
83 hline (ACS_HLINE|NORMAL_COLOR, info->widget.x-2);
84 #endif
85 #endif
86 if (get_current_type () != view_listing)
87 return;
88
89 if (!info->ready)
90 return;
91
92 my_statfs (&myfs_stats, cpanel->cwd);
93 buf = cpanel->dir.list [cpanel->selected].buf;
94 #ifdef OS2_NT
95 /* .ado: for OS/2 and NT, st_dev must > 0 */
96 if ((signed char) buf.st_dev < 0)
97 return;
98 #endif
99
100 #ifndef HAVE_X
101 /* Print only lines which fit */
102 switch (info->widget.y-2){
103 /* Note: all cases are fall-throughs */
104
105 default:
106
107 case 16:
108 widget_move (&info->widget, 16, 3);
109 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
110 printw (_("Free nodes %d (%d%%) of %d"),
111 myfs_stats.nfree,
112 myfs_stats.total
113 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
114 myfs_stats.nodes);
115 else
116 addstr (_("No node information"));
117
118 case 15:
119 widget_move (&info->widget, 15, 3);
120 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
121 addstr (_("Free space "));
122 print_bytesize (myfs_stats.avail, 1);
123 printw (_(" (%d%%) of "), myfs_stats.total
124 ? 100 * myfs_stats.avail / myfs_stats.total : 0);
125 print_bytesize (myfs_stats.total, 1);
126 } else
127 addstr (_("No space information"));
128
129 case 14:
130 widget_move (&info->widget, 14, 3);
131 printw (_("Type: %s "), myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
132 if (myfs_stats.type != 0xffff && myfs_stats.type != 0xffffffff)
133 printw (" (%Xh)", myfs_stats.type);
134
135 case 13:
136 widget_move (&info->widget, 13, 3);
137 printw (_("Device: %s"),
138 name_trunc (myfs_stats.device, info->widget.cols - 15));
139 case 12:
140 widget_move (&info->widget, 12, 3);
141 printw (_("Filesystem: %s"),
142 name_trunc (myfs_stats.mpoint, info->widget.cols - 15));
143
144 case 11:
145 widget_move (&info->widget, 11, 3);
146 printw (_("Accessed: %s"), file_date (buf.st_atime));
147
148 case 10:
149 widget_move (&info->widget, 10, 3);
150 printw (_("Modified: %s"), file_date (buf.st_mtime));
151
152 case 9:
153 widget_move (&info->widget, 9, 3);
154 printw (_("Created: %s"), file_date (buf.st_ctime));
155
156 case 8:
157 widget_move (&info->widget, 8, 3);
158 #if 0
159 #ifdef HAVE_ST_RDEV
160 if (buf.st_rdev)
161 printw ("Inode dev: major: %d, minor: %d",
162 buf.st_rdev >> 8, buf.st_rdev & 0xff);
163 else
164 #endif
165 #endif
166 {
167 printw (_("Size: "));
168 print_bytesize (buf.st_size, 0);
169 #ifdef HAVE_ST_BLOCKS
170 printw (_(" (%d blocks)"), buf.st_blocks);
171 #endif
172 }
173
174 case 7:
175 widget_move (&info->widget, 7, 3);
176 printw (_("Owner: %s/%s"), get_owner (buf.st_uid),
177 get_group (buf.st_gid));
178
179 case 6:
180 widget_move (&info->widget, 6, 3);
181 printw (_("Links: %d"), buf.st_nlink);
182
183 case 5:
184 widget_move (&info->widget, 5, 3);
185 printw (_("Mode: %s (%04o)"),
186 string_perm (buf.st_mode), buf.st_mode & 07777);
187
188 case 4:
189 widget_move (&info->widget, 4, 3);
190 printw (_("Location: %Xh:%Xh"), buf.st_dev, buf.st_ino);
191
192 case 3:
193 widget_move (&info->widget, 3, 2);
194 /* .ado: fname is invalid if selected == 0 && ifno called from current panel */
195 if (cpanel->selected){
196 printw (_("File: %s"),
197 name_trunc (cpanel->dir.list [cpanel->selected].fname,
198 info->widget.cols - 15));
199 } else
200 printw (_("File: None"));
201
202 case 2:
203 case 1:
204 case 0:
205 ;
206 } /* switch */
207 #else /* HAVE_X */
208 x_show_info (info, &myfs_stats, &buf);
209 #endif
210 }
211
212 static void info_hook (void *data)
213 {
214 WInfo *info = (WInfo *) data;
215 Widget *other_widget;
216
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;
222
223 info->ready = 1;
224 info_show_info (info);
225 }
226
227 static void info_destroy (WInfo *info)
228 {
229 delete_hook (&select_file_hook, info_hook);
230 }
231
232 static int info_callback (Dlg_head *h, WInfo *info, int msg, int par)
233 {
234 switch (msg){
235
236 case WIDGET_INIT:
237 add_hook (&select_file_hook, info_hook, info);
238 info->ready = 0;
239 #ifdef HAVE_X
240 x_create_info (h, h->wdata, info);
241 #endif
242 break;
243
244 #ifndef HAVE_X
245 case WIDGET_DRAW:
246 info_hook (info);
247 info_show_info (info);
248 return 1;
249 #endif
250
251 case WIDGET_FOCUS:
252 return 0;
253 }
254 return default_proc (h, msg, par);
255 }
256
257 WInfo *info_new ()
258 {
259 WInfo *info = xmalloc (sizeof (WInfo), "panel_info");
260
261 init_widget (&info->widget, 0, 0, 0, 0, (callback_fn)
262 info_callback, (destroy_fn) info_destroy,
263 (mouse_h) info_event, NULL);
264
265 /* We do not want the cursor */
266 widget_want_cursor (info->widget, 0);
267
268 if (!initialized){
269 initialized = 1;
270 init_my_statfs ();
271 }
272
273 return info;
274 }
275