예제 #1
0
파일: statusbar.c 프로젝트: cpbills/irssi
static void statusbar_item_default_signals(SBAR_ITEM_REC *item)
{
	SIGNAL_FUNC func;
        GSList *list;
	const char *value;
        void *signal_id;
        int *signals, *pos;

	value = statusbar_item_get_value(item);
	if (value == NULL)
		return;

	signals = special_vars_get_signals(value);
	if (signals == NULL)
		return;

	for (pos = signals; *pos != -1; pos += 2) {
		/* update signal -> item mappings */
                signal_id = GINT_TO_POINTER(*pos);
		list = g_hash_table_lookup(sbar_signal_items, signal_id);
		if (list == NULL) {
			switch (pos[1]) {
			case EXPANDO_ARG_NONE:
				func = (SIGNAL_FUNC) statusbar_update_item;
				break;
			case EXPANDO_ARG_SERVER:
				func = (SIGNAL_FUNC) statusbar_update_server;
				break;
			case EXPANDO_ARG_WINDOW:
				func = (SIGNAL_FUNC) statusbar_update_window;
				break;
			case EXPANDO_ARG_WINDOW_ITEM:
				func = (SIGNAL_FUNC) statusbar_update_window_item;
				break;
			default:
                                func = NULL;
                                break;
			}
			if (func != NULL) {
				signal_add_full_id(MODULE_NAME,
						   SIGNAL_PRIORITY_DEFAULT,
						   *pos, func, NULL);
			}
		}

		if (g_slist_find(list, item) == NULL)
			list = g_slist_append(list, item);
		g_hash_table_insert(sbar_signal_items, signal_id, list);

                /* update item -> signal mappings */
		list = g_hash_table_lookup(sbar_item_signals, item);
                if (g_slist_find(list, signal_id) == NULL)
			list = g_slist_append(list, signal_id);
		g_hash_table_insert(sbar_item_signals, item, list);
	}
        g_free(signals);
}
예제 #2
0
void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
                                    const char *str, const char *data,
                                    int escape_vars)
{
    SERVER_REC *server;
    WI_ITEM_REC *wiitem;
    char *tmpstr, *tmpstr2;
    int len;

    if (str == NULL)
        str = statusbar_item_get_value(item);
    if (str == NULL || *str == '\0') {
        item->min_size = item->max_size = 0;
        return;
    }

    if (active_win == NULL) {
        server = NULL;
        wiitem = NULL;
    } else {
        server = active_win->active_server;
        wiitem = active_win->active;
    }

    /* expand templates */
    tmpstr = theme_format_expand_data(current_theme, &str,
                                      'n', 'n',
                                      NULL, NULL,
                                      EXPAND_FLAG_ROOT |
                                      EXPAND_FLAG_IGNORE_REPLACES |
                                      EXPAND_FLAG_IGNORE_EMPTY);
    /* expand $variables */
    tmpstr2 = parse_special_string(tmpstr, server, wiitem, data, NULL,
                                   (escape_vars ? PARSE_FLAG_ESCAPE_VARS : 0 ));
    g_free(tmpstr);

    /* remove color codes (not %formats) */
    tmpstr = strip_codes(tmpstr2);
    g_free(tmpstr2);

    if (get_size_only) {
        item->min_size = item->max_size = format_get_length(tmpstr);
    } else {
        if (item->size < item->min_size) {
            /* they're forcing us smaller than minimum size.. */
            len = format_real_length(tmpstr, item->size);
            tmpstr[len] = '\0';
        }

        tmpstr2 = update_statusbar_bg(tmpstr, item->bar->color);
        gui_printtext(item->xpos, item->bar->real_ypos, tmpstr2);
        g_free(tmpstr2);
    }
    g_free(tmpstr);
}
예제 #3
0
파일: statusbar.c 프로젝트: cpbills/irssi
void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
				    const char *str, const char *data,
				    int escape_vars)
{
	SERVER_REC *server;
	WI_ITEM_REC *wiitem; 
	char *tmpstr, *tmpstr2;
	theme_rm_col reset;
	strcpy(reset.m, "n");
	int len;

	if (str == NULL)
		str = statusbar_item_get_value(item);
	if (str == NULL || *str == '\0') {
		item->min_size = item->max_size = 0;
		return;
	}

	if (active_win == NULL) {
		server = NULL;
                wiitem = NULL;
	} else {
		server = active_win->active_server != NULL ?
			active_win->active_server : active_win->connect_server;
		wiitem = active_win->active;
	}

	/* expand templates */
	tmpstr = theme_format_expand_data(current_theme, &str,
					  reset, reset,
					  NULL, NULL,
					  EXPAND_FLAG_ROOT |
					  EXPAND_FLAG_IGNORE_REPLACES |
					  EXPAND_FLAG_IGNORE_EMPTY);
	/* expand $variables */
	tmpstr2 = parse_special_string(tmpstr, server, wiitem, data, NULL,
				       (escape_vars ? PARSE_FLAG_ESCAPE_VARS : 0 ));
        g_free(tmpstr);

	/* remove color codes (not %formats) */
	tmpstr = strip_codes(tmpstr2);
        g_free(tmpstr2);

	if (get_size_only) {
		item->min_size = item->max_size = format_get_length(tmpstr);
	} else {
		GString *out;

		if (item->size < item->min_size) {
                        /* they're forcing us smaller than minimum size.. */
			len = format_real_length(tmpstr, item->size);
                        tmpstr[len] = '\0';
		}
		out = finalize_string(tmpstr, item->bar->color);
		/* make sure the str is big enough to fill the
		   requested size, so it won't corrupt screen */
		len = format_get_length(tmpstr);
		if (len < item->size) {
			int i;

			len = item->size-len;
			for (i = 0; i < len; i++)
				g_string_append_c(out, ' ');
		}

		gui_printtext(item->xpos, item->bar->real_ypos, out->str);
		g_string_free(out, TRUE);
	}
	g_free(tmpstr);
}
예제 #4
0
void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
				    const char *str, const char *data,
				    int escape_vars)
{
	SERVER_REC *server;
	WI_ITEM_REC *wiitem; 
	char *tmpstr, *tmpstr2;
	int len;

	if (str == NULL)
		str = statusbar_item_get_value(item);
	if (str == NULL || *str == '\0') {
		item->min_size = item->max_size = 0;
		return;
	}

	if (active_win == NULL) {
		server = NULL;
                wiitem = NULL;
	} else {
		server = active_win->active_server != NULL ?
			active_win->active_server : active_win->connect_server;
		wiitem = active_win->active;
	}

	/* expand templates */
	tmpstr = theme_format_expand_data(current_theme, &str,
					  'n', 'n',
					  NULL, NULL,
					  EXPAND_FLAG_ROOT |
					  EXPAND_FLAG_IGNORE_REPLACES |
					  EXPAND_FLAG_IGNORE_EMPTY);
	/* expand $variables */
	tmpstr2 = parse_special_string(tmpstr, server, wiitem, data, NULL,
				       (escape_vars ? PARSE_FLAG_ESCAPE_VARS : 0 ));
        g_free(tmpstr);

	/* remove color codes (not %formats) */
	tmpstr = strip_codes(tmpstr2);
        g_free(tmpstr2);

	/* show all control chars reversed */
	tmpstr2 = reverse_controls(tmpstr);
	g_free(tmpstr);

	tmpstr = tmpstr2;
	if (get_size_only) {
		item->min_size = item->max_size = format_get_length(tmpstr);
	} else {
		if (item->size < item->min_size) {
                        /* they're forcing us smaller than minimum size.. */
			len = format_real_length(tmpstr, item->size);
                        tmpstr[len] = '\0';
		} else {
			/* make sure the str is big enough to fill the
			   requested size, so it won't corrupt screen */
			len = format_get_length(tmpstr);
			if (len < item->size) {
				char *fill;

				len = item->size-len;
				fill = g_malloc(len + 1);
				memset(fill, ' ', len); fill[len] = '\0';

				tmpstr2 = g_strconcat(tmpstr, fill, NULL);
				g_free(fill);
				g_free(tmpstr);
				tmpstr = tmpstr2;
			}
		}

		tmpstr2 = update_statusbar_bg(tmpstr, item->bar->color);
		gui_printtext(item->xpos, item->bar->real_ypos, tmpstr2);
                g_free(tmpstr2);
	}
	g_free(tmpstr);
}