methlist.cc 6.1 KB

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