home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Connectivity / GateKeeper-2.1 / OptionsEditor.m < prev    next >
Encoding:
Text File  |  1997-03-13  |  9.7 KB  |  400 lines

  1. //*****************************************************************************
  2. //
  3. //    OptionsEditor.m.  
  4. //        
  5. //        Edit the options file contained within a Gate doc 
  6. // 
  7. //            by    Felipe A. Rodriguez        
  8. //
  9. //    This code is supplied "as is" the author makes no warranty as to its 
  10. //    suitability for any purpose.  This code is free and may be distributed 
  11. //    in accordance with the terms of the:
  12. //        
  13. //            GNU GENERAL PUBLIC LICENSE
  14. //            Version 2, June 1991
  15. //            copyright (C) 1989, 1991 Free Software Foundation, Inc.
  16. //             675 Mass Ave, Cambridge, MA 02139, USA
  17. //
  18. //*****************************************************************************
  19.  
  20.  
  21. #import "GKdefs.h"
  22. #import "OptionsEditor.h"
  23. #import "options.h"
  24. #import "Coordinator.h"
  25.  
  26.  
  27.  
  28.     char *devNames[] = { "cua", "cufa", "cudfa", "cub",    "cufb", "cudfb", "cuc",
  29.                              "cufc", "cudfc", "cud", "cufd", "cudfd", NULL};
  30.  
  31.  
  32. @implementation OptionsEditor
  33.  
  34. //*****************************************************************************
  35. //
  36. //         init -- reset ivars
  37. //
  38. //*****************************************************************************
  39.  
  40. - init
  41. {
  42.     [super init];                                        
  43.     debug = NO;
  44.     crtscts = NO;
  45.     lockFlag = NO;
  46.     defaultroute = NO;
  47.     shouldSave = NO;
  48.  
  49.     return self;
  50. }
  51. //*****************************************************************************
  52. //
  53. //         Open file to parse and search 
  54. //
  55. //*****************************************************************************
  56.  
  57. - parseOptionsFile:(const char *)filePath
  58. {
  59. struct stat statbuf;
  60. char **devNamePtr;
  61.  
  62.     setDelegate(self);
  63.  
  64.             // check for installed ports, add those found to device popup List
  65.     devNamePtr = devNames;
  66.       if (![dvPopup isKindOf:[PopUpList class]]) 
  67.         dvPopupList = [dvPopup target];        // get popuplist from trig button
  68.     while(*devNamePtr)
  69.         {
  70.         strcpy(devName, "/dev/");
  71.         strcat(devName, *devNamePtr);
  72.         if (stat(devName, &statbuf) == 0)
  73.             [dvPopupList addItem:*devNamePtr];
  74.         devNamePtr++;
  75.         }
  76.     devName[1] = 0;
  77.     options_from_file(filePath, 0, 1);
  78.     strcpy(path, filePath);
  79.  
  80.     if(defaultroute)        
  81.         [[swMatrix findCellWithTag:0] setIntValue:1];
  82.     if(lockFlag)        
  83.         [[swMatrix findCellWithTag:1] setIntValue:1];
  84.     if(crtscts)        
  85.         [[swMatrix findCellWithTag:2] setIntValue:1];
  86.     if(debug)        
  87.         [[swMatrix findCellWithTag:3] setIntValue:1];
  88.  
  89.  
  90.     return self;
  91. }
  92. //*****************************************************************************
  93. //
  94. //         Open file to parse and search without setting GUI controls
  95. //
  96. //*****************************************************************************
  97.  
  98. - parseOptions:(const char *)filePath
  99. {
  100.     setDelegate(self);
  101.     [self init];                                        // reset ivars 
  102.     options_from_file(filePath, 0, 1);
  103.  
  104.     return self;
  105. }
  106. //*****************************************************************************
  107. //
  108. //         defaultroute -- return status of or set from info in options file
  109. //
  110. //*****************************************************************************
  111.  
  112. - setDefaultRoute
  113. {
  114.     defaultroute = YES;
  115.  
  116.     return self;
  117. }
  118. - (BOOL)defaultRoute
  119. {
  120.     return defaultroute;
  121. }
  122. //*****************************************************************************
  123. //
  124. //         lockFlag -- return status of or set from info in options file
  125. //
  126. //*****************************************************************************
  127.  
  128. - setLockFlag
  129. {
  130.     lockFlag = YES;
  131.  
  132.     return self;
  133. }
  134. - (BOOL)lockFlag
  135. {
  136.     return lockFlag;
  137. }
  138. //*****************************************************************************
  139. //
  140. //         defaultroute -- return status of or set from info in options file
  141. //
  142. //*****************************************************************************
  143.  
  144. - setDebug
  145. {
  146.     debug = YES;
  147.  
  148.     return self;
  149. }
  150. - (BOOL)debug
  151. {
  152.     return debug;
  153. }
  154. //*****************************************************************************
  155. //
  156. //         defaultroute -- return status of or set from info in options file
  157. //
  158. //*****************************************************************************
  159.  
  160. - setCrtscts
  161. {
  162.     crtscts = YES;
  163.  
  164.     return self;
  165. }
  166. - (BOOL)crtscts
  167. {
  168.     return crtscts;
  169. }
  170. //*****************************************************************************
  171. //
  172. //         if set, GUI settings will be saved to options file when it is parsed
  173. //
  174. //*****************************************************************************
  175.  
  176. - (BOOL)shouldSave
  177. {
  178.     return shouldSave;
  179. }
  180. //************************************************************************
  181. //
  182. //        Target method of save switch
  183. //
  184. //************************************************************************
  185.  
  186. - setShouldSave:sender
  187. {
  188.     shouldSave = YES;
  189.     setDelegate(self);
  190.     options_from_file(path, 0, 1);
  191.     shouldSave = NO;
  192.  
  193.     return self;
  194. }
  195. //************************************************************************
  196. //
  197. //        Target method of switches
  198. //        check switches based on the tag assigned in IB to each switch.
  199. //
  200. //************************************************************************
  201.  
  202. - switch:sender
  203. {
  204.     switch([sender selectedTag])
  205.         {                            
  206.         case 0:                 // defaultroute
  207.             defaultroute = (BOOL)[sender intValue];
  208.             [self setShouldSave:self];
  209.             break;    
  210.             
  211.         case 1:                 // lock
  212.             lockFlag = (BOOL)[sender intValue];
  213.             [self setShouldSave:self];
  214.             break;    
  215.  
  216.         case 2:                 // crtscts
  217.             crtscts = (BOOL)[sender intValue];
  218.             [self setShouldSave:self];
  219.             break;    
  220.  
  221.         case 3:                 // debug
  222.             debug = (BOOL)[sender intValue];
  223.             [self setShouldSave:self];
  224.             break;    
  225.  
  226.         default:    // parent --  vfork returns pid of the child          
  227.             break;
  228.         }
  229.  
  230.     return self;
  231. }
  232. //*****************************************************************************
  233. //
  234. //         devName -- set, return and target of 
  235. //
  236. //*****************************************************************************
  237.  
  238. - setDevName:(const char *)device
  239. {
  240. const char *sPtr;
  241. static int i;
  242.  
  243.     sPtr = device + 5;
  244.     if(dvPopup != nil)        // if not connected we are just parsing for port
  245.         {
  246.         strncpy(devName, device, MAXPATHLEN);
  247.         if (![dvPopup isKindOf:[PopUpList class]]) 
  248.             dvPopupList = [dvPopup target];    // get popuplist from trig button
  249.         dvPopMtrx = [dvPopupList itemList];        // get matrix from popuplist
  250.         for (i = 0; i < [dvPopMtrx cellCount]; i++)    // scan matrix for device
  251.             {                                        // str found in options
  252.             if(strcmp(sPtr,[[[dvPopMtrx selectCellAt:i :0] 
  253.                                                     selectedCell] title])==0)
  254.                 break;
  255.             }                        // set button title to that of sel'd cell
  256.         [dvPopup setTitle:[[[dvPopMtrx selectCellAt:i :0]selectedCell] title]];
  257.         [dvPopupList setTarget:self];
  258.         [dvPopupList setAction:@selector(devPopUpAction:)];
  259.         }
  260.     else
  261.         strncpy(devName, sPtr, MAXPATHLEN);
  262.     devName[MAXPATHLEN-1] = 0;
  263.  
  264.     return self;
  265. }
  266.  
  267. - (const char *)devName
  268. {
  269.     return devName;
  270. }
  271.  
  272. - devPopUpAction:sender
  273. {
  274.     strcpy(devName, "/dev/");
  275.     strncat(devName, [[sender selectedCell] title], MAXPATHLEN - 5);
  276.     devName[MAXPATHLEN-1] = 0;
  277.     [self setShouldSave:self];
  278.  
  279.     return self;
  280. }
  281. //*****************************************************************************
  282. //
  283. //         speed -- set, return and target of 
  284. //
  285. //*****************************************************************************
  286.  
  287. - setSpeed:(const char *)aSpeed
  288. {
  289. static int i;
  290.  
  291.     strncpy(speed, aSpeed, MAXPATHLEN);
  292.     speed[MAXPATHLEN-1] = 0;
  293.     if(spPopup)
  294.         {
  295.         if (![spPopup isKindOf:[PopUpList class]]) 
  296.             spPopupList = [spPopup target];
  297.         spPopMtrx = [spPopupList itemList];
  298.         for (i = 0; i < [spPopMtrx cellCount]; i++)    // scan matrix for speed
  299.             {                                        // str found in options
  300.             if(strcmp(speed,[[[spPopMtrx selectCellAt:i :0] 
  301.                                                     selectedCell]title])==0)
  302.             break;
  303.             }                        // set button title to that of sel'd cell
  304.         [spPopupList setTarget:self];
  305.         [spPopupList setAction:@selector(speedPopUpAction:)];
  306.         if(i < [spPopMtrx cellCount])
  307.             {
  308.             [spPopup setTitle:[[[spPopMtrx selectCellAt:i :0] 
  309.                                                         selectedCell] title]];
  310.             return self;                // aSpeed was in popuplist, success
  311.             }
  312.         }
  313.  
  314.     return nil;                            // aSpeed was not in popuplist, fail
  315. }
  316.  
  317. - (const char *)speed
  318. {
  319.     return speed;
  320. }
  321.  
  322. - speedPopUpAction:sender
  323. {
  324.     strncpy(speed, [[sender selectedCell] title], MAXPATHLEN);
  325.     speed[MAXPATHLEN-1] = 0;
  326.     [self setShouldSave:self];
  327.  
  328.     return self;
  329. }
  330. //*****************************************************************************
  331. //
  332. //         return status of or set from info in options file
  333. //
  334. //*****************************************************************************
  335.  
  336. - editorWindow
  337. {
  338.     return editWin;
  339. }
  340. //*****************************************************************************
  341. //
  342. //         Edit options file in Edit.app
  343. //
  344. //*****************************************************************************
  345.  
  346. - editOptions:sender
  347. {
  348.     if([[NXApp delegate] readable:path])
  349.                         // call edit to open radioButtons selected file
  350.         [[Application workspace] openFile:path withApplication:"Edit"];
  351.     
  352.     return self;
  353. }
  354. //*****************************************************************************
  355. //
  356. //         Edit Gate pppup file in Edit.app
  357. //
  358. //*****************************************************************************
  359.  
  360. - editPppup:sender
  361. {
  362. static char *sPtr;
  363.                             
  364.     strcpy(Path, path);
  365.     sPtr = Path + (strlen(path) - 8);
  366.     strcpy(sPtr, PPPUP);
  367.     if([[NXApp delegate] readable:Path])
  368.                         // call edit to open radioButtons selected file
  369.         [[Application workspace] openFile:Path withApplication:"Edit"];
  370.  
  371.     return self;
  372. }
  373. //*****************************************************************************
  374. //
  375. //         set our owner
  376. //
  377. //*****************************************************************************
  378.  
  379. - setOwner:anObject
  380. {
  381.     owner = anObject;
  382.  
  383.     return self;
  384. }
  385. //******************* Gate doc panel delegate methods *************************
  386. //*****************************************************************************
  387. //
  388. //         called whenever the user minituriazes our status window.
  389. //
  390. //*****************************************************************************
  391.  
  392. - windowWillMiniaturize:sender toMiniwindow:miniwindow 
  393. {
  394.     return [sender setMiniwindowIcon:".dir"];
  395. }
  396.  
  397.  
  398. @end
  399.  
  400.