pkgtop.cc 10 KB

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