/*********************************************************************
 *
 *            EZFM---EZWGL based file manager for X11
 *
 *             Copyright (C) 1998  Maorong Zou
 *
 *
 *  This file is part of EZFM.
 *
 *  EZFM is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * EZFM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with EZFM; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *
 *************************************************************************/

#define _INFO_BTN_C_
#include "ezfm.h"

/**********************************************************************************/
void setupInfoButton  MY_ANSIARGS((void *btn, void *data));
void infoDialogue     MY_ANSIARGS((char *pathname, char *info_str,
				   struct stat *stat_ptr, char *comment));
/**********************************************************************************/
static int targetStartFilter MY_ANSIARGS((void *obj, void *data, char *msg, int len));
static int decodeFileInfo   MY_ANSIARGS((void *obj, void *data, char *message, int length));
static int decodeFileName   MY_ANSIARGS((void *obj, void *data, char *message, int length));
static void infoBtnCallback MY_ANSIARGS((void *widget, void *data));
/**********************************************************************************
 *
 * setup the info button
 */
void setupInfoButton(widget, data)
     void *widget; void *data;
{
  EZ_Widget *ibtn = (EZ_Widget *)widget;
  EZ_Widget *frame = (EZ_Widget *)data; /* parent frame */
  Toplevel  *toplevel;
  if(frame && (toplevel = (Toplevel *)EZ_GetWidgetPtrData(frame)) != NULL)
    EZ_AddWidgetCallBack(ibtn, EZ_CALLBACK, infoBtnCallback, toplevel, 0);
  
  EZ_WidgetAddDnDDataDecoder(ibtn, EZ_DND_DROP_START_ATOM, /* drop setup    */
			     0, targetStartFilter, NULL, NULL, NULL);
  EZ_WidgetAddDnDDataDecoder(ibtn, ezfmFileNameAtom, 0,
			     decodeFileName, NULL, NULL, NULL);
  EZ_WidgetAddDnDDataDecoder(ibtn, ezfmFileInfoAtom, 0,
			     decodeFileInfo, NULL, NULL, NULL);
}
/***************************************************************************
 *
 * decode start filter.
 */
static int targetStartFilter(obj, data, msg, len)
     void *obj; void *data; char *msg; int len;
{
  Atom          *atomsInOut, theAtom;
  int           *natomsInOut;
  unsigned int  *atypeOut;
  int           i, j, answer;
  char          *src = msg + PATHNAME_OFFSET;

  EZ_DnDGetMatchedConversionTargets(&atomsInOut,&natomsInOut, &atypeOut);  

  if(canSeeTheFile(src, msg)) theAtom = ezfmFileNameAtom;
  else theAtom = ezfmFileInfoAtom;
  for(j = 0, i = 0; i < *natomsInOut; i++)
    {
      Atom atom = atomsInOut[i]; 
      if(atom == theAtom) { atomsInOut[j++] = atom; break; }
    }
  *natomsInOut = j;
  return(0);
}
/***************************************************************************
 *
 * decode stat info
 */
static int decodeFileInfo(obj, data, message, length)
     void *obj; void *data; char *message; int length;
{
  if(length > HEADER_OFFSET)
    {
      char *pathname = message + PATHNAME_OFFSET;
      char *ptr = message + HEADER_OFFSET;
      infoDialogue(pathname, ptr, NULL, "File may reside in a foreign file system");
      return(EZ_DND_SUCCESS);      
    }
  return(EZ_DND_FAILURE);
}

/***************************************************************************
 *
 * for local file, get fileInfo from name
 */
static int decodeFileName(obj, data, message, length)
     void *obj; void *data; char *message; int length;
{
  if(length > PATHNAME_OFFSET)
    {
      char *pathname = message + PATHNAME_OFFSET;
      char info_str[512];
      struct stat  statbuf;
      if(getFileInfo(pathname, info_str, &statbuf) >= 90)
	infoDialogue(pathname, info_str, &statbuf, NULL);
      return(EZ_DND_SUCCESS);      
    }
  return(EZ_DND_FAILURE);
}
/*********************************************************************************
 *
 *    info button dialogue.
 */
static void infoBtnCallback(widget, data)
     EZ_Widget *widget; void *data;
{
  if(data)
    {
      Toplevel  *tp = (Toplevel *)data;
      Folder    **flds = tp->folder;
      EZ_Item   *item = NULL;

      item = getFolderSelection(flds[0]);
      if(item == NULL) item = getFolderSelection(flds[1]);

      /* display file info */
      if(item != NULL)
	{
	  FileInfo *p = (FileInfo *)EZ_GetItemPtrData(item);
	  if(p)
	    {
	      char info_str[512];
	      struct stat statbuf;
	      char *pathname = p->pathname;
	      if(getFileInfo(pathname, info_str, &statbuf) >= 90)
		infoDialogue(pathname, info_str, &statbuf, NULL);
	    }
	}
      else  ezfmWarning("File Info:", "You have to select a file first");
    }
}
/**************************************************************************/
static void btnCallback(widget, data) EZ_Widget *widget; void *data; 
{
  EZ_Widget *toplevel = (EZ_Widget *)data;
  EZ_DestroyWidget(toplevel);
}
/**************************************************************************
 *
 *                 Info dialogue
 */
typedef struct {
  int       smode;        /* saved access mode */
  int       mode;         /* access mode */
  EZ_Widget *toplevel;    /* toplevel frame */
  EZ_Widget *name;        /* entry for change file name */
  EZ_Widget *owner;       /* entry for change owner, group */
  EZ_Widget *group;
  EZ_Widget *applybtn;    /* the apply button */
  char      *pathname;
  char      *ownername;
  char      *groupname;
} infoControl;
/**************************************************************************/
static void applyDestroyCallback(widget, data) EZ_Widget *widget; void *data; 
{
  infoControl *ptr = (infoControl *)data;
  (void)EZ_Free((char *)ptr->ownername);
  (void)EZ_Free((char *)ptr->groupname);
  (void)EZ_Free((char *)ptr->pathname);
  (void)EZ_Free((char *)ptr);    
}
static int infoControlChanged(ptr) infoControl *ptr;
{
  int changed = 0;
  if(ptr->smode != ptr->mode) changed = 1;
  if(changed == 0)
    {
      char *p = EZ_GetEntryString(ptr->owner);
      changed = 1;
      if(!strcmp(p, ptr->ownername))
	{
	  char *p =  EZ_GetEntryString(ptr->group);
	  if(!strcmp(p, ptr->groupname))
	    {
	      char *p =  EZ_GetEntryString(ptr->name);
	      if(!strcmp(p, ptr->pathname))
		changed = 0;
	    }
	}
    }
  return(changed);
}

static void applyCallback(widget, data) EZ_Widget *widget; void *data; 
{
  infoControl *ptr = (infoControl *)data;
  EZ_Widget *toplevel = ptr->toplevel;
  int haserr = 0;
  struct stat statbuf;

  if(lstat(ptr->pathname, &statbuf) >= 0)
    {
      if(statbuf.st_mode != ptr->mode)
	{
	  if(chmod(ptr->pathname, ptr->mode) != 0)
	    {
	      char *err= (errno >= 0 && errno <sys_nerr)? 
		sys_errlist[errno] : "Unknown error";
	      ezfmWarning("chmod() failed due to the following error", err);
	      haserr++;
	    }
	}
      /* ownership */
      {
	char *owner, *group;
	int   uid,   gid;
	struct passwd *pswd;
	struct group *grp;
	owner = EZ_GetEntryString(ptr->owner);
	group = EZ_GetEntryString(ptr->group);
	
	if( (pswd = getpwnam(owner)) == NULL)
	  {
	    ezfmWarning("chown() failed due to the following error", "Bad login name");
	    haserr++;
	  }
	else
	  {
	    if((grp = getgrnam(group)) == NULL)
	      {
		ezfmWarning("chown() failed due to the following error", "Bad group name");
		haserr++;
	      }
	    else if(statbuf.st_uid != pswd->pw_uid || statbuf.st_gid != grp->gr_gid)
	      {
		if(chown(ptr->pathname, pswd->pw_uid, grp->gr_gid) != 0)
		  {
		    char *err= (errno >= 0 && errno <sys_nerr)? 
		      sys_errlist[errno] : "Unknown error";
		    ezfmWarning("chown() failed due to the following error", err);
		    haserr++;
		  }
	      }
	  }
      }
      /* rename */
      {
	char *nname = EZ_GetEntryString(ptr->name);
	if(*nname && strcmp(nname, ptr->pathname))
	  {
	    if(rename(ptr->pathname, nname) < 0)
	      {
		char *err= (errno >= 0 && errno <sys_nerr)? 
		  sys_errlist[errno] : "Unknown error";
		ezfmWarning("rename() failed due to the following error", err);
		haserr++;	      
	      }
	  }
      }
    }
  else  { ezfmWarning("Cannot stat", ptr->pathname); haserr++;}
  
  if(haserr == 0) EZ_DestroyWidget(toplevel);
}
/**************************************************************************/
static void entryMotionCallback(widget, data) 
     EZ_Widget *widget; void *data;
{
  infoControl *ptr = (infoControl *)data;
  if(infoControlChanged(ptr)) EZ_EnableWidget(ptr->applybtn);
  else   EZ_DisableWidget(ptr->applybtn);    
}
static void entryEventHandler(widget, data, etype, xev)
     EZ_Widget *widget; void *data; int etype; XEvent *xev;
{
  if(xev->type == KeyPress)
    {
      infoControl *ptr = (infoControl *)data;
      if(infoControlChanged(ptr)) EZ_EnableWidget(ptr->applybtn);
      else   EZ_DisableWidget(ptr->applybtn);    
    }
}
/**************************************************************************/
static void setmode(widget, data)  EZ_Widget *widget; void *data; 
{
  char str[12];
  infoControl *ptr = (infoControl *)data;
  EZ_Widget *clabel = (EZ_Widget *)EZ_GetWidgetPtrData(widget);
  int st_mode = ptr->mode;
  int junk, state = EZ_GetCheckButtonState(widget, &junk);
  int mask = EZ_GetWidgetIntData(widget);
  int idx, changed = 0;

  if(state) st_mode |= mask;
  else st_mode &= ~mask;
  ptr->mode = st_mode;
  if((mask & (S_IRUSR|S_IWUSR|S_IXUSR))) idx = 1;
  else if((mask & (S_IRGRP|S_IWGRP|S_IXGRP))) idx = 4;
  else idx = 7;
  strStMode(str,st_mode);
  str[idx+3] = '\0';
  EZ_ConfigureWidget(clabel, EZ_LABEL_STRING, str+idx, NULL);
  if(infoControlChanged(ptr)) EZ_EnableWidget(ptr->applybtn);
  else   EZ_DisableWidget(ptr->applybtn);    
}
/*****************************************************************************/
static void permissionRow(tframe, str, idx, mode, rr,ww,xx, data)
     EZ_Widget *tframe; char *str; int idx, mode,rr,ww,xx; void *data;
{
  EZ_Widget *clabel, *label;
  char labstr[12];
  int sidx = ((rr== S_IRUSR)? 1: (rr == S_IRGRP) ?4:7);
  strStMode(labstr,mode);
  labstr[sidx+3] = '\0';
  
  clabel =     EZ_CreateWidget(EZ_WIDGET_LABEL,        tframe,  /* to disp the perm string */
			       EZ_LABEL_STRING,        labstr+sidx,
			       EZ_PADX,                16,
			       EZ_PADY,                0,
			       EZ_FOREGROUND,          "blue",
			       EZ_FONT_ID,             ezfmFontId[LABEL_MEDIUM_FONT],
			       EZ_GRID_CELL_GEOMETRY,  5, idx , 1, 1, 
			       EZ_PROPAGATE,           False,
			       NULL);

  label =      EZ_CreateWidget(EZ_WIDGET_LABEL,       tframe,
			       EZ_LABEL_STRING,       str,
			       EZ_GRID_CELL_GEOMETRY,  0, idx , 1, 1, 
			       EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_RIGHT,
			       EZ_LABEL_POSITION,     EZ_RIGHT,
			       NULL);
  label =      EZ_CreateWidget(EZ_WIDGET_CHECK_BUTTON, tframe,
			       EZ_LABEL_STRING,        "read",
			       EZ_PADX,                 0,
			       EZ_PADY,                 0,
			       EZ_FONT_ID,              ezfmFontId[LABEL_MEDIUM_FONT],
			       EZ_CHECK_BUTTON_ON_OFF,  rr&mode,
			       EZ_GRID_CELL_GEOMETRY,  2, idx , 1, 1,
			       EZ_CLIENT_INT_DATA,     rr,
			       EZ_CLIENT_PTR_DATA,     clabel,
			       EZ_CALLBACK,            setmode, data,
			       NULL);
  label =      EZ_CreateWidget(EZ_WIDGET_CHECK_BUTTON, tframe,
			       EZ_LABEL_STRING,        "write",
			       EZ_PADX,                 0,
			       EZ_PADY,                 0,
			       EZ_FONT_ID,              ezfmFontId[LABEL_MEDIUM_FONT],
			       EZ_CHECK_BUTTON_ON_OFF,  ww&mode,
			       EZ_CLIENT_INT_DATA,     ww,
			       EZ_CLIENT_PTR_DATA,     clabel,
			       EZ_GRID_CELL_GEOMETRY,  3, idx , 1, 1, 
			       EZ_CALLBACK,            setmode, data,
			       NULL);
  label =      EZ_CreateWidget(EZ_WIDGET_CHECK_BUTTON, tframe,
			       EZ_LABEL_STRING,        "execute",
			       EZ_PADX,                 0,
			       EZ_PADY,                 0,
			       EZ_FONT_ID,              ezfmFontId[LABEL_MEDIUM_FONT],
			       EZ_CLIENT_INT_DATA,      xx,
			       EZ_CLIENT_PTR_DATA,     clabel,
			       EZ_CHECK_BUTTON_ON_OFF,  xx&mode,
			       EZ_GRID_CELL_GEOMETRY,  4, idx , 1, 1, 
			       EZ_CALLBACK,            setmode, data,
			       NULL);
}

void infoDialogue(pathname, info_str, statptr, comment)
     char *pathname, *info_str; char *comment; struct stat *statptr;
{
  EZ_Widget *infoToplevel, *nb, *page1, *page2, *label;
  EZ_Widget *bbox, *closebtn, *applybtn;

  infoToplevel = EZ_CreateWidgetXrm(EZ_WIDGET_FRAME,     NULL,
				    "InfoDialogue",      "infoDialogue",
				    EZ_FILL_MODE,        EZ_FILL_BOTH,
				    EZ_ORIENTATION,      EZ_VERTICAL,
				    EZ_IPADY,            10,
				    EZ_TRANSIENT,       True,  
				    EZ_BG_PIXMAP,          bigPixmap, 
				    EZ_EVENT_HANDLER,      ConfigureNotifyHandler, NULL,
				    NULL);
  nb =              EZ_CreateWidget(EZ_WIDGET_NOTEBOOK,    infoToplevel,
				    NULL);
  /* bottom button box */
  bbox =            EZ_CreateWidget(EZ_WIDGET_FRAME,    infoToplevel,
				    EZ_LABEL_STRING,    " ",    /* !!! */
				    EZ_HEIGHT,          0,
				    NULL);
  closebtn =        EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON, bbox,
				    EZ_LABEL_STRING,       "Close",
				    EZ_UNDERLINE,           0,
				    EZ_CALLBACK,            btnCallback, infoToplevel,
				    NULL); 

  /* now fill up the two pages on nb */
  {
    page1 =           EZ_CreateWidgetXrm(EZ_WIDGET_NB_PAGE, nb,  /* basic info page */
					 "InfoPage1", "infoPage1",
					 EZ_LABEL_STRING,   "Info",
					 EZ_UNDERLINE,       0,
					 EZ_PADY,            10,
					 EZ_IPADY,           2,
					 EZ_FONT_ID,         ezfmFontId[LABEL_LARGE_FONT],
					 EZ_TEXT_LINE_LENGTH,100,    /*idx   min weight pad */ 
					 EZ_GRID_CONSTRAINS, EZ_COLUMN,  0,   80,  0,   0,
					 EZ_GRID_CONSTRAINS, EZ_COLUMN,  1,   200, 0,  0,
					 NULL);
    /* pathname */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Pathname:",
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_PADY,               3,
				      EZ_GRID_CELL_GEOMETRY,  0, 0 , 1, 1,
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        pathname,
				       EZ_TEXT_LINE_LENGTH,    80,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_PADY,                0,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 0 , 1, 1,
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
  
    /* size */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Size:",
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_PADY,               3,
				      EZ_GRID_CELL_GEOMETRY,  0, 1 , 1, 1,
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_PADY,                0,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 1 , 1, 1,
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
    /* mtime */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Modified:",
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_PADY,               3,
				      EZ_GRID_CELL_GEOMETRY,  0, 2 , 1, 1,			 
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str+20,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_PADY,                0,
				       EZ_GRID_CELL_GEOMETRY,  1, 2 , 1, 1,	 
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
    /* owner */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Owner:",
				      EZ_PADY,               3,
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_GRID_CELL_GEOMETRY,  0, 3 , 1, 1, 
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str+50,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_PADY,                0,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 3 , 1, 1,	 
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
    /* group */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Group:",
				      EZ_PADY,               3,
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_GRID_CELL_GEOMETRY,  0, 4 , 1, 1,
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str+60,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_PADY,                0,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 4 , 1, 1,	 
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
    /* mode */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Permision:",
				      EZ_PADY,               3,
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_GRID_CELL_GEOMETRY,  0, 5 , 1, 1,				 
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str+70,
				       EZ_PADY,                0,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 5 , 1, 1,	 
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
    /* nlink */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Num Links:",
				      EZ_PADY,               3,
				      EZ_LABEL_POSITION,     EZ_RIGHT,
				      EZ_GRID_CELL_GEOMETRY,  0, 6 , 1, 1,				 
				      EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str+85,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_PADY,                0,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 6 , 1, 1,	 
				       EZ_GRID_CELL_PLACEMENT,EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				       NULL);
    /* type info */
    label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
				      EZ_LABEL_STRING,       "Type:",
				      EZ_PADY,                3,
				      EZ_LABEL_POSITION,      EZ_RIGHT,
				      EZ_GRID_CELL_GEOMETRY,  0, 7 , 1, 1,
				      EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_RIGHT,
				      NULL);
    label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
				       EZ_LABEL_STRING,        info_str+90,
				       EZ_TEXT_LINE_LENGTH,    60,
				       EZ_PADY,                0,
				       EZ_LABEL_POSITION,      EZ_LEFT,
				       EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
				       EZ_GRID_CELL_GEOMETRY,  1, 7 , 1, 1,	 
				       EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_LEFT,
				       NULL);
    /* comments */
    if(comment)
      {
	label =           EZ_CreateWidget(EZ_WIDGET_LABEL,       page1,
					  EZ_LABEL_STRING,       "Comment:",
					  EZ_FOREGROUND,         "red",
					  EZ_PADY,                3,
					  EZ_LABEL_POSITION,      EZ_RIGHT,
					  EZ_GRID_CELL_GEOMETRY,  0, 8 , 1, 1,
					  EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_RIGHT,
					  NULL);
	label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        page1,
					   EZ_LABEL_STRING,        comment,
					   EZ_FOREGROUND,         "red",
					   EZ_TEXT_LINE_LENGTH,    60,
					   EZ_PADY,                0,
					   EZ_LABEL_POSITION,      EZ_LEFT,
					   EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
					   EZ_GRID_CELL_GEOMETRY,  1, 8 , 1, 1,	 
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_LEFT,
					   NULL);

      }

    
    if(statptr != NULL) /* for local files, create the permission page */
      { 
	EZ_Widget     *tframe, *bframe, *entry;
	int           mode = statptr->st_mode;
	infoControl   *icptr = (infoControl *)EZ_Malloc(sizeof(infoControl));

	icptr->toplevel = infoToplevel;
	icptr->smode = mode;
	icptr->mode = mode;
	icptr->pathname = EZ_AllocCopyString(pathname);
	icptr->ownername = EZ_AllocCopyString(info_str+50);
	icptr->groupname = EZ_AllocCopyString(info_str+60);

	applybtn =     EZ_CreateWidget(EZ_WIDGET_NORMAL_BUTTON,bbox,
				       EZ_LABEL_STRING,       "Apply",
				       EZ_UNDERLINE,           0,
				       EZ_CALLBACK,            applyCallback, icptr,
				       EZ_DESTROY_CALLBACK,    applyDestroyCallback, icptr,
				       NULL); 
	icptr->applybtn = applybtn;
	EZ_DisableWidget(applybtn);

	page2 =       EZ_CreateWidgetXrm(EZ_WIDGET_NB_PAGE, nb,  /* basic info page */
					 "InfoPage2", "infoPage2",
					 EZ_LABEL_STRING,   "Permissions",
					 EZ_FONT_ID,         ezfmFontId[LABEL_LARGE_FONT],
					 EZ_UNDERLINE,       0,
					 EZ_FILL_MODE,       EZ_FILL_BOTH,
					 EZ_ORIENTATION,     EZ_VERTICAL,
					 NULL);

	bframe =     EZ_CreateWidget(EZ_WIDGET_FRAME,     page2,
				     EZ_LABEL_STRING,     "Ownership",
				     EZ_GRID_CONSTRAINS, EZ_ROW,     1,   20,  0,   0,
				     NULL);

	tframe =     EZ_CreateWidget(EZ_WIDGET_FRAME,     page2,
				     EZ_LABEL_STRING,     "Access Permissions",
				     EZ_GRID_CONSTRAINS,   EZ_COLUMN,  1,   10,  0,   0,
				     NULL);

	permissionRow(tframe, "User:",  0, mode, S_IRUSR, S_IWUSR, S_IXUSR, icptr);
	permissionRow(tframe, "Group:", 1, mode, S_IRGRP, S_IWGRP, S_IXGRP, icptr);
	permissionRow(tframe, "Other:", 2, mode, S_IROTH, S_IWOTH, S_IXOTH, icptr);
	
	/* owner info */
	label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        bframe,
					   EZ_LABEL_STRING,        "Name:",
					   EZ_PADY,                0,
					   EZ_LABEL_POSITION,      EZ_RIGHT,
					   EZ_GRID_CELL_GEOMETRY,  1, 0 , 1, 1,	 
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_RIGHT,
					   NULL);
	
	label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        bframe,
					   EZ_LABEL_STRING,        "Owner:",
					   EZ_PADY,                0,
					   EZ_LABEL_POSITION,      EZ_RIGHT,
					   EZ_GRID_CELL_GEOMETRY,  1, 2 , 1, 1,	 
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_RIGHT,
					   NULL);
	label =            EZ_CreateWidget(EZ_WIDGET_LABEL,        bframe,
					   EZ_LABEL_STRING,        "Group:",
					   EZ_PADY,                0,
					   EZ_LABEL_POSITION,      EZ_RIGHT,
					   EZ_GRID_CELL_GEOMETRY,  1, 3 , 1, 1,	 
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_HORIZONTALLY, EZ_RIGHT,
					   NULL);
	
	entry =            EZ_CreateWidget(EZ_WIDGET_ENTRY,        bframe,
					   EZ_ENTRY_STRING,        pathname,
					   EZ_TEXT_LINE_LENGTH,    30,
					   EZ_FOREGROUND,          "blue",
					   EZ_BORDER_WIDTH,        1,
					   EZ_GRID_CELL_GEOMETRY,  2, 0 , 1, 1,	 
					   EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],	
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_NONE, EZ_RIGHT,
					   EZ_MOTION_CALLBACK,     entryMotionCallback, icptr,
					   NULL);
	icptr->name = entry;
	entry =            EZ_CreateWidget(EZ_WIDGET_ENTRY,        bframe,
					   EZ_ENTRY_STRING,        info_str+50,
					   EZ_TEXT_LINE_LENGTH,    30,
					   EZ_BORDER_WIDTH,        1,
					   EZ_GRID_CELL_GEOMETRY,  2, 2 , 1, 1,	 
					   EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],	
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_NONE, EZ_RIGHT,
					   EZ_MOTION_CALLBACK,     entryMotionCallback, icptr,
					   NULL);
	icptr->owner = entry;
	entry =            EZ_CreateWidget(EZ_WIDGET_ENTRY,        bframe,
					   EZ_ENTRY_STRING,        info_str+60,
					   EZ_TEXT_LINE_LENGTH,    30,
					   EZ_BORDER_WIDTH,        1,
					   EZ_GRID_CELL_GEOMETRY,  2, 3 , 1, 1,	 
					   EZ_FONT_ID,             ezfmFontId[ITEM_MEDIUM_FONT],
					   EZ_GRID_CELL_PLACEMENT, EZ_FILL_NONE, EZ_RIGHT,
					   EZ_MOTION_CALLBACK,     entryMotionCallback, icptr,
					   NULL);
	icptr->group = entry;
      }
  }
  EZ_DisplayWidgetUnderPointer(closebtn, -10, -10);
  EZ_SetFocusTo(closebtn);
}
/**************************************************************************************/
#undef _INFO_BTN_C
