コード例 #1
0
ファイル: bindings.c プロジェクト: dmilith/ekg2-bsd
void binding_helper_scroll(window_t *w, int offset) {
    ncurses_window_t *n;

    if (!w || !(n = w->priv_data))
        return;

    if (offset < 0) {
        n->start += offset;
        if (n->start < 0)
            n->start = 0;

    } else {
        n->start += offset;

        if (n->start > n->lines_count - w->height + n->overflow)
            n->start = n->lines_count - w->height + n->overflow;

        if (n->start < 0)
            n->start = 0;

        /* old code from: binding_forward_page() need it */
        if (w == window_current) {
            if (ncurses_current->start == ncurses_current->lines_count - window_current->height + ncurses_current->overflow) {
                window_current->more = 0;
                update_statusbar(0);
            }
        }
    }

    ncurses_redraw(w);
    ncurses_commit();
}
コード例 #2
0
/*
 * ncurses_input_update()
 *
 * uaktualnia zmianê rozmiaru pola wpisywania tekstu -- przesuwa okienka
 * itd. je¶li zmieniono na pojedyncze, czy¶ci dane wej¶ciowe.
 */
void ncurses_input_update(int new_line_index)
{
	if (ncurses_input_size == 1) {
		g_strfreev((char **) ncurses_lines);
		ncurses_lines = NULL;
		ncurses_line = xmalloc(LINE_MAXLEN*sizeof(CHAR_T));

		ncurses_history[0] = ncurses_line;

	} else {
		ncurses_lines = xmalloc(2 * sizeof(CHAR_T *));
		ncurses_lines[0] = xmalloc(LINE_MAXLEN*sizeof(CHAR_T));
/*		ncurses_lines[1] = NULL; */
		xwcscpy(ncurses_lines[0], ncurses_line);
		xfree(ncurses_line);
		ncurses_line = ncurses_lines[0];
		ncurses_history[0] = NULL;
	}
	line_start = 0;
	line_index = new_line_index;
	lines_start = 0;
	lines_index = 0;

	ncurses_resize();

	ncurses_redraw(window_current);
	touchwin(ncurses_current->window);

	ncurses_commit();
}
コード例 #3
0
ファイル: contacts.c プロジェクト: dmilith/ekg2-bsd
/*
 * ncurses_contacts_update()
 *
 * updates contacts window 
 * 
 * it switches also groups, metacontacts, all together
 * details in documentation
 * 
 */
int ncurses_contacts_update(window_t *w, int save_pos) {
	int old_start;

	const char *header = NULL, *footer = NULL;
	char *group = NULL;
	int j;
	int all = 0; /* 1 - all, 2 - metacontacts */
	ncurses_window_t *n;
	newconference_t *c	= NULL;
	userlist_t *sorted_all	= NULL;
	int (*comp)(void *, void *) = NULL;		/* coz userlist's list are sorted we don't need to sort it again... 
								unfortunetly if we create list from serveral userlists (for instance: session && window)
								we must resort... --- in ekg2 we do 
									list_add_sorted(...., NULL) on session userlist &&
									list_add_sorted(...., contacts_compare) on window userlist
							*/

	
	if (!w) w = window_find_sa(NULL, "__contacts", 1);
	if (!w)
		return -1;

	n = w->priv_data;
	
	if (save_pos) 
		old_start = n->start;
	else
		old_start = 0;
	
	ncurses_clear(w, 1);

	if (!session_current)
		goto kon;

	if (config_contacts_groups) {
		char **groups = array_make(config_contacts_groups, ", ", 0, 1, 0);
		int count = array_count(groups);

		if (contacts_group_index > count + 2) {
			contacts_group_index = 0;
		} else if (contacts_group_index > count + 1) {
			if (metacontacts)
				all = 2;
			else
				contacts_group_index = 0;
		} else if (contacts_group_index > count) {
			all = 1;
		} else if (contacts_group_index > 0) {
			all = config_contacts_groups_all_sessions ? 1 : 0;
			group = groups[contacts_group_index - 1];
			if (*group == '@')
				group++;
			group = xstrdup(group);
			header = format_find("contacts_header_group");
			footer = format_find("contacts_footer_group");
		}
		array_free(groups);
	} else if (contacts_group_index) {
		if (contacts_group_index > ((metacontacts) ? 2 :1) )
			contacts_group_index = 0;
		else
			all = contacts_group_index;
	}

	if (all == 2) {
		header = format_find("contacts_metacontacts_header");
		footer = format_find("contacts_metacontacts_footer");
	}

	c = newconference_find(window_current->session, window_current->target);
	if (!session_current->userlist && !window_current->userlist && (!c || !c->participants) && !all && contacts_group_index == 0)
		goto kon;

	if (!header || !footer) {
		header = format_find("contacts_header");
		footer = format_find("contacts_footer");
	}

	if (format_ok(header))
		ncurses_backlog_add(w, fstring_new_format(header, group));

	if (all == 1) {
		userlist_t *l;
		session_t *s;

		for (s = sessions; s; s = s->next) {
			userlist_t *lp;

			if (!s->userlist)
				continue;

			for (lp = s->userlist; lp; lp = lp->next) {
				userlist_t *u = lp;

				if (!u->nickname)	/* don't add users without nickname.. */
					continue;

				LIST_ADD_SORTED2(&sorted_all, userlist_dup(u, u->uid, u->nickname, s), comp);
			}

			comp = contacts_compare;		/* turn on sorting */
		}

		for (l = c ? c->participants : window_current->userlist; l; l = l->next) {
			userlist_t *u = l;

			if (!u->nickname)	/* don't add users without nickname.. */
				continue;

			LIST_ADD_SORTED2(&sorted_all, userlist_dup(u, u->uid, u->nickname, w->session), comp);
		}

		if (sorted_all) comp = contacts_compare;	/* like above */
	}

	if (all == 1 || all == 2) {
		metacontact_t *m;

		/* Remove contacts contained in metacontacts. */
		if (all == 1 && config_contacts_metacontacts_swallow) {
			for (m = metacontacts; m; m = m->next) {
				metacontact_item_t *i;

				/* metacontact_find_prio() should always success [for current API] */
/*
				if (!metacontact_find_prio(m)) 
					continue;
*/
				for (i = m->metacontact_items; i; i = i->next) {
					userlist_t *u;
					userlist_t *sl;

					if (!(u = userlist_find_n(i->s_uid, i->name)))
						continue;

					for (sl = sorted_all; sl;) {
						userlist_t *up = sl;
						userlist_t *next = sl->next;;

			/* up->uid == u->uid (?) */
						if (up->uid && !xstrcmp(up->uid, u->uid))
							LIST_REMOVE2(&sorted_all, up, NULL);

						sl = next;
					}
				}
			}
		}

		for (m = metacontacts; m; m = m->next) {
			metacontact_item_t *i;
			userlist_t *u;

			if (!(i = metacontact_find_prio(m)))
				continue;

			if (!(u = userlist_find_n(i->s_uid, i->name)))
				continue;

			if (!m->name)	/* don't add metacontacts without name.. */
				continue;

			LIST_ADD_SORTED2(&sorted_all, userlist_dup(u, NULL, m->name, (void *) 2), comp);
		}
	}

	if (!all) {
		sorted_all = session_current->userlist;

		if (c && c->participants) 
			sorted_all = c->participants;
		else if (window_current->userlist)
			sorted_all = window_current->userlist;
	}

	if (!sorted_all)
		goto after_loop;	/* it skips this loop below */

	for (j = 0; j < corderlen; /* xstrlen(contacts_order); */ j += 2) {
		const char *footer_status = NULL;
		int count = 0;
		char tmp[100];
		userlist_t *ul;

		for (ul = sorted_all; ul; ul = ul->next) {
			userlist_t *u = ul;

			const char *status_t;
			const char *format;
			fstring_t *string;

			if (!u->nickname || !u->status) 
				continue;

			status_t = ekg_status_string(u->status, 0);

			if (config_contacts_orderbystate ?
				xstrncmp(contacts_order + j, status_t, 2) :		/* when config_contacts_orderbystate, we need to have got this status in contacts_order now. */
				!xstrstr(contacts_order, get_short_status(status_t)))	/* when !config_contacts_orderbystate, we need to have got this status in contacts_order anywhere. */
					continue;

			if (group && (!u->priv_data || (void *) 2 != u->priv_data)) {
				userlist_t *tmp = userlist_find(u->priv_data ? u->priv_data : session_current, u->uid);
				if ((group[0]=='!' && ekg_group_member(tmp, group+1)) ||
						(group[0]!='!' && !ekg_group_member(tmp, group)))
					continue;
			}

			if (!count) {
				snprintf(tmp, sizeof(tmp), "contacts_%s_header", status_t);
				format = format_find(tmp);
				if (format_ok(format))
					ncurses_backlog_add(w, fstring_new_format(format));
				footer_status = status_t;
			}

			if (u->descr && config_contacts_descr)
				snprintf(tmp, sizeof(tmp), "contacts_%s_descr_full", status_t);
			else if (u->descr && !config_contacts_descr)
				snprintf(tmp, sizeof(tmp), "contacts_%s_descr", status_t);
			else
				snprintf(tmp, sizeof(tmp), "contacts_%s", status_t);

			if (u->blink)
				xstrcat(tmp, "_blink");
			if (u->typing)
				xstrcat(tmp, "_typing");

			string = fstring_new_format(format_find(tmp), u->nickname, u->descr);

			if (u->priv_data == (void *) 2)
				string->priv_data = (void *) xstrdup(u->nickname);
			else 
				string->priv_data = (void *) saprintf("%s/%s", (u->priv_data) ? ((session_t *) u->priv_data)->uid : session_current->uid, u->nickname);

			ncurses_backlog_add(w, string);

			count++;
		}

		if (count) {
			const char *format;

			snprintf(tmp, sizeof(tmp), "contacts_%s_footer", footer_status);
			format = format_find(tmp);

			if (format_ok(format))
				ncurses_backlog_add(w, fstring_new_format(format));
		}

		if (!config_contacts_orderbystate)
			break;
	}

after_loop:
	if (format_ok(footer))
		ncurses_backlog_add(w, fstring_new_format(footer, group));
	if (all)
		LIST_DESTROY2(sorted_all, NULL);

	xfree(group);

kon:
/* restore old index */
	n->start = old_start;
	
	if (n->start > n->lines_count - w->height + n->overflow)
		n->start = n->lines_count - w->height + n->overflow;

	if (n->start < 0)
		n->start = 0;

/* redraw */
	n->redraw = 1;
	ncurses_redraw(w);

	return -1;
}