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 2355bd81daabcc7cc292566c8d057f08467e6529..286f2419468febcffbaf274f51e035573374bd35 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;
        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)
 
        /* 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;
                        /* 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) {
 
                                /* 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);
                                        }
 
                                                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;
                                        uid = uid->next;
+                                       i++;
                                }
                        }
                        gpgme_key_release(key);
                                }
                        }
                        gpgme_key_release(key);
index 80522d163de7cec77d31d59d3e871246bbd25bc6..eb543a31ea224d1c207899b3578f9eba8ad8ffa6 100644 (file)
@@ -47,6 +47,9 @@ static PrefParam param[] = {
        {"autocompletion", "FALSE",
         &prefs_gpg.autocompletion, P_BOOL,
         NULL, NULL, NULL},
        {"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,
        {"use_gpg_agent", "TRUE", &prefs_gpg.use_gpg_agent, P_BOOL,
         NULL, NULL, NULL},
        {"store_passphrase", "FALSE", &prefs_gpg.store_passphrase, P_BOOL,
index 28dec3f63efc195bb57862a43f95409e456a59e1..3eb9c34b7c5a28af02ab181a05938293bb4615e2 100644 (file)
@@ -35,6 +35,7 @@ struct GPGConfig
 {
        gboolean         auto_check_signatures;
        gboolean         autocompletion;
 {
        gboolean         auto_check_signatures;
        gboolean         autocompletion;
+       gint             autocompletion_limit;
        gboolean         use_gpg_agent;
        gboolean         store_passphrase;
        gint             store_passphrase_timeout;
        gboolean         use_gpg_agent;
        gboolean         store_passphrase;
        gint             store_passphrase_timeout;