about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-03-06 19:35:00 +0140
committerPaul Fariello <paul@fariello.eu>2019-04-10 16:31:45 +0200
commitba0fa6e5360ce9350df469724d912be5644ac62b (patch)
tree9053edd73dbeb7e390a962e47dc1646a028e0bf4
parent2718183d27b20eae88d808b2cf181b22610c5e26 (diff)
downloadprofani-tty-ba0fa6e5360ce9350df469724d912be5644ac62b.tar.gz
Add OMEMO commands autocompletion
-rw-r--r--src/command/cmd_ac.c31
-rw-r--r--src/command/cmd_defs.c2
2 files changed, 32 insertions, 1 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 58ad758a..daf4f3a9 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -69,6 +69,7 @@ static char* _group_autocomplete(ProfWin *window, const char *const input, gbool
 static char* _bookmark_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _otr_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _pgp_autocomplete(ProfWin *window, const char *const input, gboolean previous);
+static char* _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _connect_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _alias_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _join_autocomplete(ProfWin *window, const char *const input, gboolean previous);
@@ -157,6 +158,7 @@ static Autocomplete bookmark_property_ac;
 static Autocomplete otr_ac;
 static Autocomplete otr_log_ac;
 static Autocomplete otr_policy_ac;
+static Autocomplete omemo_ac;
 static Autocomplete connect_property_ac;
 static Autocomplete tls_property_ac;
 static Autocomplete alias_ac;
@@ -574,6 +576,10 @@ cmd_ac_init(void)
     autocomplete_add(otr_policy_ac, "opportunistic");
     autocomplete_add(otr_policy_ac, "always");
 
+    omemo_ac = autocomplete_new();
+    autocomplete_add(omemo_ac, "gen");
+    autocomplete_add(omemo_ac, "start");
+
     connect_property_ac = autocomplete_new();
     autocomplete_add(connect_property_ac, "server");
     autocomplete_add(connect_property_ac, "port");
@@ -1052,6 +1058,7 @@ cmd_ac_reset(ProfWin *window)
     autocomplete_reset(otr_ac);
     autocomplete_reset(otr_log_ac);
     autocomplete_reset(otr_policy_ac);
+    autocomplete_reset(omemo_ac);
     autocomplete_reset(connect_property_ac);
     autocomplete_reset(tls_property_ac);
     autocomplete_reset(alias_ac);
@@ -1179,6 +1186,7 @@ cmd_ac_uninit(void)
     autocomplete_free(otr_ac);
     autocomplete_free(otr_log_ac);
     autocomplete_free(otr_policy_ac);
+    autocomplete_free(omemo_ac);
     autocomplete_free(connect_property_ac);
     autocomplete_free(tls_property_ac);
     autocomplete_free(alias_ac);
@@ -1438,6 +1446,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
     g_hash_table_insert(ac_funcs, "/autoconnect",   _autoconnect_autocomplete);
     g_hash_table_insert(ac_funcs, "/otr",           _otr_autocomplete);
     g_hash_table_insert(ac_funcs, "/pgp",           _pgp_autocomplete);
+    g_hash_table_insert(ac_funcs, "/omemo",         _omemo_autocomplete);
     g_hash_table_insert(ac_funcs, "/connect",       _connect_autocomplete);
     g_hash_table_insert(ac_funcs, "/alias",         _alias_autocomplete);
     g_hash_table_insert(ac_funcs, "/join",          _join_autocomplete);
@@ -2118,6 +2127,28 @@ _pgp_autocomplete(ProfWin *window, const char *const input, gboolean previous)
 }
 
 static char*
+_omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous)
+{
+    char *found = NULL;
+
+    jabber_conn_status_t conn_status = connection_get_status();
+
+    if (conn_status == JABBER_CONNECTED) {
+        found = autocomplete_param_with_func(input, "/omemo start", roster_contact_autocomplete, previous);
+        if (found) {
+            return found;
+        }
+    }
+
+    found = autocomplete_param_with_ac(input, "/omemo", omemo_ac, TRUE, previous);
+    if (found) {
+        return found;
+    }
+
+    return NULL;
+}
+
+static char*
 _plugins_autocomplete(ProfWin *window, const char *const input, gboolean previous)
 {
     char *result = NULL;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 265af119..3cd8330e 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2331,7 +2331,7 @@ static struct cmd_t command_defs[] =
     },
 
     { "/omemo",
-        parse_args, 1, 3, NULL,
+        parse_args, 1, 2, NULL,
         CMD_SUBFUNCS(
             { "gen", cmd_omemo_gen },
             { "start", cmd_omemo_start })