コード例 #1
0
ファイル: search-param.c プロジェクト: nizarklai/gnucash-1
/* Compute the value of this parameter for this object */
gpointer
gnc_search_param_compute_value (GNCSearchParam *param, gpointer object)
{
    GNCSearchParamPrivate *priv;

    g_return_val_if_fail(param, NULL);
    g_return_val_if_fail(GNC_IS_SEARCH_PARAM(param), NULL);

    priv = GNC_SEARCH_PARAM_GET_PRIVATE(param);
    if (priv->lookup_fcn)
    {
        return ((priv->lookup_fcn)(object, priv->lookup_arg));
    }
    else
    {
        GSList *converters = gnc_search_param_get_converters (param);
        gpointer res = object;

        /* Do all the object conversions */
        for (; converters; converters = converters->next)
        {
            QofParam *qp = converters->data;
            res = (qp->param_getfcn) (res, qp);
        }

        return res;
    }
}
コード例 #2
0
ファイル: gnc-query-list.c プロジェクト: nishmu/gnucash
static void
gnc_query_list_fill(GNCQueryList *list)
{
    GNCQueryListPriv *priv;
    gchar *strings[list->num_columns + 1];
    GList *entries, *item;
    const GncGUID *guid;
    gint i;

    /* Clear all watches */
    priv = GNC_QUERY_LIST_GET_PRIVATE(list);
    gnc_gui_component_clear_watches (priv->component_id);

    /* Reverse the list now because 'append()' takes too long */
    entries = qof_query_run(list->query);

    for (item = entries; item; item = item->next)
    {
        GList *node;
        gint row;
        const QofParam *gup;
        QofParam *qp = NULL;

        for (i = 0, node = list->column_params; node; node = node->next)
        {
            GNCSearchParam *param = node->data;
            GSList *converters = gnc_search_param_get_converters (param);
            const char *type = gnc_search_param_get_param_type (param);
            gpointer res = item->data;

            /* if this is a boolean, ignore it now -- we'll use a checkmark later */
            if (!safe_strcmp (type, QOF_TYPE_BOOLEAN))
            {
                strings[i++] = g_strdup("");
                continue;
            }

            /* Do all the object conversions */
            for (; converters; converters = converters->next)
            {
                qp = converters->data;
                if (converters->next)
                {
                    res = (qp->param_getfcn)(res, qp);
                }
            }

            /* Now convert this to a text value for the row */
            if (!safe_strcmp(type, QOF_TYPE_DEBCRED) ||
                    !safe_strcmp(type, QOF_TYPE_NUMERIC))
            {
                gnc_numeric (*nfcn)(gpointer, QofParam *) =
                    (gnc_numeric(*)(gpointer, QofParam *))(qp->param_getfcn);
                gnc_numeric value = nfcn(res, qp);
                if (list->numeric_abs)
                    value = gnc_numeric_abs (value);
                strings[i++] = g_strdup(xaccPrintAmount(value, gnc_default_print_info(FALSE)));
            }
            else
                strings[i++] = qof_query_core_to_string (type, res, qp);
        }

        row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings);
        gtk_clist_set_row_data (GTK_CLIST(list), row, item->data);

        /* Free up our strings */
        for (i = 0; i < list->num_columns; i++)
        {
            if (strings[i])
                g_free (strings[i]);
        }

        /* Now update any checkmarks */
        update_booleans (list, row);

        /* and set a watcher on this item */
        gup = priv->get_guid;
        guid = (const GncGUID*)((gup->param_getfcn)(item->data, gup));
        gnc_gui_component_watch_entity (priv->component_id, guid,
                                        QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);

        list->num_entries++;
    }
}