/** Restore all persistent program state. This function finds the * "new" state file associated with the current session. It then * iterates through this state information, calling a helper function * to recreate each open window. * * @note The name of the state file is based on the name of the data * file, not the path name of the data file. If there are multiple * data files with the same name, the state files will be suffixed * with a number. E.G. test_account, test_account_2, test_account_3, * etc. * * @param session A pointer to the current session. * * @param unused An unused pointer. */ static void gnc_restore_all_state (gpointer session, gpointer unused) { GKeyFile *keyfile = NULL; gchar *file_guid = NULL; GError *error = NULL; keyfile = gnc_state_load (session); #ifdef DEBUG /* Debugging: dump a copy to the trace log */ { gchar *file_data; gsize file_length; file_data = g_key_file_to_data(keyfile, &file_length, NULL); DEBUG("=== File Data Read===\n%s\n=== File End ===\n", file_data); g_free(file_data); } #endif /* If no state file was found, keyfile will be empty * In that case, let's load the default state */ if (!g_key_file_has_group (keyfile, STATE_FILE_TOP)) { gnc_main_window_restore_default_state(NULL); LEAVE("no state file"); goto cleanup; } /* report any other keyfile read error as a warning * but still load default state */ file_guid = g_key_file_get_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID, &error); if (error) { gnc_main_window_restore_default_state(NULL); g_warning("error reading group %s key %s: %s", STATE_FILE_TOP, STATE_FILE_BOOK_GUID, error->message); LEAVE("no guid in state file"); goto cleanup; } gnc_main_window_restore_all_windows(keyfile); /* Clean up */ LEAVE("ok"); cleanup: if (error) g_error_free(error); if (file_guid) g_free(file_guid); gnc_totd_dialog_reparent (); }
/** Restore all persistent program state. This function finds the * "new" state file associated with a specific book guid. It then * iterates through this state information, calling a helper function * to recreate each open window. * * @note The name of the state file is based on the name of the data * file, not the path name of the data file. If there are multiple * data files with the same name, the state files will be suffixed * with a number. E.G. test_account, test_account_2, test_account_3, * etc. * * @param session A pointer to the current session. * * @param unused An unused pointer. */ static void gnc_restore_all_state (gpointer session, gpointer unused) { GKeyFile *keyfile = NULL; QofBook *book; const GncGUID *guid; const gchar *url, *guid_string; gchar *file_guid, *filename = NULL; GError *error = NULL; url = qof_session_get_url(session); ENTER("session %p (%s)", session, url ? url : "(null)"); if (!url) { LEAVE("no url, nothing to do"); return; } /* Get the book GncGUID */ book = qof_session_get_book(session); guid = qof_entity_get_guid(QOF_INSTANCE(book)); guid_string = guid_to_string(guid); keyfile = gnc_find_state_file(url, guid_string, &filename); if (filename) g_free(filename); if (!keyfile) { gnc_main_window_restore_default_state(); LEAVE("no state file"); return; } #ifdef DEBUG /* Debugging: dump a copy to stdout and the trace log */ { gchar *file_data; gsize file_length; file_data = g_key_file_to_data(keyfile, &file_length, NULL); DEBUG("=== File Data Read===\n%s\n=== File End ===\n", file_data); g_free(file_data); } #endif /* validate top level info */ file_guid = g_key_file_get_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID, &error); if (error) { g_warning("error reading group %s key %s: %s", STATE_FILE_TOP, STATE_FILE_BOOK_GUID, error->message); LEAVE("can't read guid"); goto cleanup; } if (!file_guid || strcmp(guid_string, file_guid)) { g_warning("guid mismatch: book guid %s, state file guid %s", guid_string, file_guid); LEAVE("guid values do not match"); goto cleanup; } gnc_main_window_restore_all_windows(keyfile); /* Clean up */ LEAVE("ok"); cleanup: if (error) g_error_free(error); if (file_guid) g_free(file_guid); g_key_file_free(keyfile); }