r16077 - gnucash/trunk/src - Add gnc_history_remove_file, call it if the history file cannot be loaded, #388500.

Andreas Köhler andi5 at cvs.gnucash.org
Sat May 12 19:30:36 EDT 2007


Author: andi5
Date: 2007-05-12 19:30:35 -0400 (Sat, 12 May 2007)
New Revision: 16077
Trac: http://svn.gnucash.org/trac/changeset/16077

Modified:
   gnucash/trunk/src/bin/gnucash-bin.c
   gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.c
   gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.h
Log:
Add gnc_history_remove_file, call it if the history file cannot be loaded, #388500.


Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c	2007-05-12 19:36:39 UTC (rev 16076)
+++ gnucash/trunk/src/bin/gnucash-bin.c	2007-05-12 23:30:35 UTC (rev 16077)
@@ -471,7 +471,8 @@
     if (!nofile && (fn = get_file_to_load())) {
         gnc_update_splash_screen(_("Loading data..."));
         gnc_destroy_splash_screen();
-        gnc_file_open_file(fn);
+        if (!gnc_file_open_file(fn))
+            gnc_history_remove_file(fn);
         g_free(fn);
     } 
     else if (gnc_gconf_get_bool("dialogs/new_user", "first_startup", &error)

Modified: gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.c	2007-05-12 19:36:39 UTC (rev 16076)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.c	2007-05-12 23:30:35 UTC (rev 16077)
@@ -206,6 +206,43 @@
 }
 
 
+/** Remove all occurences of a file name from the history list.  Move
+ *  the other key values up in the list to fill the gaps.
+ *
+ *  @param filename The name of the file to remove from the list.
+ */
+void
+gnc_history_remove_file (const char *oldfile)
+{
+  gchar *filename, *from, *to;
+  gint i, j;
+
+  if (!oldfile)
+    return;
+  if (!g_utf8_validate(oldfile, -1, NULL))
+    return;
+
+  for (i=0, j=0; i<MAX_HISTORY_FILES; i++) {
+    from = gnc_history_gconf_index_to_key(i);
+    filename = gnc_gconf_get_string(HISTORY_STRING_SECTION, from, NULL);
+
+    if (filename) {
+      if (g_utf8_collate(oldfile, filename) == 0) {
+        gnc_gconf_unset(HISTORY_STRING_SECTION, from, NULL);
+      } else {
+        if (i != j) {
+          to = gnc_history_gconf_index_to_key(j);
+          gnc_gconf_set_string(HISTORY_STRING_SECTION, to, filename, NULL);
+          gnc_gconf_unset(HISTORY_STRING_SECTION, from, NULL);
+          g_free(to);
+        }
+        j++;
+      }
+    }
+    g_free(from);
+  }
+}
+
 /*  Retrieve the name of the file most recently accessed.  This is the
  *  name at the front of the list.  Since the "list" is actually a
  *  sequence of up to ten gconf keys, this is the value of key zero.
@@ -660,7 +697,9 @@
 	 */
 	filename = g_object_get_data(G_OBJECT(action), FILENAME_STRING);
 	gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
-	gnc_file_open_file (filename); /* also opens new account page */
+	/* also opens new account page */
+	if (!gnc_file_open_file (filename))
+	  gnc_history_remove_file (filename);
 	gnc_window_set_progressbar_window (NULL);
 }
 

Modified: gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.h	2007-05-12 19:36:39 UTC (rev 16076)
+++ gnucash/trunk/src/gnome-utils/gnc-plugin-file-history.h	2007-05-12 23:30:35 UTC (rev 16077)
@@ -93,7 +93,14 @@
  */
 void gnc_history_add_file (const char *filename);
 
+/** Remove all occurences of a file name from the history list.  Move
+ *  the other key values up in the list to fill the gaps.
+ *
+ *  @param filename The name of the file to remove from the list.
+ */
+void gnc_history_remove_file (const char *filename);
 
+
 /** Retrieve the name of the file most recently accessed.  This is the
  *  name at the front of the list.  Since the "list" is actually a
  *  sequence of up to ten gconf keys, this is the value of key zero.



More information about the gnucash-changes mailing list