/**************************************************************
 * custom_report_list_view_row_activated_cb
 *
 * this is the double-click signal. No need to call
 * get_custom_report_selection as the double-click implies the
 * selection.
 **************************************************************/
void
custom_report_list_view_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
        GtkTreeViewColumn *column, gpointer data)
{
    CustomReportDialog *crd = data;
    GtkTreeModel *model;
    GtkTreeIter iter;

    model = gtk_tree_view_get_model(view);

    if (gtk_tree_model_get_iter(model, &iter, path))
    {
        if (column == crd->namecol)
        {
            GncGUID *guid = guid_malloc ();
            gchar *guid_str;

            gtk_tree_model_get(model, &iter, COL_NUM, &guid, -1);
            guid_str = g_new0 (gchar, GUID_ENCODING_LENGTH+1 );
            guid_to_string_buff (guid, guid_str);

            custom_report_run_report(scm_from_utf8_string (guid_str), crd);
        }
    }
}
/********************************************************************
 * get_custom_report_selection
 *
 * this helper function is called to get the selection when the user
 * clicks on "Run" or "Delete". Includes calling a dialog when there
 * is no selection.
 *
 * const gchar* message -- the message to provide user if there is no
 * actual selection found.
 *********************************************************************/
static SCM
get_custom_report_selection(CustomReportDialog *crd,
                            const gchar* message)
{
    GtkTreeSelection *sel;
    GtkTreeModel *model;
    GtkTreeIter iter;
    GncGUID *guid = guid_malloc ();
    gchar *guid_str;

    sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(crd->reportview));

    if (gtk_tree_selection_get_selected(sel, &model, &iter))
    {
        gtk_tree_model_get(model, &iter, COL_NUM, &guid, -1);
        guid_str = g_new0 (gchar, GUID_ENCODING_LENGTH+1 );
        guid_to_string_buff (guid, guid_str);
    }
    else
    {
        /* no selection, notify user */
        gnc_error_dialog (GTK_WINDOW (crd->dialog), "%s", message);
        return SCM_EOL;

    }
    return scm_from_utf8_string (guid_str);
}
示例#3
0
文件: guid.cpp 项目: jralls/gnucash
GncGUID *
guid_copy (const GncGUID *guid)
{
    if (!guid) return nullptr;
    auto ret = guid_malloc ();
    memcpy (ret, guid, sizeof (GncGUID));
    return ret;
}
示例#4
0
/********************************************************************
 * update_report_list
 *
 * this procedure does the real work of displaying a sorted list of
 * available custom reports
 ********************************************************************/
static void
update_report_list(GtkListStore *store, CustomReportDialog *crd)
{
    SCM get_rpt_guids = scm_c_eval_string("gnc:custom-report-template-guids");
    SCM template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid");
    SCM rpt_guids;
    int i;
    GtkTreeIter iter;
    GtkTreeModel *model = GTK_TREE_MODEL (store);
    gboolean valid_iter;

    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_NAME, GTK_SORT_ASCENDING);

    crd->reportlist = scm_call_0(get_rpt_guids);
    rpt_guids = crd->reportlist;

    /* Empty current liststore */
    valid_iter = gtk_tree_model_get_iter_first (model, &iter);
    while (valid_iter)
    {
        GValue value = { 0, };
        GncGUID *row_guid;
        g_value_init ( &value, G_TYPE_POINTER);
        gtk_tree_model_get_value (model, &iter, COL_NUM, &value);
        row_guid = (GncGUID *) g_value_get_pointer (&value);
        guid_free (row_guid);
        g_value_unset (&value);
        valid_iter = gtk_tree_model_iter_next (model, &iter);
    }
    gtk_list_store_clear(store);

    if (scm_is_list(rpt_guids))
    {
        /* for all the report guids in the list, store them, with a reference,
        	 in the gtkliststore */
        for (i = 0; !scm_is_null(rpt_guids); i++)
        {
            GncGUID *guid = guid_malloc ();
            gchar *guid_str = scm_to_utf8_string (SCM_CAR(rpt_guids));
            gchar *name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name, SCM_CAR(rpt_guids), SCM_BOOL_F));

            if (string_to_guid (guid_str, guid))
            {
                gtk_list_store_append(store, &iter);
                gtk_list_store_set(store, &iter,
                                   COL_NAME, name,
                                   COL_NUM, guid,
                                   -1);
            }
            g_free (name);
            g_free (guid_str);

            rpt_guids = SCM_CDR(rpt_guids);
        }
    }
}
示例#5
0
GncGUID *
guid_copy (const GncGUID *guid)
{
    GncGUID *copy;

    g_return_val_if_fail(guid, NULL);
    copy = guid_malloc();
    *copy = *guid;
    return copy;
}
/***********************************************************
 * gnc_ui_custom_report_edit_name
 *
 * open the custom report dialog and highlight the given
 * report's name for editing.
 ***********************************************************/
void
gnc_ui_custom_report_edit_name (GncMainWindow * window, SCM scm_guid)
{
    SCM is_custom_report;
    CustomReportDialog *crd = gnc_ui_custom_report_internal (window);
    GtkTreeModel *model;
    GtkTreeIter iter;
    GncGUID *guid;
    gchar *guid_str;
    gboolean valid_iter;

    is_custom_report = scm_c_eval_string ("gnc:report-template-is-custom/template-guid?");
    if (scm_is_false (scm_call_1 (is_custom_report, scm_guid)))
        return;

    guid = guid_malloc ();
    guid_str = scm_to_utf8_string (scm_guid);
    if (!string_to_guid (guid_str, guid))
        goto cleanup;

    /* Look up the row for the requested guid */
    model = gtk_tree_view_get_model (GTK_TREE_VIEW (crd->reportview));
    valid_iter = gtk_tree_model_get_iter_first (model, &iter);

    while (valid_iter)
    {
        GValue value = { 0, };
        GncGUID *row_guid;
        gtk_tree_model_get_value (model, &iter, COL_NUM, &value);
        row_guid = (GncGUID *) g_value_get_pointer (&value);

        if (guid_equal (guid, row_guid))
        {
            /* We found the row for the requested guid
             * Now let's set the report's name cell in edit mode
             * so the user can edit the name.
             */
            GtkTreePath *path;
            GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (crd->reportview));
            gtk_tree_selection_select_iter (selection, &iter);
            path = gtk_tree_model_get_path (model, &iter);
            g_object_set(G_OBJECT(crd->namerenderer), "editable", TRUE, NULL);
            gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (crd->reportview),
                                              path, crd->namecol,
                                              crd->namerenderer, TRUE);
            break;
        }

        g_value_unset (&value);
        valid_iter = gtk_tree_model_iter_next (model, &iter);
    }

cleanup:
    guid_free (guid);
}
示例#7
0
static void
add_event (ComponentEventInfo *cei, const GncGUID *entity,
           QofEventId event_mask, gboolean or_in)
{
    GHashTable *hash;

    if (!cei || !cei->entity_events || !entity)
        return;

    hash = cei->entity_events;

    if (event_mask == 0)
    {
        gpointer key;
        gpointer value;

        if (or_in)
            return;

        if (g_hash_table_lookup_extended (hash, entity, &key, &value))
        {
            g_hash_table_remove (hash, entity);
            guid_free (key);
            g_free (value);
        }
    }
    else
    {
        EventInfo *ei;

        ei = g_hash_table_lookup (hash, entity);
        if (ei == NULL)
        {
            GncGUID *key;

            key = guid_malloc ();
            *key = *entity;

            ei = g_new (EventInfo, 1);
            ei->event_mask = 0;

            g_hash_table_insert (hash, key, ei);
        }

        if (or_in)
            ei->event_mask |= event_mask;
        else
            ei->event_mask = event_mask;
    }
}
示例#8
0
static void
dqv_build_booklist (DialogQueryView *dqv, Query *q)
{
    GList *node;

    g_return_if_fail (dqv);

    for (node = qof_query_get_books(q); node; node = node->next)
    {
        QofBook *book = node->data;
        GncGUID *guid = guid_malloc();
        *guid = *(qof_book_get_guid(book));
        dqv->books = g_list_prepend(dqv->books, guid);
    }
}