methlist.cc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #include <stdio.h>
  23. #include <string.h>
  24. #include <assert.h>
  25. #include <errno.h>
  26. extern "C" {
  27. #include <config.h>
  28. #include <dpkg.h>
  29. #include <dpkg-db.h>
  30. }
  31. #include "dselect.h"
  32. #include "bindings.h"
  33. #include "method.h"
  34. #include "helpmsgs.h"
  35. static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
  36. const char *methodlist::itemname(int index) {
  37. return table[index]->name;
  38. }
  39. void methodlist::kd_abort() { }
  40. void methodlist::kd_quit() {
  41. if (debug) fprintf(debug,"methodlist[%p]::kd_quit() setting coption=%p\n",
  42. this, table[cursorline]);
  43. coption= table[cursorline];
  44. }
  45. void methodlist::setheights() {
  46. if (debug) fprintf(debug,"methodlist[%p]::setheights()\n",this);
  47. baselist::setheights();
  48. list_height++;
  49. }
  50. void methodlist::setwidths() {
  51. if (debug) fprintf(debug,"methodlist[%p]::setwidths()\n",this);
  52. status_width= 1;
  53. gap_width= 1;
  54. name_width= 14;
  55. name_column= status_width + gap_width;
  56. description_column= name_column + name_width + gap_width;
  57. total_width= TOTAL_LIST_WIDTH;
  58. description_width= total_width - description_column;
  59. }
  60. void methodlist::redrawtitle() {
  61. if (title_height) {
  62. mywerase(titlewin);
  63. mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
  64. wnoutrefresh(titlewin);
  65. }
  66. }
  67. void methodlist::redrawthisstate() {
  68. if (!thisstate_height) return;
  69. mywerase(thisstatepad);
  70. wprintw(thisstatepad,
  71. _("Access method `%s'."),
  72. table[cursorline]->name);
  73. pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
  74. thisstate_row, lesserint(total_width - 1, xmax - 1));
  75. }
  76. void methodlist::redraw1itemsel(int index, int selected) {
  77. int i;
  78. const char *p;
  79. wattrset(listpad, selected ? listsel_attr : list_attr);
  80. mvwaddch(listpad,index,0,
  81. table[index] == coption ? '*' : ' ');
  82. wattrset(listpad, selected ? listsel_attr : list_attr);
  83. mvwprintw(listpad,index,name_column-1, " %-*.*s ",
  84. name_width, name_width, table[index]->name);
  85. i= description_width;
  86. p= table[index]->summary ? table[index]->summary : "";
  87. while (i>0 && *p && *p != '\n') {
  88. waddch(listpad,*p);
  89. i--; p++;
  90. }
  91. while (i>0) {
  92. waddch(listpad,' ');
  93. i--;
  94. }
  95. }
  96. void methodlist::redrawcolheads() {
  97. if (colheads_height) {
  98. wattrset(colheadspad,colheads_attr);
  99. mywerase(colheadspad);
  100. mvwaddstr(colheadspad,0,0, " ");
  101. mvwaddnstr(colheadspad,0,name_column, _("Abbrev."), name_width);
  102. mvwaddnstr(colheadspad,0,description_column, _("Description"), description_width);
  103. }
  104. refreshcolheads();
  105. }
  106. methodlist::methodlist() : baselist(&methodlistbindings) {
  107. int newcursor= -1;
  108. if (debug)
  109. fprintf(debug,"methodlist[%p]::methodlist()\n",this);
  110. table= new struct dselect_option*[noptions];
  111. struct dselect_option *opt, **ip;
  112. for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
  113. if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
  114. *ip++= opt;
  115. }
  116. assert(nitems==noptions);
  117. if (newcursor==-1) newcursor= 0;
  118. setcursor(newcursor);
  119. if (debug)
  120. fprintf(debug,"methodlist[%p]::methodlist done; noptions=%d\n", this, noptions);
  121. }
  122. methodlist::~methodlist() {
  123. if (debug) fprintf(debug,"methodlist[%p]::~methodlist()\n",this);
  124. delete[] table;
  125. }
  126. quitaction methodlist::display() {
  127. int response;
  128. const keybindings::interpretation *interp;
  129. if (debug) fprintf(debug,"methodlist[%p]::display()\n",this);
  130. setupsigwinch();
  131. startdisplay();
  132. if (debug) fprintf(debug,"methodlist[%p]::display() entering loop\n",this);
  133. for (;;) {
  134. if (whatinfo_height) wcursyncup(whatinfowin);
  135. if (doupdate() == ERR) ohshite(_("doupdate failed"));
  136. signallist= this;
  137. if (sigprocmask(SIG_UNBLOCK,&sigwinchset,0)) ohshite(_("failed to unblock SIGWINCH"));
  138. do
  139. response= getch();
  140. while (response == ERR && errno == EINTR);
  141. if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite(_("failed to re-block SIGWINCH"));
  142. if (response == ERR) ohshite(_("getch failed"));
  143. interp= (*bindings)(response);
  144. if (debug)
  145. fprintf(debug,"methodlist[%p]::display() response=%d interp=%s\n",
  146. this,response, interp ? interp->action : _("[none]"));
  147. if (!interp) { beep(); continue; }
  148. (this->*(interp->mfn))();
  149. if (interp->qa != qa_noquit) break;
  150. }
  151. pop_cleanup(ehflag_normaltidy); // unset the SIGWINCH handler
  152. enddisplay();
  153. if (debug) fprintf(debug,"methodlist[%p]::display() done\n",this);
  154. return interp->qa;
  155. }
  156. void methodlist::itd_description() {
  157. whatinfovb(_("explanation of "));
  158. whatinfovb(table[cursorline]->name);
  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. };