GnuCash  5.6-150-g038405b370+
dialog-object-references.c
1 /********************************************************************\
2  * dialog-object-references.c -- dialog for displaying a list of *
3  * objects which refer to another *
4  * specific object *
5  * *
6  * Copyright (C) 2010 Phil Longstaff (plongstaff@rogers.com) *
7  * *
8  * This program is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License as *
10  * published by the Free Software Foundation; either version 2 of *
11  * the License, or (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License*
19  * along with this program; if not, contact: *
20  * *
21  * Free Software Foundation Voice: +1-617-542-5942 *
22  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
23  * Boston, MA 02110-1301, USA gnu@gnu.org *
24 \********************************************************************/
25 
26 #include <config.h>
27 
28 #include <gtk/gtk.h>
29 #include <glib/gi18n.h>
30 
31 #include "gnc-ui.h"
32 #include "dialog-utils.h"
34 
35 static QofLogModule log_module = GNC_MOD_GUI;
36 
37 void
38 gnc_ui_object_references_show( const gchar* explanation_text, GList* objlist )
39 {
40  GtkWidget* dialog;
41  GtkBuilder* builder;
42  GtkWidget* box;
43  GList* node;
44  GtkLabel* explanation;
45  GtkListStore* store;
46  GtkWidget* listview;
47  GtkTreeViewColumn* column;
48  GtkCellRenderer* renderer;
49 
50  ENTER("");
51 
52  /* Open the dialog */
53  builder = gtk_builder_new();
54  gnc_builder_add_from_file (builder, "dialog-object-references.glade", "object_references_dialog" );
55  dialog = GTK_WIDGET(gtk_builder_get_object (builder, "object_references_dialog" ));
56 
57  // Set the name for this dialog so it can be easily manipulated with css
58  gtk_widget_set_name (GTK_WIDGET(dialog), "gnc-id-object-reference");
59 
60  explanation = GTK_LABEL(gtk_builder_get_object (builder, "lbl_explanation" ));
61  gtk_label_set_text( explanation, explanation_text );
62 
63  /* Set up the list store */
64  store = gtk_list_store_new( 1, G_TYPE_STRING );
65  for ( node = objlist; node != NULL; node = node->next )
66  {
67  QofInstance* inst = node->data;
68  GtkTreeIter iter;
69 
70  gtk_list_store_append( store, &iter );
71  gtk_list_store_set( store, &iter, 0, qof_instance_get_display_name( inst ), -1 );
72  }
73 
74  /* Set up the list view */
75  listview = gtk_tree_view_new_with_model( GTK_TREE_MODEL(store) );
76  renderer = gtk_cell_renderer_text_new();
77  column = gtk_tree_view_column_new_with_attributes( "Object", renderer, "text", 0, NULL );
78  gtk_tree_view_append_column( GTK_TREE_VIEW(listview), column );
79 
80  box = GTK_WIDGET(gtk_builder_get_object (builder, "hbox_list" ));
81  gtk_container_add( GTK_CONTAINER(box), listview );
82 
83  /* Autoconnect signals */
84  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dialog);
85 
86  /* Run the dialog */
87  gtk_widget_show_all( dialog );
88  gtk_dialog_run( GTK_DIALOG(dialog) );
89  g_object_unref(G_OBJECT(builder));
90  g_object_unref (store);
91  gtk_widget_destroy( dialog );
92 
93  LEAVE("");
94 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
This file contains the functions to present a dialog box with a list of object references and an expl...
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
gchar * qof_instance_get_display_name(const QofInstance *inst)
Returns a displayable name for this object.