methlist.cc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * methlist.cc - list of access methods and options
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2001 Wichert Akkerman <wakkerma@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
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * 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 <http://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <assert.h>
  24. #include <errno.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <dpkg/i18n.h>
  28. #include <dpkg/dpkg.h>
  29. #include <dpkg/dpkg-db.h>
  30. #include "dselect.h"
  31. #include "bindings.h"
  32. #include "method.h"
  33. #include "helpmsgs.h"
  34. static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
  35. const char *methodlist::itemname(int index) {
  36. return table[index]->name;
  37. }
  38. void methodlist::kd_abort() { }
  39. void methodlist::kd_quit() {
  40. if (debug) fprintf(debug,"methodlist[%p]::kd_quit() setting coption=%p\n",
  41. this, table[cursorline]);
  42. coption= table[cursorline];
  43. }
  44. void methodlist::setheights() {
  45. if (debug) fprintf(debug,"methodlist[%p]::setheights()\n",this);
  46. baselist::setheights();
  47. list_height++;
  48. }
  49. void methodlist::setwidths() {
  50. if (debug) fprintf(debug,"methodlist[%p]::setwidths()\n",this);
  51. status_width= 1;
  52. gap_width= 1;
  53. name_width= 14;
  54. name_column= status_width + gap_width;
  55. description_column= name_column + name_width + gap_width;
  56. total_width= TOTAL_LIST_WIDTH;
  57. if (total_width < COLS)
  58. total_width= COLS;
  59. description_width= total_width - description_column;
  60. }
  61. void methodlist::redrawtitle() {
  62. if (title_height) {
  63. mywerase(titlewin);
  64. mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
  65. wnoutrefresh(titlewin);
  66. }
  67. }
  68. void methodlist::redrawthisstate() {
  69. if (!thisstate_height) return;
  70. mywerase(thisstatepad);
  71. wprintw(thisstatepad,
  72. _("Access method `%s'."),
  73. table[cursorline]->name);
  74. pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
  75. thisstate_row, lesserint(total_width - 1, xmax - 1));
  76. }
  77. void methodlist::redraw1itemsel(int index, int selected) {
  78. int i;
  79. const char *p;
  80. wattrset(listpad, selected ? listsel_attr : list_attr);
  81. mvwaddch(listpad,index,0,
  82. table[index] == coption ? '*' : ' ');
  83. wattrset(listpad, selected ? listsel_attr : list_attr);
  84. mvwprintw(listpad,index,name_column-1, " %-*.*s ",
  85. name_width, name_width, table[index]->name);
  86. i= description_width;
  87. p= table[index]->summary ? table[index]->summary : "";
  88. while (i>0 && *p && *p != '\n') {
  89. waddch(listpad,*p);
  90. i--; p++;
  91. }
  92. while (i>0) {
  93. waddch(listpad,' ');
  94. i--;
  95. }
  96. }
  97. void methodlist::redrawcolheads() {
  98. if (colheads_height) {
  99. wattrset(colheadspad,colheads_attr);
  100. mywerase(colheadspad);
  101. mvwaddstr(colheadspad,0,0, " ");
  102. mvwaddnstr(colheadspad,0,name_column, _("Abbrev."), name_width);
  103. mvwaddnstr(colheadspad,0,description_column, _("Description"), description_width);
  104. }
  105. refreshcolheads();
  106. }
  107. methodlist::methodlist() : baselist(&methodlistbindings) {
  108. int newcursor= -1;
  109. if (debug)
  110. fprintf(debug,"methodlist[%p]::methodlist()\n",this);
  111. table= new struct dselect_option*[noptions];
  112. struct dselect_option *opt, **ip;
  113. for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
  114. if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
  115. *ip++= opt;
  116. }
  117. assert(nitems==noptions);
  118. if (newcursor==-1) newcursor= 0;
  119. setcursor(newcursor);
  120. if (debug)
  121. fprintf(debug,"methodlist[%p]::methodlist done; noptions=%d\n", this, noptions);
  122. }
  123. methodlist::~methodlist() {
  124. if (debug) fprintf(debug,"methodlist[%p]::~methodlist()\n",this);
  125. delete[] table;
  126. }
  127. quitaction methodlist::display() {
  128. int response;
  129. const keybindings::interpretation *interp;
  130. if (debug) fprintf(debug,"methodlist[%p]::display()\n",this);
  131. setupsigwinch();
  132. startdisplay();
  133. if (debug) fprintf(debug,"methodlist[%p]::display() entering loop\n",this);
  134. for (;;) {
  135. if (whatinfo_height) wcursyncup(whatinfowin);
  136. if (doupdate() == ERR) ohshite(_("doupdate failed"));
  137. signallist= this;
  138. if (sigprocmask(SIG_UNBLOCK,&sigwinchset,0)) ohshite(_("failed to unblock SIGWINCH"));
  139. do
  140. response= getch();
  141. while (response == ERR && errno == EINTR);
  142. if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite(_("failed to re-block SIGWINCH"));
  143. if (response == ERR) ohshite(_("getch failed"));
  144. interp= (*bindings)(response);
  145. if (debug)
  146. fprintf(debug,"methodlist[%p]::display() response=%d interp=%s\n",
  147. this,response, interp ? interp->action : "[none]");
  148. if (!interp) { beep(); continue; }
  149. (this->*(interp->mfn))();
  150. if (interp->qa != qa_noquit) break;
  151. }
  152. pop_cleanup(ehflag_normaltidy); // unset the SIGWINCH handler
  153. enddisplay();
  154. if (debug) fprintf(debug,"methodlist[%p]::display() done\n",this);
  155. return interp->qa;
  156. }
  157. void methodlist::itd_description() {
  158. whatinfovb(_("Explanation"));
  159. wattrset(infopad,info_headattr);
  160. waddstr(infopad, table[cursorline]->name);
  161. waddstr(infopad," - ");
  162. waddstr(infopad, table[cursorline]->summary);
  163. wattrset(infopad,info_attr);
  164. const char *m= table[cursorline]->description;
  165. if (!m || !*m) m= _("No explanation available.");
  166. waddstr(infopad,"\n\n");
  167. wordwrapinfo(0,m);
  168. }
  169. void methodlist::redrawinfo() {
  170. if (!info_height) return;
  171. whatinfovb.reset();
  172. werase(infopad); wmove(infopad,0,0);
  173. if (debug) fprintf(debug,"methodlist[%p]::redrawinfo()\n", this);
  174. itd_description();
  175. whatinfovb.terminate();
  176. int y,x;
  177. getyx(infopad, y,x);
  178. if (x) y++;
  179. infolines= y;
  180. refreshinfo();
  181. }
  182. const struct helpmenuentry *methodlist::helpmenulist() {
  183. static const struct helpmenuentry list[]= {
  184. { 'i', &hlp_methintro },
  185. { 'k', &hlp_methkeys },
  186. { 0 }
  187. };
  188. return list;
  189. };