]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-account-settings.c
Updated Basque language
[empathy.git] / libempathy / empathy-account-settings.c
index 6d43c478878dd6013c5b22084100312dc4c40d2f..49eb63366f0cef541457cd54cd043eb7f865fe8f 100644 (file)
@@ -40,6 +40,7 @@ enum {
   PROP_CM_NAME,
   PROP_PROTOCOL,
   PROP_DISPLAY_NAME,
+  PROP_DISPLAY_NAME_OVERRIDDEN,
   PROP_READY
 };
 
@@ -61,6 +62,7 @@ struct _EmpathyAccountSettingsPriv
   gchar *protocol;
   gchar *display_name;
   gchar *icon_name;
+  gboolean display_name_overridden;
   gboolean ready;
 
   GHashTable *parameters;
@@ -85,7 +87,9 @@ empathy_account_settings_init (EmpathyAccountSettings *obj)
   priv->managers = empathy_connection_managers_dup_singleton ();
   priv->account_manager = empathy_account_manager_dup_singleton ();
 
-  priv->parameters = tp_asv_new (NULL, NULL);
+  priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
+    g_free, (GDestroyNotify) tp_g_value_slice_free);
+
   priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *));
 }
 
@@ -119,6 +123,9 @@ empathy_account_settings_set_property (GObject *object,
       case PROP_DISPLAY_NAME:
         priv->display_name = g_value_dup_string (value);
         break;
+      case PROP_DISPLAY_NAME_OVERRIDDEN:
+        priv->display_name_overridden = g_value_get_boolean (value);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -148,6 +155,9 @@ empathy_account_settings_get_property (GObject *object,
       case PROP_DISPLAY_NAME:
         g_value_set_string (value, priv->display_name);
         break;
+      case PROP_DISPLAY_NAME_OVERRIDDEN:
+        g_value_set_boolean (value, priv->display_name_overridden);
+        break;
       case PROP_READY:
         g_value_set_boolean (value, priv->ready);
         break;
@@ -172,9 +182,13 @@ empathy_account_settings_constructed (GObject *object)
         g_strdup (empathy_account_get_connection_manager (priv->account));
       priv->protocol =
         g_strdup (empathy_account_get_protocol (priv->account));
+      priv->icon_name = g_strdup
+        (empathy_account_get_icon_name (priv->account));
+    }
+  else
+    {
+      priv->icon_name = empathy_protocol_icon_name (priv->protocol);
     }
-
-  priv->icon_name = g_strdup_printf ("im-%s", priv->protocol);
 
   g_assert (priv->cm_name != NULL && priv->protocol != NULL);
 
@@ -238,6 +252,14 @@ empathy_account_settings_class_init (
       NULL,
       G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
+  g_object_class_install_property (object_class, PROP_DISPLAY_NAME_OVERRIDDEN,
+      g_param_spec_boolean ("display-name-overridden",
+        "display-name-overridden",
+        "Whether the display name for this account has been manually "
+        "overridden",
+        FALSE,
+        G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
+
   g_object_class_install_property (object_class, PROP_READY,
     g_param_spec_boolean ("ready",
       "Ready",
@@ -352,7 +374,7 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
 
       g_free (priv->icon_name);
       priv->icon_name =
-        (gchar *) empathy_account_get_icon_name (priv->account);
+        g_strdup (empathy_account_get_icon_name (priv->account));
     }
 
   priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager,
@@ -513,6 +535,29 @@ empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings,
   return NULL;
 }
 
+static void
+account_settings_remove_from_unset (EmpathyAccountSettings *settings,
+    const gchar *param)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+  int idx;
+  gchar *val;
+
+  for (idx = 0; idx < priv->unset_parameters->len; idx++)
+    {
+      val = g_array_index (priv->unset_parameters, gchar *, idx);
+
+      if (!tp_strdiff (val, param))
+        {
+          priv->unset_parameters =
+            g_array_remove_index (priv->unset_parameters, idx);
+          g_free (val);
+
+          break;
+        }
+    }
+}
+
 const GValue *
 empathy_account_settings_get_default (EmpathyAccountSettings *settings,
     const gchar *param)
@@ -570,7 +615,6 @@ empathy_account_settings_get (EmpathyAccountSettings *settings,
   return empathy_account_settings_get_default (settings, param);
 }
 
-
 void
 empathy_account_settings_unset (EmpathyAccountSettings *settings,
     const gchar *param)
@@ -586,6 +630,15 @@ empathy_account_settings_unset (EmpathyAccountSettings *settings,
   g_hash_table_remove (priv->parameters, param);
 }
 
+void
+empathy_account_settings_discard_changes (EmpathyAccountSettings *settings)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+
+  g_hash_table_remove_all (priv->parameters);
+  empathy_account_settings_free_unset_parameters (settings);
+}
+
 const gchar *
 empathy_account_settings_get_string (EmpathyAccountSettings *settings,
     const gchar *param)
@@ -765,7 +818,9 @@ empathy_account_settings_set_string (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  tp_asv_set_string (priv->parameters, param, value);
+  tp_asv_set_string (priv->parameters, g_strdup (param), value);
+
+  account_settings_remove_from_unset (settings, param);
 }
 
 void
@@ -775,7 +830,9 @@ empathy_account_settings_set_int32 (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  tp_asv_set_int32 (priv->parameters, param, value);
+  tp_asv_set_int32 (priv->parameters, g_strdup (param), value);
+
+  account_settings_remove_from_unset (settings, param);
 }
 
 void
@@ -785,7 +842,9 @@ empathy_account_settings_set_int64 (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  tp_asv_set_int64 (priv->parameters, param, value);
+  tp_asv_set_int64 (priv->parameters, g_strdup (param), value);
+
+  account_settings_remove_from_unset (settings, param);
 }
 
 void
@@ -795,7 +854,9 @@ empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  tp_asv_set_uint32 (priv->parameters, param, value);
+  tp_asv_set_uint32 (priv->parameters, g_strdup (param), value);
+
+  account_settings_remove_from_unset (settings, param);
 }
 
 void
@@ -805,7 +866,9 @@ empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  tp_asv_set_uint64 (priv->parameters, param, value);
+  tp_asv_set_uint64 (priv->parameters, g_strdup (param), value);
+
+  account_settings_remove_from_unset (settings, param);
 }
 
 void
@@ -815,7 +878,9 @@ empathy_account_settings_set_boolean (EmpathyAccountSettings *settings,
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  tp_asv_set_boolean (priv->parameters, param, value);
+  tp_asv_set_boolean (priv->parameters, g_strdup (param), value);
+
+  account_settings_remove_from_unset (settings, param);
 }
 
 static void
@@ -879,7 +944,75 @@ empathy_account_settings_set_display_name_finish (
     return FALSE;
 
   g_return_val_if_fail (g_simple_async_result_is_valid (result,
-    G_OBJECT (settings), empathy_account_settings_set_display_name_finish), FALSE);
+    G_OBJECT (settings), empathy_account_settings_set_display_name_finish),
+      FALSE);
+
+  return TRUE;
+}
+
+static void
+account_settings_icon_name_set_cb (GObject *src,
+    GAsyncResult *res,
+    gpointer user_data)
+{
+  GError *error = NULL;
+  EmpathyAccount *account = EMPATHY_ACCOUNT (src);
+  GSimpleAsyncResult *set_result = user_data;
+
+  empathy_account_set_icon_name_finish (account, res, &error);
+
+  if (error != NULL)
+    {
+      g_simple_async_result_set_from_error (set_result, error);
+      g_error_free (error);
+    }
+
+  g_simple_async_result_complete (set_result);
+  g_object_unref (set_result);
+}
+
+void
+empathy_account_settings_set_icon_name_async (
+  EmpathyAccountSettings *settings,
+  const gchar *name,
+  GAsyncReadyCallback callback,
+  gpointer user_data)
+{
+  EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (settings),
+      callback, user_data, empathy_account_settings_set_icon_name_finish);
+
+  if (priv->account == NULL)
+    {
+      if (priv->icon_name != NULL)
+        g_free (priv->icon_name);
+
+      priv->icon_name = g_strdup (name);
+
+      g_simple_async_result_complete_in_idle (result);
+
+      return;
+    }
+
+  empathy_account_set_icon_name_async (priv->account, name,
+      account_settings_icon_name_set_cb, result);
+}
+
+gboolean
+empathy_account_settings_set_icon_name_finish (
+  EmpathyAccountSettings *settings,
+  GAsyncResult *result,
+  GError **error)
+{
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
+      error))
+    return FALSE;
+
+  g_return_val_if_fail (g_simple_async_result_is_valid (result,
+    G_OBJECT (settings), empathy_account_settings_set_icon_name_finish),
+      FALSE);
 
   return TRUE;
 }
@@ -900,6 +1033,10 @@ empathy_account_settings_account_updated (GObject *source,
       g_simple_async_result_set_from_error (priv->apply_result, error);
       g_error_free (error);
     }
+  else
+    {
+      empathy_account_settings_discard_changes (settings);
+    }
 
   r = priv->apply_result;
   priv->apply_result = NULL;
@@ -929,6 +1066,7 @@ empathy_account_settings_created_cb (GObject *source,
   else
     {
       priv->account = g_object_ref (account);
+      empathy_account_settings_discard_changes (settings);
     }
 
   r = priv->apply_result;
@@ -980,6 +1118,9 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *settings)
         TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence);
     }
 
+  tp_asv_set_string (properties, TP_IFACE_ACCOUNT ".Icon",
+      priv->icon_name);
+
   empathy_account_manager_create_account_async (priv->account_manager,
     priv->cm_name, priv->protocol, priv->display_name,
     priv->parameters, properties,
@@ -1042,9 +1183,6 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
       empathy_account_update_settings_async (priv->account,
         priv->parameters, (const gchar **)priv->unset_parameters->data,
         empathy_account_settings_account_updated, settings);
-
-      g_hash_table_remove_all (priv->parameters);
-      empathy_account_settings_free_unset_parameters (settings);
     }
 }