pkgdisplay.cc 8.5 KB

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