chiark / gitweb /
lib/dpkg/tarfn.c: Kludge `tar_header_decode' to handle spurious `errno'.
[dpkg] / dselect / pkginfo.cc
1 /*
2  * dselect - Debian package maintenance user interface
3  * pkginfo.cc - handles (re)draw of package list window infopad
4  *
5  * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6  *
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.
11  *
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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20
21 #include <config.h>
22 #include <compat.h>
23
24 #include <string.h>
25 #include <stdio.h>
26
27 #include <dpkg/i18n.h>
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
30 #include <dpkg/string.h>
31
32 #include "dselect.h"
33 #include "bindings.h"
34 #include "helpmsgs.h"
35
36 const struct helpmenuentry *packagelist::helpmenulist() {
37   static const struct helpmenuentry
38     rw[]= {
39       { 'i', &hlp_mainintro       },
40       { 'k', &hlp_listkeys        },
41       { 'l', &hlp_displayexplain1 },
42       { 'd', &hlp_displayexplain2 },
43       {  0                        }
44     },
45     ro[]= {
46       { 'i', &hlp_readonlyintro   },
47       { 'k', &hlp_listkeys        },
48       { 'l', &hlp_displayexplain1 },
49       { 'd', &hlp_displayexplain2 },
50       {  0                        }
51     },
52     recur[]= {
53       { 'i', &hlp_recurintro      },
54       { 'k', &hlp_listkeys        },
55       { 'l', &hlp_displayexplain1 },
56       { 'd', &hlp_displayexplain2 },
57       {  0                        }
58     };
59   return
60     modstatdb_get_status() == msdbrw_readonly ? ro :
61     !recursive ? rw :
62                  recur;
63 }
64
65 bool
66 packagelist::itr_recursive()
67 {
68   return recursive;
69 }
70
71 const packagelist::infotype packagelist::infoinfos[]= {
72   { &packagelist::itr_recursive, &packagelist::itd_relations         },
73   { nullptr,                     &packagelist::itd_description       },
74   { nullptr,                     &packagelist::itd_statuscontrol     },
75   { nullptr,                     &packagelist::itd_availablecontrol  },
76   { nullptr,                     nullptr                             }
77 };
78
79 const packagelist::infotype *const packagelist::baseinfo= infoinfos;
80
81 void packagelist::severalinfoblurb()
82 {
83   varbuf vb;
84   vb(_("The line you have highlighted represents many packages; "
85      "if you ask to install, remove, hold, etc. it you will affect all "
86      "the packages which match the criterion shown.\n"
87      "\n"
88      "If you move the highlight to a line for a particular package "
89      "you will see information about that package displayed here."
90      "\n"
91      "You can use 'o' and 'O' to change the sort order and give yourself "
92      "the opportunity to mark packages in different kinds of groups."));
93   wordwrapinfo(0,vb.string());
94 }
95
96 void packagelist::itd_relations() {
97   whatinfovb(_("Interrelationships"));
98
99   if (table[cursorline]->pkg->set->name) {
100     debug(dbg_general, "packagelist[%p]::idt_relations(); '%s'",
101           this, table[cursorline]->relations.string());
102     waddstr(infopad,table[cursorline]->relations.string());
103   } else {
104     severalinfoblurb();
105   }
106 }
107
108 void packagelist::itd_description() {
109   whatinfovb(_("Description"));
110
111   if (table[cursorline]->pkg->set->name) {
112     const char *m= table[cursorline]->pkg->available.description;
113     if (str_is_unset(m))
114       m = table[cursorline]->pkg->installed.description;
115     if (str_is_unset(m))
116       m = _("No description available.");
117     const char *p= strchr(m,'\n');
118     int l= p ? (int)(p-m) : strlen(m);
119     wattrset(infopad, part_attr[info_head]);
120     waddstr(infopad, table[cursorline]->pkg->set->name);
121     waddstr(infopad," - ");
122     waddnstr(infopad,m,l);
123     wattrset(infopad, part_attr[info_body]);
124     if (p) {
125       waddstr(infopad,"\n\n");
126       wordwrapinfo(1,++p);
127     }
128   } else {
129     severalinfoblurb();
130   }
131 }
132
133 void packagelist::itd_statuscontrol() {
134   whatinfovb(_("Installed control file information"));
135
136   werase(infopad);
137   if (!table[cursorline]->pkg->set->name) {
138     severalinfoblurb();
139   } else {
140     varbuf vb;
141     varbufrecord(&vb,table[cursorline]->pkg,&table[cursorline]->pkg->installed);
142     debug(dbg_general, "packagelist[%p]::idt_statuscontrol(); '%s'",
143           this, vb.string());
144     waddstr(infopad,vb.string());
145   }
146 }
147
148 void packagelist::itd_availablecontrol() {
149   whatinfovb(_("Available control file information"));
150
151   werase(infopad);
152   if (!table[cursorline]->pkg->set->name) {
153     severalinfoblurb();
154   } else {
155     varbuf vb;
156     varbufrecord(&vb,table[cursorline]->pkg,&table[cursorline]->pkg->available);
157     debug(dbg_general, "packagelist[%p]::idt_availablecontrol(); '%s'",
158           this, vb.string());
159     waddstr(infopad,vb.string());
160   }
161 }
162
163 void packagelist::redrawinfo() {
164   for (;;) {
165     if (!currentinfo || !currentinfo->display) currentinfo= baseinfo;
166     if (!currentinfo->relevant) break;
167     if ((this->*currentinfo->relevant)()) break;
168     currentinfo++;
169   }
170   if (!info_height) return;
171   whatinfovb.reset();
172   werase(infopad); wmove(infopad,0,0);
173
174   debug(dbg_general, "packagelist[%p]::redrawinfo(); #=%d",
175         this, (int)(currentinfo - baseinfo));
176
177   (this->*currentinfo->display)();
178
179   int y,x;
180   getyx(infopad, y,x);
181   if (x) y++;
182   infolines= y;
183
184   refreshinfo();
185 }