Пример #1
0
gboolean
equals_node_val_vs_kvp_frame(xmlNodePtr node, const KvpFrame *frm)
{
    KvpFrame *cmpfrm;

    g_return_val_if_fail(node, FALSE);
    g_return_val_if_fail(frm, FALSE);

    cmpfrm = dom_tree_to_kvp_frame(node);

    g_return_val_if_fail(cmpfrm, FALSE);

    if (compare(frm, cmpfrm) == 0)
    {
        delete cmpfrm;
        return TRUE;
    }
    else
    {
        auto frm1str = g_strdup(frm->to_string().c_str());
        auto frm2str = g_strdup(cmpfrm->to_string().c_str());

        printf("%s vs %s\n", frm1str, frm2str);

        g_free(frm1str);
        g_free(frm2str);

        delete cmpfrm;
        return FALSE;
    }
}
Пример #2
0
/** Returns pointer to default gain/loss policy for book, if one exists in the
  * KVP, or NULL; does not validate contents nor determine if there is a valid
  * book-currency, both of which are required, for the 'book-currency'
  * currency accounting method to apply. Use instead
  * 'gnc_book_get_default_gains_policy' which does these validations. */
const gchar *
qof_book_get_default_gains_policy (QofBook *book)
{
    KvpFrame *kvp;
    KvpValue *value;

    if (!book)
    {
        PWARN ("No book!!!");
        return NULL;
    }

    /* Get the KVP from the current book */
    kvp = qof_instance_get_slots (QOF_INSTANCE (book));

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return NULL;
    }

    /* See if there is a default gain/loss policy */
    value = kvp->get_slot({KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS,
                           OPTION_NAME_DEFAULT_GAINS_POLICY});
    if (!value)
    /* No default gain/loss policy, therefore not valid book-currency
       accounting method */
        return nullptr;

    return g_strdup(value->get<const char*>());
}
Пример #3
0
gchar *
qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
{
    KvpFrame *kvp;
    KvpValue *value;
    gint64 counter;
    gchar* format;
    gchar* result;

    if (!book)
    {
        PWARN ("No book!!!");
        return NULL;
    }

    if (!counter_name || *counter_name == '\0')
    {
        PWARN ("Invalid counter name.");
        return NULL;
    }

    /* Get the current counter value from the KVP in the book. */
    counter = qof_book_get_counter(book, counter_name);

    /* Check if an error occurred */
    if (counter < 0)
        return NULL;

    /* Increment the counter */
    counter++;

    /* Get the KVP from the current book */
    kvp = qof_instance_get_slots (QOF_INSTANCE (book));

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return NULL;
    }

    /* Save off the new counter */
    qof_book_begin_edit(book);
    value = new KvpValue(counter);
    delete kvp->set_path({"counters", counter_name}, value);
    qof_instance_set_dirty (QOF_INSTANCE (book));
    qof_book_commit_edit(book);

    format = qof_book_get_counter_format(book, counter_name);

    if (!format)
    {
        PWARN("Cannot get format for counter");
        return NULL;
    }

    /* Generate a string version of the counter */
    result = g_strdup_printf(format, counter);
    g_free (format);
    return result;
}
Пример #4
0
/** Returns pointer to book-currency name for book, if one exists in the
  * KVP, or NULL; does not validate contents nor determine if there is a valid
  * default gain/loss policy, both of which are required, for the
  * 'book-currency' currency accounting method to apply. Use instead
  * 'gnc_book_get_book_currency' which does these validations. */
const gchar *
qof_book_get_book_currency (QofBook *book)
{
    KvpFrame *kvp;
    KvpValue *value;

    if (!book)
    {
        PWARN ("No book!!!");
        return NULL;
    }

    /* Get the KVP from the current book */
    kvp = qof_instance_get_slots (QOF_INSTANCE (book));

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return NULL;
    }

    /* See if there is a book currency. */
    value = kvp->get_slot({KVP_OPTION_PATH, OPTION_SECTION_ACCOUNTS,
                           OPTION_NAME_BOOK_CURRENCY});
    if (!value) /* No book-currency */
        return nullptr;

    return value->get<const char*>();
}
Пример #5
0
KvpValue*
qof_book_get_option (QofBook *book, GSList *path)
{
    KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
    Path path_v {KVP_OPTION_PATH};
    for (auto item = path; item != nullptr; item = g_slist_next(item))
        path_v.push_back(static_cast<const char*>(item->data));
    return root->get_slot(path_v);
}
Пример #6
0
void
qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
{
    KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
    qof_book_begin_edit (book);
    delete frame->set_path({GNC_FEATURES, key}, new KvpValue(descr));
    qof_instance_set_dirty (QOF_INSTANCE (book));
    qof_book_commit_edit (book);
}
Пример #7
0
const gchar *
qof_book_get_counter_format(const QofBook *book, const char *counter_name)
{
    KvpFrame *kvp;
    const char *format;
    KvpValue *value;
    gchar *error;

    if (!book)
    {
        PWARN ("No book!!!");
        return NULL;
    }

    if (!counter_name || *counter_name == '\0')
    {
        PWARN ("Invalid counter name.");
        return NULL;
    }

    /* Get the KVP from the current book */
    kvp = qof_instance_get_slots (QOF_INSTANCE (book));

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return NULL;
    }

    format = NULL;

    /* Get the format string */
    value = kvp->get_slot({"counter_formats", counter_name});
    if (value)
    {
        format = value->get<const char*>();
        error = qof_book_validate_counter_format(format);
        if (error != NULL)
        {
            PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", format, counter_name, error);
            /* Invalid format string */
            format = NULL;
            g_free(error);
        }
    }

    /* If no (valid) format string was found, use the default format
     * string */
    if (!format)
    {
        /* Use the default format */
        format = "%.6" G_GINT64_FORMAT;
    }
    return format;
}
Пример #8
0
char *
qof_book_get_counter_format(const QofBook *book, const char *counter_name)
{
    KvpFrame *kvp;
    const char *user_format = NULL;
    gchar *norm_format = NULL;
    KvpValue *value;
    gchar *error = NULL;

    if (!book)
    {
        PWARN ("No book!!!");
        return NULL;
    }

    if (!counter_name || *counter_name == '\0')
    {
        PWARN ("Invalid counter name.");
        return NULL;
    }

    /* Get the KVP from the current book */
    kvp = qof_instance_get_slots (QOF_INSTANCE (book));

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return NULL;
    }

    /* Get the format string */
    value = kvp->get_slot({"counter_formats", counter_name});
    if (value)
    {
        user_format = value->get<const char*>();
        norm_format = qof_book_normalize_counter_format(user_format, &error);
        if (!norm_format)
        {
            PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", user_format, counter_name, error);
            /* Invalid format string */
            user_format = NULL;
            g_free(error);
        }
    }

    /* If no (valid) format string was found, use the default format
     * string */
    if (!norm_format)
    {
        /* Use the default format */
        norm_format = g_strdup ("%.6" PRIi64);
    }
    return norm_format;
}
Пример #9
0
void
qof_book_set_option (QofBook *book, KvpValue *value, GSList *path)
{
    KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE (book));
    Path path_v {KVP_OPTION_PATH};
    for (auto item = path; item != nullptr; item = g_slist_next(item))
        path_v.push_back(static_cast<const char*>(item->data));
    qof_book_begin_edit (book);
    delete root->set_path(path_v, value);
    qof_instance_set_dirty (QOF_INSTANCE (book));
    qof_book_commit_edit (book);
}
Пример #10
0
xmlNodePtr
qof_instance_slots_to_dom_tree(const char *tag, const QofInstance* inst)
{
    xmlNodePtr ret;
    const char ** keys;
    unsigned int i;
    KvpFrame *frame = qof_instance_get_slots(inst);
    if (!frame)
        return nullptr;

    ret = xmlNewNode(nullptr, BAD_CAST tag);
    frame->for_each_slot(add_kvp_slot, static_cast<void*>(ret));
    return ret;
}
Пример #11
0
GHashTable *
qof_book_get_features (QofBook *book)
{
    KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
    GHashTable *features = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                  NULL, g_free);

    auto slot = frame->get_slot(GNC_FEATURES);
    if (slot != nullptr)
    {
	frame = slot->get<KvpFrame*>();
	frame->for_each_slot(&add_feature_to_hash, &features);
    }
    return features;
}
Пример #12
0
gint64
qof_book_get_counter (QofBook *book, const char *counter_name)
{
    KvpFrame *kvp;
    KvpValue *value;

    if (!book)
    {
        PWARN ("No book!!!");
        return -1;
    }

    if (!counter_name || *counter_name == '\0')
    {
        PWARN ("Invalid counter name.");
        return -1;
    }

    /* Use the KVP in the book */
    kvp = qof_instance_get_slots (QOF_INSTANCE (book));

    if (!kvp)
    {
        PWARN ("Book has no KVP_Frame");
        return -1;
    }

    value = kvp->get_slot({"counters", counter_name});
    if (value)
    {
        /* found it */
        return value->get<int64_t>();
    }
    else
    {
        /* New counter */
        return 0;
    }
}
Пример #13
0
gboolean
gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean is_infant,
                    QofInstance *inst)
{
     slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, g_string_new(NULL) };
     KvpFrame *pFrame = qof_instance_get_slots (inst);

    g_return_val_if_fail( be != NULL, FALSE );
    g_return_val_if_fail( guid != NULL, FALSE );
    g_return_val_if_fail( pFrame != NULL, FALSE );

    // If this is not saving into a new db, clear out the old saved slots first
    if ( !be->is_pristine_db && !is_infant )
    {
        (void)gnc_sql_slots_delete( be, guid );
    }

    slot_info.be = be;
    slot_info.guid = guid;
    pFrame->for_each_slot(save_slot, &slot_info);
    (void)g_string_free( slot_info.path, TRUE );

    return slot_info.is_ok;
}
Пример #14
0
void
qof_book_options_delete (QofBook *book)
{
    KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
    delete root->set_path(KVP_OPTION_PATH, nullptr);
}