Release 1.15.8
[dpkg.git] / dselect / pkgtop.cc
blob826877c76388d393824a2001b3718c3e9658bbd2
1 /*
2 * dselect - Debian package maintenance user interface
3 * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate
5 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but 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.
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/>.
21 #include <config.h>
22 #include <compat.h>
24 #include <assert.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <stdio.h>
29 #include <dpkg/i18n.h>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.h>
33 #include "dselect.h"
34 #include "pkglist.h"
36 static const char *
37 pkgprioritystring(const struct pkginfo *pkg)
39 if (pkg->priority == pkginfo::pri_unset) {
40 return 0;
41 } else if (pkg->priority == pkginfo::pri_other) {
42 return pkg->otherpriority;
43 } else {
44 assert(pkg->priority <= pkginfo::pri_unknown);
45 return gettext(prioritystrings[pkg->priority]);
49 int packagelist::describemany(char buf[], const char *prioritystring,
50 const char *section,
51 const struct perpackagestate *pps) {
52 const char *ssostring, *ssoabbrev;
53 int statindent;
55 statindent= 0;
56 ssostring= 0;
57 ssoabbrev= _("All");
58 switch (statsortorder) {
59 case sso_avail:
60 if (pps->ssavail == -1) break;
61 ssostring= ssastrings[pps->ssavail];
62 ssoabbrev= ssaabbrevs[pps->ssavail];
63 statindent++;
64 break;
65 case sso_state:
66 if (pps->ssstate == -1) break;
67 ssostring= sssstrings[pps->ssstate];
68 ssoabbrev= sssabbrevs[pps->ssstate];
69 statindent++;
70 break;
71 case sso_unsorted:
72 break;
73 default:
74 internerr("unknown statsortrder in describemany all");
77 if (!prioritystring) {
78 if (!section) {
79 strcpy(buf, ssostring ? gettext(ssostring) : _("All packages"));
80 return statindent;
81 } else {
82 if (!*section) {
83 sprintf(buf,_("%s packages without a section"),gettext(ssoabbrev));
84 } else {
85 sprintf(buf,_("%s packages in section %s"),gettext(ssoabbrev),section);
87 return statindent+1;
89 } else {
90 if (!section) {
91 sprintf(buf,_("%s %s packages"),gettext(ssoabbrev),prioritystring);
92 return statindent+1;
93 } else {
94 if (!*section) {
95 sprintf(buf,_("%s %s packages without a section"),gettext(ssoabbrev),prioritystring);
96 } else {
97 sprintf(buf,_("%s %s packages in section %s"),gettext(ssoabbrev),prioritystring,section);
99 return statindent+2;
104 void packagelist::redrawthisstate() {
105 if (!thisstate_height) return;
106 mywerase(thisstatepad);
108 const char *section= table[cursorline]->pkg->section;
109 const char *priority= pkgprioritystring(table[cursorline]->pkg);
110 char *buf= new char[500+
111 max((table[cursorline]->pkg->name ?
112 strlen(table[cursorline]->pkg->name) : 0),
113 (section ? strlen(section) : 0) +
114 (priority ? strlen(priority) : 0))];
116 if (table[cursorline]->pkg->name) {
117 sprintf(buf,
118 _("%-*s %s%s%s; %s (was: %s). %s"),
119 package_width,
120 table[cursorline]->pkg->name,
121 gettext(statusstrings[table[cursorline]->pkg->status]),
122 ((eflagstrings[table[cursorline]->pkg->eflag][0]==' ') &&
123 (eflagstrings[table[cursorline]->pkg->eflag][1]=='\0')) ? "" : " - ",
124 gettext(eflagstrings[table[cursorline]->pkg->eflag]),
125 gettext(wantstrings[table[cursorline]->selected]),
126 gettext(wantstrings[table[cursorline]->original]),
127 priority);
128 } else {
129 describemany(buf,priority,section,table[cursorline]->pkg->clientdata);
131 mvwaddnstr(thisstatepad,0,0, buf, total_width);
132 pnoutrefresh(thisstatepad, 0,leftofscreen, thisstate_row,0,
133 thisstate_row, min(total_width - 1, xmax - 1));
135 delete[] buf;
138 void packagelist::redraw1itemsel(int index, int selected) {
139 int i, indent, j;
140 const char *p;
141 const struct pkginfo *pkg= table[index]->pkg;
142 const struct pkginfoperfile *info= &pkg->available;
143 int screenline = index - topofscreen;
145 wattrset(listpad, selected ? listsel_attr : list_attr);
147 if (pkg->name) {
149 if (verbose) {
151 mvwprintw(listpad, screenline, 0, "%-*.*s ",
152 status_hold_width, status_hold_width,
153 gettext(eflagstrings[pkg->eflag]));
154 wprintw(listpad, "%-*.*s ",
155 status_status_width, status_status_width,
156 gettext(statusstrings[pkg->status]));
157 wprintw(listpad, "%-*.*s ",
158 status_want_width, status_want_width,
159 /* FIXME: keep this? */
160 /*table[index]->original == table[index]->selected ? "(same)"
161 : */gettext(wantstrings[table[index]->original]));
162 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
163 wprintw(listpad, "%-*.*s",
164 status_want_width, status_want_width,
165 gettext(wantstrings[table[index]->selected]));
166 wattrset(listpad, selected ? listsel_attr : list_attr);
167 waddch(listpad, ' ');
169 mvwprintw(listpad, screenline, priority_column - 1, " %-*.*s",
170 priority_width, priority_width,
171 pkg->priority == pkginfo::pri_other ? pkg->otherpriority :
172 gettext(prioritystrings[pkg->priority]));
174 } else {
176 mvwaddch(listpad, screenline, 0, eflagchars[pkg->eflag]);
177 waddch(listpad, statuschars[pkg->status]);
178 waddch(listpad,
179 /* FIXME: keep this feature? */
180 /*table[index]->original == table[index]->selected ? ' '
181 : */wantchars[table[index]->original]);
183 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
184 waddch(listpad, wantchars[table[index]->selected]);
185 wattrset(listpad, selected ? listsel_attr : list_attr);
187 wmove(listpad, screenline, priority_column - 1);
188 waddch(listpad, ' ');
189 if (pkg->priority == pkginfo::pri_other) {
190 int i;
191 const char *p;
192 for (i=priority_width, p=pkg->otherpriority;
193 i > 0 && *p;
194 i--, p++)
195 waddch(listpad, tolower(*p));
196 while (i-- > 0) waddch(listpad,' ');
197 } else {
198 wprintw(listpad, "%-*.*s", priority_width, priority_width,
199 gettext(priorityabbrevs[pkg->priority]));
204 mvwprintw(listpad, screenline, section_column - 1, " %-*.*s",
205 section_width, section_width,
206 pkg->section ? pkg->section : "?");
208 mvwprintw(listpad, screenline, package_column - 1, " %-*.*s ",
209 package_width, package_width, pkg->name);
211 if (versioninstalled_width)
212 mvwprintw(listpad, screenline, versioninstalled_column, "%-*.*s ",
213 versioninstalled_width, versioninstalled_width,
214 versiondescribe(&pkg->installed.version, vdew_nonambig));
215 if (versionavailable_width) {
216 if (informativeversion(&pkg->available.version) &&
217 versioncompare(&pkg->available.version,&pkg->installed.version) > 0)
218 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
219 mvwprintw(listpad, screenline, versionavailable_column, "%-*.*s",
220 versionavailable_width, versionavailable_width,
221 versiondescribe(&pkg->available.version, vdew_nonambig));
222 wattrset(listpad, selected ? listsel_attr : list_attr);
223 waddch(listpad,' ');
226 i= description_width;
227 p= info->description ? info->description :
228 pkg->installed.description ? pkg->installed.description : "";
229 while (i>0 && *p && *p != '\n') { waddnstr(listpad,p,1); i--; p++; }
231 } else {
233 const char *section= pkg->section;
234 const char *priority= pkgprioritystring(pkg);
236 char *buf= new char[500+
237 (section ? strlen(section) : 0) +
238 (priority ? strlen(priority) : 0)];
240 indent= describemany(buf,priority,section,pkg->clientdata);
242 mvwaddstr(listpad, screenline, 0, " ");
243 i= total_width-7;
244 j= (indent<<1) + 1;
245 while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
246 waddch(listpad,' ');
248 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
249 p= buf;
250 while (i>0 && *p) { waddnstr(listpad, p,1); p++; i--; }
251 wattrset(listpad, selected ? listsel_attr : list_attr);
253 waddch(listpad,' ');
254 j= (indent<<1) + 1;
255 while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
257 delete[] buf;
261 while (i>0) { waddch(listpad,' '); i--; }
264 void packagelist::redrawcolheads() {
265 if (colheads_height) {
266 wattrset(colheadspad,colheads_attr);
267 mywerase(colheadspad);
268 if (verbose) {
269 wmove(colheadspad,0,0);
270 for (int i=0; i<status_width-status_want_width; i++) waddch(colheadspad,'.');
271 mvwaddnstr(colheadspad,0,
273 _("Error"),
274 status_hold_width);
275 mvwaddnstr(colheadspad,0,
276 status_hold_width+1,
277 _("Installed?"),
278 status_status_width);
279 mvwaddnstr(colheadspad,0,
280 status_hold_width+status_status_width+2,
281 _("Old mark"),
282 status_want_width);
283 mvwaddnstr(colheadspad,0,
284 status_hold_width+status_status_width+status_want_width+3,
285 _("Marked for"),
286 status_want_width);
287 } else {
288 mvwaddstr(colheadspad,0,0, _("EIOM"));
290 mvwaddnstr(colheadspad,0,section_column, _("Section"), section_width);
291 mvwaddnstr(colheadspad,0,priority_column, _("Priority"), priority_width);
292 mvwaddnstr(colheadspad,0,package_column, _("Package"), package_width);
294 if (versioninstalled_width)
295 mvwaddnstr(colheadspad,0,versioninstalled_column,
296 _("Inst.ver"),versioninstalled_width);
297 if (versionavailable_width)
298 mvwaddnstr(colheadspad,0,versionavailable_column,
299 _("Avail.ver"),versionavailable_width);
301 mvwaddnstr(colheadspad,0,description_column, _("Description"), description_width);
303 refreshcolheads();