diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/trg-json-widgets.c | 12 | ||||
-rw-r--r-- | src/util.c | 12 | ||||
-rw-r--r-- | src/util.h | 1 |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/trg-json-widgets.c b/src/trg-json-widgets.c index d3030cb..2409ba1 100644 --- a/src/trg-json-widgets.c +++ b/src/trg-json-widgets.c @@ -21,6 +21,7 @@ #include <json-glib/json-glib.h> #include "trg-json-widgets.h" +#include "util.h" void trg_json_widgets_save(GList *list, JsonObject *out) { @@ -103,6 +104,7 @@ static GtkWidget *trg_json_widget_spin_common_new(GList **wl, JsonObject *obj, { GtkWidget *w = gtk_spin_button_new_with_range(min, max, step); trg_json_widget_desc *wd = g_new0(trg_json_widget_desc, 1); + JsonNode *node = json_object_get_member(obj, key); if (type == TRG_JSON_WIDGET_SPIN_DOUBLE) wd->saveFunc = trg_json_widget_spin_save_double; @@ -118,6 +120,8 @@ static GtkWidget *trg_json_widget_spin_common_new(GList **wl, JsonObject *obj, G_CALLBACK(toggle_active_arg_is_sensitive), w); } + gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), json_node_really_get_double(node)); + *wl = g_list_append(*wl, wd); return w; @@ -126,17 +130,13 @@ static GtkWidget *trg_json_widget_spin_common_new(GList **wl, JsonObject *obj, GtkWidget *trg_json_widget_spin_new_int(GList **wl, JsonObject *obj, const gchar *key, GtkWidget *toggleDep, gint min, gint max, gint step) { - GtkWidget *w = trg_json_widget_spin_common_new(wl, obj, key, toggleDep, TRG_JSON_WIDGET_SPIN_INT, min, max, (gdouble)step); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), (gdouble)json_object_get_int_member(obj, key)); - return w; + return trg_json_widget_spin_common_new(wl, obj, key, toggleDep, TRG_JSON_WIDGET_SPIN_INT, min, max, (gdouble)step); } GtkWidget *trg_json_widget_spin_new_double(GList **wl, JsonObject *obj, const gchar *key, GtkWidget *toggleDep, gint min, gint max, gdouble step) { - GtkWidget *w = trg_json_widget_spin_common_new(wl, obj, key, toggleDep, TRG_JSON_WIDGET_SPIN_DOUBLE, min, max, step); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), json_object_get_double_member(obj, key)); - return w; + return trg_json_widget_spin_common_new(wl, obj, key, toggleDep, TRG_JSON_WIDGET_SPIN_DOUBLE, min, max, step); } void trg_json_widget_check_save(GtkWidget *widget, JsonObject *obj, gchar *key) @@ -384,13 +384,19 @@ void trg_widget_set_visible(GtkWidget * w, gboolean visible) { gdouble json_double_to_progress(JsonNode *n) { + return json_node_really_get_double(n)*100.0; +} + +gdouble json_node_really_get_double(JsonNode *node) +{ GValue a = { 0 }; - json_node_get_value(n, &a); + + json_node_get_value(node, &a); switch (G_VALUE_TYPE(&a)) { case G_TYPE_INT64: - return (gdouble) g_value_get_int64(&a) * 100.0; + return (gdouble) g_value_get_int64(&a); case G_TYPE_DOUBLE: - return g_value_get_double(&a) * 100.0; + return g_value_get_double(&a); default: return 0.0; } @@ -70,5 +70,6 @@ gchar *trg_base64encode(const gchar *filename); GtkWidget *my_scrolledwin_new(GtkWidget * child); gboolean is_url(gchar *string); gboolean is_magnet(gchar *string); +gdouble json_node_really_get_double(JsonNode *node); #endif /* UTIL_H_ */ |