static void keyboard_save(GObject *obj, Key *key) { GtkTreeModel *model; GtkTreeSelection *sel; GtkTreeIter iter; const char *key_name, *data; KeyAction *action; key_name = gtk_entry_get_text(g_object_get_data(obj, "key")); if (*key_name == '\0') { gui_popup_error("Key can't be empty"); return; } data = gtk_entry_get_text(g_object_get_data(obj, "data")); /* get selected action */ sel = gtk_tree_view_get_selection(g_object_get_data(obj, "action_tree")); if (!gtk_tree_selection_get_selected(sel, &model, &iter)) { gui_popup_error("No action was selected"); return; } gtk_tree_model_get(model, &iter, COL_PTR, &action, -1); if (key != NULL && strcmp(key->key, key_name) != 0) key_configure_remove(key->key); key_configure_add(action->id, key_name, data); }
/* SYNTAX: BIND [-list] [-delete] [<key> [<command> [<data>]]] */ static void cmd_bind(const char *data) { GHashTable *optlist; char *key, *id, *keydata; void *free_arg; int command_id; if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS, "bind", &optlist, &key, &id, &keydata)) return; if (g_hash_table_lookup(optlist, "list")) { GSList *tmp; for (tmp = keyinfos; tmp != NULL; tmp = tmp->next) { KEYINFO_REC *rec = tmp->data; printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_BIND_COMMAND_LIST, rec->id, rec->description ? rec->description : ""); } cmd_params_free(free_arg); return; } if (*key != '\0' && g_hash_table_lookup(optlist, "delete")) { /* delete key */ key_configure_remove(key); cmd_params_free(free_arg); return; } if (*id == '\0') { /* show some/all keys */ cmd_show_keys(key, FALSE); cmd_params_free(free_arg); return; } command_id = strchr(settings_get_str("cmdchars"), *id) != NULL; if (command_id) { /* using shortcut to command id */ keydata = g_strconcat(id+1, " ", keydata, NULL); id = "command"; } if (key_info_find(id) == NULL) printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_BIND_UNKNOWN_ID, id); else { key_configure_add(id, key, keydata); cmd_show_keys(key, TRUE); } if (command_id) g_free(keydata); cmd_params_free(free_arg); }
/* Configure new key */ static void key_configure_create(const char *id, const char *key, const char *data) { KEYINFO_REC *info; KEY_REC *rec; g_return_if_fail(id != NULL); g_return_if_fail(key != NULL && *key != '\0'); info = key_info_find(id); if (info == NULL) return; key_configure_remove(key); rec = g_new0(KEY_REC, 1); rec->key = g_strdup(key); rec->info = info; rec->data = g_strdup(data); info->keys = g_slist_append(info->keys, rec); g_hash_table_insert(keys, rec->key, rec); }
void read_keyinfo(KEYINFO_REC *info, CONFIG_NODE *node) { GSList *tmp; char *data, *key; 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_remove(((KEY_REC *) info->keys->data)->key); /* add the new keys */ for (tmp = node->value; tmp != NULL; tmp = tmp->next) { node = tmp->data; data = config_node_get_str(node->value, "data", NULL); key = config_node_get_str(node->value, "key", NULL); if (key != NULL) key_configure_add(info->id, data, key); } }