mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
- register gncAddress for queries
- register gncJob for queries - add customer->address and vendor->address methods - rename gncJobSortFunc to gncJobCompare git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6685 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
a161f3714c
commit
5836537d92
@ -25,6 +25,7 @@ libgncmod_business_core_la_SOURCES = \
|
|||||||
|
|
||||||
noinst_HEADERS = \
|
noinst_HEADERS = \
|
||||||
gncAddress.h \
|
gncAddress.h \
|
||||||
|
gncAddressP.h \
|
||||||
gncBusiness.h \
|
gncBusiness.h \
|
||||||
gncBusinessP.h \
|
gncBusinessP.h \
|
||||||
gncCustomer.h \
|
gncCustomer.h \
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "gnc-module-api.h"
|
#include "gnc-module-api.h"
|
||||||
#include "gw-business-core.h"
|
#include "gw-business-core.h"
|
||||||
|
|
||||||
|
#include "gncAddressP.h"
|
||||||
#include "gncCustomerP.h"
|
#include "gncCustomerP.h"
|
||||||
#include "gncEmployeeP.h"
|
#include "gncEmployeeP.h"
|
||||||
#include "gncEntryP.h"
|
#include "gncEntryP.h"
|
||||||
@ -53,6 +54,7 @@ gnc_module_init(int refcount)
|
|||||||
if(refcount == 0)
|
if(refcount == 0)
|
||||||
{
|
{
|
||||||
/* initialize known types */
|
/* initialize known types */
|
||||||
|
gncAddressRegister ();
|
||||||
gncCustomerRegister ();
|
gncCustomerRegister ();
|
||||||
gncEmployeeRegister ();
|
gncEmployeeRegister ();
|
||||||
gncEntryRegister ();
|
gncEntryRegister ();
|
||||||
|
@ -7,9 +7,12 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <string.h> /* for strcmp */
|
|
||||||
|
#include "gnc-engine-util.h" /* safe_strcmp */
|
||||||
|
#include "QueryObject.h"
|
||||||
|
|
||||||
#include "gncAddress.h"
|
#include "gncAddress.h"
|
||||||
|
#include "gncAddressP.h"
|
||||||
|
|
||||||
struct _gncAddress {
|
struct _gncAddress {
|
||||||
GNCBook * book;
|
GNCBook * book;
|
||||||
@ -25,6 +28,8 @@ struct _gncAddress {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define _GNC_MOD_NAME GNC_ADDRESS_MODULE_NAME
|
||||||
|
|
||||||
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
#define CACHE_INSERT(str) g_cache_insert(gnc_engine_get_string_cache(), (gpointer)(str));
|
||||||
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
#define CACHE_REMOVE(str) g_cache_remove(gnc_engine_get_string_cache(), (str));
|
||||||
|
|
||||||
@ -72,7 +77,7 @@ void gncAddressDestroy (GncAddress *addr){
|
|||||||
#define SET_STR(member, str) { \
|
#define SET_STR(member, str) { \
|
||||||
char * tmp; \
|
char * tmp; \
|
||||||
\
|
\
|
||||||
if (!strcmp (member, str)) return; \
|
if (!safe_strcmp (member, str)) return; \
|
||||||
tmp = CACHE_INSERT (str); \
|
tmp = CACHE_INSERT (str); \
|
||||||
CACHE_REMOVE (member); \
|
CACHE_REMOVE (member); \
|
||||||
member = tmp; \
|
member = tmp; \
|
||||||
@ -203,3 +208,28 @@ void gncAddressClearDirty (GncAddress *addr)
|
|||||||
if (!addr) return;
|
if (!addr) return;
|
||||||
addr->dirty = FALSE;
|
addr->dirty = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gncAddressCompare (const GncAddress *a, const GncAddress *b)
|
||||||
|
{
|
||||||
|
if (!a && !b) return 0;
|
||||||
|
if (!a && b) return 1;
|
||||||
|
if (a && !b) return -1;
|
||||||
|
|
||||||
|
return safe_strcmp (a->name, b->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean gncAddressRegister (void)
|
||||||
|
{
|
||||||
|
static QueryObjectDef params[] = {
|
||||||
|
|
||||||
|
{ ADDRESS_NAME, QUERYCORE_STRING, (QueryAccess)gncAddressGetName },
|
||||||
|
{ ADDRESS_PHONE, QUERYCORE_STRING, (QueryAccess)gncAddressGetPhone },
|
||||||
|
{ ADDRESS_FAX, QUERYCORE_STRING, (QueryAccess)gncAddressGetFax },
|
||||||
|
{ ADDRESS_EMAIL, QUERYCORE_STRING, (QueryAccess)gncAddressGetEmail },
|
||||||
|
{ NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncAddressCompare, params);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include "gnc-book.h"
|
#include "gnc-book.h"
|
||||||
|
|
||||||
|
#define GNC_ADDRESS_MODULE_NAME "gncAddress"
|
||||||
|
|
||||||
struct _gncAddress;
|
struct _gncAddress;
|
||||||
typedef struct _gncAddress GncAddress;
|
typedef struct _gncAddress GncAddress;
|
||||||
|
|
||||||
@ -41,4 +43,11 @@ const char * gncAddressGetFax (const GncAddress *addr);
|
|||||||
const char * gncAddressGetEmail (const GncAddress *addr);
|
const char * gncAddressGetEmail (const GncAddress *addr);
|
||||||
gboolean gncAddressIsDirty (const GncAddress *addr);
|
gboolean gncAddressIsDirty (const GncAddress *addr);
|
||||||
|
|
||||||
|
int gncAddressCompare (const GncAddress *a, const GncAddress *b);
|
||||||
|
|
||||||
|
#define ADDRESS_NAME "name"
|
||||||
|
#define ADDRESS_PHONE "phone"
|
||||||
|
#define ADDRESS_FAX "fax"
|
||||||
|
#define ADDRESS_EMAIL "email"
|
||||||
|
|
||||||
#endif /* GNC_ADDRESS_H_ */
|
#endif /* GNC_ADDRESS_H_ */
|
||||||
|
12
src/business/business-core/gncAddressP.h
Normal file
12
src/business/business-core/gncAddressP.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* gncAddressP.h -- Business Interface: Addresses
|
||||||
|
* Copyright (C) 2001, 2002 Derek Atkins
|
||||||
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GNC_ADDRESSP_H_
|
||||||
|
#define GNC_ADDRESSP_H_
|
||||||
|
|
||||||
|
gboolean gncAddressRegister (void);
|
||||||
|
|
||||||
|
#endif /* GNC_ADDRESSP_H_ */
|
@ -184,7 +184,8 @@ void gncCustomerAddJob (GncCustomer *cust, GncJob *job)
|
|||||||
if (!job) return;
|
if (!job) return;
|
||||||
|
|
||||||
if (g_list_index(cust->jobs, job) == -1)
|
if (g_list_index(cust->jobs, job) == -1)
|
||||||
cust->jobs = g_list_insert_sorted (cust->jobs, job, gncJobSortFunc);
|
cust->jobs = g_list_insert_sorted (cust->jobs, job,
|
||||||
|
(GCompareFunc)gncJobCompare);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
|
void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job)
|
||||||
@ -404,6 +405,8 @@ gboolean gncCustomerRegister (void)
|
|||||||
{ CUSTOMER_ID, QUERYCORE_STRING, (QueryAccess)gncCustomerGetID },
|
{ CUSTOMER_ID, QUERYCORE_STRING, (QueryAccess)gncCustomerGetID },
|
||||||
{ CUSTOMER_NAME, QUERYCORE_STRING, (QueryAccess)gncCustomerGetName },
|
{ CUSTOMER_NAME, QUERYCORE_STRING, (QueryAccess)gncCustomerGetName },
|
||||||
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncCustomerGetBook },
|
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncCustomerGetBook },
|
||||||
|
{ CUSTOMER_ADDR, GNC_ADDRESS_MODULE_NAME, (QueryAccess)gncCustomerGetAddr },
|
||||||
|
{ CUSTOMER_SHIPADDR, GNC_ADDRESS_MODULE_NAME, (QueryAccess)gncCustomerGetShipAddr },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,5 +63,7 @@ int gncCustomerCompare (GncCustomer *a, GncCustomer *b);
|
|||||||
#define CUSTOMER_GUID "guid"
|
#define CUSTOMER_GUID "guid"
|
||||||
#define CUSTOMER_ID "id"
|
#define CUSTOMER_ID "id"
|
||||||
#define CUSTOMER_NAME "name"
|
#define CUSTOMER_NAME "name"
|
||||||
|
#define CUSTOMER_ADDR "addr"
|
||||||
|
#define CUSTOMER_SHIPADDR "shipaddr"
|
||||||
|
|
||||||
#endif /* GNC_CUSTOMER_H_ */
|
#endif /* GNC_CUSTOMER_H_ */
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "gnc-numeric.h"
|
#include "gnc-numeric.h"
|
||||||
#include "gnc-book-p.h"
|
#include "gnc-book-p.h"
|
||||||
#include "GNCIdP.h"
|
#include "GNCIdP.h"
|
||||||
|
#include "QueryObject.h"
|
||||||
|
|
||||||
#include "gncBusiness.h"
|
#include "gncBusiness.h"
|
||||||
#include "gncJob.h"
|
#include "gncJob.h"
|
||||||
@ -234,13 +235,12 @@ gboolean gncJobIsDirty (GncJob *job)
|
|||||||
|
|
||||||
/* Other functions */
|
/* Other functions */
|
||||||
|
|
||||||
gint gncJobSortFunc (gconstpointer a, gconstpointer b) {
|
int gncJobCompare (const GncJob * a, const GncJob *b) {
|
||||||
GncJob *ja = (GncJob *) a;
|
if (!a && !b) return 0;
|
||||||
GncJob *jb = (GncJob *) b;
|
if (!a && b) return 1;
|
||||||
|
if (a && !b) return -1;
|
||||||
|
|
||||||
if (!a || !b) return 0;
|
return (safe_strcmp(a->id, b->id));
|
||||||
|
|
||||||
return (safe_strcmp(ja->id, jb->id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -317,6 +317,18 @@ static GncObject_t gncJobDesc = {
|
|||||||
|
|
||||||
gboolean gncJobRegister (void)
|
gboolean gncJobRegister (void)
|
||||||
{
|
{
|
||||||
|
static QueryObjectDef params[] = {
|
||||||
|
{ JOB_GUID, QUERYCORE_GUID, (QueryAccess)gncJobGetGUID },
|
||||||
|
{ JOB_ID, QUERYCORE_STRING, (QueryAccess)gncJobGetID },
|
||||||
|
{ JOB_NAME, QUERYCORE_STRING, (QueryAccess)gncJobGetName },
|
||||||
|
{ JOB_REFERENCE, QUERYCORE_STRING, (QueryAccess)gncJobGetReference },
|
||||||
|
{ JOB_OWNER, GNC_OWNER_MODULE_NAME, (QueryAccess)gncJobGetOwner },
|
||||||
|
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncJobGetBook },
|
||||||
|
{ NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncJobCompare, params);
|
||||||
|
|
||||||
return gncObjectRegister (&gncJobDesc);
|
return gncObjectRegister (&gncJobDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,12 @@ gboolean gncJobIsDirty (GncJob *job);
|
|||||||
|
|
||||||
/* Other functions */
|
/* Other functions */
|
||||||
|
|
||||||
gint gncJobSortFunc (gconstpointer a, gconstpointer b);
|
int gncJobCompare (const GncJob *a, const GncJob *b);
|
||||||
|
|
||||||
|
#define JOB_GUID "guid"
|
||||||
|
#define JOB_ID "id"
|
||||||
|
#define JOB_NAME "name"
|
||||||
|
#define JOB_REFERENCE "reference"
|
||||||
|
#define JOB_OWNER "owner"
|
||||||
|
|
||||||
#endif /* GNC_JOB_H_ */
|
#endif /* GNC_JOB_H_ */
|
||||||
|
@ -143,6 +143,29 @@ GncOwner * gncOwnerGetEndOwner (GncOwner *owner)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gncOwnerCompare (const GncOwner *a, const GncOwner *b)
|
||||||
|
{
|
||||||
|
if (!a && !b) return 0;
|
||||||
|
if (!a && b) return 1;
|
||||||
|
if (a && !b) return -1;
|
||||||
|
|
||||||
|
if (a->type != b->type)
|
||||||
|
return (a->type - b->type);
|
||||||
|
|
||||||
|
switch (a->type) {
|
||||||
|
case GNC_OWNER_NONE:
|
||||||
|
case GNC_OWNER_UNDEFINED:
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
case GNC_OWNER_CUSTOMER:
|
||||||
|
return gncCustomerCompare (a->owner.customer, b->owner.customer);
|
||||||
|
case GNC_OWNER_VENDOR:
|
||||||
|
return gncVendorCompare (a->owner.vendor, b->owner.vendor);
|
||||||
|
case GNC_OWNER_JOB:
|
||||||
|
return gncJobCompare (a->owner.job, b->owner.job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const GUID * gncOwnerGetEndGUID (GncOwner *owner)
|
const GUID * gncOwnerGetEndGUID (GncOwner *owner)
|
||||||
{
|
{
|
||||||
if (!owner) return NULL;
|
if (!owner) return NULL;
|
||||||
@ -165,7 +188,7 @@ gboolean gncOwnerRegister (void)
|
|||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncCustomerCompare,params);
|
gncQueryObjectRegister (_GNC_MOD_NAME, (QuerySort)gncOwnerCompare, params);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ GncVendor * gncOwnerGetVendor (const GncOwner *owner);
|
|||||||
|
|
||||||
void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
|
void gncOwnerCopy (const GncOwner *src, GncOwner *dest);
|
||||||
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
|
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b);
|
||||||
|
int gncOwnerCompare (const GncOwner *a, const GncOwner *b);
|
||||||
|
|
||||||
const char * gncOwnerGetName (GncOwner *owner);
|
const char * gncOwnerGetName (GncOwner *owner);
|
||||||
|
|
||||||
|
@ -215,7 +215,8 @@ void gncVendorAddJob (GncVendor *vendor, GncJob *job)
|
|||||||
if (!job) return;
|
if (!job) return;
|
||||||
|
|
||||||
if (g_list_index(vendor->jobs, job) == -1)
|
if (g_list_index(vendor->jobs, job) == -1)
|
||||||
vendor->jobs = g_list_insert_sorted (vendor->jobs, job, gncJobSortFunc);
|
vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
|
||||||
|
(GCompareFunc)gncJobCompare);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
|
void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
|
||||||
@ -360,6 +361,7 @@ gboolean gncVendorRegister (void)
|
|||||||
{ VENDOR_ID, QUERYCORE_STRING, (QueryAccess)gncVendorGetID },
|
{ VENDOR_ID, QUERYCORE_STRING, (QueryAccess)gncVendorGetID },
|
||||||
{ VENDOR_NAME, QUERYCORE_STRING, (QueryAccess)gncVendorGetName },
|
{ VENDOR_NAME, QUERYCORE_STRING, (QueryAccess)gncVendorGetName },
|
||||||
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncVendorGetBook },
|
{ QUERY_PARAM_BOOK, GNC_ID_BOOK, (QueryAccess)gncVendorGetBook },
|
||||||
|
{ VENDOR_ADDR, GNC_ADDRESS_MODULE_NAME, (QueryAccess)gncVendorGetAddr },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,5 +55,6 @@ int gncVendorCompare (GncVendor *a, GncVendor *b);
|
|||||||
#define VENDOR_GUID "guid"
|
#define VENDOR_GUID "guid"
|
||||||
#define VENDOR_ID "id"
|
#define VENDOR_ID "id"
|
||||||
#define VENDOR_NAME "name"
|
#define VENDOR_NAME "name"
|
||||||
|
#define VENDOR_ADDR "addr"
|
||||||
|
|
||||||
#endif /* GNC_VENDOR_H_ */
|
#endif /* GNC_VENDOR_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user