dpkg (1.2.12); priority=LOW
[dpkg.git] / dselect / pkgtop.cc
blob00d642fc2bc2532eda46fb63bbfd7019993b6de7
1 /*
2 * dselect - Debian GNU/Linux package maintenance user interface
3 * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate
5 * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.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
9 * published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
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.
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.
22 #include <stdio.h>
23 #include <string.h>
24 #include <ncurses.h>
25 #include <assert.h>
26 #include <signal.h>
27 #include <ctype.h>
29 extern "C" {
30 #include "config.h"
31 #include "dpkg.h"
32 #include "dpkg-db.h"
34 #include "dselect.h"
35 #include "pkglist.h"
37 const char *pkgprioritystring(const struct pkginfo *pkg) {
38 if (pkg->priority == pkginfo::pri_unset) {
39 return 0;
40 } else if (pkg->priority == pkginfo::pri_other) {
41 return pkg->otherpriority;
42 } else {
43 assert(pkg->priority <= pkginfo::pri_unknown);
44 return prioritystrings[pkg->priority];
48 int packagelist::describemany(char buf[], const char *prioritystring,
49 const char *section,
50 const struct perpackagestate *pps) {
51 const char *ssostring, *ssoabbrev;
52 int statindent;
54 statindent= 0;
55 ssostring= 0;
56 ssoabbrev= "All";
57 switch (statsortorder) {
58 case sso_avail:
59 if (pps->ssavail == -1) break;
60 ssostring= ssastrings[pps->ssavail];
61 ssoabbrev= ssaabbrevs[pps->ssavail];
62 statindent++;
63 break;
64 case sso_state:
65 if (pps->ssstate == -1) break;
66 ssostring= sssstrings[pps->ssstate];
67 ssoabbrev= sssabbrevs[pps->ssstate];
68 statindent++;
69 break;
70 case sso_unsorted:
71 break;
72 default:
73 internerr("unknown statsortrder in describemany all");
76 if (!prioritystring) {
77 if (!section) {
78 strcpy(buf, ssostring ? ssostring : "All packages");
79 return statindent;
80 } else {
81 if (!*section) {
82 sprintf(buf,"%s packages without a section",ssoabbrev);
83 } else {
84 sprintf(buf,"%s packages in section %s",ssoabbrev,section);
86 return statindent+1;
88 } else {
89 if (!section) {
90 sprintf(buf,"%s %s packages",ssoabbrev,prioritystring);
91 return statindent+1;
92 } else {
93 if (!*section) {
94 sprintf(buf,"%s %s packages without a section",ssoabbrev,prioritystring);
95 } else {
96 sprintf(buf,"%s %s packages in section %s",ssoabbrev,prioritystring,section);
98 return statindent+2;
103 void packagelist::redrawthisstate() {
104 if (!thisstate_height) return;
105 mywerase(thisstatepad);
107 const char *section= table[cursorline]->pkg->section;
108 const char *priority= pkgprioritystring(table[cursorline]->pkg);
109 char *buf= new char[500+
110 greaterint((table[cursorline]->pkg->name
111 ? strlen(table[cursorline]->pkg->name) : 0),
112 (section ? strlen(section) : 0) +
113 (priority ? strlen(priority) : 0))];
115 if (table[cursorline]->pkg->name) {
116 sprintf(buf,
117 "%-*s %s%s%s; %s (was: %s). %s",
118 package_width,
119 table[cursorline]->pkg->name,
120 statusstrings[table[cursorline]->pkg->status],
121 eflagstrings[table[cursorline]->pkg->eflag][0] ? " - " : "",
122 eflagstrings[table[cursorline]->pkg->eflag],
123 wantstrings[table[cursorline]->selected],
124 wantstrings[table[cursorline]->original],
125 priority);
126 } else {
127 describemany(buf,priority,section,table[cursorline]->pkg->clientdata);
129 mvwaddnstr(thisstatepad,0,0, buf, total_width);
130 pnoutrefresh(thisstatepad, 0,leftofscreen, thisstate_row,0,
131 thisstate_row, lesserint(total_width - 1, xmax - 1));
133 delete[] buf;
136 void packagelist::redraw1itemsel(int index, int selected) {
137 int i, indent, j;
138 const char *p;
139 const struct pkginfo *pkg= table[index]->pkg;
140 const struct pkginfoperfile *info= &pkg->available;
142 wattrset(listpad, selected ? listsel_attr : list_attr);
144 if (pkg->name) {
146 if (verbose) {
148 mvwprintw(listpad,index,0, "%-*.*s ",
149 status_hold_width, status_hold_width,
150 eflagstrings[pkg->eflag]);
151 wprintw(listpad, "%-*.*s ",
152 status_status_width, status_status_width,
153 statusstrings[pkg->status]);
154 wprintw(listpad, "%-*.*s ",
155 status_want_width, status_want_width,
156 /* fixme: keep this ? */
157 /*table[index]->original == table[index]->selected ? "(same)"
158 : */wantstrings[table[index]->original]);
159 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
160 wprintw(listpad, "%-*.*s",
161 status_want_width, status_want_width,
162 wantstrings[table[index]->selected]);
163 wattrset(listpad, selected ? listsel_attr : list_attr);
164 waddch(listpad, ' ');
166 mvwprintw(listpad,index,priority_column-1, " %-*.*s",
167 priority_width, priority_width,
168 pkg->priority == pkginfo::pri_other ? pkg->otherpriority :
169 prioritystrings[pkg->priority]);
171 } else {
173 mvwaddch(listpad,index,0, eflagchars[pkg->eflag]);
174 waddch(listpad, statuschars[pkg->status]);
175 waddch(listpad,
176 /* fixme: keep this feature? */
177 /*table[index]->original == table[index]->selected ? ' '
178 : */wantchars[table[index]->original]);
180 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
181 waddch(listpad, wantchars[table[index]->selected]);
182 wattrset(listpad, selected ? listsel_attr : list_attr);
184 wmove(listpad,index,priority_column-1); waddch(listpad,' ');
185 if (pkg->priority == pkginfo::pri_other) {
186 int i;
187 char *p;
188 for (i=priority_width, p=pkg->otherpriority;
189 i > 0 && *p;
190 i--, p++)
191 waddch(listpad, tolower(*p));
192 while (i-- > 0) waddch(listpad,' ');
193 } else {
194 wprintw(listpad, "%-*.*s", priority_width, priority_width,
195 priorityabbrevs[pkg->priority]);
200 mvwprintw(listpad,index,section_column-1, " %-*.*s",
201 section_width, section_width,
202 pkg->section ? pkg->section : "?");
204 mvwprintw(listpad,index,package_column-1, " %-*.*s ",
205 package_width, package_width, pkg->name);
207 if (versioninstalled_width)
208 mvwprintw(listpad,index,versioninstalled_column, "%-*.*s ",
209 versioninstalled_width, versioninstalled_width,
210 versiondescribe(&pkg->installed.version,vdew_never));
211 if (versionavailable_width) {
212 if (informativeversion(&pkg->available.version) &&
213 versioncompare(&pkg->available.version,&pkg->installed.version) > 0)
214 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
215 mvwprintw(listpad,index,versionavailable_column, "%-*.*s",
216 versionavailable_width, versionavailable_width,
217 versiondescribe(&pkg->available.version,vdew_never));
218 wattrset(listpad, selected ? listsel_attr : list_attr);
219 waddch(listpad,' ');
222 i= description_width;
223 p= info->description ? info->description : "";
224 while (i>0 && *p && *p != '\n') { waddch(listpad,*p); i--; p++; }
226 } else {
228 const char *section= pkg->section;
229 const char *priority= pkgprioritystring(pkg);
231 char *buf= new char[500+
232 (section ? strlen(section) : 0) +
233 (priority ? strlen(priority) : 0)];
235 indent= describemany(buf,priority,section,pkg->clientdata);
237 mvwaddstr(listpad,index,0, " ");
238 i= total_width-6;
239 j= (indent<<1) + 1;
240 while (j-- >0) { waddch(listpad,'-'); i--; }
241 waddch(listpad,' ');
243 wattrset(listpad, selected ? selstatesel_attr : selstate_attr);
244 p= buf;
245 while (i>0 && *p) { waddch(listpad, *p); p++; i--; }
246 wattrset(listpad, selected ? listsel_attr : list_attr);
248 waddch(listpad,' ');
249 j= (indent<<1) + 1;
250 while (j-- >0) { waddch(listpad,'-'); i--; }
252 delete[] buf;
256 while (i>0) { waddch(listpad,' '); i--; }
259 void packagelist::redrawcolheads() {
260 if (colheads_height) {
261 wattrset(colheadspad,colheads_attr);
262 mywerase(colheadspad);
263 if (verbose) {
264 wmove(colheadspad,0,0);
265 for (int i=0; i<status_width-status_want_width; i++) waddch(colheadspad,'.');
266 mvwaddnstr(colheadspad,0,
268 "Error",
269 status_hold_width);
270 mvwaddnstr(colheadspad,0,
271 status_hold_width+1,
272 "Installed?",
273 status_status_width);
274 mvwaddnstr(colheadspad,0,
275 status_hold_width+status_status_width+2,
276 "Old mark",
277 status_want_width);
278 mvwaddnstr(colheadspad,0,
279 status_hold_width+status_status_width+status_want_width+3,
280 "Marked for",
281 status_want_width);
282 } else {
283 mvwaddstr(colheadspad,0,0, "EIOM");
285 mvwaddnstr(colheadspad,0,section_column, "Section", section_width);
286 mvwaddnstr(colheadspad,0,priority_column, "Priority", priority_width);
287 mvwaddnstr(colheadspad,0,package_column, "Package", package_width);
289 if (versioninstalled_width)
290 mvwaddnstr(colheadspad,0,versioninstalled_column,
291 "Inst.ver",versioninstalled_width);
292 if (versionavailable_width)
293 mvwaddnstr(colheadspad,0,versionavailable_column,
294 "Avail.ver",versionavailable_width);
296 mvwaddnstr(colheadspad,0,description_column, "Description", description_width);
298 refreshcolheads();