[gnome-video-arcade] Save main window state.



commit 652257cea69fd6aae2d53bba8d2e264f8045a491
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat May 14 22:41:02 2011 -0400

    Save main window state.
    
    Save main window dimensions and position across sessions.
    Was previously using GConfBridge for this.  Less automated now.

 data/gnome-video-arcade.builder                |    2 +
 docs/reference/gnome-video-arcade-sections.txt |    3 +
 docs/reference/tmpl/gva-main.sgml              |   20 +++++++
 docs/reference/tmpl/gva-util.sgml              |   13 +++++
 src/gva-main.c                                 |   69 ++++++++++++++++++++++--
 src/gva-main.h                                 |    5 ++
 src/gva-util.c                                 |   60 ++++++++++++++++++++
 src/gva-util.h                                 |    6 ++
 8 files changed, 173 insertions(+), 5 deletions(-)
---
diff --git a/data/gnome-video-arcade.builder b/data/gnome-video-arcade.builder
index e6021d8..e83d283 100644
--- a/data/gnome-video-arcade.builder
+++ b/data/gnome-video-arcade.builder
@@ -440,6 +440,8 @@
     <property name="default_height">400</property>
     <property name="icon_name">gnome-video-arcade</property>
     <signal name="destroy" handler="gva_main_window_destroy_cb" swapped="no"/>
+    <signal name="window-state-event" handler="gva_main_window_window_state_event_cb" swapped="no"/>
+    <signal name="configure-event" handler="gva_main_window_configure_event_cb" swapped="no"/>
     <child>
       <object class="GtkVBox" id="main-vbox">
         <property name="visible">True</property>
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index bee5c02..e57cac9 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -192,6 +192,8 @@ gva_main_search_entry_changed_cb
 gva_main_search_entry_icon_release_cb
 gva_main_search_entry_notify_cb
 gva_main_search_query_tooltip_cb
+gva_main_window_configure_event_cb
+gva_main_window_window_state_event_cb
 gva_main_window_destroy_cb
 </SECTION>
 
@@ -503,6 +505,7 @@ gva_get_settings
 gva_get_time_elapsed
 gva_get_user_data_dir
 gva_help_display
+gva_save_window_state
 gva_search_collate_key
 gva_spawn_with_pipes
 </SECTION>
diff --git a/docs/reference/tmpl/gva-main.sgml b/docs/reference/tmpl/gva-main.sgml
index 0320b26..f40388d 100644
--- a/docs/reference/tmpl/gva-main.sgml
+++ b/docs/reference/tmpl/gva-main.sgml
@@ -242,6 +242,26 @@
 @Returns: 
 
 
+<!-- ##### FUNCTION gva_main_window_configure_event_cb ##### -->
+<para>
+
+</para>
+
+ window: 
+ event: 
+ Returns: 
+
+
+<!-- ##### FUNCTION gva_main_window_window_state_event_cb ##### -->
+<para>
+
+</para>
+
+ window: 
+ event: 
+ Returns: 
+
+
 <!-- ##### FUNCTION gva_main_window_destroy_cb ##### -->
 <para>
 
diff --git a/docs/reference/tmpl/gva-util.sgml b/docs/reference/tmpl/gva-util.sgml
index 5d22b11..597c03b 100644
--- a/docs/reference/tmpl/gva-util.sgml
+++ b/docs/reference/tmpl/gva-util.sgml
@@ -113,6 +113,19 @@
 @link_id: 
 
 
+<!-- ##### FUNCTION gva_save_window_state ##### -->
+<para>
+
+</para>
+
+ window: 
+ width_key: 
+ height_key: 
+ maximized_key: 
+ x_key: 
+ y_key: 
+
+
 <!-- ##### FUNCTION gva_search_collate_key ##### -->
 <para>
 
diff --git a/src/gva-main.c b/src/gva-main.c
index e7c0847..f0b9d07 100644
--- a/src/gva-main.c
+++ b/src/gva-main.c
@@ -169,11 +169,18 @@ gva_main_init (void)
                 GVA_WIDGET_MAIN_MUTE_BUTTON, "muted",
                 G_SETTINGS_BIND_DEFAULT);
 
-#if 0  /* GSETTINGS */
-        gconf_bridge_bind_window (
-                gconf_bridge_get (), GVA_GCONF_WINDOW_PREFIX,
-                GTK_WINDOW (GVA_WIDGET_MAIN_WINDOW), TRUE, TRUE);
-#endif
+        gtk_window_move (
+                GTK_WINDOW (GVA_WIDGET_MAIN_WINDOW),
+                g_settings_get_int (settings, "window-x"),
+                g_settings_get_int (settings, "window-y"));
+
+        gtk_window_resize (
+                GTK_WINDOW (GVA_WIDGET_MAIN_WINDOW),
+                g_settings_get_int (settings, "window-width"),
+                g_settings_get_int (settings, "window-height"));
+
+        if (g_settings_get_boolean (settings, "window-maximized"))
+                gtk_window_maximize (GTK_WINDOW (GVA_WIDGET_MAIN_WINDOW));
 
         /* Initialize the search entry. */
         text = gva_main_get_last_search_text ();
@@ -1022,6 +1029,58 @@ gva_main_search_query_tooltip_cb (GtkWidget *widget,
 }
 
 /**
+ * gva_main_window_configure_event_cb:
+ * @window: the main window
+ * @event: a #GdkEventConfigure
+ *
+ * Handler for #GtkWidget::configure-event signals to the main window.
+ *
+ * Saves the main window state to dconf.
+ *
+ * Returns: %FALSE always
+ **/
+gboolean
+gva_main_window_configure_event_cb (GtkWindow *window,
+                                    GdkEventConfigure *event)
+{
+        gva_save_window_state (
+                window,
+                "window-width",
+                "window-height",
+                "window-maximized",
+                "window-x",
+                "window-y");
+
+        return FALSE;
+}
+
+/**
+ * gva_main_window_window_state_event_cb:
+ * @window: the main window
+ * @event: a #GdkEventWindowState
+ *
+ * Handler for #GtkWidget::window-state-event signals to the main window.
+ *
+ * Saves the main window state to dconf.
+ *
+ * Returns: %FALSE always
+ **/
+gboolean
+gva_main_window_window_state_event_cb (GtkWindow *window,
+                                       GdkEventWindowState *event)
+{
+        gva_save_window_state (
+                window,
+                "window-width",
+                "window-height",
+                "window-maximized",
+                "window-x",
+                "window-y");
+
+        return FALSE;
+}
+
+/**
  * gva_main_window_destroy_cb:
  * @window: the main window
  *
diff --git a/src/gva-main.h b/src/gva-main.h
index 054011b..843e722 100644
--- a/src/gva-main.h
+++ b/src/gva-main.h
@@ -77,6 +77,11 @@ gboolean      gva_main_search_query_tooltip_cb   (GtkWidget *widget,
                                                   gint y,
                                                   gboolean keyboard_mode,
                                                   GtkTooltip *tooltip);
+gboolean      gva_main_window_configure_event_cb (GtkWindow *window,
+                                                  GdkEventConfigure *event);
+gboolean      gva_main_window_window_state_event_cb
+                                                 (GtkWindow *window,
+                                                  GdkEventWindowState *event);
 void          gva_main_window_destroy_cb         (GtkWindow *window);
 
 G_END_DECLS
diff --git a/src/gva-util.c b/src/gva-util.c
index 22ac7c2..fa5ef6b 100644
--- a/src/gva-util.c
+++ b/src/gva-util.c
@@ -378,6 +378,66 @@ exit:
 }
 
 /**
+ * gva_save_window_state:
+ * @window: a #GtkWindow
+ * @width_key: name of the window width integer setting, or %NULL
+ * @height_key: name of the window height integer setting, or %NULL
+ * @maximized_key: name of the window maximized boolean setting, or %NULL
+ * @x_key: name of the window X-position integer setting, or %NULL
+ * @y_key: name of the window Y-position integer setting, or %NULL
+ *
+ * Writes the dimensions, position and maximize state of @window to the
+ * given #GSettings keys.  If a key name argument is %NULL, the function
+ * will skip writing a value to that setting.
+ **/
+void
+gva_save_window_state (GtkWindow *window,
+                       const gchar *width_key,
+                       const gchar *height_key,
+                       const gchar *maximized_key,
+                       const gchar *x_key,
+                       const gchar *y_key)
+{
+        GSettings *settings;
+        GdkWindow *gdk_window;
+        GdkWindowState state;
+        gboolean maximized;
+
+        g_return_if_fail (GTK_IS_WINDOW (window));
+
+        settings = gva_get_settings ();
+
+        gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+        state = gdk_window_get_state (gdk_window);
+        maximized = ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0);
+
+        if (!maximized)
+        {
+                gint x, y;
+                gint width;
+                gint height;
+
+                gtk_window_get_position (window, &x, &y);
+                gtk_window_get_size (window, &width, &height);
+
+                if (x_key != NULL)
+                        g_settings_set_int (settings, x_key, x);
+
+                if (y_key != NULL)
+                        g_settings_set_int (settings, y_key, y);
+
+                if (width_key != NULL)
+                        g_settings_set_int (settings, width_key, width);
+
+                if (height_key != NULL)
+                        g_settings_set_int (settings, height_key, height);
+        }
+
+        if (maximized_key != NULL)
+                g_settings_set_boolean (settings, maximized_key, maximized);
+}
+
+/**
  * gva_search_collate_key:
  * @string: a string
  *
diff --git a/src/gva-util.h b/src/gva-util.h
index aeb8df1..ddc7e2b 100644
--- a/src/gva-util.h
+++ b/src/gva-util.h
@@ -71,6 +71,12 @@ void            gva_get_time_elapsed            (GTimeVal *start_time,
 const gchar *   gva_get_user_data_dir           (void);
 void            gva_help_display                (GtkWindow *parent,
                                                  const gchar *link_id);
+void            gva_save_window_state           (GtkWindow *window,
+                                                 const gchar *width_key,
+                                                 const gchar *height_key,
+                                                 const gchar *maximized_key,
+                                                 const gchar *x_key,
+                                                 const gchar *y_key);
 gchar *         gva_search_collate_key          (const gchar *string);
 gboolean        gva_spawn_with_pipes            (const gchar *command_line,
                                                  GPid *child_pid,



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