[ekiga/ds-clutter] GmWindow: Allow applications to save and restore the state of GmWindow.



commit 10c0d8722f03c824f49d78cb35a31d8c435d9eeb
Author: Damien Sandras <dsandras beip be>
Date:   Mon Dec 30 12:06:30 2013 +0100

    GmWindow: Allow applications to save and restore the state of GmWindow.

 lib/gui/gmwindow.c |  132 +++++++++++++++++++++++++++++-----------------------
 lib/gui/gmwindow.h |   16 ++++++-
 2 files changed, 87 insertions(+), 61 deletions(-)
---
diff --git a/lib/gui/gmwindow.c b/lib/gui/gmwindow.c
index 5734335..41052c5 100644
--- a/lib/gui/gmwindow.c
+++ b/lib/gui/gmwindow.c
@@ -81,11 +81,9 @@ static gboolean
 gm_window_configure_event (GtkWidget *widget,
                            GdkEventConfigure *event);
 
-
 /*
  * GObject stuff
  */
-
 static void
 gm_window_finalize (GObject *obj)
 {
@@ -258,53 +256,13 @@ static void
 window_realize_cb (GtkWidget *w,
                   G_GNUC_UNUSED gpointer data)
 {
-  int x = 0;
-  int y = 0;
-
   GmWindow *self = NULL;
 
-  gchar *size = NULL;
-  gchar *position = NULL;
-  gchar **couple = NULL;
-
   self = GM_WINDOW (w);
 
-  g_return_if_fail (g_strcmp0 (self->priv->key, ""));
-
-  if (gtk_window_get_resizable (GTK_WINDOW (w))) {
-
-    size = g_settings_get_string (self->priv->settings, "size");
-    if (size)
-      couple = g_strsplit (size, ",", 0);
-
-    if (couple && couple [0])
-      x = atoi (couple [0]);
-    if (couple && couple [1])
-      y = atoi (couple [1]);
-
-    if (x > 0 && y > 0) {
-      gtk_window_resize (GTK_WINDOW (w), x, y);
-    }
-
-    g_strfreev (couple);
-    g_free (size);
-  }
-
-  position = g_settings_get_string (self->priv->settings, "position");
-  if (position)
-    couple = g_strsplit (position, ",", 0);
-
-  if (couple && couple [0])
-    x = atoi (couple [0]);
-  if (couple && couple [1])
-    y = atoi (couple [1]);
+  g_return_if_fail (g_strcmp0 (self->priv->key, "") && self);
 
-  if (x != 0 && y != 0)
-    gtk_window_move (GTK_WINDOW (w), x, y);
-
-  g_strfreev (couple);
-  couple = NULL;
-  g_free (position);
+  gm_window_restore (self);
 
   gtk_widget_realize (GTK_WIDGET (w));
 }
@@ -316,25 +274,11 @@ window_hide_cb (GtkWidget *w,
 {
   GmWindow *self = NULL;
 
-  gchar *size = NULL;
-  gchar *position = NULL;
-
   g_return_if_fail (w != NULL);
 
   self = GM_WINDOW (w);
 
-  g_return_if_fail (g_strcmp0 (self->priv->key, ""));
-
-  position = g_strdup_printf ("%d,%d", self->priv->x, self->priv->y);
-  g_settings_set_string (self->priv->settings, "position", position);
-  g_free (position);
-
-  if (gtk_window_get_resizable (GTK_WINDOW (w))) {
-
-    size = g_strdup_printf ("%d,%d", self->priv->width, self->priv->height);
-    g_settings_set_string (self->priv->settings, "size", size);
-    g_free (size);
-  }
+  gm_window_save (self);
 }
 
 
@@ -371,6 +315,76 @@ gm_window_new_with_key (const char *key)
 
 
 void
+gm_window_save (GmWindow *self)
+{
+  gchar *size = NULL;
+  gchar *position = NULL;
+
+  g_return_if_fail (g_strcmp0 (self->priv->key, "") || self);
+
+  position = g_strdup_printf ("%d,%d", self->priv->x, self->priv->y);
+  g_settings_set_string (self->priv->settings, "position", position);
+  g_free (position);
+
+  if (gtk_window_get_resizable (GTK_WINDOW (self))) {
+
+    size = g_strdup_printf ("%d,%d", self->priv->width, self->priv->height);
+    g_settings_set_string (self->priv->settings, "size", size);
+    g_free (size);
+  }
+}
+
+
+void
+gm_window_restore (GmWindow *self)
+{
+  int x = 0;
+  int y = 0;
+
+  gchar *size = NULL;
+  gchar *position = NULL;
+  gchar **couple = NULL;
+
+  g_return_if_fail (g_strcmp0 (self->priv->key, "") && self);
+
+  if (gtk_window_get_resizable (GTK_WINDOW (self))) {
+
+    size = g_settings_get_string (self->priv->settings, "size");
+    if (size)
+      couple = g_strsplit (size, ",", 0);
+
+    if (couple && couple [0])
+      x = atoi (couple [0]);
+    if (couple && couple [1])
+      y = atoi (couple [1]);
+
+    if (x > 0 && y > 0) {
+      gtk_window_resize (GTK_WINDOW (self), x, y);
+    }
+
+    g_strfreev (couple);
+    g_free (size);
+  }
+
+  position = g_settings_get_string (self->priv->settings, "position");
+  if (position)
+    couple = g_strsplit (position, ",", 0);
+
+  if (couple && couple [0])
+    x = atoi (couple [0]);
+  if (couple && couple [1])
+    y = atoi (couple [1]);
+
+  if (x != 0 && y != 0)
+    gtk_window_move (GTK_WINDOW (self), x, y);
+
+  g_strfreev (couple);
+  couple = NULL;
+  g_free (position);
+}
+
+
+void
 gm_window_get_size (GmWindow *self,
                     int *x,
                     int *y)
diff --git a/lib/gui/gmwindow.h b/lib/gui/gmwindow.h
index f64631b..c614ab0 100644
--- a/lib/gui/gmwindow.h
+++ b/lib/gui/gmwindow.h
@@ -64,7 +64,7 @@ struct _GmWindowClass
 /* Public API */
 
 /** Create a new GmWindow.
- * @return A GmWindow 
+ * @return A GmWindow
  */
 GtkWidget *gm_window_new ();
 
@@ -72,11 +72,23 @@ GtkWidget *gm_window_new ();
 /** Create a new GmWindow.
  * @param The key where the position and size of the
  * window will be saved.
- * @return A GmWindow 
+ * @return A GmWindow
  */
 GtkWidget *gm_window_new_with_key (const char *key);
 
 
+/** Save the state of a GmWindow.
+ * @param A GmWindow
+ */
+void gm_window_save (GmWindow *window);
+
+
+/** Restore the state of a GmWindow.
+ * @param A GmWindow
+ */
+void gm_window_restore (GmWindow *window);
+
+
 /** Return the size of the GmWindow.
  * @param window is the GmWindow
  * @param x is the width


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]