+void
+psppire_conf_set_boolean (PsppireConf *conf,
+ const gchar *base, const gchar *name,
+ gboolean value)
+{
+ g_key_file_set_boolean (conf->keyfile, base, name, value);
+ conf_write (conf);
+}
+
+
+void
+psppire_conf_set_string (PsppireConf *conf,
+ const gchar *base, const gchar *name,
+ const gchar *value)
+{
+ g_key_file_set_string (conf->keyfile, base, name, value);
+ conf_write (conf);
+}
+
+void
+psppire_conf_set_variant (PsppireConf *conf,
+ const gchar *base, const gchar *name,
+ GVariant *value)
+{
+ gchar *v = g_variant_print (value, FALSE);
+ g_key_file_set_string (conf->keyfile, base, name, v);
+ conf_write (conf);
+ g_free (v);
+}
+
+void
+psppire_conf_set_enum (PsppireConf *conf,
+ const gchar *base, const gchar *name,
+ GType enum_type,
+ int value)
+{
+ GEnumClass *ec = g_type_class_ref (enum_type);
+ GEnumValue *ev = g_enum_get_value (ec, value);
+
+ g_key_file_set_string (conf->keyfile, base, name,
+ ev->value_nick);
+
+ g_type_class_unref (ec);
+
+ conf_write (conf);
+}
+
+
+
+/*
+ A convenience function to set the geometry of a
+ window from from a saved config
+*/
+void
+psppire_conf_set_window_geometry (PsppireConf *conf,
+ const gchar *base,
+ GtkWindow *window)
+{
+ gint height, width;
+ gint x, y;
+ gboolean maximize;
+
+ if (psppire_conf_get_int (conf, base, "height", &height)
+ &&
+ psppire_conf_get_int (conf, base, "width", &width))
+ {
+ gtk_window_set_default_size (window, width, height);
+ }
+
+ if (psppire_conf_get_int (conf, base, "x", &x)
+ &&
+ psppire_conf_get_int (conf, base, "y", &y))
+ {
+ gtk_window_move (window, x, y);
+ }
+
+ if (psppire_conf_get_boolean (conf, base, "maximize", &maximize))
+ {
+ if (maximize)
+ gtk_window_maximize (window);
+ else
+ gtk_window_unmaximize (window);
+ }
+}
+
+
+/*
+ A convenience function to save the window geometry.
+ This should typically be called from a window's
+ "configure-event" and "window-state-event" signal handlers
+ */
+void
+psppire_conf_save_window_geometry (PsppireConf *conf,
+ const gchar *base,
+ GtkWindow *gtk_window)
+{
+ gboolean maximized;
+ GdkWindow *w;
+
+ w = gtk_widget_get_window (GTK_WIDGET (gtk_window));
+ if (w == NULL)
+ return;
+
+ maximized = (gdk_window_get_state (w) & GDK_WINDOW_STATE_MAXIMIZED) != 0;
+ psppire_conf_set_boolean (conf, base, "maximize", maximized);
+
+ if (!maximized)
+ {
+ gint x, y;
+
+ gint width = gdk_window_get_width (w);
+ gint height= gdk_window_get_height (w);
+
+ gdk_window_get_position (w, &x, &y);
+
+ psppire_conf_set_int (conf, base, "height", height);
+ psppire_conf_set_int (conf, base, "width", width);
+ psppire_conf_set_int (conf, base, "x", x);
+ psppire_conf_set_int (conf, base, "y", y);
+ }
+}