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. */
21 #include <sys/types.h>
26 #include "mouse.h" /* Gpm_Event */
30 #include "dir.h" /* required by panel */
31 #include "panel.h" /* for the panel structure */
32 #include "main.h" /* other_panel, current_panel definitions */
33 #include "util.h" /* size_trunc_len */
35 #include "key.h" /* is_idle() */
36 #include "mountlist.h"
39 # define VERSION "undefined"
47 /* Have we called the init_my_statfs routine? */
48 static int initialized
;
49 static struct my_statfs myfs_stats
;
51 static void info_box (Dlg_head
*h
, struct WInfo
*info
)
54 attrset (NORMAL_COLOR
);
55 widget_erase (&info
->widget
);
56 draw_double_box (h
, info
->widget
.y
, info
->widget
.x
,
57 info
->widget
.lines
, info
->widget
.cols
);
61 info_show_info (struct WInfo
*info
)
63 static int i18n_adjust
=0;
64 static const char *file_label
;
71 info_box (info
->widget
.parent
, info
);
72 attrset (MARKED_COLOR
);
73 widget_move (&info
->widget
, 1, 3);
74 printw (const_cast(char *, _("Midnight Commander %s")), VERSION
);
75 attrset (NORMAL_COLOR
);
76 widget_move (&info
->widget
, 2, 1);
77 hline (ACS_HLINE
|NORMAL_COLOR
, info
->widget
.x
-2);
78 if (get_current_type () != view_listing
)
84 my_statfs (&myfs_stats
, current_panel
->cwd
);
85 st
= current_panel
->dir
.list
[current_panel
->selected
].st
;
87 /* Print only lines which fit */
90 /* This printf pattern string is used as a reference for size */
91 file_label
=_("File: %s");
92 i18n_adjust
=strlen(file_label
)+2;
95 switch (info
->widget
.lines
-2){
96 /* Note: all cases are fall-throughs */
101 widget_move (&info
->widget
, 16, 3);
102 if (myfs_stats
.nfree
>0 || myfs_stats
.nodes
> 0)
103 printw (const_cast(char *, _("Free nodes: %d (%d%%) of %d")),
106 ? 100 * myfs_stats
.nfree
/ myfs_stats
.nodes
: 0,
109 addstr (_("No node information"));
112 widget_move (&info
->widget
, 15, 3);
113 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0){
114 char buffer1
[6], buffer2
[6];
115 size_trunc_len (buffer1
, 5, myfs_stats
.avail
, 1);
116 size_trunc_len (buffer2
, 5, myfs_stats
.total
, 1);
117 printw (const_cast(char *, _("Free space: %s (%d%%) of %s")), buffer1
, myfs_stats
.total
?
118 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0,
121 addstr (_("No space information"));
124 widget_move (&info
->widget
, 14, 3);
125 printw (const_cast(char *, _("Type: %s ")), myfs_stats
.typename
? myfs_stats
.typename
: _("non-local vfs"));
126 if (myfs_stats
.type
!= 0xffff && myfs_stats
.type
!= -1)
127 printw (" (%Xh)", myfs_stats
.type
);
130 widget_move (&info
->widget
, 13, 3);
131 printw (const_cast(char *, _("Device: %s")),
132 name_trunc (myfs_stats
.device
, info
->widget
.cols
- i18n_adjust
));
134 widget_move (&info
->widget
, 12, 3);
135 printw (const_cast(char *, _("Filesystem: %s")),
136 name_trunc (myfs_stats
.mpoint
, info
->widget
.cols
- i18n_adjust
));
139 widget_move (&info
->widget
, 11, 3);
140 printw (const_cast(char *, _("Accessed: %s")), file_date (st
.st_atime
));
143 widget_move (&info
->widget
, 10, 3);
144 printw (const_cast(char *, _("Modified: %s")), file_date (st
.st_mtime
));
147 widget_move (&info
->widget
, 9, 3);
148 printw (const_cast(char *, _("Created: %s")), file_date (st
.st_ctime
));
151 widget_move (&info
->widget
, 8, 3);
153 #ifdef HAVE_STRUCT_STAT_ST_RDEV
155 printw ("Inode dev: major: %d, minor: %d",
156 st
.st_rdev
>> 8, st
.st_rdev
& 0xff);
162 size_trunc_len(buffer
, 9, st
.st_size
, 0);
163 printw (const_cast(char *, _("Size: %s")), buffer
);
164 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
165 printw (const_cast(char *, (st
.st_blocks
==1) ?
166 _(" (%ld block)") : _(" (%ld blocks)")), (long) st
.st_blocks
);
171 widget_move (&info
->widget
, 7, 3);
172 printw (const_cast(char *, _("Owner: %s/%s")), get_owner (st
.st_uid
),
173 get_group (st
.st_gid
));
176 widget_move (&info
->widget
, 6, 3);
177 printw (const_cast(char *, _("Links: %d")), (int) st
.st_nlink
);
180 widget_move (&info
->widget
, 5, 3);
181 printw (const_cast(char *, _("Mode: %s (%04o)")),
182 string_perm (st
.st_mode
), st
.st_mode
& 07777);
185 widget_move (&info
->widget
, 4, 3);
186 printw (const_cast(char *, _("Location: %Xh:%Xh")), (int)st
.st_dev
, (int)st
.st_ino
);
189 widget_move (&info
->widget
, 3, 2);
190 /* .ado: fname is invalid if selected == 0 && info called from current panel */
191 if (current_panel
->selected
){
192 printw (const_cast(char *, file_label
),
193 name_trunc (current_panel
->dir
.list
[current_panel
->selected
].fname
,
194 info
->widget
.cols
- i18n_adjust
));
196 addstr (_("File: None"));
205 static void info_hook (void *data
)
207 struct WInfo
*info
= (struct WInfo
*) data
;
208 Widget
*other_widget
;
210 other_widget
= get_panel_widget (get_current_index ());
213 if (dlg_overlap (&info
->widget
, other_widget
))
217 info_show_info (info
);
221 info_callback (struct WInfo
*info
, widget_msg_t msg
, int parm
)
226 add_hook (&select_file_hook
, info_hook
, info
);
232 info_show_info (info
);
236 return MSG_NOT_HANDLED
;
239 delete_hook (&select_file_hook
, info_hook
);
243 return default_proc (msg
, parm
);
247 struct WInfo
*info_new ()
249 struct WInfo
*info
= g_new (struct WInfo
, 1);
251 init_widget (&info
->widget
, 0, 0, 0, 0, (callback_fn
)
252 info_callback
, NULL
);
254 /* We do not want the cursor */
255 widget_want_cursor (info
->widget
, 0);