45 static gchar* state_file_name = NULL;
46 static gchar* state_file_name_pre_241 = NULL;
48 static GKeyFile *state_file = NULL;
72 gchar *basename, *original = NULL, *filename, *file_guid;
73 gchar *sf_extension = NULL, *newstyle_filename = NULL;
78 GKeyFile *key_file = NULL;
82 g_free (state_file_name);
83 g_free (state_file_name_pre_241);
84 state_file_name = NULL;
85 state_file_name_pre_241 = NULL;
87 uri = qof_session_get_url(session);
88 ENTER(
"session %p (%s)", session, uri ? uri :
"(null)");
91 LEAVE(
"no uri, nothing to do");
104 basename = g_path_get_basename (path);
110 gchar* protocol = NULL;
112 gchar* dbname = NULL;
113 gchar* username = NULL;
114 gchar* password = NULL;
117 &username, &password, &dbname);
119 basename = g_strjoin (
"_", protocol, host, username, dbname, NULL);
127 DEBUG (
"Basename %s", basename);
130 DEBUG (
"Original %s", original);
132 sf_extension = g_strdup (STATE_FILE_EXT);
137 filename = g_strconcat (original, sf_extension, NULL);
139 filename = g_strdup_printf (
"%s_%d%s", original, i, sf_extension);
140 DEBUG (
"Trying %s", filename);
142 DEBUG (
"Result %p", key_file);
146 DEBUG (
"No key file by that name");
147 if (g_strcmp0 (sf_extension, STATE_FILE_EXT) == 0)
149 DEBUG (
"Trying old state file names for compatibility");
151 g_free ( sf_extension);
152 sf_extension = g_strdup (
"");
158 state_file_name = filename;
168 file_guid = g_key_file_get_string (key_file,
169 STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
171 DEBUG (
"File GncGUID is %s", file_guid ? file_guid :
"<not found>");
172 if (g_strcmp0 (guid_string, file_guid) == 0)
174 DEBUG (
"Matched !!!");
178 if (g_strcmp0 (sf_extension, STATE_FILE_EXT) == 0)
179 state_file_name = filename;
181 state_file_name_pre_241 = filename;
186 DEBUG (
"Clean up this pass");
188 g_key_file_free (key_file);
195 g_key_file_free (key_file);
203 GKeyFile *keyfile = NULL;
204 GError *error = NULL;
209 g_key_file_free (state_file);
213 gnc_state_set_base (session);
215 if (state_file_name_pre_241)
218 else if (state_file_name)
228 GError *error = NULL;
230 if (!qof_session_get_url(session))
232 DEBUG(
"No file associated with session - skip state saving");
236 gnc_state_set_base (session);
242 PWARN (
"No state file name set, can't save state");
246 PERR (
"Error: Failure saving state file.\n %s",
248 g_error_free (error);
256 PINFO (
"No pre-existing state found, creating new one");
257 state_file = g_key_file_new ();
267 gint found_count = 0, dropped_count = 0;
269 GError *error = NULL;
273 PWARN (
"No pre-existing state found, ignoring drop request");
279 groups = g_key_file_get_groups (state_file, &num_groups);
280 for (i = 0; i < num_groups; i++)
282 if (g_strstr_len (groups[i], -1, partial_name))
284 DEBUG (
"Section \"%s\" matches \"%s\", removing", groups[i], partial_name);
286 if (!g_key_file_remove_group (state_file, groups[i], &error))
288 PWARN (
"Warning: unable to remove section %s.\n %s",
291 g_error_free (error);
300 LEAVE(
"Found %i sections matching \"%s\", successfully removed %i",
301 found_count, partial_name, dropped_count);
302 return dropped_count;
Functions to load, save and get gui state.
gchar * gnc_build_book_path(const gchar *filename)
Make a path to filename in the book subdirectory of the user's configuration directory.
gboolean gnc_uri_is_file_uri(const gchar *uri)
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
void gnc_state_save(const QofSession *session)
#define PINFO(format, args...)
gint gnc_state_drop_sections_for(const gchar *partial_name)
#define DEBUG(format, args...)
GKeyFile helper routines.
gchar * gnc_uri_get_path(const gchar *uri)
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
#define PERR(format, args...)
#define ENTER(format, args...)
GKeyFile * gnc_state_get_current(void)
#define PWARN(format, args...)
QofBook * qof_session_get_book(const QofSession *session)
gboolean gnc_key_file_save_to_file(const gchar *filename, GKeyFile *key_file, GError **error)
#define GUID_ENCODING_LENGTH
void gnc_uri_get_components(const gchar *uri, gchar **protocol, gchar **hostname, gint32 *port, gchar **username, gchar **password, gchar **path)
GKeyFile * gnc_key_file_load_from_file(const gchar *filename, gboolean ignore_error, gboolean return_empty_struct, GError **caller_error)
const GncGUID * qof_entity_get_guid(gconstpointer)
#define LEAVE(format, args...)
Utility functions for convert uri in separate components and back.
File path resolution utility functions.
GKeyFile * gnc_state_load(const QofSession *session)
const gchar * QofLogModule