home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Networking / SambaManager / Printers.m < prev    next >
Encoding:
Text File  |  1998-03-28  |  5.4 KB  |  188 lines

  1. /*
  2.     SambaManger. A graphical frontend to configure the NetInfo enhanced samba.
  3.     Copyright (C) 1998  Robert Frank
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.         
  19.         Robert Frank, frank@ifi.unibas.ch
  20. */
  21.  
  22. #import "Printers.h"
  23. #import "Controller.h"
  24. #import "NIDirectory.h"
  25. #import "NIProperty.h"
  26. #import "NetInfoKeys.h"
  27.  
  28. // The property names of a printer's directory:
  29. #define P_NAME                        "name"
  30. #define P_SAMBANAME                "netbios name"
  31. #define P_COMMENT                    "note"
  32. #define P_REMOTE                    "rm"
  33. #define P_COMMDIR                    "Comm"
  34. #define P_COMMHOST                "HostName"
  35. #define P_SHAREDAS                "sharedAs"
  36. #define P_PRINTERDRIVER        "nt printer driver"
  37. #define P_PRINTCOMMAND        "print command"
  38. #define P_LPRMCOMMAND            "lprm command"
  39. #define P_LPQCOMMAND            "lpq command"
  40. #define P_LPRESUMECOMMAND    "lp resume command"
  41. #define P_LPPAUSECOMMAND    "lp pause command"
  42.  
  43.  
  44. // Class variable with the string for the open/save panel's title.
  45. static const char *title;
  46.  
  47. @implementation Printers
  48.  
  49.  
  50. // ************************************************************************
  51. // Class methods:
  52. + initialize
  53. // Called once by the run time system
  54. {
  55.         title = [Service stringFor:"Title:Printers"];
  56.         return self;
  57. }
  58.  
  59. + new:sender at:(NXCoord *)offset
  60. {
  61. NIDirectory    *NIDir;
  62. Printers        *printer = [Printers alloc];
  63.  
  64.         if ((NIDir = [NIDirectory new:sender root:SMNI_PRINTERS directory:NULL])) {
  65.             [NIDir setDelegate:printer];
  66.             if ([printer init:sender dirObj:NIDir delta:offset service:NULL]) {
  67.                 [NIDir setSaveTitle:title];
  68.                 return printer;
  69.             }
  70.             [NIDir close];
  71.         }
  72.         return [printer free];
  73. }
  74.  
  75. + open:sender at:(NXCoord *)offset
  76. {
  77. NIDirectory    *NIDir;
  78. Printers        *printer = [Printers alloc];
  79.  
  80.         if ((NIDir = [NIDirectory open:sender root:SMNI_PRINTERS withTitle:title])) {        
  81.             [NIDir setDelegate:printer];
  82.             if ([printer init:sender dirObj:NIDir delta:offset service:[NIDir baseName]])
  83.                 return printer;
  84.  
  85.             [NIDir close];
  86.         }
  87.         return [printer free];
  88. }
  89.  
  90. // ************************************************************************
  91. //    Methods:
  92.  
  93. - (BOOL)minimumOK
  94. {
  95. const char *name = [textSambaName stringValue];
  96.  
  97.         if (strlen(name) > 15) {
  98.             NXRunAlertPanel(getString("Alert:Alert"),
  99.                                             getString("Message:Samba Name may have atmost 15 characters."),
  100.                                             getString("Button:OK"),NULL,NULL);
  101.             return NO;
  102.         }
  103.         if (*name && (strchr(name, '.') || strchr(name, ' '))) {
  104.             NXRunAlertPanel(getString("Alert:Alert"),
  105.                                             getString("Message:Samba Name may not contain dots or spaces."),
  106.                                             getString("Button:OK"),NULL,NULL);
  107.             return NO;
  108.         }
  109.         return YES;
  110. }
  111.  
  112. - setupAndLoad
  113. {        
  114. ni_id                cdir;
  115. ni_proplist    lprops;
  116. int                    i;
  117. BOOL                showNote = NO;
  118. const char    *sharedName;
  119. NIProperty    *remoteDir, *sharedDir, *sambaNameDir;
  120.  
  121.         sambaNameDir = [ni_dirObj addString:P_SAMBANAME outlet:textSambaName];
  122.         [ni_dirObj addString:P_NAME outlet:textUnixName];
  123.         [ni_dirObj addString:P_COMMENT outlet:textComment];
  124.         
  125.         [ni_dirObj addString:P_PRINTERDRIVER outlet:textDriver];
  126.         
  127.         [ni_dirObj addString:P_PRINTCOMMAND outlet:textPrint];
  128.         [ni_dirObj addString:P_LPRMCOMMAND outlet:textDelete];
  129.         [ni_dirObj addString:P_LPQCOMMAND outlet:textShowQueue];
  130.         [ni_dirObj addString:P_LPPAUSECOMMAND outlet:textResume];
  131.         [ni_dirObj addString:P_LPRESUMECOMMAND outlet:textPause];
  132.  
  133.         remoteDir = [ni_dirObj addProperty:P_REMOTE];
  134.         sharedDir = [ni_dirObj addProperty:P_SHAREDAS];
  135.  
  136.         // Check for a subdirectory P_COMMDIR with the property P_COMMHOST.
  137.         cdir = [ni_dirObj directoryID];
  138.         if (ni_pathsearch([ni_dirObj handle], &cdir, P_COMMDIR) == NI_OK) 
  139.             if ((ni_read([ni_dirObj handle], &cdir, &lprops)) == NI_OK) {
  140.                 for (i = 0; i < lprops.ni_proplist_len; i++)
  141.                     showNote|= !strcmp(P_COMMHOST, lprops.ni_proplist_val[i].nip_name);
  142.                 ni_proplist_free(&lprops);
  143.             }
  144.  
  145.         // Scan the loaded NetInfo values and update the GUI.
  146.         [ni_dirObj scan];
  147.  
  148.         showNote|= [remoteDir values];
  149.         
  150.         sharedName = [sharedDir valueAt:0];
  151.         if (*sharedName && !*[sambaNameDir valueAt:0]) {
  152.             [sambaNameDir insertValue:sharedName];
  153.             [textSambaName setStringValue:sharedName];
  154.         }
  155.  
  156.         [textUnixName setEditable:NO];
  157.         [textSambaName selectText:self];
  158.  
  159.         // We found an entry of a network printer. This could be attached to
  160.         // a NetInfo host or be a stand alone network printer. In the first
  161.         // case it would be better to run Samba on the host to which the printer
  162.         // is physically attatched, in the second case it would be better to 
  163.         // declare the printer from within Windows.
  164.         if (showNote) {
  165.             // Run a modal for the panel.
  166.             [NXApp runModalFor:notePanel];
  167.             [notePanel close];
  168.         }
  169.  
  170.         return self;
  171. }
  172.  
  173. // Actions from the note panel
  174. - noteOK:sender
  175. {
  176.         [NXApp stopModal];
  177.         return self;
  178. }
  179.  
  180. // ************************************************************************
  181. // Actions:
  182.  
  183. // ************************************************************************
  184. // Delegates:
  185.  
  186.  
  187. @end
  188.