Hidden preference to limit PGP autocompletion
authorChristian Hesse <mail@eworm.de>
Mon, 7 Sep 2015 18:24:01 +0000 (20:24 +0200)
committerRicardo Mones <ricardo@mones.org>
Mon, 7 Sep 2015 22:32:03 +0000 (00:32 +0200)
Some keys have a lot of UIDs, resulting in a huge dropdown list. This
allows to limit PGP autocompletion to use the first n UID/address of a
key only.

src/plugins/pgpcore/autocompletion.c
src/plugins/pgpcore/prefs_gpg.c
src/plugins/pgpcore/prefs_gpg.h

index 2355bd8..286f241 100644 (file)
@@ -49,6 +49,7 @@ static gboolean pgp_autocompletion_hook(gpointer source, gpointer data)
        gpgme_user_id_t uid;
        address_entry *ae;
        GList *addr_list = NULL;
+       gint i;
 
        /* just return if autocompletion is disabled */
        if (!prefs_gpg_get_config()->autocompletion)
@@ -68,6 +69,7 @@ static gboolean pgp_autocompletion_hook(gpointer source, gpointer data)
                        /* skip keys that are revoked, expired, ... */
                        if ((key->revoked || key->expired || key->disabled || key->invalid) == FALSE) {
                                uid = key->uids;
+                               i = 0;
 
                                /* walk all user ids within a key */
                                while (uid != NULL) {
@@ -89,7 +91,13 @@ static gboolean pgp_autocompletion_hook(gpointer source, gpointer data)
 
                                                debug_print("%s <%s>\n", uid->name, uid->email);
                                        }
+
+                                       if (prefs_gpg_get_config()->autocompletion_limit > 0 &&
+                                                       prefs_gpg_get_config()->autocompletion_limit == i)
+                                               break;
+
                                        uid = uid->next;
+                                       i++;
                                }
                        }
                        gpgme_key_release(key);
index 80522d1..eb543a3 100644 (file)
@@ -47,6 +47,9 @@ static PrefParam param[] = {
        {"autocompletion", "FALSE",
         &prefs_gpg.autocompletion, P_BOOL,
         NULL, NULL, NULL},
+       {"autocompletion_limit", "0",
+        &prefs_gpg.autocompletion_limit, P_INT,
+        NULL, NULL, NULL},
        {"use_gpg_agent", "TRUE", &prefs_gpg.use_gpg_agent, P_BOOL,
         NULL, NULL, NULL},
        {"store_passphrase", "FALSE", &prefs_gpg.store_passphrase, P_BOOL,
index 28dec3f..3eb9c34 100644 (file)
@@ -35,6 +35,7 @@ struct GPGConfig
 {
        gboolean         auto_check_signatures;
        gboolean         autocompletion;
+       gint             autocompletion_limit;
        gboolean         use_gpg_agent;
        gboolean         store_passphrase;
        gint             store_passphrase_timeout;