
#import "clientDirector.h"
#import "UnderstudyAgent.h"
#import "PAStringList.h"

@implementation clientDirector

+ (BOOL)allowMultipleLoads
{
  return YES ;
}

- initWithController:aController andTag:(int)aTag 
{
  char nibPath[MAXPATHLEN+1] ;
  char actorPath[MAXPATHLEN+1] ;

  [super initWithController:aController andTag:aTag] ;

  if ([[NXBundle bundleForClass:[self class]] getPath:nibPath 
       forResource:"clientDirector" ofType:"nib"])
  {
    [NXApp loadNibFile:nibPath owner:self] ;
  }

  /* add a new actor */
  sprintf(actorPath, "%s/Library/Actors/RedBall.actor", getenv("HOME")) ;
  theClient=[self createNewActorFrom:actorPath] ;

  /* make sure attachments are allowed */
  [theClient setDropEnabled:YES] ;

  /* have the client subscribe to demoService */
  NXLogError("Telling actor (%s) to subscribe to demoService", [theClient alias]) ;
  [theClient subscribeTo:"demoService"] ;

  NXLogError("Client subscribed to demoService with server named %s", [[theClient server] alias]) ;

  return self ;
}

- activationOccurredOn:anActor 
{
  return self ;
}

- clearOccurredOn:anActor 
{
  return self ;
}

- didAddActor:anActor 
{
  return self ;
}

- documentWillClose 
{
  return self ;
}

- dragOccurredOn:anActor 
{
  return self ;
}

- dropOccurredOn:anActor 
{ 
  return self ;
}

- launchOccurredOn:anActor 
{ 
  return self ;
}

- specialActivationOccurredOn:anActor
{
  char **theAttachments ;
  int looper=-1 ;
  char theTitle[100] ;

  /* get the attachments on the actor */
  if (!(theAttachments=[anActor droppedFiles]))
  {				/* no attachments, so just show alert panel */
    NXRunAlertPanel([[self class] name], "Special Activation Occurred for %s", NULL, NULL, NULL,
		    [anActor alias]) ;
    return self ;
  }

  /* empty the stringHandler */
  [stringHandler freeStrings] ;

  /* fill the string handler with the attachment names */
  while (theAttachments[++looper])
  {
    [stringHandler addString:theAttachments[looper]] ;
  }

  /* have the attachmentsBrowser fill itself */
  [attachmentsBrowser loadColumnZero] ;

  /* change the title on the attachmentsPanel */
  sprintf(theTitle, "%s:Attachments for %s", [[self class] name], [anActor alias]) ;
  [attachmentsPanel setTitle:theTitle] ;

  /* bring up the attachmentsPanel */
  [attachmentsPanel makeKeyAndOrderFront:self] ;

  return self ;
}

- willEnterScreenSaverMode 
{
  return self ;
}

- willExitScreenSaverMode 
{
  return self ;
}

- willRemoveActor:anActor 
{ 
  return self ;
}

@end
