pkgtop.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 <ijackson@chiark.greenend.org.uk>
  6. * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <assert.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <dpkg/i18n.h>
  27. #include <dpkg/c-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 == PKG_PRIO_UNSET) {
  36. return nullptr;
  37. } else if (pkg->priority == PKG_PRIO_OTHER) {
  38. return pkg->otherpriority;
  39. } else {
  40. assert(pkg->priority <= PKG_PRIO_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 = nullptr;
  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 %d", statsortorder);
  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. max((table[cursorline]->pkg->set->name ?
  103. strlen(table[cursorline]->pkg->set->name) : 0),
  104. (section ? strlen(section) : 0) +
  105. (priority ? strlen(priority) : 0))];
  106. if (table[cursorline]->pkg->set->name) {
  107. sprintf(buf,
  108. _("%-*s %s%s%s; %s (was: %s). %s"),
  109. col_package.width,
  110. table[cursorline]->pkg->set->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, min(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. int screenline = index - topofscreen;
  131. wattrset(listpad, part_attr[selected ? listsel : list]);
  132. if (pkg->set->name) {
  133. if (verbose) {
  134. draw_column_item(col_status_hold, screenline,
  135. gettext(eflagstrings[pkg->eflag]));
  136. draw_column_sep(col_status_status, screenline);
  137. draw_column_item(col_status_status, screenline,
  138. gettext(statusstrings[pkg->status]));
  139. draw_column_sep(col_status_old_want, screenline);
  140. draw_column_item(col_status_old_want, screenline,
  141. /* FIXME: keep this? */
  142. /*table[index]->original == table[index]->selected ? "(same)"
  143. : */gettext(wantstrings[table[index]->original]));
  144. draw_column_sep(col_status_new_want, screenline);
  145. wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
  146. draw_column_item(col_status_new_want, screenline,
  147. gettext(wantstrings[table[index]->selected]));
  148. wattrset(listpad, part_attr[selected ? listsel : list]);
  149. draw_column_sep(col_priority, screenline);
  150. draw_column_item(col_priority, screenline,
  151. pkg->priority == PKG_PRIO_OTHER ?
  152. pkg->otherpriority :
  153. gettext(prioritystrings[pkg->priority]));
  154. } else {
  155. mvwaddch(listpad, screenline, 0, eflagchars[pkg->eflag]);
  156. waddch(listpad, statuschars[pkg->status]);
  157. waddch(listpad,
  158. /* FIXME: keep this feature? */
  159. /*table[index]->original == table[index]->selected ? ' '
  160. : */wantchars[table[index]->original]);
  161. wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
  162. waddch(listpad, wantchars[table[index]->selected]);
  163. wattrset(listpad, part_attr[selected ? listsel : list]);
  164. wmove(listpad, screenline, col_priority.x - 1);
  165. waddch(listpad, ' ');
  166. if (pkg->priority == PKG_PRIO_OTHER) {
  167. for (i = col_priority.width, p = pkg->otherpriority;
  168. i > 0 && *p;
  169. i--, p++)
  170. waddch(listpad, c_tolower(*p));
  171. while (i-- > 0) waddch(listpad,' ');
  172. } else {
  173. wprintw(listpad, "%-*.*s", col_priority.width, col_priority.width,
  174. gettext(priorityabbrevs[pkg->priority]));
  175. }
  176. }
  177. draw_column_sep(col_section, screenline);
  178. draw_column_item(col_section, screenline,
  179. pkg->section ? pkg->section : "?");
  180. draw_column_sep(col_package, screenline);
  181. draw_column_item(col_package, screenline,
  182. pkg->set->name);
  183. waddch(listpad, ' ');
  184. if (col_archinstalled.width) {
  185. draw_column_sep(col_archinstalled, screenline);
  186. draw_column_item(col_archinstalled, screenline, pkg->installed.arch->name);
  187. waddch(listpad, ' ');
  188. }
  189. if (col_archavailable.width) {
  190. draw_column_sep(col_archavailable, screenline);
  191. draw_column_item(col_archavailable, screenline, pkg->available.arch->name);
  192. waddch(listpad, ' ');
  193. }
  194. if (col_versioninstalled.width) {
  195. draw_column_item(col_versioninstalled, screenline,
  196. versiondescribe(&pkg->installed.version, vdew_nonambig));
  197. waddch(listpad, ' ');
  198. }
  199. if (col_versionavailable.width) {
  200. if (dpkg_version_is_informative(&pkg->available.version) &&
  201. dpkg_version_compare(&pkg->available.version,
  202. &pkg->installed.version) > 0)
  203. wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
  204. draw_column_item(col_versionavailable, screenline,
  205. versiondescribe(&pkg->available.version, vdew_nonambig));
  206. wattrset(listpad, part_attr[selected ? listsel : list]);
  207. waddch(listpad,' ');
  208. }
  209. i = col_description.width;
  210. p = pkg->available.description ? pkg->available.description :
  211. pkg->installed.description ? pkg->installed.description : "";
  212. while (i>0 && *p && *p != '\n') { waddnstr(listpad,p,1); i--; p++; }
  213. } else {
  214. const char *section= pkg->section;
  215. const char *priority= pkgprioritystring(pkg);
  216. char *buf= new char[500+
  217. (section ? strlen(section) : 0) +
  218. (priority ? strlen(priority) : 0)];
  219. indent= describemany(buf,priority,section,pkg->clientdata);
  220. mvwaddstr(listpad, screenline, 0, " ");
  221. i= total_width-7;
  222. j= (indent<<1) + 1;
  223. while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
  224. waddch(listpad,' ');
  225. wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
  226. p= buf;
  227. while (i>0 && *p) { waddnstr(listpad, p,1); p++; i--; }
  228. wattrset(listpad, part_attr[selected ? listsel : list]);
  229. waddch(listpad,' ');
  230. j= (indent<<1) + 1;
  231. while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
  232. delete[] buf;
  233. }
  234. while (i>0) { waddch(listpad,' '); i--; }
  235. }
  236. void packagelist::redrawcolheads() {
  237. if (colheads_height) {
  238. wattrset(colheadspad, part_attr[colheads]);
  239. mywerase(colheadspad);
  240. if (verbose) {
  241. wmove(colheadspad,0,0);
  242. for (int i = 0; i < col_status_old_want.width; i++)
  243. waddch(colheadspad, '.');
  244. draw_column_head(col_status_hold);
  245. draw_column_head(col_status_status);
  246. draw_column_head(col_status_old_want);
  247. draw_column_head(col_status_new_want);
  248. } else {
  249. draw_column_head(col_status);
  250. }
  251. draw_column_head(col_section);
  252. draw_column_head(col_priority);
  253. draw_column_head(col_package);
  254. if (col_archinstalled.width)
  255. draw_column_head(col_archinstalled);
  256. if (col_archavailable.width)
  257. draw_column_head(col_archavailable);
  258. if (col_versioninstalled.width)
  259. draw_column_head(col_versioninstalled);
  260. if (col_versionavailable.width)
  261. draw_column_head(col_versionavailable);
  262. draw_column_head(col_description);
  263. }
  264. refreshcolheads();
  265. }