home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / seyon197.tz / seyon197 / seyon / SeInit.c < prev    next >
C/C++ Source or Header  |  1993-02-20  |  16KB  |  483 lines

  1.  
  2. /*
  3.  * This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
  4.  * Saggaf. All rights reserved.
  5.  *
  6.  * See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
  7.  * statement of rights and permissions for this program.
  8.  */
  9.  
  10. #include <signal.h>
  11.  
  12. #include <fcntl.h>
  13.  
  14. #include <X11/Intrinsic.h>
  15. #include <X11/StringDefs.h>
  16. #include <X11/Shell.h>
  17. #include <X11/Xaw/Label.h>
  18. #include <X11/Xaw/Dialog.h>
  19.  
  20. #include "seyon.h"
  21. #include "SeDecl.h"
  22.  
  23. #ifndef HELPFILE
  24. #define HELPFILE "/usr/lib/X11/seyon.help"
  25. #endif
  26.  
  27. extern int      ConvertStringToIntArray();
  28. extern void     top_shell(),
  29.                 upload_acc_ok(),
  30.                 shell_acc_ok(),
  31.                 setVal_action_ok(),
  32.                 manual_dial_action_ok(),
  33.                 divert_action_ok(),
  34.                 script_action_ok(),
  35.                 topAbout(),
  36.                 topHelp(),
  37.                 top_misc(),
  38.                 SetNewlineTrMode(),
  39.                 FunMessage();
  40. extern Boolean  CvtStringToStringArray();
  41.  
  42. void            HangupConfirm(),
  43.                 ExecHangup(),
  44.                 ExitConfirm(),
  45.                 kill_w_child(),
  46.                 ExitAction(),
  47.                 test();
  48.  
  49. Boolean         inhibit_child = False;
  50. Widget          w_exit,
  51.                 w_kill,
  52.                 statusMessage;
  53. pid_t           w_child_pid = 0;
  54. int             defaultPhoneEntries[MAX_ENT];
  55. Pixmap          progIcon;
  56.  
  57. #include "progIcon.h"
  58.  
  59. void
  60. InitVariables(topLevel)
  61.      Widget          topLevel;
  62. {
  63.   char            buffer[REG_BUF];
  64.  
  65.   sprintf(captureFile, "%s/%s", expand_fname(qres.defaultDirectory, buffer),
  66.       qres.captureFile);
  67.  
  68.   SetNewlineTrMode(qres.newlineTranslation);
  69.   ConvertStringToIntArray(qres.defaultPhoneEntries, defaultPhoneEntries);
  70. }
  71.  
  72. void
  73. SetIcon(topLevel)
  74.      Widget          topLevel;
  75. {
  76.   progIcon = XCreateBitmapFromData(XtDisplay(topLevel),
  77.                    DefaultRootWindow(XtDisplay(topLevel)),
  78.                    progIcon_bits, progIcon_width,
  79.                    progIcon_height);
  80.   XtVaSetValues(topLevel, XtNiconPixmap, progIcon, NULL);
  81. }
  82.  
  83. Widget
  84. CreateCommandCenter(app_con, topLevelWidget)
  85.      XtAppContext    app_con;
  86.      Widget          topLevelWidget;
  87. {
  88.   Widget          mainBox,
  89.                   menuBox,
  90.   statusBox,
  91.                   messageBox,
  92.                   dial;
  93.   static Widget status[NUM_MDM_STAT];
  94.   void            (*callback) ();
  95.   static Atom     wm_delete_window;
  96.  
  97.   static XtActionsRec actionTable[] =
  98.   {
  99.     {"UploadOk", upload_acc_ok},
  100.     {"ShellOk", shell_acc_ok},
  101.     {"SetValOk", setVal_action_ok},
  102.     {"ManualDialOk", manual_dial_action_ok},
  103.     {"DivertOk", divert_action_ok},
  104.     {"ScriptOk", script_action_ok},
  105.     {"Exit", ExitAction}
  106.   };
  107.  
  108.   XtAppAddActions(app_con, actionTable, XtNumber(actionTable));
  109.  
  110.   mainBox = SeAddPaned("mainBox", topLevelWidget);
  111.   messageBox = SeAddForm("messageBox", mainBox);
  112.   statusBox = SeAddBox("statusBox", mainBox);
  113.   menuBox = SeAddBox("menuBox", mainBox);
  114.  
  115.   status[0] = SeAddToggle("dcd", statusBox, NULL);
  116.   status[1] = SeAddToggle("dtr", statusBox, NULL);
  117.   status[2] = SeAddToggle("dsr", statusBox, NULL);
  118.   status[3] = SeAddToggle("rts", statusBox, NULL);
  119.   status[4] = SeAddToggle("cts", statusBox, NULL);
  120.   status[5] = SeAddToggle("rng", statusBox, NULL);
  121.  
  122.   statusMessage = SeAddLabel("message", messageBox);
  123.  
  124.   SeAddButton("about", menuBox, topAbout);
  125.   SeAddButton("set", menuBox, top_set);
  126.   dial = SeAddButton("dial", menuBox, topDial);
  127.   SeAddButton("transfer", menuBox, top_transfer);
  128.   SeAddButton("shellCommand", menuBox, top_shell);
  129.   SeAddButton("misc", menuBox, top_misc);
  130.  
  131.   qres.hangupConfirm ? (callback = HangupConfirm) : (callback = ExecHangup);
  132.   SeAddButton("hangup", menuBox, callback);
  133.   w_exit = SeAddButton("exit", menuBox, ExitConfirm);
  134.   w_kill = SeAddButton("kill", menuBox, kill_w_child);
  135.  
  136.   XtOverrideTranslations(topLevelWidget,
  137.           XtParseTranslationTable("<Message>WM_PROTOCOLS: Exit()"));
  138.  
  139.   /* Call UpdateStatusBox() before realizing the top-level widget so that
  140.      the status widget array in that function would be properly initialized
  141.      before the user is able to call hangup(), since the latter passes NULL
  142.      to UpdateStatusBox() */
  143.   UpdateStatusBox((XtPointer)status);
  144.   XtRealizeWidget(topLevelWidget);
  145.   /*
  146.    * width of message box = label width
  147.    *                      + 2*border width (2*1)
  148.    *                      + defaultDistance (right) (1)
  149.    *                      + horizDistance (left) (4)
  150.    *
  151.    * desired width of label = width of menu box
  152.    *                        - hSpace of menu box (2*4) (to align with buttons)
  153.    *                        - border with of label (2*1)
  154.    *                        = width of menu box - 10
  155.    *
  156.    * => width of message box = width of menu box - 10 + 7
  157.    * => width of message box < width of menu box
  158.    * => menu box width is the controlling factor in deciding the widnow
  159.    *    width, as desired.
  160.    */
  161.   XtVaSetValues(statusMessage, XtNwidth, SeWidgetWidth(menuBox) - 10, NULL);
  162.   XtVaSetValues(statusMessage, XtNresizable, False, NULL);
  163.   SeyonMessagef("Welcome to Seyon version %s%d", VERSION, REVISION);
  164.  
  165.   wm_delete_window = XInternAtom(XtDisplay(topLevelWidget), 
  166.                                  "WM_DELETE_WINDOW", False);
  167.   (void)XSetWMProtocols(XtDisplay(topLevelWidget), XtWindow(topLevelWidget),
  168.                         &wm_delete_window, 1);
  169.  
  170.   IdleGuard();
  171.   if (qres.showFunMessages)
  172.     XtAppAddTimeOut(app_con, qres.funMessagesInterval * 1000, FunMessage,
  173.                     (XtPointer) app_con);
  174.  
  175.   return dial;
  176. }
  177.  
  178. /*
  179.  * displays the help file
  180.  */
  181.  
  182. void
  183. topAbout(parent)
  184.      Widget          parent;
  185. {
  186.   Widget          popup,
  187.                   mBox,
  188.                   uBox,
  189.                   lBox,
  190.                   pic,
  191.                   msg,
  192.                   caption;
  193.   Pixmap          pix;
  194.   Dimension       width1,
  195.                   width2;
  196.   char            msgStr[LRG_BUF];
  197. #include "authPic.h"
  198.  
  199.   popup = SeAddPopup("about", parent);
  200.   mBox = SeAddPaned("mBox", popup);
  201.   uBox = SeAddBox("uBox", mBox);
  202.   lBox = SeAddBox("lBox", mBox);
  203.  
  204.   msg = SeAddLabel("msg", uBox);
  205.   pic = SeAddLabel("pic", uBox);
  206.   caption = SeAddLabel("caption", uBox);
  207.  
  208.   sprintf(msgStr, "%s %s rev. %d\n%s\n%s\n%s", "Seyon version", VERSION,
  209.       REVISION, "Copyright 1992-1993", "(c) Muhammad M. Saggaf",
  210.       "All rights reserved");
  211.   XtVaSetValues(msg, XtNlabel, msgStr, NULL);
  212.  
  213.   pix = XCreateBitmapFromData(XtDisplay(pic),
  214.                   DefaultRootWindow(XtDisplay(pic)),
  215.                   authPic_bits, authPic_width,
  216.                   authPic_height);
  217.   XtVaSetValues(pic, XtNbitmap, pix, NULL);
  218.  
  219.   width1 = SeWidgetWidth(msg);
  220.   width2 = SeWidgetWidth(pic);
  221.   width1 = width1 > width2 ? width1 : width2;
  222.   width2 = SeWidgetWidth(caption);
  223.   width1 = width1 > width2 ? width1 : width2;
  224.  
  225.   XtVaSetValues(msg, XtNwidth, width1, NULL);
  226.   XtVaSetValues(pic, XtNwidth, width1, NULL);
  227.   XtVaSetValues(caption, XtNwidth, width1, NULL);
  228.  
  229.   SeAddButton("dismiss", lBox, DestroyShell);
  230.   SeAddButton("help", lBox, topHelp);
  231.  
  232.   XtPopupSpringLoaded(popup);
  233. }
  234.  
  235. void
  236. topHelp(parent)
  237.      Widget          parent;
  238. {
  239.   SeDisplayFile(parent, XtParent(XtParent(parent)), qres.helpFile);
  240. }
  241.  
  242. void
  243. ExecHangup()
  244. {
  245.   hangup();
  246.   SeyonMessage("Line Disconnected");
  247. }
  248.  
  249. void
  250. DoHangup(widget)
  251.      Widget          widget;
  252. {
  253.   DestroyShell(widget);
  254.   ExecHangup();
  255. }
  256.  
  257. void
  258. HangupConfirm(parent)
  259.      Widget          parent;
  260. {
  261.   Widget          popup,
  262.                   dialog;
  263.  
  264.   popup = AddSimplePopup("hangup", parent);
  265.   dialog = SeAddDialog("dialog", popup);
  266.  
  267.   XawDialogAddButton(dialog, "yes", DoHangup, (XtPointer) dialog);
  268.   XawDialogAddButton(dialog, "cancel", DestroyShell, NULL);
  269.  
  270.   PopupCentered(popup, parent);
  271. }
  272.  
  273. void
  274. ExitNoHangup(widget)
  275.      Widget          widget;
  276. {
  277.   DestroyShell(widget);
  278.   s_exit(widget);
  279. }
  280.  
  281. void
  282. ExitHangup(widget)
  283.      Widget          widget;
  284. {
  285.   ExecHangup();
  286.   ExitNoHangup(widget);
  287. }
  288.  
  289. void
  290. ExitConfirm(widget)
  291.      Widget          widget;
  292. {
  293.   Widget          popup,
  294.                   dialog;
  295.  
  296.   if (qres.exitConfirm && !qres.ignoreModemDCD && Online()) {
  297.     popup = AddSimplePopup("exit", widget);
  298.     dialog = SeAddDialog("dialog", popup);
  299.     
  300.     XawDialogAddButton(dialog, "yes", ExitHangup, NULL);
  301.     XawDialogAddButton(dialog, "no", ExitNoHangup, NULL);
  302.     XawDialogAddButton(dialog, "cancel", DestroyShell, NULL);
  303.     
  304.     PopupCentered(popup, widget);
  305.   }
  306.   else
  307.     s_exit();
  308. }
  309.  
  310. void
  311. ExitAction(widget)
  312.      Widget          widget;
  313. {
  314.   Boolean         wExitButtonStatus;
  315.  
  316.   /* Prevent the user from exiting the program by f.delete if exiting
  317.      is not permitted */
  318.   XtVaGetValues(w_exit, XtNsensitive, &wExitButtonStatus, NULL);
  319.   ret_if_up(widget, !wExitButtonStatus);
  320.   s_exit();
  321. }
  322.  
  323. void
  324. w_exit_up(w_exit_status)
  325.      Boolean         w_exit_status;
  326. {
  327.   XtVaSetValues(w_exit, XtNsensitive, w_exit_status, NULL);
  328. }
  329.  
  330. void
  331. w_kill_up(w_kill_status)
  332.      Boolean         w_kill_status;
  333. {
  334.   XtVaSetValues(w_kill, XtNsensitive, w_kill_status, NULL);
  335.   w_exit_up(!w_kill_status);
  336. }
  337.  
  338. void
  339. kill_w_child()
  340. {
  341.   if (w_child_pid) {
  342.     kill(w_child_pid, SIGTERM);
  343.     w_child_pid = 0;
  344.   }
  345. }
  346.  
  347. void
  348. GetResources(topLevelWidget)
  349.      Widget          topLevelWidget;
  350. {
  351. #define offset(field) XtOffsetOf(struct QueryResources, field)
  352.  
  353.   static XtResource resources[] = {
  354.     {"modem", "Modem", XtRString, sizeof(String),
  355.        offset(modem), XtRString, (XtPointer) NULL},
  356.     {"script", "Script", XtRString, sizeof(String),
  357.        offset(script), XtRString, (XtPointer) NULL},
  358.     
  359.     {"defaultBPS", "DefaultBPS", XtRString, sizeof(String),
  360.        offset(defaultBPS), XtRString, (XtPointer) "9600"},
  361.     {"defaultBits", "DefaultBits", XtRInt, sizeof(int),
  362.        offset(defaultBits), XtRImmediate, (XtPointer) 8},
  363.     {"defaultParity", "DefaultParity", XtRInt, sizeof(int),
  364.        offset(defaultParity), XtRImmediate, (XtPointer) 0},
  365.     {"defaultStopBits", "DefaultStopBits", XtRInt, sizeof(int),
  366.        offset(defaultStopBits), XtRImmediate, (XtPointer) 1},
  367.     {"stripHighBit", "StripHighBit", XtRBoolean, sizeof(Boolean),
  368.        offset(stripHighBit), XtRImmediate, (XtPointer) False},
  369.     {"backspaceTranslation", "BackspaceTranslation", XtRBoolean,
  370.        sizeof(Boolean), offset(backspaceTranslation), XtRImmediate,
  371.        (XtPointer) False},
  372.     {"metaKeyTranslation", "MetaKeyTranslation", XtRBoolean,
  373.        sizeof(Boolean), offset(metaKeyTranslation), XtRImmediate,
  374.        (XtPointer) True},
  375.     {"xonxoffFlowControl", "XonxoffFlowControl", XtRBoolean,
  376.        sizeof(Boolean), offset(xonxoffFlowControl), XtRImmediate,
  377.        (XtPointer) False},
  378.     {"rtsctsFlowControl", "RtsctsFlowControl", XtRBoolean,
  379.        sizeof(Boolean), offset(rtsctsFlowControl), XtRImmediate,
  380.        (XtPointer) False},
  381.     {"newlineTranslation", "NewlineTranslation", XtRString,
  382.        sizeof(String), offset(newlineTranslation), XtRImmediate,
  383.        (XtPointer) "cr"},
  384.  
  385.     {"dialPrefix", "DialPrefix", XtRString, sizeof(String),
  386.        offset(dialPrefix), XtRString, (XtPointer) "ATDT"},
  387.     {"dialSuffix", "DialSuffix", XtRString, sizeof(String),
  388.        offset(dialSuffix), XtRString, (XtPointer) "^M"},
  389.     {"dialCancel", "DialCancel", XtRString, sizeof(String),
  390.        offset(dialCancel), XtRString, (XtPointer) "^M"},
  391.  
  392.     {"dialTimeOut", "DialTimeOut", XtRInt, sizeof(int),
  393.        offset(dialTimeOut), XtRImmediate, (XtPointer) 45},
  394.     {"dialDelay", "DialDelay", XtRInt, sizeof(int),
  395.        offset(dialDelay), XtRImmediate, (XtPointer) 10},
  396.     {"dialRepeat", "DialRepeat", XtRInt, sizeof(int),
  397.        offset(dialRepeat), XtRImmediate, (XtPointer) 5},
  398.  
  399.     {"connectString", "ConnectString", XtRString, sizeof(String),
  400.        offset(connectString), XtRString, (XtPointer) "CONNECT"},
  401.     {"noConnectString1", "NoConnectString1", XtRString, sizeof(String),
  402.        offset(noConnectString[0]), XtRString, (XtPointer) "NO CARRIER"},
  403.     {"noConnectString2", "NoConnectString2", XtRString, sizeof(String),
  404.        offset(noConnectString[1]), XtRString, (XtPointer) "NO DIALTONE"},
  405.     {"noConnectString3", "NoConnectString3", XtRString, sizeof(String),
  406.        offset(noConnectString[2]), XtRString, (XtPointer) "BUSY"},
  407.     {"noConnectString4", "NoConnectString4", XtRString, sizeof(String),
  408.        offset(noConnectString[3]), XtRString, (XtPointer) "VOICE"},
  409.  
  410.     {"hangupBeforeDial", "HangupBeforeDial", XtRBoolean, sizeof(Boolean),
  411.        offset(hangupBeforeDial), XtRImmediate, (XtPointer) True},
  412.     {"dialDirAutoOpen", "DialDirAutoOpen", XtRBoolean, sizeof(Boolean),
  413.        offset(dialDirAutoOpen), XtRImmediate, (XtPointer) False},
  414.     {"dialAutoStart", "DialAutoStart", XtRBoolean, sizeof(Boolean),
  415.        offset(dialAutoStart), XtRImmediate, (XtPointer) False},
  416.     {"dialDirAutoClose", "DialDirAutoClose", XtRBoolean, sizeof(Boolean),
  417.        offset(dialDirAutoClose), XtRImmediate, (XtPointer) False},
  418.     {"dialDirFormat", "DialDirFormat", XtRString, sizeof(String),
  419.        offset(dialDirFormat), XtRString,
  420.        (XtPointer)"%-15s %-15s %6s %1c%1c%1c %1c%1c %s"},
  421.     {"defaultPhoneEntries", "DefaultPhoneEntries", XtRString, sizeof(String),
  422.        offset(defaultPhoneEntries), XtRString, (XtPointer) NULL},
  423.  
  424.     {"modemVMin", "ModemVMin", XtRInt, sizeof(int),
  425.        offset(modemVMin), XtRImmediate, (XtPointer) 1},
  426.     {"ignoreModemDCD", "IgnoreModemDCD", XtRBoolean, sizeof(Boolean),
  427.        offset(ignoreModemDCD), XtRImmediate, (XtPointer) False},
  428.     {"hayesHangup", "hayesHangup", XtRBoolean, sizeof(Boolean),
  429.        offset(hayesHangup), XtRImmediate, (XtPointer) False},
  430.     {"hangupConfirm", "HangupConfirm", XtRBoolean, sizeof(Boolean),
  431.        offset(hangupConfirm), XtRImmediate, (XtPointer) True},
  432.     {"exitConfirm", "ExitConfirm", XtRBoolean, sizeof(Boolean),
  433.        offset(exitConfirm), XtRImmediate, (XtPointer) True},
  434.  
  435.     {"zmodemAutoDownload", "ZmodemAutoDownload", XtRBoolean,
  436.        sizeof(Boolean), offset(zmodemAutoDownload), XtRImmediate,
  437.        (XtPointer) True},
  438.     {"zmodemAutoDownloadCommand", "ZmodemAutoDownloadCommand",
  439.        XtRString, sizeof(String), offset(zmodemAutoDownloadCommand),
  440.        XtRString, (XtPointer) "$rz"},
  441.  
  442.     {"defaultDirectory", "DefaultDirectory", XtRString, sizeof(String),
  443.        offset(defaultDirectory), XtRString, (XtPointer) "~/.seyon"},
  444.     {"scriptDirectory", "scriptDirectory", XtRString, sizeof(String),
  445.        offset(scriptDirectory), XtRString, (XtPointer) NULL},
  446.     {"startupFile", "StartupFile", XtRString, sizeof(String),
  447.        offset(startupFile), XtRString, (XtPointer) "startup"},
  448.     {"phoneFile", "PhoneFile", XtRString, sizeof(String),
  449.        offset(phoneFile), XtRString, (XtPointer) "phonelist"},
  450.     {"protocolsFile", "ProtocolsFile", XtRString, sizeof(String),
  451.        offset(protocolsFile), XtRString, (XtPointer) "protocols"},
  452.     {"captureFile", "CaptureFile", XtRString, sizeof(String),
  453.        offset(captureFile), XtRString, (XtPointer) "capture"},
  454.     {"helpFile", "HelpFile", XtRString, sizeof(String),
  455.        offset(helpFile), XtRString, (XtPointer) HELPFILE},
  456.  
  457.     {"modemStatusInterval", "ModemStatusInterval", XtRInt, sizeof(int),
  458.        offset(modemStatusInterval), XtRImmediate, (XtPointer) 5},
  459.  
  460.     {"idleGuard", "IdleGuard", XtRBoolean, sizeof(Boolean),
  461.        offset(idleGuard), XtRImmediate, (XtPointer) False},
  462.     {"idleGuardInterval", "IdleGuardInterval", XtRInt, sizeof(int),
  463.        offset(idleGuardInterval), XtRImmediate, (XtPointer) 300},
  464.     {"idleGuardString", "IdleGuardString", XtRString, sizeof(String),
  465.        offset(idleGuardString), XtRImmediate, (XtPointer) " ^H"},
  466.  
  467.     {"showFunMessages", "ShowFunMessages", XtRBoolean, sizeof(Boolean),
  468.        offset(showFunMessages), XtRImmediate, (XtPointer) True},
  469.     {"funMessagesInterval", "FunMessagesInterval", XtRInt, sizeof(int),
  470.        offset(funMessagesInterval), XtRImmediate, (XtPointer) 15},
  471.     {"funMessages", "FunMessages", XtRStringArray, sizeof(String *),
  472.        offset(funMessages), XtRStringArray, (XtPointer) NULL},
  473.   };
  474.  
  475. #undef offset
  476.  
  477.   XtSetTypeConverter(XtRString, XtRStringArray, CvtStringToStringArray,
  478.                      NULL, 0, XtCacheNone, NULL);
  479.  
  480.   XtGetApplicationResources(topLevelWidget, (XtPointer)&qres, resources,
  481.                             XtNumber(resources), NULL, 0);
  482. }
  483.