From c5c7a9164713055c43ec69bdda8c2767271515a1 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Fri, 23 May 2008 09:24:18 +0000 Subject: [PATCH] * Fixes NB#85740, save separator position as float in order to enhace placement accuracy pmo-trunk-r4561 --- src/modest-conf.c | 33 +++++++++++++++++++++++++++++++++ src/modest-conf.h | 30 ++++++++++++++++++++++++++++++ src/modest-widget-memory.c | 12 +++++++----- 3 files changed, 70 insertions(+), 5 deletions(-) diff --git a/src/modest-conf.c b/src/modest-conf.c index e8fc818..4696520 100644 --- a/src/modest-conf.c +++ b/src/modest-conf.c @@ -207,6 +207,18 @@ modest_conf_get_int (ModestConf* self, const gchar* key, GError **err) return gconf_client_get_int (priv->gconf_client, key, err); } +gdouble +modest_conf_get_float (ModestConf* self, const gchar* key, GError **err) +{ + ModestConfPrivate *priv; + + g_return_val_if_fail (self, -1); + g_return_val_if_fail (key, -1); + + priv = MODEST_CONF_GET_PRIVATE(self); + + return gconf_client_get_float (priv->gconf_client, key, err); +} gboolean modest_conf_get_bool (ModestConf* self, const gchar* key, GError **err) @@ -281,6 +293,27 @@ modest_conf_set_int (ModestConf* self, const gchar* key, gint val, return gconf_client_set_int (priv->gconf_client, key, val, err); } +gboolean +modest_conf_set_float (ModestConf* self, + const gchar* key, + gdouble val, + GError **err) +{ + ModestConfPrivate *priv; + + g_return_val_if_fail (self,FALSE); + g_return_val_if_fail (key, FALSE); + + priv = MODEST_CONF_GET_PRIVATE(self); + + if (!gconf_client_key_is_writable(priv->gconf_client,key,err)) { + g_printerr ("modest: '%s' is not writable\n", key); + return FALSE; + } + + return gconf_client_set_float (priv->gconf_client, key, val, err); +} + gboolean modest_conf_set_bool (ModestConf* self, const gchar* key, gboolean val, diff --git a/src/modest-conf.h b/src/modest-conf.h index c681549..4cdfb57 100644 --- a/src/modest-conf.h +++ b/src/modest-conf.h @@ -121,6 +121,19 @@ gchar* modest_conf_get_string (ModestConf* self, const gchar* key, GError */ gint modest_conf_get_int (ModestConf* self, const gchar* key, GError **err); +/** + * modest_conf_get_float: + * @self: a ModestConf instance + * @key: the key of the value to retrieve + * @err: a GError ptr, or NULL to ignore. + * + * get an integer from the configuration system + * + * Returns: an double with the value for the key, or -1 in case of + * error (of course, -1 can also be returned in non-error cases). + * @err gives details in case of error + */ +gdouble modest_conf_get_float (ModestConf* self, const gchar* key, GError **err); /** * modest_conf_get_bool: @@ -183,6 +196,23 @@ gboolean modest_conf_set_int (ModestConf* self, const gchar* key, int val GError **err); /** + * modest_conf_set_float: + * @self: a ModestConf instance + * @key: the key of the value to set + * @val: the value to set + * @err: a GError ptr, or NULL if not interested. + * + * store an integer value in the configuration system + * + * Returns: TRUE if succeeded or FALSE in case of error. + * @err gives details in case of error + */ +gboolean modest_conf_set_float (ModestConf* self, + const gchar* key, + gdouble val, + GError **err); + +/** * modest_conf_set_bool: * @self: a ModestConf instance * @key: the key of the value to set diff --git a/src/modest-widget-memory.c b/src/modest-widget-memory.c index f98238c..56ab18a 100644 --- a/src/modest-widget-memory.c +++ b/src/modest-widget-memory.c @@ -219,16 +219,17 @@ static gboolean save_settings_paned (ModestConf *conf, GtkPaned *paned, const gchar *name) { gchar *key; - int pos, percent; + gint pos; + gdouble percent; /* Don't save the paned position if it's not visible, * because it could not be correct: */ if (GTK_WIDGET_REALIZED (GTK_WIDGET (paned))) { pos = gtk_paned_get_position (paned); - percent = pos * 100 / GTK_WIDGET (paned)->allocation.width; + percent = (gdouble) (pos * 100) / (gdouble) GTK_WIDGET (paned)->allocation.width; key = _modest_widget_memory_get_keyname (name, MODEST_WIDGET_MEMORY_PARAM_POS); - modest_conf_set_int (conf, key, percent, NULL); + modest_conf_set_float (conf, key, percent, NULL); g_free (key); } @@ -240,10 +241,11 @@ static gboolean restore_settings_paned (ModestConf *conf, GtkPaned *paned, const gchar *name) { gchar *key; - int percent, pos; + gdouble percent; + gint pos; key = _modest_widget_memory_get_keyname (name, MODEST_WIDGET_MEMORY_PARAM_POS); - percent = modest_conf_get_int (conf, key, NULL); + percent = modest_conf_get_float (conf, key, NULL); if (GTK_WIDGET_VISIBLE (GTK_WIDGET (paned)) && GTK_WIDGET_REALIZED (GTK_WIDGET (paned))) { pos = GTK_WIDGET (paned)->allocation.width * percent /100; -- 1.7.9.5