home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* Copyright 1990 by Chuck Musciano and Harris Corporation */
- /* */
- /* Permission to use, copy, modify, and distribute this software */
- /* and its documentation for any purpose and without fee is */
- /* hereby granted, provided that the above copyright notice */
- /* appear in all copies and that both that copyright notice and */
- /* this permission notice appear in supporting documentation, and */
- /* that the name of Chuck Musciano and Harris Corporation not be */
- /* used in advertising or publicity pertaining to distribution */
- /* of the software without specific, written prior permission. */
- /* Chuck Musciano and Harris Corporation make no representations */
- /* about the suitability of this software for any purpose. It is */
- /* provided "as is" without express or implied warranty. */
- /* */
- /* This code contains data and information that is proprietary */
- /* to Casio Corporation. You may be subject to legal action if */
- /* this information is released without explicit permission from */
- /* Casio. */
- /************************************************************************/
-
- /************************************************************************/
- /* */
- /* do_schedule add Casio appointments to calentool file */
- /* */
- /************************************************************************/
-
- #include <stdio.h>
- #include <sys/param.h>
- #include <sys/types.h>
- #include <xview/xview.h>
- #include <xview/panel.h>
- #include "boss_ui.h"
-
- #include "manifest.h"
- #include "object.h"
- #include "globals.h"
-
- #include "calentool.h"
-
- #define round_minute(x) (((x) < 30)? 0 : 30)
- #define wc(x, y) (((x) == WILDCARD) || ((x) == (y)))
-
- #define CALENTOOL 0
- #define CALENDAR_MANAGER 1
-
- #define CALENTOOL_START (8 * 2) /* 8 AM in half hours */
- #define CALENTOOL_END (17 * 2 + 1) /* 5:30 PM */
-
- PUBLIC boss_base_objects *boss_base;
-
- PRIVATE boss_schedule_dialog_objects *dialog = NULL;
-
- /************************************************************************/
- PRIVATE reconcile_schedule_range(hour, minute, len, msg)
-
- int *hour;
- int *minute;
- int *len;
- char **msg;
-
- { char *p;
- int start, end, oh, om, new_start = FALSE, new_end = FALSE;
-
- start = *hour * 2 + *minute / 30;
- end = start + *len;
- if (start < CALENTOOL_START) {
- start = CALENTOOL_START;
- new_start = TRUE;
- }
- if (start > CALENTOOL_END) {
- start = CALENTOOL_END;
- new_start = TRUE;
- }
- if (end < CALENTOOL_START) {
- end = CALENTOOL_START;
- new_end = TRUE;
- }
- if (end > CALENTOOL_END) {
- end = CALENTOOL_END;
- new_end = TRUE;
- }
- if (new_start || new_end) {
- p = (char *) malloc(strlen(*msg) + 20);
- oh = *hour + *len / 2;
- om = *minute + (*len % 2 + 1) * 30;
- if (om >= 60) {
- oh++;
- om -= 60;
- }
- if (oh > 12)
- oh -= 12;
- if (new_start && !new_end)
- sprintf(p, "%s (%d:%02d)", *msg, (*hour > 12)? *hour - 12 : *hour, *minute);
- else if (new_start && new_end)
- sprintf(p, "%s (%d:%02d to %d:%02d)", *msg, (*hour > 12)? *hour - 12 : *hour, *minute, oh, om);
- else if (!new_start && new_end)
- sprintf(p, "%s (to %d:%02d)", *msg, oh, om);
- free(*msg);
- *msg = p;
- *hour = start / 2;
- *minute = (start % 2) * 30;
- *len = end - start;
- }
- }
-
- /************************************************************************/
- PRIVATE int convert_to_calentool()
-
- { calen *cal, *app, *new;
- char *path, *p, *msg;
- object *obj;
- int year, hour, minute, len;
-
- path = (char *) xv_get(dialog->appt_file, PANEL_VALUE);
- if (cal = load_calentool(path)) {
- for (obj = data[OBJ_SCHEDULE]; obj; obj = obj->next) {
- msg = strsave(obj->sch_memo);
- for (p = msg; *p; p++)
- if (*p == '\r')
- *p = ' ';
- year = obj->sch_date.year % 100;
- if (obj->sch_start_time.hour == INVALID_TIME) {
- hour = 99;
- minute = 99;
- }
- else {
- hour = obj->sch_start_time.hour;
- minute = round_minute(obj->sch_start_time.minute);
- }
- if (obj->sch_stop_time.hour == INVALID_TIME)
- len = 0;
- else
- len = ((obj->sch_stop_time.hour * 60 + round_minute(obj->sch_stop_time.minute)) - (hour * 60 + minute)) / 30 - 1;
- if (hour != 99)
- reconcile_schedule_range(&hour, &minute, &len, &msg);
- for (app = cal; app; app = app->next) {
- if (wc(app->year, year) && wc(app->month, obj->sch_date.month) && wc(app->day, obj->sch_date.day)) {
- if (hour == 99) {
- if (app->hour == 99 && strcmp(app->message, msg) == 0)
- break;
- }
- else if (hour == app->hour && minute == app->minute && len == app->length && strcmp(app->message, msg) == 0)
- break;
- }
- }
- if (app == NULL) {
- new = (calen *) malloc(sizeof(calen));
- bzero(new, sizeof(calen));
- new->kind = LINE_APPOINTMENT;
- new->year = year;
- new->month = obj->sch_date.month;
- new->day = obj->sch_date.day;
- new->hour = hour;
- new->minute = (hour == 99)? 0 : minute;
- new->length = len;
- new->repeat = -1;
- new->message = msg;
- for (app = cal; app->next; app = app->next)
- ;
- app->next = new;
- }
- else
- free(msg);
- }
- store_calentool(path, cal);
- return(XV_OK);
- }
- return(XV_ERROR);
- }
-
- /************************************************************************/
- PRIVATE int convert_to_calendar_manager()
-
- {
- error("Calendar Manager conversion is not yet available");
- return(XV_ERROR);
- }
-
- /************************************************************************/
- EXPORT Menu_item schedule_dialog(item, op)
-
- Menu_item item;
- Menu_generate op;
-
- {
- if (op == MENU_NOTIFY) {
- if (dialog == NULL) {
- dialog = boss_schedule_dialog_objects_initialize(NULL, boss_base->base);
- xv_set(dialog->appt_file,
- PANEL_VALUE, appts_file,
- PANEL_NOTIFY_LEVEL, PANEL_SPECIFIED,
- PANEL_NOTIFY_STRING, "\n\r ",
- PANEL_INACTIVE, FALSE,
- NULL);
- xv_set(dialog->schedule_format, PANEL_VALUE, 0, NULL);
- place_dialog(boss_base->base, dialog->schedule_dialog);
- }
- xv_set(dialog->schedule_dialog, XV_SHOW, TRUE, NULL);
- }
- return item;
- }
-
- /************************************************************************/
- EXPORT void schedule_notify(item, value, event)
-
- Panel_item item;
- int value;
- Event *event;
-
- {
- if (value == CALENTOOL)
- xv_set(dialog->appt_file, PANEL_INACTIVE, FALSE, NULL);
- else if (value == CALENDAR_MANAGER)
- xv_set(dialog->appt_file, PANEL_INACTIVE, TRUE, NULL);
- }
-
- /************************************************************************/
- EXPORT void accept_schedule(item, event)
-
- Panel_item item;
- Event *event;
-
- { int result, format;
-
- lets_get_busy(TRUE, NULL);
- if ((format = (int) xv_get(dialog->schedule_format, PANEL_VALUE)) == CALENTOOL)
- result = convert_to_calentool();
- else if (format == CALENDAR_MANAGER)
- result = convert_to_calendar_manager();
- xv_set(item, PANEL_NOTIFY_STATUS, result, NULL);
- lets_get_busy(FALSE, NULL);
- }
-