Added a simple singleton object for user preference storage.
[pspp] / src / ui / gui / psppire-window.c
index 407ba9737296142db83d3cb86849cca6d5d87cad..5de6afd84a8e416ea23275d7c04a5cc151917670 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "psppire-window.h"
 #include "psppire-window-register.h"
+#include "psppire-conf.h"
 
 static void psppire_window_base_finalize (PsppireWindowClass *, gpointer);
 static void psppire_window_base_init     (PsppireWindowClass *class);
@@ -190,6 +191,49 @@ psppire_window_get_property (GObject         *object,
 }
 
 
+static void
+on_realize (GtkWindow *window, gpointer data)
+{
+  gint height, width;
+  gint x, y;
+
+  PsppireConf *conf = psppire_conf_new ();
+
+  const gchar *base = G_OBJECT_TYPE_NAME (window);
+
+  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, "x", &y) )
+    {
+      gtk_window_move (window, x, y);
+    }
+
+}
+
+
+static gboolean
+on_configure (GtkWidget *w, GdkEventConfigure *event, gpointer data)
+{
+  const gchar *base = G_OBJECT_TYPE_NAME (w);
+
+  PsppireConf *conf = psppire_conf_new ();
+
+  psppire_conf_set_int (conf, base, "height", event->height);
+  psppire_conf_set_int (conf, base, "width", event->width);
+  psppire_conf_set_int (conf, base, "x", event->x);
+  psppire_conf_set_int (conf, base, "y", event->y);
+
+  return FALSE;
+}
+
 
 static void
 psppire_window_finalize (GObject *object)
@@ -402,6 +446,12 @@ psppire_window_init (PsppireWindow *window)
 
   g_object_set (window, "icon-name", "psppicon", NULL);
 
+  g_signal_connect (window, "configure-event",
+                   G_CALLBACK (on_configure), window);
+
+  g_signal_connect (window, "realize",
+                   G_CALLBACK (on_realize), window);
+
 }