[empathy/mc5: 208/483] Add empathy_account_settings_is_valid ()



commit a84e75c56b59533a551a411ff7a2aa7d88659cd4
Author: Cosimo Cecchi <cosimo cecchi collabora co uk>
Date:   Sun Jul 26 17:09:06 2009 +0200

    Add empathy_account_settings_is_valid ()

 libempathy/empathy-account-settings.c |   60 +++++++++++++++++++++++++++++++++
 libempathy/empathy-account-settings.h |    1 +
 2 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 4e32dfc..59cfcc5 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -72,6 +72,7 @@ struct _EmpathyAccountSettingsPriv
 
   GHashTable *parameters;
   GArray *unset_parameters;
+  GArray *required_params;
 
   gulong managers_ready_id;
   gulong account_ready_id;
@@ -360,6 +361,23 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
       return;
     }
 
+  if (priv->required_params == NULL)
+    {
+      TpConnectionManagerParam *cur;
+      char *val;
+
+      priv->required_params = g_array_new (TRUE, FALSE, sizeof (gchar *));
+
+      for (cur = priv->tp_protocol->params; cur->name != NULL; cur++)
+        {
+          if (tp_connection_manager_param_is_required (cur))
+            {
+              val = g_strdup (cur->name);
+              g_array_append_val (priv->required_params, val);
+            }
+        }
+    }
+
   g_object_ref (priv->manager);
 
   priv->ready = TRUE;
@@ -1022,3 +1040,45 @@ empathy_account_settings_owns_account (EmpathyAccountSettings *settings,
 
   return (account == priv->account);
 }
+
+gboolean
+empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
+{
+  EmpathyAccountSettingsPriv *priv;
+  int idx;
+  gchar *current;
+  gboolean missed = FALSE;
+
+  g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
+
+  priv = GET_PRIV (settings);
+
+  for (idx = 0; idx < priv->required_params->len; idx++)
+    {
+      current = g_array_index (priv->required_params, gchar *, idx);
+
+      /* first, look if it's set in our own parameters */
+      if (tp_asv_lookup (priv->parameters, current))
+        continue;
+
+      /* if we did not unset the parameter, look if it's in the account */
+      if (priv->account != NULL &&
+          !empathy_account_settings_is_unset (settings, current))
+        {
+          const GHashTable *account_params;
+
+          account_params = empathy_account_get_parameters (priv->account);
+          if (tp_asv_lookup (account_params, current))
+            continue;
+        }
+
+      /* see if there's a default value */
+      if (empathy_account_settings_get_default (settings, current))
+        continue;
+
+      missed = TRUE;
+      break;
+    }
+
+  return !missed;
+}
diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h
index 8119879..b660add 100644
--- a/libempathy/empathy-account-settings.h
+++ b/libempathy/empathy-account-settings.h
@@ -153,6 +153,7 @@ gboolean empathy_account_settings_apply_finish (
   GAsyncResult *result,
   GError **error);
 
+gboolean empathy_account_settings_is_valid (EmpathyAccountSettings *settings);
 
 G_END_DECLS
 



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