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/>.
28 #include <dpkg/i18n.h>
29 #include <dpkg/c-ctype.h>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.h>
37 pkgprioritystring(const struct pkginfo
*pkg
)
39 if (pkg
->priority
== PKG_PRIO_UNSET
) {
41 } else if (pkg
->priority
== PKG_PRIO_OTHER
) {
42 return pkg
->otherpriority
;
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
,
53 const struct perpackagestate
*pps
) {
54 const char *ssostring
, *ssoabbrev
;
60 switch (statsortorder
) {
62 if (pps
->ssavail
== ssa_none
)
64 ssostring
= ssastrings
[pps
->ssavail
];
65 ssoabbrev
= ssaabbrevs
[pps
->ssavail
];
69 if (pps
->ssstate
== sss_none
)
71 ssostring
= sssstrings
[pps
->ssstate
];
72 ssoabbrev
= sssabbrevs
[pps
->ssstate
];
78 internerr("unknown statsortrder %d", statsortorder
);
81 if (!prioritystring
) {
83 strcpy(buf
, ssostring
? gettext(ssostring
) : _("All packages"));
87 sprintf(buf
,_("%s packages without a section"),gettext(ssoabbrev
));
89 sprintf(buf
,_("%s packages in section %s"),gettext(ssoabbrev
),section
);
95 sprintf(buf
,_("%s %s packages"),gettext(ssoabbrev
),prioritystring
);
99 sprintf(buf
,_("%s %s packages without a section"),gettext(ssoabbrev
),prioritystring
);
101 sprintf(buf
,_("%s %s packages in section %s"),gettext(ssoabbrev
),prioritystring
,section
);
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
) {
122 _("%-*s %s%s%s; %s (was: %s). %s"),
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
]),
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));
142 void packagelist::redraw1itemsel(int index
, int selected
) {
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
) {
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
?
176 gettext(prioritystrings
[pkg
->priority
]));
178 mvwaddch(listpad
, screenline
, 0, eflagchars
[pkg
->eflag
]);
179 waddch(listpad
, statuschars
[pkg
->status
]);
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
;
195 waddch(listpad
, c_tolower(*p
));
196 while (i
-- > 0) waddch(listpad
,' ');
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
,
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
]);
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
++; }
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, " ");
260 while (j
-- >0) { waddch(listpad
,ACS_HLINE
); i
--; }
263 wattrset(listpad
, part_attr
[selected
? selstatesel
: selstate
]);
265 while (i
>0 && *p
) { waddnstr(listpad
, p
,1); p
++; i
--; }
266 wattrset(listpad
, part_attr
[selected
? listsel
: list
]);
270 while (j
-- >0) { waddch(listpad
,ACS_HLINE
); i
--; }
275 while (i
>0) { waddch(listpad
,' '); i
--; }
278 void packagelist::redrawcolheads() {
279 if (colheads_height
) {
280 wattrset(colheadspad
, part_attr
[colheads
]);
281 mywerase(colheadspad
);
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
);
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
);