pkgtop.cc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <ncurses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. #include <ctype.h>
  27. extern "C" {
  28. #include "config.h"
  29. #include "dpkg.h"
  30. #include "dpkg-db.h"
  31. }
  32. #include "dselect.h"
  33. #include "pkglist.h"
  34. const char *pkgprioritystring(const struct pkginfo *pkg) {
  35. if (pkg->priority == pkginfo::pri_unset) {
  36. return 0;
  37. } else if (pkg->priority == pkginfo::pri_other) {
  38. return pkg->otherpriority;
  39. } else {
  40. assert(pkg->priority <= pkginfo::pri_unknown);
  41. return prioritystrings[pkg->priority];
  42. }
  43. }
  44. static int describemany(char buf[], const char *prioritystring, const char *section) {
  45. if (!prioritystring) {
  46. if (!section) {
  47. strcpy(buf, "All packages");
  48. return 0;
  49. } else {
  50. if (!*section) {
  51. strcpy(buf, "All packages without a section");
  52. } else {
  53. sprintf(buf, "All packages in section %s", section);
  54. }
  55. return 1;
  56. }
  57. } else {
  58. if (!section) {
  59. sprintf(buf, "All %s packages", prioritystring);
  60. return 1;
  61. } else {
  62. if (!*section) {
  63. sprintf(buf, "All %s packages without a section", prioritystring);
  64. } else {
  65. sprintf(buf, "All %s packages in section %s", prioritystring, section);
  66. }
  67. return 2;
  68. }
  69. }
  70. }
  71. void packagelist::redrawthisstate() {
  72. if (!thisstate_height) return;
  73. mywerase(thisstatepad);
  74. const char *section= table[cursorline]->pkg->section;
  75. const char *priority= pkgprioritystring(table[cursorline]->pkg);
  76. char *buf= new char[220+
  77. greaterint((table[cursorline]->pkg->name
  78. ? strlen(table[cursorline]->pkg->name) : 0),
  79. (section ? strlen(section) : 0) +
  80. (priority ? strlen(priority) : 0))];
  81. if (table[cursorline]->pkg->name) {
  82. sprintf(buf,
  83. "%-*s %s%s%s; %s (was: %s). %s",
  84. package_width,
  85. table[cursorline]->pkg->name,
  86. statusstrings[table[cursorline]->pkg->status],
  87. holdstrings[table[cursorline]->pkg->eflag][0] ? " - " : "",
  88. holdstrings[table[cursorline]->pkg->eflag],
  89. wantstrings[table[cursorline]->selected],
  90. wantstrings[table[cursorline]->original],
  91. priority);
  92. } else {
  93. describemany(buf,priority,section);
  94. }
  95. mvwaddnstr(thisstatepad,0,0, buf, total_width);
  96. pnoutrefresh(thisstatepad, 0,leftofscreen, thisstate_row,0,
  97. thisstate_row, lesserint(total_width - 1, xmax - 1));
  98. delete[] buf;
  99. }
  100. void packagelist::redraw1itemsel(int index, int selected) {
  101. int i, indent, j;
  102. const char *p;
  103. const struct pkginfo *pkg= table[index]->pkg;
  104. const struct pkginfoperfile *info= &pkg->available;
  105. wattrset(listpad, selected ? listsel_attr : list_attr);
  106. if (pkg->name) {
  107. if (verbose) {
  108. mvwprintw(listpad,index,0, "%-*.*s ",
  109. status_hold_width, status_hold_width,
  110. holdstrings[pkg->eflag]);
  111. wprintw(listpad, "%-*.*s ",
  112. status_status_width, status_status_width,
  113. statusstrings[pkg->status]);
  114. wprintw(listpad, "%-*.*s ",
  115. status_want_width, status_want_width,
  116. /* fixme: keep this ? */
  117. /*table[index]->original == table[index]->selected ? "(same)"
  118. : */wantstrings[table[index]->original]);
  119. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  120. wprintw(listpad, "%-*.*s",
  121. status_want_width, status_want_width,
  122. wantstrings[table[index]->selected]);
  123. wattrset(listpad, selected ? listsel_attr : list_attr);
  124. waddch(listpad, ' ');
  125. mvwprintw(listpad,index,priority_column-1, " %-*.*s",
  126. priority_width, priority_width,
  127. pkg->priority == pkginfo::pri_other ? pkg->otherpriority :
  128. prioritystrings[pkg->priority]);
  129. } else {
  130. mvwaddch(listpad,index,0, holdchars[pkg->eflag]);
  131. waddch(listpad, statuschars[pkg->status]);
  132. waddch(listpad,
  133. /* fixme: keep this feature? */
  134. /*table[index]->original == table[index]->selected ? ' '
  135. : */wantchars[table[index]->original]);
  136. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  137. waddch(listpad, wantchars[table[index]->selected]);
  138. wattrset(listpad, selected ? listsel_attr : list_attr);
  139. wmove(listpad,index,priority_column-1); waddch(listpad,' ');
  140. if (pkg->priority == pkginfo::pri_other) {
  141. int i;
  142. char *p;
  143. for (i=priority_width, p=pkg->otherpriority;
  144. i > 0 && *p;
  145. i--, p++)
  146. waddch(listpad, tolower(*p));
  147. while (i-- > 0) waddch(listpad,' ');
  148. } else {
  149. wprintw(listpad, "%-*.*s", priority_width, priority_width,
  150. priorityabbrevs[pkg->priority]);
  151. }
  152. }
  153. mvwprintw(listpad,index,section_column-1, " %-*.*s",
  154. section_width, section_width,
  155. pkg->section ? pkg->section : "?");
  156. mvwprintw(listpad,index,package_column-1, " %-*.*s ",
  157. package_width, package_width, pkg->name);
  158. i= description_width;
  159. p= info->description ? info->description : "";
  160. while (i>0 && *p && *p != '\n') { waddch(listpad,*p); i--; p++; }
  161. } else {
  162. const char *section= pkg->section;
  163. const char *priority= pkgprioritystring(pkg);
  164. char *buf= new char[220+
  165. (section ? strlen(section) : 0) +
  166. (priority ? strlen(priority) : 0)];
  167. indent= describemany(buf,priority,section);
  168. mvwaddstr(listpad,index,0, " ");
  169. i= total_width-6;
  170. j= (indent<<1) + 1;
  171. while (j-- >0) { waddch(listpad,'-'); i--; }
  172. waddch(listpad,' ');
  173. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  174. p= buf;
  175. while (i>0 && *p) { waddch(listpad, *p); p++; i--; }
  176. wattrset(listpad, selected ? listsel_attr : list_attr);
  177. waddch(listpad,' ');
  178. j= (indent<<1) + 1;
  179. while (j-- >0) { waddch(listpad,'-'); i--; }
  180. delete[] buf;
  181. }
  182. while (i>0) { waddch(listpad,' '); i--; }
  183. }
  184. void packagelist::redrawcolheads() {
  185. if (colheads_height) {
  186. wattrset(colheadspad,colheads_attr);
  187. mywerase(colheadspad);
  188. if (verbose) {
  189. wmove(colheadspad,0,0);
  190. for (int i=0; i<status_width-status_want_width; i++) waddch(colheadspad,'.');
  191. mvwaddnstr(colheadspad,0,
  192. 0,
  193. "Hold/Err.",
  194. status_hold_width);
  195. mvwaddnstr(colheadspad,0,
  196. status_hold_width+1,
  197. "Installed?",
  198. status_status_width);
  199. mvwaddnstr(colheadspad,0,
  200. status_hold_width+status_status_width+2,
  201. "Old sel.",
  202. status_want_width);
  203. mvwaddnstr(colheadspad,0,
  204. status_hold_width+status_status_width+status_want_width+3,
  205. "Selection",
  206. status_want_width);
  207. } else {
  208. mvwaddstr(colheadspad,0,0, "HIOS");
  209. }
  210. mvwaddnstr(colheadspad,0,section_column, "Section", section_width);
  211. mvwaddnstr(colheadspad,0,priority_column, "Priority", priority_width);
  212. mvwaddnstr(colheadspad,0,package_column, "Package", package_width);
  213. mvwaddnstr(colheadspad,0,description_column, "Description", description_width);
  214. }
  215. refreshcolheads();
  216. }