Example #1
0
static int
show_date (CmdConfig *cmd_config, CameraWidget *date)
{
	CDKCALENDAR *calendar = NULL;
	int day, month, year, selection;
	time_t time;
	struct tm *date_info;
	const char *label;
	char title[1024];

	gp_widget_get_value (date, &time);
	date_info = localtime (&time);

	/* Month in CDK starts with 1 */
	day = date_info->tm_mday;
	month = date_info->tm_mon + 1;
	year = date_info->tm_year + 1900;

	gp_widget_get_label (date, &label);
	snprintf (title, sizeof (title), "<C></5>%s", label);

	/* Create the calendar */
	calendar = newCDKCalendar (cmd_config->screen, CENTER, 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, TRUE, FALSE);
	if (!calendar)
		return (GP_ERROR);

	drawCDKCalendar (calendar, TRUE);
	selection = activateCDKCalendar (calendar, 0);

	if (calendar->exitType == vNORMAL) {
		date_info = localtime (&time);

		/* Month in CDK starts with 1 */
		date_info->tm_mday = calendar->day;
		date_info->tm_mon = calendar->month - 1;
		date_info->tm_year = calendar->year - 1900;

		time = mktime (date_info);
		gp_widget_set_value (date, &time);
		set_config (cmd_config);
	}

	destroyCDKCalendar (calendar);
	return (GP_OK);
}
Example #2
0
/*
 * This program demonstrates the Cdk calendar widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen         = 0;
   CDKCALENDAR *calendar        = 0;
   WINDOW *cursesWin            = 0;
   const char *title            = "<C></U>CDK Appointment Book\n<C><#HL(30)>\n";
   char *filename               = 0;
   struct tm *dateInfo          = 0;
   time_t clck                  = 0;
   struct AppointmentInfo appointmentInfo;
   int day, month, year, ret, x;
   char temp[1000];

   /*
    * Get the current dates and set the default values for
    * the day/month/year values for the calendar.
    */
   /* *INDENT-EQLS* */
   time (&clck);
   dateInfo    = gmtime (&clck);
   day         = dateInfo->tm_mday;
   month       = dateInfo->tm_mon + 1;
   year        = dateInfo->tm_year + 1900;

   /* Check the command line for options. */
   while (1)
   {
      /* Are there any more command line options to parse. */
      if ((ret = getopt (argc, argv, "d:m:y:t:f:")) == -1)
      {
	 break;
      }

      switch (ret)
      {
      case 'd':
	 day = atoi (optarg);
	 break;

      case 'm':
	 month = atoi (optarg);
	 break;

      case 'y':
	 year = atoi (optarg);
	 break;

      case 't':
	 title = copyChar (optarg);
	 break;

      case 'f':
	 filename = copyChar (optarg);
	 break;
      }
   }

   /* Create the appointment book filename. */
   if (filename == 0)
   {
      char *home = getenv ("HOME");
      if (home != 0)
      {
	 sprintf (temp, "%.*s/.appointment", (int)sizeof (temp) - 20, home);
      }
      else
      {
	 strcat (temp, ".appointment");
      }
      filename = copyChar (temp);
   }

   /* Read the appointment book information. */
   readAppointmentFile (filename, &appointmentInfo);

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

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

   /* Create the calendar widget. */
   calendar = newCDKCalendar (cdkscreen, CENTER, CENTER,
			      title, day, month, year,
			      A_NORMAL, A_NORMAL,
			      A_NORMAL, A_REVERSE,
			      TRUE, FALSE);

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

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

      /* Spit out a message. */
      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, &appointmentInfo);
   bindCDKObject (vCALENDAR, calendar, 'M', createCalendarMarkCB, &appointmentInfo);
   bindCDKObject (vCALENDAR, calendar, 'r', removeCalendarMarkCB, &appointmentInfo);
   bindCDKObject (vCALENDAR, calendar, 'R', removeCalendarMarkCB, &appointmentInfo);
   bindCDKObject (vCALENDAR, calendar, '?', displayCalendarMarkCB, &appointmentInfo);
   bindCDKObject (vCALENDAR, calendar, 'j', accelerateToDateCB, &appointmentInfo);
   bindCDKObject (vCALENDAR, calendar, 'J', accelerateToDateCB, &appointmentInfo);

   /* Set all the appointments read from the file. */
   for (x = 0; x < appointmentInfo.appointmentCount; x++)
   {
      chtype marker = GPAppointmentAttributes[appointmentInfo.appointment[x].type];

      setCDKCalendarMarker (calendar,
			    appointmentInfo.appointment[x].day,
			    appointmentInfo.appointment[x].month,
			    appointmentInfo.appointment[x].year,
			    marker);
   }

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

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

   /* Save the appointment information. */
   saveAppointmentFile (filename, &appointmentInfo);

   free (filename);

   /* Clean up and exit. */
   destroyCDKCalendar (calendar);
   destroyCDKScreen (cdkscreen);
   endCDK ();

   ExitProgram (EXIT_SUCCESS);
}
Example #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);
}