/* Bind a key for function */ void key_bind(const char *id, const char *description, const char *key_default, const char *data, SIGNAL_FUNC func) { KEYINFO_REC *info; char *key; g_return_if_fail(id != NULL); /* create key info record */ info = key_info_find(id); if (info == NULL) { g_return_if_fail(func != NULL); if (description == NULL) g_warning("key_bind(%s) should have description!", id); info = g_new0(KEYINFO_REC, 1); info->id = g_strdup(id); info->description = g_strdup(description); keyinfos = g_slist_append(keyinfos, info); /* add the signal */ key = g_strconcat("key ", id, NULL); signal_add(key, func); g_free(key); signal_emit("keyinfo created", 1, info); } if (key_default != NULL && *key_default != '\0') { key_default_add(id, key_default, data); key_configure_create(id, key_default, data); } }
/* Configure new key */ void key_configure_add(const char *id, const char *key, const char *data) { g_return_if_fail(id != NULL); g_return_if_fail(key != NULL && *key != '\0'); key_configure_create(id, key, data); keyconfig_save(id, key, data); }
static void key_config_read(CONFIG_NODE *node) { char *key, *id, *data; g_return_if_fail(node != NULL); key = config_node_get_str(node, "key", NULL); id = config_node_get_str(node, "id", NULL); data = config_node_get_str(node, "data", NULL); if (key != NULL && id != NULL) key_configure_create(id, key, data); }
void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node) { GSList *tmp; g_return_if_fail(info != NULL); g_return_if_fail(node != NULL); g_return_if_fail(is_node_list(node)); /* remove all old keys */ while (info->keys != NULL) key_configure_destroy(info->keys->data); /* add the new keys */ for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; if (node->key != NULL) key_configure_create(info->id, node->key, node->value); } }