2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2007 Free Software Foundation, Inc.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 * \brief Source: panel managing
28 #include "../src/tty/tty.h"
29 #include "../src/tty/mouse.h" /* Gpm_Event */
30 #include "../src/tty/color.h"
33 #include "dir.h" /* required by panel */
34 #include "panel.h" /* for the panel structure */
35 #include "main.h" /* other_panel, current_panel definitions */
36 #include "util.h" /* size_trunc_len */
38 #include "../src/tty/key.h" /* is_idle() */
39 #include "mountlist.h"
40 #include "unixcompat.h"
44 # define VERSION "undefined"
52 /* Have we called the init_my_statfs routine? */
53 static int initialized
;
54 static struct my_statfs myfs_stats
;
56 static void info_box (Dlg_head
*h
, struct WInfo
*info
)
58 tty_set_normal_attrs ();
59 tty_setcolor (NORMAL_COLOR
);
60 widget_erase (&info
->widget
);
61 draw_box (h
, info
->widget
.y
, info
->widget
.x
,
62 info
->widget
.lines
, info
->widget
.cols
);
66 info_show_info (struct WInfo
*info
)
68 static int i18n_adjust
=0;
69 static const char *file_label
;
76 info_box (info
->widget
.parent
, info
);
77 tty_setcolor (MARKED_COLOR
);
78 widget_move (&info
->widget
, 1, 3);
79 tty_printf (_("Midnight Commander %s"), VERSION
);
80 tty_setcolor (NORMAL_COLOR
);
81 tty_draw_hline (info
->widget
.y
+ 2, info
->widget
.x
+ 1,
82 ACS_HLINE
, info
->widget
.cols
- 2);
83 if (get_current_type () != view_listing
)
89 my_statfs (&myfs_stats
, current_panel
->cwd
);
90 st
= current_panel
->dir
.list
[current_panel
->selected
].st
;
92 /* Print only lines which fit */
95 /* This printf pattern string is used as a reference for size */
96 file_label
=_("File: %s");
97 i18n_adjust
= str_term_width1(file_label
) + 2;
100 buff
= g_string_new ("");
102 switch (info
->widget
.lines
-2){
103 /* Note: all cases are fall-throughs */
108 widget_move (&info
->widget
, 16, 3);
109 if (myfs_stats
.nfree
>0 || myfs_stats
.nodes
> 0)
110 tty_printf (_("Free nodes: %d (%d%%) of %d"),
113 ? 100 * myfs_stats
.nfree
/ myfs_stats
.nodes
: 0,
116 tty_print_string (_("No node information"));
119 widget_move (&info
->widget
, 15, 3);
120 if (myfs_stats
.avail
> 0 || myfs_stats
.total
> 0){
121 char buffer1
[6], buffer2
[6];
122 size_trunc_len (buffer1
, 5, myfs_stats
.avail
, 1);
123 size_trunc_len (buffer2
, 5, myfs_stats
.total
, 1);
124 tty_printf (_("Free space: %s (%d%%) of %s"), buffer1
, myfs_stats
.total
?
125 (int)(100 * (double)myfs_stats
.avail
/ myfs_stats
.total
) : 0,
128 tty_print_string (_("No space information"));
131 widget_move (&info
->widget
, 14, 3);
132 tty_printf (_("Type: %s "),
133 myfs_stats
.typename
? myfs_stats
.typename
: _("non-local vfs"));
134 if (myfs_stats
.type
!= 0xffff && myfs_stats
.type
!= -1)
135 tty_printf (" (%Xh)", myfs_stats
.type
);
138 widget_move (&info
->widget
, 13, 3);
139 str_printf (buff
, _("Device: %s"),
140 str_trunc (myfs_stats
.device
, info
->widget
.cols
- i18n_adjust
));
141 tty_print_string (buff
->str
);
142 g_string_set_size(buff
, 0);
144 widget_move (&info
->widget
, 12, 3);
145 str_printf (buff
, _("Filesystem: %s"),
146 str_trunc (myfs_stats
.mpoint
, info
->widget
.cols
- i18n_adjust
));
147 tty_print_string (buff
->str
);
148 g_string_set_size(buff
, 0);
150 widget_move (&info
->widget
, 11, 3);
151 str_printf (buff
, _("Accessed: %s"), file_date (st
.st_atime
));
152 tty_print_string (buff
->str
);
153 g_string_set_size(buff
, 0);
155 widget_move (&info
->widget
, 10, 3);
156 str_printf (buff
, _("Modified: %s"), file_date (st
.st_mtime
));
157 tty_print_string (buff
->str
);
158 g_string_set_size(buff
, 0);
160 widget_move (&info
->widget
, 9, 3);
161 /* TRANSLATORS: "Status changed", like in the stat(2) man page */
162 str_printf (buff
, _("Status: %s"), file_date (st
.st_ctime
));
163 tty_print_string (buff
->str
);
164 g_string_set_size(buff
, 0);
167 widget_move (&info
->widget
, 8, 3);
168 #ifdef HAVE_STRUCT_STAT_ST_RDEV
169 if (S_ISCHR (st
.st_mode
) || S_ISBLK(st
.st_mode
))
170 tty_printf (_("Dev. type: major %lu, minor %lu"),
171 (unsigned long) major (st
.st_rdev
),
172 (unsigned long) minor (st
.st_rdev
));
177 size_trunc_len(buffer
, 9, st
.st_size
, 0);
178 tty_printf (_("Size: %s"), buffer
);
179 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
180 tty_printf (ngettext(" (%ld block)", " (%ld blocks)",
181 (unsigned long int) st
.st_blocks
),
182 (long int) st
.st_blocks
);
187 widget_move (&info
->widget
, 7, 3);
188 tty_printf (_("Owner: %s/%s"),
189 get_owner (st
.st_uid
),
190 get_group (st
.st_gid
));
193 widget_move (&info
->widget
, 6, 3);
194 tty_printf (_("Links: %d"), (int) st
.st_nlink
);
197 widget_move (&info
->widget
, 5, 3);
198 tty_printf (_("Mode: %s (%04o)"),
199 string_perm (st
.st_mode
), (unsigned) st
.st_mode
& 07777);
202 widget_move (&info
->widget
, 4, 3);
203 tty_printf (_("Location: %Xh:%Xh"), (int)st
.st_dev
, (int)st
.st_ino
);
206 widget_move (&info
->widget
, 3, 2);
207 /* .ado: fname is invalid if selected == 0 && info called from current panel */
208 if (current_panel
->selected
){
209 str_printf (buff
, file_label
,
210 str_trunc (current_panel
->dir
.list
[current_panel
->selected
].fname
,
211 info
->widget
.cols
- i18n_adjust
));
212 tty_print_string (buff
->str
);
214 tty_print_string (_("File: None"));
221 g_string_free (buff
, TRUE
);
224 static void info_hook (void *data
)
226 struct WInfo
*info
= (struct WInfo
*) data
;
227 Widget
*other_widget
;
229 other_widget
= get_panel_widget (get_current_index ());
232 if (dlg_overlap (&info
->widget
, other_widget
))
236 info_show_info (info
);
240 info_callback (Widget
*w
, widget_msg_t msg
, int parm
)
242 struct WInfo
*info
= (struct WInfo
*) w
;
247 add_hook (&select_file_hook
, info_hook
, info
);
253 info_show_info (info
);
257 return MSG_NOT_HANDLED
;
260 delete_hook (&select_file_hook
, info_hook
);
264 return default_proc (msg
, parm
);
268 struct WInfo
*info_new ()
270 struct WInfo
*info
= g_new (struct WInfo
, 1);
272 init_widget (&info
->widget
, 0, 0, 0, 0, info_callback
, NULL
);
274 /* We do not want the cursor */
275 widget_want_cursor (info
->widget
, 0);