2 * empathy-account-settings.c - Source for EmpathyAccountSettings
3 * Copyright (C) 2009 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <telepathy-glib/util.h>
26 #include <telepathy-glib/interfaces.h>
27 #include <telepathy-glib/gtypes.h>
29 #include "empathy-account-settings.h"
30 #include "empathy-account-manager.h"
31 #include "empathy-connection-managers.h"
32 #include "empathy-utils.h"
34 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountSettings)
36 G_DEFINE_TYPE(EmpathyAccountSettings, empathy_account_settings, G_TYPE_OBJECT)
43 PROP_DISPLAY_NAME_OVERRIDDEN,
47 /* private structure */
48 typedef struct _EmpathyAccountSettingsPriv EmpathyAccountSettingsPriv;
50 struct _EmpathyAccountSettingsPriv
52 gboolean dispose_has_run;
53 EmpathyConnectionManagers *managers;
54 EmpathyAccountManager *account_manager;
55 gulong account_manager_ready_id;
57 TpConnectionManager *manager;
58 const TpConnectionManagerProtocol *tp_protocol;
60 EmpathyAccount *account;
65 gboolean display_name_overridden;
68 GHashTable *parameters;
69 GArray *unset_parameters;
70 GArray *required_params;
72 gulong managers_ready_id;
73 gulong account_ready_id;
75 GSimpleAsyncResult *apply_result;
79 empathy_account_settings_init (EmpathyAccountSettings *obj)
81 EmpathyAccountSettingsPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE ((obj),
82 EMPATHY_TYPE_ACCOUNT_SETTINGS, EmpathyAccountSettingsPriv);
86 /* allocate any data required by the object here */
87 priv->managers = empathy_connection_managers_dup_singleton ();
88 priv->account_manager = empathy_account_manager_dup_singleton ();
90 priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal,
91 g_free, (GDestroyNotify) tp_g_value_slice_free);
93 priv->unset_parameters = g_array_new (TRUE, FALSE, sizeof (gchar *));
96 static void empathy_account_settings_dispose (GObject *object);
97 static void empathy_account_settings_finalize (GObject *object);
98 static void empathy_account_settings_ready_cb (GObject *obj,
99 GParamSpec *spec, gpointer user_data);
100 static void empathy_account_settings_check_readyness (
101 EmpathyAccountSettings *self);
104 empathy_account_settings_set_property (GObject *object,
109 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (object);
110 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
115 priv->account = g_value_dup_object (value);
118 priv->cm_name = g_value_dup_string (value);
121 priv->protocol = g_value_dup_string (value);
123 case PROP_DISPLAY_NAME:
124 priv->display_name = g_value_dup_string (value);
126 case PROP_DISPLAY_NAME_OVERRIDDEN:
127 priv->display_name_overridden = g_value_get_boolean (value);
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 empathy_account_settings_get_property (GObject *object,
141 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (object);
142 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
147 g_value_set_object (value, priv->account);
150 g_value_set_string (value, priv->cm_name);
153 g_value_set_string (value, priv->protocol);
155 case PROP_DISPLAY_NAME:
156 g_value_set_string (value, priv->display_name);
158 case PROP_DISPLAY_NAME_OVERRIDDEN:
159 g_value_set_boolean (value, priv->display_name_overridden);
162 g_value_set_boolean (value, priv->ready);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 empathy_account_settings_constructed (GObject *object)
173 EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object);
174 EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
176 if (priv->account != NULL)
178 g_free (priv->cm_name);
179 g_free (priv->protocol);
182 g_strdup (empathy_account_get_connection_manager (priv->account));
184 g_strdup (empathy_account_get_protocol (priv->account));
187 priv->icon_name = g_strdup_printf ("im-%s", priv->protocol);
189 g_assert (priv->cm_name != NULL && priv->protocol != NULL);
191 empathy_account_settings_check_readyness (self);
195 g_signal_connect (priv->account, "notify::ready",
196 G_CALLBACK (empathy_account_settings_ready_cb), self);
197 g_signal_connect (priv->managers, "notify::ready",
198 G_CALLBACK (empathy_account_settings_ready_cb), self);
202 empathy_account_settings_parent_class)->constructed != NULL)
204 empathy_account_settings_parent_class)->constructed (object);
209 empathy_account_settings_class_init (
210 EmpathyAccountSettingsClass *empathy_account_settings_class)
212 GObjectClass *object_class = G_OBJECT_CLASS (empathy_account_settings_class);
214 g_type_class_add_private (empathy_account_settings_class, sizeof
215 (EmpathyAccountSettingsPriv));
217 object_class->dispose = empathy_account_settings_dispose;
218 object_class->finalize = empathy_account_settings_finalize;
219 object_class->set_property = empathy_account_settings_set_property;
220 object_class->get_property = empathy_account_settings_get_property;
221 object_class->constructed = empathy_account_settings_constructed;
223 g_object_class_install_property (object_class, PROP_ACCOUNT,
224 g_param_spec_object ("account",
226 "The EmpathyAccount backing these settings",
227 EMPATHY_TYPE_ACCOUNT,
228 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
230 g_object_class_install_property (object_class, PROP_CM_NAME,
231 g_param_spec_string ("connection-manager",
232 "connection-manager",
233 "The name of the connection manager this account uses",
235 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
237 g_object_class_install_property (object_class, PROP_PROTOCOL,
238 g_param_spec_string ("protocol",
240 "The name of the protocol this account uses",
242 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
244 g_object_class_install_property (object_class, PROP_DISPLAY_NAME,
245 g_param_spec_string ("display-name",
247 "The display name account these settings belong to",
249 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
251 g_object_class_install_property (object_class, PROP_DISPLAY_NAME_OVERRIDDEN,
252 g_param_spec_boolean ("display-name-overridden",
253 "display-name-overridden",
254 "Whether the display name for this account has been manually overridden",
256 G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
258 g_object_class_install_property (object_class, PROP_READY,
259 g_param_spec_boolean ("ready",
261 "Whether this account is ready to be used",
263 G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
267 empathy_account_settings_dispose (GObject *object)
269 EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object);
270 EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
272 if (priv->dispose_has_run)
275 priv->dispose_has_run = TRUE;
277 if (priv->managers_ready_id != 0)
278 g_signal_handler_disconnect (priv->managers, priv->managers_ready_id);
279 priv->managers_ready_id = 0;
281 if (priv->managers != NULL)
282 g_object_unref (priv->managers);
283 priv->managers = NULL;
285 if (priv->manager != NULL)
286 g_object_unref (priv->manager);
287 priv->manager = NULL;
289 if (priv->account_manager_ready_id != 0)
290 g_signal_handler_disconnect (priv->account_manager,
291 priv->account_manager_ready_id);
292 priv->account_manager_ready_id = 0;
294 if (priv->account_manager != NULL)
295 g_object_unref (priv->account_manager);
296 priv->account_manager = NULL;
298 if (priv->account_ready_id != 0)
299 g_signal_handler_disconnect (priv->account, priv->account_ready_id);
300 priv->account_ready_id = 0;
302 if (priv->account != NULL)
303 g_object_unref (priv->account);
304 priv->account = NULL;
306 /* release any references held by the object here */
307 if (G_OBJECT_CLASS (empathy_account_settings_parent_class)->dispose)
308 G_OBJECT_CLASS (empathy_account_settings_parent_class)->dispose (object);
312 empathy_account_settings_free_unset_parameters (
313 EmpathyAccountSettings *settings)
315 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
318 for (i = 0 ; i < priv->unset_parameters->len; i++)
319 g_free (g_array_index (priv->unset_parameters, gchar *, i));
321 g_array_set_size (priv->unset_parameters, 0);
325 empathy_account_settings_finalize (GObject *object)
327 EmpathyAccountSettings *self = EMPATHY_ACCOUNT_SETTINGS (object);
328 EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
330 /* free any data held directly by the object here */
331 g_free (priv->cm_name);
332 g_free (priv->protocol);
333 g_free (priv->display_name);
334 g_free (priv->icon_name);
336 g_hash_table_destroy (priv->parameters);
338 empathy_account_settings_free_unset_parameters (self);
339 g_array_free (priv->unset_parameters, TRUE);
341 G_OBJECT_CLASS (empathy_account_settings_parent_class)->finalize (object);
345 empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
347 EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
352 if (priv->account != NULL && !empathy_account_is_ready (priv->account))
355 if (!empathy_connection_managers_is_ready (priv->managers))
358 priv->manager = empathy_connection_managers_get_cm (
359 priv->managers, priv->cm_name);
361 if (priv->manager == NULL)
364 if (priv->account != NULL)
366 g_free (priv->display_name);
368 g_strdup (empathy_account_get_display_name (priv->account));
370 g_free (priv->icon_name);
372 g_strdup (empathy_account_get_icon_name (priv->account));
375 priv->tp_protocol = tp_connection_manager_get_protocol (priv->manager,
378 if (priv->tp_protocol == NULL)
380 priv->manager = NULL;
384 if (priv->required_params == NULL)
386 TpConnectionManagerParam *cur;
389 priv->required_params = g_array_new (TRUE, FALSE, sizeof (gchar *));
391 for (cur = priv->tp_protocol->params; cur->name != NULL; cur++)
393 if (tp_connection_manager_param_is_required (cur))
395 val = g_strdup (cur->name);
396 g_array_append_val (priv->required_params, val);
401 g_object_ref (priv->manager);
404 g_object_notify (G_OBJECT (self), "ready");
408 empathy_account_settings_ready_cb (GObject *obj,
412 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
414 empathy_account_settings_check_readyness (settings);
417 EmpathyAccountSettings *
418 empathy_account_settings_new (const gchar *connection_manager,
419 const gchar *protocol,
420 const char *display_name)
422 return g_object_new (EMPATHY_TYPE_ACCOUNT_SETTINGS,
423 "connection-manager", connection_manager,
424 "protocol", protocol,
425 "display-name", display_name,
429 EmpathyAccountSettings *
430 empathy_account_settings_new_for_account (EmpathyAccount *account)
432 return g_object_new (EMPATHY_TYPE_ACCOUNT_SETTINGS,
437 TpConnectionManagerParam *
438 empathy_account_settings_get_tp_params (EmpathyAccountSettings *settings)
440 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
442 g_return_val_if_fail (priv->tp_protocol != NULL, NULL);
444 return priv->tp_protocol->params;
448 empathy_account_settings_is_ready (EmpathyAccountSettings *settings)
450 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
456 empathy_account_settings_get_cm (EmpathyAccountSettings *settings)
458 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
460 return priv->cm_name;
464 empathy_account_settings_get_protocol (EmpathyAccountSettings *settings)
466 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
468 return priv->protocol;
472 empathy_account_settings_get_icon_name (EmpathyAccountSettings *settings)
474 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
476 return priv->icon_name;
480 empathy_account_settings_get_display_name (EmpathyAccountSettings *settings)
482 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
484 return priv->display_name;
488 empathy_account_settings_get_account (EmpathyAccountSettings *settings)
490 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
492 return priv->account;
496 empathy_account_settings_is_unset (EmpathyAccountSettings *settings,
499 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
503 a = priv->unset_parameters;
505 for (i = 0; i < a->len; i++)
507 if (!tp_strdiff (g_array_index (a, gchar *, i), param))
514 static TpConnectionManagerParam *
515 empathy_account_settings_get_tp_param (EmpathyAccountSettings *settings,
518 TpConnectionManagerParam *tp_params =
519 empathy_account_settings_get_tp_params (settings);
520 TpConnectionManagerParam *p;
522 for (p = tp_params; p != NULL && p->name != NULL; p++)
524 if (tp_strdiff (p->name, param))
534 account_settings_remove_from_unset (EmpathyAccountSettings *settings,
537 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
541 for (idx = 0; idx < priv->unset_parameters->len; idx++)
543 val = g_array_index (priv->unset_parameters, gchar *, idx);
545 if (!tp_strdiff (val, param))
547 priv->unset_parameters =
548 g_array_remove_index (priv->unset_parameters, idx);
557 empathy_account_settings_get_default (EmpathyAccountSettings *settings,
560 TpConnectionManagerParam *p;
562 p = empathy_account_settings_get_tp_param (settings, param);
564 if (p == NULL || !(p->flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT))
567 return &(p->default_value);
571 empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings,
574 TpConnectionManagerParam *p;
576 p = empathy_account_settings_get_tp_param (settings, param);
581 return p->dbus_signature;
585 empathy_account_settings_get (EmpathyAccountSettings *settings,
588 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
589 const GValue *result = NULL;
591 /* Lookup the update parameters we set */
592 result = tp_asv_lookup (priv->parameters, param);
596 /* If the parameters isn't unset use the accounts setting if any */
597 if (priv->account != NULL
598 && !empathy_account_settings_is_unset (settings, param))
600 const GHashTable *parameters;
602 parameters = empathy_account_get_parameters (priv->account);
603 result = tp_asv_lookup (parameters, param);
609 /* fallback to the default */
610 return empathy_account_settings_get_default (settings, param);
614 empathy_account_settings_unset (EmpathyAccountSettings *settings,
617 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
619 if (empathy_account_settings_is_unset (settings, param))
622 v = g_strdup (param);
624 g_array_append_val (priv->unset_parameters, v);
625 g_hash_table_remove (priv->parameters, param);
629 empathy_account_settings_discard_changes (EmpathyAccountSettings *settings)
631 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
633 g_hash_table_remove_all (priv->parameters);
634 empathy_account_settings_free_unset_parameters (settings);
638 empathy_account_settings_get_string (EmpathyAccountSettings *settings,
643 v = empathy_account_settings_get (settings, param);
645 if (v == NULL || !G_VALUE_HOLDS_STRING (v))
648 return g_value_get_string (v);
652 empathy_account_settings_get_int32 (EmpathyAccountSettings *settings,
658 v = empathy_account_settings_get (settings, param);
663 switch G_VALUE_TYPE (v)
666 ret = g_value_get_uchar (v);
669 ret = g_value_get_int (v);
672 ret = CLAMP (G_MININT32, g_value_get_uint (v), G_MAXINT32);
675 ret = CLAMP (G_MININT32, g_value_get_int64 (v), G_MAXINT32);
678 ret = CLAMP (G_MININT32, g_value_get_uint64 (v), G_MAXINT32);
689 empathy_account_settings_get_int64 (EmpathyAccountSettings *settings,
695 v = empathy_account_settings_get (settings, param);
699 switch G_VALUE_TYPE (v)
702 ret = g_value_get_uchar (v);
705 ret = g_value_get_int (v);
708 ret = g_value_get_uint (v);
711 ret = g_value_get_int64 (v);
714 ret = CLAMP (G_MININT64, g_value_get_uint64 (v), G_MAXINT64);
725 empathy_account_settings_get_uint32 (EmpathyAccountSettings *settings,
731 v = empathy_account_settings_get (settings, param);
733 switch G_VALUE_TYPE (v)
736 ret = g_value_get_uchar (v);
739 ret = MAX (0, g_value_get_int (v));
742 ret = g_value_get_uint (v);
745 ret = CLAMP (0, g_value_get_int64 (v), G_MAXUINT32);
748 ret = CLAMP (0, g_value_get_uint64 (v), G_MAXUINT32);
759 empathy_account_settings_get_uint64 (EmpathyAccountSettings *settings,
765 v = empathy_account_settings_get (settings, param);
767 if (v == NULL || !G_VALUE_HOLDS_INT (v))
770 switch G_VALUE_TYPE (v)
773 ret = g_value_get_uchar (v);
776 ret = MAX (0, g_value_get_int (v));
779 ret = g_value_get_uint (v);
782 ret = MAX (0, g_value_get_int64 (v));
785 ret = CLAMP (0, g_value_get_uint64 (v), G_MAXUINT64);
796 empathy_account_settings_get_boolean (EmpathyAccountSettings *settings,
801 v = empathy_account_settings_get (settings, param);
803 if (v == NULL || !G_VALUE_HOLDS_BOOLEAN (v))
806 return g_value_get_boolean (v);
810 empathy_account_settings_set_string (EmpathyAccountSettings *settings,
814 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
816 tp_asv_set_string (priv->parameters, g_strdup (param), value);
818 account_settings_remove_from_unset (settings, param);
822 empathy_account_settings_set_int32 (EmpathyAccountSettings *settings,
826 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
828 tp_asv_set_int32 (priv->parameters, g_strdup (param), value);
830 account_settings_remove_from_unset (settings, param);
834 empathy_account_settings_set_int64 (EmpathyAccountSettings *settings,
838 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
840 tp_asv_set_int64 (priv->parameters, g_strdup (param), value);
842 account_settings_remove_from_unset (settings, param);
846 empathy_account_settings_set_uint32 (EmpathyAccountSettings *settings,
850 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
852 tp_asv_set_uint32 (priv->parameters, g_strdup (param), value);
854 account_settings_remove_from_unset (settings, param);
858 empathy_account_settings_set_uint64 (EmpathyAccountSettings *settings,
862 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
864 tp_asv_set_uint64 (priv->parameters, g_strdup (param), value);
866 account_settings_remove_from_unset (settings, param);
870 empathy_account_settings_set_boolean (EmpathyAccountSettings *settings,
874 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
876 tp_asv_set_boolean (priv->parameters, g_strdup (param), value);
878 account_settings_remove_from_unset (settings, param);
882 account_settings_display_name_set_cb (GObject *src,
886 GError *error = NULL;
887 EmpathyAccount *account = EMPATHY_ACCOUNT (src);
888 GSimpleAsyncResult *set_result = user_data;
890 empathy_account_set_display_name_finish (account, res, &error);
894 g_simple_async_result_set_from_error (set_result, error);
895 g_error_free (error);
898 g_simple_async_result_complete (set_result);
899 g_object_unref (set_result);
903 empathy_account_settings_set_display_name_async (
904 EmpathyAccountSettings *settings,
906 GAsyncReadyCallback callback,
909 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
910 GSimpleAsyncResult *result;
912 result = g_simple_async_result_new (G_OBJECT (settings),
913 callback, user_data, empathy_account_settings_set_display_name_finish);
915 if (priv->account == NULL)
917 if (priv->display_name != NULL)
918 g_free (priv->display_name);
920 priv->display_name = g_strdup (name);
922 g_simple_async_result_complete_in_idle (result);
927 empathy_account_set_display_name_async (priv->account, name,
928 account_settings_display_name_set_cb, result);
932 empathy_account_settings_set_display_name_finish (
933 EmpathyAccountSettings *settings,
934 GAsyncResult *result,
937 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
941 g_return_val_if_fail (g_simple_async_result_is_valid (result,
942 G_OBJECT (settings), empathy_account_settings_set_display_name_finish),
949 empathy_account_settings_account_updated (GObject *source,
950 GAsyncResult *result,
953 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
954 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
955 GSimpleAsyncResult *r;
956 GError *error = NULL;
958 if (!empathy_account_update_settings_finish (EMPATHY_ACCOUNT (source),
961 g_simple_async_result_set_from_error (priv->apply_result, error);
962 g_error_free (error);
966 empathy_account_settings_discard_changes (settings);
969 r = priv->apply_result;
970 priv->apply_result = NULL;
972 g_simple_async_result_complete (r);
977 empathy_account_settings_created_cb (GObject *source,
978 GAsyncResult *result,
981 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
982 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
983 EmpathyAccount *account;
984 GError *error = NULL;
985 GSimpleAsyncResult *r;
987 account = empathy_account_manager_create_account_finish (
988 EMPATHY_ACCOUNT_MANAGER (source), result, &error);
992 g_simple_async_result_set_from_error (priv->apply_result, error);
996 priv->account = g_object_ref (account);
997 empathy_account_settings_discard_changes (settings);
1000 r = priv->apply_result;
1001 priv->apply_result = NULL;
1003 g_simple_async_result_complete (r);
1009 empathy_account_settings_do_create_account (EmpathyAccountSettings *settings)
1011 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
1012 GHashTable *properties;
1013 TpConnectionPresenceType type;
1017 properties = tp_asv_new (NULL, NULL);
1019 type = empathy_account_manager_get_requested_global_presence
1020 (priv->account_manager, &status, &message);
1022 if (type != TP_CONNECTION_PRESENCE_TYPE_UNSET)
1024 /* Create the account with the requested presence the same as the current
1025 * global requested presence, but don't enable it */
1026 GValueArray *presence;
1027 GValue vtype = { 0, };
1028 GValue vstatus = { 0, };
1029 GValue vmessage = { 0, };
1031 presence = g_value_array_new (3);
1033 g_value_init (&vtype, G_TYPE_UINT);
1034 g_value_set_uint (&vtype, type);
1035 g_value_array_append (presence, &vtype);
1037 g_value_init (&vstatus, G_TYPE_STRING);
1038 g_value_take_string (&vstatus, status);
1039 g_value_array_append (presence, &vstatus);
1041 g_value_init (&vmessage, G_TYPE_STRING);
1042 g_value_take_string (&vmessage, message);
1043 g_value_array_append (presence, &vmessage);
1045 tp_asv_take_boxed (properties, TP_IFACE_ACCOUNT ".RequestedPresence",
1046 TP_STRUCT_TYPE_SIMPLE_PRESENCE, presence);
1049 empathy_account_manager_create_account_async (priv->account_manager,
1050 priv->cm_name, priv->protocol, priv->display_name,
1051 priv->parameters, properties,
1052 empathy_account_settings_created_cb,
1055 g_hash_table_unref (properties);
1059 empathy_account_settings_manager_ready_cb (EmpathyAccountManager *manager,
1063 EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (user_data);
1064 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
1066 if (empathy_account_manager_is_ready (manager))
1068 g_assert (priv->apply_result != NULL && priv->account == NULL);
1069 g_signal_handler_disconnect (priv->account_manager,
1070 priv->account_manager_ready_id);
1071 priv->account_manager_ready_id = 0;
1073 empathy_account_settings_do_create_account (settings);
1078 empathy_account_settings_apply_async (EmpathyAccountSettings *settings,
1079 GAsyncReadyCallback callback,
1082 EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
1084 if (priv->apply_result != NULL)
1086 g_simple_async_report_error_in_idle (G_OBJECT (settings),
1087 callback, user_data,
1088 G_IO_ERROR, G_IO_ERROR_PENDING, "Applying already in progress");
1092 priv->apply_result = g_simple_async_result_new (G_OBJECT (settings),
1093 callback, user_data, empathy_account_settings_apply_finish);
1095 if (priv->account == NULL)
1097 if (empathy_account_manager_is_ready (priv->account_manager))
1098 empathy_account_settings_do_create_account (settings);
1100 priv->account_manager_ready_id = g_signal_connect (
1101 priv->account_manager,
1103 G_CALLBACK (empathy_account_settings_manager_ready_cb),
1108 empathy_account_update_settings_async (priv->account,
1109 priv->parameters, (const gchar **)priv->unset_parameters->data,
1110 empathy_account_settings_account_updated, settings);
1115 empathy_account_settings_apply_finish (EmpathyAccountSettings *settings,
1116 GAsyncResult *result,
1119 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
1123 g_return_val_if_fail (g_simple_async_result_is_valid (result,
1124 G_OBJECT (settings), empathy_account_settings_apply_finish), FALSE);
1130 empathy_account_settings_has_account (EmpathyAccountSettings *settings,
1131 EmpathyAccount *account)
1133 EmpathyAccountSettingsPriv *priv;
1135 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
1136 g_return_val_if_fail (EMPATHY_IS_ACCOUNT (account), FALSE);
1138 priv = GET_PRIV (settings);
1140 return (account == priv->account);
1144 empathy_account_settings_is_valid (EmpathyAccountSettings *settings)
1146 EmpathyAccountSettingsPriv *priv;
1149 gboolean missed = FALSE;
1151 g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
1153 priv = GET_PRIV (settings);
1155 for (idx = 0; idx < priv->required_params->len; idx++)
1157 current = g_array_index (priv->required_params, gchar *, idx);
1159 /* first, look if it's set in our own parameters */
1160 if (tp_asv_lookup (priv->parameters, current))
1163 /* if we did not unset the parameter, look if it's in the account */
1164 if (priv->account != NULL &&
1165 !empathy_account_settings_is_unset (settings, current))
1167 const GHashTable *account_params;
1169 account_params = empathy_account_get_parameters (priv->account);
1170 if (tp_asv_lookup (account_params, current))