Ejemplo n.º 1
0
/*
 * This program demonstrates the Cdk radio widget.
 *
 * Options (in addition to normal CLI parameters):
 *	-c	create the data after the widget
 *	-s SPOS	location for the scrollbar
 *	-t TEXT	title for the widget
 *
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKRADIO *radio      = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = "<C></5>Select a filename";
   char **item          = 0;
   const char *mesg[5];
   char temp[256];
   int selection, count;

   CDK_PARAMS params;

   CDKparseParams (argc, argv, &params, "cs:t:" CDK_CLI_PARAMS);

   /* Use the current diretory list to fill the radio list. */
   count = CDKgetDirectoryContents (".", &item);
   if (count <= 0)
   {
      fprintf (stderr, "Cannot get directory list\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Set up CDK Colors. */
   initCDKColor ();

   /* Create the radio list. */
   radio = newCDKRadio (cdkscreen,
			CDKparamValue (&params, 'X', CENTER),
			CDKparamValue (&params, 'Y', CENTER),
			CDKparsePosition (CDKparamString2 (&params,
							   's',
							   "RIGHT")),
			CDKparamValue (&params, 'H', 10),
			CDKparamValue (&params, 'W', 40),
			CDKparamString2 (&params, 't', title),
			CDKparamNumber (&params, 'c') ? 0 : (CDK_CSTRING2) item,
			CDKparamNumber (&params, 'c') ? 0 : count,
			'#' | A_REVERSE, 1,
			A_REVERSE,
			CDKparamValue (&params, 'N', TRUE),
			CDKparamValue (&params, 'S', FALSE));

   /* Check if the radio list is null. */
   if (radio == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the radio widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber (&params, 'c'))
   {
      setCDKRadioItems (radio, (CDK_CSTRING2) item, count);
   }

   /* loop until user selects a file, or cancels */
   for (;;)
   {
      /* Activate the radio list. */
      selection = activateCDKRadio (radio, 0);

      /* Check the exit status of the widget. */
      if (radio->exitType == vESCAPE_HIT)
      {
	 mesg[0] = "<C>You hit escape. No item selected.";
	 mesg[1] = "";
	 mesg[2] = "<C>Press any key to continue.";
	 popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
	 break;
      }
      else if (radio->exitType == vNORMAL)
      {
	 struct stat sb;

	 if (stat (item[selection], &sb) == 0
	     && (sb.st_mode & S_IFMT) == S_IFDIR)
	 {
	    char **nitem = 0;

	    mesg[0] = "<C>You selected a directory";
	    sprintf (temp, "<C>%.*s", (int)(sizeof (temp) - 20), item[selection]);
	    mesg[1] = temp;
	    mesg[2] = "";
	    mesg[3] = "<C>Press any key to continue.";
	    popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 4);
	    count = CDKgetDirectoryContents (item[selection], &nitem);
	    if (count > 0)
	    {
	       CDKfreeStrings (item);
	       item = nitem;
	       if (chdir (item[selection]) == 0)
		  setCDKRadioItems (radio, (CDK_CSTRING2) item, count);
	    }
	 }
	 else
	 {
	    mesg[0] = "<C>You selected the filename";
	    sprintf (temp, "<C>%.*s", (int)(sizeof (temp) - 20), item[selection]);
	    mesg[1] = temp;
	    mesg[2] = "";
	    mesg[3] = "<C>Press any key to continue.";
	    popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 4);
	    break;
	 }
      }
   }

   /* Clean up. */
   CDKfreeStrings (item);
   destroyCDKRadio (radio);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Ejemplo n.º 2
0
Archivo: fselect.c Proyecto: dyne/MuSE
/*
 * This creates a list of the files in the current directory.
 */
int setCDKFselectDirContents (CDKFSELECT *fselect)
{
   /* Declare local variables. */
   struct stat fileStat;
   char **dirList = 0;
   char temp[200], mode;
   int fileCount;
   int x = 0;

   /* Get the directory contents. */
   fileCount = CDKgetDirectoryContents (fselect->pwd, &dirList);
   if (fileCount == -1)
   {
      /* We couldn't read the directory. Return. */
      return 0;
   }

   /* Clean out the old directory list. */
   freeCharList (fselect->dirContents, fselect->fileCounter);
   fselect->fileCounter = fileCount;

   /* Set the properties of the files. */
   for (x=0; x < fselect->fileCounter; x++)
   {
      /* Stat the file. */
      lstat (dirList[x], &fileStat);

      /* Check the mode. */
      mode = ' ';
      if (((fileStat.st_mode & S_IXUSR) != 0) ||
		((fileStat.st_mode & S_IXGRP) != 0) ||
		((fileStat.st_mode & S_IXOTH) != 0))
      {
	  mode = '*';
      }

      /* Create the filename. */
      switch (mode2Filetype(fileStat.st_mode)) {
      case 'l':
	 sprintf (temp, "%s%s@", fselect->linkAttribute, dirList[x]);
	 break;
      case '@':
	 sprintf (temp, "%s%s&", fselect->sockAttribute, dirList[x]);
	 break;
      case '-':
	 sprintf (temp, "%s%s%c", fselect->fileAttribute, dirList[x], mode);
	 break;
      case 'd':
	 sprintf (temp, "%s%s/", fselect->dirAttribute, dirList[x]);
	 break;
      default:
	 sprintf (temp, "%s%c", dirList[x], mode);
	 break;
      }
      fselect->dirContents[x] = copyChar (temp);

      /* Free up this piece of memory. */
   }
   CDKfreeStrings (dirList);
   return 1;
}