[evolution/gnome-3-16] Suggest the best authentication method after checking supported auths



commit 036c5713e90e9a1fa1d3bf02a14bd56ee9286ab3
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 31 10:16:49 2015 +0200

    Suggest the best authentication method after checking supported auths

 e-util/e-auth-combo-box.c       |   73 ++++++++++++++++++++++++++++++++++++++-
 e-util/e-auth-combo-box.h       |    2 +
 mail/e-mail-config-auth-check.c |    2 +
 3 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/e-util/e-auth-combo-box.c b/e-util/e-auth-combo-box.c
index bb54472..ff2ec86 100644
--- a/e-util/e-auth-combo-box.c
+++ b/e-util/e-auth-combo-box.c
@@ -214,6 +214,29 @@ e_auth_combo_box_set_provider (EAuthComboBox *combo_box,
        auth_combo_box_rebuild_model (combo_box);
 }
 
+static gint
+e_auth_combo_box_get_preference_level (const gchar *authproto)
+{
+       /* In order of preference, from the least to the best */
+       const gchar *protos[] = {
+               "CRAM-MD5",
+               "DIGEST-MD5",
+               "NTLM",
+               "GSSAPI"
+       };
+       gint ii;
+
+       if (!authproto)
+               return -1;
+
+       for (ii = 0; ii < G_N_ELEMENTS (protos); ii++) {
+               if (g_ascii_strcasecmp (protos[ii], authproto) == 0)
+                       return ii;
+       }
+
+       return -1;
+}
+
 void
 e_auth_combo_box_update_available (EAuthComboBox *combo_box,
                                    GList *available_authtypes)
@@ -223,6 +246,7 @@ e_auth_combo_box_update_available (EAuthComboBox *combo_box,
        GtkTreeIter iter;
        gint active_index;
        gint available_index = -1;
+       gint chosen_preference_level = -1;
        gint index = 0;
        gboolean iter_set;
 
@@ -237,6 +261,7 @@ e_auth_combo_box_update_available (EAuthComboBox *combo_box,
        while (iter_set) {
                CamelServiceAuthType *authtype;
                gboolean available;
+               gint preference_level = -1;
 
                gtk_tree_model_get (
                        model, &iter, COLUMN_AUTHTYPE, &authtype, -1);
@@ -248,11 +273,16 @@ e_auth_combo_box_update_available (EAuthComboBox *combo_box,
                        GTK_LIST_STORE (model), &iter,
                        COLUMN_STRIKETHROUGH, !available, -1);
 
+               if (authtype)
+                       preference_level = e_auth_combo_box_get_preference_level (authtype->authproto);
+
                if (index == active_index && !available)
                        active_index = -1;
 
-               if (available && available_index == -1)
+               if (available && (available_index == -1 || chosen_preference_level < preference_level)) {
                        available_index = index;
+                       chosen_preference_level = preference_level;
+               }
 
                iter_set = gtk_tree_model_iter_next (model, &iter);
                index++;
@@ -263,3 +293,44 @@ e_auth_combo_box_update_available (EAuthComboBox *combo_box,
        if (active_index == -1 && available_index != -1)
                gtk_combo_box_set_active (gtk_combo_box, available_index);
 }
+
+void
+e_auth_combo_box_pick_highest_available (EAuthComboBox *combo_box)
+{
+       GtkComboBox *gtk_combo_box;
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       gint highest_available_index = -1, index = 0;
+       gint chosen_preference_level = -1;
+
+       g_return_if_fail (E_IS_AUTH_COMBO_BOX (combo_box));
+
+       gtk_combo_box = GTK_COMBO_BOX (combo_box);
+       model = gtk_combo_box_get_model (gtk_combo_box);
+
+       if (gtk_tree_model_get_iter_first (model, &iter)) {
+               do {
+                       CamelServiceAuthType *authtype = NULL;
+                       gboolean unavailable = TRUE;
+                       gint preference_level = -1;
+
+                       gtk_tree_model_get (model, &iter,
+                               COLUMN_STRIKETHROUGH, &unavailable,
+                               COLUMN_AUTHTYPE, &authtype,
+                               -1);
+
+                       if (authtype)
+                               preference_level = e_auth_combo_box_get_preference_level 
(authtype->authproto);
+
+                       if (!unavailable && (highest_available_index == -1 || chosen_preference_level < 
preference_level)) {
+                               highest_available_index = index;
+                               chosen_preference_level = preference_level;
+                       }
+
+                       index++;
+               } while (gtk_tree_model_iter_next (model, &iter));
+       }
+
+       if (highest_available_index != -1)
+               gtk_combo_box_set_active (gtk_combo_box, highest_available_index);
+}
diff --git a/e-util/e-auth-combo-box.h b/e-util/e-auth-combo-box.h
index 8257091..3482838 100644
--- a/e-util/e-auth-combo-box.h
+++ b/e-util/e-auth-combo-box.h
@@ -67,6 +67,8 @@ void          e_auth_combo_box_set_provider   (EAuthComboBox *combo_box,
 void           e_auth_combo_box_update_available
                                                (EAuthComboBox *combo_box,
                                                 GList *available_authtypes);
+void           e_auth_combo_box_pick_highest_available
+                                               (EAuthComboBox *combo_box);
 
 G_END_DECLS
 
diff --git a/mail/e-mail-config-auth-check.c b/mail/e-mail-config-auth-check.c
index f547843..63c89f7 100644
--- a/mail/e-mail-config-auth-check.c
+++ b/mail/e-mail-config-auth-check.c
@@ -103,6 +103,8 @@ mail_config_auth_check_update_done_cb (GObject *source_object,
                e_auth_combo_box_update_available (
                        E_AUTH_COMBO_BOX (auth_check->priv->combo_box),
                        available_authtypes);
+               e_auth_combo_box_pick_highest_available (E_AUTH_COMBO_BOX (auth_check->priv->combo_box));
+
                g_list_free (available_authtypes);
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]