diff options
Diffstat (limited to 'libempathy-gtk/empathy-contact-widget.c')
-rw-r--r-- | libempathy-gtk/empathy-contact-widget.c | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c index 93ab9d510..4efa9a0da 100644 --- a/libempathy-gtk/empathy-contact-widget.c +++ b/libempathy-gtk/empathy-contact-widget.c @@ -279,6 +279,23 @@ contact_info_field_spec_cmp (TpContactInfoFieldSpec *spec1, return contact_info_field_name_cmp (spec1->name, spec2->name); } +static TpContactInfoFieldSpec * +get_spec_from_list (GList *list, + const gchar *name) +{ + GList *l; + + for (l = list; l != NULL; l = g_list_next (l)) + { + TpContactInfoFieldSpec *spec = l->data; + + if (!tp_strdiff (spec->name, name)) + return spec; + } + + return NULL; +} + static guint contact_widget_details_update_edit (EmpathyContactWidget *information) { @@ -1062,13 +1079,44 @@ set_nickname_cb (GObject *source, } } +/* Update all the contact info fields having the +* Overwritten_By_Nickname flag to the new alias. This avoid accidentally +* reseting the alias when calling SetContactInfo(). See bgo #644298 for +* details. */ static void -set_alias_on_account (TpAccount *account, - const gchar *alias) +update_nickname_in_contact_info (EmpathyContactWidget *self, + TpConnection *connection, + const gchar *nickname) { - DEBUG ("Set Account.Nickname to %s", alias); + GList *specs, *l; - tp_account_set_nickname_async (account, alias, set_nickname_cb, NULL); + specs = tp_connection_get_contact_info_supported_fields (connection); + + for (l = self->details_to_set; l != NULL; l= g_list_next (l)) + { + TpContactInfoField *field = l->data; + TpContactInfoFieldSpec *spec; + + spec = get_spec_from_list (specs, field->field_name); + /* We shouldn't have added the field to details_to_set if it's not + * supported by the CM */ + g_assert (spec != NULL); + + if (spec->flags & TP_CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME) + { + const gchar *strv[] = { nickname, NULL }; + + DEBUG ("Updating field '%s' to '%s' as it has the " + "Overwritten_By_Nickname flag and Account.Nickname has " + "been updated", field->field_name, nickname); + + if (field->field_value != NULL) + g_strfreev (field->field_value); + field->field_value = g_strdupv ((GStrv) strv); + } + } + + g_list_free (specs); } static gboolean @@ -1085,9 +1133,21 @@ contact_widget_entry_alias_focus_event_cb (GtkEditable *editable, if (empathy_contact_is_user (information->contact)) { TpAccount * account; + const gchar *current_nickname; account = empathy_contact_get_account (information->contact); - set_alias_on_account (account, alias); + current_nickname = tp_account_get_nickname (account); + + if (tp_strdiff (current_nickname, alias)) + { + DEBUG ("Set Account.Nickname to %s", alias); + + tp_account_set_nickname_async (account, alias, set_nickname_cb, + NULL); + + update_nickname_in_contact_info (information, + empathy_contact_get_connection (information->contact), alias); + } } else { |