methlist.cc 6.3 KB

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