tkinfo.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Midnight Commander Tk Information display
  2. Copyright (C) 1995 Miguel de Icaza
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. #include <config.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "fs.h"
  19. #include "dlg.h"
  20. #include "widget.h"
  21. #include "info.h"
  22. #include "win.h"
  23. #include "tkmain.h"
  24. /* The following three include files are needed for cpanel */
  25. #include "main.h"
  26. #include "dir.h"
  27. #include "panel.h"
  28. /* Create the Tk widget */
  29. void
  30. x_create_info (Dlg_head *h, widget_data parent, WInfo *info)
  31. {
  32. char *cmd;
  33. widget_data container = info->widget.wcontainer;
  34. cmd = tk_new_command (container, info, 0, 'o');
  35. tk_evalf ("newinfo %s %s " VERSION, (char *)container,
  36. wtk_win (info->widget));
  37. }
  38. /* Updates the information on the Tk widgets */
  39. void
  40. x_show_info (WInfo *info, struct my_statfs *s, struct stat *b)
  41. {
  42. char bsize [17];
  43. char avail_buf [17], total_buf [17];
  44. char *mod, *acc, *cre;
  45. char *fname;
  46. int have_space, have_nodes;
  47. int space_percent;
  48. int ispace_percent;
  49. fname = cpanel->dir.list [cpanel->selected].fname;
  50. sprint_bytesize (bsize, b->st_size, 0);
  51. mod = strdup (file_date (b->st_mtime));
  52. acc = strdup (file_date (b->st_atime));
  53. cre = strdup (file_date (b->st_ctime));
  54. /* Do we have information on space/inodes? */
  55. have_space = s->avail > 0 || s->total > 0;
  56. have_nodes = s->nfree > 0 || s->nodes > 0;
  57. /* Compute file system usage */
  58. sprint_bytesize (avail_buf, s->avail, 1);
  59. sprint_bytesize (total_buf, s->total, 1);
  60. space_percent = s->total
  61. ? 100 * s->avail / s->total : 0;
  62. /* inode percentage use */
  63. ispace_percent = s->total ? 100 * s->nfree / s->nodes : 0;
  64. tk_evalf ("info_update %s.b {%s} %X %X " /* window fname dev ino */
  65. "{%s} %o " /* mode mode_oct */
  66. "%d %s %s " /* links owner group */
  67. #ifdef HAVE_ST_BLOCKS
  68. #define BLOCKS b->st_blocks
  69. "1 %d " /* have_blocks blocks */
  70. #else
  71. #define BLOCKS 0
  72. "0 %d " /* have_blocks blocks */
  73. #endif
  74. "{%s} " /* size */
  75. #ifdef HAVE_RDEV
  76. #define RDEV b->st_rdev
  77. "1 %d %d " /* have_rdev rdev rdev2 */
  78. #else
  79. #define RDEV 0
  80. "0 %d %d " /* have_rdev rdev rdev2 */
  81. #endif
  82. "{%s} {%s} {%s} " /* create modify access */
  83. "{%s} {%s} {%s} " /* fsys dev type */
  84. "%d {%s} %d {%s} " /* have_space avail percent total */
  85. "%d %d %d %d", /* have_ino nfree inoperc inotot */
  86. wtk_win (info->widget), fname,
  87. b->st_dev, b->st_ino,
  88. string_perm (b->st_mode), b->st_mode & 07777,
  89. b->st_nlink, get_owner (b->st_uid), get_group (b->st_gid),
  90. BLOCKS,
  91. bsize,
  92. RDEV >> 8, RDEV & 0xff,
  93. cre, mod, acc,
  94. s->mpoint, s->device, s->typename,
  95. have_space, avail_buf, space_percent, total_buf,
  96. have_nodes, s->nfree, ispace_percent, s->nodes);
  97. free (mod);
  98. free (acc);
  99. free (cre);
  100. }