From 5a464a08117785832583bdf720288502410952aa Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Tue, 25 Aug 2009 13:18:56 -0400 Subject: - The account display gets updated in the account list and in the account name label. - By default, the account default display name is set to the login id. --- src/empathy-accounts-dialog.c | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 6fa484924..8a3d35531 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -112,6 +112,11 @@ enum { PROP_PARENT = 1 }; +static void accounts_dialog_account_display_name_changed_cb ( + EmpathyAccount *account, + GParamSpec *pspec, + gpointer user_data); + static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings ( EmpathyAccountsDialog *dialog); @@ -181,8 +186,16 @@ static void empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object, EmpathyAccountsDialog *dialog) { + const gchar *default_display_name; EmpathyAccountSettings *settings = accounts_dialog_model_get_selected_settings (dialog); + + /* Setting the display name to the login ID. */ + default_display_name = empathy_account_settings_get_string (settings, + "account"); + empathy_account_settings_set_display_name_async (settings, + default_display_name, NULL, NULL); + accounts_dialog_update_settings (dialog, settings); if (settings) @@ -572,6 +585,8 @@ accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog, if (account != NULL) { + g_signal_handlers_disconnect_by_func (account, + accounts_dialog_account_display_name_changed_cb, account_dialog); empathy_account_remove_async (account, NULL, NULL); g_object_unref (account); } @@ -919,6 +934,37 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, dialog); } +static void +accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account, + GParamSpec *pspec, + gpointer user_data) +{ + const gchar *display_name; + GtkTreeIter iter; + GtkTreeModel *model; + EmpathyAccountSettings *settings; + EmpathyAccount *selected_account; + EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data); + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + + display_name = empathy_account_get_display_name (account); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); + settings = accounts_dialog_model_get_selected_settings (dialog); + selected_account = empathy_account_settings_get_account (settings); + + if (accounts_dialog_get_account_iter (dialog, account, &iter)) + { + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COL_NAME, display_name, + -1); + } + + if (selected_account == account) + accounts_dialog_update_name_label (dialog, display_name); + + g_object_unref (settings); +} + static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog, EmpathyAccount *account) @@ -955,6 +1001,9 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, TP_CONNECTION_STATUS_DISCONNECTED, dialog); + g_signal_connect (account, "notify::display-name", + G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog); + g_object_unref (settings); } @@ -1007,8 +1056,12 @@ accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); if (accounts_dialog_get_account_iter (dialog, account, &iter)) - gtk_list_store_remove (GTK_LIST_STORE ( + { + g_signal_handlers_disconnect_by_func (account, + accounts_dialog_account_display_name_changed_cb, dialog); + gtk_list_store_remove (GTK_LIST_STORE ( gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter); + } } static void -- cgit From 28c3c1f834345cf6da157262841e2731feaf85ed Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Wed, 26 Aug 2009 14:36:19 -0400 Subject: Only setting the display name to the Login ID for protocol which have this property. --- src/empathy-accounts-dialog.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 8a3d35531..89e1adc17 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -190,11 +190,15 @@ empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object, EmpathyAccountSettings *settings = accounts_dialog_model_get_selected_settings (dialog); - /* Setting the display name to the login ID. */ + /* Setting the display name to the login ID (if there is one). */ default_display_name = empathy_account_settings_get_string (settings, "account"); - empathy_account_settings_set_display_name_async (settings, - default_display_name, NULL, NULL); + + if (default_display_name != NULL) + { + empathy_account_settings_set_display_name_async (settings, + default_display_name, NULL, NULL); + } accounts_dialog_update_settings (dialog, settings); -- cgit From 5a9bf924644f14f67a62717eeca98a0dfbce60d7 Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Wed, 26 Aug 2009 15:37:39 -0400 Subject: Using a new logic to set the default display name: * If irc use "[account] on [server]" * If there is an account property use "[account]" * If there is no account property use "[protocol] Account" --- src/empathy-accounts-dialog.c | 49 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 89e1adc17..0bd58189e 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -182,23 +182,52 @@ empathy_account_dialog_widget_cancelled_cb (EmpathyAccountWidget *widget_object, g_object_unref (settings); } +static gchar * +get_default_display_name (EmpathyAccountSettings *settings) +{ + const gchar *login_id; + const gchar *protocol; + gchar *default_display_name; + + login_id = empathy_account_settings_get_string (settings, "account"); + protocol = empathy_account_settings_get_protocol (settings); + + if (login_id != NULL) + { + if (!tp_strdiff(protocol, "irc")) + { + const gchar* server; + server = empathy_account_settings_get_string (settings, "server"); + + default_display_name = + g_strdup_printf (_("%s on %s"), login_id, server); + } + else + { + default_display_name = g_strdup (login_id); + } + } + else if (protocol != NULL) + { + default_display_name = g_strdup_printf (_("%s Account"), protocol); + } + else + { + default_display_name = g_strdup (_("New account")); + } + + return default_display_name; +} + static void empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object, EmpathyAccountsDialog *dialog) { - const gchar *default_display_name; EmpathyAccountSettings *settings = accounts_dialog_model_get_selected_settings (dialog); - /* Setting the display name to the login ID (if there is one). */ - default_display_name = empathy_account_settings_get_string (settings, - "account"); - - if (default_display_name != NULL) - { - empathy_account_settings_set_display_name_async (settings, - default_display_name, NULL, NULL); - } + empathy_account_settings_set_display_name_async (settings, + get_default_display_name (settings), NULL, NULL); accounts_dialog_update_settings (dialog, settings); -- cgit From c66fa1223a902be9b51cf1568b07870e6f2dd402 Mon Sep 17 00:00:00 2001 From: Jonathan Tellier Date: Thu, 27 Aug 2009 09:18:10 -0400 Subject: - Added information intented to translators. - Fixed leak of the the display name. --- src/empathy-accounts-dialog.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 0bd58189e..1cb903ec0 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -199,6 +199,9 @@ get_default_display_name (EmpathyAccountSettings *settings) const gchar* server; server = empathy_account_settings_get_string (settings, "server"); + /* To translators: The first parameter is the login id and the + * second one is the server. The resulting string will be something + * like: "MyUserName on chat.freenode.net" */ default_display_name = g_strdup_printf (_("%s on %s"), login_id, server); } @@ -209,6 +212,8 @@ get_default_display_name (EmpathyAccountSettings *settings) } else if (protocol != NULL) { + /* To translators: The parameter is the protocol name. The resulting + * string will be something like: "Jabber Account" */ default_display_name = g_strdup_printf (_("%s Account"), protocol); } else @@ -223,11 +228,16 @@ static void empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object, EmpathyAccountsDialog *dialog) { + gchar *display_name; EmpathyAccountSettings *settings = accounts_dialog_model_get_selected_settings (dialog); + display_name = get_default_display_name (settings); + empathy_account_settings_set_display_name_async (settings, - get_default_display_name (settings), NULL, NULL); + display_name, NULL, NULL); + + g_free (display_name); accounts_dialog_update_settings (dialog, settings); @@ -1182,7 +1192,7 @@ accounts_dialog_button_create_clicked_cb (GtkWidget *button, /* Create account */ /* To translator: %s is the name of the protocol, such as "Google Talk" or - * "Yahoo! + * "Yahoo!" */ str = g_strdup_printf (_("New %s account"), display_name); settings = empathy_account_settings_new (cm->name, proto->name, str); -- cgit