[Gnucash-changes] r12905 - gnucash/trunk - Check for bogus window structures (i.e. empty) when reading/writing

David Hampton hampton at cvs.gnucash.org
Thu Jan 19 20:02:58 EST 2006


Author: hampton
Date: 2006-01-19 20:02:57 -0500 (Thu, 19 Jan 2006)
New Revision: 12905
Trac: http://svn.gnucash.org/trac/changeset/12905

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
Log:
Check for bogus window structures (i.e. empty) when reading/writing
the state file.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-01-20 00:38:53 UTC (rev 12904)
+++ gnucash/trunk/ChangeLog	2006-01-20 01:02:57 UTC (rev 12905)
@@ -1,3 +1,8 @@
+2006-01-19  David Hampton  <hampton at employees.org>
+
+	* src/gnome-utils/gnc-main-window.c: Check for bogus window
+	structures (i.e. empty) when reading/writing the state file.
+
 2006-01-19  Derek Atkins  <derek at ihtfp.com>
 
 	* src/business/business-gnome/dialog-invoice.c:

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2006-01-20 00:38:53 UTC (rev 12904)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2006-01-20 01:02:57 UTC (rev 12905)
@@ -499,7 +499,6 @@
 static void
 gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *data)
 {
-  GncMainWindowPrivate *priv;
   gint *pos, *geom;
   gsize length;
   gboolean max;
@@ -510,10 +509,39 @@
   /* Setup */
   ENTER("window %p, data %p (key file %p, window %d)",
 	window, data, data->key_file, data->window_num);
-  priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
   window_group = g_strdup_printf(WINDOW_STRING, data->window_num + 1);
 
-  /* Save the window coordinates, etc. */
+  /* Get this window's notebook info */
+  page_count = g_key_file_get_integer(data->key_file,
+				      window_group, WINDOW_PAGECOUNT, &error);
+  if (error) {
+    g_warning("error reading group %s key %s: %s",
+	      window_group, WINDOW_PAGECOUNT, error->message);
+    goto cleanup;
+  }
+  if (page_count == 0) {
+    /* Shound never happen, but has during alpha testing. Having this
+     * check doesn't hurt anything. */
+    goto cleanup;
+  }
+  page_start = g_key_file_get_integer(data->key_file,
+				      window_group, WINDOW_FIRSTPAGE, &error);
+  if (error) {
+    g_warning("error reading group %s key %s: %s",
+	      window_group, WINDOW_FIRSTPAGE, error->message);
+    goto cleanup;
+  }
+
+  /* Build a window if we don't already have one */
+  if (window == NULL) {
+    DEBUG("Window %d doesn't exist. Creating new window.", data->window_num);
+    DEBUG("active_windows %p.", active_windows);
+    if (active_windows)
+      DEBUG("first window %p.", active_windows->data);
+    window = gnc_main_window_new();
+  }
+
+  /* Get the window coordinates, etc. */
   pos = g_key_file_get_integer_list(data->key_file, window_group,
 				    WINDOW_POSITION, &length, &error);
   if (error) {
@@ -555,22 +583,7 @@
     gtk_window_maximize(GTK_WINDOW(window));
   }
 
-  /* Get this window's notebook info */
-  page_start = g_key_file_get_integer(data->key_file,
-				      window_group, WINDOW_FIRSTPAGE, &error);
-  if (error) {
-    g_warning("error reading group %s key %s: %s",
-	      window_group, WINDOW_FIRSTPAGE, error->message);
-    goto cleanup;
-  }
-  page_count = g_key_file_get_integer(data->key_file,
-				      window_group, WINDOW_PAGECOUNT, &error);
-  if (error) {
-    g_warning("error reading group %s key %s: %s",
-	      window_group, WINDOW_PAGECOUNT, error->message);
-    goto cleanup;
-  }
-
+  /* Now populate the window with pages. */
   for (i = 0; i < page_count; i++) {
     data->page_offset = page_start;
     data->page_num = i;
@@ -695,13 +708,6 @@
   for (i = 0; i < window_count; i++) {
     data.window_num = i;
     window = g_list_nth_data(active_windows, i);
-    if (window == NULL) {
-      DEBUG("Window %d doesn't exist. Creating new window.", i);
-      DEBUG("active_windows %p.", active_windows);
-      if (active_windows)
-	DEBUG("first window %p.", active_windows->data);
-      window = gnc_main_window_new();
-    }
     gnc_main_window_restore_window(window, &data);
   }
 
@@ -765,7 +771,20 @@
   ENTER("window %p, data %p (key file %p, window %d)",
 	window, data, data->key_file, data->window_num);
   priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
+
+  /* Check for bogus window structures. */
+  num_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(priv->notebook));
+  if (0 == num_pages) {
+    LEAVE("empty window %p", window);
+    return;
+  }
+
+  /* Save this window's notebook info */
   window_group = g_strdup_printf(WINDOW_STRING, data->window_num++);
+  g_key_file_set_integer(data->key_file, window_group,
+			 WINDOW_PAGECOUNT, num_pages);
+  g_key_file_set_integer(data->key_file, window_group,
+			 WINDOW_FIRSTPAGE, data->page_num);
 
   /* Save the window coordinates, etc. */
   gtk_window_get_position(GTK_WINDOW(window), &coords[0], &coords[1]);
@@ -782,13 +801,6 @@
 	coords[2], coords[3],
 	maximized ? "maximized" : "not maximized");
 
-  /* Save this window's notebook info */
-  num_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(priv->notebook));
-  g_key_file_set_integer(data->key_file, window_group,
-			 WINDOW_PAGECOUNT, num_pages);
-  g_key_file_set_integer(data->key_file, window_group,
-			 WINDOW_FIRSTPAGE, data->page_num);
-
   /* Save individual pages in this window */
   g_list_foreach(priv->installed_pages, (GFunc)gnc_main_window_save_page, data);
 



More information about the gnucash-changes mailing list