[empathy] account-settings: always use GVariant to store parameters
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy] account-settings: always use GVariant to store parameters
- Date: Thu, 7 Jun 2012 10:51:41 +0000 (UTC)
commit 4da4893bd535d6e122f99300e2f5152d40723bbc
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Thu Jun 7 11:50:14 2012 +0200
account-settings: always use GVariant to store parameters
https://bugzilla.gnome.org/show_bug.cgi?id=677545
libempathy-gtk/empathy-account-widget-irc.c | 23 ++-
libempathy-gtk/empathy-account-widget.c | 65 ++++--
libempathy-gtk/empathy-irc-network-chooser.c | 5 +-
libempathy-gtk/empathy-new-account-dialog.c | 8 +-
libempathy/empathy-account-settings.c | 299 +++++++++++++-------------
libempathy/empathy-account-settings.h | 8 +-
6 files changed, 220 insertions(+), 188 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget-irc.c b/libempathy-gtk/empathy-account-widget-irc.c
index b4d5673..8e67194 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 df56816..00f85df 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 ac814e6..d6c51ae 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 ed09be8..c36cfcf 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);
}
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 8a0e61f..a14e5c1 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -492,7 +492,7 @@ empathy_account_settings_migrate_password_cb (GObject *source,
g_hash_table_unref (empty);
}
-static const GValue * empathy_account_settings_get (
+static GVariant * empathy_account_settings_dup (
EmpathyAccountSettings *settings,
const gchar *param);
@@ -500,13 +500,16 @@ static void
empathy_account_settings_try_migrating_password (EmpathyAccountSettings *self)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (self);
- const GValue *v;
+ GVariant *v;
const gchar *password;
- if (!priv->supports_sasl || empathy_account_settings_get (
- self, "password") == NULL)
+ v = empathy_account_settings_dup (self, "password");
+ if (v == NULL)
return;
+ if (!priv->supports_sasl)
+ goto out;
+
/* mission-control still has our password, although the CM
* supports SASL. Let's try migrating it. */
@@ -514,16 +517,14 @@ empathy_account_settings_try_migrating_password (EmpathyAccountSettings *self)
"keyring ourselves for account %s",
tp_account_get_path_suffix (priv->account));
- v = empathy_account_settings_get (self, "password");
-
/* I can't imagine why this would fail. */
- if (!G_VALUE_HOLDS_STRING (v))
- return;
+ if (!g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
+ goto out;
- password = g_value_get_string (v);
+ password = g_variant_get_string (v, NULL);
if (EMP_STR_EMPTY (password))
- return;
+ goto out;
empathy_keyring_set_account_password_async (priv->account, password,
empathy_account_settings_migrate_password_cb, self);
@@ -534,6 +535,9 @@ empathy_account_settings_try_migrating_password (EmpathyAccountSettings *self)
priv->password = g_strdup (password);
priv->password_original = g_strdup (password);
+
+out:
+ g_variant_unref (v);
}
static void
@@ -832,18 +836,17 @@ account_settings_remove_from_unset (EmpathyAccountSettings *settings,
}
}
-const GValue *
-empathy_account_settings_get_default (EmpathyAccountSettings *settings,
+GVariant *
+empathy_account_settings_dup_default (EmpathyAccountSettings *settings,
const gchar *param)
{
const TpConnectionManagerParam *p;
p = empathy_account_settings_get_tp_param (settings, param);
-
- if (p == NULL || !(p->flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT))
+ if (p == NULL)
return NULL;
- return &(p->default_value);
+ return tp_connection_manager_param_dup_default_variant (p);
}
const gchar *
@@ -860,43 +863,35 @@ empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *settings,
return tp_connection_manager_param_get_dbus_signature (p);
}
-static const GValue *
-empathy_account_settings_get (EmpathyAccountSettings *settings,
+static GVariant *
+empathy_account_settings_dup (EmpathyAccountSettings *settings,
const gchar *param)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- const GValue *result = NULL;
- GVariant *variant;
+ GVariant *result;
/* Lookup the update parameters we set */
- variant = g_hash_table_lookup (priv->parameters, param);
- if (variant != NULL)
- {
- GValue v = G_VALUE_INIT;
-
- dbus_g_value_parse_g_variant (variant, &v);
- result = (const GValue *) tp_g_value_slice_dup (&v);
-
- g_value_unset (&v);
- /* FIXME: this GValue is leaked */
- return result;
- }
+ result = g_hash_table_lookup (priv->parameters, param);
+ if (result != NULL)
+ return g_variant_ref (result);
/* If the parameters isn't unset use the accounts setting if any */
if (priv->account != NULL
&& !empathy_account_settings_is_unset (settings, param))
{
- const GHashTable *parameters;
+ GVariant *parameters;
- parameters = tp_account_get_parameters (priv->account);
- result = tp_asv_lookup (parameters, param);
+ parameters = tp_account_dup_parameters_vardict (priv->account);
+ result = g_variant_lookup_value (parameters, param, NULL);
+ g_variant_unref (parameters);
if (result != NULL)
+ /* g_variant_lookup_value() is (transfer full) */
return result;
}
/* fallback to the default */
- return empathy_account_settings_get_default (settings, param);
+ return empathy_account_settings_dup_default (settings, param);
}
void
@@ -940,76 +935,80 @@ empathy_account_settings_discard_changes (EmpathyAccountSettings *settings)
priv->uri_scheme_tel = FALSE;
}
-const gchar *
-empathy_account_settings_get_string (EmpathyAccountSettings *settings,
+gchar *
+empathy_account_settings_dup_string (EmpathyAccountSettings *settings,
const gchar *param)
{
EmpathyAccountSettingsPriv *priv = GET_PRIV (settings);
- const GValue *v;
+ GVariant *v;
+ gchar *result = NULL;
if (!tp_strdiff (param, "password") && priv->supports_sasl)
{
- return priv->password;
+ return g_strdup (priv->password);
}
- v = empathy_account_settings_get (settings, param);
-
- if (v == NULL || !G_VALUE_HOLDS_STRING (v))
+ v = empathy_account_settings_dup (settings, param);
+ if (v == NULL)
return NULL;
- return g_value_get_string (v);
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING))
+ result = g_variant_dup_string (v, NULL);
+
+ g_variant_unref (v);
+ return result;
}
-const gchar * const *
-empathy_account_settings_get_strv (EmpathyAccountSettings *settings,
+GStrv
+empathy_account_settings_dup_strv (EmpathyAccountSettings *settings,
const gchar *param)
{
- const GValue *v;
-
- v = empathy_account_settings_get (settings, param);
+ GVariant *v;
+ GStrv result = NULL;
- if (v == NULL || !G_VALUE_HOLDS (v, G_TYPE_STRV))
+ v = empathy_account_settings_dup (settings, param);
+ if (v == NULL)
return NULL;
- return g_value_get_boxed (v);
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING_ARRAY))
+ result = g_variant_dup_strv (v, NULL);
+
+ g_variant_unref (v);
+ return result;
}
gint32
empathy_account_settings_get_int32 (EmpathyAccountSettings *settings,
const gchar *param)
{
- const GValue *v;
+ GVariant *v;
gint32 ret = 0;
- v = empathy_account_settings_get (settings, param);
-
+ v = empathy_account_settings_dup (settings, param);
if (v == NULL)
return 0;
- switch G_VALUE_TYPE (v)
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+ ret = g_variant_get_byte (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+ ret = g_variant_get_int32 (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+ ret = CLAMP (g_variant_get_uint32 (v), (guint) G_MININT32,
+ G_MAXINT32);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+ ret = CLAMP (g_variant_get_int64 (v), G_MININT32, G_MAXINT32);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+ ret = CLAMP (g_variant_get_uint64 (v), (guint64) G_MININT32, G_MAXINT32);
+ else
{
- case G_TYPE_UCHAR:
- ret = g_value_get_uchar (v);
- break;
- case G_TYPE_INT:
- ret = g_value_get_int (v);
- break;
- case G_TYPE_UINT:
- ret = CLAMP (g_value_get_uint (v), (guint) G_MININT32,
- G_MAXINT32);
- break;
- case G_TYPE_INT64:
- ret = CLAMP (g_value_get_int64 (v), G_MININT32, G_MAXINT32);
- break;
- case G_TYPE_UINT64:
- ret = CLAMP (g_value_get_uint64 (v), (guint64) G_MININT32,
- G_MAXINT32);
- break;
- default:
- ret = 0;
- break;
+ gchar *tmp;
+
+ tmp = g_variant_print (v, TRUE);
+ DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+ g_free (tmp);
}
+ g_variant_unref (v);
return ret;
}
@@ -1017,35 +1016,33 @@ gint64
empathy_account_settings_get_int64 (EmpathyAccountSettings *settings,
const gchar *param)
{
- const GValue *v;
+ GVariant *v;
gint64 ret = 0;
- v = empathy_account_settings_get (settings, param);
+ v = empathy_account_settings_dup (settings, param);
if (v == NULL)
return 0;
- switch G_VALUE_TYPE (v)
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+ ret = g_variant_get_byte (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+ ret = g_variant_get_int32 (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+ ret = g_variant_get_uint32 (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+ ret = g_variant_get_int64 (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+ ret = CLAMP (g_variant_get_uint64 (v), (guint64) G_MININT64, G_MAXINT64);
+ else
{
- case G_TYPE_UCHAR:
- ret = g_value_get_uchar (v);
- break;
- case G_TYPE_INT:
- ret = g_value_get_int (v);
- break;
- case G_TYPE_UINT:
- ret = g_value_get_uint (v);
- break;
- case G_TYPE_INT64:
- ret = g_value_get_int64 (v);
- break;
- case G_TYPE_UINT64:
- ret = CLAMP (g_value_get_uint64 (v), (guint64) G_MININT64, G_MAXINT64);
- break;
- default:
- ret = 0;
- break;
+ gchar *tmp;
+
+ tmp = g_variant_print (v, TRUE);
+ DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+ g_free (tmp);
}
+ g_variant_unref (v);
return ret;
}
@@ -1053,35 +1050,33 @@ guint32
empathy_account_settings_get_uint32 (EmpathyAccountSettings *settings,
const gchar *param)
{
- const GValue *v;
- guint32 ret;
+ GVariant *v;
+ guint32 ret = 0;
- v = empathy_account_settings_get (settings, param);
+ v = empathy_account_settings_dup (settings, param);
if (v == NULL)
return 0;
- switch G_VALUE_TYPE (v)
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+ ret = g_variant_get_byte (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+ ret = MAX (0, g_variant_get_int32 (v));
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+ ret = g_variant_get_uint32 (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+ ret = CLAMP (g_variant_get_int64 (v), 0, G_MAXUINT32);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+ ret = MIN (g_variant_get_uint64 (v), G_MAXUINT32);
+ else
{
- case G_TYPE_UCHAR:
- ret = g_value_get_uchar (v);
- break;
- case G_TYPE_INT:
- ret = MAX (0, g_value_get_int (v));
- break;
- case G_TYPE_UINT:
- ret = g_value_get_uint (v);
- break;
- case G_TYPE_INT64:
- ret = CLAMP (g_value_get_int64 (v), 0, G_MAXUINT32);
- break;
- case G_TYPE_UINT64:
- ret = MIN (g_value_get_uint64 (v), G_MAXUINT32);
- break;
- default:
- ret = 0;
- break;
+ gchar *tmp;
+
+ tmp = g_variant_print (v, TRUE);
+ DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+ g_free (tmp);
}
+ g_variant_unref (v);
return ret;
}
@@ -1089,36 +1084,34 @@ guint64
empathy_account_settings_get_uint64 (EmpathyAccountSettings *settings,
const gchar *param)
{
- const GValue *v;
+ GVariant *v;
guint64 ret = 0;
- v = empathy_account_settings_get (settings, param);
-
- if (v == NULL || !G_VALUE_HOLDS_INT (v))
+ v = empathy_account_settings_dup (settings, param);
+ if (v == NULL)
return 0;
- switch G_VALUE_TYPE (v)
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BYTE))
+ ret = g_variant_get_byte (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT32))
+ ret = MAX (0, g_variant_get_int32 (v));
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT32))
+ ret = g_variant_get_uint32 (v);
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_INT64))
+ ret = MAX (0, g_variant_get_int64 (v));
+ else if (g_variant_is_of_type (v, G_VARIANT_TYPE_UINT64))
+ ret = g_variant_get_uint64 (v);
+ else
{
- case G_TYPE_UCHAR:
- ret = g_value_get_uchar (v);
- break;
- case G_TYPE_INT:
- ret = MAX (0, g_value_get_int (v));
- break;
- case G_TYPE_UINT:
- ret = g_value_get_uint (v);
- break;
- case G_TYPE_INT64:
- ret = MAX (0, g_value_get_int64 (v));
- break;
- case G_TYPE_UINT64:
- ret = g_value_get_uint64 (v);
- break;
- default:
- ret = 0;
- break;
+ gchar *tmp;
+
+ tmp = g_variant_print (v, TRUE);
+ DEBUG ("Unsupported type for param '%s': %s'", param, tmp);
+ g_free (tmp);
}
+
+ g_variant_unref (v);
return ret;
}
@@ -1126,14 +1119,17 @@ gboolean
empathy_account_settings_get_boolean (EmpathyAccountSettings *settings,
const gchar *param)
{
- const GValue *v;
+ GVariant *v;
+ gboolean result = FALSE;
- v = empathy_account_settings_get (settings, param);
+ v = empathy_account_settings_dup (settings, param);
+ if (v == NULL)
+ return result;
- if (v == NULL || !G_VALUE_HOLDS_BOOLEAN (v))
- return FALSE;
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_BOOLEAN))
+ result = g_variant_get_boolean (v);
- return g_value_get_boolean (v);
+ return result;
}
void
@@ -1673,7 +1669,6 @@ empathy_account_settings_parameter_is_valid (
{
EmpathyAccountSettingsPriv *priv;
const GRegex *regex;
- const gchar *value;
g_return_val_if_fail (EMPATHY_IS_ACCOUNT_SETTINGS (settings), FALSE);
@@ -1704,9 +1699,17 @@ test_regex:
regex = g_hash_table_lookup (priv->param_regexps, param);
if (regex)
{
- value = empathy_account_settings_get_string (settings, param);
- if (value != NULL && !g_regex_match (regex, value, 0, NULL))
+ gchar *value;
+ gboolean match;
+
+ value = empathy_account_settings_dup_string (settings, param);
+ if (value == NULL)
return FALSE;
+
+ match = g_regex_match (regex, value, 0, NULL);
+
+ g_free (value);
+ return match;
}
return TRUE;
diff --git a/libempathy/empathy-account-settings.h b/libempathy/empathy-account-settings.h
index fef3282..e48ce98 100644
--- a/libempathy/empathy-account-settings.h
+++ b/libempathy/empathy-account-settings.h
@@ -104,14 +104,14 @@ const gchar *
empathy_account_settings_get_dbus_signature (EmpathyAccountSettings *setting,
const gchar *param);
-const GValue *
-empathy_account_settings_get_default (EmpathyAccountSettings *settings,
+GVariant *
+empathy_account_settings_dup_default (EmpathyAccountSettings *settings,
const gchar *param);
-const gchar *empathy_account_settings_get_string (
+gchar * empathy_account_settings_dup_string (
EmpathyAccountSettings *settings,
const gchar *param);
-const gchar * const * empathy_account_settings_get_strv (
+GStrv empathy_account_settings_dup_strv (
EmpathyAccountSettings *settings,
const gchar *param);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]