pkgtop.cc 10 KB

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