Removed draw_double_box() function.
[midnight-commander.git] / src / info.c
blob3d287393c4182ef267fa134e1333fed1c2859c23
1 /* Panel managing.
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. */
19 /** \file info.c
20 * \brief Source: panel managing
23 #include <config.h>
25 #include <stdio.h>
27 #include "global.h"
28 #include "../src/tty/tty.h"
29 #include "../src/tty/mouse.h" /* Gpm_Event */
30 #include "../src/tty/color.h"
31 #include "dialog.h"
32 #include "info.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 */
37 #include "layout.h"
38 #include "../src/tty/key.h" /* is_idle() */
39 #include "mountlist.h"
40 #include "unixcompat.h"
41 #include "strutil.h"
43 #ifndef VERSION
44 # define VERSION "undefined"
45 #endif
47 struct WInfo {
48 Widget widget;
49 int ready;
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);
65 static void
66 info_show_info (struct WInfo *info)
68 static int i18n_adjust=0;
69 static const char *file_label;
70 GString *buff;
71 struct stat st;
73 if (!is_idle ())
74 return;
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)
84 return;
86 if (!info->ready)
87 return;
89 my_statfs (&myfs_stats, current_panel->cwd);
90 st = current_panel->dir.list [current_panel->selected].st;
92 /* Print only lines which fit */
94 if(!i18n_adjust) {
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 */
105 default:
107 case 16:
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"),
111 myfs_stats.nfree,
112 myfs_stats.total
113 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
114 myfs_stats.nodes);
115 else
116 tty_print_string (_("No node information"));
118 case 15:
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,
126 buffer2);
127 } else
128 tty_print_string (_("No space information"));
130 case 14:
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);
137 case 13:
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);
143 case 12:
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);
149 case 11:
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);
154 case 10:
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);
159 case 9:
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);
166 case 8:
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));
173 else
174 #endif
176 char buffer[10];
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);
183 #endif
186 case 7:
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));
192 case 6:
193 widget_move (&info->widget, 6, 3);
194 tty_printf (_("Links: %d"), (int) st.st_nlink);
196 case 5:
197 widget_move (&info->widget, 5, 3);
198 tty_printf (_("Mode: %s (%04o)"),
199 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
201 case 4:
202 widget_move (&info->widget, 4, 3);
203 tty_printf (_("Location: %Xh:%Xh"), (int)st.st_dev, (int)st.st_ino);
205 case 3:
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);
213 } else
214 tty_print_string (_("File: None"));
216 case 2:
217 case 1:
218 case 0:
220 } /* switch */
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 ());
230 if (!other_widget)
231 return;
232 if (dlg_overlap (&info->widget, other_widget))
233 return;
235 info->ready = 1;
236 info_show_info (info);
239 static cb_ret_t
240 info_callback (Widget *w, widget_msg_t msg, int parm)
242 struct WInfo *info = (struct WInfo *) w;
244 switch (msg) {
246 case WIDGET_INIT:
247 add_hook (&select_file_hook, info_hook, info);
248 info->ready = 0;
249 return MSG_HANDLED;
251 case WIDGET_DRAW:
252 info_hook (info);
253 info_show_info (info);
254 return MSG_HANDLED;
256 case WIDGET_FOCUS:
257 return MSG_NOT_HANDLED;
259 case WIDGET_DESTROY:
260 delete_hook (&select_file_hook, info_hook);
261 return MSG_HANDLED;
263 default:
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);
277 if (!initialized){
278 initialized = 1;
279 init_my_statfs ();
282 return info;