po: Update German man pages translation
[dpkg.git] / dselect / pkgtop.cc
blobb904fb5698c1e4f64b9c88beb112a89d8160311b
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 <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
22 #include <config.h>
23 #include <compat.h>
25 #include <string.h>
26 #include <stdio.h>
28 #include <dpkg/i18n.h>
29 #include <dpkg/c-ctype.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 == PKG_PRIO_UNSET) {
40 return nullptr;
41 } else if (pkg->priority == PKG_PRIO_OTHER) {
42 return pkg->otherpriority;
43 } else {
44 if (pkg->priority > PKG_PRIO_UNKNOWN)
45 internerr("package %s has out-of-range priority %d",
46 pkg_name_const(pkg, pnaw_always), pkg->priority);
47 return gettext(prioritystrings[pkg->priority]);
51 int packagelist::describemany(char buf[], const char *prioritystring,
52 const char *section,
53 const struct perpackagestate *pps) {
54 const char *ssostring, *ssoabbrev;
55 int statindent;
57 statindent= 0;
58 ssostring = nullptr;
59 ssoabbrev= _("All");
60 switch (statsortorder) {
61 case sso_avail:
62 if (pps->ssavail == ssa_none)
63 break;
64 ssostring= ssastrings[pps->ssavail];
65 ssoabbrev= ssaabbrevs[pps->ssavail];
66 statindent++;
67 break;
68 case sso_state:
69 if (pps->ssstate == sss_none)
70 break;
71 ssostring= sssstrings[pps->ssstate];
72 ssoabbrev= sssabbrevs[pps->ssstate];
73 statindent++;
74 break;
75 case sso_unsorted:
76 break;
77 default:
78 internerr("unknown statsortrder %d", statsortorder);
81 if (!prioritystring) {
82 if (!section) {
83 strcpy(buf, ssostring ? gettext(ssostring) : _("All packages"));
84 return statindent;
85 } else {
86 if (!*section) {
87 sprintf(buf,_("%s packages without a section"),gettext(ssoabbrev));
88 } else {
89 sprintf(buf,_("%s packages in section %s"),gettext(ssoabbrev),section);
91 return statindent+1;
93 } else {
94 if (!section) {
95 sprintf(buf,_("%s %s packages"),gettext(ssoabbrev),prioritystring);
96 return statindent+1;
97 } else {
98 if (!*section) {
99 sprintf(buf,_("%s %s packages without a section"),gettext(ssoabbrev),prioritystring);
100 } else {
101 sprintf(buf,_("%s %s packages in section %s"),gettext(ssoabbrev),prioritystring,section);
103 return statindent+2;
108 void packagelist::redrawthisstate() {
109 if (!thisstate_height) return;
110 mywerase(thisstatepad);
112 const char *section= table[cursorline]->pkg->section;
113 const char *priority= pkgprioritystring(table[cursorline]->pkg);
114 char *buf= new char[500+
115 max((table[cursorline]->pkg->set->name ?
116 strlen(table[cursorline]->pkg->set->name) : 0),
117 (section ? strlen(section) : 0) +
118 (priority ? strlen(priority) : 0))];
120 if (table[cursorline]->pkg->set->name) {
121 sprintf(buf,
122 _("%-*s %s%s%s; %s (was: %s). %s"),
123 col_package.width,
124 table[cursorline]->pkg->set->name,
125 gettext(statusstrings[table[cursorline]->pkg->status]),
126 ((eflagstrings[table[cursorline]->pkg->eflag][0]==' ') &&
127 (eflagstrings[table[cursorline]->pkg->eflag][1]=='\0')) ? "" : " - ",
128 gettext(eflagstrings[table[cursorline]->pkg->eflag]),
129 gettext(wantstrings[table[cursorline]->selected]),
130 gettext(wantstrings[table[cursorline]->original]),
131 priority);
132 } else {
133 describemany(buf,priority,section,table[cursorline]->pkg->clientdata);
135 mvwaddnstr(thisstatepad,0,0, buf, total_width);
136 pnoutrefresh(thisstatepad, 0,leftofscreen, thisstate_row,0,
137 thisstate_row, min(total_width - 1, xmax - 1));
139 delete[] buf;
142 void packagelist::redraw1itemsel(int index, int selected) {
143 int i;
144 const char *p;
145 const struct pkginfo *pkg= table[index]->pkg;
146 int screenline = index - topofscreen;
148 wattrset(listpad, part_attr[selected ? listsel : list]);
150 if (pkg->set->name) {
151 if (verbose) {
152 draw_column_item(col_status_hold, screenline,
153 gettext(eflagstrings[pkg->eflag]));
155 draw_column_sep(col_status_status, screenline);
156 draw_column_item(col_status_status, screenline,
157 gettext(statusstrings[pkg->status]));
159 draw_column_sep(col_status_old_want, screenline);
160 draw_column_item(col_status_old_want, screenline,
161 /* FIXME: keep this? */
162 /*table[index]->original == table[index]->selected ? "(same)"
163 : */gettext(wantstrings[table[index]->original]));
165 draw_column_sep(col_status_new_want, screenline);
166 wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
167 draw_column_item(col_status_new_want, screenline,
168 gettext(wantstrings[table[index]->selected]));
170 wattrset(listpad, part_attr[selected ? listsel : list]);
172 draw_column_sep(col_priority, screenline);
173 draw_column_item(col_priority, screenline,
174 pkg->priority == PKG_PRIO_OTHER ?
175 pkg->otherpriority :
176 gettext(prioritystrings[pkg->priority]));
177 } else {
178 mvwaddch(listpad, screenline, 0, eflagchars[pkg->eflag]);
179 waddch(listpad, statuschars[pkg->status]);
180 waddch(listpad,
181 /* FIXME: keep this feature? */
182 /*table[index]->original == table[index]->selected ? ' '
183 : */wantchars[table[index]->original]);
185 wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
186 waddch(listpad, wantchars[table[index]->selected]);
187 wattrset(listpad, part_attr[selected ? listsel : list]);
189 wmove(listpad, screenline, col_priority.x - 1);
190 waddch(listpad, ' ');
191 if (pkg->priority == PKG_PRIO_OTHER) {
192 for (i = col_priority.width, p = pkg->otherpriority;
193 i > 0 && *p;
194 i--, p++)
195 waddch(listpad, c_tolower(*p));
196 while (i-- > 0) waddch(listpad,' ');
197 } else {
198 wprintw(listpad, "%-*.*s", col_priority.width, col_priority.width,
199 gettext(priorityabbrevs[pkg->priority]));
203 draw_column_sep(col_section, screenline);
204 draw_column_item(col_section, screenline,
205 pkg->section ? pkg->section : "?");
207 draw_column_sep(col_package, screenline);
208 draw_column_item(col_package, screenline,
209 pkg->set->name);
211 waddch(listpad, ' ');
213 if (col_archinstalled.width) {
214 draw_column_sep(col_archinstalled, screenline);
215 draw_column_item(col_archinstalled, screenline, pkg->installed.arch->name);
217 waddch(listpad, ' ');
219 if (col_archavailable.width) {
220 draw_column_sep(col_archavailable, screenline);
221 draw_column_item(col_archavailable, screenline, pkg->available.arch->name);
223 waddch(listpad, ' ');
226 if (col_versioninstalled.width) {
227 draw_column_item(col_versioninstalled, screenline,
228 versiondescribe(&pkg->installed.version, vdew_nonambig));
229 waddch(listpad, ' ');
231 if (col_versionavailable.width) {
232 if (dpkg_version_is_informative(&pkg->available.version) &&
233 dpkg_version_compare(&pkg->available.version,
234 &pkg->installed.version) > 0)
235 wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
236 draw_column_item(col_versionavailable, screenline,
237 versiondescribe(&pkg->available.version, vdew_nonambig));
238 wattrset(listpad, part_attr[selected ? listsel : list]);
239 waddch(listpad,' ');
242 i = col_description.width;
243 p = pkg->available.description ? pkg->available.description :
244 pkg->installed.description ? pkg->installed.description : "";
245 while (i>0 && *p && *p != '\n') { waddnstr(listpad,p,1); i--; p++; }
246 } else {
247 int j, indent;
248 const char *section= pkg->section;
249 const char *priority= pkgprioritystring(pkg);
251 char *buf= new char[500+
252 (section ? strlen(section) : 0) +
253 (priority ? strlen(priority) : 0)];
255 indent= describemany(buf,priority,section,pkg->clientdata);
257 mvwaddstr(listpad, screenline, 0, " ");
258 i= total_width-7;
259 j= (indent<<1) + 1;
260 while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
261 waddch(listpad,' ');
263 wattrset(listpad, part_attr[selected ? selstatesel : selstate]);
264 p= buf;
265 while (i>0 && *p) { waddnstr(listpad, p,1); p++; i--; }
266 wattrset(listpad, part_attr[selected ? listsel : list]);
268 waddch(listpad,' ');
269 j= (indent<<1) + 1;
270 while (j-- >0) { waddch(listpad,ACS_HLINE); i--; }
272 delete[] buf;
275 while (i>0) { waddch(listpad,' '); i--; }
278 void packagelist::redrawcolheads() {
279 if (colheads_height) {
280 wattrset(colheadspad, part_attr[colheads]);
281 mywerase(colheadspad);
282 if (verbose) {
283 wmove(colheadspad,0,0);
284 for (int i = 0; i < col_status_old_want.width; i++)
285 waddch(colheadspad, '.');
286 draw_column_head(col_status_hold);
287 draw_column_head(col_status_status);
288 draw_column_head(col_status_old_want);
289 draw_column_head(col_status_new_want);
290 } else {
291 draw_column_head(col_status);
294 draw_column_head(col_section);
295 draw_column_head(col_priority);
296 draw_column_head(col_package);
298 if (col_archinstalled.width)
299 draw_column_head(col_archinstalled);
300 if (col_archavailable.width)
301 draw_column_head(col_archavailable);
303 if (col_versioninstalled.width)
304 draw_column_head(col_versioninstalled);
305 if (col_versionavailable.width)
306 draw_column_head(col_versionavailable);
308 draw_column_head(col_description);
310 refreshcolheads();