Ejemplo n.º 1
0
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);
        }
}
Ejemplo n.º 2
0
extern int
count_multi_appts(CSA_entry_handle *list, int num_entries, Calendar *c)
{
    CSA_return_code stat;
    Dtcm_appointment *appt;
    int count = 0, i, meoval;
    Props *pr = (Props*)c->properties;
    Lines *lines, *l_ptr;

    meoval = get_int_prop(pr, CP_PRINTPRIVACY);

    appt = allocate_appt_struct(appt_read,
                                c->general->version,
                                CSA_ENTRY_ATTR_CLASSIFICATION_I,
                                CSA_X_DT_ENTRY_ATTR_SHOWTIME_I,
                                CSA_ENTRY_ATTR_SUMMARY_I,
                                NULL);
    for (i = 0; i < num_entries; i++) {

        stat = query_appt_struct(c->cal_handle, list[i], appt);

        if (stat != CSA_SUCCESS) {
            free_appt_struct(&appt);
            return 0;
        }

        if ((privacy_set(appt) == CSA_CLASS_PUBLIC) && !(meoval & PRINT_PUBLIC))
            continue;
        else if ((privacy_set(appt) == CSA_CLASS_CONFIDENTIAL) &&
                 !(meoval & PRINT_SEMIPRIVATE))
            continue;
        else if ((privacy_set(appt) == CSA_CLASS_PRIVATE) &&
                 !(meoval & PRINT_PRIVATE))
            continue;

        if (showtime_set(appt)) {
            count++;
        }
        l_ptr = lines = text_to_lines(appt->what->value->item.string_value, 10);
        while (lines != NULL) {
            count++;
            lines = lines->next;
        }
        destroy_lines(l_ptr);
    }
    free_appt_struct(&appt);
    return(count);
}
Ejemplo n.º 3
0
/*
 *  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);
}
Ejemplo n.º 4
0
/*
 *  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);
}
Ejemplo n.º 5
0
Archivo: alarm.c Proyecto: juddy/edcde
/*
**  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));
}
Ejemplo n.º 6
0
Archivo: alarm.c Proyecto: juddy/edcde
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);
}
Ejemplo n.º 7
0
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;
			}
		}
	}
}
Ejemplo n.º 8
0
/*
 *  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);
}