Exemplo n.º 1
0
static int timedate_set(void)
{
    /* Make a local copy of the time struct */
    struct tm tm = *get_time();
    int result;

    /* do some range checks */
    /* This prevents problems with time/date setting after a power loss */
    if (!valid_time(&tm))
    {
/* Macros to convert a 2-digit string to a decimal constant. 
        (YEAR), MONTH and DAY are set by the date command, which outputs
        DAY as 00..31 and MONTH as 01..12. The leading zero would lead to
        misinterpretation as an octal constant. */
#define S100(x) 1 ## x
#define C2DIG2DEC(x) (S100(x)-100)

        tm.tm_hour = 0;
        tm.tm_min  = 0;
        tm.tm_sec  = 0;
        tm.tm_mday = C2DIG2DEC(DAY);
        tm.tm_mon  = C2DIG2DEC(MONTH)-1;
        tm.tm_wday = 1;
        tm.tm_year = YEAR-1900;
    }

    result = (int)set_time_screen(str(LANG_SET_TIME), &tm);

    if(tm.tm_year != -1) {
        set_time(&tm);
    }
    return result;
}
Exemplo n.º 2
0
static bool timedate_set(void)
{
    struct tm tm;
    bool result;

    /* Make a local copy of the time struct */
    memcpy(&tm, get_time(), sizeof(struct tm));

    /* do some range checks */
    /* This prevents problems with time/date setting after a power loss */
    if (!valid_time(&tm))
    {
        /* hour   */
        tm.tm_hour = 0;
        tm.tm_min = 0;
        tm.tm_sec = 0;
        tm.tm_mday = 1;
        tm.tm_mon = 0;
        tm.tm_wday = 1;
        tm.tm_year = 100;
    }

    result = set_time_screen(str(LANG_TIME), &tm);

    if(tm.tm_year != -1) {
        set_time(&tm);
    }
    return result;
}
Exemplo n.º 3
0
int parse_time(char* time_string, int* seconds, int* minutes, int* hours) {	
	int len =0;
	len = strlen(time_string);
	if (len !=8) {
		return 0;
	}
	if (time_string[2]!= ':' || time_string[5] != ':') {
		return 0;	
	}
	//seconds
	if ( !is_num(time_string[0]) || !is_num(time_string[1])) {
		return 0;
	}
	//minutes
	if ( !is_num(time_string[3]) || !is_num(time_string[4])) {
		return 0;
	}
	//hours
	if ( !is_num(time_string[6]) || !is_num(time_string[7])) {
		return 0;
	}
	*seconds = (time_string[0]-'0')*10 + (time_string[1]-'0');
	*minutes = (time_string[3]-'0')*10 + (time_string[4]-'0');
	*hours = (time_string[6]-'0')*10 + (time_string[7]-'0');
	return valid_time(*seconds, *minutes, *hours);
}
Exemplo n.º 4
0
/* have to do this manually because the setting screen
   doesnt handle variable item count */
static int alarm_setting(void)
{
    struct opt_items items[ALARM_START_COUNT];
    int i = 0;
    items[i].string = str(LANG_RESUME_PLAYBACK);
    items[i].voice_id = LANG_RESUME_PLAYBACK;
    i++;
#if CONFIG_TUNER
    if (radio_hardware_present())
    {
        items[i].string = str(LANG_FM_RADIO);
        items[i].voice_id = LANG_FM_RADIO;
        i++;
    }
#endif
#ifdef HAVE_RECORDING
    items[i].string = str(LANG_RECORDING);
    items[i].voice_id = LANG_RECORDING;
    i++;
#endif
    return set_option(str(LANG_ALARM_WAKEUP_SCREEN),
                      &global_settings.alarm_wake_up_screen, 
                      INT, items, i, NULL);
}

MENUITEM_FUNCTION(alarm_wake_up_screen, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN),
                  alarm_setting, NULL, alarm_callback, Icon_Menu_setting);
#endif /* CONFIG_TUNER || defined(HAVE_RECORDING) */

#endif /* HAVE_RTC_ALARM */
static void talk_timedate(void)
{
    struct tm *tm = get_time();
    if (!global_settings.talk_menu)
        return;
    talk_id(VOICE_CURRENT_TIME, false);
    if (valid_time(tm))
    {
        talk_time(tm, true);
        talk_date(get_time(), true);
    }
    else
    {
        talk_id(LANG_UNKNOWN, true);
    }
}
Exemplo n.º 5
0
static void draw_timedate(struct viewport *vp, struct screen *display)
{
    struct tm *tm = get_time();
    int line;
    char time[16], date[16];
    const char *t = time, *d = date;
    if (vp->height == 0)
        return;
    display->set_viewport(vp);
    display->clear_viewport();
    if (viewport_get_nb_lines(vp) >= 4)
        line = 1;
    else
        line = 0;

    if (valid_time(tm))
    {
        snprintf(time, sizeof(time), "%02d:%02d:%02d%s", 
                global_settings.timeformat == 0 ? tm->tm_hour :
                        ((tm->tm_hour + 11) % 12) + 1,
                            tm->tm_min, 
                            tm->tm_sec, 
                        global_settings.timeformat == 0 ? "" :
                                tm->tm_hour>11 ? " P" : " A");
        snprintf(date, sizeof(date), "%s %d %d", 
                str(LANG_MONTH_JANUARY + tm->tm_mon),
                    tm->tm_mday,
                    tm->tm_year+1900);
    }
    else
    {
        t = "--:--:--";
        d = str(LANG_UNKNOWN);
    }

    display->puts(0, line++, t);
    display->puts(0, line, d);

    display->update_viewport();
    display->set_viewport(NULL);
}
Exemplo n.º 6
0
static void
prompt_for_insert(Props *p) {
	char		date_str[BUFSIZ], what_buffer[BUFSIZ], buf[BUFSIZ], *timecopy;
	int		index, next, valid = FALSE;
	DisplayType	dt = get_int_prop(p, CP_DEFAULTDISP);

        format_tick(now(), get_int_prop(p, CP_DATEORDERING),
		    get_int_prop(p, CP_DATESEPARATOR), date_str);

	printf("%s", catgets(DT_catd, 1, 193, "Please enter the information for the appointment you wish to add.\nDefaults will be shown in parentheses.\n"));
	prompt_for_line(catgets(DT_catd, 1, 194, 
		"Calendar (%s): "), cm_get_credentials(), cm_target);
	prompt_for_line(catgets(DT_catd, 1, 195, 
		"Date (%s): "), date_str, cm_date);
	while (valid != TRUE)
	{
		format_time(now(), dt, cm_start);
		prompt_for_line(catgets(DT_catd, 1, 196, 
			"Start (%s): "), cm_start, cm_start);
		if (cm_start && cm_start[0])
		{
			timecopy = (char *)cm_strdup(cm_start);
			if (valid_time(p, timecopy))
				valid = TRUE;
			else
				printf("%s", catgets(DT_catd, 1, 197, "You have entered an invalid time.  Please try again:\n"));
			free(timecopy);
		}
	}

	sprintf(buf, "%s %s", date_str, cm_start);
	next = (int) cm_getdate(buf, NULL);
        next = next + hrsec;

	format_time(next, dt, cm_end);
	if (cm_start && cm_start[0])
		prompt_for_line(
			catgets(DT_catd, 1, 198, "End (%s): "), cm_end, cm_end);
	else
		prompt_for_line(
			catgets(DT_catd, 1, 199, "End (%s): "), "None", cm_end);

	strcpy(cm_repeatstr, catgets(DT_catd, 1, 200, "One Time"));

	prompt_for_line(catgets(DT_catd, 1, 201, 
			"Repeat (%s): "), cm_repeatstr, cm_repeatstr);

	if (strcmp(cm_repeatstr, catgets(DT_catd, 1, 200, "One Time"))) {
		sprintf(buf, "%s", catgets(DT_catd, 1, 203, "no default"));
		prompt_for_line(
			catgets(DT_catd, 1, 204, "For (%s): "), buf, cm_for);
	}

	printf("%s", catgets(DT_catd, 1, 205, 
		"What (you may enter up to 5 lines, use ^D to finish):\n"));
	cm_what[0] = NULL;
	for (index = 0; index < 5; index++)
	{
        	*what_buffer = '\0';
        	fgets (what_buffer, sizeof(what_buffer), stdin);
        	if (strlen(what_buffer) &&
		    what_buffer[strlen(what_buffer)-1] == '\n')
          	  what_buffer[strlen(what_buffer)-1] = '\0';

		if (what_buffer[0] == '\000')
			break;
		else
		{
			strcat(cm_what, what_buffer);
			strcat(cm_what, "\\n");
		}
		memset(what_buffer, '\000', 256);
	}
	
}
Exemplo n.º 7
0
/*
**  This function will consume form values and stuff them into an appointment.
*/
extern Boolean
dssw_form_to_todo(DSSW *dssw, Dtcm_appointment *a, char *name, Tick t)
{
	time_t		start_tick, stop_tick;
	char		ampm_buf[BUFSIZ], buf[BUFSIZ];
	Props		*p = (Props *)dssw->cal->properties;
	Props_pu	*pu = (Props_pu *)dssw->cal->properties_pu;
	DisplayType	dt = get_int_prop(p, CP_DEFAULTDISP);

	get_dssw_vals(dssw, t);
	/*
	 * Todo does not have end time.  So to distinguish between this
	 * and the editor, zero this out.
	 */
	sprintf(dssw->stop_val.val, "\0");
	if (blank_buf(dssw->date_val)) {
		editor_err_msg(dssw->parent, name, MISSING_DATE,
			       pu->xm_error_pixmap);
		return False;
	}

	if (!blank_buf(dssw->start_val.val)) {
		if (!valid_time(p, dssw->start_val.val)) {
			editor_err_msg(dssw->parent, name, INVALID_TIME,
				pu->xm_error_pixmap);
			return False;
		}

		if (dt == HOUR12) {
			if (dssw->start_val.block == TIME_AM)
				sprintf(ampm_buf, "am");
			else
				sprintf(ampm_buf, "pm");
		} else
			ampm_buf[0] = '\0';

		sprintf(buf, "%s %s%s",
			dssw->date_val, dssw->start_val.val, ampm_buf); 

		/* 
		 * No check here for stop time.
		 */
	} else {
		editor_err_msg(dssw->parent, name, MISSING_TIME,
			pu->xm_error_pixmap);
		return False;
	}

	start_tick = cm_getdate(buf, NULL);
	if(start_tick < 0) {
		editor_err_msg(dssw->parent, name, INVALID_DATE,
			pu->xm_error_pixmap);
		return False;
	}

	a->time->value->item.date_time_value = (char *) malloc(BUFSIZ);
	_csa_tick_to_iso8601(start_tick, a->time->value->item.date_time_value);
	a->what->value->item.string_value = (char *)cm_strdup(dssw->what_val);
	a->show_time->value->item.sint32_value = True;

	free(a->end_time->value);
	a->end_time->value = NULL;

	return True;
}
Exemplo n.º 8
0
extern Boolean
dssw_form_flags_to_appt(DSSW *dssw, Dtcm_appointment *a, char *name, Tick t, int *flagsP)
{
	time_t		start_tick, stop_tick;
	char		ampm_buf[BUFSIZ], buf[BUFSIZ];
	Props		*p = (Props *)dssw->cal->properties;
	Props_pu	*pu = (Props_pu *)dssw->cal->properties_pu;
	DisplayType	dt = get_int_prop(p, CP_DEFAULTDISP);
	int		flags = 0;

	if (flagsP == (int *)NULL)
	  flagsP = &flags;

	/*
	**  If neither start nor end times exist, then the start time is set
	**  to 3:41am (magic time) and the end time to 3:41 plus one minute.
	*/
	get_dssw_vals(dssw, t);
	if (blank_buf(dssw->date_val)) {
		editor_err_msg(dssw->parent, name, MISSING_DATE,
			       pu->xm_error_pixmap);
		return False;
	}

	if (!blank_buf(dssw->start_val.val)) {
		if (!valid_time(p, dssw->start_val.val)) {
			if (a->type->value->item.sint32_value == CSA_TYPE_TODO)
				editor_err_msg(dssw->parent, name, 
					       INVALID_TIME_DUE,
					       pu->xm_error_pixmap);
			else
				editor_err_msg(dssw->parent, name, 
					       INVALID_START,
					       pu->xm_error_pixmap);
			return False;
		}

		if (dt == HOUR12) {
			/* am and pm should not be translated.  They are only
			 * used in the date parsing code and never shown to
			 * the user.
			 */
			if (dssw->start_val.block == TIME_AM)
				sprintf(ampm_buf, "am");
			else
				sprintf(ampm_buf, "pm");
		} else
			ampm_buf[0] = '\0';

		sprintf(buf, "%s %s%s",
			dssw->date_val, dssw->start_val.val, ampm_buf); 

		if (!blank_buf(dssw->stop_val.val)
			&& !valid_time(p, dssw->stop_val.val)) {
			editor_err_msg(dssw->parent, name, INVALID_STOP,
				pu->xm_error_pixmap);
               		return False;
		}
	} else if (!blank_buf(dssw->stop_val.val)) {
		editor_err_msg(dssw->parent, name, MISSING_START,
			pu->xm_error_pixmap);
		return False;
	} else
		sprintf(buf, "%s 3:41am", dssw->date_val);

	start_tick = cm_getdate(buf, NULL);
	if(start_tick < 0) {
		editor_err_msg(dssw->parent, name, INVALID_DATE,
			pu->xm_error_pixmap);
		return False;
	}

	if (blank_buf(dssw->what_val) && blank_buf(dssw->start_val.val)
		&& blank_buf(dssw->stop_val.val)) {
		editor_err_msg(dssw->parent, name, INVALID_NOTIME_APPT,
			pu->xm_error_pixmap);
		return False;
	}

	a->time->value->item.date_time_value = (char *) malloc(BUFSIZ);
	_csa_tick_to_iso8601(start_tick, a->time->value->item.date_time_value);
	a->what->value->item.string_value = (char *)cm_strdup(dssw->what_val);
	a->show_time->value->item.sint32_value = True;

	if (!blank_buf(dssw->stop_val.val)) {
		if (dt == HOUR12) {
			/* am and pm should not be translated.  They are only
			 * used in the date parsing code and never shown to
			 * the user.
			 */
			if (dssw->stop_val.block == TIME_AM)
				sprintf(ampm_buf, "am");
			else
				sprintf(ampm_buf, "pm");
		} else
			ampm_buf[0] = '\0';

		sprintf(buf, "%s %s%s", dssw->date_val,
			dssw->stop_val.val, ampm_buf); 
		if ((stop_tick = cm_getdate(buf, NULL)) <= 0) {
			editor_err_msg(dssw->parent, name, INVALID_DATE,
				       pu->xm_error_pixmap);
			return False;
		}
		if (stop_tick < start_tick) {
		    if (*flagsP == 0)
		    {
		  	char *title = XtNewString(catgets(calendar->DT_catd, 1, 248,
					"Calendar : Schedule Appointment"));
		  	char *ident1 = XtNewString(catgets(calendar->DT_catd, 1,
					923, "Cancel"));
		  	char *ident2 = XtNewString(catgets(calendar->DT_catd, 1,
					250, "Next Day"));
			sprintf(buf, "%s", catgets(calendar->DT_catd, 1, 247,
				"This appointment has an end time earlier than\nits begin time.  Do you want to\nschedule it into the next day?"));
			*flagsP = dialog_popup(dssw->parent,
				DIALOG_TITLE, title,
				DIALOG_TEXT, buf,
				BUTTON_IDENT, -1, ident1,
				BUTTON_IDENT, DSSW_NEXT_DAY, ident2,
				DIALOG_IMAGE, pu->xm_question_pixmap,
				NULL);
			XtFree(ident2);
			XtFree(ident1);
			XtFree(title);
		    }
		    switch (*flagsP) {
		    case DSSW_NEXT_DAY:
			stop_tick += daysec;
			break;

		    default:
			*flagsP = 0;
		        return False;
		    }
		}

		a->end_time->value->item.date_time_value = (char *) malloc(BUFSIZ);
		_csa_tick_to_iso8601(stop_tick, a->end_time->value->item.date_time_value);
	} else if (blank_buf(dssw->start_val.val)) {
		a->end_time->value->item.date_time_value = (char *) malloc(BUFSIZ);
		_csa_tick_to_iso8601(start_tick + minsec, a->end_time->value->item.date_time_value);
		a->show_time->value->item.sint32_value = False;
	} else {
		free(a->end_time->value);
		a->end_time->value = NULL;
	}

	return True;
}