pkgdisplay.cc 8.4 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 <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 aroung gettext which uses the empty
  40. * string to store information about the translation
  41. */
  42. *const eflagstrings[]= { N_(" "),
  43. N_("REINSTALL"),
  44. 0 },
  45. *const statusstrings[]= { N_("not installed"),
  46. N_("unpacked (not set up)"),
  47. N_("failed config"),
  48. N_("installed"),
  49. N_("half installed"),
  50. N_("removed (configs remain)"),
  51. 0 },
  52. *const prioritystrings[]= { N_("Required"),
  53. N_("Important"),
  54. N_("Standard"),
  55. N_("Recommended"),
  56. N_("Optional"),
  57. N_("Extra"),
  58. N_("Contrib"),
  59. N_("!Bug!"),
  60. N_("Unclassified"),
  61. 0 },
  62. *const relatestrings[]= { N_("suggests"),
  63. N_("recommends"),
  64. N_("depends on"),
  65. N_("pre-depends on"),
  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_("Rec"),
  75. N_("Opt"),
  76. N_("Xtr"),
  77. N_("Ctb"),
  78. N_("bUG"),
  79. N_("?") };
  80. const char statuschars[]= " UC*I-";
  81. const char eflagchars[]= " R?#";
  82. const char wantchars[]= "n*=-_";
  83. /* These MUST be in the same order as the corresponding enums in pkglist.h */
  84. const char
  85. *const ssaabbrevs[]= { N_("Broken"),
  86. N_("New"),
  87. N_("Updated"),
  88. N_("Obsolete/local"),
  89. N_("Up-to-date"),
  90. N_("Available"),
  91. N_("Removed") },
  92. *const ssastrings[]= { N_("Brokenly installed packages"),
  93. N_("Newly available packages"),
  94. N_("Updated packages (newer version is available)"),
  95. N_("Obsolete and local packages present on system"),
  96. N_("Up to date installed packages"),
  97. N_("Available packages (not currently installed)"),
  98. N_("Removed and no longer available packages") };
  99. const char
  100. *const sssstrings[]= { N_("Brokenly installed packages"),
  101. N_("Installed packages"),
  102. N_("Removed packages (configuration still present)"),
  103. N_("Purged packages and those never installed") },
  104. *const sssabbrevs[]= { N_("Broken"),
  105. N_("Installed"),
  106. N_("Removed"),
  107. N_("Purged") };
  108. static int maximumstring(const char *const *array) {
  109. int maxlen= 0;
  110. while (*array) {
  111. int l= strlen(gettext(*array));
  112. const char *p= strchr(*array, '(');
  113. if (p && p > *array && *--p == ' ') l= p - *array;
  114. if (l > maxlen) maxlen= l;
  115. array++;
  116. }
  117. return maxlen;
  118. }
  119. void packagelist::setwidths() {
  120. if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
  121. if (verbose) {
  122. status_hold_width= 9;
  123. status_status_width= maximumstring(statusstrings);
  124. status_want_width= maximumstring(wantstrings);
  125. status_width= status_hold_width+status_status_width+status_want_width*2+3;
  126. priority_width= 8;
  127. package_width= 16;
  128. } else {
  129. status_width= 4;
  130. priority_width= 3;
  131. package_width= 12;
  132. }
  133. section_width= 8;
  134. gap_width= 1;
  135. if (sortorder == so_section) {
  136. section_column= status_width + gap_width;
  137. priority_column= section_column + section_width + gap_width;
  138. package_column= priority_column + priority_width + gap_width;
  139. } else {
  140. priority_column= status_width + gap_width;
  141. section_column= priority_column + priority_width + gap_width;
  142. package_column= section_column + section_width + gap_width;
  143. }
  144. int versiondescriptioncolumn= package_column + package_width + gap_width;
  145. switch (versiondisplayopt) {
  146. case vdo_none:
  147. versioninstalled_column= versioninstalled_width= 0;
  148. versionavailable_column= versionavailable_width= 0;
  149. description_column= versiondescriptioncolumn;
  150. break;
  151. case vdo_available:
  152. versioninstalled_column= versioninstalled_width= 0;
  153. versionavailable_column= versiondescriptioncolumn;
  154. versionavailable_width= 11;
  155. description_column= versionavailable_column + versionavailable_width + gap_width;
  156. break;
  157. case vdo_both:
  158. versioninstalled_column= versiondescriptioncolumn;
  159. versioninstalled_width= 11;
  160. versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
  161. versionavailable_width= versioninstalled_width;
  162. description_column= versionavailable_column + versionavailable_width + gap_width;
  163. break;
  164. default:
  165. internerr("unknown versiondisplayopt in setwidths");
  166. }
  167. total_width= TOTAL_LIST_WIDTH;
  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. }