summaryrefslogtreecommitdiff
path: root/src/trg-json-widgets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/trg-json-widgets.c')
-rw-r--r--src/trg-json-widgets.c58
1 files changed, 53 insertions, 5 deletions
diff --git a/src/trg-json-widgets.c b/src/trg-json-widgets.c
index 21d5610..7815a38 100644
--- a/src/trg-json-widgets.c
+++ b/src/trg-json-widgets.c
@@ -28,6 +28,8 @@
#include "json.h"
#include "util.h"
+#define TRG_JSON_WIDGET_SPIN_DOUBLE_DIGITS 2
+
/* Functions for creating widgets that load/save their state from/to a JSON
* object. This is used by the torrent properties and remote settings dialogs.
* The pattern here is farily similar to that used in local configuration,
@@ -121,15 +123,52 @@ GtkWidget *trg_json_widget_entry_new(GList ** wl, JsonObject * obj,
return w;
}
-GtkWidget *trg_json_widget_spin_new(GList ** wl, JsonObject * obj,
+GtkWidget *trg_json_widget_spin_int_new(GList ** wl, JsonObject * obj,
+ const gchar * key,
+ GtkWidget * toggleDep, gint min,
+ gint max, gint step)
+{
+ GtkWidget *w = gtk_spin_button_new_with_range((gdouble)min,
+ (gdouble)max,
+ (gdouble)step);
+
+ gtk_spin_button_set_digits(GTK_SPIN_BUTTON(w), 0);
+
+ trg_json_widget_desc *wd = g_new0(trg_json_widget_desc, 1);
+
+ wd->saveFunc = trg_json_widget_spin_int_save;
+ wd->key = g_strdup(key);
+ wd->widget = w;
+
+ if (toggleDep) {
+ gtk_widget_set_sensitive(w,
+ gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON(toggleDep)));
+ g_signal_connect(G_OBJECT(toggleDep), "toggled",
+ G_CALLBACK(toggle_active_arg_is_sensitive), w);
+ }
+
+ gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
+ (double)json_object_get_int_member(obj, key));
+
+ *wl = g_list_append(*wl, wd);
+
+ return w;
+}
+
+GtkWidget *trg_json_widget_spin_double_new(GList ** wl, JsonObject * obj,
const gchar * key,
GtkWidget * toggleDep, gdouble min,
gdouble max, gdouble step)
{
GtkWidget *w = gtk_spin_button_new_with_range(min, max, step);
+
+ gtk_spin_button_set_digits(GTK_SPIN_BUTTON(w),
+ TRG_JSON_WIDGET_SPIN_DOUBLE_DIGITS);
+
trg_json_widget_desc *wd = g_new0(trg_json_widget_desc, 1);
- wd->saveFunc = trg_json_widget_spin_save_int;
+ wd->saveFunc = trg_json_widget_spin_double_save;
wd->key = g_strdup(key);
wd->widget = w;
@@ -142,7 +181,7 @@ GtkWidget *trg_json_widget_spin_new(GList ** wl, JsonObject * obj,
}
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w),
- (double)json_object_get_int_member(obj, key));
+ json_object_get_double_member(obj, key));
*wl = g_list_append(*wl, wd);
@@ -167,10 +206,19 @@ trg_json_widget_entry_save(GtkWidget * widget, JsonObject * obj,
}
void
-trg_json_widget_spin_save_int(GtkWidget * widget, JsonObject * obj,
+trg_json_widget_spin_int_save(GtkWidget * widget, JsonObject * obj,
gchar * key)
{
json_object_set_int_member(obj, key,
- gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
+ gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
+ (widget)));
+}
+
+void
+trg_json_widget_spin_double_save(GtkWidget * widget, JsonObject * obj,
+ gchar * key)
+{
+ json_object_set_double_member(obj, key,
+ gtk_spin_button_get_value(GTK_SPIN_BUTTON
(widget)));
}