Skip to content

Commit

Permalink
Some const correctness improvements in owner and invoice functions
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21411 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
gjanssens committed Oct 10, 2011
1 parent e409352 commit 012ab52
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/backend/xml/gnc-owner-xml-v2.c
Expand Up @@ -56,7 +56,7 @@ const gchar *owner_version_string = "2.0.0";
#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;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/xml/gnc-owner-xml-v2.h
Expand Up @@ -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 */
9 changes: 1 addition & 8 deletions src/business/business-gnome/business-gnome-utils.c
Expand Up @@ -204,19 +204,12 @@ static void
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)
Expand Down
51 changes: 9 additions & 42 deletions src/business/business-gnome/dialog-invoice.c
Expand Up @@ -1480,7 +1480,7 @@ gnc_invoice_window_refresh_handler (GHashTable *changes, gpointer user_data)
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)
Expand Down Expand Up @@ -1840,7 +1840,7 @@ find_handler (gpointer find_data, gpointer user_data)

static InvoiceWindow *
gnc_invoice_new_page (QofBook *bookp, InvoiceDialogType type,
GncInvoice *invoice, GncOwner *owner,
GncInvoice *invoice, const GncOwner *owner,
GncMainWindow *window)
{
InvoiceWindow *iw;
Expand Down Expand Up @@ -2198,13 +2198,14 @@ gnc_invoice_create_page (InvoiceWindow *iw, gpointer page)
}

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)
{
Expand Down Expand Up @@ -2236,17 +2237,18 @@ gnc_invoice_window_new_invoice (QofBook *bookp, GncOwner *owner,
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));
Expand Down Expand Up @@ -2677,15 +2679,8 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book)
*/
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
Expand Down Expand Up @@ -2771,34 +2766,6 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book)
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)
{
Expand Down
9 changes: 0 additions & 9 deletions src/business/business-gnome/dialog-invoice.h
Expand Up @@ -59,15 +59,6 @@ InvoiceWindow * gnc_ui_invoice_duplicate (GncInvoice *invoice);
/* 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);
Expand Down
7 changes: 3 additions & 4 deletions src/business/business-gnome/dialog-payment.c
Expand Up @@ -706,7 +706,7 @@ gnc_ui_payment_window_destroy (PaymentWindow *pw)
}

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;
Expand All @@ -715,15 +715,14 @@ gnc_ui_payment_new_with_invoice (GncOwner *owner, QofBook *book,
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 *
Expand Down
2 changes: 1 addition & 1 deletion src/business/business-gnome/dialog-payment.h
Expand Up @@ -31,7 +31,7 @@ typedef struct _payment_window PaymentWindow;

/* 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);
Expand Down
2 changes: 1 addition & 1 deletion src/business/business-ledger/gncEntryLedgerDisplay.c
Expand Up @@ -141,7 +141,7 @@ gnc_entry_ledger_set_watches (GncEntryLedger *ledger, GList *entries)
/* 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)
Expand Down
7 changes: 3 additions & 4 deletions src/business/business-ledger/gncEntryLedgerLoad.c
Expand Up @@ -108,7 +108,7 @@ static void load_discount_how_cells (GncEntryLedger *ledger)
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,
Expand Down Expand Up @@ -356,16 +356,15 @@ void gnc_entry_ledger_load (GncEntryLedger *ledger, GList *entry_list)
/* 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;
gnc_numeric discount = gnc_numeric_zero ();
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);
Expand Down
19 changes: 10 additions & 9 deletions src/engine/gncInvoice.c
Expand Up @@ -696,7 +696,7 @@ const char * gncInvoiceGetID (const GncInvoice *invoice)
return invoice->id;
}

GncOwner * gncInvoiceGetOwner (GncInvoice *invoice)
const GncOwner * gncInvoiceGetOwner (const GncInvoice *invoice)
{
if (!invoice) return NULL;
return &invoice->owner;
Expand Down Expand Up @@ -776,7 +776,7 @@ const char * gncInvoiceGetNotes (const GncInvoice *invoice)
return invoice->notes;
}

GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice)
GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice)
{
const GncOwner *owner;
g_return_val_if_fail (invoice, GNC_OWNER_NONE);
Expand Down Expand Up @@ -877,7 +877,7 @@ GList * gncInvoiceGetTypeListForOwnerType (GncOwnerType type)

}

GncInvoiceType gncInvoiceGetType (GncInvoice *invoice)
GncInvoiceType gncInvoiceGetType (const GncInvoice *invoice)
{
if (!invoice) return GNC_INVOICE_UNDEFINED;
switch (gncInvoiceGetOwnerType (invoice))
Expand All @@ -893,7 +893,7 @@ GncInvoiceType gncInvoiceGetType (GncInvoice *invoice)
}
}

const char * gncInvoiceGetTypeString (GncInvoice *invoice)
const char * gncInvoiceGetTypeString (const GncInvoice *invoice)
{
GncInvoiceType type = gncInvoiceGetType(invoice);
switch (type)
Expand Down Expand Up @@ -1154,7 +1154,7 @@ gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
return gncInvoiceLookup(book, guid);
}

gboolean gncInvoiceAmountPositive (GncInvoice *invoice)
gboolean gncInvoiceAmountPositive (const GncInvoice *invoice)
{
switch (gncInvoiceGetType (invoice))
{
Expand All @@ -1174,15 +1174,16 @@ gboolean gncInvoiceAmountPositive (GncInvoice *invoice)

struct lotmatch
{
GncOwner *owner;
const GncOwner *owner;
gboolean positive_balance;
};

static gboolean
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 */
Expand Down Expand Up @@ -1217,7 +1218,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
const char *name, *type;
char *lot_title;
Account *ccard_acct = NULL;
GncOwner *owner;
const GncOwner *owner;

if (!invoice || !acc) return NULL;

Expand Down Expand Up @@ -1964,7 +1965,7 @@ gboolean gncInvoiceRegister (void)
return qof_object_register (&gncInvoiceDesc);
}

gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner)
gchar *gncInvoiceNextID (QofBook *book, const GncOwner *owner)
{
gchar *nextID;
switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
Expand Down
10 changes: 5 additions & 5 deletions src/engine/gncInvoice.h
Expand Up @@ -129,17 +129,17 @@ void gncInvoiceSortEntries (GncInvoice *invoice);
/** @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);
Expand Down Expand Up @@ -170,7 +170,7 @@ GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity* commodity);
* 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
Expand Down
2 changes: 1 addition & 1 deletion src/engine/gncInvoiceP.h
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/engine/gncOwner.c
Expand Up @@ -571,7 +571,7 @@ GncGUID gncOwnerRetGUID (GncOwner *owner)
return *guid_null ();
}

GncOwner * gncOwnerGetEndOwner (GncOwner *owner)
const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner)
{
if (!owner) return NULL;
switch (owner->type)
Expand Down Expand Up @@ -615,11 +615,10 @@ int gncOwnerCompare (const GncOwner *a, const GncOwner *b)
}
}

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)
Expand Down
4 changes: 2 additions & 2 deletions src/engine/gncOwner.h
Expand Up @@ -175,8 +175,8 @@ GncGUID gncOwnerRetGUID (GncOwner *owner);
* 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);
Expand Down

0 comments on commit 012ab52

Please sign in to comment.