45 static gchar* state_file_name = NULL;
46 static gchar* state_file_name_pre_241 = NULL;
48 static GKeyFile *state_file = NULL;
70 gnc_state_set_base (
const QofSession *session)
72 gchar *basename, *original = NULL, *filename, *file_guid;
73 gchar *sf_extension = 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* scheme = NULL;
112 gchar* dbname = NULL;
113 gchar* username = NULL;
114 gchar* password = NULL;
117 &username, &password, &dbname);
119 basename = g_strjoin (
"_", scheme, 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);
194 g_free(sf_extension);
196 if (key_file != NULL)
197 g_key_file_free (key_file);
207 g_key_file_free (state_file);
211 gnc_state_set_base (session);
213 if (state_file_name_pre_241)
216 else if (state_file_name)
225 GError *error = NULL;
227 if (!strlen (qof_session_get_url(session)))
229 DEBUG(
"No file associated with session - skip state saving");
233 gnc_state_set_base (session);
239 PWARN (
"No state file name set, can't save state");
243 PERR (
"Error: Cannot open state file %s", error->message);
244 g_error_free (error);
252 PINFO (
"No pre-existing state found, creating new one");
253 state_file = g_key_file_new ();
263 gint found_count = 0, dropped_count = 0;
265 GError *error = NULL;
269 PWARN (
"No pre-existing state found, ignoring drop request");
275 groups = g_key_file_get_groups (state_file, &num_groups);
276 for (i = 0; i < num_groups; i++)
278 if (g_strstr_len (groups[i], -1, partial_name))
280 DEBUG (
"Section \"%s\" matches \"%s\", removing", groups[i], partial_name);
282 if (!g_key_file_remove_group (state_file, groups[i], &error))
284 PWARN (
"Warning: unable to remove section %s.\n %s",
287 g_error_free (error);
296 LEAVE(
"Found %i sections matching \"%s\", successfully removed %i",
297 found_count, partial_name, dropped_count);
298 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.
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
void gnc_state_save(const QofSession *session)
Save the state to a state file on disk for the given session.
#define PINFO(format, args...)
Print an informational note.
gint gnc_state_drop_sections_for(const gchar *partial_name)
Drop all sections from the state file whose name contains partial_name.
#define DEBUG(format, args...)
Print a debugging message.
GKeyFile helper routines.
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
void gnc_uri_get_components(const gchar *uri, gchar **scheme, gchar **hostname, gint32 *port, gchar **username, gchar **password, gchar **path)
Converts a uri in separate components.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
gboolean gnc_key_file_save_to_file(const gchar *filename, GKeyFile *key_file, GError **error)
Write a key/value file from memory to disk.
#define PWARN(format, args...)
Log a warning.
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
const GncGUID * qof_entity_get_guid(gconstpointer ent)
gboolean gnc_uri_targets_local_fs(const gchar *uri)
Checks if the given uri is either a valid file uri or a local filesystem path.
#define LEAVE(format, args...)
Print a function exit debugging message.
Utility functions for convert uri in separate components and back.
File path resolution utility functions.
GKeyFile * gnc_state_load(const QofSession *session)
Load the state from a state file on disk for the given session.
GKeyFile * gnc_key_file_load_from_file(const gchar *filename, gboolean ignore_error, gboolean return_empty_struct, GError **caller_error)
Open and read a key/value file from disk into memory.
The type used to store guids in C.