Esempio n. 1
0
/*
 * Convert a model/owner pair into a gtk_tree_model_iter.  This
 * routine should only be called from the file
 * gnc-tree-view-owner.c.
 */
gboolean
gnc_tree_model_owner_get_iter_from_owner (GncTreeModelOwner *model,
        GncOwner *owner,
        GtkTreeIter *iter)
{
    GncTreeModelOwnerPrivate *priv;
    GList *owner_in_list;

    ENTER("model %p, owner %p, iter %p", model, owner, iter);
    gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), FALSE);
    gnc_leave_return_val_if_fail ((owner != NULL), FALSE);
    gnc_leave_return_val_if_fail ((iter != NULL), FALSE);


    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
    owner_in_list = g_list_find_custom (priv->owner_list, (gconstpointer)owner, (GCompareFunc)gncOwnerGCompareFunc);
    if (owner_in_list)
    {
        iter->stamp = model->stamp;
        iter->user_data = owner_in_list->data;
        iter->user_data2 = GINT_TO_POINTER (g_list_position (priv->owner_list, owner_in_list));
        iter->user_data3 = NULL;
        LEAVE("iter %s", iter_to_string (iter));
        return TRUE;
    }
    else
    {
        iter->stamp = 0;
        iter->user_data = NULL;
        LEAVE("Owner not found in list");
        return FALSE;
    }
}
Esempio n. 2
0
/*
 * Convert a model/owner pair into a gtk_tree_model_path.  This
 * routine should only be called from the file
 * gnc-tree-view-owner.c.
 */
GtkTreePath *
gnc_tree_model_owner_get_path_from_owner (GncTreeModelOwner *model,
        GncOwner *owner)
{
    GtkTreeIter tree_iter;
    GtkTreePath *tree_path;

    ENTER("model %p, owner %p", model, owner);
    gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), NULL);
    gnc_leave_return_val_if_fail (owner != NULL, NULL);

    if (!gnc_tree_model_owner_get_iter_from_owner (model, owner,
            &tree_iter))
    {
        LEAVE("no iter");
        return NULL;
    }

    tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &tree_iter);
    if (tree_path)
    {
        gchar *path_string = gtk_tree_path_to_string(tree_path);
        LEAVE("path (2) %s", path_string);
        g_free(path_string);
    }
    else
    {
        LEAVE("no path");
    }
    return tree_path;
}
Esempio n. 3
0
static gboolean
gnc_tree_model_owner_iter_next (GtkTreeModel *tree_model,
                                GtkTreeIter *iter)
{
    GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
    GncTreeModelOwnerPrivate *priv;
    GncOwner *owner;
    gint i;

    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), FALSE);
    g_return_val_if_fail (iter != NULL, FALSE);
    g_return_val_if_fail (iter->user_data != NULL, FALSE);
    g_return_val_if_fail (iter->stamp == model->stamp, FALSE);

    ENTER("model %p, iter %s", tree_model, iter_to_string (iter));

    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);

    /* Get the *next* sibling owner. */
    i = GPOINTER_TO_INT (iter->user_data2);
    owner = g_list_nth_data (priv->owner_list, i + 1);
    if (owner == NULL)
    {
        iter->stamp = 0;
        LEAVE("failed (3)");
        return FALSE;
    }

    iter->user_data = owner;
    iter->user_data2 = GINT_TO_POINTER (i + 1);
    iter->user_data3 = NULL;

    LEAVE("iter %s", iter_to_string(iter));
    return TRUE;
}
Esempio n. 4
0
static gboolean
gnc_tree_model_owner_iter_children (GtkTreeModel *tree_model,
                                    GtkTreeIter *iter,
                                    GtkTreeIter *parent_iter)
{
    GncTreeModelOwnerPrivate *priv;
    GncTreeModelOwner *model;

    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);
    ENTER("model %p, iter %p (to be filed in), parent %s",
          tree_model, iter, (parent_iter ? iter_to_string(parent_iter) : "(null)"));

    model = GNC_TREE_MODEL_OWNER (tree_model);
    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);

    /* Owner lists don't have children, so this function call only
     * makes sense if no parent_iter was supplied. In that case,
     * return the first owner in the list */
    if (!parent_iter)
    {
        iter->user_data = g_list_nth_data (priv->owner_list, 0);
        iter->user_data2 = GINT_TO_POINTER (0);
        iter->user_data3 = NULL;
        iter->stamp = model->stamp;
        LEAVE("iter (2) %s", iter_to_string(iter));
        return TRUE;
    }
    else
    {
        iter->stamp = 0;
        LEAVE("failed (owners don't have children)");
        return FALSE;
    }
}
Esempio n. 5
0
static int
gnc_tree_model_owner_get_n_columns (GtkTreeModel *tree_model)
{
    g_return_val_if_fail(GNC_IS_TREE_MODEL_OWNER(tree_model), -1);

    return GNC_TREE_MODEL_OWNER_NUM_COLUMNS;
}
Esempio n. 6
0
static void
gnc_tree_model_owner_dispose (GObject *object)
{
    GncTreeModelOwnerPrivate *priv;
    GncTreeModelOwner *model;

    g_return_if_fail (object != NULL);
    g_return_if_fail (GNC_IS_TREE_MODEL_OWNER (object));

    ENTER("model %p", object);

    model = GNC_TREE_MODEL_OWNER (object);
    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);

    if (priv->event_handler_id)
    {
        qof_event_unregister_handler (priv->event_handler_id);
        priv->event_handler_id = 0;
    }

    gnc_prefs_remove_cb_by_func(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
                                gnc_tree_model_owner_update_color,
                                model);

    if (G_OBJECT_CLASS (parent_class)->dispose)
        G_OBJECT_CLASS (parent_class)->dispose (object);
    LEAVE(" ");
}
Esempio n. 7
0
/*
 * Convert a model/iter pair to a gnucash owner.  This routine should
 * only be called from an owner tree view filter function.
 */
GncOwner *
gnc_tree_model_owner_get_owner (GncTreeModelOwner *model,
                                GtkTreeIter *iter)
{
    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), NULL);
    g_return_val_if_fail (iter != NULL, NULL);
    g_return_val_if_fail (iter->user_data != NULL, NULL);
    g_return_val_if_fail (iter->stamp == model->stamp, NULL);

    return (GncOwner *) iter->user_data;
}
Esempio n. 8
0
/** Tell the GncTreeModelOwner code to update the color that it will
 *  use for negative numbers.  This function will iterate over all
 *  existing models and update their setting.
 *
 *  @internal
 */
static void
gnc_tree_model_owner_update_color (gpointer gsettings, gchar *key, gpointer user_data)
{
    GncTreeModelOwnerPrivate *priv;
    GncTreeModelOwner *model;
    gboolean use_red;

    g_return_if_fail(GNC_IS_TREE_MODEL_OWNER(user_data));
    model = user_data;
    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
    use_red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
    priv->negative_color = use_red ? "red" : NULL;
}
Esempio n. 9
0
static gboolean
gnc_tree_model_owner_get_iter (GtkTreeModel *tree_model,
                               GtkTreeIter *iter,
                               GtkTreePath *path)
{
    GncTreeModelOwnerPrivate *priv;
    GncTreeModelOwner *model;
    GncOwner *owner;
    gint *indices;

    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);

    {
        gchar *path_string = gtk_tree_path_to_string(path);
        ENTER("model %p, iter %p, path %s", tree_model, iter, path_string);
        g_free(path_string);
    }

    model = GNC_TREE_MODEL_OWNER (tree_model);
    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);

    /* We keep a simple list of owners, not a tree, so only depth 1 is valid */
    if (gtk_tree_path_get_depth (path) != 1)
    {
        LEAVE("bad depth");
        return FALSE;
    }

    indices = gtk_tree_path_get_indices (path);

    owner = g_list_nth_data (priv->owner_list, indices[0]);
    if (owner == NULL)
    {
        iter->stamp = 0;
        LEAVE("bad index");
        return FALSE;
    }

    iter->stamp = model->stamp;
    iter->user_data = owner;
    iter->user_data2 = GINT_TO_POINTER (indices[0]);
    iter->user_data3 = NULL;

    LEAVE("iter %s", iter_to_string (iter));
    return TRUE;
}
Esempio n. 10
0
static GtkTreePath *
gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
                               GtkTreeIter *iter)
{
    GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
    GncTreeModelOwnerPrivate *priv;
    GncOwner *owner;
    GtkTreePath *path;
    gint i;

    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), NULL);
    g_return_val_if_fail (iter != NULL, NULL);
    g_return_val_if_fail (iter->user_data != NULL, NULL);
    g_return_val_if_fail (iter->stamp == model->stamp, NULL);

    ENTER("model %p, iter %s", model, iter_to_string(iter));

    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
    if (priv->owner_list == NULL)
    {
        LEAVE("failed (1)");
        return NULL;
    }

    owner = (GncOwner *) iter->user_data;

    path = gtk_tree_path_new ();
    i = g_list_index (priv->owner_list, owner);
    if (i == -1)
    {
        gtk_tree_path_free (path);
        LEAVE("failed (3)");
        return NULL;
    }
    gtk_tree_path_prepend_index (path, i);

    {
        gchar *path_string = gtk_tree_path_to_string(path);
        LEAVE("path (4) %s", path_string);
        g_free(path_string);
    }
    return path;
}
Esempio n. 11
0
static gboolean
gnc_tree_view_owner_filter_helper (GtkTreeModel *model,
                                   GtkTreeIter *iter,
                                   gpointer data)
{
    GncOwner *owner;
    GncTreeViewOwner *view = data;
    GncTreeViewOwnerPrivate *priv;

    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), FALSE);
    g_return_val_if_fail (iter != NULL, FALSE);

    owner = gnc_tree_model_owner_get_owner (
                GNC_TREE_MODEL_OWNER(model), iter);

    priv = GNC_TREE_VIEW_OWNER_GET_PRIVATE(view);
    if (priv->filter_fn)
        return priv->filter_fn(owner, priv->filter_data);
    else return TRUE;
}
Esempio n. 12
0
static void
gnc_tree_model_owner_finalize (GObject *object)
{
    GncTreeModelOwnerPrivate *priv;
    GncTreeModelOwner *model;

    g_return_if_fail (object != NULL);
    g_return_if_fail (GNC_IS_TREE_MODEL_OWNER (object));

    ENTER("model %p", object);

    model = GNC_TREE_MODEL_OWNER (object);
    priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);

    priv->book       = NULL;
    priv->owner_list = NULL;

    if (G_OBJECT_CLASS (parent_class)->finalize)
        G_OBJECT_CLASS(parent_class)->finalize (object);
    LEAVE(" ");
}
Esempio n. 13
0
static int
gnc_tree_model_owner_iter_n_children (GtkTreeModel *tree_model,
                                      GtkTreeIter *iter)
{
    GncTreeModelOwner *model;
    GncTreeModelOwnerPrivate *priv;

    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), -1);

    model = GNC_TREE_MODEL_OWNER (tree_model);
    priv  = GNC_TREE_MODEL_OWNER_GET_PRIVATE (model);

    /* Owner lists don't have children, so always return 0, except for
     * the special case this request comes for the special "root" iter
     * (NULL). For that exception we return the size of the ower list.
     */
    if (iter == NULL)
        return (gint) g_list_length (priv->owner_list);

    g_return_val_if_fail (
        GNC_TREE_MODEL_OWNER (tree_model)->stamp == iter->stamp, -1);

    return 0;
}
Esempio n. 14
0
static GType
gnc_tree_model_owner_get_column_type (GtkTreeModel *tree_model,
                                      int index)
{
    g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), G_TYPE_INVALID);
    g_return_val_if_fail ((index < GNC_TREE_MODEL_OWNER_NUM_COLUMNS) && (index >= 0), G_TYPE_INVALID);

    switch (index)
    {
    case GNC_TREE_MODEL_OWNER_COL_NAME:
    case GNC_TREE_MODEL_OWNER_COL_TYPE:
    case GNC_TREE_MODEL_OWNER_COL_CURRENCY:
    case GNC_TREE_MODEL_OWNER_COL_ID:
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_NAME:
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_1:
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_2:
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_3:
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_4:
    case GNC_TREE_MODEL_OWNER_COL_PHONE:
    case GNC_TREE_MODEL_OWNER_COL_FAX:
    case GNC_TREE_MODEL_OWNER_COL_EMAIL:
    case GNC_TREE_MODEL_OWNER_COL_BALANCE:
    case GNC_TREE_MODEL_OWNER_COL_BALANCE_REPORT:
    case GNC_TREE_MODEL_OWNER_COL_NOTES:

    case GNC_TREE_MODEL_OWNER_COL_COLOR_BALANCE:
        return G_TYPE_STRING;

    case GNC_TREE_MODEL_OWNER_COL_ACTIVE:
        return G_TYPE_BOOLEAN;

    default:
        g_assert_not_reached ();
        return G_TYPE_INVALID;
    }
}
Esempio n. 15
0
static void
gnc_tree_model_owner_get_value (GtkTreeModel *tree_model,
                                GtkTreeIter *iter,
                                int column,
                                GValue *value)
{
    GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
    GncOwner *owner;
    gboolean negative; /* used to set "deficit style" also known as red numbers */
    gchar *string = NULL;

    g_return_if_fail (GNC_IS_TREE_MODEL_OWNER (model));
    g_return_if_fail (iter != NULL);
    g_return_if_fail (iter->user_data != NULL);
    g_return_if_fail (iter->stamp == model->stamp);

    ENTER("model %p, iter %s, col %d", tree_model,
          iter_to_string(iter), column);

    owner = (GncOwner *) iter->user_data;

    switch (column)
    {
    case GNC_TREE_MODEL_OWNER_COL_NAME:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value, gncOwnerGetName (owner));
        break;
    case GNC_TREE_MODEL_OWNER_COL_TYPE:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value,
                            gncOwnerTypeToQofIdType (gncOwnerGetType (owner)));
        break;
    case GNC_TREE_MODEL_OWNER_COL_ID:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value, gncOwnerGetID (owner));
        break;
    case GNC_TREE_MODEL_OWNER_COL_CURRENCY:
        g_value_init (value, G_TYPE_STRING);
        g_value_set_string (value,
                            gnc_commodity_get_fullname(gncOwnerGetCurrency (owner)));
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_NAME:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetName (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_1:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr1 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_2:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr2 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_3:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr3 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_ADDRESS_4:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetAddr4 (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_PHONE:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetPhone (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_FAX:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetFax (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;
    case GNC_TREE_MODEL_OWNER_COL_EMAIL:
        g_value_init (value, G_TYPE_STRING);
        string = g_strdup (gncAddressGetEmail (gncOwnerGetAddr (owner)));
        if (string)
            g_value_take_string (value, string);
        else
            g_value_set_static_string (value, "");
        break;

    case GNC_TREE_MODEL_OWNER_COL_BALANCE:
        g_value_init (value, G_TYPE_STRING);
        string = gnc_ui_owner_get_print_balance(owner, &negative);
        g_value_take_string (value, string);
        break;

    case GNC_TREE_MODEL_OWNER_COL_BALANCE_REPORT:
        g_value_init (value, G_TYPE_STRING);
        string = gnc_ui_owner_get_print_report_balance(owner, &negative);
        g_value_take_string (value, string);
        break;
    case GNC_TREE_MODEL_OWNER_COL_COLOR_BALANCE:
        g_value_init (value, G_TYPE_STRING);
        string = gnc_ui_owner_get_print_balance(owner, &negative);
        gnc_tree_model_owner_set_color(model, negative, value);
        g_free(string);
        break;

    case GNC_TREE_MODEL_OWNER_COL_NOTES:
        g_value_init (value, G_TYPE_STRING);
        switch (gncOwnerGetType (owner))
        {
        case GNC_OWNER_NONE:
        case GNC_OWNER_UNDEFINED:
        case GNC_OWNER_EMPLOYEE:
        case GNC_OWNER_JOB:
        default:
            g_value_set_static_string (value, "");
            break;
        case GNC_OWNER_VENDOR:
            g_value_set_string (value, gncVendorGetNotes (gncOwnerGetVendor (owner)));
            break;
        case GNC_OWNER_CUSTOMER:
            g_value_set_string (value, gncCustomerGetNotes (gncOwnerGetCustomer (owner)));
            break;
        }
        break;

    case GNC_TREE_MODEL_OWNER_COL_ACTIVE:
        g_value_init (value, G_TYPE_BOOLEAN);
        g_value_set_boolean (value, gncOwnerGetActive (owner));
        break;

    default:
        g_assert_not_reached ();
    }
    LEAVE(" ");
}