methlist.cc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <curses.h>
  24. #include <assert.h>
  25. #include <signal.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::setwidths() {
  46. if (debug) fprintf(debug,"methodlist[%p]::setwidths()\n",this);
  47. status_width= 1;
  48. gap_width= 1;
  49. name_width= 14;
  50. name_column= status_width + gap_width;
  51. description_column= name_column + name_width + gap_width;
  52. total_width= TOTAL_LIST_WIDTH;
  53. description_width= total_width - description_column;
  54. }
  55. void methodlist::redrawtitle() {
  56. if (title_height) {
  57. mywerase(titlewin);
  58. mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
  59. wnoutrefresh(titlewin);
  60. }
  61. }
  62. void methodlist::redrawthisstate() {
  63. if (!thisstate_height) return;
  64. mywerase(thisstatepad);
  65. wprintw(thisstatepad,
  66. _("Access method `%s'."),
  67. table[cursorline]->name);
  68. pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
  69. thisstate_row, lesserint(total_width - 1, xmax - 1));
  70. }
  71. void methodlist::redraw1itemsel(int index, int selected) {
  72. int i;
  73. const char *p;
  74. wattrset(listpad, selected ? listsel_attr : list_attr);
  75. mvwaddch(listpad,index,0,
  76. table[index] == coption ? '*' : ' ');
  77. wattrset(listpad, selected ? listsel_attr : list_attr);
  78. mvwprintw(listpad,index,name_column-1, " %-*.*s ",
  79. name_width, name_width, table[index]->name);
  80. i= description_width;
  81. p= table[index]->summary ? table[index]->summary : "";
  82. while (i>0 && *p && *p != '\n') {
  83. waddch(listpad,*p);
  84. i--; p++;
  85. }
  86. while (i>0) {
  87. waddch(listpad,' ');
  88. i--;
  89. }
  90. }
  91. void methodlist::redrawcolheads() {
  92. if (colheads_height) {
  93. wattrset(colheadspad,colheads_attr);
  94. mywerase(colheadspad);
  95. mvwaddstr(colheadspad,0,0, " ");
  96. mvwaddnstr(colheadspad,0,name_column, _("Abbrev."), name_width);
  97. mvwaddnstr(colheadspad,0,description_column, _("Description"), description_width);
  98. }
  99. refreshcolheads();
  100. }
  101. methodlist::methodlist() : baselist(&methodlistbindings) {
  102. int newcursor= -1;
  103. if (debug)
  104. fprintf(debug,"methodlist[%p]::methodlist()\n",this);
  105. table= new struct option*[noptions];
  106. struct option *opt, **ip;
  107. for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
  108. if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
  109. *ip++= opt;
  110. }
  111. assert(nitems==noptions);
  112. if (newcursor==-1) newcursor= 0;
  113. setcursor(newcursor);
  114. if (debug)
  115. fprintf(debug,"methodlist[%p]::methodlist done; noptions=%d\n", this, noptions);
  116. }
  117. methodlist::~methodlist() {
  118. if (debug) fprintf(debug,"methodlist[%p]::~methodlist()\n",this);
  119. delete[] table;
  120. }
  121. quitaction methodlist::display() {
  122. int response;
  123. const keybindings::interpretation *interp;
  124. if (debug) fprintf(debug,"methodlist[%p]::display()\n",this);
  125. setupsigwinch();
  126. startdisplay();
  127. if (debug) fprintf(debug,"methodlist[%p]::display() entering loop\n",this);
  128. for (;;) {
  129. if (whatinfo_height) wcursyncup(whatinfowin);
  130. if (doupdate() == ERR) ohshite(_("doupdate failed"));
  131. signallist= this;
  132. if (sigprocmask(SIG_UNBLOCK,&sigwinchset,0)) ohshite(_("failed to unblock SIGWINCH"));
  133. response= getch();
  134. if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite(_("failed to re-block SIGWINCH"));
  135. if (response == ERR) ohshite(_("getch failed"));
  136. interp= (*bindings)(response);
  137. if (debug)
  138. fprintf(debug,"methodlist[%p]::display() response=%d interp=%s\n",
  139. this,response, interp ? interp->action : _("[none]"));
  140. if (!interp) { beep(); continue; }
  141. (this->*(interp->mfn))();
  142. if (interp->qa != qa_noquit) break;
  143. }
  144. pop_cleanup(ehflag_normaltidy); // unset the SIGWINCH handler
  145. enddisplay();
  146. if (debug) fprintf(debug,"methodlist[%p]::display() done\n",this);
  147. return interp->qa;
  148. }
  149. void methodlist::itd_description() {
  150. whatinfovb(_("explanation of "));
  151. whatinfovb(table[cursorline]->name);
  152. wattrset(infopad,info_headattr);
  153. waddstr(infopad, table[cursorline]->name);
  154. waddstr(infopad," - ");
  155. waddstr(infopad, table[cursorline]->summary);
  156. wattrset(infopad,info_attr);
  157. const char *m= table[cursorline]->description;
  158. if (!m || !*m) m= _("No explanation available.");
  159. waddstr(infopad,"\n\n");
  160. wordwrapinfo(0,m);
  161. }
  162. void methodlist::redrawinfo() {
  163. if (!info_height) return;
  164. whatinfovb.reset();
  165. werase(infopad); wmove(infopad,0,0);
  166. if (debug) fprintf(debug,"methodlist[%p]::redrawinfo()\n", this);
  167. itd_description();
  168. whatinfovb.terminate();
  169. int y,x;
  170. getyx(infopad, y,x);
  171. if (x) y++;
  172. infolines= y;
  173. refreshinfo();
  174. }
  175. const struct helpmenuentry *methodlist::helpmenulist() {
  176. static const struct helpmenuentry list[]= {
  177. { 'i', &hlp_methintro },
  178. { 'k', &hlp_methkeys },
  179. { 0 }
  180. };
  181. return list;
  182. };