/******************************************************************************
 *
 * RCS ID
 * $Id: globals,v 1.4 2000/04/22 14:51:09 david Exp $
 *
 * HISTORY
 * $Log: globals,v $
 * Revision 1.4  2000/04/22 14:51:09  david
 * Updates for nmbd module debugging.
 * Updates for integrating nmbd with main smbserver application
 *
 * Revision 1.3  2000/01/29 17:24:46  david
 * Changed message and event handler registering to be driver by tables.
 *
 * Revision 1.2  2000/01/11 20:17:54  david
 * Added a define to split out booleans into General, File Create
 * and Filename read options. Not released yet - just playing with it.
 * Checked that !smbconfig will compile standalone.
 *
 * Revision 1.1  1999/11/07 15:15:19  david
 * New WIMP configuration using toolbox libs
 *
 *
 *
 *****************************************************************************/                    


#include <stdlib.h>
#include <string.h>
#include <stdio.h>  
#include "kernel.h"
#include "swis.h"
#include "wimp.h"
#include "toolbox.h"
#include "event.h"
#include "wimplib.h"
#include "proginfo.h"
#include "quit.h"   
#include "gadgets.h"
#include "version.h"


#include "includes.h"
#include "smb.h"

#include "smbconfig.h"

extern fstring global_myworkgroup;


int globWindAboutToBeShown(int event_code,
                           ToolboxEvent *event,
                           IdBlock *id_block,
                           void *handle)
{           
 



  tpGadgetList aGadget,after;                             
  int before;  

  if (GlobWindGadgets==NULL)
  {


    addWindowGadgets(&GlobWindGadgets,
                     id_block->self_id, 
                     0,
                     P_GLOBAL);    
             
    before = -1;          
    after = NULL;
    aGadget=GlobWindGadgets;
    while (aGadget!=NULL)
    {
      if (aGadget->agadget.hdr.type == WritableField_Base)
      {          
         if (after!=NULL)                        
         {
            after->agadget.data.writable_field.after=
               aGadget->agadget.hdr.component_id;
         }
         after=aGadget;
         aGadget->agadget.data.writable_field.before = before;
         before = aGadget->agadget.hdr.component_id;
      }
      aGadget=aGadget->next;
    }    
  }

  fillInGadgetFields(id_block->self_id,
                     GlobWindGadgets,
                     0);

  return 1;
}
                   
void globWindOk(ObjectId winId)
{  
  BOOL oldNameserverEnabled,newNameserverEnabled;

  if (haveGadgetFieldsChanged(winId,
                      GlobWindGadgets,
                      0)==True)
  {   
     oldNameserverEnabled = lp_nameserver_enabled();

     storeInGadgetFields(winId,
                         GlobWindGadgets,
                         0);
     window_set_title(0,TopWindId,"Samba Server Configuration *");
     window_set_title(0,GlobWindId,"Global Variables *");
     optionsChanged = True;

     /* copy the workgroup in case it has changed! */
     fstrcpy(global_myworkgroup, lp_workgroup());    

     newNameserverEnabled = lp_nameserver_enabled();

     if (oldNameserverEnabled==False && newNameserverEnabled==True)
     {
        nmbd_init();
     }
     else
     if (oldNameserverEnabled==True && newNameserverEnabled==False)
     {
        nmbd_stop(True);
     }
  }
}             



