Exemplo n.º 1
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*>();
}
Exemplo n.º 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*>());
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
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;
    }
}