示例#1
0
/* SYNTAX: STATUSBAR RESET <statusbar> */
static void cmd_statusbar_reset(const char *data, void *server, void *witem)
{
	CONFIG_NODE *node, *parent;
	char *name;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_STRIP_TRAILING_WS, &name))
		return;

	if (*name == '\0') {
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	}

	node = sbar_node(name, FALSE);
	if (node == NULL && !sbar_node_isdefault(name)) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_NOT_FOUND, name);
		cmd_params_free(free_arg);
		return;
	}

	parent = iconfig_node_traverse("statusbar", FALSE);
	if (parent != NULL) {
		parent = iconfig_node_section(parent, active_statusbar_group->name, -1);
	}

	if (parent != NULL && node != NULL) {
		iconfig_node_set_str(parent, node->key, NULL);
	}

	read_statusbar_config();
	cmd_params_free(free_arg);
}
示例#2
0
/* SYNTAX: STATUSBAR ADDITEM|MODIFYITEM [-before | -after <item>]
           [-priority #] [-alignment left|right] <item> <statusbar> */
static void cmd_statusbar_additem_modifyitem(const char *data, void *server, void *witem)
{
	CONFIG_NODE *node;
	GHashTable *optlist;
	char *item, *statusbar, *value;
	void *free_arg;
	int index;
	int additem = GPOINTER_TO_INT(signal_get_user_data());

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_STRIP_TRAILING_WS,
	                    "statusbar additem", &optlist, &item, &statusbar))
		return;

	if (*statusbar == '\0') {
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	}

	node = sbar_find_item_with_defaults(statusbar, item, additem);
	if (node == NULL) {
		cmd_params_free(free_arg);
		return;
	}

	/* get the index */
	index = -1;
	value = g_hash_table_lookup(optlist, "before");
	if (value != NULL)
		index = config_node_index(node, value);
	value = g_hash_table_lookup(optlist, "after");
	if (value != NULL)
		index = config_node_index(node, value) + 1;

	/* create/move item */
	node = iconfig_node_section_index(node, item, index, NODE_TYPE_BLOCK);

	/* set the options */
	value = g_hash_table_lookup(optlist, "priority");
	if (value != NULL) iconfig_node_set_int(node, "priority", atoi(value));

	value = g_hash_table_lookup(optlist, "alignment");
	if (value != NULL) {
		iconfig_node_set_str(node, "alignment",
				     g_ascii_strcasecmp(value, "right") == 0 ?
				     "right" : NULL);
	}

	read_statusbar_config();
	cmd_params_free(free_arg);
}
示例#3
0
void statusbar_config_init(void)
{
        read_statusbar_config();
	signal_add_last("setup reread", (SIGNAL_FUNC) read_statusbar_config);
	signal_add("theme changed", (SIGNAL_FUNC) read_statusbar_config);

        command_bind("statusbar", NULL, (SIGNAL_FUNC) cmd_statusbar);
        command_bind("statusbar enable", NULL, (SIGNAL_FUNC) cmd_statusbar_enable);
        command_bind("statusbar disable", NULL, (SIGNAL_FUNC) cmd_statusbar_disable);
        command_bind("statusbar reset", NULL, (SIGNAL_FUNC) cmd_statusbar_reset);
        command_bind("statusbar add", NULL, (SIGNAL_FUNC) cmd_statusbar_add);
        command_bind("statusbar remove", NULL, (SIGNAL_FUNC) cmd_statusbar_remove);
        command_bind("statusbar type", NULL, (SIGNAL_FUNC) cmd_statusbar_type);
        command_bind("statusbar placement", NULL, (SIGNAL_FUNC) cmd_statusbar_placement);
        command_bind("statusbar position", NULL, (SIGNAL_FUNC) cmd_statusbar_position);
        command_bind("statusbar visible", NULL, (SIGNAL_FUNC) cmd_statusbar_visible);

	command_set_options("statusbar add", "+before +after +priority +alignment");
}
示例#4
0
static void cmd_statusbar(const char *data)
{
        CONFIG_NODE *node;
	char *name, *cmd, *params, *signal;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
			    &name, &cmd, &params))
		return;

	if (*name == '\0') {
		/* list all statusbars */
                cmd_statusbar_list();
		cmd_params_free(free_arg);
                return;
	}

	if (*cmd == '\0') {
		/* print statusbar info */
                cmd_statusbar_print_info(name);
		cmd_params_free(free_arg);
                return;
	}

        /* lookup/create the statusbar node */
	node = iconfig_node_traverse("statusbar", TRUE);
	node = config_node_section(node, active_statusbar_group->name,
				   NODE_TYPE_BLOCK);
	node = config_node_section(node, name, NODE_TYPE_BLOCK);

	/* call the subcommand */
	signal = g_strconcat("command statusbar ", cmd, NULL);
        g_strdown(signal);
	if (!signal_emit(signal, 4, params, NULL, NULL, node)) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			    TXT_STATUSBAR_UNKNOWN_COMMAND, cmd);
	} else {
                read_statusbar_config();
	}
	g_free(signal);

	cmd_params_free(free_arg);
}
示例#5
0
/* SYNTAX: STATUSBAR REMOVEITEM <item> <statusbar> */
static void cmd_statusbar_removeitem(const char *data, void *server, void *witem)
{
	CONFIG_NODE *node;
	char *item, *statusbar;
	void *free_arg;
	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_STRIP_TRAILING_WS, &item, &statusbar))
		return;

	if (*statusbar == '\0') {
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	}

	node = sbar_find_item_with_defaults(statusbar, item, FALSE);

	if (node != NULL)
		iconfig_node_set_str(node, item, NULL);

	read_statusbar_config();
	cmd_params_free(free_arg);
}
示例#6
0
void statusbar_config_init(void)
{
        read_statusbar_config();
	signal_add_last("setup reread", (SIGNAL_FUNC) read_statusbar_config);
	signal_add("theme changed", (SIGNAL_FUNC) read_statusbar_config);

	command_bind("statusbar", NULL, (SIGNAL_FUNC) cmd_statusbar);
	command_bind("statusbar list", NULL, (SIGNAL_FUNC) cmd_statusbar_list);
	command_bind_data("statusbar add", NULL, (SIGNAL_FUNC) cmd_statusbar_add_modify, GINT_TO_POINTER(TRUE));
	command_bind_data("statusbar modify", NULL, (SIGNAL_FUNC) cmd_statusbar_add_modify, GINT_TO_POINTER(FALSE));
	command_bind("statusbar reset", NULL, (SIGNAL_FUNC) cmd_statusbar_reset);
	command_bind("statusbar info", NULL, (SIGNAL_FUNC) cmd_statusbar_info);
	command_bind_data("statusbar additem", NULL, (SIGNAL_FUNC) cmd_statusbar_additem_modifyitem, GINT_TO_POINTER(TRUE));
	command_bind_data("statusbar modifyitem", NULL, (SIGNAL_FUNC) cmd_statusbar_additem_modifyitem, GINT_TO_POINTER(FALSE));
	command_bind("statusbar removeitem", NULL, (SIGNAL_FUNC) cmd_statusbar_removeitem);

	command_set_options("statusbar additem", "+before +after +priority +alignment");
	command_set_options("statusbar modifyitem", "+before +after +priority +alignment");
	command_set_options("statusbar add",
	                    "disable nodisable +type +placement +position +visible");
	command_set_options("statusbar modify",
	                    "disable nodisable +type +placement +position +visible");
}
示例#7
0
/* SYNTAX: STATUSBAR ADD|MODIFY [-disable | -nodisable] [-type window|root]
           [-placement top|bottom] [-position #] [-visible always|active|inactive] <statusbar> */
static void cmd_statusbar_add_modify(const char *data, void *server, void *witem)
{
	GHashTable *optlist;
	CONFIG_NODE *node;
	char *name, *type, *placement, *visible;
	void *free_arg;
	int error;
	int add = GPOINTER_TO_INT(signal_get_user_data());

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | PARAM_FLAG_STRIP_TRAILING_WS,
	                    "statusbar add", &optlist, &name))
		return;

	if (*name == '\0') {
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	}

	error = 0;

	type = NULL;
	data = g_hash_table_lookup(optlist, "type");
	if (data != NULL) {
		if (g_ascii_strcasecmp(data, "window") == 0)
			type = "window";
		else if (g_ascii_strcasecmp(data, "root") == 0)
			type = "root";
		else {
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_UNKNOWN_TYPE,
			            data);
			error++;
		}
	}

	placement = NULL;
	data = g_hash_table_lookup(optlist, "placement");
	if (data != NULL) {
		if (g_ascii_strcasecmp(data, "top") == 0)
			placement = "top";
		else if (g_ascii_strcasecmp(data, "bottom") == 0)
			placement = "bottom";
		else {
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			            TXT_STATUSBAR_UNKNOWN_PLACEMENT, data);
			error++;
		}
	}

	visible = NULL;
	data = g_hash_table_lookup(optlist, "visible");
	if (data != NULL) {
		if (g_ascii_strcasecmp(data, "always") == 0)
			visible = "always";
		else if (g_ascii_strcasecmp(data, "active") == 0)
			visible = "active";
		else if (g_ascii_strcasecmp(data, "inactive") == 0)
			visible = "inactive";
		else {
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			            TXT_STATUSBAR_UNKNOWN_VISIBILITY, data);
			error++;
		}
	}

	if (!error) {
		node = sbar_node(name, add);
		if (node == NULL && !add && sbar_node_isdefault(name)) {
			/* If this node is a default status bar, we need to create it in the config
			 * to configure it */
			node = sbar_node(name, TRUE);
		}

		if (node == NULL) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_NOT_FOUND, name);
			error++;
		}
	}

	if (error) {
		cmd_params_free(free_arg);
		return;
	}

	if (g_hash_table_lookup(optlist, "nodisable"))
		iconfig_node_set_str(node, "disabled", NULL);
	if (g_hash_table_lookup(optlist, "disable"))
		iconfig_node_set_bool(node, "disabled", TRUE);
	if (type != NULL)
		iconfig_node_set_str(node, "type", type);
	if (placement != NULL)
		iconfig_node_set_str(node, "placement", placement);
	data = g_hash_table_lookup(optlist, "position");
	if (data != NULL)
		iconfig_node_set_int(node, "position", atoi(data));
	if (visible != NULL)
		iconfig_node_set_str(node, "visible", visible);

	read_statusbar_config();
	cmd_params_free(free_arg);
}