diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-07 17:50:14 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-07 18:04:23 +0800 |
commit | 4da4893bd535d6e122f99300e2f5152d40723bbc (patch) | |
tree | b3fbaef040501dba97675502208c4b10af1e3d01 /libempathy-gtk | |
parent | 9d8d7a2e4f9cd772fe69dae15c4c21728e974df3 (diff) | |
download | gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.tar gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.tar.gz gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.tar.bz2 gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.tar.lz gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.tar.xz gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.tar.zst gsoc2013-empathy-4da4893bd535d6e122f99300e2f5152d40723bbc.zip |
account-settings: always use GVariant to store parameters
https://bugzilla.gnome.org/show_bug.cgi?id=677545
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-account-widget-irc.c | 23 | ||||
-rw-r--r-- | libempathy-gtk/empathy-account-widget.c | 65 | ||||
-rw-r--r-- | libempathy-gtk/empathy-irc-network-chooser.c | 5 | ||||
-rw-r--r-- | libempathy-gtk/empathy-new-account-dialog.c | 8 |
4 files changed, 65 insertions, 36 deletions
diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c index b4d5673a8..8e6719464 100644 --- a/libempathy-gtk/empathy-account-widget-irc.c +++ b/libempathy-gtk/empathy-account-widget-irc.c @@ -57,19 +57,19 @@ account_widget_irc_destroy_cb (GtkWidget *widget, static void account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) { - const gchar *nick = NULL; - const gchar *fullname = NULL; + gchar *nick = NULL; + gchar *fullname = NULL; EmpathyAccountSettings *ac_settings; g_object_get (settings->self, "settings", &ac_settings, NULL); - nick = empathy_account_settings_get_string (ac_settings, "account"); - fullname = empathy_account_settings_get_string (ac_settings, + nick = empathy_account_settings_dup_string (ac_settings, "account"); + fullname = empathy_account_settings_dup_string (ac_settings, "fullname"); if (nick == NULL) { - nick = g_get_user_name (); + nick = g_strdup (g_get_user_name ()); empathy_account_settings_set (ac_settings, "account", g_variant_new_string (nick)); @@ -77,14 +77,17 @@ account_widget_irc_setup (EmpathyAccountWidgetIrc *settings) if (fullname == NULL) { - fullname = g_get_real_name (); + fullname = g_strdup (g_get_real_name ()); if (fullname == NULL) - fullname = nick; + fullname = g_strdup (nick); empathy_account_settings_set (ac_settings, "fullname", g_variant_new_string (fullname)); } + + g_free (nick); + g_free (fullname); } static void @@ -146,7 +149,7 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self, EmpathyAccountWidgetIrc *settings; EmpathyAccountSettings *ac_settings; GtkWidget *entry_password; - const gchar *password; + gchar *password; settings = g_slice_new0 (EmpathyAccountWidgetIrc); settings->self = self; @@ -190,7 +193,7 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self, g_object_unref (ac_settings); /* Automatically set password-prompt when needed */ - password = empathy_account_settings_get_string (ac_settings, "password"); + password = empathy_account_settings_dup_string (ac_settings, "password"); if (set_password_prompt_if_needed (ac_settings, password)) { @@ -198,6 +201,8 @@ empathy_account_widget_irc_build (EmpathyAccountWidget *self, empathy_account_settings_apply_async (ac_settings, NULL, NULL); } + g_free (password); + g_signal_connect (entry_password, "changed", G_CALLBACK (entry_password_changed_cb), settings); diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index df56816bb..00f85df6d 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -288,16 +288,18 @@ account_widget_entry_changed_common (EmpathyAccountWidget *self, if (EMP_STR_EMPTY (str)) { - const gchar *value = NULL; - empathy_account_settings_unset (self->priv->settings, param_name); if (focus) { - value = empathy_account_settings_get_string (self->priv->settings, + gchar *value; + + value = empathy_account_settings_dup_string (self->priv->settings, param_name); + DEBUG ("Unset %s and restore to %s", param_name, value); gtk_entry_set_text (entry, value ? value : ""); + g_free (value); } } else @@ -450,7 +452,7 @@ account_widget_combobox_changed_cb (GtkWidget *widget, GtkTreeIter iter; GtkTreeModel *model; const gchar *value; - const GValue *v; + GVariant *v; const gchar *default_value = NULL; const gchar *param_name; @@ -463,9 +465,9 @@ account_widget_combobox_changed_cb (GtkWidget *widget, param_name = g_object_get_data (G_OBJECT (widget), "param_name"); - v = empathy_account_settings_get_default (self->priv->settings, param_name); - if (v != NULL) - default_value = g_value_get_string (v); + v = empathy_account_settings_dup_default (self->priv->settings, param_name); + if (v != NULL && g_variant_is_of_type (v, G_VARIANT_TYPE_STRING)) + default_value = g_variant_get_string (v, NULL); if (!tp_strdiff (value, default_value)) { @@ -480,6 +482,8 @@ account_widget_combobox_changed_cb (GtkWidget *widget, } empathy_account_widget_changed (self); + + tp_clear_pointer (&v, g_variant_unref); } static void @@ -576,9 +580,9 @@ empathy_account_widget_setup_widget (EmpathyAccountWidget *self, } else if (GTK_IS_ENTRY (widget)) { - const gchar *str = NULL; + gchar *str; - str = empathy_account_settings_get_string (self->priv->settings, + str = empathy_account_settings_dup_string (self->priv->settings, param_name); gtk_entry_set_text (GTK_ENTRY (widget), str ? str : ""); @@ -609,11 +613,12 @@ empathy_account_widget_setup_widget (EmpathyAccountWidget *self, g_signal_connect (widget, "activate", G_CALLBACK (account_entry_activated_cb), self); - g_signal_connect (widget, "changed", G_CALLBACK (account_widget_entry_changed_cb), self); g_signal_connect (widget, "map", G_CALLBACK (account_widget_entry_map_cb), self); + + g_free (str); } else if (GTK_IS_TOGGLE_BUTTON (widget)) { @@ -631,12 +636,12 @@ empathy_account_widget_setup_widget (EmpathyAccountWidget *self, { /* The combo box's model has to contain the param value in its first * column (as a string) */ - const gchar *str; + gchar *str; GtkTreeModel *model; GtkTreeIter iter; gboolean valid; - str = empathy_account_settings_get_string (self->priv->settings, + str = empathy_account_settings_dup_string (self->priv->settings, param_name); model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); @@ -659,6 +664,8 @@ empathy_account_widget_setup_widget (EmpathyAccountWidget *self, g_free (name); } + g_free (str); + g_signal_connect (widget, "changed", G_CALLBACK (account_widget_combobox_changed_cb), self); @@ -1225,14 +1232,15 @@ static void suffix_id_widget_changed_cb (GtkWidget *entry, EmpathyAccountWidget *self) { - const gchar *account; + gchar *account; g_assert (self->priv->jid_suffix != NULL); account_widget_entry_changed_common (self, GTK_ENTRY (entry), FALSE); - account = empathy_account_settings_get_string (self->priv->settings, + account = empathy_account_settings_dup_string (self->priv->settings, "account"); + if (!EMP_STR_EMPTY (account) && !g_str_has_suffix (account, self->priv->jid_suffix)) { @@ -1248,6 +1256,8 @@ suffix_id_widget_changed_cb (GtkWidget *entry, } empathy_account_widget_changed (self); + + g_free (account); } static gchar * @@ -1267,7 +1277,7 @@ setup_id_widget_with_suffix (EmpathyAccountWidget *self, GtkWidget *widget, const gchar *suffix) { - const gchar *str = NULL; + gchar *str = NULL; g_object_set_data_full (G_OBJECT (widget), "param_name", g_strdup ("account"), g_free); @@ -1275,7 +1285,7 @@ setup_id_widget_with_suffix (EmpathyAccountWidget *self, g_assert (self->priv->jid_suffix == NULL); self->priv->jid_suffix = g_strdup (suffix); - str = empathy_account_settings_get_string (self->priv->settings, "account"); + str = empathy_account_settings_dup_string (self->priv->settings, "account"); if (str != NULL) { gchar *tmp; @@ -1283,6 +1293,7 @@ setup_id_widget_with_suffix (EmpathyAccountWidget *self, tmp = remove_jid_suffix (self, str); gtk_entry_set_text (GTK_ENTRY (widget), tmp); g_free (tmp); + g_free (str); } self->priv->param_account_widget = widget; @@ -1883,7 +1894,9 @@ account_settings_password_retrieved_cb (GObject *object, gpointer user_data) { EmpathyAccountWidget *self = user_data; - const gchar *password = empathy_account_settings_get_string ( + gchar *password; + + password = empathy_account_settings_dup_string ( self->priv->settings, "password"); if (password != NULL) @@ -1900,6 +1913,8 @@ account_settings_password_retrieved_cb (GObject *object, gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), !EMP_STR_EMPTY (password)); + + g_free (password); } static void @@ -1984,10 +1999,14 @@ do_constructed (GObject *obj) } else { + gchar *password; + + password = empathy_account_settings_dup_string (self->priv->settings, + "password"); + gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (self->priv->remember_password_widget), - !EMP_STR_EMPTY (empathy_account_settings_get_string ( - self->priv->settings, "password"))); + !EMP_STR_EMPTY (password)); /* The password might not have been retrieved from the * keyring yet. We should update the remember password @@ -1995,6 +2014,8 @@ do_constructed (GObject *obj) tp_g_signal_connect_object (self->priv->settings, "password-retrieved", G_CALLBACK (account_settings_password_retrieved_cb), self, 0); + + g_free (password); } g_signal_connect (self->priv->remember_password_widget, "toggled", @@ -2232,12 +2253,12 @@ empathy_account_widget_new_for_protocol (EmpathyAccountSettings *settings, gchar * empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self) { - const gchar *login_id; + gchar *login_id; const gchar *protocol, *p; gchar *default_display_name; Service service; - login_id = empathy_account_settings_get_string (self->priv->settings, + login_id = empathy_account_settings_dup_string (self->priv->settings, "account"); protocol = empathy_account_settings_get_protocol (self->priv->settings); service = account_widget_get_service (self); @@ -2291,6 +2312,8 @@ empathy_account_widget_get_default_display_name (EmpathyAccountWidget *self) default_display_name = g_strdup (_("New account")); } + g_free (login_id); + return default_display_name; } diff --git a/libempathy-gtk/empathy-irc-network-chooser.c b/libempathy-gtk/empathy-irc-network-chooser.c index ac814e614..d6c51aee6 100644 --- a/libempathy-gtk/empathy-irc-network-chooser.c +++ b/libempathy-gtk/empathy-irc-network-chooser.c @@ -225,11 +225,11 @@ static void set_label_from_settings (EmpathyIrcNetworkChooser *self) { EmpathyIrcNetworkChooserPriv *priv = GET_PRIV (self); - const gchar *server; + gchar *server; tp_clear_object (&priv->network); - server = empathy_account_settings_get_string (priv->settings, "server"); + server = empathy_account_settings_dup_string (priv->settings, "server"); if (server != NULL) { @@ -263,6 +263,7 @@ set_label_from_settings (EmpathyIrcNetworkChooser *self) set_label (self); g_object_unref (srv); + g_free (server); return; } diff --git a/libempathy-gtk/empathy-new-account-dialog.c b/libempathy-gtk/empathy-new-account-dialog.c index ed09be829..c36cfcfce 100644 --- a/libempathy-gtk/empathy-new-account-dialog.c +++ b/libempathy-gtk/empathy-new-account-dialog.c @@ -66,11 +66,11 @@ protocol_changed_cb (GtkComboBox *chooser, /* Save "account" and "password" parameters */ if (self->priv->settings != NULL) { - account = g_strdup (empathy_account_settings_get_string ( - self->priv->settings, "account")); + account = empathy_account_settings_dup_string ( + self->priv->settings, "account"); - password = g_strdup (empathy_account_settings_get_string ( - self->priv->settings, "password")); + password = empathy_account_settings_dup_string ( + self->priv->settings, "password"); g_object_unref (self->priv->settings); } |