pkgtop.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate
  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 <stdio.h>
  23. #include <string.h>
  24. #include <assert.h>
  25. #include <ctype.h>
  26. #include <dpkg.h>
  27. #include <dpkg-db.h>
  28. #include "dselect.h"
  29. #include "pkglist.h"
  30. const char *pkgprioritystring(const struct pkginfo *pkg) {
  31. if (pkg->priority == pkginfo::pri_unset) {
  32. return 0;
  33. } else if (pkg->priority == pkginfo::pri_other) {
  34. return pkg->otherpriority;
  35. } else {
  36. assert(pkg->priority <= pkginfo::pri_unknown);
  37. return gettext(prioritystrings[pkg->priority]);
  38. }
  39. }
  40. int packagelist::describemany(char buf[], const char *prioritystring,
  41. const char *section,
  42. const struct perpackagestate *pps) {
  43. const char *ssostring, *ssoabbrev;
  44. int statindent;
  45. statindent= 0;
  46. ssostring= 0;
  47. ssoabbrev= _("All");
  48. switch (statsortorder) {
  49. case sso_avail:
  50. if (pps->ssavail == -1) break;
  51. ssostring= ssastrings[pps->ssavail];
  52. ssoabbrev= ssaabbrevs[pps->ssavail];
  53. statindent++;
  54. break;
  55. case sso_state:
  56. if (pps->ssstate == -1) break;
  57. ssostring= sssstrings[pps->ssstate];
  58. ssoabbrev= sssabbrevs[pps->ssstate];
  59. statindent++;
  60. break;
  61. case sso_unsorted:
  62. break;
  63. default:
  64. internerr("unknown statsortrder in describemany all");
  65. }
  66. if (!prioritystring) {
  67. if (!section) {
  68. strcpy(buf, ssostring ? gettext(ssostring) : _("All packages"));
  69. return statindent;
  70. } else {
  71. if (!*section) {
  72. sprintf(buf,_("%s packages without a section"),gettext(ssoabbrev));
  73. } else {
  74. sprintf(buf,_("%s packages in section %s"),gettext(ssoabbrev),section);
  75. }
  76. return statindent+1;
  77. }
  78. } else {
  79. if (!section) {
  80. sprintf(buf,_("%s %s packages"),gettext(ssoabbrev),prioritystring);
  81. return statindent+1;
  82. } else {
  83. if (!*section) {
  84. sprintf(buf,_("%s %s packages without a section"),gettext(ssoabbrev),prioritystring);
  85. } else {
  86. sprintf(buf,_("%s %s packages in section %s"),gettext(ssoabbrev),prioritystring,section);
  87. }
  88. return statindent+2;
  89. }
  90. }
  91. }
  92. void packagelist::redrawthisstate() {
  93. if (!thisstate_height) return;
  94. mywerase(thisstatepad);
  95. const char *section= table[cursorline]->pkg->section;
  96. const char *priority= pkgprioritystring(table[cursorline]->pkg);
  97. char *buf= new char[500+
  98. greaterint((table[cursorline]->pkg->name
  99. ? strlen(table[cursorline]->pkg->name) : 0),
  100. (section ? strlen(section) : 0) +
  101. (priority ? strlen(priority) : 0))];
  102. if (table[cursorline]->pkg->name) {
  103. sprintf(buf,
  104. _("%-*s %s%s%s; %s (was: %s). %s"),
  105. package_width,
  106. table[cursorline]->pkg->name,
  107. gettext(statusstrings[table[cursorline]->pkg->status]),
  108. ((eflagstrings[table[cursorline]->pkg->eflag][0]==' ') &&
  109. (eflagstrings[table[cursorline]->pkg->eflag][1]=='\0')) ? "" : " - ",
  110. gettext(eflagstrings[table[cursorline]->pkg->eflag]),
  111. gettext(wantstrings[table[cursorline]->selected]),
  112. gettext(wantstrings[table[cursorline]->original]),
  113. priority);
  114. } else {
  115. describemany(buf,priority,section,table[cursorline]->pkg->clientdata);
  116. }
  117. mvwaddnstr(thisstatepad,0,0, buf, total_width);
  118. pnoutrefresh(thisstatepad, 0,leftofscreen, thisstate_row,0,
  119. thisstate_row, lesserint(total_width - 1, xmax - 1));
  120. delete[] buf;
  121. }
  122. void packagelist::redraw1itemsel(int index, int selected) {
  123. int i, indent, j;
  124. const char *p;
  125. const struct pkginfo *pkg= table[index]->pkg;
  126. const struct pkginfoperfile *info= &pkg->available;
  127. int screenline = index - topofscreen;
  128. wattrset(listpad, selected ? listsel_attr : list_attr);
  129. if (pkg->name) {
  130. if (verbose) {
  131. mvwprintw(listpad, screenline, 0, "%-*.*s ",
  132. status_hold_width, status_hold_width,
  133. gettext(eflagstrings[pkg->eflag]));
  134. wprintw(listpad, "%-*.*s ",
  135. status_status_width, status_status_width,
  136. gettext(statusstrings[pkg->status]));
  137. wprintw(listpad, "%-*.*s ",
  138. status_want_width, status_want_width,
  139. /* FIXME: keep this? */
  140. /*table[index]->original == table[index]->selected ? "(same)"
  141. : */gettext(wantstrings[table[index]->original]));
  142. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  143. wprintw(listpad, "%-*.*s",
  144. status_want_width, status_want_width,
  145. gettext(wantstrings[table[index]->selected]));
  146. wattrset(listpad, selected ? listsel_attr : list_attr);
  147. waddch(listpad, ' ');
  148. mvwprintw(listpad, screenline, priority_column - 1, " %-*.*s",
  149. priority_width, priority_width,
  150. pkg->priority == pkginfo::pri_other ? pkg->otherpriority :
  151. gettext(prioritystrings[pkg->priority]));
  152. } else {
  153. mvwaddch(listpad, screenline, 0, eflagchars[pkg->eflag]);
  154. waddch(listpad, statuschars[pkg->status]);
  155. waddch(listpad,
  156. /* FIXME: keep this feature? */
  157. /*table[index]->original == table[index]->selected ? ' '
  158. : */wantchars[table[index]->original]);
  159. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  160. waddch(listpad, wantchars[table[index]->selected]);
  161. wattrset(listpad, selected ? listsel_attr : list_attr);
  162. wmove(listpad, screenline, priority_column - 1);
  163. waddch(listpad, ' ');
  164. if (pkg->priority == pkginfo::pri_other) {
  165. int i;
  166. const char *p;
  167. for (i=priority_width, p=pkg->otherpriority;
  168. i > 0 && *p;
  169. i--, p++)
  170. waddch(listpad, tolower(*p));
  171. while (i-- > 0) waddch(listpad,' ');
  172. } else {
  173. wprintw(listpad, "%-*.*s", priority_width, priority_width,
  174. gettext(priorityabbrevs[pkg->priority]));
  175. }
  176. }
  177. mvwprintw(listpad, screenline, section_column - 1, " %-*.*s",
  178. section_width, section_width,
  179. pkg->section ? pkg->section : "?");
  180. mvwprintw(listpad, screenline, package_column - 1, " %-*.*s ",
  181. package_width, package_width, pkg->name);
  182. if (versioninstalled_width)
  183. mvwprintw(listpad, screenline, versioninstalled_column, "%-*.*s ",
  184. versioninstalled_width, versioninstalled_width,
  185. versiondescribe(&pkg->installed.version, vdew_nonambig));
  186. if (versionavailable_width) {
  187. if (informativeversion(&pkg->available.version) &&
  188. versioncompare(&pkg->available.version,&pkg->installed.version) > 0)
  189. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  190. mvwprintw(listpad, screenline, versionavailable_column, "%-*.*s",
  191. versionavailable_width, versionavailable_width,
  192. versiondescribe(&pkg->available.version, vdew_nonambig));
  193. wattrset(listpad, selected ? listsel_attr : list_attr);
  194. waddch(listpad,' ');
  195. }
  196. i= description_width;
  197. p= info->description ? info->description :
  198. pkg->installed.description ? pkg->installed.description : "";
  199. while (i>0 && *p && *p != '\n') { waddnstr(listpad,p,1); i--; p++; }
  200. } else {
  201. const char *section= pkg->section;
  202. const char *priority= pkgprioritystring(pkg);
  203. char *buf= new char[500+
  204. (section ? strlen(section) : 0) +
  205. (priority ? strlen(priority) : 0)];
  206. indent= describemany(buf,priority,section,pkg->clientdata);
  207. mvwaddstr(listpad, screenline, 0, " ");
  208. i= total_width-7;
  209. j= (indent<<1) + 1;
  210. while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
  211. waddch(listpad,' ');
  212. wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
  213. p= buf;
  214. while (i>0 && *p) { waddnstr(listpad, p,1); p++; i--; }
  215. wattrset(listpad, selected ? listsel_attr : list_attr);
  216. waddch(listpad,' ');
  217. j= (indent<<1) + 1;
  218. while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
  219. delete[] buf;
  220. }
  221. while (i>0) { waddch(listpad,' '); i--; }
  222. }
  223. void packagelist::redrawcolheads() {
  224. if (colheads_height) {
  225. wattrset(colheadspad,colheads_attr);
  226. mywerase(colheadspad);
  227. if (verbose) {
  228. wmove(colheadspad,0,0);
  229. for (int i=0; i<status_width-status_want_width; i++) waddch(colheadspad,'.');
  230. mvwaddnstr(colheadspad,0,
  231. 0,
  232. _("Error"),
  233. status_hold_width);
  234. mvwaddnstr(colheadspad,0,
  235. status_hold_width+1,
  236. _("Installed?"),
  237. status_status_width);
  238. mvwaddnstr(colheadspad,0,
  239. status_hold_width+status_status_width+2,
  240. _("Old mark"),
  241. status_want_width);
  242. mvwaddnstr(colheadspad,0,
  243. status_hold_width+status_status_width+status_want_width+3,
  244. _("Marked for"),
  245. status_want_width);
  246. } else {
  247. mvwaddstr(colheadspad,0,0, _("EIOM"));
  248. }
  249. mvwaddnstr(colheadspad,0,section_column, _("Section"), section_width);
  250. mvwaddnstr(colheadspad,0,priority_column, _("Priority"), priority_width);
  251. mvwaddnstr(colheadspad,0,package_column, _("Package"), package_width);
  252. if (versioninstalled_width)
  253. mvwaddnstr(colheadspad,0,versioninstalled_column,
  254. _("Inst.ver"),versioninstalled_width);
  255. if (versionavailable_width)
  256. mvwaddnstr(colheadspad,0,versionavailable_column,
  257. _("Avail.ver"),versionavailable_width);
  258. mvwaddnstr(colheadspad,0,description_column, _("Description"), description_width);
  259. }
  260. refreshcolheads();
  261. }