Example #1
0
void gnc_state_save (const QofSession *session)
{
    GError *error = NULL;

    if (!qof_session_get_url(session))
    {
        DEBUG("No file associated with session - skip state saving");
        return;
    }

    gnc_state_set_base (session);

    /* Write it all out to disk */
    if (state_file_name)
        gnc_key_file_save_to_file(state_file_name, state_file, &error);
    else
        PWARN ("No state file name set, can't save state");

    if (error)
    {
        PERR ("Error: Failure saving state file.\n  %s",
              error->message);
        g_error_free (error);
    }
}
Example #2
0
void
gnc_exp_parser_shutdown (void)
{
    GKeyFile* key_file;
    gchar *filename;

    if (!parser_inited)
        return;

    filename = gnc_exp_parser_filname();
    key_file = g_key_file_new();
    g_hash_table_foreach (variable_bindings, set_one_key, key_file);
    g_key_file_set_comment(key_file, GROUP_NAME, NULL,
                           " Variables are in the form 'name=value'",
                           NULL);
    gnc_key_file_save_to_file(filename, key_file, NULL);
    g_key_file_free(key_file);
    g_free(filename);

    g_hash_table_foreach_remove (variable_bindings, remove_binding, NULL);
    g_hash_table_destroy (variable_bindings);
    variable_bindings = NULL;

    last_error = PARSER_NO_ERROR;
    last_gncp_error = NO_ERR;

    parser_inited = FALSE;
}
Example #3
0
/** Save all persistent program state to disk.  This function finds the
 *  name of the "new" state file associated with a specific book guid.
 *  It saves some top level data, then iterates through the list of
 *  open windows calling a helper function to save each 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 The QofSession whose state should be saved.
 *
 *  @param unused */
static void
gnc_save_all_state (gpointer session, gpointer unused)
{
    QofBook *book;
    const char *url, *guid_string;
    gchar *filename;
    const GncGUID *guid;
    GError *error = NULL;
    GKeyFile *keyfile = 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);

    /* Find the filename to use.  This returns the data from the
     * file so its possible that we could reuse the data and
     * maintain comments that were added to the data file, but
     * that's not something we currently do. For now the existing
     * data is dumped and completely regenerated.*/
    keyfile = gnc_find_state_file(url, guid_string, &filename);
    if (keyfile)
        g_key_file_free(keyfile);

    keyfile = g_key_file_new();
    /* Store top level info in the data structure */
    g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID,
                          guid_string);

    gnc_main_window_save_all_windows(keyfile);

#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 Written===\n%s\n=== File End ===\n", file_data);
        g_free(file_data);
    }
#endif

    /* Write it all out to disk */
    gnc_key_file_save_to_file(filename, keyfile, &error);
    if (error)
    {
        g_critical(_("Error: Failure saving state file.\n  %s"),
                   error->message);
        g_error_free(error);
    }
    g_free(filename);

    /* Clean up */
    g_key_file_free(keyfile);
    LEAVE("");
}