pkgdisplay.cc 8.5 KB

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