update
[midnight-commander.git] / xv / xvinfo.c
blob78a742a6252effdbe64ee272e84a42d74d0a1d03
1 /* XView info stuff.
2 Copyright (C) 1995 Jakub Jelinek.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 #include <config.h>
19 #include <xview/xview.h>
20 #include <xview/frame.h>
21 #include <xview/panel.h>
22 #include <xview/canvas.h>
23 #include <xview/svrimage.h>
24 #include <xview/cms.h>
25 #include <xview/font.h>
26 #include <xview/scrollbar.h>
27 #include <X11/xpm.h>
29 #include "fs.h"
30 #include "dir.h"
31 #include "panel.h"
32 #include "dlg.h"
33 #include "widget.h"
34 #include "info.h"
35 #include "main.h"
36 #include "util.h"
37 #include "win.h"
38 #include "xvmain.h"
40 #include "mc.icon"
42 extern Dlg_head *midnight_dlg;
43 extern int defaultDepth; /* xvmain.c */
44 extern Display *dpy; /* xvmain.c */
45 extern Frame mcframe; /* ??? xvmain.c, but is this what we want?? */
47 static Cms infocms;
48 Server_image mcimage;
50 #include "mc_icon.xpm"
52 void x_setup_info (void)
54 Pixmap pixmap, shapemask = 0;
56 infocms = xv_create (XV_NULL, CMS,
57 CMS_SIZE, sizeof (mc_colors) / sizeof (Xv_singlecolor) + CMS_CONTROL_COLORS,
58 CMS_CONTROL_CMS, TRUE,
59 CMS_NAME, "infocms",
60 CMS_COLORS, &mc_colors,
61 NULL);
63 XpmCreatePixmapFromData (dpy, (Drawable)xv_get(mcframe, XV_XID),
64 mc_icon_xpm, &pixmap, &shapemask, NULL);
66 mcimage = xv_create (XV_NULL, SERVER_IMAGE,
67 XV_WIDTH, mc_width,
68 XV_HEIGHT, mc_height,
69 SERVER_IMAGE_COLORMAP, "infocms",
70 SERVER_IMAGE_DEPTH, defaultDepth,
71 /* SERVER_IMAGE_X_BITS, mc_bits, */
72 SERVER_IMAGE_PIXMAP, pixmap,
73 NULL);
76 #if 0
77 static void x_info_recalculate (Columnizer tile)
79 int i, j, top = xv_get (tile, COLUMNIZER_N_COLUMNS);
80 int count = xv_get (tile, COLUMNIZER_N_ROWS), max, w;
82 for (i = 0; i < top; i++) {
83 max = 0;
84 for (j = 0; j < count; j++) {
85 w = xv_get ((Rectobj) xv_get (tile, COLUMNIZER_POSITION, i, j),
86 XV_WIDTH);
87 if (w > max)
88 max = w;
90 for (j = 0; j < count; j++) {
91 xv_set ((Rectobj) xv_get (tile, COLUMNIZER_POSITION, i, j),
92 XV_WIDTH, max,
93 NULL);
97 #endif
99 void x_show_info (WInfo *info, struct my_statfs *s, struct stat *b)
101 #if 0
102 Canvas_shell canvas = (Canvas_shell) xv_get ((Bag) (info->widget.wdata),
103 XV_OWNER);
104 Columnizer tile = (Columnizer) xv_get ((Bag) (info->widget.wdata),
105 RECTOBJ_NTH_CHILD, 3);
106 char buffer [100];
107 char *text;
108 char *p;
109 int i;
110 Xv_opaque win;
111 int w, h;
112 Scrollbar scrollbar;
114 xv_set (canvas,
115 CANVAS_SHELL_DELAY_REPAINT, TRUE,
116 NULL);
118 for (i = 0; i < 14; i++) {
119 text = buffer;
120 switch (i + 3) {
121 case 16:
122 if (s->nfree >0 || s->nodes > 0)
123 sprintf (buffer, "%d (%d%%) of %d",
124 s->nfree,
125 s->total
126 ? 100 * s->nfree / s->nodes : 0,
127 s->nodes);
128 else
129 text = "No node information";
130 break;
132 case 15:
133 if (s->avail > 0 || s->total > 0){
134 sprint_bytesize (buffer, s->avail, 1);
135 p = strchr (buffer, 0);
136 sprintf (p, " (%d%%) of ", s->total
137 ? 100 * s->avail / s->total : 0);
138 p = strchr (buffer, 0);
139 sprint_bytesize (p, s->total, 1);
140 } else
141 text = "No space information";
142 break;
144 case 14:
145 sprintf (buffer, "%s ", s->typename);
146 p = strchr (buffer, 0);
147 if ((unsigned) s->type != 0xffff &&
148 (unsigned) s->type != 0xffffffff)
149 sprintf (p, " (%Xh)", s->type);
150 break;
152 case 13:
153 text = s->device;
154 break;
156 case 12:
157 text = s->mpoint;
158 break;
160 case 11:
161 text = file_date (b->st_atime);
162 break;
164 case 10:
165 text = file_date (b->st_mtime);
166 break;
168 case 9:
169 text = file_date (b->st_ctime);
170 break;
172 case 8:
173 #ifdef HAVE_ST_RDEV
174 if (b->st_rdev) {
175 sprintf (buffer, "major: %d, minor: %d",
176 b->st_rdev >> 8, b->st_rdev & 0xff);
177 xv_set (xv_get (tile, COLUMNIZER_POSITION, 0, i),
178 DRAWTEXT_STRING, "Inode dev:",
179 NULL);
180 } else {
181 xv_set (xv_get (tile, COLUMNIZER_POSITION, 0, i),
182 DRAWTEXT_STRING, "Size:",
183 NULL);
184 #endif
185 sprint_bytesize (buffer, b->st_size, 0);
186 p = strchr (buffer, 0);
187 #ifdef HAVE_ST_BLOCKS
188 sprintf (p, " (%d blocks)", (int) b->st_blocks);
189 #endif
190 #ifdef HAVE_ST_RDEV
192 #endif
193 break;
195 case 7:
196 sprintf (buffer, "%s/%s", get_owner (b->st_uid),
197 get_group (b->st_gid));
198 break;
200 case 6:
201 sprintf (buffer, "%d", b->st_nlink);
202 break;
204 case 5:
205 sprintf (buffer, "%s (%o)",
206 string_perm (b->st_mode), b->st_mode & 07777);
207 break;
209 case 4:
210 sprintf (buffer, "%Xh:%Xh", (int) b->st_dev, (int) b->st_ino);
211 break;
213 case 3:
214 text = cpanel->dir.list [cpanel->selected].fname;
215 break;
217 xv_set (xv_get (tile, COLUMNIZER_POSITION, 1, i),
218 DRAWTEXT_STRING, text,
219 NULL);
222 x_info_recalculate (tile);
224 w = xv_get ((Bag) (info->widget.wdata), XV_WIDTH);
225 h = xv_get ((Bag) (info->widget.wdata), XV_HEIGHT);
227 xv_set (canvas,
228 CANVAS_MIN_PAINT_WIDTH, w,
229 CANVAS_MIN_PAINT_HEIGHT, h,
230 NULL);
232 OPENWIN_EACH_VIEW (canvas, win)
233 scrollbar = (Scrollbar) xv_get (canvas, OPENWIN_HORIZONTAL_SCROLLBAR, win);
234 if (scrollbar != XV_NULL)
235 xv_set (scrollbar,
236 SCROLLBAR_OBJECT_LENGTH, w,
237 SCROLLBAR_PIXELS_PER_UNIT, 1,
238 NULL);
239 scrollbar = (Scrollbar) xv_get (canvas, OPENWIN_VERTICAL_SCROLLBAR, win);
240 if (scrollbar != XV_NULL)
241 xv_set (scrollbar,
242 SCROLLBAR_OBJECT_LENGTH, h,
243 SCROLLBAR_PIXELS_PER_UNIT, 1,
244 NULL);
245 OPENWIN_END_EACH
247 xv_set (canvas,
248 CANVAS_SHELL_DELAY_REPAINT, FALSE,
249 NULL);
250 #endif
253 #ifndef VERSION
254 # define VERSION "undefined"
255 #endif
257 #if 0
258 void backevent_proc_seal (Xv_window, Event *, Canvas_shell, Rectobj);
259 #endif
260 int x_create_info (Dlg_head *h, widget_data parent, WInfo *info)
262 #if 0
263 Canvas canvas =
264 (Canvas) x_get_parent_object ((Widget *) info, parent);
265 Bag tile;
266 Xv_opaque previous;
267 char buffer [50];
268 Drawtext text;
269 Columnizer tile1;
270 int i, height;
271 static char *names [] = { "File:", "Location:", "Mode:", "Links:", "Owner:",
272 "Size:", "Created:", "Modified:", "Accessed:", "Filesystem:", "Device:",
273 "Type:", "Free space:", "Free nodes:" };
275 previous = xv_get (canvas, RECTOBJ_NTH_CHILD, 0);
277 if (previous != XV_NULL)
278 xv_destroy_safe (previous);
280 tile = xv_create (canvas, BAG,
281 XV_KEY_DATA, KEY_DATA_PANEL, info,
282 XV_KEY_DATA, KEY_DATA_PANEL_CONTAINER, xv_get (canvas, XV_OWNER),
283 RECTOBJ_EVENT_PROC, backevent_proc_seal,
284 XV_X, 5,
285 XV_Y, 5,
286 XV_KEY_DATA, KEY_DATA_BOLD_FONT,
287 xv_find (canvas, FONT,
288 FONT_FAMILY, xv_get (xv_get (canvas, CANVAS_SHELL_FONT),
289 FONT_FAMILY),
290 FONT_SIZE, xv_get (xv_get (canvas, CANVAS_SHELL_FONT),
291 FONT_SIZE),
292 FONT_STYLE, FONT_STYLE_BOLD,
293 NULL),
294 NULL);
295 xv_set (canvas,
296 XV_KEY_DATA, KEY_DATA_TILE, tile,
297 RECTOBJ_ACCEPTS_DROP, FALSE,
298 RECTOBJ_EVENT_PROC, backevent_proc_seal,
299 CANVAS_PAINTWINDOW_ATTRS,
300 WIN_IGNORE_EVENTS,
301 KBD_DONE, KBD_USE, WIN_ASCII_EVENTS, WIN_LEFT_KEYS, WIN_TOP_KEYS,
302 WIN_RIGHT_KEYS, WIN_META_EVENTS, WIN_EDIT_KEYS, WIN_MOTION_KEYS,
303 WIN_TEXT_KEYS,
304 NULL,
305 NULL,
306 CANVAS_SHELL_EVENT_PROC, NULL,
307 WIN_CMS, infocms,
308 NULL);
309 xv_create (tile, DRAWIMAGE,
310 XV_X, 10,
311 XV_Y, 10,
312 XV_WIDTH, mc_width,
313 XV_HEIGHT, mc_height,
314 DRAWIMAGE_IMAGE1, mcimage,
315 RECTOBJ_SELECTABLE, FALSE,
316 RECTOBJ_EVENT_PROC, backevent_proc_seal,
317 NULL);
318 sprintf (buffer, "Midnight X Commander, version %s", VERSION);
319 text = (Drawtext) xv_create (tile, DRAWTEXT,
320 XV_X, 10,
321 XV_Y, mc_height + 15,
322 DRAWTEXT_STRING, buffer,
323 DRAWTEXT_FONT, xv_get (tile, XV_KEY_DATA, KEY_DATA_BOLD_FONT),
324 RECTOBJ_SELECTABLE, FALSE,
325 RECTOBJ_EVENT_PROC, backevent_proc_seal,
326 NULL);
327 height = xv_get (text, XV_HEIGHT) + mc_height + 15;
328 xv_create (tile, DRAWRECT,
329 XV_X, 10,
330 XV_Y, height + 2,
331 XV_WIDTH, xv_get (text, XV_WIDTH),
332 XV_HEIGHT, 4,
333 DRAWRECT_BORDER2, 1,
334 RECTOBJ_SELECTABLE, FALSE,
335 RECTOBJ_EVENT_PROC, backevent_proc_seal,
336 NULL);
337 tile1 = xv_create (tile, COLUMNIZER,
338 XV_X, 10,
339 XV_Y, height + 10,
340 COLUMNIZER_N_COLUMNS, 2,
341 COLUMNIZER_N_ROWS, 14,
342 COLUMNIZER_COLUMN_GAP, 10,
343 COLUMNIZER_ROW_GAP, 0,
344 RECTOBJ_EVENT_PROC, backevent_proc_seal,
345 NULL);
346 for (i = 0; i < 14; i++) {
347 xv_create (tile1, DRAWTEXT,
348 DRAWTEXT_STRING, names [i],
349 DRAWTEXT_FONT, xv_get (tile, XV_KEY_DATA, KEY_DATA_BOLD_FONT),
350 RECTOBJ_SELECTABLE, FALSE,
351 RECTOBJ_EVENT_PROC, backevent_proc_seal,
352 NULL);
353 xv_create (tile1, DRAWTEXT,
354 RECTOBJ_SELECTABLE, FALSE,
355 RECTOBJ_EVENT_PROC, backevent_proc_seal,
356 NULL);
358 info->widget.wdata = (widget_data) tile;
359 info_show_info (info);
360 x_info_recalculate (tile1);
361 #endif
362 return 1;