summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/keyboard.c53
-rw-r--r--src/fe-common/core/keyboard.h2
-rw-r--r--src/fe-common/core/module-formats.c16
-rw-r--r--src/fe-common/core/module-formats.h15
4 files changed, 74 insertions, 12 deletions
diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c
index 79f0fbe4..827a80bd 100644
--- a/src/fe-common/core/keyboard.c
+++ b/src/fe-common/core/keyboard.c
@@ -19,8 +19,10 @@
*/
#include "module.h"
+#include "module-formats.h"
#include "signals.h"
#include "commands.h"
+#include "levels.h"
#include "lib-config/iconfig.h"
#include "settings.h"
@@ -55,7 +57,7 @@ static void keyconfig_clear(const char *id, const char *key)
if (key == NULL)
iconfig_node_set_str(node, id, NULL);
else {
- node = config_node_section(node, id, 0);
+ node = config_node_section(node, id, -1);
if (node != NULL) iconfig_node_set_str(node, key, NULL);
}
}
@@ -261,6 +263,51 @@ static void read_keyboard_config(void)
}
}
+static void cmd_show_keys(const char *searchkey)
+{
+ GSList *info, *key;
+ int len;
+
+ len = searchkey == NULL ? 0 : strlen(searchkey);
+ for (info = keyinfos; info != NULL; info = info->next) {
+ KEYINFO_REC *rec = info->data;
+
+ for (key = rec->keys; key != NULL; key = key->next) {
+ KEY_REC *rec = key->data;
+
+ if (len == 0 || strncmp(rec->key, searchkey, len) == 0) {
+ printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_BIND_KEY,
+ rec->key, rec->info->id, rec->data == NULL ? "" : rec->data);
+ }
+ }
+ }
+}
+
+static void cmd_bind(const char *data)
+{
+ GHashTable *optlist;
+ char *key, *id, *keydata;
+ void *free_arg;
+
+ if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS,
+ "bind", &optlist, &key, &id, &keydata))
+ return;
+
+ if (*key != '\0' && g_hash_table_lookup(optlist, "delete")) {
+ key_configure_remove(key);
+ } else if (*id == '\0') {
+ /* show some/all keys */
+ cmd_show_keys(key);
+ } else if (key_info_find(id) == NULL)
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_BIND_UNKNOWN_ID, id);
+ else {
+ key_configure_add(id, key, keydata);
+ cmd_show_keys(key);
+ }
+
+ cmd_params_free(free_arg);
+}
+
void keyboard_init(void)
{
keys = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
@@ -270,6 +317,9 @@ void keyboard_init(void)
read_keyboard_config();
signal_add("setup reread", (SIGNAL_FUNC) read_keyboard_config);
+
+ command_bind("bind", NULL, (SIGNAL_FUNC) cmd_bind);
+ command_set_options("bind", "delete");
}
void keyboard_deinit(void)
@@ -279,4 +329,5 @@ void keyboard_deinit(void)
g_hash_table_destroy(keys);
signal_remove("setup reread", (SIGNAL_FUNC) read_keyboard_config);
+ command_unbind("bind", (SIGNAL_FUNC) cmd_bind);
}
diff --git a/src/fe-common/core/keyboard.h b/src/fe-common/core/keyboard.h
index 4bce8c2b..6c41fbfd 100644
--- a/src/fe-common/core/keyboard.h
+++ b/src/fe-common/core/keyboard.h
@@ -14,7 +14,7 @@ typedef struct {
KEYINFO_REC *info;
char *key;
- void *data;
+ char *data;
} KEY_REC;
extern GSList *keyinfos;
diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c
index 497dab92..b6d66f70 100644
--- a/src/fe-common/core/module-formats.c
+++ b/src/fe-common/core/module-formats.c
@@ -97,15 +97,13 @@ FORMAT_REC fecommon_core_formats[] = {
{ "module_unloaded", "Unloaded module %_$0", 1, { 0 } },
/* ---- */
- { NULL, "Misc", 0 },
+ { NULL, "Commands", 0 },
- { "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
- { "perl_error", "Perl error: $0", 1, { 0 } },
+ { "command_unknown", "Unknown command: $0", 1, { 0 } },
+ { "command_ambiguous", "Ambiguous command: $0", 1, { 0 } },
{ "option_unknown", "Unknown option: $0", 1, { 0 } },
{ "option_ambiguous", "Ambiguous option: $0", 1, { 0 } },
{ "option_missing_arg", "Missing required argument for: $0", 1, { 0 } },
- { "command_unknown", "Unknown command: $0", 1, { 0 } },
- { "command_ambiguous", "Ambiguous command: $0", 1, { 0 } },
{ "not_enough_params", "Not enough parameters given", 0 },
{ "not_connected", "Not connected to IRC server yet", 0 },
{ "not_joined", "Not joined to any channels yet", 0 },
@@ -113,5 +111,13 @@ FORMAT_REC fecommon_core_formats[] = {
{ "chan_not_synced", "Channel not fully synchronized yet, try again after a while", 0 },
{ "not_good_idea", "Doing this is not a good idea. Add -YES if you really mean it", 0 },
+ /* ---- */
+ { NULL, "Misc", 0 },
+
+ { "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
+ { "perl_error", "Perl error: $0", 1, { 0 } },
+ { "bind_key", "$[10]0 $1 $2", 3, { 0, 0, 0 } },
+ { "bind_unknown_id", "Unknown bind action: $0", 1, { 0 } },
+
{ NULL, NULL, 0 }
};
diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h
index c88788c3..afb78bb4 100644
--- a/src/fe-common/core/module-formats.h
+++ b/src/fe-common/core/module-formats.h
@@ -71,19 +71,24 @@ enum {
IRCTXT_FILL_7,
- IRCTXT_NOT_TOGGLE,
- IRCTXT_PERL_ERROR,
+ IRCTXT_COMMAND_UNKNOWN,
+ IRCTXT_COMMAND_AMBIGUOUS,
IRCTXT_OPTION_UNKNOWN,
IRCTXT_OPTION_AMBIGUOUS,
IRCTXT_OPTION_MISSING_ARG,
- IRCTXT_COMMAND_UNKNOWN,
- IRCTXT_COMMAND_AMBIGUOUS,
IRCTXT_NOT_ENOUGH_PARAMS,
IRCTXT_NOT_CONNECTED,
IRCTXT_NOT_JOINED,
IRCTXT_CHAN_NOT_FOUND,
IRCTXT_CHAN_NOT_SYNCED,
- IRCTXT_NOT_GOOD_IDEA
+ IRCTXT_NOT_GOOD_IDEA,
+
+ IRCTXT_FILL_8,
+
+ IRCTXT_NOT_TOGGLE,
+ IRCTXT_PERL_ERROR,
+ IRCTXT_BIND_KEY,
+ IRCTXT_BIND_UNKNOWN_ID
};