r21411 - gnucash/trunk/src - Some const correctness improvements in owner and invoice functions

Geert Janssens gjanssens at code.gnucash.org
Mon Oct 10 08:34:58 EDT 2011


Author: gjanssens
Date: 2011-10-10 08:34:58 -0400 (Mon, 10 Oct 2011)
New Revision: 21411
Trac: http://svn.gnucash.org/trac/changeset/21411

Modified:
   gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.c
   gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.h
   gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/business/business-gnome/dialog-invoice.h
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
   gnucash/trunk/src/business/business-gnome/dialog-payment.h
   gnucash/trunk/src/business/business-ledger/gncEntryLedgerDisplay.c
   gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoice.h
   gnucash/trunk/src/engine/gncInvoiceP.h
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/gncOwner.h
Log:
Some const correctness improvements in owner and invoice functions

Modified: gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -56,7 +56,7 @@
 #define owner_id_string		"owner:id"
 
 xmlNodePtr
-gnc_owner_to_dom_tree (const char *tag, GncOwner *owner)
+gnc_owner_to_dom_tree (const char *tag, const GncOwner *owner)
 {
     xmlNodePtr ret;
     const char *type_str;

Modified: gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.h
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.h	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/backend/xml/gnc-owner-xml-v2.h	2011-10-10 12:34:58 UTC (rev 21411)
@@ -28,7 +28,7 @@
 
 gboolean   gnc_dom_tree_to_owner (xmlNodePtr node, GncOwner *owner,
                                   QofBook *book);
-xmlNodePtr gnc_owner_to_dom_tree (const char *tag, GncOwner *addr);
+xmlNodePtr gnc_owner_to_dom_tree (const char *tag, const GncOwner *addr);
 void gnc_owner_xml_initialize (void);
 
 #endif /* GNC_OWNER_XML_V2_H */

Modified: gnucash/trunk/src/business/business-gnome/business-gnome-utils.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/business-gnome-utils.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-gnome/business-gnome-utils.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -204,19 +204,12 @@
 gnc_invoice_select_search_set_label(GncISI* isi)
 {
     GncOwnerType owner_type;
-    GncOwner *tmp;
     char *label;
 
     g_assert(isi);
     if (!isi->label) return;
 
-    tmp = &isi->owner;
-    owner_type = gncOwnerGetType(tmp);
-    while (owner_type == GNC_OWNER_JOB)
-    {
-        tmp = gncOwnerGetEndOwner(tmp);
-        owner_type = gncOwnerGetType(tmp);
-    }
+    owner_type = gncOwnerGetType(gncOwnerGetEndOwner(&isi->owner));
 
     /* Translators:  See comments in dialog-invoice.c:gnc_invoice_search() */
     switch (owner_type)

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -1480,7 +1480,7 @@
     InvoiceWindow *iw = user_data;
     const EventInfo *info;
     GncInvoice *invoice = iw_get_invoice (iw);
-    GncOwner *owner;
+    const GncOwner *owner;
 
     /* If there isn't an invoice behind us, close down */
     if (!invoice)
@@ -1840,7 +1840,7 @@
 
 static InvoiceWindow *
 gnc_invoice_new_page (QofBook *bookp, InvoiceDialogType type,
-                      GncInvoice *invoice, GncOwner *owner,
+                      GncInvoice *invoice, const GncOwner *owner,
                       GncMainWindow *window)
 {
     InvoiceWindow *iw;
@@ -2198,13 +2198,14 @@
 }
 
 static InvoiceWindow *
-gnc_invoice_window_new_invoice (QofBook *bookp, GncOwner *owner,
+gnc_invoice_window_new_invoice (QofBook *bookp, const GncOwner *owner,
                                 GncInvoice *invoice)
 {
     InvoiceWindow *iw;
     GladeXML *xml;
     GtkWidget *hbox;
     GncOwner *billto;
+    const GncOwner *start_owner;
 
     if (invoice)
     {
@@ -2236,17 +2237,18 @@
         invoice = gncInvoiceCreate (bookp);
         gncInvoiceSetCurrency (invoice, gnc_default_currency ());
         iw->book = bookp;
+        start_owner = owner;
     }
     else
     {
         iw->dialog_type = MOD_INVOICE;
-        owner = gncInvoiceGetOwner (invoice);
+        start_owner = gncInvoiceGetOwner (invoice);
         iw->book = gncInvoiceGetBook (invoice);
     }
 
     /* Save this for later */
-    gncOwnerCopy (gncOwnerGetEndOwner(owner), &(iw->owner));
-    gncOwnerInitJob (&(iw->job), gncOwnerGetJob (owner));
+    gncOwnerCopy (gncOwnerGetEndOwner(start_owner), &(iw->owner));
+    gncOwnerInitJob (&(iw->job), gncOwnerGetJob (start_owner));
 
     billto = gncInvoiceGetBillTo (invoice);
     gncOwnerCopy (gncOwnerGetEndOwner (billto), &(iw->proj_cust));
@@ -2677,15 +2679,8 @@
      */
     if (owner)
     {
-        GncOwner *tmp = owner;
-
         /* First, figure out the type of owner here.. */
-        owner_type = gncOwnerGetType(owner);
-        while (owner_type == GNC_OWNER_JOB)
-        {
-            tmp = gncOwnerGetEndOwner(tmp);
-            owner_type = gncOwnerGetType(tmp);
-        }
+        owner_type = gncOwnerGetType (gncOwnerGetEndOwner (owner));
 
         /* Then if there's an actual owner add it to the query
          * and limit the search to this owner
@@ -2771,34 +2766,6 @@
                                      label);
 }
 
-GNCSearchWindow *
-gnc_invoice_search_select (gpointer start, gpointer book)
-{
-    GncInvoice *i = start;
-    GncOwner owner, *ownerp;
-
-    if (!book) return NULL;
-
-    if (i)
-    {
-        ownerp = gncInvoiceGetOwner (i);
-        gncOwnerCopy (ownerp, &owner);
-    }
-    else
-        gncOwnerInitCustomer (&owner, NULL); /* XXX */
-
-    return gnc_invoice_search (start, NULL, book);
-}
-
-GNCSearchWindow *
-gnc_invoice_search_edit (gpointer start, gpointer book)
-{
-    if (start)
-        gnc_ui_invoice_edit (start);
-
-    return NULL;
-}
-
 DialogQueryList *
 gnc_invoice_show_bills_due (QofBook *book, double days_in_advance)
 {

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.h	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.h	2011-10-10 12:34:58 UTC (rev 21411)
@@ -59,15 +59,6 @@
 /* Search for invoices */
 GNCSearchWindow * gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book);
 
-/*
- * These callbacks are for use with the gnc_general_search widget
- *
- * select() provides a Select Dialog and returns it.
- * edit() opens the existing invoice for editing and returns NULL.
- */
-GNCSearchWindow * gnc_invoice_search_select (gpointer start, gpointer book);
-GNCSearchWindow * gnc_invoice_search_edit (gpointer start, gpointer book);
-
 void gnc_business_call_owner_report (GncOwner *owner, Account *acc);
 
 void gnc_invoice_window_sort (InvoiceWindow *iw, invoice_sort_type_t sort_code);

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -706,7 +706,7 @@
 }
 
 PaymentWindow *
-gnc_ui_payment_new_with_invoice (GncOwner *owner, QofBook *book,
+gnc_ui_payment_new_with_invoice (const GncOwner *owner, QofBook *book,
                                  GncInvoice *invoice)
 {
     GncOwner owner_def;
@@ -715,15 +715,14 @@
     if (owner)
     {
         /* Figure out the company */
-        owner = gncOwnerGetEndOwner (owner);
+        gncOwnerCopy (gncOwnerGetEndOwner (owner), &owner_def);
     }
     else
     {
         gncOwnerInitCustomer (&owner_def, NULL);
-        owner = &owner_def;
     }
 
-    return new_payment_window (owner, book, invoice);
+    return new_payment_window (&owner_def, book, invoice);
 }
 
 PaymentWindow *

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.h	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.h	2011-10-10 12:34:58 UTC (rev 21411)
@@ -31,7 +31,7 @@
 
 /* Create a payment window */
 PaymentWindow * gnc_ui_payment_new (GncOwner *owner, QofBook *book);
-PaymentWindow * gnc_ui_payment_new_with_invoice (GncOwner *owner,
+PaymentWindow * gnc_ui_payment_new_with_invoice (const GncOwner *owner,
         QofBook *book,
         GncInvoice *invoice);
 PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn);

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedgerDisplay.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedgerDisplay.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedgerDisplay.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -141,7 +141,7 @@
     /* For expense vouchers, watch the employee and refresh if it's changed */
     if (ledger->type == GNCENTRY_EXPVOUCHER_ENTRY)
     {
-        GncOwner *owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
+        const GncOwner *owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (ledger->invoice));
         GncEmployee *employee = gncOwnerGetEmployee (owner);
 
         if (employee)

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -108,7 +108,7 @@
 static void load_payment_type_cells (GncEntryLedger *ledger)
 {
     ComboCell *cell;
-    GncOwner *owner;
+    const GncOwner *owner;
     GncEmployee *employee;
 
     cell = (ComboCell *) gnc_table_layout_get_cell (ledger->table->layout,
@@ -356,7 +356,7 @@
             /* The rest of this does not apply to expense vouchers */
             if (ledger->type != GNCENTRY_EXPVOUCHER_ENTRY)
             {
-                GncOwner *owner = gncInvoiceGetOwner (ledger->invoice);
+                const GncOwner *owner = gncInvoiceGetOwner (ledger->invoice);
                 GncTaxTable *table = NULL;
                 GncTaxIncluded taxincluded_p = GNC_TAXINCLUDED_USEGLOBAL;
                 gboolean taxincluded = FALSE;
@@ -364,8 +364,7 @@
                 GNCOptionDB *odb;
 
                 /* Determine the TaxIncluded and Discount values */
-                owner = gncOwnerGetEndOwner (owner);
-                switch (gncOwnerGetType (owner))
+                switch (gncOwnerGetType (gncOwnerGetEndOwner (owner)))
                 {
                 case GNC_OWNER_CUSTOMER:
                     taxincluded_p = gncCustomerGetTaxIncluded (owner->owner.customer);

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/engine/gncInvoice.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -696,7 +696,7 @@
     return invoice->id;
 }
 
-GncOwner * gncInvoiceGetOwner (GncInvoice *invoice)
+const GncOwner * gncInvoiceGetOwner (const GncInvoice *invoice)
 {
     if (!invoice) return NULL;
     return &invoice->owner;
@@ -776,7 +776,7 @@
     return invoice->notes;
 }
 
-GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice)
+GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice)
 {
     const GncOwner *owner;
     g_return_val_if_fail (invoice, GNC_OWNER_NONE);
@@ -877,7 +877,7 @@
 
 }
 
-GncInvoiceType gncInvoiceGetType (GncInvoice *invoice)
+GncInvoiceType gncInvoiceGetType (const GncInvoice *invoice)
 {
     if (!invoice) return GNC_INVOICE_UNDEFINED;
     switch (gncInvoiceGetOwnerType (invoice))
@@ -893,7 +893,7 @@
     }
 }
 
-const char * gncInvoiceGetTypeString (GncInvoice *invoice)
+const char * gncInvoiceGetTypeString (const GncInvoice *invoice)
 {
     GncInvoiceType type = gncInvoiceGetType(invoice);
     switch (type)
@@ -1154,7 +1154,7 @@
     return gncInvoiceLookup(book, guid);
 }
 
-gboolean gncInvoiceAmountPositive (GncInvoice *invoice)
+gboolean gncInvoiceAmountPositive (const GncInvoice *invoice)
 {
     switch (gncInvoiceGetType (invoice))
     {
@@ -1174,7 +1174,7 @@
 
 struct lotmatch
 {
-    GncOwner *owner;
+    const GncOwner *owner;
     gboolean positive_balance;
 };
 
@@ -1182,7 +1182,8 @@
 gnc_lot_match_owner_payment (GNCLot *lot, gpointer user_data)
 {
     struct lotmatch *lm = user_data;
-    GncOwner owner_def, *owner;
+    GncOwner owner_def;
+    const GncOwner *owner;
     gnc_numeric balance = gnc_lot_get_balance (lot);
 
     /* Is this a payment lot */
@@ -1217,7 +1218,7 @@
     const char *name, *type;
     char *lot_title;
     Account *ccard_acct = NULL;
-    GncOwner *owner;
+    const GncOwner *owner;
 
     if (!invoice || !acc) return NULL;
 
@@ -1964,7 +1965,7 @@
     return qof_object_register (&gncInvoiceDesc);
 }
 
-gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner)
+gchar *gncInvoiceNextID (QofBook *book, const GncOwner *owner)
 {
     gchar *nextID;
     switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))

Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/engine/gncInvoice.h	2011-10-10 12:34:58 UTC (rev 21411)
@@ -129,17 +129,17 @@
 /** @name Get Functions
  @{ */
 const char * gncInvoiceGetID (const GncInvoice *invoice);
-GncOwner * gncInvoiceGetOwner (GncInvoice *invoice);
+const GncOwner * gncInvoiceGetOwner (const GncInvoice *invoice);
 Timespec gncInvoiceGetDateOpened (const GncInvoice *invoice);
 Timespec gncInvoiceGetDatePosted (const GncInvoice *invoice);
 Timespec gncInvoiceGetDateDue (const GncInvoice *invoice);
 GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice);
 const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
 const char * gncInvoiceGetNotes (const GncInvoice *invoice);
-GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
+GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice);
 GList * gncInvoiceGetTypeListForOwnerType (const GncOwnerType type);
-GncInvoiceType gncInvoiceGetType (GncInvoice *invoice);
-const char * gncInvoiceGetTypeString (GncInvoice *invoice);
+GncInvoiceType gncInvoiceGetType (const GncInvoice *invoice);
+const char * gncInvoiceGetTypeString (const GncInvoice *invoice);
 gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);
 GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice);
 gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice);
@@ -170,7 +170,7 @@
  *  Returns TRUE if the invoice will increase the balance or FALSE
  *  otherwise.
  */
-gboolean gncInvoiceAmountPositive (GncInvoice *invoice);
+gboolean gncInvoiceAmountPositive (const GncInvoice *invoice);
 
 /** Post this invoice to an account.  Returns the new Transaction
  * that is tied to this invoice.   The transaction is set with

Modified: gnucash/trunk/src/engine/gncInvoiceP.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoiceP.h	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/engine/gncInvoiceP.h	2011-10-10 12:34:58 UTC (rev 21411)
@@ -35,7 +35,7 @@
 #include "gncOwner.h"
 
 gboolean gncInvoiceRegister (void);
-gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner);
+gchar *gncInvoiceNextID (QofBook *book, const GncOwner *owner);
 void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
 void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
 void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/engine/gncOwner.c	2011-10-10 12:34:58 UTC (rev 21411)
@@ -571,7 +571,7 @@
     return *guid_null ();
 }
 
-GncOwner * gncOwnerGetEndOwner (GncOwner *owner)
+const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner)
 {
     if (!owner) return NULL;
     switch (owner->type)
@@ -615,11 +615,10 @@
     }
 }
 
-const GncGUID * gncOwnerGetEndGUID (GncOwner *owner)
+const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner)
 {
     if (!owner) return NULL;
-    owner = gncOwnerGetEndOwner (owner);
-    return gncOwnerGetGUID (owner);
+    return gncOwnerGetGUID (gncOwnerGetEndOwner (owner));
 }
 
 void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)

Modified: gnucash/trunk/src/engine/gncOwner.h
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h	2011-10-09 21:18:08 UTC (rev 21410)
+++ gnucash/trunk/src/engine/gncOwner.h	2011-10-10 12:34:58 UTC (rev 21411)
@@ -175,8 +175,8 @@
  * Get the "parent" Owner or GncGUID thereof.  The "parent" owner
  * is the Customer or Vendor, or the Owner of a Job
  */
-GncOwner * gncOwnerGetEndOwner (GncOwner *owner);
-const GncGUID * gncOwnerGetEndGUID (GncOwner *owner);
+const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner);
+const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner);
 
 /** attach an owner to a lot */
 void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot);



More information about the gnucash-changes mailing list