pkgtop.cc 10 KB

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