pkgdisplay.cc 8.6 KB

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