Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | /* |
2 | * dselect - Debian package maintenance user interface | |
3 | * pkgdisplay.cc - package list display | |
4 | * | |
5 | * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk> | |
6 | * Copyright © 2006, 2008-2015 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 | ||
22 | #include <config.h> | |
23 | #include <compat.h> | |
24 | ||
25 | #include <string.h> | |
26 | #include <stdio.h> | |
27 | ||
28 | #include <dpkg/i18n.h> | |
29 | #include <dpkg/dpkg.h> | |
30 | #include <dpkg/dpkg-db.h> | |
31 | ||
32 | #include "dselect.h" | |
33 | #include "pkglist.h" | |
34 | ||
35 | /* These MUST be in the same order as the corresponding enums in dpkg-db.h */ | |
36 | const char | |
37 | *const wantstrings[]= { N_("new package"), | |
38 | N_("install"), | |
39 | N_("hold"), | |
40 | N_("remove"), | |
41 | N_("purge"), | |
42 | nullptr }, | |
43 | ||
44 | /* TRANSLATORS: The space is a trick to work around gettext which uses | |
45 | * the empty string to store information about the translation. DO NOT | |
46 | * CHANGE THAT IN A TRANSLATION! The code really relies on that being | |
47 | * a single space. */ | |
48 | *const eflagstrings[]= { N_(" "), | |
49 | N_("REINSTALL"), | |
50 | nullptr }, | |
51 | ||
52 | *const statusstrings[]= { N_("not installed"), | |
53 | N_("removed (configs remain)"), | |
54 | N_("half installed"), | |
55 | N_("unpacked (not set up)"), | |
56 | N_("half configured (config failed)"), | |
57 | N_("awaiting trigger processing"), | |
58 | N_("triggered"), | |
59 | N_("installed"), | |
60 | nullptr }, | |
61 | ||
62 | *const prioritystrings[]= { N_("Required"), | |
63 | N_("Important"), | |
64 | N_("Standard"), | |
65 | N_("Optional"), | |
66 | N_("Extra"), | |
67 | N_("Unclassified"), | |
68 | nullptr }, | |
69 | ||
70 | *const relatestrings[]= { N_("suggests"), | |
71 | N_("recommends"), | |
72 | N_("depends on"), | |
73 | N_("pre-depends on"), | |
74 | N_("breaks"), | |
75 | N_("conflicts with"), | |
76 | N_("provides"), | |
77 | N_("replaces"), | |
78 | N_("enhances"), | |
79 | nullptr }, | |
80 | ||
81 | *const priorityabbrevs[]= { N_("Req"), | |
82 | N_("Imp"), | |
83 | N_("Std"), | |
84 | N_("Opt"), | |
85 | N_("Xtr"), | |
86 | N_("bUG"), | |
87 | N_("?") }; | |
88 | ||
89 | const char statuschars[] = " -IUCWt*"; | |
90 | const char eflagchars[] = " R"; | |
91 | const char wantchars[]= "n*=-_"; | |
92 | ||
93 | /* These MUST be in the same order as the corresponding enums in pkglist.h */ | |
94 | const char | |
95 | *const ssaabbrevs[]= { N_("Broken"), | |
96 | N_("New"), | |
97 | N_("Upgradable"), | |
98 | N_("Obsolete/local"), | |
99 | N_("Installed"), | |
100 | N_("Available"), | |
101 | N_("Removed") }, | |
102 | *const ssastrings[]= { N_("Brokenly installed packages"), | |
103 | N_("Newly available packages"), | |
104 | N_("Upgradable packages"), | |
105 | N_("Obsolete and locally created packages"), | |
106 | N_("Installed packages"), | |
107 | N_("Available not installed packages"), | |
108 | N_("Removed and no longer available packages") }; | |
109 | ||
110 | const char | |
111 | *const sssstrings[]= { N_("Brokenly installed packages"), | |
112 | N_("Installed packages"), | |
113 | N_("Removed packages (configuration still present)"), | |
114 | N_("Purged packages and those never installed") }, | |
115 | *const sssabbrevs[]= { N_("Broken"), | |
116 | N_("Installed"), | |
117 | N_("Removed"), | |
118 | N_("Purged") }; | |
119 | ||
120 | static int maximumstring(const char *const *array) { | |
121 | int maxlen= 0; | |
122 | while (*array) { | |
123 | int l= strlen(gettext(*array)); | |
124 | const char *p= strchr(*array, '('); | |
125 | if (p && p > *array && *--p == ' ') l= p - *array; | |
126 | if (l > maxlen) maxlen= l; | |
127 | array++; | |
128 | } | |
129 | return maxlen; | |
130 | } | |
131 | ||
132 | void packagelist::setwidths() { | |
133 | debug(dbg_general, "packagelist[%p]::setwidths()", this); | |
134 | ||
135 | col_cur_x = 0; | |
136 | ||
137 | if (verbose) { | |
138 | add_column(col_status_hold, _("Error"), 9); | |
139 | add_column(col_status_status, _("Installed?"), maximumstring(statusstrings)); | |
140 | add_column(col_status_old_want, _("Old mark"), maximumstring(wantstrings)); | |
141 | add_column(col_status_new_want, _("Marked for"), maximumstring(wantstrings)); | |
142 | } else { | |
143 | add_column(col_status, _("EIOM"), 4); | |
144 | } | |
145 | ||
146 | if (sortorder == so_section) | |
147 | add_column(col_section, _("Section"), 8); | |
148 | add_column(col_priority, _("Priority"), verbose ? 8 : 3); | |
149 | if (sortorder != so_section) | |
150 | add_column(col_section, _("Section"), 8); | |
151 | ||
152 | add_column(col_package, _("Package"), verbose ? 16 : 12); | |
153 | ||
154 | switch (archdisplayopt) { | |
155 | case ado_none: | |
156 | col_archinstalled.blank(); | |
157 | col_archavailable.blank(); | |
158 | break; | |
159 | case ado_available: | |
160 | col_archinstalled.blank(); | |
161 | add_column(col_archavailable, _("Avail.arch"), verbose ? 14 : 10); | |
162 | break; | |
163 | case ado_both: | |
164 | add_column(col_archinstalled, _("Inst.arch"), verbose ? 14 : 10); | |
165 | add_column(col_archavailable, _("Avail.arch"), verbose ? 14 : 10); | |
166 | break; | |
167 | default: | |
168 | internerr("unknown archdisplayopt %d", archdisplayopt); | |
169 | } | |
170 | ||
171 | switch (versiondisplayopt) { | |
172 | case vdo_none: | |
173 | col_versioninstalled.blank(); | |
174 | col_versionavailable.blank(); | |
175 | break; | |
176 | case vdo_available: | |
177 | col_versioninstalled.blank(); | |
178 | add_column(col_versionavailable, _("Avail.ver"), 11); | |
179 | break; | |
180 | case vdo_both: | |
181 | add_column(col_versioninstalled, _("Inst.ver"), 11); | |
182 | add_column(col_versionavailable, _("Avail.ver"), 11); | |
183 | break; | |
184 | default: | |
185 | internerr("unknown versiondisplayopt %d", versiondisplayopt); | |
186 | } | |
187 | ||
188 | end_column(col_description, _("Description")); | |
189 | } | |
190 | ||
191 | void packagelist::redrawtitle() { | |
192 | int x, y DPKG_ATTR_UNUSED; | |
193 | ||
194 | if (title_height) { | |
195 | mywerase(titlewin); | |
196 | mvwaddnstr(titlewin,0,0, | |
197 | recursive ? _("dselect - recursive package listing") : | |
198 | modstatdb_get_status() == msdbrw_readonly ? | |
199 | _("dselect - inspection of package states") : | |
200 | _("dselect - main package listing"), | |
201 | xmax); | |
202 | getyx(titlewin,y,x); | |
203 | if (x < xmax) { | |
204 | switch (sortorder) { | |
205 | case so_section: | |
206 | switch (statsortorder) { | |
207 | case sso_unsorted: | |
208 | waddnstr(titlewin, _(" (by section)"), xmax-x); | |
209 | break; | |
210 | case sso_avail: | |
211 | waddnstr(titlewin, _(" (avail., section)"), xmax-x); | |
212 | break; | |
213 | case sso_state: | |
214 | waddnstr(titlewin, _(" (status, section)"), xmax-x); | |
215 | break; | |
216 | default: | |
217 | internerr("bad statsort %d on so_section", statsortorder); | |
218 | } | |
219 | break; | |
220 | case so_priority: | |
221 | switch (statsortorder) { | |
222 | case sso_unsorted: | |
223 | waddnstr(titlewin, _(" (by priority)"), xmax-x); | |
224 | break; | |
225 | case sso_avail: | |
226 | waddnstr(titlewin, _(" (avail., priority)"), xmax-x); | |
227 | break; | |
228 | case sso_state: | |
229 | waddnstr(titlewin, _(" (status, priority)"), xmax-x); | |
230 | break; | |
231 | default: | |
232 | internerr("bad statsort %d on so_priority", statsortorder); | |
233 | } | |
234 | break; | |
235 | case so_alpha: | |
236 | switch (statsortorder) { | |
237 | case sso_unsorted: | |
238 | waddnstr(titlewin, _(" (alphabetically)"), xmax-x); | |
239 | break; | |
240 | case sso_avail: | |
241 | waddnstr(titlewin, _(" (by availability)"), xmax-x); | |
242 | break; | |
243 | case sso_state: | |
244 | waddnstr(titlewin, _(" (by status)"), xmax-x); | |
245 | break; | |
246 | default: | |
247 | internerr("bad statsort %d on so_priority", statsortorder); | |
248 | } | |
249 | break; | |
250 | case so_unsorted: | |
251 | break; | |
252 | default: | |
253 | internerr("bad sort %d", sortorder); | |
254 | } | |
255 | } | |
256 | const char *helpstring; | |
257 | ||
258 | if (modstatdb_get_status() == msdbrw_write) | |
259 | helpstring = (verbose ? _(" mark:+/=/- terse:v help:?") | |
260 | : _(" mark:+/=/- verbose:v help:?")); | |
261 | else | |
262 | helpstring = (verbose ? _(" terse:v help:?") | |
263 | : _(" verbose:v help:?")); | |
264 | ||
265 | int l= strlen(helpstring); | |
266 | getyx(titlewin,y,x); | |
267 | if (xmax-l > 0) { | |
268 | mvwaddstr(titlewin,0,xmax-l, helpstring); | |
269 | } | |
270 | wnoutrefresh(titlewin); | |
271 | } | |
272 | } |