pkgdisplay.cc 8.4 KB

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