]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-account-settings.c
Updated Basque language
[empathy.git] / libempathy / empathy-account-settings.c
index 1c5bc719ad20e0d0700d10a0fe864bb4a961f40e..49eb63366f0cef541457cd54cd043eb7f865fe8f 100644 (file)
@@ -23,6 +23,8 @@
 #include <stdlib.h>
 
 #include <telepathy-glib/util.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/gtypes.h>
 
 #include "empathy-account-settings.h"
 #include "empathy-account-manager.h"
 
 G_DEFINE_TYPE(EmpathyAccountSettings, empathy_account_settings, G_TYPE_OBJECT)
 
-/* signal enum */
-#if 0
-enum
-{
-    LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-#endif
-
 enum {
   PROP_ACCOUNT = 1,
   PROP_CM_NAME,
   PROP_PROTOCOL,
   PROP_DISPLAY_NAME,
+  PROP_DISPLAY_NAME_OVERRIDDEN,
   PROP_READY
 };
 
@@ -68,6 +61,8 @@ struct _EmpathyAccountSettingsPriv
   gchar *cm_name;
   gchar *protocol;
   gchar *display_name;
+  gchar *icon_name;
+  gboolean display_name_overridden;
   gboolean ready;
 
   GHashTable *parameters;
@@ -92,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 *));
 }
 
@@ -126,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;
@@ -155,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;
@@ -174,18 +177,20 @@ empathy_account_settings_constructed (GObject *object)
     {
       g_free (priv->cm_name);
       g_free (priv->protocol);
-      g_free (priv->display_name);
 
       priv->cm_name =
         g_strdup (empathy_account_get_connection_manager (priv->account));
       priv->protocol =
         g_strdup (empathy_account_get_protocol (priv->account));
-      priv->display_name =
-        g_strdup (empathy_account_get_display_name (priv->account));
+      priv->icon_name = g_strdup
+        (empathy_account_get_icon_name (priv->account));
+    }
+  else
+    {
+      priv->icon_name = empathy_protocol_icon_name (priv->protocol);
     }
 
-  g_assert (priv->cm_name != NULL && priv->protocol != NULL
-    && priv->display_name != NULL);
+  g_assert (priv->cm_name != NULL && priv->protocol != NULL);
 
   empathy_account_settings_check_readyness (self);
 
@@ -247,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",
@@ -302,7 +315,7 @@ empathy_account_settings_dispose (GObject *object)
 
 static void
 empathy_account_settings_free_unset_parameters (
-  EmpathyAccountSettings *settings)
+    EmpathyAccountSettings *settings)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
   int i;
@@ -323,6 +336,7 @@ empathy_account_settings_finalize (GObject *object)
   g_free (priv->cm_name);
   g_free (priv->protocol);
   g_free (priv->display_name);
+  g_free (priv->icon_name);
 
   g_hash_table_destroy (priv->parameters);
 
@@ -352,6 +366,17 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
   if (priv->manager == NULL)
     return;
 
+  if (priv->account != NULL)
+    {
+      g_free (priv->display_name);
+      priv->display_name =
+        g_strdup (empathy_account_get_display_name (priv->account));
+
+      g_free (priv->icon_name);
+      priv->icon_name =
+        g_strdup (empathy_account_get_icon_name (priv->account));
+    }
+
   priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager,
     priv->protocol);
 
@@ -386,7 +411,8 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
 
 static void
 empathy_account_settings_ready_cb (GObject *obj,
-  GParamSpec *spec, gpointer user_data)
+    GParamSpec *spec,
+    gpointer user_data)
 {
   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
 
@@ -447,15 +473,12 @@ empathy_account_settings_get_protocol (EmpathyAccountSettings *settings)
   return priv->protocol;
 }
 
-const gchar *
+gchar *
 empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
-  if (priv->account != NULL)
-    return empathy_account_get_icon_name (priv->account);
-
-  return NULL;
+  return priv->icon_name;
 }
 
 const gchar *
@@ -476,7 +499,7 @@ empathy_account_settings_get_account (EmpathyAccountSettings *settings)
 
 static gboolean
 empathy_account_settings_is_unset (EmpathyAccountSettings *settings,
-  const gchar *param)
+    const gchar *param)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
   GArray *a;
@@ -495,7 +518,7 @@ empathy_account_settings_is_unset (EmpathyAccountSettings *settings,
 
 static TpConnectionManagerParam *
 empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings,
-  const gchar *param)
+    const gchar *param)
 {
   TpConnectionManagerParam *tp_params =
       empathy_account_settings_get_tp_params (settings);
@@ -512,9 +535,32 @@ 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)
+    const gchar *param)
 {
   TpConnectionManagerParam *p;
 
@@ -527,8 +573,8 @@ empathy_account_settings_get_default (EmpathyAccountSettings *settings,
 }
 
 const gchar *
-empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings,
-  const gchar *param)
+empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings,
+    const gchar *param)
 {
   TpConnectionManagerParam *p;
 
@@ -542,7 +588,7 @@ empathy_settings_get_dbus_signature (EmpathyAccountSettings *settings,
 
 const GValue *
 empathy_account_settings_get (EmpathyAccountSettings *settings,
-  const gchar *param)
+    const gchar *param)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
   const GValue *result = NULL;
@@ -569,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)
@@ -585,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)
@@ -764,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
@@ -774,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
@@ -784,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
@@ -794,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
@@ -804,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
@@ -814,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
@@ -878,14 +944,83 @@ 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;
 }
 
 static void
 empathy_account_settings_account_updated (GObject *source,
-  GAsyncResult *result, gpointer user_data)
+    GAsyncResult *result,
+    gpointer user_data)
 {
   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
@@ -898,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;
@@ -908,8 +1047,8 @@ empathy_account_settings_account_updated (GObject *source,
 
 static void
 empathy_account_settings_created_cb (GObject *source,
-  GAsyncResult *result,
-  gpointer user_data)
+    GAsyncResult *result,
+    gpointer user_data)
 {
   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
@@ -927,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;
@@ -942,8 +1082,44 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *settings)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
   GHashTable *properties;
+  TpConnectionPresenceType type;
+  gchar *status;
+  gchar *message;
 
-  properties = g_hash_table_new (NULL, NULL);
+  properties = tp_asv_new (NULL, NULL);
+
+  type = empathy_account_manager_get_requested_global_presence
+    (priv->account_manager, &status, &message);
+
+  if (type != TP_CONNECTION_PRESENCE_TYPE_UNSET)
+    {
+      /* Create the account with the requested presence the same as the current
+        * global requested presence, but don't enable it */
+      GValueArray *presence;
+      GValue vtype = { 0, };
+      GValue vstatus = { 0, };
+      GValue vmessage = { 0, };
+
+      presence = g_value_array_new (3);
+
+      g_value_init (&vtype, G_TYPE_UINT);
+      g_value_set_uint (&vtype, type);
+      g_value_array_append (presence, &vtype);
+
+      g_value_init (&vstatus, G_TYPE_STRING);
+      g_value_take_string (&vstatus, status);
+      g_value_array_append (presence, &vstatus);
+
+      g_value_init (&vmessage, G_TYPE_STRING);
+      g_value_take_string (&vmessage, message);
+      g_value_array_append (presence, &vmessage);
+
+      tp_asv_take_boxed (properties, TP_IFACE_ACCOUNT ".RequestedPresence",
+        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,
@@ -956,7 +1132,8 @@ empathy_account_settings_do_create_account (EmpathyAccountSettings *settings)
 
 static void
 empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager,
-  GParamSpec *spec, gpointer user_data)
+    GParamSpec *spec,
+    gpointer user_data)
 {
   EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
@@ -974,8 +1151,8 @@ empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager,
 
 void
 empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
-  GAsyncReadyCallback callback,
-  gpointer user_data)
+    GAsyncReadyCallback callback,
+    gpointer user_data)
 {
   EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
 
@@ -1006,16 +1183,13 @@ 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);
     }
 }
 
 gboolean
 empathy_account_settings_apply_finish (EmpathyAccountSettings *settings,
-  GAsyncResult *result,
-  GError **error)
+    GAsyncResult *result,
+    GError **error)
 {
   if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
       error))