home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Internet / TurboTCP 2.1 ƒ / PP MiniTelnet source / CTelnetSettingsDialog.cp < prev    next >
Encoding:
Text File  |  1995-01-19  |  7.7 KB  |  364 lines  |  [TEXT/MMCC]

  1. //
  2. // CTelnetSettingsDialog.cp
  3. //
  4. //    MiniTelnet application
  5. //    Telnet settings dialog director
  6. //    PowerPlant version
  7. //
  8. //    Copyright © 1993-95, FrostByte Design / Eric Scouten
  9. //
  10.  
  11. #include "CTelnetSettingsDialog.h"
  12.  
  13. #include <LEditField.h>
  14. #include <LStdControl.h>
  15. #include <PP_Messages.h>
  16.  
  17.  
  18. //***********************************************************
  19.  
  20. /*______________________________________________________________________
  21. **
  22. ** DefaultSettings
  23. **
  24. **    Creates a new blank settings record and copies this to the dialog.
  25. **
  26. */
  27.  
  28. void CTelnetSettingsDialog::DefaultSettings()
  29.  
  30. {
  31.     TelnetSettingsRec theSettings;
  32.     
  33.     theSettings.signature = kTSRsignature;
  34.     theSettings.settingsVersion = kTSRversion;
  35.     theSettings.settingsMinVersion = 0;
  36.     theSettings.hostName[0] = '\0';
  37.     ::BlockMoveData("UNKNOWN", &theSettings.termEmulation, 8);
  38. //    theSettings.backspaceChar = charBS;
  39.     theSettings.backspaceChar = 0x7F; // charDEL;
  40.     theSettings.closeOnSessionEnd = false;
  41.     theSettings.showDebug = false;
  42.     
  43.     PutSettings(theSettings);
  44. }
  45.  
  46.  
  47. //***********************************************************
  48.  
  49. /*______________________________________________________________________
  50. **
  51. ** GrabSettings
  52. **
  53. **    Get the settings from the dialog box fields and put them into the
  54. **    settings record.
  55. **
  56. */
  57.  
  58.  
  59.  
  60.  
  61. //***********************************************************
  62.  
  63. /*______________________________________________________________________
  64. **
  65. ** PutSettings
  66. **
  67. **    Copy the settings from the settings record to the dialog box fields.
  68. **
  69. */
  70.  
  71.  
  72.  
  73.  
  74. //    —— dialog handling functions ——
  75.  
  76. //***********************************************************
  77.  
  78. /*______________________________________________________________________
  79. **
  80. ** DoCommand
  81. **
  82. **    Handle all commands that the dialog can understand.
  83. **
  84. **        theCommand (long):    the command number which was issued
  85. **
  86. */
  87.  
  88.  
  89.  
  90. //***********************************************************
  91.  
  92. /*______________________________________________________________________
  93. **
  94. ** UpdateMenus
  95. **
  96. **    Enable Telnet-specific commands.
  97. **
  98. */
  99.  
  100.  
  101.  
  102.  
  103. //    —— file interactions ——
  104.  
  105. //***********************************************************
  106.  
  107. /*______________________________________________________________________
  108. **
  109. ** DoSaveFile
  110. **
  111. **    Save a settings record to a file.
  112. **
  113. */
  114.  
  115. void CTelnetSettingsDialog::DoSaveFile()
  116.  
  117. {
  118. /*
  119.     Point            corner;                // top left corner of dialog box
  120.     Str255        origName;                // default name for file
  121.     short        nameLength;            // length of default name
  122.     StringHandle    prompt;                // prompt string
  123.     Boolean        wasLocked;
  124.     
  125.     CDataFile*    itsFile;                // don’t keep the file around
  126.     SFReply        macSFReply;            // reply from Std File
  127.  
  128.  
  129.     // ask user for settings file name
  130.  
  131.     FindDlogPosition('DLOG', putDlgID, &corner);
  132.     BlockMove(&r.hostName, &origName[1], 31);
  133.     nameLength = cstrlen(r.hostName);
  134.     origName[0] = (nameLength > 31 ? 31 : nameLength);
  135.     
  136.     prompt = GetString(STR_SettingsPrompt);
  137.     FailNILRes(prompt);
  138.     
  139.     MoveHHi((Handle) prompt);
  140.     HLock((Handle) prompt);
  141.     SFPPutFile(corner, *prompt, origName, NULL, &macSFReply, putDlgID, NULL);
  142.     ReleaseResource((Handle) prompt);
  143.  
  144.  
  145.     // create the file
  146.  
  147.     TRY {
  148.         itsFile = new CDataFile;
  149.         itsFile->SFSpecify(&macSFReply);
  150.  
  151.         if (itsFile->ExistsOnDisk()) {
  152.             itsFile->Open(fsRdWrPerm);
  153.             itsFile->SetLength(0);
  154.                 // TEMPORARY: need to reset file type
  155.         }
  156.         else {
  157.             itsFile->CreateNew(gSignature, kSettingsFileType);
  158.             itsFile->Open(fsRdWrPerm);
  159.         }
  160.         itsFile->WriteSome((Ptr) &r, sizeof(TelnetSettingsRec));
  161.         itsFile->Close();
  162.         delete itsFile;
  163.     }
  164.     
  165.     CATCH {
  166.         ForgetObject(itsFile);
  167.     }
  168.     ENDTRY;
  169. */
  170. }
  171.  
  172. CTelnetSettingsDialog* CTelnetSettingsDialog::CreateDialogBoxStream
  173.     (LStream* inStream)                    // PPob stream describing the dialog box
  174.  
  175. {
  176.     return new CTelnetSettingsDialog(inStream);
  177. }
  178.  
  179.  
  180. CTelnetSettingsDialog::CTelnetSettingsDialog
  181.     (LStream* inStream)
  182.     
  183. : LDialogBox(inStream)
  184. {
  185.     DefaultSettings();
  186. }
  187.  
  188.  
  189. void CTelnetSettingsDialog::GrabSettings
  190.     (TelnetSettingsRec& outSettings)            // where to put the settings
  191.  
  192.     // Get the settings from the dialog box.
  193.  
  194. // virtual LPane* FindPaneByID(PaneIDT inPaneID);
  195. {
  196. /* TEMPORARY: not *absolutely* necessary…
  197.  
  198.     CCheckBox*        theCheckBox;
  199.     CEditText*        theText;
  200.     CRadioGroupPane*    theRadios;
  201.     CView*            theView;
  202.     short              textSize;
  203. */
  204.  
  205.     // blank out the settings record
  206.     
  207.     char* p = (char*) &outSettings;
  208.     for (int i = 0; i < sizeof (TelnetSettingsRec); i++)
  209.         *p++ = 0;
  210.  
  211.  
  212.     // recreate signature, version info
  213.  
  214.     outSettings.signature = kTSRsignature;
  215.     outSettings.settingsVersion = kTSRversion;
  216.     outSettings.settingsMinVersion = 0;
  217.  
  218.  
  219.     // get host name
  220.  
  221.     Str255 theHostName;
  222.     LEditField* theEditField = (LEditField*) FindPaneByID('HOST');        //! TEMPORARY: we’ll do constants later
  223.     ThrowIfNil_(theEditField);
  224.  
  225.     theEditField->GetDescriptor(theHostName);
  226.     ::BlockMoveData(&theHostName[1], &outSettings.hostName, theHostName[0]);
  227.     outSettings.hostName[theHostName[0]] = '\0';
  228.  
  229.  
  230.     // get terminal emulation
  231.  
  232.     ::BlockMoveData("UNKNOWN", &outSettings.termEmulation, 8);
  233.  
  234.  
  235.     // get backspace/del configuration
  236.  
  237.     LStdRadioButton* theButton = (LStdRadioButton*) FindPaneByID('BS  ');    //! TEMPORARY: we’ll do constants later
  238.     ThrowIfNil_(theButton);
  239.     outSettings.backspaceChar = (theButton->GetValue() ? 0x08 : 0x7F);    //! TEMPORARY: again, constants later
  240.  
  241.  
  242.     // get window go away config
  243.  
  244.     LStdCheckBox* theCheckBox = (LStdCheckBox*) FindPaneByID('GOWY');    //! TEMPORARY: we’ll do constants later
  245.     ThrowIfNil_(theCheckBox);
  246.     outSettings.closeOnSessionEnd = theCheckBox->GetValue();
  247.  
  248.  
  249.     // get show debug codes config
  250.  
  251.     theCheckBox = (LStdCheckBox*) FindPaneByID('DEBG');    //! TEMPORARY: we’ll do constants later
  252.     ThrowIfNil_(theCheckBox);
  253.     outSettings.showDebug = theCheckBox->GetValue();
  254.  
  255. }
  256.  
  257.  
  258. void CTelnetSettingsDialog::PutSettings
  259.     (TelnetSettingsRec& inSettings)            // where to get settings from
  260.  
  261.     // Configure the dialog box to reflect the given settings record.
  262.  
  263. {
  264. /* TEMPORARY: not *absolutely* necessary…
  265.  
  266.     CCheckBox*        theCheckBox;
  267.     CEditText*        theText;
  268.     CPane*            thePane;
  269.     CRadioGroupPane*    theRadios;
  270.     CView*            theView;
  271.  
  272.  
  273.     // get host name
  274.  
  275.     theView = itsWindow->FindViewByID(itemHostName);
  276.     theText = TCL_DYNAMIC_CAST(CEditText, theView);
  277.     if (theText)
  278.         theText->SetTextPtr((char*) &r.hostName, cstrlen(r.hostName));
  279.  
  280.  
  281.     // get backspace/del configuration
  282.  
  283.     theView = itsWindow->FindViewByID(itemBSPane);
  284.     theRadios = TCL_DYNAMIC_CAST(CRadioGroupPane, theView);
  285.     if (theRadios)
  286.         theRadios->SetStationID((r.backspaceChar == charDEL) ? itemBS_DEL : itemBS_BS);
  287.  
  288.  
  289.     // get window go away config
  290.  
  291.     theView = itsWindow->FindViewByID(itemGoAway);
  292.     theCheckBox = TCL_DYNAMIC_CAST(CCheckBox, theView);
  293.     if (theCheckBox)
  294.         theCheckBox->SetValue(r.closeOnSessionEnd);
  295.  
  296.  
  297.     // get show debug codes config
  298.  
  299.     theView = itsWindow->FindViewByID(itemShowDebug);
  300.     theCheckBox = TCL_DYNAMIC_CAST(CCheckBox, theView);
  301.     if (theCheckBox)
  302.         theCheckBox->SetValue(r.showDebug);
  303.  
  304.  
  305.     // ignore other parms
  306.  
  307.     // force redraw
  308.  
  309.     thePane = TCL_DYNAMIC_CAST(CPane, itsWindow);
  310.     if (thePane)
  311.         thePane->Refresh();
  312. */
  313. }
  314.  
  315.  
  316. void    CTelnetSettingsDialog::ListenToMessage
  317.     (MessageT    inMessage,            // message number
  318.     void*        ioParam)                 // optional extra info
  319.  
  320. {
  321.     switch (inMessage) {
  322.  
  323.         case msg_OpenSession:
  324.             BroadcastMessage(msg_OpenSession, this);
  325.             DoClose();
  326.             break;
  327.  
  328.         case msg_Cancel:
  329.             DoClose();
  330.             break;
  331.             
  332.         default:
  333.             LDialogBox::ListenToMessage(inMessage, ioParam);
  334.     }
  335.  
  336. }
  337.  
  338.  
  339. void CTelnetSettingsDialog::FindCommandStatus
  340.     (CommandT    inCommand,
  341.     Boolean&        outEnabled,
  342.     Boolean&        outUsesMark,
  343.     Char16&        outMark,
  344.     Str255        outName)
  345.  
  346. {
  347. /*
  348.     CDLOGDirector::UpdateMenus();
  349.     gBartender->EnableCmd(cmdSave);
  350.     gBartender->EnableCmd(cmdSaveAs);
  351. */
  352.     LDialogBox::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
  353. }
  354.  
  355.  
  356. Boolean CTelnetSettingsDialog::ObeyCommand
  357.     (CommandT    inCommand,            // the command number
  358.     void*        ioParam)                // optional additional info
  359.  
  360. {
  361.     return LDialogBox::ObeyCommand(inCommand, ioParam);
  362. }
  363.  
  364.