pkgdisplay.cc 8.5 KB

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