pkginfo.cc 5.4 KB

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