1998-02-27 07:54:42 +03:00
|
|
|
/* Panel managing.
|
2007-09-26 14:22:25 +04:00
|
|
|
Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
|
|
|
2005, 2007 Free Software Foundation, Inc.
|
2010-04-06 11:16:11 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2010-04-06 11:16:11 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file info.c
|
|
|
|
* \brief Source: panel managing
|
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
2010-05-29 17:16:34 +04:00
|
|
|
#include <sys/stat.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-05-29 17:16:34 +04:00
|
|
|
#include "lib/unixcompat.h"
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/tty.h"
|
2010-04-06 11:16:11 +04:00
|
|
|
#include "lib/tty/key.h" /* is_idle() */
|
|
|
|
#include "lib/tty/mouse.h" /* Gpm_Event */
|
2010-01-21 16:06:15 +03:00
|
|
|
#include "lib/skin.h"
|
2010-01-21 15:17:26 +03:00
|
|
|
#include "lib/strutil.h"
|
2009-09-03 13:48:15 +04:00
|
|
|
|
2003-10-25 03:20:30 +04:00
|
|
|
#include "dialog.h"
|
2010-04-06 11:16:11 +04:00
|
|
|
#include "widget.h" /* default_proc */
|
|
|
|
#include "main-widgets.h" /* the_menubar */
|
|
|
|
#include "panel.h" /* for the panel structure */
|
|
|
|
#include "menu.h" /* menubar_visible */
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "layout.h"
|
2001-06-19 02:24:04 +04:00
|
|
|
#include "mountlist.h"
|
2010-03-09 22:03:51 +03:00
|
|
|
#include "setup.h" /* panels_options */
|
2009-09-03 13:48:15 +04:00
|
|
|
#include "info.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-12-02 08:18:20 +03:00
|
|
|
#ifndef VERSION
|
|
|
|
# define VERSION "undefined"
|
|
|
|
#endif
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
struct WInfo
|
|
|
|
{
|
2003-10-26 08:54:55 +03:00
|
|
|
Widget widget;
|
|
|
|
int ready;
|
|
|
|
};
|
|
|
|
|
2001-06-05 20:41:44 +04:00
|
|
|
static struct my_statfs myfs_stats;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
static void
|
2010-05-29 17:30:47 +04:00
|
|
|
info_box (struct WInfo *info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2010-05-29 17:30:47 +04:00
|
|
|
const char *title = _("Information");
|
|
|
|
const int len = str_term_width1 (title);
|
|
|
|
|
2009-06-02 08:55:07 +04:00
|
|
|
tty_set_normal_attrs ();
|
2009-05-11 16:13:58 +04:00
|
|
|
tty_setcolor (NORMAL_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
widget_erase (&info->widget);
|
2010-05-29 17:30:47 +04:00
|
|
|
draw_box (info->widget.parent, info->widget.y, info->widget.x,
|
|
|
|
info->widget.lines, info->widget.cols, FALSE);
|
|
|
|
|
|
|
|
widget_move (&info->widget, 0, (info->widget.cols - len - 2)/2);
|
|
|
|
tty_printf (" %s ", title);
|
|
|
|
|
|
|
|
widget_move (&info->widget, 2, 0);
|
|
|
|
tty_print_alt_char (ACS_LTEE, FALSE);
|
|
|
|
widget_move (&info->widget, 2, info->widget.cols - 1);
|
|
|
|
tty_print_alt_char (ACS_RTEE, FALSE);
|
|
|
|
tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-12-03 00:27:27 +03:00
|
|
|
static void
|
2003-10-26 08:54:55 +03:00
|
|
|
info_show_info (struct WInfo *info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-10-31 23:04:35 +03:00
|
|
|
static int i18n_adjust = 0;
|
2004-09-19 19:55:58 +04:00
|
|
|
static const char *file_label;
|
2009-04-14 14:29:01 +04:00
|
|
|
GString *buff;
|
2003-08-18 04:47:43 +04:00
|
|
|
struct stat st;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!is_idle ())
|
2010-04-06 11:16:11 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-05-29 17:30:47 +04:00
|
|
|
info_box (info);
|
|
|
|
|
2009-05-11 16:13:58 +04:00
|
|
|
tty_setcolor (MARKED_COLOR);
|
1998-02-27 07:54:42 +03:00
|
|
|
widget_move (&info->widget, 1, 3);
|
2005-09-05 05:34:25 +04:00
|
|
|
tty_printf (_("Midnight Commander %s"), VERSION);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!info->ready)
|
2010-04-06 11:16:11 +04:00
|
|
|
return;
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2010-05-29 17:30:47 +04:00
|
|
|
if (get_current_type () != view_listing)
|
|
|
|
return;
|
|
|
|
|
2003-10-26 09:45:59 +03:00
|
|
|
my_statfs (&myfs_stats, current_panel->cwd);
|
2010-04-06 11:16:11 +04:00
|
|
|
st = current_panel->dir.list[current_panel->selected].st;
|
2003-08-18 04:47:43 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Print only lines which fit */
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
if (i18n_adjust == 0)
|
|
|
|
{
|
|
|
|
/* This printf pattern string is used as a reference for size */
|
|
|
|
file_label = _("File: %s");
|
|
|
|
i18n_adjust = str_term_width1 (file_label) + 2;
|
1999-04-06 23:00:16 +04:00
|
|
|
}
|
2009-04-14 14:29:01 +04:00
|
|
|
|
2010-05-29 17:30:47 +04:00
|
|
|
tty_setcolor (NORMAL_COLOR);
|
|
|
|
|
2009-04-14 14:29:01 +04:00
|
|
|
buff = g_string_new ("");
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
switch (info->widget.lines - 2)
|
|
|
|
{
|
|
|
|
/* Note: all cases are fall-throughs */
|
2009-04-14 14:29:01 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
default:
|
|
|
|
|
|
|
|
case 16:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 16, 3);
|
|
|
|
if (myfs_stats.nfree > 0 || myfs_stats.nodes > 0)
|
|
|
|
tty_printf (_("Free nodes: %d (%d%%) of %d"),
|
|
|
|
myfs_stats.nfree,
|
|
|
|
myfs_stats.total
|
|
|
|
? 100 * myfs_stats.nfree / myfs_stats.nodes : 0, myfs_stats.nodes);
|
|
|
|
else
|
|
|
|
tty_print_string (_("No node information"));
|
2009-08-07 11:38:28 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 15:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 15, 3);
|
|
|
|
if (myfs_stats.avail > 0 || myfs_stats.total > 0)
|
|
|
|
{
|
|
|
|
char buffer1[6], buffer2[6];
|
2010-03-09 22:03:51 +03:00
|
|
|
size_trunc_len (buffer1, 5, myfs_stats.avail, 1, panels_options.kilobyte_si);
|
|
|
|
size_trunc_len (buffer2, 5, myfs_stats.total, 1, panels_options.kilobyte_si);
|
2010-04-06 11:16:11 +04:00
|
|
|
tty_printf (_("Free space: %s (%d%%) of %s"), buffer1, myfs_stats.total ?
|
|
|
|
(int) (100 * (double) myfs_stats.avail / myfs_stats.total) : 0, buffer2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tty_print_string (_("No space information"));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case 14:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 14, 3);
|
|
|
|
tty_printf (_("Type: %s "),
|
|
|
|
myfs_stats.typename ? myfs_stats.typename : _("non-local vfs"));
|
|
|
|
if (myfs_stats.type != 0xffff && myfs_stats.type != -1)
|
|
|
|
tty_printf (" (%Xh)", myfs_stats.type);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case 13:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 13, 3);
|
|
|
|
str_printf (buff, _("Device: %s"),
|
|
|
|
str_trunc (myfs_stats.device, info->widget.cols - i18n_adjust));
|
2009-05-13 08:58:12 +04:00
|
|
|
tty_print_string (buff->str);
|
2010-04-06 11:16:11 +04:00
|
|
|
g_string_set_size (buff, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
case 12:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 12, 3);
|
2008-12-29 02:09:05 +03:00
|
|
|
str_printf (buff, _("Filesystem: %s"),
|
2010-04-06 11:16:11 +04:00
|
|
|
str_trunc (myfs_stats.mpoint, info->widget.cols - i18n_adjust));
|
2009-05-13 08:58:12 +04:00
|
|
|
tty_print_string (buff->str);
|
2010-04-06 11:16:11 +04:00
|
|
|
g_string_set_size (buff, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
case 11:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 11, 3);
|
2008-12-29 02:09:05 +03:00
|
|
|
str_printf (buff, _("Accessed: %s"), file_date (st.st_atime));
|
2009-05-13 08:58:12 +04:00
|
|
|
tty_print_string (buff->str);
|
2010-04-06 11:16:11 +04:00
|
|
|
g_string_set_size (buff, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
case 10:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 10, 3);
|
2008-12-29 02:09:05 +03:00
|
|
|
str_printf (buff, _("Modified: %s"), file_date (st.st_mtime));
|
2009-05-13 08:58:12 +04:00
|
|
|
tty_print_string (buff->str);
|
2010-04-06 11:16:11 +04:00
|
|
|
g_string_set_size (buff, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
case 9:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 9, 3);
|
2010-04-19 15:26:49 +04:00
|
|
|
/* The field st_ctime is changed by writing or by setting inode
|
|
|
|
information (i.e., owner, group, link count, mode, etc.). */
|
|
|
|
/* TRANSLATORS: Time of last status change as in stat(2) man. */
|
|
|
|
str_printf (buff, _("Changed: %s"), file_date (st.st_ctime));
|
2009-05-13 08:58:12 +04:00
|
|
|
tty_print_string (buff->str);
|
2010-04-06 11:16:11 +04:00
|
|
|
g_string_set_size (buff, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case 8:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 8, 3);
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2010-04-06 11:16:11 +04:00
|
|
|
if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode))
|
|
|
|
tty_printf (_("Dev. type: major %lu, minor %lu"),
|
|
|
|
(unsigned long) major (st.st_rdev), (unsigned long) minor (st.st_rdev));
|
|
|
|
else
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
|
|
|
char buffer[10];
|
2010-03-09 22:03:51 +03:00
|
|
|
size_trunc_len (buffer, 9, st.st_size, 0, panels_options.kilobyte_si);
|
2010-04-06 11:16:11 +04:00
|
|
|
tty_printf (_("Size: %s"), buffer);
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2010-04-06 11:16:11 +04:00
|
|
|
tty_printf (ngettext (" (%ld block)", " (%ld blocks)",
|
|
|
|
(unsigned long int) st.st_blocks), (long int) st.st_blocks);
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
2010-04-06 11:16:11 +04:00
|
|
|
}
|
2009-08-07 11:38:28 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 7:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 7, 3);
|
|
|
|
tty_printf (_("Owner: %s/%s"), get_owner (st.st_uid), get_group (st.st_gid));
|
2009-10-31 23:04:35 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 6:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 6, 3);
|
|
|
|
tty_printf (_("Links: %d"), (int) st.st_nlink);
|
2009-10-31 23:04:35 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 5:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 5, 3);
|
|
|
|
tty_printf (_("Mode: %s (%04o)"),
|
|
|
|
string_perm (st.st_mode), (unsigned) st.st_mode & 07777);
|
2009-10-31 23:04:35 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 4:
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 4, 3);
|
|
|
|
tty_printf (_("Location: %Xh:%Xh"), (int) st.st_dev, (int) st.st_ino);
|
2009-10-31 23:04:35 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 3:
|
2010-04-06 11:16:11 +04:00
|
|
|
{
|
|
|
|
const char *fname;
|
2009-10-31 23:04:35 +03:00
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
widget_move (&info->widget, 3, 2);
|
|
|
|
fname = current_panel->dir.list[current_panel->selected].fname;
|
|
|
|
str_printf (buff, file_label, str_trunc (fname, info->widget.cols - i18n_adjust));
|
|
|
|
tty_print_string (buff->str);
|
|
|
|
}
|
2009-08-07 11:38:28 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
case 2:
|
|
|
|
case 1:
|
|
|
|
case 0:
|
2010-04-06 11:16:11 +04:00
|
|
|
;
|
|
|
|
} /* switch */
|
2009-04-14 14:29:01 +04:00
|
|
|
g_string_free (buff, TRUE);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
static void
|
|
|
|
info_hook (void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-26 08:54:55 +03:00
|
|
|
struct WInfo *info = (struct WInfo *) data;
|
1998-02-27 07:54:42 +03:00
|
|
|
Widget *other_widget;
|
2009-10-31 23:04:35 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
other_widget = get_panel_widget (get_current_index ());
|
|
|
|
if (!other_widget)
|
2010-04-06 11:16:11 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (dlg_overlap (&info->widget, other_widget))
|
2010-04-06 11:16:11 +04:00
|
|
|
return;
|
2009-10-31 23:04:35 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
info->ready = 1;
|
|
|
|
info_show_info (info);
|
|
|
|
}
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
static cb_ret_t
|
2010-04-06 11:16:11 +04:00
|
|
|
info_callback (Widget * w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-05-23 20:30:44 +04:00
|
|
|
struct WInfo *info = (struct WInfo *) w;
|
|
|
|
|
2010-04-06 11:16:11 +04:00
|
|
|
switch (msg)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case WIDGET_INIT:
|
2010-05-29 17:16:34 +04:00
|
|
|
init_my_statfs ();
|
2010-04-06 11:16:11 +04:00
|
|
|
add_hook (&select_file_hook, info_hook, info);
|
|
|
|
info->ready = 0;
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case WIDGET_DRAW:
|
2010-04-06 11:16:11 +04:00
|
|
|
info_hook (info);
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case WIDGET_FOCUS:
|
2010-04-06 11:16:11 +04:00
|
|
|
return MSG_NOT_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
case WIDGET_DESTROY:
|
2010-04-06 11:16:11 +04:00
|
|
|
delete_hook (&select_file_hook, info_hook);
|
2010-05-29 17:16:34 +04:00
|
|
|
free_my_statfs ();
|
2010-04-06 11:16:11 +04:00
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
default:
|
2010-04-06 11:16:11 +04:00
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
2009-09-03 13:48:15 +04:00
|
|
|
|
|
|
|
static int
|
2010-04-06 11:16:11 +04:00
|
|
|
info_event (Gpm_Event * event, void *data)
|
2009-09-03 13:48:15 +04:00
|
|
|
{
|
|
|
|
Widget *w = &((WInfo *) data)->widget;
|
|
|
|
|
|
|
|
/* rest of the upper frame, the menu is invisible - call menu */
|
2010-04-06 11:16:11 +04:00
|
|
|
if (event->type & GPM_DOWN && event->y == 1 && !menubar_visible)
|
|
|
|
{
|
|
|
|
event->x += w->x;
|
|
|
|
return the_menubar->widget.mouse (event, the_menubar);
|
2009-09-03 13:48:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WInfo *
|
2010-05-16 10:11:51 +04:00
|
|
|
info_new (int y, int x, int lines, int cols)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-26 08:54:55 +03:00
|
|
|
struct WInfo *info = g_new (struct WInfo, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-05-16 10:11:51 +04:00
|
|
|
init_widget (&info->widget, y, x, lines, cols, info_callback, info_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* We do not want the cursor */
|
|
|
|
widget_want_cursor (info->widget, 0);
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|