/* * Format the appointment in the character array passed (assumed to be pointing * to allocated space) to contain the time followed by the what string. The * appointment string is truncated at "max" chars or at DEFAULT_APPT_LEN if * max is 0. */ extern void format_appt(Dtcm_appointment *appt, char *b, DisplayType display, int max) { int hr, mn, len, i = 0, j = 0; Tick tick; struct tm *tm; register char *what_ptr; _Xltimeparams localtime_buf; if (!appt || !b) return; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); tm = _XLocaltime(&tick, localtime_buf); hr = tm->tm_hour; mn = tm->tm_min; if (showtime_set(appt) && !magic_time(tick)) { if (display == HOUR12) { adjust_hour(&hr); sprintf(b, "%2d:%02d ", hr, mn); } else sprintf(b, "%02d%02d ", hr, mn); i = cm_strlen(b); } if (appt->what->value->item.string_value) { if (max <= 0) max = DEFAULT_APPT_LEN; len = max - i; what_ptr = appt->what->value->item.string_value; while ((i < len) && *what_ptr != '\n' && *what_ptr) b[i++] = *what_ptr++; b[i] = '\0'; } }
static boolean_t visit1(caddr_t node, caddr_t d) { boolean_t stop = B_FALSE; switch (((Appt_4 *) d)->tag->tag) { case otherTag_4: /* * otherTags = events read in from files. * Don't write to log. */ return(stop); case appointment_4: /* * a little hack to get us off the * totally hokey magic-time business. */ if (magic_time(((Appt_4 *)d)->appt_id.tick)) { ((Appt_4 *)d)->tag->showtime = 0; } break; } if ((dump_error = _DtCmsAppendAppt4ByFD(fd, (Appt_4 *)d, _DtCmsLogAdd)) != CSA_SUCCESS) stop = B_TRUE; return(stop); }
extern void format_abbrev_appt(Dtcm_appointment *appt, char *b, Boolean show_am, DisplayType display) { int hr, mn; Tick tick; Lines *lines=NULL; Boolean am = True; struct tm *tm; _Xltimeparams localtime_buf; if(appt==NULL || b==NULL) return; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); tm = _XLocaltime(&tick, localtime_buf); hr = tm->tm_hour; mn = tm->tm_min; if (showtime_set(appt) && !magic_time(tick)) { if (display == HOUR12) { am = adjust_hour(&hr); if (show_am) sprintf(b, "%2d:%02d%s ", hr, mn, am ? "a" : "p"); else sprintf(b, "%2d:%02d ", hr, mn); } else sprintf(b, "%02d%02d ", hr, mn); } lines = text_to_lines(appt->what->value->item.string_value, 1); if (lines != NULL && lines->s != NULL) { (void) cm_strcat(b, lines->s); destroy_lines(lines); } }
/* * Format the appointment in the character array passed (assumed to be pointing * to allocated space) to contain the formatted string for the group * appointment editor. The string is truncated at "max" chars or at * DEFAULT_GAPPT_LEN if max is 0. */ extern void format_gappt(Dtcm_appointment *appt, char *name, char *b, DisplayType display, int max) { int hr, mn, i, j; Tick tick; char *what_ptr; struct tm *tm; _Xltimeparams localtime_buf; if (!appt || !b) return; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); if ((tick > 0) && !magic_time(tick) && showtime_set(appt)) { tm = _XLocaltime(&tick, localtime_buf); hr = tm->tm_hour; mn = tm->tm_min; if (display == HOUR12) { adjust_hour(&hr); sprintf(b, "%2d:%02d ", hr, mn); } else sprintf(b, "%02d%02d ", hr, mn); } else sprintf(b, "%6s", " "); if (max <= 0) max = DEFAULT_GAPPT_LEN; i = cm_strlen(b); j = 0; while (j < 10 && i < max && name && name[j]) b[i++] = name[j++]; while (j < 11 && i < max) b[i++] = ' ', ++j; if (i >= max) { b[i - 1] = '\0'; return; } b[i] = '\0'; if (appt->what->value->item.string_value) { what_ptr = appt->what->value->item.string_value; while (i < max && *what_ptr != '\n' && *what_ptr) b[i++] = *what_ptr++; b[i] = '\0'; } }
static int paint_entry(Calendar *c, int x, int y, int maxchars, Paint_cache *cache_entry, XRectangle *rect) { XFontSetExtents fontextents; Props *p = (Props*)c->properties; int nlines = 0, dt = get_int_prop(p, CP_DEFAULTDISP); new_XContext *xc = c->xcontext; char buf1[50], buf2[WHAT_LEN+1]; Week *w = (Week *)c->view->week_info; Tick tick; /* * Write an appointment entry into a day */ if (maxchars >= 40) /* maxed out possible=40 */ maxchars = 40; buf1[0] = '\0'; buf2[0] = '\0'; format_entry(cache_entry, buf1, buf2, dt); tick = cache_entry->start_time; if (cache_entry->show_time && !magic_time(tick) && (buf1[0] != '\0')) { maxchars = gr_nchars(w->day_width - 5, buf1,c->fonts->boldfont); buf1[min(cm_strlen(buf1), maxchars)] = '\0'; gr_text(xc, x, y, c->fonts->boldfont, buf1, rect); nlines++; CalFontExtents(c->fonts->boldfont, &fontextents); y += fontextents.max_logical_extent.height;; } if (buf2[0] != '\0') { maxchars = gr_nchars(w->day_width - 5, buf2, c->fonts->viewfont); buf2[min(cm_strlen(buf2), maxchars)] = '\0'; gr_text(xc, x, y, c->fonts->viewfont, buf2, rect); nlines++; } return(nlines); }
/* * Format 2 lines of appt data */ extern void format_line2(Dtcm_appointment *appt, char *buf1, char *buf2, DisplayType display) { Tick tick, end_tick = 0; int hour1, min1, hour2, min2; Lines *lines; char *s1, *s2; struct tm *tm; _Xltimeparams localtime_buf; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); if (appt->end_time) _csa_iso8601_to_tick(appt->end_time->value->item.string_value, &end_tick); /* * Extract an appointment and format it into 2 lines of no more * then maxchars */ *buf1 = *buf2 = NULL; if (appt == NULL || appt->what->value->item.string_value == NULL) return; tm = _XLocaltime(&tick, localtime_buf); hour1 = tm->tm_hour; min1 = tm->tm_min; if (!showtime_set(appt) || magic_time(tick)) { lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1); if (lines==NULL) return; strncpy(buf2, lines->s, 256); destroy_lines(lines); return; } s1 = s2 = "am"; if (display == HOUR12 && !adjust_hour(&hour1)) s1="pm"; if (end_tick) { hour2 = hour(end_tick); min2 = minute(end_tick); if (display == HOUR12 && !adjust_hour(&hour2)) s2="pm"; } if (end_tick == 0 || (hour1 == hour2 && min1 == min2 && (strcmp(s1, s2) == 0))) { if (display == HOUR24) sprintf(buf1, "%02d%.2d", hour1, min1); else sprintf(buf1, "%d:%.2d%s", hour1, min1, s1); } else { if (display == HOUR12) sprintf(buf1, "%d:%.2d%s-%d:%.2d%s", hour1, min1, s1, hour2, min2, s2); else sprintf(buf1, "%02d%02d-%02d%02d", hour1, min1, hour2, min2); } lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 1); if (lines == NULL || lines->s == NULL || (cm_strlen(lines->s) == 1 && lines->s[0] == ' ')) buf2[0] = NULL; else sprintf(buf2, " %s", lines->s); destroy_lines(lines); }
/* * Format 2 lines of appt data */ extern void format_maxchars(Dtcm_appointment *appt, char *buf1, int maxchars, DisplayType display) { Tick tick, end_tick = 0; int hour1, min1, hour2, min2; Lines *lines; char *s1, *s2; struct tm *tm; _Xltimeparams localtime_buf; _csa_iso8601_to_tick(appt->time->value->item.string_value, &tick); if (appt->end_time) _csa_iso8601_to_tick(appt->end_time->value->item.string_value, &end_tick); *buf1 = NULL; if (appt == NULL || appt->what->value->item.string_value == NULL) return; tm = _XLocaltime(&tick, localtime_buf); hour1 = tm->tm_hour; min1 = tm->tm_min; if (showtime_set(appt) && !magic_time(tick)) { s1 = s2 = "am"; if (display == HOUR12 && !adjust_hour(&hour1)) s1="pm"; if (end_tick) { hour2 = hour(end_tick); if (display == HOUR12 && !adjust_hour(&hour2)) s2="pm"; min2 = minute(end_tick); } if (end_tick == 0 || hour1 == hour2 && min1 == min2) { if (display == HOUR24) sprintf(buf1, "%02d%02d ", hour1, min1); else sprintf(buf1, "%d:%.2d%s ", hour1, min1, s1); } else { if (display == HOUR12) sprintf(buf1, "%d:%.2d%s-%d:%.2d%s ", hour1, min1, s1, hour2, min2, s2); else sprintf(buf1, "%02d%02d-%02d%02d ", hour1, min1, hour2, min2); } } lines = (Lines *) text_to_lines(appt->what->value->item.string_value, 10); while (lines != NULL) { if ((cm_strlen(buf1) + cm_strlen(lines->s)) < (maxchars-2)) { cm_strcat(buf1, lines->s); lines = lines->next; if (lines != NULL) cm_strcat(buf1, " - "); } else { strncat(buf1, lines->s, (maxchars - cm_strlen(buf1)-1)); break; } } destroy_lines(lines); }
/* * Format 1 line of appt data. Returns True if begin hour is < 10 - thus * padding needs to be done. */ extern Boolean format_line(Tick tick, char *what, char *buf, int end_tick, Boolean showtime, DisplayType display) { int hr, hr1, mn, mn1; Boolean am=True; Boolean am_end=True; struct tm *tm; Boolean pad = FALSE; _Xltimeparams localtime_buf; if (buf==NULL) return pad; buf[0]=NULL; tm = _XLocaltime(&tick, localtime_buf); hr = tm->tm_hour; mn = tm->tm_min; if (showtime && !magic_time(tick)) { if (display == HOUR12) am = adjust_hour(&hr); if (end_tick && end_tick != tick) { hr1 = hour(end_tick); mn1 = minute(end_tick); if (display == HOUR12) { am_end = adjust_hour(&hr1); if (am_end != am) { (void) sprintf(buf, "%d:%.2d - %d:%.2d%s ", hr, mn, hr1, mn1, am_end ? "am" : "pm"); } else { (void) sprintf(buf, "%d:%.2d - %d:%.2d ", hr, mn, hr1, mn1); } if (hr < 10) pad = TRUE; } else (void) sprintf(buf, "%02d%02d - %02d%02d ", hr, mn, hr1, mn1); } else { /* Check to see if there are 2 digits in in initial time format. If so, pad with 1 space; if not 2. The font is not fixed width, so I have to line it up myself.. */ if (display == HOUR12) { if (hr > 9) (char *)sprintf(buf, "%2d:%.2d%s ", hr, mn, am ? "a" : "p"); else { (char *)sprintf(buf, "%d:%.2d%s ", hr, mn, am ? "a" : "p"); pad = TRUE; } } else (char *)sprintf(buf, "%02d%02d ", hr, mn); } } if (what) (void) cm_strcat(buf, what); return pad; }
extern Boolean dssw_attrs_to_form(DSSW *dssw, Dtcm_appointment *appt) { int start_hr, stop_hr; char *what; time_t tick, end_tick = 0; Boolean showtime; Props *p = (Props *)dssw->cal->properties; DisplayType dt = get_int_prop(p, CP_DEFAULTDISP); _csa_iso8601_to_tick(appt->time->value->item.date_time_value, &tick); showtime = showtime_set(appt); if (appt->end_time) _csa_iso8601_to_tick(appt->end_time->value->item.\ date_time_value, &end_tick); what = appt->what->value->item.string_value; /* ** Set the date, start, stop, and what fields */ if (!showtime || magic_time(tick)) { dssw->start_val.val[0] = '\0'; dssw->stop_val.val[0] = '\0'; } else { if ((start_hr = hour(tick)) < 12) dssw->start_val.block = TIME_AM; else dssw->start_val.block = TIME_PM; if (dt == HOUR12) { if (start_hr == 0) start_hr = 12; else if (start_hr > 12) start_hr -= 12; sprintf(dssw->start_val.val, "%2d:%02d", start_hr, minute(tick)); } else sprintf(dssw->start_val.val, "%02d%02d", start_hr, minute(tick)); if (end_tick) { if ((stop_hr = hour(end_tick)) < 12) dssw->stop_val.block = TIME_AM; else dssw->stop_val.block = TIME_PM; if (dt == HOUR12) { if (stop_hr == 0) stop_hr = 12; else if (stop_hr > 12) stop_hr -= 12; sprintf(dssw->stop_val.val, "%2d:%02d", stop_hr, minute(end_tick)); } else sprintf(dssw->stop_val.val, "%02d%02d", stop_hr, minute(end_tick)); } else { /* no end time */ sprintf(dssw->stop_val.val, "\0"); dssw->stop_val.block = TIME_AM; } } /* limit the size of the text pulled out of the appointment. */ if (what) { strncpy(dssw->what_val, what, WHAT_LEN - 1); dssw->what_val[WHAT_LEN-1] = NULL; } set_dssw_vals(dssw, tick); return True; }
/* ** Functions to build and popup the postup reminder */ extern void postup_show_proc(Calendar *c, CSA_reminder_reference *r) { int start_hr, stop_hr; char text[BUFSIZ]; time_t st, sp = 0; Lines *lines, *l = NULL; Props *p = (Props *)c->properties; Widget pu_frame, pu_base_form, pu_text_form, separator, pu_form, button_form, pu_date, pu_range, pu_image, pu_close, line, last_line; Boolean start_am, stop_am; XmString xmstr; CSA_return_code stat; DisplayType dis_t = get_int_prop(p, CP_DEFAULTDISP); OrderingType ord_t = get_int_prop(p, CP_DATEORDERING); SeparatorType sep_t = get_int_prop(p, CP_DATESEPARATOR); Dtcm_appointment *appt; char *title; if (!c->postup) c->postup = XtAppCreateShell("calendar_postup", "Dtcm", xmDialogShellWidgetClass, c->xcontext->display, NULL, 0); /* ** Create the Motif objects */ title = XtNewString(catgets(c->DT_catd, 1, 839, "Calendar : Reminder")); pu_frame = XtVaCreatePopupShell("pu_frame", topLevelShellWidgetClass, c->postup, XmNtitle, title, XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE, XmNdeleteResponse, XmDESTROY, NULL); XtFree(title); pu_base_form = XtVaCreateWidget("pu_base_form", xmFormWidgetClass, pu_frame, NULL); pu_text_form = XtVaCreateWidget("pu_test_form", xmFormWidgetClass, pu_base_form, XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNleftOffset, 1, XmNrightOffset, 1, XmNtopOffset, 1, NULL); pu_image = XtVaCreateWidget("pu_image", xmLabelGadgetClass, pu_text_form, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 5, XmNlabelType, XmPIXMAP, XmNlabelPixmap, ((Props_pu *)c->properties_pu)->postup_pixmap, NULL); button_form = XtVaCreateWidget("pu_form", xmFormWidgetClass, pu_base_form, XmNbottomAttachment, XmATTACH_FORM, XmNbottomOffset, 2, XmNleftOffset, 1, XmNrightOffset, 1, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNfractionBase, 3, NULL); xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 680, "Close")); pu_close = XtVaCreateManagedWidget("close", xmPushButtonWidgetClass, button_form, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_POSITION, XmNrightAttachment, XmATTACH_POSITION, XmNleftPosition, 1, XmNrightPosition, 2, XmNbottomOffset, 1, XmNlabelString, xmstr, NULL); XmStringFree(xmstr); separator = XtVaCreateWidget("separator", xmSeparatorGadgetClass, pu_base_form, XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_WIDGET, XmNbottomWidget, button_form, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, pu_text_form, XmNtopOffset, 1, NULL); pu_form = XtVaCreateWidget("pu_form", xmFormWidgetClass, pu_text_form, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 1, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, pu_image, XmNverticalSpacing, 10, NULL); pu_date = XtVaCreateWidget("pu_date", xmLabelGadgetClass, pu_form, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_FORM, NULL); pu_range = XtVaCreateWidget("pu_range", xmLabelGadgetClass, pu_form, XmNleftAttachment, XmATTACH_FORM, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, pu_date, XmNtopOffset, 8, NULL); XtAddCallback(pu_close, XmNactivateCallback, close_cb, pu_frame); appt = allocate_appt_struct(appt_read, c->general->version, CSA_ENTRY_ATTR_START_DATE_I, CSA_ENTRY_ATTR_END_DATE_I, CSA_ENTRY_ATTR_SUMMARY_I, CSA_X_DT_ENTRY_ATTR_SHOWTIME_I, NULL); stat = query_appt_struct(c->cal_handle, r->entry, appt); backend_err_msg(c->frame, c->calname, stat, ((Props_pu *)c->properties_pu)->xm_error_pixmap); if (stat != CSA_SUCCESS) { free_appt_struct(&appt); return; } _csa_iso8601_to_tick(appt->time->value->item.date_time_value, &st); if (appt->end_time) _csa_iso8601_to_tick(appt->end_time->value->\ item.date_time_value, &sp); l = lines = text_to_lines(appt->what->value->item.string_value, 5); last_line = 0; while (l) { xmstr = XmStringCreateLocalized(l->s); line = XtVaCreateWidget("text_line", xmLabelGadgetClass, pu_text_form, XmNlabelString, xmstr, XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, pu_form, XmNleftOffset, 15, NULL); XmStringFree(xmstr); if (last_line) XtVaSetValues(line, XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, last_line, XmNtopOffset, 8, NULL); else XtVaSetValues(line, XmNtopAttachment, XmATTACH_FORM, XmNtopOffset, 8, NULL); last_line = line; l = l->next; } if (lines) destroy_lines(lines); /* ** Now fill in the correct information */ set_date_in_widget(st, pu_date, ord_t, sep_t); if (!showtime_set(appt) || magic_time(st)) text[0] = '\0'; else { start_hr = hour(st); if (sp) stop_hr = hour(sp); if (dis_t == HOUR12) { start_am = adjust_hour(&start_hr); if (sp) { /* NL_COMMENT Message 1087 : This message is used to form the alarm string that appears in the reminder popup. In the C locale it would look something like this: ``From 11:00am to 1:00pm'' In the printf conversion string the $n are: $1 -> start hour $2 -> start minute $3 -> am or pm $4 -> stop hour $5 -> stop minute $6 -> am or pm */ char *am = XtNewString(catgets(c->DT_catd, 1, 4, "am")); char *pm = XtNewString(catgets(c->DT_catd, 1, 3, "pm")); stop_am = adjust_hour(&stop_hr); sprintf(text, catgets(c->DT_catd, 1, 1087, "From %1$2d:%2$02d%3$s to %4$2d:%5$02d%6$s"), start_hr, minute(st), (start_am) ? am : pm, stop_hr, minute(sp), (stop_am) ? am : pm ); XtFree(am); XtFree(pm); } else { /* NL_COMMENT Message 1088 : This message is used to form the alarm string that appears in the reminder popup. It is used when an appt does not have and ``end'' time. In the C locale it would look something like this: ``11:00am'' In the printf conversion string the $n are: $1 -> start hour $2 -> start minute $3 -> am or pm */ char *meridian = XtNewString ((start_am) ? catgets(c->DT_catd, 1, 4, "am"): catgets(c->DT_catd, 1, 3, "pm")); sprintf(text, catgets(c->DT_catd, 1, 1088, "%1$2d:%2$02d%3$s"), start_hr, minute(st), meridian ); XtFree(meridian); } } else { if (sp) { /* NL_COMMENT Message 1089 : This message is used to form the alarm string that appears in the reminder popup. This string is used when a user has asked that times be displayed in 24 hour format. In the C locale it would look something like this: ``From 0100 to 1600'' In the printf conversion string the $n are: $1 -> start hour $2 -> start minute $3 -> stop hour $4 -> stop minute */ sprintf(text, catgets(c->DT_catd, 1, 1089, "From %1$02d%2$02d to %3$02d%4$02d"), start_hr, minute(st), stop_hr, minute(sp)); } else { /* NL_COMMENT Message 1090 : This message is used to form the alarm string that appears in the reminder popup. This string is used when an appt does not have an end time and the user has asked that times be displayed in 24 hour format. In the C locale it would look something like this: ``1600'' In the printf conversion string the $n are: $1 -> start hour $2 -> start minute */ sprintf(text, catgets(c->DT_catd, 1, 1090, "%1$02d%2$02d"), start_hr, minute(st)); } } } free_appt_struct(&appt); xmstr = XmStringCreateLocalized(text); XtVaSetValues(pu_range, XmNlabelString, xmstr, NULL); XmStringFree(xmstr); ManageChildren(pu_form); ManageChildren(pu_base_form); ManageChildren(pu_text_form); XtManageChild(pu_base_form); XtVaSetValues(button_form, XmNdefaultButton, pu_close, NULL); XtVaSetValues(button_form, XmNcancelButton, pu_close, NULL); XtPopup(pu_frame, XtGrabNone); DtWsmOccupyAllWorkspaces(c->xcontext->display, XtWindow(pu_frame)); }
extern void mail_it(XtPointer client_data, XtIntervalId *interval_id, CSA_reminder_reference *r) { Calendar *c = (Calendar *)client_data; int hr; Lines *lines = NULL, *l = NULL; Props *p = (Props *)c->properties; Boolean pm; DisplayType dt = get_int_prop(p, CP_DEFAULTDISP); Dtcm_appointment *appt; char subbuf[BUFSIZ], bodybuf[BUFSIZ]; char datebuf[200], startbuf[100], stopbuf[100]; char whatbuf[BUFSIZ]; char *to; CSA_return_code stat; Tick start, stop; char *addr_data = NULL; appt = allocate_appt_struct(appt_read, c->general->version, CSA_ENTRY_ATTR_START_DATE_I, CSA_ENTRY_ATTR_SUMMARY_I, CSA_ENTRY_ATTR_ORGANIZER_I, CSA_X_DT_ENTRY_ATTR_SHOWTIME_I, CSA_ENTRY_ATTR_END_DATE_I, CSA_ENTRY_ATTR_MAIL_REMINDER_I, NULL); stat = query_appt_struct(c->cal_handle, r->entry, appt); backend_err_msg(c->frame, c->calname, stat, ((Props_pu *)c->properties_pu)->xm_error_pixmap); if (stat != CSA_SUCCESS) { free_appt_struct(&appt); return; } /* compose to field */ if (appt->mail->value->item.reminder_value->reminder_data.data == NULL || (appt->mail->value->item.reminder_value->reminder_data.size == 0)) { /* empty recipient */ if (debug) fprintf(stderr, "%s", catgets(c->DT_catd, 1, 1, "dtcm: empty recipient in mail reminder\n")); to = appt->author->value->item.calendar_user_value->user_name; } else { addr_data = calloc(appt->mail->value->item.reminder_value->reminder_data.size + 1, 1); strncpy(addr_data, (char *) appt->mail->value->item.reminder_value->reminder_data.data, appt->mail->value->item.reminder_value->reminder_data.size); to = addr_data; } /* compose subject field */ lines = text_to_lines(appt->what->value->item.string_value, 5); sprintf(subbuf, catgets(c->DT_catd, 1, 2, "Reminder- %s"), (lines) ? lines->s : "\0"); /* compose message body */ _csa_iso8601_to_tick(appt->time->value->item.date_time_value, &start); format_tick(start, ORDER_MDY, SEPARATOR_SLASH, datebuf); if (showtime_set(appt) && !magic_time(start)) { hr = hour(start); pm = (dt == HOUR12 && !adjust_hour(&hr)) ? True : False; if (dt == HOUR12) { sprintf(startbuf, "%2d:%02d %s", hr, minute(start), pm ? "pm" : "am"); } else { sprintf(startbuf, "%02d%02d", hr, minute(start)); } } else startbuf[0] = '\0'; if (showtime_set(appt) && !magic_time(start) && appt->end_time) { _csa_iso8601_to_tick(appt->end_time->value->\ item.date_time_value, &stop); hr = hour(stop); pm = (dt == HOUR12 && !adjust_hour(&hr)) ? True : False; if (dt == HOUR12) { sprintf(stopbuf, "%2d:%02d %s", hr, minute(stop), pm ? catgets(c->DT_catd, 1, 3, "pm") : catgets(c->DT_catd, 1, 4, "am")); } else { sprintf(stopbuf, "%02d%02d", hr, minute(stop)); } } else stopbuf[0] = '\0'; if (l = lines) { sprintf(whatbuf, "%s\n", l->s); l = l->next; } else whatbuf[0] = '\0'; while(l != NULL) { strcat(whatbuf, "\t\t"); strcat(whatbuf, l->s); strcat(whatbuf, "\n"); l = l->next; } if (lines) destroy_lines(lines); if (stopbuf[0] != '\0') { sprintf(bodybuf, catgets(c->DT_catd, 1, 7, "\n\n\t** Calendar Appointment **\n\n\tDate:\t%s\n\tStart:\t%s\n\tEnd:\t%s\n\tWhat:\t%s"), datebuf, startbuf, stopbuf, whatbuf); } else { sprintf(bodybuf, catgets(c->DT_catd, 1, 1100, "\n\n\t** Calendar To Do Item **\n\n\tDue Date:\t%s\n\tTime Due:\t%s\n\tWhat:\t\t%s"), datebuf, startbuf, whatbuf); } if (debug) { fprintf(stderr, "to = `%s`\n", to); fprintf(stderr, "subject = `%s`\n", subbuf); fprintf(stderr, "body = `%s`\n", bodybuf); } (void)submit_mail(to, subbuf, bodybuf); free_appt_struct(&appt); if (addr_data) free(addr_data); }
static void paint_dayview_appts(Calendar *c, Paint_cache *cache, int a_total, void *rect) { int w = c->view->boxw; int h = c->view->boxh; int begin_time, end_time; int x, x2, y, y2, num_hrs, i, last_hr, hr, x_off; Cal_Font *pf = c->fonts->boldfont; Cal_Font *pf2 = c->fonts->viewfont; XFontSetExtents fontextents; XFontSetExtents fontextents2; Props *p = (Props*)c->properties; Boolean am = True; char buf[5], *appt_str; int pfy, curr_line, maxlines; Lines *lines = NULL, *headlines = NULL; DisplayType disp_t; Colormap cmap; Pixel fg; Tick start_tick, end_tick; int nop, hrbox_margin; CalFontExtents(pf, &fontextents); CalFontExtents(pf2, &fontextents2); XtVaGetValues(c->canvas, XmNcolormap, &cmap, XmNforeground, &fg, NULL); /* draw horizontal lines */ begin_time = get_int_prop(p, CP_DAYBEGIN); end_time = get_int_prop(p, CP_DAYEND); disp_t = get_int_prop(p, CP_DEFAULTDISP); num_hrs = end_time - begin_time + 1; if (disp_t == HOUR12) CalTextExtents(pf, "12pm", 4, &nop, &nop, &hrbox_margin, &nop); else CalTextExtents(pf, "24 ", 3, &nop, &nop, &hrbox_margin, &nop); x = MOBOX_AREA_WIDTH+2; x2 = x + w; y = c->view->topoffset; for (i = 0; i <= num_hrs; i++) { gr_draw_line(c->xcontext, x, y, x2, y, gr_solid, rect); y += h; } /* draw vertical line */ y = c->view->topoffset; y2 = y + num_hrs * h; x += hrbox_margin; gr_draw_line(c->xcontext, x, y, x, y2, gr_solid, rect); x = MOBOX_AREA_WIDTH+3; y += h/2+4; /* draw in hours */ for (i = begin_time - 1; i < end_time; i++) { hr = i; if (i < begin_time) (void) sprintf(buf, ""); else if (disp_t == HOUR12) { am = adjust_hour(&hr); (void) sprintf(buf, "%d%s", hr, am ? "a" : "p"); } else (void) sprintf(buf, "%02d", hr); x_off = gr_center(hrbox_margin, buf, pf); /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x+x_off, y, pf, buf, fg, cmap, rect); else */ gr_text(c->xcontext, x+x_off, y, pf, buf, rect); y += h; } /* draw in appointments */ x = MOBOX_AREA_WIDTH + hrbox_margin + 6; pfy = fontextents2.max_logical_extent.height; maxlines = (h - 6) / pfy; curr_line = last_hr = 0; /* loop thru, getting out the "no time" appointments */ for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; hr = begin_time; if (cache[i].show_time == 0) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time); headlines = lines = text_to_lines(cache[i].summary, 4); start_tick = cache[i].start_time; end_tick = cache[i].end_time; if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } for (i = 0; i < a_total; i++) { if (i != a_total) last_hr = hr; start_tick = cache[i].start_time; end_tick = cache[i].end_time; hr = hour(start_tick); if (hr >= begin_time && hr < end_time && (cache[i].show_time && !magic_time(start_tick))) { if (last_hr != hr) curr_line = 0; y = c->view->topoffset + 2 + pfy; if (curr_line < maxlines) { y += (curr_line * pfy) + h * (hr - begin_time + 1); headlines = lines = text_to_lines(cache[i].summary, 4); if (lines != NULL && lines->s != NULL) { appt_str = ckalloc(cm_strlen(lines->s)+18); format_line(start_tick, lines->s, appt_str, end_tick, cache[i].show_time, disp_t); lines = lines->next; } else { appt_str = ckalloc(15); format_line(start_tick, (char*)NULL, appt_str, end_tick, cache[i].show_time, disp_t); } appt_str[cm_strlen(appt_str)]=NULL; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); free(appt_str); appt_str = NULL; curr_line++; if (curr_line < maxlines && lines != NULL) { appt_str = ckalloc(324); cm_strcpy(appt_str, " "); while (lines != NULL) { if (lines->s != NULL) cm_strcat(appt_str, lines->s); lines = lines->next; if (lines != NULL && lines->s != NULL) cm_strcat(appt_str, " - "); } y += pfy; /* REVISIT: unclear why we're still distinguishing between gr_text[_rgb] if (c->xcontext->screen_depth >= 8) gr_text_rgb(c->xcontext, x, y, pf2, appt_str, fg, cmap, rect); else */ gr_text(c->xcontext, x, y, pf2, appt_str, rect); curr_line++; free(appt_str); appt_str = NULL; } destroy_lines(headlines); lines=NULL; } } } }
/* * Format 2 lines of appt data */ static void format_entry(Paint_cache *cache_entry, char *buf1, char *buf2, DisplayType display) { Tick tick, end_tick = 0; int hour1, min1, hour2, min2; Lines *lines; char *s1, *s2; struct tm *tm; _Xltimeparams localtime_buf; tick = cache_entry->start_time; end_tick = cache_entry->end_time; /* * Extract an appointment and format it into 2 lines of no more * then maxchars */ *buf1 = *buf2 = '\0'; if (cache_entry == NULL || cache_entry->summary == NULL) return; tm = _XLocaltime(&tick, localtime_buf); hour1 = tm->tm_hour; min1 = tm->tm_min; if (!cache_entry->show_time || magic_time(tick)) { lines = (Lines *) text_to_lines(cache_entry->summary, 1); if (lines==NULL) return; strncpy(buf2, lines->s, 256); destroy_lines(lines); return; } s1 = s2 = "am"; if (display == HOUR12 && !adjust_hour(&hour1)) s1="pm"; if (end_tick) { hour2 = hour(end_tick); min2 = minute(end_tick); if (display == HOUR12 && !adjust_hour(&hour2)) s2="pm"; } if (end_tick == 0 || (hour1 == hour2 && min1 == min2 && (strcmp(s1, s2) == 0))) { if (display == HOUR24) sprintf(buf1, "%02d%.2d", hour1, min1); else sprintf(buf1, "%d:%.2d%s", hour1, min1, s1); } else { if (display == HOUR12) sprintf(buf1, "%d:%.2d%s-%d:%.2d%s", hour1, min1, s1, hour2, min2, s2); else sprintf(buf1, "%02d%02d-%02d%02d", hour1, min1, hour2, min2); } lines = (Lines *) text_to_lines(cache_entry->summary, 1); if (lines == NULL || lines->s == NULL || (cm_strlen(lines->s) == 1 && lines->s[0] == ' ')) buf2[0] = '\0'; else sprintf(buf2, " %s", lines->s); destroy_lines(lines); }