diff options
author | Rob Bradford <rob@linux.intel.com> | 2010-06-03 21:24:21 +0800 |
---|---|---|
committer | Rob Bradford <rob@linux.intel.com> | 2010-06-03 21:57:32 +0800 |
commit | 55b79bd79477ddb3be777d760e19fa1bc468e56b (patch) | |
tree | afb92542a4e78d9f7abdc03bc21d9881483d2433 /src/empathy-accounts-dialog.c | |
parent | ff6007612e6560514dbd6a5a581475d72de8c29d (diff) | |
download | gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.tar gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.tar.gz gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.tar.bz2 gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.tar.lz gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.tar.xz gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.tar.zst gsoc2013-empathy-55b79bd79477ddb3be777d760e19fa1bc468e56b.zip |
accounts-dialog: avoid leaking the account status message
Originally this function mixed const and allocated strings using the same
variable, resulting in leaks. This change refactors the code slightly to
prevent such leaks.
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=620476
Diffstat (limited to 'src/empathy-accounts-dialog.c')
-rw-r--r-- | src/empathy-accounts-dialog.c | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 2acac45a5..d81d3de2d 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -191,12 +191,22 @@ accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog, } static void +accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog, + const gchar *message) +{ + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + gchar *message_markup; + + message_markup = g_markup_printf_escaped ("<i>%s</i>", message); + gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup); + g_free (message_markup); +} + +static void accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, TpAccount *account) { EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - const gchar *message; - gchar *message_markup; gchar *status_message = NULL; guint status; guint reason; @@ -259,7 +269,8 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, switch (status) { case TP_CONNECTION_STATUS_CONNECTING: - message = _("Connecting…"); + accounts_dialog_status_infobar_set_message (dialog, + _("Connecting…")); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_INFO); @@ -270,14 +281,24 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, case TP_CONNECTION_STATUS_CONNECTED: if (g_strcmp0 (status_message, "") == 0) { + gchar *message; + message = g_strdup_printf ("%s", empathy_presence_get_default_message (presence)); + + accounts_dialog_status_infobar_set_message (dialog, message); + g_free (message); } else { + gchar *message; + message = g_strdup_printf ("%s — %s", empathy_presence_get_default_message (presence), status_message); + + accounts_dialog_status_infobar_set_message (dialog, message); + g_free (message); } gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_INFO); @@ -286,31 +307,41 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gtk_widget_hide (priv->throbber); break; case TP_CONNECTION_STATUS_DISCONNECTED: - message = g_strdup_printf (_("Disconnected — %s"), - empathy_status_reason_get_default_message (reason)); - if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED) { + gchar *message; + message = g_strdup_printf (_("Offline — %s"), empathy_status_reason_get_default_message (reason)); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_WARNING); + + accounts_dialog_status_infobar_set_message (dialog, message); + g_free (message); } else { + gchar *message; + + message = g_strdup_printf (_("Disconnected — %s"), + empathy_status_reason_get_default_message (reason)); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_ERROR); + + accounts_dialog_status_infobar_set_message (dialog, message); + g_free (message); } if (!empathy_connectivity_is_online (priv->connectivity)) - message = _("Offline — No Network Connection"); + accounts_dialog_status_infobar_set_message (dialog, + _("Offline — No Network Connection")); gtk_spinner_stop (GTK_SPINNER (priv->throbber)); gtk_widget_show (priv->image_status); gtk_widget_hide (priv->throbber); break; default: - message = _("Unknown Status"); + accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status")); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_WARNING); @@ -321,7 +352,8 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, } else { - message = _("Offline — Account Disabled"); + accounts_dialog_status_infobar_set_message (dialog, + _("Offline — Account Disabled")); gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar), GTK_MESSAGE_WARNING); @@ -330,8 +362,6 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gtk_widget_hide (priv->throbber); } - message_markup = g_markup_printf_escaped ("<i>%s</i>", message); - gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup); gtk_widget_show (priv->label_status); if (!creating_account) @@ -340,7 +370,6 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gtk_widget_hide (priv->infobar); g_free (status_message); - g_free (message_markup); } void |