GnuCash  5.6-150-g038405b370+
dialog-choose-owner.c
1 /*
2  * dialog-choose-owner.c -- Dialog to choose an owner for a business Split
3  * Copyright (C) 2006 Derek Atkins
4  * Author: Derek Atkins <warlord@MIT.EDU>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, contact:
18  *
19  * Free Software Foundation Voice: +1-617-542-5942
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21  * Boston, MA 02110-1301, USA gnu@gnu.org
22  */
23 
24 #include <config.h>
25 
26 #include <gtk/gtk.h>
27 #include <glib/gi18n.h>
28 #include "qof.h"
29 
30 #include "Transaction.h"
31 #include "dialog-utils.h"
32 #include "gncOwner.h"
33 
34 #include "dialog-choose-owner.h"
35 #include "business-gnome-utils.h"
36 
38 {
39  GtkWidget * dialog;
40  GtkWidget * owner_choice;
41  QofBook * book;
42  GncOwner owner;
43  Split * split;
44 };
45 
46 static DialogChooseOwner *
47 gcoi_create_dialog(Split* split)
48 {
49  DialogChooseOwner* dco;
50  GtkBuilder *builder;
51  GtkWidget *widget, *box;
52 
53  g_return_val_if_fail(split, NULL);
54 
55  dco = g_new0(DialogChooseOwner, 1);
56  g_assert(dco);
57  dco->book = qof_instance_get_book(QOF_INSTANCE(split));
58  dco->split = split;
59 
60  /* Open the Glade file */
61  builder = gtk_builder_new();
62  gnc_builder_add_from_file (builder, "dialog-choose-owner.glade", "choose_owner_dialog");
63  g_assert(builder);
64 
65  /* Get the dialog handle */
66  dco->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "choose_owner_dialog"));
67  g_assert(dco->dialog);
68 
69  // Set the name for this dialog so it can be easily manipulated with css
70  gtk_widget_set_name (GTK_WIDGET(dco->dialog), "gnc-id-owner");
71 
72  /* Get the title widget and set the title */
73  widget = GTK_WIDGET(gtk_builder_get_object (builder, "title_label"));
74  if (1 == 1)
75  {
76  gncOwnerInitCustomer(&(dco->owner), NULL);
77  gtk_label_set_text(GTK_LABEL(widget),
78  _("This transaction needs to be assigned to a Customer."
79  " Please choose the Customer below."));
80  }
81  else
82  {
83  gncOwnerInitVendor(&(dco->owner), NULL);
84  gtk_label_set_text(GTK_LABEL(widget),
85  _("This transaction needs to be assigned to a Vendor."
86  " Please choose the Vendor below."));
87  }
88 
89  /* Get the transaction description and set it */
90  widget = GTK_WIDGET(gtk_builder_get_object (builder, "desc_label"));
91  gtk_label_set_text(GTK_LABEL(widget),
93 
94  /* Get the owner label and the owner box */
95  widget = GTK_WIDGET(gtk_builder_get_object (builder, "owner_label"));
96  box = GTK_WIDGET(gtk_builder_get_object (builder, "owner_box"));
97  dco->owner_choice = gnc_owner_select_create(widget, box, dco->book,
98  &(dco->owner));
99 
100  gtk_widget_show_all(dco->dialog);
101 
102  g_object_unref(G_OBJECT(builder));
103 
104  return dco;
105 }
106 
107 
108 gboolean
109 gnc_split_assign_owner(GtkWidget* window, Split* split)
110 {
111  if (1 == 0)
112  gcoi_create_dialog(split);
113 
114  return FALSE;
115 }
Business Interface: Object OWNERs.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
API for Transactions and Splits (journal entries)