Ticket #1648: implemented single-line boxes.
[kaloumi3.git] / src / info.c
blob73bc586859c923d442b4782cc992b0b7d80ea4fc
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 "lib/global.h"
29 #include "lib/tty/tty.h"
30 #include "lib/tty/key.h" /* is_idle() */
31 #include "lib/tty/mouse.h" /* Gpm_Event */
32 #include "lib/skin.h"
33 #include "lib/unixcompat.h"
34 #include "lib/strutil.h"
36 #include "dialog.h"
37 #include "widget.h" /* default_proc*/
38 #include "main-widgets.h" /* the_menubar*/
39 #include "dir.h" /* required by panel */
40 #include "panel.h" /* for the panel structure */
41 #include "main.h" /* other_panel, current_panel definitions */
42 #include "menu.h" /* menubar_visible */
43 #include "layout.h"
44 #include "mountlist.h"
45 #include "info.h"
47 #ifndef VERSION
48 # define VERSION "undefined"
49 #endif
51 struct WInfo {
52 Widget widget;
53 int ready;
56 /* Have we called the init_my_statfs routine? */
57 static gboolean initialized = FALSE;
58 static struct my_statfs myfs_stats;
60 static void info_box (Dlg_head *h, struct WInfo *info)
62 tty_set_normal_attrs ();
63 tty_setcolor (NORMAL_COLOR);
64 widget_erase (&info->widget);
65 draw_box (h, info->widget.y, info->widget.x,
66 info->widget.lines, info->widget.cols, FALSE);
69 static void
70 info_show_info (struct WInfo *info)
72 static int i18n_adjust = 0;
73 static const char *file_label;
74 GString *buff;
75 struct stat st;
77 if (!is_idle ())
78 return;
80 info_box (info->widget.parent, info);
81 tty_setcolor (MARKED_COLOR);
82 widget_move (&info->widget, 1, 3);
83 tty_printf (_("Midnight Commander %s"), VERSION);
84 tty_setcolor (NORMAL_COLOR);
85 tty_draw_hline (info->widget.y + 2, info->widget.x + 1,
86 ACS_HLINE, info->widget.cols - 2);
87 if (get_current_type () != view_listing)
88 return;
90 if (!info->ready)
91 return;
93 my_statfs (&myfs_stats, current_panel->cwd);
94 st = current_panel->dir.list [current_panel->selected].st;
96 /* Print only lines which fit */
98 if (i18n_adjust == 0) {
99 /* This printf pattern string is used as a reference for size */
100 file_label = _("File: %s");
101 i18n_adjust = str_term_width1 (file_label) + 2;
104 buff = g_string_new ("");
106 switch (info->widget.lines-2){
107 /* Note: all cases are fall-throughs */
109 default:
111 case 16:
112 widget_move (&info->widget, 16, 3);
113 if (myfs_stats.nfree >0 || myfs_stats.nodes > 0)
114 tty_printf (_("Free nodes: %d (%d%%) of %d"),
115 myfs_stats.nfree,
116 myfs_stats.total
117 ? 100 * myfs_stats.nfree / myfs_stats.nodes : 0,
118 myfs_stats.nodes);
119 else
120 tty_print_string (_("No node information"));
122 case 15:
123 widget_move (&info->widget, 15, 3);
124 if (myfs_stats.avail > 0 || myfs_stats.total > 0){
125 char buffer1 [6], buffer2[6];
126 size_trunc_len (buffer1, 5, myfs_stats.avail, 1);
127 size_trunc_len (buffer2, 5, myfs_stats.total, 1);
128 tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
129 (int)(100 * (double)myfs_stats.avail / myfs_stats.total) : 0,
130 buffer2);
131 } else
132 tty_print_string (_("No space information"));
134 case 14:
135 widget_move (&info->widget, 14, 3);
136 tty_printf (_("Type: %s "),
137 myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
138 if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
139 tty_printf (" (%Xh)", myfs_stats.type);
141 case 13:
142 widget_move (&info->widget, 13, 3);
143 str_printf (buff, _("Device: %s"),
144 str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
145 tty_print_string (buff->str);
146 g_string_set_size(buff, 0);
147 case 12:
148 widget_move (&info->widget, 12, 3);
149 str_printf (buff, _("Filesystem: %s"),
150 str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
151 tty_print_string (buff->str);
152 g_string_set_size(buff, 0);
153 case 11:
154 widget_move (&info->widget, 11, 3);
155 str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
156 tty_print_string (buff->str);
157 g_string_set_size(buff, 0);
158 case 10:
159 widget_move (&info->widget, 10, 3);
160 str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
161 tty_print_string (buff->str);
162 g_string_set_size(buff, 0);
163 case 9:
164 widget_move (&info->widget, 9, 3);
165 /* TRANSLATORS: "Status changed", like in the stat(2) man page */
166 str_printf (buff, _("Status: %s"), file_date (st.st_ctime));
167 tty_print_string (buff->str);
168 g_string_set_size(buff, 0);
170 case 8:
171 widget_move (&info->widget, 8, 3);
172 #ifdef HAVE_STRUCT_STAT_ST_RDEV
173 if (S_ISCHR (st.st_mode) || S_ISBLK(st.st_mode))
174 tty_printf (_("Dev. type: major %lu, minor %lu"),
175 (unsigned long) major (st.st_rdev),
176 (unsigned long) minor (st.st_rdev));
177 else
178 #endif
180 char buffer[10];
181 size_trunc_len(buffer, 9, st.st_size, 0);
182 tty_printf (_("Size: %s"), buffer);
183 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
184 tty_printf (ngettext(" (%ld block)", " (%ld blocks)",
185 (unsigned long int) st.st_blocks),
186 (long int) st.st_blocks);
187 #endif
190 case 7:
191 widget_move (&info->widget, 7, 3);
192 tty_printf (_("Owner: %s/%s"),
193 get_owner (st.st_uid),
194 get_group (st.st_gid));
196 case 6:
197 widget_move (&info->widget, 6, 3);
198 tty_printf (_("Links: %d"), (int) st.st_nlink);
200 case 5:
201 widget_move (&info->widget, 5, 3);
202 tty_printf (_("Mode: %s (%04o)"),
203 string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
205 case 4:
206 widget_move (&info->widget, 4, 3);
207 tty_printf (_("Location: %Xh:%Xh"), (int)st.st_dev, (int)st.st_ino);
209 case 3:
211 const char *fname;
213 widget_move (&info->widget, 3, 2);
214 fname = current_panel->dir.list [current_panel->selected].fname;
215 str_printf (buff, file_label,
216 str_trunc (fname, info->widget.cols - i18n_adjust));
217 tty_print_string (buff->str);
220 case 2:
221 case 1:
222 case 0:
224 } /* switch */
225 g_string_free (buff, TRUE);
228 static void info_hook (void *data)
230 struct WInfo *info = (struct WInfo *) data;
231 Widget *other_widget;
233 other_widget = get_panel_widget (get_current_index ());
234 if (!other_widget)
235 return;
236 if (dlg_overlap (&info->widget, other_widget))
237 return;
239 info->ready = 1;
240 info_show_info (info);
243 static cb_ret_t
244 info_callback (Widget *w, widget_msg_t msg, int parm)
246 struct WInfo *info = (struct WInfo *) w;
248 switch (msg) {
250 case WIDGET_INIT:
251 add_hook (&select_file_hook, info_hook, info);
252 info->ready = 0;
253 return MSG_HANDLED;
255 case WIDGET_DRAW:
256 info_hook (info);
257 info_show_info (info);
258 return MSG_HANDLED;
260 case WIDGET_FOCUS:
261 return MSG_NOT_HANDLED;
263 case WIDGET_DESTROY:
264 delete_hook (&select_file_hook, info_hook);
265 return MSG_HANDLED;
267 default:
268 return default_proc (msg, parm);
272 static int
273 info_event (Gpm_Event *event, void *data)
275 Widget *w = &((WInfo *) data)->widget;
277 /* rest of the upper frame, the menu is invisible - call menu */
278 if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible) {
279 event->x += w->x;
280 return the_menubar->widget.mouse (event, the_menubar);
283 return MOU_NORMAL;
286 WInfo *
287 info_new (void)
289 struct WInfo *info = g_new (struct WInfo, 1);
291 init_widget (&info->widget, 0, 0, 0, 0, info_callback, info_event);
293 /* We do not want the cursor */
294 widget_want_cursor (info->widget, 0);
296 if (!initialized) {
297 initialized = TRUE;
298 init_my_statfs ();
301 return info;