]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-account-settings.c
Updated Basque language
[empathy.git] / libempathy / empathy-account-settings.c
index 6129570c2f068d715ba6aa1b06340911955d09bb..49eb63366f0cef541457cd54cd043eb7f865fe8f 100644 (file)
@@ -182,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);
 
@@ -251,7 +255,8 @@ empathy_account_settings_class_init (
   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",
+        "Whether the display name for this account has been manually "
+        "overridden",
         FALSE,
         G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
 
@@ -575,6 +580,9 @@ empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings,
 
   p = empathy_account_settings_get_tp_param (settings, param);
 
+  if (p == NULL)
+    return NULL;
+
   return p->dbus_signature;
 }
 
@@ -627,14 +635,8 @@ empathy_account_settings_discard_changes (EmpathyAccountSettings *settings)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  if (g_hash_table_size (priv->parameters) > 0)
-    g_hash_table_remove_all (priv->parameters);
-
-  if (priv->unset_parameters->len > 0)
-    {
-      g_array_remove_range (priv->unset_parameters, 0,
-          priv->unset_parameters->len);
-    }
+  g_hash_table_remove_all (priv->parameters);
+  empathy_account_settings_free_unset_parameters (settings);
 }
 
 const gchar *
@@ -948,6 +950,73 @@ empathy_account_settings_set_display_name_finish (
   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;
+}
+
 static void
 empathy_account_settings_account_updated (GObject *source,
     GAsyncResult *result,
@@ -964,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;
@@ -987,9 +1060,14 @@ empathy_account_settings_created_cb (GObject *source,
     EMPATHY_ACCOUNT_MANAGER (source), result, &error);
 
   if (account == NULL)
-    g_simple_async_result_set_from_error (priv->apply_result, error);
+    {
+      g_simple_async_result_set_from_error (priv->apply_result, error);
+    }
   else
-    priv->account = g_object_ref (account);
+    {
+      priv->account = g_object_ref (account);
+      empathy_account_settings_discard_changes (settings);
+    }
 
   r = priv->apply_result;
   priv->apply_result = NULL;
@@ -1040,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,
@@ -1088,12 +1169,6 @@ empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
 
   if (priv->account == NULL)
     {
-      const gchar *default_display_name;
-      default_display_name = empathy_account_settings_get_string (settings,
-          "account");
-      empathy_account_settings_set_display_name_async (settings,
-          default_display_name, NULL, NULL);
-
       if (empathy_account_manager_is_ready (priv->account_manager))
         empathy_account_settings_do_create_account (settings);
       else
@@ -1108,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);
     }
 }