pkgdisplay.cc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * pkgdisplay.cc - package list display
  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 <curses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. extern "C" {
  27. #include <config.h>
  28. #include <dpkg.h>
  29. #include <dpkg-db.h>
  30. }
  31. #include "dselect.h"
  32. #include "pkglist.h"
  33. /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
  34. const char
  35. *const wantstrings[]= { N_("new package"),
  36. N_("install"),
  37. N_("hold"),
  38. N_("remove"),
  39. N_("purge"),
  40. 0 },
  41. *const eflagstrings[]= { N_(""),
  42. N_("REINSTALL"),
  43. 0 },
  44. *const statusstrings[]= { N_("not installed"),
  45. N_("unpacked (not set up)"),
  46. N_("failed config"),
  47. N_("installed"),
  48. N_("half installed"),
  49. N_("removed (configs remain)"),
  50. 0 },
  51. *const prioritystrings[]= { N_("Required"),
  52. N_("Important"),
  53. N_("Standard"),
  54. N_("Recommended"),
  55. N_("Optional"),
  56. N_("Extra"),
  57. N_("Contrib"),
  58. N_("!Bug!"),
  59. N_("Unclassified"),
  60. 0 },
  61. *const relatestrings[]= { N_("suggests"),
  62. N_("recommends"),
  63. N_("depends on"),
  64. N_("pre-depends on"),
  65. N_("conflicts with"),
  66. N_("provides"),
  67. N_("replaces"),
  68. N_("enhances"),
  69. 0 },
  70. *const priorityabbrevs[]= { N_("Req"),
  71. N_("Imp"),
  72. N_("Std"),
  73. N_("Rec"),
  74. N_("Opt"),
  75. N_("Xtr"),
  76. N_("Ctb"),
  77. N_("bUG"),
  78. N_("?") };
  79. const char statuschars[]= " UC*I-";
  80. const char eflagchars[]= " R?#";
  81. const char wantchars[]= "n*=-_";
  82. /* These MUST be in the same order as the corresponding enums in pkglist.h */
  83. const char
  84. *const ssaabbrevs[]= { N_("Broken"),
  85. N_("New"),
  86. N_("Updated"),
  87. N_("Obsolete/local"),
  88. N_("Up-to-date"),
  89. N_("Available"),
  90. N_("Removed") },
  91. *const ssastrings[]= { N_("Brokenly installed packages"),
  92. N_("Newly available packages"),
  93. N_("Updated packages (newer version is available)"),
  94. N_("Obsolete and local packages present on system"),
  95. N_("Up to date installed packages"),
  96. N_("Available packages (not currently installed)"),
  97. N_("Removed and no longer available packages") };
  98. const char
  99. *const sssstrings[]= { N_("Brokenly installed packages"),
  100. N_("Installed packages"),
  101. N_("Removed packages (configuration still present)"),
  102. N_("Purged packages and those never installed") },
  103. *const sssabbrevs[]= { N_("Broken"),
  104. N_("Installed"),
  105. N_("Removed"),
  106. N_("Purged") };
  107. static int maximumstring(const char *const *array) {
  108. int maxlen= 0;
  109. while (*array) {
  110. int l= strlen(gettext(*array));
  111. const char *p= strchr(*array, '(');
  112. if (p && p > *array && *--p == ' ') l= p - *array;
  113. if (l > maxlen) maxlen= l;
  114. array++;
  115. }
  116. return maxlen;
  117. }
  118. void packagelist::setwidths() {
  119. if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
  120. if (verbose) {
  121. status_hold_width= 9;
  122. status_status_width= maximumstring(statusstrings);
  123. status_want_width= maximumstring(wantstrings);
  124. status_width= status_hold_width+status_status_width+status_want_width*2+3;
  125. priority_width= 8;
  126. package_width= 16;
  127. } else {
  128. status_width= 4;
  129. priority_width= 3;
  130. package_width= 12;
  131. }
  132. section_width= 8;
  133. gap_width= 1;
  134. if (sortorder == so_section) {
  135. section_column= status_width + gap_width;
  136. priority_column= section_column + section_width + gap_width;
  137. package_column= priority_column + priority_width + gap_width;
  138. } else {
  139. priority_column= status_width + gap_width;
  140. section_column= priority_column + priority_width + gap_width;
  141. package_column= section_column + section_width + gap_width;
  142. }
  143. int versiondescriptioncolumn= package_column + package_width + gap_width;
  144. switch (versiondisplayopt) {
  145. case vdo_none:
  146. versioninstalled_column= versioninstalled_width= 0;
  147. versionavailable_column= versionavailable_width= 0;
  148. description_column= versiondescriptioncolumn;
  149. break;
  150. case vdo_available:
  151. versioninstalled_column= versioninstalled_width= 0;
  152. versionavailable_column= versiondescriptioncolumn;
  153. versionavailable_width= 11;
  154. description_column= versionavailable_column + versionavailable_width + gap_width;
  155. break;
  156. case vdo_both:
  157. versioninstalled_column= versiondescriptioncolumn;
  158. versioninstalled_width= 11;
  159. versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
  160. versionavailable_width= versioninstalled_width;
  161. description_column= versionavailable_column + versionavailable_width + gap_width;
  162. break;
  163. default:
  164. internerr("unknown versiondisplayopt in setwidths");
  165. }
  166. total_width= TOTAL_LIST_WIDTH;
  167. description_width= total_width - description_column;
  168. }
  169. void packagelist::redrawtitle() {
  170. int x,y;
  171. if (title_height) {
  172. mywerase(titlewin);
  173. mvwaddnstr(titlewin,0,0,
  174. recursive ? _("dselect - recursive package listing") :
  175. !readwrite ? _("dselect - inspection of package states") :
  176. _("dselect - main package listing"),
  177. xmax);
  178. getyx(titlewin,y,x);
  179. if (x < xmax) {
  180. switch (sortorder) {
  181. case so_section:
  182. switch (statsortorder) {
  183. case sso_unsorted:
  184. waddnstr(titlewin, _(" (by section)"), xmax-x);
  185. break;
  186. case sso_avail:
  187. waddnstr(titlewin, _(" (avail., section)"), xmax-x);
  188. break;
  189. case sso_state:
  190. waddnstr(titlewin, _(" (status, section)"), xmax-x);
  191. break;
  192. default:
  193. internerr("bad statsort in redrawtitle/so_section");
  194. }
  195. break;
  196. case so_priority:
  197. switch (statsortorder) {
  198. case sso_unsorted:
  199. waddnstr(titlewin, _(" (by priority)"), xmax-x);
  200. break;
  201. case sso_avail:
  202. waddnstr(titlewin, _(" (avail., priority)"), xmax-x);
  203. break;
  204. case sso_state:
  205. waddnstr(titlewin, _(" (status, priority)"), xmax-x);
  206. break;
  207. default:
  208. internerr("bad statsort in redrawtitle/so_priority");
  209. }
  210. break;
  211. case so_alpha:
  212. switch (statsortorder) {
  213. case sso_unsorted:
  214. waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
  215. break;
  216. case sso_avail:
  217. waddnstr(titlewin, _(" (by availability)"), xmax-x);
  218. break;
  219. case sso_state:
  220. waddnstr(titlewin, _(" (by status)"), xmax-x);
  221. break;
  222. default:
  223. internerr("bad statsort in redrawtitle/so_priority");
  224. }
  225. break;
  226. waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
  227. break;
  228. case so_unsorted:
  229. break;
  230. default:
  231. internerr("bad sort in redrawtitle");
  232. }
  233. }
  234. const char *helpstring= readwrite ? (verbose ? _(" mark:+/=/- terse:v help:?")
  235. : _(" mark:+/=/- verbose:v help:?"))
  236. : (verbose ? _(" terse:v help:?")
  237. : _(" verbose:v help:?"));
  238. int l= strlen(helpstring);
  239. getyx(titlewin,y,x);
  240. if (xmax-l > 0) {
  241. mvwaddstr(titlewin,0,xmax-l, helpstring);
  242. }
  243. wnoutrefresh(titlewin);
  244. }
  245. }