Пример #1
0
static gint
sort_by_source (GtkTreeModel *f_model,
                GtkTreeIter *f_iter_a,
                GtkTreeIter *f_iter_b,
                gpointer user_data)
{
    GNCPrice *price_a, *price_b;
    gint result;

    if (!get_prices (f_model, f_iter_a, f_iter_b, &price_a, &price_b))
        return sort_ns_or_cm (f_model, f_iter_a, f_iter_b);

    /* sort by source first */
    result = gnc_price_get_source (price_a) < gnc_price_get_source (price_b);
    if (result != 0)
        return result;

    return default_sort (price_a, price_b);
}
static xmlNodePtr
gnc_price_to_dom_tree(const xmlChar *tag, GNCPrice *price)
{
    xmlNodePtr price_xml;
    const gchar *typestr, *sourcestr;
    xmlNodePtr tmpnode;
    gnc_commodity *commodity;
    gnc_commodity *currency;
    Timespec timesp;
    gnc_numeric value;

    if (!(tag && price)) return NULL;

    price_xml = xmlNewNode(NULL, tag);
    if (!price_xml) return NULL;

    commodity = gnc_price_get_commodity(price);
    currency = gnc_price_get_currency(price);

    if (!(commodity && currency)) return NULL;

    tmpnode = guid_to_dom_tree("price:id", gnc_price_get_guid(price));
    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;

    tmpnode = commodity_ref_to_dom_tree("price:commodity", commodity);
    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;

    tmpnode = commodity_ref_to_dom_tree("price:currency", currency);
    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;

    timesp = gnc_price_get_time(price);
    tmpnode = timespec_to_dom_tree("price:time", &timesp);
    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;

    sourcestr = gnc_price_get_source(price);
    if (sourcestr && (strlen(sourcestr) != 0))
    {
        tmpnode = text_to_dom_tree("price:source", sourcestr);
        if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
    }

    typestr = gnc_price_get_typestr(price);
    if (typestr && (strlen(typestr) != 0))
    {
        tmpnode = text_to_dom_tree("price:type", typestr);
        if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;
    }

    value = gnc_price_get_value(price);
    tmpnode = gnc_numeric_to_dom_tree("price:value", &value);
    if (!add_child_or_kill_parent(price_xml, tmpnode)) return NULL;

    return price_xml;
}
Пример #3
0
static gboolean
write_price (GNCPrice* p, gpointer data)
{
    write_objects_t* s = (write_objects_t*)data;

    g_return_val_if_fail (p != NULL, FALSE);
    g_return_val_if_fail (data != NULL, FALSE);

    if (s->is_ok && gnc_price_get_source (p) != PRICE_SOURCE_TEMP)
    {
        s->is_ok = save_price (s->be, QOF_INSTANCE (p));
    }

    return s->is_ok;
}