home *** CD-ROM | disk | FTP | other *** search
/ ftp.freefriends.org / ftp.freefriends.org.tar / ftp.freefriends.org / arnold / Source / mush.rstevens.tar.gz / mush.tar / misc_frame.c < prev    next >
C/C++ Source or Header  |  1990-05-03  |  8KB  |  301 lines

  1. /* @(#) misc_frame.c    (c) copyright    9/29/89 (Dan Heller) */
  2.  
  3. /*
  4.  * This file contains several functions which create dialog box frames
  5.  * for (currently) mail aliases and ignored headers.  Each dialog box
  6.  * has a list of some kind and a way to add or delete items from the
  7.  * list.  The list is a textsw which is updated (currently) by do_set().
  8.  * Public routines:
  9.  *    update_list_textsw(struct options **) updates the textsw list.
  10.  *    do_alias()    creates the alias dialog frame box
  11.  *    do_ignore()    creates the ignored headers dialog frame box
  12.  */
  13.  
  14. #include "mush.h"
  15.  
  16. extern Notify_value fkey_interposer();
  17.  
  18. /****************** Mail Aliases ********************/
  19.  
  20. Frame    alias_frame;
  21. Panel_item alias_msg, alias_name, alias_value, alias_list_textsw;
  22. static void set_alias();
  23.  
  24. Frame    ignore_frame;
  25. Panel_item ignore_msg, ignore_name, ignore_list_textsw;
  26. static Panel_setting set_ignore();
  27.  
  28. #define MY_FRAME_WIDTH    600
  29.  
  30. static void
  31. frame_help(item)
  32. Panel_item item;
  33. {
  34.     (void) help(0, panel_get(item, PANEL_CLIENT_DATA), tool_help);
  35. }
  36.  
  37. void
  38. update_list_textsw(list)
  39. struct options **list;
  40. {
  41.     Textsw save = pager_textsw;
  42.  
  43.     if (list == &aliases)
  44.     pager_textsw = alias_list_textsw;
  45.     else if (list == &ignore_hdr)
  46.     pager_textsw = ignore_list_textsw;
  47.     else
  48.     /* no textsw for this guy yet */
  49.     return;
  50.  
  51.     if (pager_textsw && !!window_get(pager_textsw, WIN_SHOW))
  52.     (void) do_set(*list, NULL);
  53.     pager_textsw = save;
  54. }
  55.  
  56. static void
  57. alias_done()
  58. {
  59.     window_destroy(alias_frame);
  60.     alias_frame = (Frame) 0;
  61. }
  62.  
  63. void
  64. do_aliases()
  65. {
  66.     Panel    panel;
  67.  
  68.     if (alias_frame) {
  69.     window_set(alias_frame, WIN_SHOW, TRUE, NULL);
  70.     return;
  71.     }
  72. #ifdef SUN_3_5
  73.     if (nopenfiles(0) < 5) {
  74.     print("Too many frames; close one first!\n");
  75.     return;
  76.     }
  77. #endif /* SUN_3_5 */
  78.  
  79.     alias_frame = window_create(tool, FRAME,
  80.     FRAME_SHOW_LABEL,    TRUE,
  81.     FRAME_LABEL,        "Mail Aliases",
  82.     FRAME_NO_CONFIRM,    TRUE,
  83.     FRAME_DONE_PROC,    alias_done,
  84.     WIN_SHOW,        TRUE,
  85.     WIN_WIDTH,        MY_FRAME_WIDTH,
  86.     NULL);
  87.  
  88.     panel = window_create(alias_frame, PANEL,
  89.     PANEL_WIDTH,        MY_FRAME_WIDTH,
  90.     NULL);
  91.     notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  92.  
  93.     panel_create_item(panel, PANEL_BUTTON,
  94.     PANEL_LABEL_IMAGE,
  95.         panel_button_image(panel, "Help", 4, mush_font),
  96.     PANEL_CLIENT_DATA,    "aliases",
  97.     PANEL_NOTIFY_PROC,    frame_help,
  98.     NULL);
  99.     panel_create_item(panel, PANEL_BUTTON,
  100.     PANEL_LABEL_IMAGE,
  101.         panel_button_image(panel, "Set", 3, mush_font),
  102.     PANEL_NOTIFY_PROC,    set_alias,
  103.     PANEL_CLIENT_DATA,    TRUE,
  104.     NULL);
  105.     panel_create_item(panel, PANEL_BUTTON,
  106.     PANEL_LABEL_IMAGE,
  107.         panel_button_image(panel, "Unset", 5, mush_font),
  108.     PANEL_NOTIFY_PROC,    set_alias,
  109.     PANEL_CLIENT_DATA,    FALSE,
  110.     NULL);
  111.  
  112.     alias_msg = panel_create_item(panel, PANEL_MESSAGE,
  113.     PANEL_LABEL_STRING,
  114.         "Type name of alias and address list and select <set> or <unset>",
  115.     NULL);
  116.  
  117.     alias_name = panel_create_item(panel, PANEL_TEXT,
  118.     PANEL_LABEL_STRING,    "Alias Name:",
  119.     PANEL_VALUE_DISPLAY_LENGTH, 60,
  120.     NULL);
  121.     alias_value = panel_create_item(panel, PANEL_TEXT,
  122.     PANEL_LABEL_STRING,    "Alias Address(es):",
  123.     PANEL_VALUE_DISPLAY_LENGTH, 60,
  124.     NULL);
  125.     window_fit_height(panel);
  126.  
  127.     alias_list_textsw = window_create(alias_frame, TEXTSW,
  128.     WIN_BELOW,            panel,
  129.     WIN_WIDTH,            MY_FRAME_WIDTH,
  130.     WIN_HEIGHT,            15 * l_height(),
  131. #ifdef SUN_4_0 /* SunOS 4.0+ */
  132.     TEXTSW_LINE_BREAK_ACTION,    TEXTSW_WRAP_AT_WORD,
  133. #else /* SUN_4_0 */
  134.     TEXTSW_LINE_BREAK_ACTION,    TEXTSW_WRAP_AT_CHAR,
  135. #endif /* SUN_4_0 */
  136.     NULL);
  137.     (void) notify_interpose_event_func(alias_list_textsw,
  138.     fkey_interposer, NOTIFY_SAFE);
  139.  
  140.     window_fit_height(alias_frame);
  141.     update_list_textsw(&aliases);
  142. }
  143.  
  144. static void
  145. set_alias(item)
  146. Panel_item item;
  147. {
  148.     int argc, set_it = (int)panel_get(item, PANEL_CLIENT_DATA);
  149.     char buf[BUFSIZ], **argv, *name, *value;
  150.  
  151.     name = panel_get_value(alias_name);
  152.     if (!*name) {
  153.     panel_set(alias_msg, PANEL_LABEL_STRING, "Need an alias name.", NULL);
  154.     return;
  155.     }
  156.     if (any(name, " \t")) {
  157.     panel_set(alias_msg,
  158.         PANEL_LABEL_STRING, "Alias name may not contain spaces.",
  159.         NULL);
  160.     return;
  161.     }
  162.     if (set_it) {
  163.     value = panel_get_value(alias_value);
  164.     if (!*value) {
  165.         panel_set(alias_msg,
  166.         PANEL_LABEL_STRING, "Specify alias address(es).",
  167.         NULL);
  168.         return;
  169.     }
  170.     sprintf(buf, "alias %s %s", name, value);
  171.     } else
  172.     sprintf(buf, "unalias %s", name);
  173.     if (!(argv = mk_argv(buf, &argc, TRUE)) || do_alias(argc, argv) == -1)
  174.     panel_set(alias_msg,
  175.         PANEL_LABEL_STRING, "Couldn't set alias.",
  176.         NULL);
  177.     else
  178.     panel_set(alias_msg,
  179.         PANEL_LABEL_STRING, "",
  180.         NULL);
  181.     panel_set_value(alias_name, "");
  182.     panel_set_value(alias_value, "");
  183.     free_vec(argv);
  184. }
  185.  
  186. /* int cuz it's also the callback for the text item */
  187. static Panel_setting
  188. set_ignore(item)
  189. Panel_item item;
  190. {
  191.     int argc, set_it = (int)panel_get(item, PANEL_CLIENT_DATA);
  192.     char buf[BUFSIZ], *name, **argv;
  193.  
  194.     name = panel_get_value(ignore_name);
  195.     if (!*name) {
  196.     panel_set(ignore_msg, PANEL_LABEL_STRING, "Missing header name.", NULL);
  197.     return PANEL_NONE;
  198.     }
  199.     if (set_it)
  200.     sprintf(buf, "ignore %s", name);
  201.     else
  202.     sprintf(buf, "unignore %s", name);
  203.     /* set() will call update_list_textsw() */
  204.     if (!(argv = mk_argv(buf, &argc, TRUE)) || set(argc, argv, NULL) == -1)
  205.     panel_set(ignore_msg,
  206.         PANEL_LABEL_STRING, "Internal Error!?",
  207.         NULL);
  208.     else
  209.     panel_set(ignore_msg,
  210.         PANEL_LABEL_STRING, "",
  211.         NULL);
  212.     free_vec(argv);
  213.     panel_set_value(ignore_name, "");
  214.     return PANEL_NONE;
  215. }
  216.  
  217. static void
  218. ignore_done()
  219. {
  220.     window_destroy(ignore_frame);
  221.     ignore_frame = (Frame) 0;
  222. }
  223.  
  224. void
  225. do_ignore()
  226. {
  227.     Panel    panel;
  228.  
  229.     if (ignore_frame) {
  230.     window_set(ignore_frame, WIN_SHOW, TRUE, NULL);
  231.     return;
  232.     }
  233. #ifdef SUN_3_5
  234.     if (nopenfiles(0) < 5) {
  235.     print("Too many frames; close one first!\n");
  236.     return;
  237.     }
  238. #endif /* SUN_3_5 */
  239.  
  240.     ignore_frame = window_create(tool, FRAME,
  241.     FRAME_SHOW_LABEL,    TRUE,
  242.     FRAME_LABEL,        "Ignored Headers",
  243.     FRAME_NO_CONFIRM,    TRUE,
  244.     FRAME_DONE_PROC,    ignore_done,
  245.     WIN_SHOW,        TRUE,
  246.     WIN_WIDTH,        MY_FRAME_WIDTH,
  247.     NULL);
  248.  
  249.     panel = window_create(ignore_frame, PANEL,
  250.     PANEL_WIDTH,        MY_FRAME_WIDTH,
  251.     NULL);
  252.     (void) notify_interpose_event_func(panel, fkey_interposer, NOTIFY_SAFE);
  253.     (void) panel_create_item(panel, PANEL_BUTTON,
  254.     PANEL_LABEL_IMAGE,    
  255.         panel_button_image(panel, "Help", 4, mush_font),
  256.     PANEL_NOTIFY_PROC,    frame_help,
  257.     PANEL_CLIENT_DATA,    "ignore",
  258.     NULL);
  259.     (void) panel_create_item(panel, PANEL_BUTTON,
  260.     PANEL_LABEL_IMAGE,    
  261.         panel_button_image(panel, "Set", 3, mush_font),
  262.     PANEL_NOTIFY_PROC,    set_ignore,
  263.     PANEL_CLIENT_DATA,    TRUE,
  264.     NULL);
  265.     panel_create_item(panel, PANEL_BUTTON,
  266.     PANEL_LABEL_IMAGE,    
  267.         panel_button_image(panel, "Unset", 5, mush_font),
  268.     PANEL_NOTIFY_PROC,    set_ignore,
  269.     PANEL_CLIENT_DATA,    FALSE,
  270.     NULL);
  271.  
  272.     ignore_msg = panel_create_item(panel, PANEL_MESSAGE,
  273.     PANEL_LABEL_STRING,
  274.         "Type name of header to ignore and then <set> or <unset>",
  275.     NULL);
  276.  
  277.     ignore_name = panel_create_item(panel, PANEL_TEXT,
  278.     PANEL_LABEL_STRING,    "Ignored Header:",
  279.     PANEL_NOTIFY_PROC,    set_ignore,
  280.     PANEL_CLIENT_DATA,    1,
  281.     PANEL_VALUE_DISPLAY_LENGTH, 60,
  282.     NULL);
  283.     window_fit_height(panel);
  284.  
  285.     ignore_list_textsw = window_create(ignore_frame, TEXTSW,
  286.     WIN_BELOW,        panel,
  287.     WIN_WIDTH,        MY_FRAME_WIDTH,
  288.     WIN_HEIGHT,        15 * l_height(),
  289. #ifdef SUN_4_0 /* SunOS 4.0+ */
  290.     TEXTSW_LINE_BREAK_ACTION,    TEXTSW_WRAP_AT_WORD,
  291. #else /* SUN_4_0 */
  292.     TEXTSW_LINE_BREAK_ACTION,    TEXTSW_WRAP_AT_CHAR,
  293. #endif /* SUN_4_0 */
  294.     NULL);
  295.     (void) notify_interpose_event_func(ignore_list_textsw,
  296.     fkey_interposer, NOTIFY_SAFE);
  297.  
  298.     window_fit_height(ignore_frame);
  299.     update_list_textsw(&ignore_hdr);
  300. }
  301.