about summary refs log tree commit diff stats
path: root/src/pgp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-08-25 23:44:03 +0100
committerJames Booth <boothj5@gmail.com>2015-08-25 23:44:03 +0100
commitcb19be2ffcc1f2881427cc12f01ac8790d9236c1 (patch)
treefac2e88be2d777db348696fb00088ae45a87301f /src/pgp
parent55c2d1cc21974936e5b431de49ae81e6fc3845be (diff)
downloadprofani-tty-cb19be2ffcc1f2881427cc12f01ac8790d9236c1.tar.gz
Added PGP key autocompleter
Diffstat (limited to 'src/pgp')
-rw-r--r--src/pgp/gpg.c32
-rw-r--r--src/pgp/gpg.h2
2 files changed, 34 insertions, 0 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index b4bcef48..8d075cd9 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -47,6 +47,7 @@
 #include "pgp/gpg.h"
 #include "log.h"
 #include "common.h"
+#include "tools/autocomplete.h"
 
 #define PGP_SIGNATURE_HEADER "-----BEGIN PGP SIGNATURE-----"
 #define PGP_SIGNATURE_FOOTER "-----END PGP SIGNATURE-----"
@@ -59,6 +60,8 @@ static GHashTable *pubkeys;
 static gchar *pubsloc;
 static GKeyFile *pubkeyfile;
 
+static Autocomplete key_ac;
+
 static char* _remove_header_footer(char *str, const char * const footer);
 static char* _add_header_footer(const char * const str, const char * const header, const char * const footer);
 static void _save_pubkeys(void);
@@ -80,6 +83,10 @@ p_gpg_init(void)
     gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
 
     pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_p_gpg_free_pubkeyid);
+
+    key_ac = autocomplete_new();
+    GHashTable *keys = p_gpg_list_keys();
+    p_gpg_free_keys(keys);
 }
 
 void
@@ -97,6 +104,9 @@ p_gpg_close(void)
 
     free(pubsloc);
     pubsloc = NULL;
+
+    autocomplete_free(key_ac);
+    key_ac = NULL;
 }
 
 void
@@ -327,6 +337,16 @@ p_gpg_list_keys(void)
 
     gpgme_release(ctx);
 
+    autocomplete_clear(key_ac);
+    GList *ids = g_hash_table_get_keys(result);
+    GList *curr = ids;
+    while (curr) {
+        ProfPGPKey *key = g_hash_table_lookup(result, curr->data);
+        autocomplete_add(key_ac, key->id);
+        curr = curr->next;
+    }
+    g_list_free(ids);
+
     return result;
 }
 
@@ -639,6 +659,18 @@ p_gpg_free_decrypted(char *decrypted)
     g_free(decrypted);
 }
 
+char *
+p_gpg_autocomplete_key(const char * const search_str)
+{
+    return autocomplete_complete(key_ac, search_str, TRUE);
+}
+
+void
+p_gpg_autocomplete_key_reset(void)
+{
+    autocomplete_reset(key_ac);
+}
+
 static char*
 _remove_header_footer(char *str, const char * const footer)
 {
diff --git a/src/pgp/gpg.h b/src/pgp/gpg.h
index 2d3a78a3..48742dd7 100644
--- a/src/pgp/gpg.h
+++ b/src/pgp/gpg.h
@@ -67,5 +67,7 @@ void p_gpg_verify(const char * const barejid, const char *const sign);
 char* p_gpg_encrypt(const char * const barejid, const char * const message);
 char* p_gpg_decrypt(const char * const cipher);
 void p_gpg_free_decrypted(char *decrypted);
+char* p_gpg_autocomplete_key(const char * const search_str);
+void p_gpg_autocomplete_key_reset(void);
 
 #endif