Exemplo n.º 1
0
/*
 * This sends the new list of names to the properties database.  Note it ignores
 * items that have been tagged for deletion.
 */
static void
blist_write_list(Browselist *bl, Props *p) {
	int		i, len = 0;
	char		*buf;
	BlistData	*bd;

	/*
	 * First pass, count the number of bytes we're going to need
	 */
	for (i = 1; i <= bl->blist_data->count; i++) {
		bd = (BlistData *)CmDataListGetData(bl->blist_data, i);
		if (bd && bd->name && bd->tag != BLIST_DELETE)
			len += cm_strlen(bd->name) + 2; /* one for spacing */
	}
	if (len <= 0)
		return;

	/*
	 * We have names, so build the string, making sure to exclude items
	 * tagged for delete.
	 */
	buf = (char *)ckalloc(len);
	memset(buf, '\0', len);
	for (i = 1; i <= bl->blist_data->count; i++) {
		bd = (BlistData *)CmDataListGetData(bl->blist_data, i);
		if (bd && bd->name && bd->tag != BLIST_DELETE) {
			cm_strcat(buf, bd->name);
			cm_strcat(buf, " ");
			bd->tag = BLIST_ACTIVE;
		}
	}
        set_char_prop(p, CP_DAYCALLIST, buf);
	save_props(p);
        free(buf);
}
Exemplo n.º 2
0
/*
 * Remove the name from the UI and from the list if the calendar handle is NULL.
 * If the calendar handle is not null, tag it as deleted and it will be taken
 * care of later.
 */
static void
blist_removenames(Widget widget, XtPointer client_data, XtPointer call_data) {
	int		i, idx, valid_cnt, *pos_list, pos_cnt;
	Calendar	*c = (Calendar *)client_data;
	BlistData	*bd = NULL;
	Browselist	*bl = (Browselist *)c->browselist;
	int		rejected_name = 0;

	set_message(bl->message, " ");
	XmListGetSelectedPos(bl->browse_list, &pos_list, &pos_cnt);
	if (pos_cnt <= 0) {
		set_message(bl->message, catgets(calendar->DT_catd, 1, 17,
					      "Select a name to remove"));
		return;
	}

	for (i = 0; i < pos_cnt; i++) {
		if (pos_list[i] == 1) {
			set_message(bl->message, catgets(calendar->DT_catd, 1,
				16, "You may not remove the default calendar"));
			rejected_name++;
			continue;
		}

		XmListDeletePos(bl->browse_list, pos_list[i] - i + rejected_name);
		bd = (BlistData *)CmDataListGetData(bl->blist_data, pos_list[i]);

		if (bd)
		{
			bd->tag = BLIST_DELETE;
		}
	}
	blist_clean(bl, False);
	bl_list_is_changed(bl);
}
Exemplo n.º 3
0
static Boolean 
validate_dropped_appt(char *filename, Calendar *c) {
	Props			*p = (Props *)c->properties;
	Props_pu		*pu = (Props_pu *)c->properties_pu;
	CmDataList		*list = CmDataListCreate();
	Validate_op		op;
	int			i;
	Dtcm_appointment	*a;

	if (!filename || *filename == '\0')
		return(False);

	op = parse_appt_from_file(c->DT_catd, filename, list, p, query_user, 
				  (void *)c, c->general->version);

	for (i = 1; i <= list->count; i++)
		if (a = (Dtcm_appointment *)CmDataListGetData(list, i))
			free_appt_struct(&a);
	CmDataListDestroy(list, B_FALSE);

	if (op == VALID_APPT)
		return(True);
	else
		return(False);

}
Exemplo n.º 4
0
extern void
blist_clean(Browselist *bl, Boolean clean_all) {
	int		i, left_cnt = 1, cnt;
	BlistData	*bd;

	if (NULL == bl->blist_data) return;

	cnt = bl->blist_data->count;
	for (i = 1; i <= cnt; i++) {
		bd = (BlistData *)CmDataListGetData(bl->blist_data, left_cnt);
		if (bd && bd->cal_handle == NULL &&
		    (clean_all || bd->tag != BLIST_ACTIVE)) {
			if (bd->name)
				free(bd->name);
			CmDataListDeletePos(bl->blist_data, left_cnt, True);
		} else
			++left_cnt;
	}
}
Exemplo n.º 5
0
extern void
blist_init_ui(Calendar *c) {
	int		i;
	XmString	xmstr;
	BlistData	*bd;
	Browselist	*bl = (Browselist *)c->browselist;

	XtVaSetValues(bl->form, XmNresizePolicy, XmRESIZE_NONE, NULL);
	XmListDeleteAllItems(bl->browse_list);
	for (i = 1; i <= bl->blist_data->count; i++) {
		bd = (BlistData *)CmDataListGetData(bl->blist_data, i);
		if (bd && bd->name && bd->tag != BLIST_DELETE) {
			xmstr = XmStringCreateLocalized(bd->name);
			if (!XmListItemExists(bl->browse_list, xmstr))
				XmListAddItem(bl->browse_list, xmstr, 0);
			XmStringFree(xmstr);
		}
	}
	XmTextFieldSetString(bl->username, "");
	XtVaSetValues(bl->form, XmNresizePolicy, XmRESIZE_ANY, NULL);
}
Exemplo n.º 6
0
/*
 * Append the new name to the list and set the necessary tags.  Note this only
 * adds the name to the linked list - not to the UI.  Also, it won't add a
 * duplicate name.
 */
static int
blist_name_append(Calendar *c, char *name, BlistTag t) {
        int             i = 1;
	Boolean		marked = False;
        int             location = 2;
        BlistData       *bd;
        Browselist      *bl = (Browselist *)c->browselist;
	char		*defname;
 

	/* This while loop is doing double duty here.  The primary 
	   purpose of the list is to find out if the name we're 
	   inserting is already in the list.  While looping thru, 
	   the secondary purpose is to find the lexicographical 
	   position of the name relative to the current set of entries.  
	   The business about marked and location is related to that 
	   second purpose. */

        while ((bd = (BlistData *)CmDataListGetData(bl->blist_data, i)) &&
               strcmp(bd->name, name) != 0)
	{
                if ((marked == False) && (strcoll(name, bd->name) < 0) && 
		    (i != 1)) {
                        location = i;
			marked = True;
		}
                ++i;
	}

        if (bd) {
		/* Since the user may have hit the reset button, any items
		 * that had been marked for deletion need to be made active.
		 */
		if (bd->tag == BLIST_DELETE)
			bd->tag = BLIST_ACTIVE;

                return -1;
	}
	
	/* 2 special cases here.  If the name is that of the calendar 
	   owner, it should always be at the head of the list.  If the 
	   name wasn't maked against any of the people on the list, 
	   then it should be inserted at the end. */

	defname = get_user_calendar();
	if (strcmp(defname, name) == 0) {
		location = 1;
	} else if (marked == False) {
		location = i;
	}
	free(defname);
 
        bd = (BlistData *)ckalloc(sizeof(BlistData));
        bd->name = cm_strdup(name);
        bd->tag = t;
        bd->cal_handle = NULL;
        CmDataListAdd(bl->blist_data, (void *)bd, location);
 
        return location;

}
Exemplo n.º 7
0
/*
 * Call the routines in file_parse (in libDtCm) to read the appointments!
 */
extern int 
drag_load_proc(char *filename, Calendar *c) {
	int			ret_val, i = 1;
	char			buf[MAXNAMELEN * 2];
	CmDataList		*list = CmDataListCreate();
	Props			*p = (Props *)c->properties;
	Props_pu		*pu = (Props_pu *)c->properties_pu;
	Validate_op		op;
	Dtcm_appointment	*a;
	char			*msg;

	if (!filename || *filename == '\0')
		return -1;

	op = parse_appt_from_file(c->DT_catd, filename, list, p, query_user, 
				  (void *)c, c->general->version);
	if (list->count <= 0) {
		op = CANCEL_APPT;
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 842, 
	     "The information transferred did not\ncontain any appointments."));
	}

	switch(op) {
	case COULD_NOT_OPEN_FILE:
	  	msg = XtNewString(catgets(c->DT_catd, 1, 843, 
					"Drag and Drop operation failed."));
		sprintf(buf, "%s\n%s",
			msg,
			catgets(c->DT_catd, 1, 844, 
			      "Unable to locate the transferred information."));
		XtFree(msg);
		break;
	case INVALID_DATE:
		sprintf(buf, "%s",
			catgets(c->DT_catd, 1, 218, "Invalid DATE specified"));
		break;
	case INVALID_START:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 219,
					   "Invalid START time specified"));
		break;
	case INVALID_STOP:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 220,
					   "Invalid END time specified"));
		break;
	case MISSING_DATE:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 221,
					   "Empty or missing DATE field"));
		break;
	case MISSING_START:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 222,
					   "Empty or missing START field"));
		break;
	case MISSING_WHAT:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 223,
					   "Empty or missing WHAT field"));
		break;
	case REPEAT_FOR_MISMATCH:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 224,
					   "REPEAT and FOR field mismatch"));
		break;
	case VALID_APPT:
		break;
	case CANCEL_APPT:
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 225,
					   "Schedule appointment was cancelled."));
		break;
	default:
		op = CANCEL_APPT;
		sprintf(buf, "%s", catgets(c->DT_catd, 1, 225,
					   "Schedule appointment was cancelled."));
		break;
	}

	while (op == VALID_APPT && i <= list->count) {
		extern void scrub_attr_list(Dtcm_appointment *); 

		a = (Dtcm_appointment *)CmDataListGetData(list, i);

		scrub_attr_list(a);

		ret_val = schedule_appt(c, a);
		if (ret_val < 0) {
			op = CANCEL_APPT;
			sprintf(buf, "%s", catgets(c->DT_catd, 1, 226,
				"Internal error scheduling appointment."));
		} else if (ret_val == 0) {
			op = CANCEL_APPT;
			sprintf(buf, "%s", catgets(c->DT_catd, 1, 225,
				"Schedule appointment was cancelled."));
		}
		++i;
	}

	for (i = 1; i <= list->count; i++)
		if (a = (Dtcm_appointment *)CmDataListGetData(list, i))
			free_appt_struct(&a);
	CmDataListDestroy(list, B_FALSE);

	if (op != VALID_APPT) {
	  	char *title = XtNewString(catgets(c->DT_catd, 1, 1073,
					  "Calendar : Error - Drag and Drop"));
		char *ident = XtNewString(catgets(c->DT_catd, 1, 95, "Continue"));
		dialog_popup(c->frame,
			DIALOG_TITLE, title,
			DIALOG_TEXT, buf,
			BUTTON_IDENT, 1, ident,
			BUTTON_HELP, DND_ERROR_HELP,
			DIALOG_IMAGE, pu->xm_error_pixmap,
			NULL);
		XtFree(ident);
		XtFree(title);
		return -1;
	}

	return 0;
}