예제 #1
0
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKVIEWER *example   = 0;
   CDKFSELECT *fSelect  = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = "<C>Pick\n<C>A\n<C>File";
   const char *label    = "File: ";
   char **info          = 0;
   const char *button[5];
   const char *mesg[4];
   char *filename;
   char vTitle[256];
   char temp[256];
   int selected, lines;

   CDK_PARAMS params;
   char *directory;

   CDKparseParams (argc, argv, &params, "d:" CDK_CLI_PARAMS);
   directory = CDKparamString2 (&params, 'd', ".");

   /* Create the viewer buttons. */
   button[0] = "</5><OK><!5>";
   button[1] = "</5><Cancel><!5>";

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

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   fSelect = newCDKFselect (cdkscreen,
			    CDKparamValue (&params, 'X', CENTER),
			    CDKparamValue (&params, 'Y', CENTER),
			    CDKparamValue (&params, 'H', 20),
			    CDKparamValue (&params, 'W', 65),
			    title, label, A_NORMAL, '_', A_REVERSE,
			    "</5>", "</48>", "</N>", "</N>",
			    CDKparamValue (&params, 'N', TRUE),
			    CDKparamValue (&params, 'S', FALSE));

   if (fSelect == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK ();

      fprintf (stderr, "Cannot create widget\n");
      ExitProgram (EXIT_FAILURE);
   }

   bindCDKObject (vFSELECT, fSelect, '?', do_help, NULL);
   bindCDKObject (vFSELECT, fSelect, KEY_F1, do_help, NULL);
   bindCDKObject (vFSELECT, fSelect, KEY_F2, do_delete, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F3, do_delete1, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F4, do_reload, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F5, do_undo, fSelect);

   /*
    * Set the starting directory. This is not necessary because when
    * the file selector starts it uses the present directory as a default.
    */
   setCDKFselect (fSelect, directory, A_NORMAL, ' ', A_REVERSE,
		  "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box);
   myUserList = copyCharList ((const char **)getCDKFselectContents (fSelect, &userSize));
   myUndoList = (UNDO *) malloc ((size_t) userSize * sizeof (UNDO));
   undoSize = 0;

   /* Activate the file selector. */
   filename = activateCDKFselect (fSelect, 0);

   /* Check how the person exited from the widget. */
   if (fSelect->exitType == vESCAPE_HIT)
   {
      /* Pop up a message for the user. */
      mesg[0] = "<C>Escape hit. No file selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);

      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      ExitProgram (EXIT_SUCCESS);
   }

   /* Create the file viewer to view the file selected. */
   example = newCDKViewer (cdkscreen, CENTER, CENTER, 20, -2,
			   (CDK_CSTRING2)button, 2, A_REVERSE, TRUE, FALSE);

   /* Could we create the viewer widget? */
   if (example == 0)
   {
      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Can't seem to create viewer. Is the window too small?\n");
      ExitProgram (EXIT_SUCCESS);
   }

   /* Open the file and read the contents. */
   lines = CDKreadFile (filename, &info);
   if (lines == -1)
   {
      filename = copyChar (filename);

      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Could not open \"%s\"\n", filename);

      ExitProgram (EXIT_FAILURE);
   }

   /* Set up the viewer title, and the contents to the widget. */
   sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename);
   setCDKViewer (example, vTitle,
		 (CDK_CSTRING2)info, lines,
		 A_REVERSE, TRUE, TRUE, TRUE);

   CDKfreeStrings (info);

   /* Destroy the file selector widget. */
   destroyCDKFselect (fSelect);

   /* Activate the viewer widget. */
   selected = activateCDKViewer (example, 0);

   /* Check how the person exited from the widget. */
   if (example->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>Escape hit. No Button selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }
   else if (example->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected button %d", selected);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }

   /* Clean up. */
   destroyCDKViewer (example);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
예제 #2
0
파일: radio_ex.c 프로젝트: lavenliu/linuxc
/*
 * 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);
}
예제 #3
0
/*
 * This program demonstrates the Cdk calendar widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen		= 0;
   CDKCALENDAR *calendar	= 0;
   const char *mesg[5];
   char temp[256];
   struct tm *dateInfo;
   time_t clck, retVal;

   CDK_PARAMS params;
   char *title;
   int day;
   int month;
   int year;

   /*
    * Get the current dates and set the default values for
    * the day/month/year values for the calendar.
    */
   time (&clck);
   dateInfo	= gmtime (&clck);

   /* *INDENT-EQLS* */
   CDKparseParams (argc, argv, &params, "d:m:y:t:w:" CDK_MIN_PARAMS);
   day   = CDKparamNumber2 (&params, 'd', dateInfo->tm_mday);
   month = CDKparamNumber2 (&params, 'm', dateInfo->tm_mon + 1);
   year  = CDKparamNumber2 (&params, 'y', dateInfo->tm_year + 1900);
   title = CDKparamString2 (&params, 't', "<C></U>CDK Calendar Widget\n<C>Demo");

   cdkscreen = initCDKScreen (NULL);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the calendar widget. */
   calendar = newCDKCalendar (cdkscreen,
			      CDKparamValue (&params, 'X', CENTER),
			      CDKparamValue (&params, 'Y', CENTER),
			      title, day, month, year,
			      COLOR_PAIR (16) | A_BOLD,
			      COLOR_PAIR (24) | A_BOLD,
			      COLOR_PAIR (32) | A_BOLD,
			      COLOR_PAIR (40) | A_REVERSE,
			      CDKparamValue (&params, 'N', TRUE),
			      CDKparamValue (&params, 'S', FALSE));

   /* Is the widget null? */
   if (calendar == 0)
   {
      /* Clean up the memory. */
      destroyCDKScreen (cdkscreen);

      /* End curses... */
      endCDK ();

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

   /* Create a key binding to mark days on the calendar. */
   bindCDKObject (vCALENDAR, calendar, 'm', createCalendarMarkCB, calendar);
   bindCDKObject (vCALENDAR, calendar, 'M', createCalendarMarkCB, calendar);
   bindCDKObject (vCALENDAR, calendar, 'r', removeCalendarMarkCB, calendar);
   bindCDKObject (vCALENDAR, calendar, 'R', removeCalendarMarkCB, calendar);

   calendar->weekBase = CDKparamNumber (&params, 'w');

   /* Draw the calendar widget. */
   drawCDKCalendar (calendar, ObjOf (calendar)->box);

   /* Let the user play with the widget. */
   retVal = activateCDKCalendar (calendar, 0);

   /* Check which day they selected. */
   if (calendar->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No date selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (calendar->exitType == vNORMAL)
   {
      mesg[0] = "You selected the following date";
      sprintf (temp, "<C></B/16>%02d/%02d/%d (dd/mm/yyyy)",
	       calendar->day,
	       calendar->month,
	       calendar->year);
      mesg[1] = temp;
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }

   /* Clean up and exit. */
   destroyCDKCalendar (calendar);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   fflush (stdout);
   printf ("Selected Time: %s\n", ctime (&retVal));
   ExitProgram (EXIT_SUCCESS);
}
예제 #4
0
/*
 * This program demonstrates the Cdk selection 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)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKSELECTION *selection	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C></5>Pick one or more accounts.";
   char *choices[]		= {"   ", "-->"};
   char **item = 0;
   char temp[256], *mesg[200];
   struct passwd *ent;
   unsigned x, y;
   unsigned used = 0;
   unsigned count = 0;

   CDK_PARAMS params;

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

   /* Use the account names to create a list. */
   count = 0;
   while ((ent = getpwent ()) != 0)
   {
      used = CDKallocStrings(&item, ent->pw_name, count++, used);
   }
   endpwent();
   count--;

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

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

   /* Create the selection list. */
   selection = newCDKSelection (cdkscreen,
				CDKparamValue(&params, 'X', CENTER),
				CDKparamValue(&params, 'Y', CENTER),
				CDKparsePosition(CDKparamString2(&params, 's', "RIGHT")),
				CDKparamValue(&params, 'H', 10),
				CDKparamValue(&params, 'W', 50),
				CDKparamString2(&params, 't', title),
				CDKparamNumber(&params, 'c') ? 0 : item,
				CDKparamNumber(&params, 'c') ? 0 : count,
				choices, 2,
				A_REVERSE,
				CDKparamValue(&params, 'N', TRUE),
				CDKparamValue(&params, 'S', FALSE));

   /* Is the selection list null? */
   if (selection == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message and exit. */
      printf ("Oops. Can;t seem to create the selection list. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber(&params, 'c'))
   {
      setCDKSelectionItems (selection, item, count);
   }

   /* Activate the selection list. */
   activateCDKSelection (selection, 0);

   /* Check the exit status of the widget. */
   if (selection->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No items selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (selection->exitType == vNORMAL)
   {
      mesg[0] = "<C>Here are the accounts you selected.";
      y = 1;
      for (x=0; x < count; x++)
      {
	 if (selection->selections[x] == 1)
	 {
	    sprintf (temp, "<C></5>%.*s", (int)(sizeof(temp) - 20), item[x]);
	    mesg[y++] = copyChar (temp);
	 }
      }
      popupLabel (cdkscreen, mesg, y);

      /* Clean up. */
      for (x=1; x < y; x++)
      {
	  freeChar (mesg[x]);
      }
   }

   /* Clean up. */
   CDKfreeStrings (item);
   destroyCDKSelection (selection);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
예제 #5
0
/*
 * This program demonstrates the file selector and the viewer widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKVIEWER *example   = 0;
   CDKFSELECT *fSelect  = 0;
   char **info          = 0;
   const char *button[5];
   char vTitle[256];
   const char *mesg[4];
   char temp[256];
   int selected, lines;

   CDK_PARAMS params;
   char *filename;		/* specify filename, bypassing fselect */
   char *directory;		/* specify starting directory for fselect */
   int interp_it;		/* interpret embedded markup */
   int link_it;			/* load file via embedded link */

   CDKparseParams (argc, argv, &params, "f:d:il" CDK_CLI_PARAMS);
   /* *INDENT-EQLS* */
   filename     = CDKparamString (&params, 'f');
   directory    = CDKparamString2 (&params, 'd', ".");
   interp_it    = CDKparamNumber2 (&params, 'i', FALSE);
   link_it      = CDKparamNumber2 (&params, 'l', FALSE);

   /* Create the viewer buttons. */
   button[0] = "</5><OK><!5>";
   button[1] = "</5><Cancel><!5>";

   cdkscreen = initCDKScreen (NULL);

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   if (filename == 0)
   {
      const char *title = "<C>Pick\n<C>A\n<C>File";
      const char *label = "File:  ";

      fSelect = newCDKFselect (cdkscreen,
			       CDKparamValue (&params, 'X', CENTER),
			       CDKparamValue (&params, 'Y', CENTER),
			       CDKparamValue (&params, 'H', 20),
			       CDKparamValue (&params, 'W', 65),
			       title, label, A_NORMAL, '_', A_REVERSE,
			       "</5>", "</48>", "</N>", "</N>",
			       CDKparamValue (&params, 'N', TRUE),
			       CDKparamValue (&params, 'S', FALSE));
      if (fSelect == 0)
      {
	 destroyCDKScreen (cdkscreen);
	 endCDK ();

	 fprintf (stderr, "Cannot create fselect-widget\n");
	 ExitProgram (EXIT_FAILURE);
      }

      /*
       * Set the starting directory. This is not necessary because when
       * the file selector starts it uses the present directory as a default.
       */
      setCDKFselect (fSelect, directory, A_NORMAL, '.', A_REVERSE,
		     "</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box);

      /* Activate the file selector. */
      filename = activateCDKFselect (fSelect, 0);

      /* Check how the person exited from the widget. */
      if (fSelect->exitType == vESCAPE_HIT)
      {
	 /* Pop up a message for the user. */
	 mesg[0] = "<C>Escape hit. No file selected.";
	 mesg[1] = "";
	 mesg[2] = "<C>Press any key to continue.";
	 popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);

	 /* Exit CDK. */
	 destroyCDKFselect (fSelect);
	 destroyCDKScreen (cdkscreen);
	 endCDK ();
	 ExitProgram (EXIT_SUCCESS);
      }
   }

   /* Create the file viewer to view the file selected. */
   example = newCDKViewer (cdkscreen,
			   CDKparamValue (&params, 'X', CENTER),
			   CDKparamValue (&params, 'Y', CENTER),
			   CDKparamValue (&params, 'H', 20),
			   CDKparamValue (&params, 'W', -2),
			   (CDK_CSTRING2)button, 2, A_REVERSE,
			   CDKparamValue (&params, 'N', TRUE),
			   CDKparamValue (&params, 'S', FALSE));

   /* Could we create the viewer widget? */
   if (example == 0)
   {
      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create viewer. Is the window too small?\n");
      ExitProgram (EXIT_SUCCESS);
   }

   if (link_it)
   {
      info = (char **)calloc (2, sizeof (char *));
      info[0] = (char *)malloc (5 + strlen (filename));
      sprintf (info[0], "<F=%s>", filename);
      lines = -1;
      interp_it = TRUE;
   }
   else
   {
      setCDKViewer (example, "reading...", 0, 0, A_REVERSE, TRUE, TRUE, TRUE);
      /* Open the file and read the contents. */
      lines = CDKreadFile (filename, &info);
      if (lines == -1)
      {
	 endCDK ();
	 printf ("Could not open \"%s\"\n", filename);
	 ExitProgram (EXIT_FAILURE);
      }
   }

   /* Set up the viewer title, and the contents to the widget. */
   sprintf (vTitle, "<C></B/21>Filename:<!21></22>%20s<!22!B>", filename);
   setCDKViewer (example, vTitle,
		 (CDK_CSTRING2)info, lines,
		 A_REVERSE, interp_it, TRUE, TRUE);

   CDKfreeStrings (info);

   /* Destroy the file selector widget. */
   destroyCDKFselect (fSelect);

   /* Activate the viewer widget. */
   selected = activateCDKViewer (example, 0);

   /* Check how the person exited from the widget. */
   if (example->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>Escape hit. No Button selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }
   else if (example->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected button %d", selected);
      mesg[0] = temp;
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
   }

   /* Clean up. */
   destroyCDKViewer (example);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
예제 #6
0
/*
 * This program demonstrates the Cdk radio widget.
 */
int main(int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = (CDKSCREEN *) NULL;
   CDKRADIO *radio = (CDKRADIO *) NULL;
   WINDOW *cursesWin = (WINDOW *) NULL;
   char *item[5] =
   {"Choice A", "Choice B", "Choice C"};
   char *mesg[5], temp[100];
   int selection;

   CDK_PARAMS params;

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

   /* 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', "NONE")),
			CDKparamValue(&params, 'H', 5),
			CDKparamValue(&params, 'W', 20),
		        CDKparamString(&params, 't'),
			item, 3,
			'#' | A_REVERSE, 1,
			A_REVERSE,
			CDKparamValue(&params, 'N', TRUE),
			CDKparamValue(&params, 'S', FALSE));

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

      /* Print out a message and exit. */
      printf ("Oops. Can't seem to create the radio widget. ");
      printf ("Is the window too small??\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the radio list. */
   selection = activateCDKRadio (radio, (chtype *) NULL);

   /* 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, mesg, 3);
   }
   else if (radio->exitType == vNORMAL)
   {
      mesg[0] = "<C>You selected the filename";
      sprintf (temp, "<C>%.*s", (int)(sizeof(temp) - 20), item[selection]);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);
      freeChar (mesg[1]);
   }

   destroyCDKRadio (radio);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
예제 #7
0
파일: ui_cdk.c 프로젝트: NYAMNYAM3/twilc
int main(int argc, char *argv[]){
    /* Read config file */
    clit_config *config = malloc(sizeof(clit_config));
    parse_config(config);
    printf("key:%s,secret:%s\n",config->key,config->secret);
    /* If no user info exists, intialize oauth process */
    init_oauth(config->key,config->secret);

    create_filters();

    home = malloc(sizeof(statuses));
    home->count = 0;

    setlocale(LC_ALL,"");
    CDKSCREEN *cdkscreen = 0;
    CDKSCROLL *home_scroll = 0;
    WINDOW *cursesWin = 0;
    char *title = "<C><\5>Home";
    char **home_items = 0;
    int selection,count;

    char *tmpfile = get_home();
    count = load_timeline(tmpfile,home);
    printf("count:%d\n",count);
    home_items = malloc(count*sizeof(char *));

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

    cursesWin = initscr();
    cdkscreen = initCDKScreen(cursesWin);
    initCDKColor();

    status *p = home->head;
    for(int i=0;i<count;++i){
        if(p){
            home_items[i] = p->text;
            p = p->next;
        }
        else break;
    }
//    count = CDKgetDirectoryContents (".", &home_items);

    home_scroll = newCDKScroll(cdkscreen,
                               CDKparamValue (&params, 'X', CENTER),
                               CDKparamValue (&params, 'Y', CENTER),
                               CDKparsePosition(CDKparamString2(&params, 's', "RIGHT")),
                               CDKparamValue (&params, 'H', 0),
                               CDKparamValue (&params, 'W', 0),
                               CDKparamString2(&params, 't', title),
                               CDKparamNumber(&params, 'c') ? 0 : home_items,
                               CDKparamNumber(&params, 'c') ? 0 : count,
                               TRUE,
                               A_REVERSE,
                               CDKparamValue (&params, 'N', TRUE),
                               CDKparamValue (&params, 'S', FALSE));
    if(home_scroll == 0){
        destroyCDKScreen(cdkscreen);
        endCDK();
        exit(EXIT_FAILURE);
    }
    if (CDKparamNumber(&params, 'c')){
        setCDKScrollItems (home_scroll, home_items, count, TRUE);
    }
    selection = activateCDKScroll (home_scroll, 0);

    char ch = '\0';
    while((ch = getch()) != 'q'){
        switch(ch){
            case 'n':
                break;
        }
    }

    //CDKfreeStrings (home_items);
    destroyCDKScroll(home_scroll);
    destroyCDKScreen(cdkscreen);
    endCDK();
    exit(EXIT_SUCCESS);
}