Drop all sections from the state file whose name contains partial_name.
This function is meant to be called when an object is deleted for which state is kept. For example, when an account is deleted from GnuCash, all state sections that refer to it should get removed. In that case you can call this function with the account's guid as parameter.
261{
262 gchar **groups;
263 gint found_count = 0, dropped_count = 0;
264 gsize i, num_groups;
265 GError *error = NULL;
266
267 if (!state_file)
268 {
269 PWARN (
"No pre-existing state found, ignoring drop request");
270 return 0;
271 }
272
274
275 groups = g_key_file_get_groups (state_file, &num_groups);
276 for (i = 0; i < num_groups; i++)
277 {
278 if (g_strstr_len (groups[i], -1, partial_name))
279 {
280 DEBUG (
"Section \"%s\" matches \"%s\", removing", groups[i], partial_name);
281 found_count++;
282 if (!g_key_file_remove_group (state_file, groups[i], &error))
283 {
284 PWARN (
"Warning: unable to remove section %s.\n %s",
285 groups[i],
286 error->message);
287 g_error_free (error);
288 }
289 else
290 dropped_count++;
291
292 }
293 }
294 g_strfreev (groups);
295
296 LEAVE(
"Found %i sections matching \"%s\", successfully removed %i",
297 found_count, partial_name, dropped_count);
298 return dropped_count;
299
300}
#define DEBUG(format, args...)
Print a debugging message.
#define LEAVE(format, args...)
Print a function exit debugging message.
#define PWARN(format, args...)
Log a warning.
#define ENTER(format, args...)
Print a function entry debugging message.