From 94d8372af6d1755546ace525938b301913ac1dd1 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Sat, 17 Nov 2001 01:17:06 +0000 Subject: [PATCH] Derek Atkins's business accounting patch. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5902 57a11ea4-9604-0410-9ed3-97b8803252fd --- configure.in | 4 + po/POTFILES.in | 2 - src/Makefile.am | 3 +- src/app-file/gnome/Makefile.am | 5 +- src/business/.cvsignore | 1 + src/business/Makefile.am | 4 + src/business/business-core/.cvsignore | 6 + src/business/business-core/Makefile.am | 70 + src/business/business-core/business-core.scm | 1 + src/business/business-core/businessmod-core.c | 72 ++ src/business/business-core/gncAddress.c | 205 +++ src/business/business-core/gncAddress.h | 44 + src/business/business-core/gncBusiness.c | 171 +++ src/business/business-core/gncBusiness.h | 64 + src/business/business-core/gncBusinessP.h | 15 + src/business/business-core/gncCustomer.c | 398 ++++++ src/business/business-core/gncCustomer.h | 61 + src/business/business-core/gncCustomerP.h | 17 + src/business/business-core/gncEmployee.c | 328 +++++ src/business/business-core/gncEmployee.h | 50 + src/business/business-core/gncEmployeeP.h | 17 + src/business/business-core/gncJob.c | 276 ++++ src/business/business-core/gncJob.h | 50 + src/business/business-core/gncJobP.h | 17 + src/business/business-core/gncVendor.c | 310 +++++ src/business/business-core/gncVendor.h | 48 + src/business/business-core/gncVendorP.h | 17 + .../business-core/gw-business-core-spec.scm | 107 ++ src/business/business-core/test/.cvsignore | 7 + src/business/business-core/test/Makefile.am | 42 + .../business-core/test/test-address.c | 77 ++ .../business-core/test/test-business.c | 195 +++ .../business-core/test/test-customer.c | 196 +++ .../business-core/test/test-employee.c | 180 +++ src/business/business-core/test/test-job.c | 191 +++ src/business/business-core/test/test-vendor.c | 175 +++ src/business/business-gnome/.cvsignore | 6 + src/business/business-gnome/Makefile.am | 92 ++ .../business-gnome/business-chooser.c | 249 ++++ .../business-gnome/business-chooser.glade | 209 +++ .../business-gnome/business-chooser.h | 35 + .../business-gnome/business-gnome.scm | 1 + .../business-gnome/businessmod-gnome.c | 54 + src/business/business-gnome/customer.glade | 1138 +++++++++++++++++ src/business/business-gnome/dialog-customer.c | 683 ++++++++++ src/business/business-gnome/dialog-customer.h | 27 + src/business/business-gnome/dialog-employee.c | 590 +++++++++ src/business/business-gnome/dialog-employee.h | 27 + .../business-gnome/dialog-job-select.c | 344 +++++ .../business-gnome/dialog-job-select.h | 18 + src/business/business-gnome/dialog-job.c | 461 +++++++ src/business/business-gnome/dialog-job.h | 22 + src/business/business-gnome/dialog-vendor.c | 580 +++++++++ src/business/business-gnome/dialog-vendor.h | 27 + src/business/business-gnome/employee.glade | 797 ++++++++++++ .../business-gnome/gnc-business-utils.c | 19 + .../business-gnome/gnc-business-utils.h | 11 + .../business-gnome/gw-business-gnome-spec.scm | 183 +++ src/business/business-gnome/job.glade | 715 +++++++++++ src/business/business-gnome/vendor.glade | 741 +++++++++++ src/gnc-module/Makefile.am | 6 +- src/gnome-utils/Makefile.am | 1 + src/gnome-utils/dialog-options.c | 6 +- src/gnome-utils/gnc-commodity-edit.c | 4 +- src/gnome-utils/gnc-commodity-edit.h | 9 +- src/gnome-utils/gnc-general-select.c | 20 +- src/gnome-utils/gnc-general-select.h | 21 +- src/gnome/dialog-price-editor.c | 6 +- src/gnome/druid-hierarchy.c | 6 +- src/import-export/binary-import/Makefile.am | 2 +- src/import-export/qif-import/Makefile.am | 5 +- src/report/report-system/Makefile.am | 4 +- src/scm/extensions.scm | 66 + src/tax/us/Makefile.am | 4 +- 74 files changed, 10578 insertions(+), 37 deletions(-) create mode 100644 src/business/.cvsignore create mode 100644 src/business/Makefile.am create mode 100644 src/business/business-core/.cvsignore create mode 100644 src/business/business-core/Makefile.am create mode 100644 src/business/business-core/business-core.scm create mode 100644 src/business/business-core/businessmod-core.c create mode 100644 src/business/business-core/gncAddress.c create mode 100644 src/business/business-core/gncAddress.h create mode 100644 src/business/business-core/gncBusiness.c create mode 100644 src/business/business-core/gncBusiness.h create mode 100644 src/business/business-core/gncBusinessP.h create mode 100644 src/business/business-core/gncCustomer.c create mode 100644 src/business/business-core/gncCustomer.h create mode 100644 src/business/business-core/gncCustomerP.h create mode 100644 src/business/business-core/gncEmployee.c create mode 100644 src/business/business-core/gncEmployee.h create mode 100644 src/business/business-core/gncEmployeeP.h create mode 100644 src/business/business-core/gncJob.c create mode 100644 src/business/business-core/gncJob.h create mode 100644 src/business/business-core/gncJobP.h create mode 100644 src/business/business-core/gncVendor.c create mode 100644 src/business/business-core/gncVendor.h create mode 100644 src/business/business-core/gncVendorP.h create mode 100644 src/business/business-core/gw-business-core-spec.scm create mode 100644 src/business/business-core/test/.cvsignore create mode 100644 src/business/business-core/test/Makefile.am create mode 100644 src/business/business-core/test/test-address.c create mode 100644 src/business/business-core/test/test-business.c create mode 100644 src/business/business-core/test/test-customer.c create mode 100644 src/business/business-core/test/test-employee.c create mode 100644 src/business/business-core/test/test-job.c create mode 100644 src/business/business-core/test/test-vendor.c create mode 100644 src/business/business-gnome/.cvsignore create mode 100644 src/business/business-gnome/Makefile.am create mode 100644 src/business/business-gnome/business-chooser.c create mode 100644 src/business/business-gnome/business-chooser.glade create mode 100644 src/business/business-gnome/business-chooser.h create mode 100644 src/business/business-gnome/business-gnome.scm create mode 100644 src/business/business-gnome/businessmod-gnome.c create mode 100644 src/business/business-gnome/customer.glade create mode 100644 src/business/business-gnome/dialog-customer.c create mode 100644 src/business/business-gnome/dialog-customer.h create mode 100644 src/business/business-gnome/dialog-employee.c create mode 100644 src/business/business-gnome/dialog-employee.h create mode 100644 src/business/business-gnome/dialog-job-select.c create mode 100644 src/business/business-gnome/dialog-job-select.h create mode 100644 src/business/business-gnome/dialog-job.c create mode 100644 src/business/business-gnome/dialog-job.h create mode 100644 src/business/business-gnome/dialog-vendor.c create mode 100644 src/business/business-gnome/dialog-vendor.h create mode 100644 src/business/business-gnome/employee.glade create mode 100644 src/business/business-gnome/gnc-business-utils.c create mode 100644 src/business/business-gnome/gnc-business-utils.h create mode 100644 src/business/business-gnome/gw-business-gnome-spec.scm create mode 100644 src/business/business-gnome/job.glade create mode 100644 src/business/business-gnome/vendor.glade diff --git a/configure.in b/configure.in index 91c6ed30a3..09144019e5 100644 --- a/configure.in +++ b/configure.in @@ -834,6 +834,10 @@ AC_OUTPUT( src/tax/us/Makefile src/tax/us/test/Makefile src/test-core/Makefile + src/business/Makefile + src/business/business-core/Makefile + src/business/business-core/test/Makefile + src/business/business-gnome/Makefile dnl # non-makefiles dnl # Please read doc/build-system before adding *anything* here diff --git a/po/POTFILES.in b/po/POTFILES.in index e831397c27..a50784299e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -158,7 +158,6 @@ src/engine/gnc-engine-util.c src/app-file/gnc-file.c src/app-file/gncmod-app-file.c src/app-file/gnome/gnc-file-history.c -src/app-file/gnome/gncmod-app-file-gnome.c src/app-file/gnome/gnc-file-dialog.c src/experimental/cgi-bin/fastcgi-hello.c src/experimental/cgi-bin/gnc-server.c @@ -232,7 +231,6 @@ src/gnome/gnucash.desktop.in src/gnome/window-main-summarybar.c src/gnome/argv-list-converters.c src/gnome/file-utils.c -src/guile/tip-of-the-day.c src/import-export/qif-import/dialog-account-picker.c src/import-export/qif-import/druid-qif-import.c src/import-export/qif-import/gncmod-qif-import.c diff --git a/src/Makefile.am b/src/Makefile.am index 6ce3298de5..b30e8fc85a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,7 @@ SUBDIRS = \ scm \ quotes \ pixmaps \ + business \ optional # Engine Makefile.am file. @@ -48,12 +49,12 @@ gnucash_LDADD = \ gnome/libgncguile.la \ gnome/libgncgnome.la \ gnome/libgncguile.la \ + ${GUILE_LIBS} \ ${GUPPI_LIBS} \ ${GNOME_LIBDIR} \ ${GNOMEUI_LIBS} \ ${GNOME_PRINT_LIBS} \ ${G_WRAP_LINK_ARGS} \ - ${GUILE_LIBS} \ ${GTKHTML_LIBS} \ ${GHTTP_LIBS} \ ${GLADE_LIBS} \ diff --git a/src/app-file/gnome/Makefile.am b/src/app-file/gnome/Makefile.am index d0af29bc87..f8b05e5750 100644 --- a/src/app-file/gnome/Makefile.am +++ b/src/app-file/gnome/Makefile.am @@ -19,8 +19,7 @@ gncinclude_HEADERS = \ gnc-file-history-gnome.h libgnc_app_file_gnome_la_LIBADD = \ + ${GUILE_LIBS} \ ${GNOMEUI_LIBS} \ ${GNOME_LIBDIR} \ - ${GLIB_LIBS} \ - ${GUILE_LIBS} - + ${GLIB_LIBS} diff --git a/src/business/.cvsignore b/src/business/.cvsignore new file mode 100644 index 0000000000..f3c7a7c5da --- /dev/null +++ b/src/business/.cvsignore @@ -0,0 +1 @@ +Makefile diff --git a/src/business/Makefile.am b/src/business/Makefile.am new file mode 100644 index 0000000000..fce4167d5d --- /dev/null +++ b/src/business/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = \ + business-core \ + business-gnome + diff --git a/src/business/business-core/.cvsignore b/src/business/business-core/.cvsignore new file mode 100644 index 0000000000..a78fbcda20 --- /dev/null +++ b/src/business/business-core/.cvsignore @@ -0,0 +1,6 @@ +.scm-links +Makefile +gw-business-core.c +gw-business-core.h +gw-business-core.html +gw-business-core.scm diff --git a/src/business/business-core/Makefile.am b/src/business/business-core/Makefile.am new file mode 100644 index 0000000000..f8502e85fe --- /dev/null +++ b/src/business/business-core/Makefile.am @@ -0,0 +1,70 @@ +SUBDIRS = . test + +pkglib_LTLIBRARIES = libgw-business-core.la libgncmod-business-core.la + +AM_CFLAGS = \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/engine \ + -I${top_srcdir}/src/gnc-module \ + ${G_WRAP_COMPILE_ARGS} \ + ${GUILE_INCS} \ + ${GLIB_CFLAGS} + +libgncmod_business_core_la_SOURCES = \ + businessmod-core.c \ + gncAddress.c \ + gncBusiness.c \ + gncCustomer.c \ + gncEmployee.c \ + gncJob.c \ + gncVendor.c + +noinst_HEADERS = \ + gncAddress.h \ + gncBusiness.h \ + gncCustomer.h \ + gncCustomerP.h \ + gncEmployee.h \ + gncEmployeeP.h \ + gncJob.h \ + gncJobP.h \ + gncVendor.h \ + gncVendorP.h + +libgncmod_business_core_la_LDFLAGS = -module + +libgncmod_business_core_la_LIBADD = \ + ${GUILE_LIBS} \ + ${GLIB_LIBS} \ + ${EFENCE_LIBS} + + # business-core-helpers.c +libgw_business_core_la_SOURCES = gw-business-core.c +libgw_business_core_la_LDFLAGS = -module ${G_WRAP_LINK_ARGS} + +gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash +gncmod_DATA = business-core.scm + +gwmoddir = ${GNC_GWRAP_LIBDIR} +gwmod_DATA = \ + gw-business-core.scm \ + gw-business-core-spec.scm + +.scm-links: + rm -f gnucash g-wrapped + ln -sf . gnucash + ln -sf . g-wrapped + touch .scm-links + +gncmod-business-core.c: gw-business-core.h + +gw-business-core.scm gw-business-core.c gw-business-core.h: .scm-links gw-business-core-spec.scm + FLAVOR=gnome guile -c \ + "(set! %load-path (cons \"${G_WRAP_MODULE_DIR}\" %load-path)) \ + (set! %load-path (cons \"${PWD}\" %load-path)) \ + (set! %load-path (cons \"../../engine\" %load-path)) \ + (primitive-load \"./gw-business-core-spec.scm\") \ + (gw:generate-module \"gw-business-core\")" + +BUILT_SOURCES = gw-business-core.scm gw-business-core.c gw-business-core.h +CLEANFILES = gw-business-core.scm gw-business-core.c gw-business-core.h gw-business-core.html diff --git a/src/business/business-core/business-core.scm b/src/business/business-core/business-core.scm new file mode 100644 index 0000000000..c278421183 --- /dev/null +++ b/src/business/business-core/business-core.scm @@ -0,0 +1 @@ +(define-module (gnucash business-core)) diff --git a/src/business/business-core/businessmod-core.c b/src/business/business-core/businessmod-core.c new file mode 100644 index 0000000000..451fa10092 --- /dev/null +++ b/src/business/business-core/businessmod-core.c @@ -0,0 +1,72 @@ +/********************************************************************* + * businessmod-core.c + * module definition/initialization for the core Business module + * + * Copyright (c) 2001 Derek Atkins + *********************************************************************/ + +#include +#include +#include + +#include "gnc-module.h" +#include "gnc-module-api.h" +#include "gw-business-core.h" + +#include "gncBusinessP.h" +#include "gncCustomerP.h" +#include "gncEmployeeP.h" +#include "gncJobP.h" +#include "gncVendorP.h" + +/* version of the gnc module system interface we require */ +int gnc_module_system_interface = 0; + +/* module versioning uses libtool semantics. */ +int gnc_module_current = 0; +int gnc_module_revision = 0; +int gnc_module_age = 0; + +char * +gnc_module_path(void) +{ + return g_strdup("gnucash/business-core"); +} + +char * +gnc_module_description(void) +{ + return g_strdup("The Gnucash business core"); +} + +int +gnc_module_init(int refcount) +{ + /* load the engine (we depend on it) */ + if(!gnc_module_load("gnucash/engine", 0)) { + return FALSE; + } + + if(refcount == 0) + { + /* initialize the business engine on the first load */ + gncBusinessInitialize (0, NULL); + + /* initialize known types */ + gncCustomerRegister (); + gncEmployeeRegister (); + gncJobRegister (); + gncVendorRegister (); + } + + gh_eval_str("(use-modules (g-wrapped gw-business-core))"); + gh_eval_str("(use-modules (gnucash business-core))"); + + return TRUE; +} + +int +gnc_module_end(int refcount) { + return TRUE; +} + diff --git a/src/business/business-core/gncAddress.c b/src/business/business-core/gncAddress.c new file mode 100644 index 0000000000..0421e4df6d --- /dev/null +++ b/src/business/business-core/gncAddress.c @@ -0,0 +1,205 @@ +/* + * gncAddress.h -- an Address object + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include +#include /* for strcmp */ + +#include "gncAddress.h" + +struct _gncAddress { + GncBusiness * business; + gboolean dirty; + char * name; + char * addr1; + char * addr2; + char * addr3; + char * addr4; + char * phone; + char * fax; + char * email; + +}; + +#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)); + +/* Create/Destroy functions */ + +GncAddress * gncAddressCreate (GncBusiness *business) +{ + GncAddress *addr; + + if (!business) return NULL; + + addr = g_new0 (GncAddress, 1); + addr->business = business; + addr->dirty = FALSE; + + addr->name = CACHE_INSERT (""); + addr->addr1 = CACHE_INSERT (""); + addr->addr2 = CACHE_INSERT (""); + addr->addr3 = CACHE_INSERT (""); + addr->addr4 = CACHE_INSERT (""); + addr->phone = CACHE_INSERT (""); + addr->fax = CACHE_INSERT (""); + addr->email = CACHE_INSERT (""); + + return addr; +} + +void gncAddressDestroy (GncAddress *addr){ + if (!addr) return; + + CACHE_REMOVE (addr->name); + CACHE_REMOVE (addr->addr1); + CACHE_REMOVE (addr->addr2); + CACHE_REMOVE (addr->addr3); + CACHE_REMOVE (addr->addr4); + CACHE_REMOVE (addr->phone); + CACHE_REMOVE (addr->fax); + CACHE_REMOVE (addr->email); + + g_free (addr); +} + +/* Set functions */ + +#define SET_STR(member, str) { \ + char * tmp; \ + \ + if (!strcmp (member, str)) return; \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } + +void gncAddressSetName (GncAddress *addr, const char *name) +{ + if (!addr) return; + if (!name) return; + SET_STR(addr->name, name); + addr->dirty = TRUE; +} + +void gncAddressSetAddr1 (GncAddress *addr, const char *addr1) +{ + if (!addr) return; + if (!addr1) return; + SET_STR(addr->addr1, addr1); + addr->dirty = TRUE; +} + +void gncAddressSetAddr2 (GncAddress *addr, const char *addr2) +{ + if (!addr) return; + if (!addr2) return; + SET_STR(addr->addr2, addr2); + addr->dirty = TRUE; +} + +void gncAddressSetAddr3 (GncAddress *addr, const char *addr3) +{ + if (!addr) return; + if (!addr3) return; + SET_STR(addr->addr3, addr3); + addr->dirty = TRUE; +} + +void gncAddressSetAddr4 (GncAddress *addr, const char *addr4) +{ + if (!addr) return; + if (!addr4) return; + SET_STR(addr->addr4, addr4); + addr->dirty = TRUE; +} + +void gncAddressSetPhone (GncAddress *addr, const char *phone) +{ + if (!addr) return; + if (!phone) return; + SET_STR(addr->phone, phone); + addr->dirty = TRUE; +} + +void gncAddressSetFax (GncAddress *addr, const char *fax) +{ + if (!addr) return; + if (!fax) return; + SET_STR(addr->fax, fax); + addr->dirty = TRUE; +} + +void gncAddressSetEmail (GncAddress *addr, const char *email) +{ + if (!addr) return; + if (!email) return; + SET_STR(addr->email, email); + addr->dirty = TRUE; +} + +/* Get Functions */ + +const char * gncAddressGetName (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->name; +} + +const char * gncAddressGetAddr1 (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->addr1; +} + +const char * gncAddressGetAddr2 (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->addr2; +} + +const char * gncAddressGetAddr3 (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->addr3; +} + +const char * gncAddressGetAddr4 (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->addr4; +} + +const char * gncAddressGetPhone (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->phone; +} + +const char * gncAddressGetFax (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->fax; +} + +const char * gncAddressGetEmail (const GncAddress *addr) +{ + if (!addr) return NULL; + return addr->email; +} + +gboolean gncAddressIsDirty (const GncAddress *addr) +{ + if (!addr) return FALSE; + return addr->dirty; +} + +void gncAddressClearDirty (GncAddress *addr) +{ + if (!addr) return; + addr->dirty = FALSE; +} diff --git a/src/business/business-core/gncAddress.h b/src/business/business-core/gncAddress.h new file mode 100644 index 0000000000..01d7eb97e1 --- /dev/null +++ b/src/business/business-core/gncAddress.h @@ -0,0 +1,44 @@ +/* + * gncAddress.h -- an Address object + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_ADDRESS_H_ +#define GNC_ADDRESS_H_ + +#include "gncBusiness.h" + +struct _gncAddress; +typedef struct _gncAddress GncAddress; + +/* Create/Destroy functions */ + +GncAddress * gncAddressCreate (GncBusiness *business); +void gncAddressDestroy (GncAddress *addr); + +/* Set functions */ + +void gncAddressSetName (GncAddress *addr, const char *name); +void gncAddressSetAddr1 (GncAddress *addr, const char *addr1); +void gncAddressSetAddr2 (GncAddress *addr, const char *addr2); +void gncAddressSetAddr3 (GncAddress *addr, const char *addr3); +void gncAddressSetAddr4 (GncAddress *addr, const char *addr4); +void gncAddressSetPhone (GncAddress *addr, const char *phone); +void gncAddressSetFax (GncAddress *addr, const char *fax); +void gncAddressSetEmail (GncAddress *addr, const char *email); +void gncAddressClearDirty (GncAddress *address); + +/* Get Functions */ + +const char * gncAddressGetName (const GncAddress *addr); +const char * gncAddressGetAddr1 (const GncAddress *addr); +const char * gncAddressGetAddr2 (const GncAddress *addr); +const char * gncAddressGetAddr3 (const GncAddress *addr); +const char * gncAddressGetAddr4 (const GncAddress *addr); +const char * gncAddressGetPhone (const GncAddress *addr); +const char * gncAddressGetFax (const GncAddress *addr); +const char * gncAddressGetEmail (const GncAddress *addr); +gboolean gncAddressIsDirty (const GncAddress *addr); + +#endif /* GNC_ADDRESS_H_ */ diff --git a/src/business/business-core/gncBusiness.c b/src/business/business-core/gncBusiness.c new file mode 100644 index 0000000000..9c351cc670 --- /dev/null +++ b/src/business/business-core/gncBusiness.c @@ -0,0 +1,171 @@ +/* + * gncBusiness.c -- the Core Business Object Registry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include +#include + +#include "messages.h" + +#include "gncBusiness.h" +#include "gncBusinessP.h" + +static gboolean business_is_initialized = FALSE; +static GList *business_modules = NULL; + +struct _gncBusiness { + GHashTable * objects; + GNCSession * session; +}; + +GncBusiness *gncBusinessCreate (GNCSession *session) +{ + GncBusiness *bus; + GList *iter; + + if (!session) return NULL; + + bus = g_new0 (GncBusiness, 1); + bus->objects = g_hash_table_new (g_str_hash, g_str_equal); + bus->session = session; + + /* Populate the objects hash table with hash tables for + * each of the business objects. + */ + for (iter = business_modules; iter; iter = iter->next) { + const GncBusinessObject *obj = iter->data; + g_hash_table_insert (bus->objects, (gpointer)obj->name, + guid_hash_table_new ()); + } + + return bus; +} + +void gncBusinessDestroy (GncBusiness *bus) +{ + if (!bus) return; + + /* XXX: destroy the objects under us... */ + g_hash_table_destroy (bus->objects); + g_free (bus); +} + +GNCSession * gncBusinessGetSession (const GncBusiness *bus) +{ + if (!bus) return NULL; + + return bus->session; +} + +gpointer +gncBusinessLookupGUID (GncBusiness *business, const char *type_name, + const GUID * guid) +{ + GHashTable *table; + + if (!business || !type_name || !guid) return NULL; + + table = gncBusinessEntityTable (business, type_name); + if (!table) return NULL; + + return g_hash_table_lookup (table, guid); +} + +GList * +gncBusinessGetList (GncBusiness *business, const char *type_name, + gboolean show_all) +{ + const GncBusinessObject *obj; + + if (!business || !type_name) return NULL; + + obj = gncBusinessLookup (type_name); + if (!obj) return NULL; + + if (obj->get_list) + return ((*(obj->get_list))(business, show_all)); + + return NULL; +} + +const char * +gncBusinessPrintable (GncBusiness *business, const char *type_name, + gpointer obj) +{ + const GncBusinessObject *b_obj; + + if (!business || !type_name || !obj) return NULL; + + b_obj = gncBusinessLookup (type_name); + if (!b_obj) return NULL; + + if (b_obj->printable) + return ((*(b_obj->printable))(obj)); + + return NULL; +} + +const char * gncBusinessGetTypeLabel (const char *type_name) +{ + const GncBusinessObject *obj; + + if (!type_name) return NULL; + + obj = gncBusinessLookup (type_name); + if (!obj) return NULL; + + return _(obj->type_label); +} + +/* INITIALIZATION and PRIVATE FUNCTIONS */ + +void +gncBusinessInitialize (int argc, char **argv) +{ + if (business_is_initialized) return; + business_is_initialized = TRUE; +} + +/* Register new types of business objects. + * Return TRUE if successful, + * return FALSE if it fails, invalid arguments, or if the object + * already exists + */ +gboolean gncBusinessRegister (const GncBusinessObject *object) +{ + if (!object) return FALSE; + if (object->version != GNC_BUSINESS_VERSION) return FALSE; + if (!business_is_initialized) return FALSE; + + if (g_list_index (business_modules, (gpointer)object) == -1) + business_modules = g_list_append (business_modules, (gpointer)object); + else + return FALSE; + + return TRUE; +} + +const GncBusinessObject * gncBusinessLookup (const char *name) +{ + GList *iter; + const GncBusinessObject *obj; + + if (!name) return NULL; + + for (iter = business_modules; iter; iter = iter->next) { + obj = iter->data; + if (!strcmp (obj->name, name)) + return obj; + } + return NULL; +} + +GHashTable * gncBusinessEntityTable (GncBusiness *bus, const char *name) +{ + if (!bus || !name) return NULL; + return (g_hash_table_lookup (bus->objects, name)); +} diff --git a/src/business/business-core/gncBusiness.h b/src/business/business-core/gncBusiness.h new file mode 100644 index 0000000000..74654483cf --- /dev/null +++ b/src/business/business-core/gncBusiness.h @@ -0,0 +1,64 @@ +/* + * gncBusiness.h -- the Core Business Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_BUSINESS_H_ +#define GNC_BUSINESS_H_ + +#include "gnc-session.h" + +/* Defines the version of the core business object registration + * interface. Only business modules compiled against this version + * of the interface will load properly + */ +#define GNC_BUSINESS_VERSION 1 + +typedef struct _gncBusinessObject GncBusinessObject; +typedef struct _gncBusiness GncBusiness; + +/* This is the Business Object descriptor */ +struct _gncBusinessObject { + gint version; + const char * name; + const char * type_label; + void (*destroy)(GncBusiness *); + GList * (*get_list)(GncBusiness *, gboolean show_all); + const char * (*printable)(gpointer obj); +}; + +/* Create and Destroy the Gnc Business subsystem state */ +GncBusiness *gncBusinessCreate (GNCSession *session); +void gncBusinessDestroy (GncBusiness *business); + +/* Return the GNC Session from the Business Object */ +GNCSession * gncBusinessGetSession (const GncBusiness *bus); + +/* Obtain an object from the type and GUID */ +gpointer gncBusinessLookupGUID (GncBusiness *business, const char *type_name, + const GUID * guid); + +GList * gncBusinessGetList (GncBusiness *business, const char *type_name, + gboolean show_all); + +const char * gncBusinessPrintable (GncBusiness *business, + const char *type_name, + gpointer obj); + +/* Grab the entity table for an object */ +GHashTable * gncBusinessEntityTable (GncBusiness *business, const char *name); + +/* REGISTRATION AND REG-LOOKUP FUNCTIONS */ + +/* Register new types of business objects */ +gboolean gncBusinessRegister (const GncBusinessObject *object); + +/* Get the printable label for a type */ +const char * gncBusinessGetTypeLabel (const char *type_name); + +/* Lookup a business object */ +const GncBusinessObject * gncBusinessLookup (const char *name); + + +#endif /* GNC_BUSINESS_H_ */ diff --git a/src/business/business-core/gncBusinessP.h b/src/business/business-core/gncBusinessP.h new file mode 100644 index 0000000000..c92c933642 --- /dev/null +++ b/src/business/business-core/gncBusinessP.h @@ -0,0 +1,15 @@ +/* + * gncBusinessP.h -- the Core Business Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_BUSINESSP_H_ +#define GNC_BUSINESSP_H_ + +#include "gncBusiness.h" + +/* Initialize the business subsystem */ +void gncBusinessInitialize (int argc, char **argv); + +#endif /* GNC_BUSINESSP_H_ */ diff --git a/src/business/business-core/gncCustomer.c b/src/business/business-core/gncCustomer.c new file mode 100644 index 0000000000..d2998acbb6 --- /dev/null +++ b/src/business/business-core/gncCustomer.c @@ -0,0 +1,398 @@ +/* + * gncCustomer.c -- the Core Customer Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include +#include + +#include "messages.h" + +#include "gnc-numeric.h" +#include "gncCustomer.h" +#include "gncCustomerP.h" +#include "gncAddress.h" +#include "gncBusiness.h" + +struct _gncCustomer { + GncBusiness * business; + GUID guid; + char * id; + char * name; + char * notes; + GncAddress * addr; + GncAddress * shipaddr; + gnc_numeric discount; + gnc_numeric credit; + gint terms; + gboolean taxincluded; + gboolean active; + GList * jobs; + gboolean dirty; +}; + +#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)); + +static void gncCustomerAdd (GncCustomer *cust); +static void gncCustomerRemove (GncCustomer *cust); + +/* Create/Destroy Functions */ + +GncCustomer *gncCustomerCreate (GncBusiness *business) +{ + GncCustomer *cust; + + if (!business) return NULL; + + cust = g_new0 (GncCustomer, 1); + cust->business = business; + cust->dirty = FALSE; + cust->id = CACHE_INSERT (""); + cust->name = CACHE_INSERT (""); + cust->notes = CACHE_INSERT (""); + cust->addr = gncAddressCreate (business); + cust->shipaddr = gncAddressCreate (business); + cust->discount = gnc_numeric_zero(); + cust->credit = gnc_numeric_zero(); + cust->terms = 30; + cust->taxincluded = FALSE; + cust->active = TRUE; + cust->jobs = NULL; + + guid_new (&cust->guid); + + gncCustomerAdd (cust); + + return cust; +} + +void gncCustomerDestroy (GncCustomer *cust) +{ + if (!cust) return; + + CACHE_REMOVE (cust->id); + CACHE_REMOVE (cust->name); + CACHE_REMOVE (cust->notes); + gncAddressDestroy (cust->addr); + gncAddressDestroy (cust->shipaddr); + g_list_free (cust->jobs); + + gncCustomerRemove (cust); + + g_free (cust); +} + +/* Set Functions */ + +#define SET_STR(member, str) { \ + char * tmp; \ + \ + if (!strcmp (member, str)) return; \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } + +void gncCustomerSetID (GncCustomer *cust, const char *id) +{ + if (!cust) return; + if (!id) return; + SET_STR(cust->id, id); + cust->dirty = TRUE; +} + +void gncCustomerSetName (GncCustomer *cust, const char *name) +{ + if (!cust) return; + if (!name) return; + SET_STR(cust->name, name); + cust->dirty = TRUE; +} + +void gncCustomerSetNotes (GncCustomer *cust, const char *notes) +{ + if (!cust) return; + if (!notes) return; + SET_STR(cust->notes, notes); + cust->dirty = TRUE; +} + +void gncCustomerSetGUID (GncCustomer *cust, const GUID *guid) +{ + if (!cust || !guid) return; + if (guid_equal (guid, &cust->guid)) return; + gncCustomerRemove (cust); + cust->guid = *guid; + gncCustomerAdd (cust); +} + +void gncCustomerSetTerms (GncCustomer *cust, gint terms) +{ + if (!cust) return; + if (terms == cust->terms) return; + cust->terms = terms; + cust->dirty = TRUE; +} + +void gncCustomerSetTaxIncluded (GncCustomer *cust, gboolean taxincl) +{ + if (!cust) return; + if (taxincl == cust->taxincluded) return; + cust->taxincluded = taxincl; + cust->dirty = TRUE; +} + +void gncCustomerSetActive (GncCustomer *cust, gboolean active) +{ + if (!cust) return; + if (active == cust->active) return; + cust->active = active; + cust->dirty = TRUE; +} + +void gncCustomerSetDiscount (GncCustomer *cust, gnc_numeric discount) +{ + if (!cust) return; + if (gnc_numeric_equal (discount, cust->discount)) return; + cust->discount = discount; + cust->dirty = TRUE; +} + +void gncCustomerSetCredit (GncCustomer *cust, gnc_numeric credit) +{ + if (!cust) return; + if (gnc_numeric_equal (credit, cust->credit)) return; + cust->credit = credit; + cust->dirty = TRUE; +} + +/* Note that JobList changes do not affect the "dirtiness" of the customer */ +void gncCustomerAddJob (GncCustomer *cust, GncJob *job) +{ + if (!cust) return; + if (!job) return; + + if (g_list_index(cust->jobs, job) == -1) + cust->jobs = g_list_insert_sorted (cust->jobs, job, gncJobSortFunc); +} + +void gncCustomerRemoveJob (GncCustomer *cust, GncJob *job) +{ + GList *node; + + if (!cust) return; + if (!job) return; + + node = g_list_find (cust->jobs, job); + if (!node) { + /* PERR ("split not in account"); */ + } else { + cust->jobs = g_list_remove_link (cust->jobs, node); + g_list_free_1 (node); + } +} + +void gncCustomerCommitEdit (GncCustomer *cust) +{ + /* XXX COMMIT TO DATABASE */ + cust->dirty = FALSE; +} + +/* Get Functions */ + +GncBusiness * gncCustomerGetBusiness (GncCustomer *cust) +{ + if (!cust) return NULL; + return cust->business; +} + +const GUID * gncCustomerGetGUID (GncCustomer *cust) +{ + if (!cust) return NULL; + return &cust->guid; +} + +const char * gncCustomerGetID (GncCustomer *cust) +{ + if (!cust) return NULL; + return cust->id; +} + +const char * gncCustomerGetName (GncCustomer *cust) +{ + if (!cust) return NULL; + return cust->name; +} + +GncAddress * gncCustomerGetAddr (GncCustomer *cust) +{ + if (!cust) return NULL; + return cust->addr; +} + +GncAddress * gncCustomerGetShipAddr (GncCustomer *cust) +{ + if (!cust) return NULL; + return cust->shipaddr; +} + +const char * gncCustomerGetNotes (GncCustomer *cust) +{ + if (!cust) return NULL; + return cust->notes; +} + +gint gncCustomerGetTerms (GncCustomer *cust) +{ + if (!cust) return 0; + return cust->terms; +} + +gboolean gncCustomerGetTaxIncluded (GncCustomer *cust) +{ + if (!cust) return FALSE; + return cust->taxincluded; +} + +gboolean gncCustomerGetActive (GncCustomer *cust) +{ + if (!cust) return FALSE; + return cust->active; +} + +gnc_numeric gncCustomerGetDiscount (GncCustomer *cust) +{ + if (!cust) return gnc_numeric_zero(); + return cust->discount; +} + +gnc_numeric gncCustomerGetCredit (GncCustomer *cust) +{ + if (!cust) return gnc_numeric_zero(); + return cust->credit; +} + +GList * gncCustomerGetJoblist (GncCustomer *cust, gboolean show_all) +{ + if (!cust) return NULL; + + if (show_all) { + return (g_list_copy (cust->jobs)); + } else { + GList *list = NULL, *iterator; + for (iterator = cust->jobs; iterator; iterator=iterator->next) { + GncJob *j = iterator->data; + if (gncJobGetActive (j)) + list = g_list_append (list, j); + } + return list; + } +} + +gboolean gncCustomerIsDirty (GncCustomer *cust) +{ + if (!cust) return FALSE; + return (cust->dirty || + gncAddressIsDirty (cust->addr) || + gncAddressIsDirty (cust->shipaddr)); +} + +/* Other functions */ + +static gint gncCustomerSortFunc (gconstpointer a, gconstpointer b) { + GncCustomer *ca = (GncCustomer *) a; + GncCustomer *cb = (GncCustomer *) b; + return(strcmp(ca->name, cb->name)); +} + +/* Package-Private functions */ + +static void gncCustomerAdd (GncCustomer *cust) +{ + GHashTable *ht = gncBusinessEntityTable (cust->business, + GNC_CUSTOMER_MODULE_NAME); + if (ht) + g_hash_table_insert (ht, &cust->guid, cust); +} + +static void gncCustomerRemove (GncCustomer *cust) +{ + GHashTable *ht = gncBusinessEntityTable (cust->business, + GNC_CUSTOMER_MODULE_NAME); + if (ht) + g_hash_table_remove (ht, &cust->guid); +} + +struct _iterate { + GList *list; + gboolean show_all; +}; + +static void get_list (gpointer key, gpointer item, gpointer arg) +{ + struct _iterate *iter = arg; + GncCustomer *cust = item; + + if (iter->show_all || gncCustomerGetActive (cust)) { + iter->list = g_list_insert_sorted (iter->list, cust, gncCustomerSortFunc); + } +} + +static GList * _gncCustomerGetList (GncBusiness *bus, gboolean show_all) +{ + GHashTable *ht; + struct _iterate iter; + + if (!bus) return NULL; + + iter.list = NULL; + iter.show_all = show_all; + + ht = gncBusinessEntityTable (bus, GNC_CUSTOMER_MODULE_NAME); + if (ht) + g_hash_table_foreach (ht, get_list, &iter); + + return iter.list; +} + +static const char * _gncCustomerPrintable (gpointer item) +{ + GncCustomer *c; + + if (!item) return NULL; + + c = item; + return c->name; +} + +static void _gncCustomerDestroy (GncBusiness *bus) +{ + if (!bus) return; + + /* XXX: should we be sure to destroy all the customer objects? */ +} + +static GncBusinessObject gncCustomerDesc = { + GNC_BUSINESS_VERSION, + GNC_CUSTOMER_MODULE_NAME, + "Customer", + _gncCustomerDestroy, + _gncCustomerGetList, + _gncCustomerPrintable +}; + +gboolean gncCustomerRegister (void) +{ + return gncBusinessRegister (&gncCustomerDesc); +} + +static gint lastCustomer = 27; + +gint gncCustomerNextID (GncBusiness *business) +{ + return ++lastCustomer; /* XXX: Look into Database! */ +} diff --git a/src/business/business-core/gncCustomer.h b/src/business/business-core/gncCustomer.h new file mode 100644 index 0000000000..d2d6e63b97 --- /dev/null +++ b/src/business/business-core/gncCustomer.h @@ -0,0 +1,61 @@ +/* + * gncCustomer.h -- the Core Customer Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_CUSTOMER_H_ +#define GNC_CUSTOMER_H_ + +struct _gncCustomer; +typedef struct _gncCustomer GncCustomer; + +#include "gncBusiness.h" +#include "gncAddress.h" +#include "gncJob.h" + +#include "gnc-numeric.h" + +#define GNC_CUSTOMER_MODULE_NAME "gncCustomer" + +/* Create/Destroy Functions */ + +GncCustomer *gncCustomerCreate (GncBusiness *business); +void gncCustomerDestroy (GncCustomer *customer); + +/* Set Functions */ + +void gncCustomerSetID (GncCustomer *customer, const char *id); +void gncCustomerSetName (GncCustomer *customer, const char *name); +void gncCustomerSetNotes (GncCustomer *customer, const char *notes); +void gncCustomerSetTerms (GncCustomer *customer, gint terms); +void gncCustomerSetTaxIncluded (GncCustomer *customer, gboolean taxincl); +void gncCustomerSetActive (GncCustomer *customer, gboolean active); +void gncCustomerSetDiscount (GncCustomer *customer, gnc_numeric discount); +void gncCustomerSetCredit (GncCustomer *customer, gnc_numeric credit); + +void gncCustomerAddJob (GncCustomer *customer, GncJob *job); +void gncCustomerRemoveJob (GncCustomer *customer, GncJob *job); + +void gncCustomerCommitEdit (GncCustomer *customer); + +/* Get Functions */ + +GncBusiness * gncCustomerGetBusiness (GncCustomer *business); +const GUID * gncCustomerGetGUID (GncCustomer *customer); +const char * gncCustomerGetID (GncCustomer *customer); +const char * gncCustomerGetName (GncCustomer *customer); +GncAddress * gncCustomerGetAddr (GncCustomer *customer); +GncAddress * gncCustomerGetShipAddr (GncCustomer *customer); +const char * gncCustomerGetNotes (GncCustomer *customer); +gint gncCustomerGetTerms (GncCustomer *customer); +gboolean gncCustomerGetTaxIncluded (GncCustomer *customer); +gboolean gncCustomerGetActive (GncCustomer *customer); +gnc_numeric gncCustomerGetDiscount (GncCustomer *customer); +gnc_numeric gncCustomerGetCredit (GncCustomer *customer); + +GList * gncCustomerGetJoblist (GncCustomer *customer, gboolean show_all); + +gboolean gncCustomerIsDirty (GncCustomer *customer); + +#endif /* GNC_CUSTOMER_H_ */ diff --git a/src/business/business-core/gncCustomerP.h b/src/business/business-core/gncCustomerP.h new file mode 100644 index 0000000000..c5991fd5b6 --- /dev/null +++ b/src/business/business-core/gncCustomerP.h @@ -0,0 +1,17 @@ +/* + * gncCustomerP.h -- the Core Customer Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_CUSTOMERP_H_ +#define GNC_CUSTOMERP_H_ + +#include "gncBusiness.h" +#include "gncCustomer.h" + +gboolean gncCustomerRegister (void); +gint gncCustomerNextID (GncBusiness *business); +void gncCustomerSetGUID (GncCustomer *customer, const GUID *guid); + +#endif /* GNC_CUSTOMERP_H_ */ diff --git a/src/business/business-core/gncEmployee.c b/src/business/business-core/gncEmployee.c new file mode 100644 index 0000000000..254528a617 --- /dev/null +++ b/src/business/business-core/gncEmployee.c @@ -0,0 +1,328 @@ +/* + * gncEmployee.c -- the Core Employee Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include +#include + +#include "guid.h" +#include "messages.h" + +#include "gncEmployee.h" +#include "gncEmployeeP.h" +#include "gncAddress.h" +#include "gncBusiness.h" + +struct _gncEmployee { + GncBusiness * business; + GUID guid; + char * id; + char * username; + char * language; + char * acl; + GncAddress * addr; + gnc_numeric workday; + gnc_numeric rate; + gboolean active; + gboolean dirty; +}; + +#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)); + +static void gncEmployeeAdd (GncEmployee *employee); +static void gncEmployeeRemove (GncEmployee *employee); + +/* Create/Destroy Functions */ + +GncEmployee *gncEmployeeCreate (GncBusiness *business) +{ + GncEmployee *employee; + + if (!business) return NULL; + + employee = g_new0 (GncEmployee, 1); + employee->business = business; + employee->dirty = FALSE; + + employee->id = CACHE_INSERT (""); + employee->username = CACHE_INSERT (""); + employee->language = CACHE_INSERT (""); + employee->acl = CACHE_INSERT (""); + employee->addr = gncAddressCreate (business); + employee->workday = gnc_numeric_zero(); + employee->rate = gnc_numeric_zero(); + employee->active = TRUE; + + guid_new (&employee->guid); + + gncEmployeeAdd (employee); + + return employee; +} + +void gncEmployeeDestroy (GncEmployee *employee) +{ + if (!employee) return; + + CACHE_REMOVE (employee->id); + CACHE_REMOVE (employee->username); + CACHE_REMOVE (employee->language); + CACHE_REMOVE (employee->acl); + gncAddressDestroy (employee->addr); + + gncEmployeeRemove (employee); + + g_free (employee); +} + +/* Set Functions */ + +#define SET_STR(member, str) { \ + char * tmp; \ + \ + if (!strcmp (member, str)) return; \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } + +void gncEmployeeSetID (GncEmployee *employee, const char *id) +{ + if (!employee) return; + if (!id) return; + SET_STR(employee->id, id); + employee->dirty = TRUE; +} + +void gncEmployeeSetUsername (GncEmployee *employee, const char *username) +{ + if (!employee) return; + if (!username) return; + SET_STR(employee->username, username); + employee->dirty = TRUE; +} + +void gncEmployeeSetLanguage (GncEmployee *employee, const char *language) +{ + if (!employee) return; + if (!language) return; + SET_STR(employee->language, language); + employee->dirty = TRUE; +} + +void gncEmployeeSetGUID (GncEmployee *employee, const GUID *guid) +{ + if (!employee || !guid) return; + if (guid_equal (guid, &employee->guid)) return; + gncEmployeeRemove (employee); + employee->guid = *guid; + gncEmployeeAdd (employee); +} + +void gncEmployeeSetAcl (GncEmployee *employee, const char *acl) +{ + if (!employee) return; + if (!acl) return; + SET_STR(employee->acl, acl); + employee->dirty = TRUE; +} + +void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday) +{ + if (!employee) return; + if (gnc_numeric_equal (workday, employee->workday)) return; + employee->workday = workday; + employee->dirty = TRUE; +} + +void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate) +{ + if (!employee) return; + if (gnc_numeric_equal (rate, employee->rate)) return; + employee->rate = rate; + employee->dirty = TRUE; +} + +void gncEmployeeSetActive (GncEmployee *employee, gboolean active) +{ + if (!employee) return; + if (active == employee->active) return; + employee->active = active; + employee->dirty = TRUE; +} + +/* Get Functions */ + +GncBusiness * gncEmployeeGetBusiness (GncEmployee *employee) +{ + if (!employee) return NULL; + return employee->business; +} + +const GUID * gncEmployeeGetGUID (GncEmployee *employee) +{ + if (!employee) return NULL; + return &employee->guid; +} + +const char * gncEmployeeGetID (GncEmployee *employee) +{ + if (!employee) return NULL; + return employee->id; +} + +const char * gncEmployeeGetUsername (GncEmployee *employee) +{ + if (!employee) return NULL; + return employee->username; +} + +GncAddress * gncEmployeeGetAddr (GncEmployee *employee) +{ + if (!employee) return NULL; + return employee->addr; +} + +const char * gncEmployeeGetLanguage (GncEmployee *employee) +{ + if (!employee) return NULL; + return employee->language; +} + +const char * gncEmployeeGetAcl (GncEmployee *employee) +{ + if (!employee) return NULL; + return employee->acl; +} + +gnc_numeric gncEmployeeGetWorkday (GncEmployee *employee) +{ + if (!employee) return gnc_numeric_zero(); + return employee->workday; +} + +gnc_numeric gncEmployeeGetRate (GncEmployee *employee) +{ + if (!employee) return gnc_numeric_zero(); + return employee->rate; +} + +gboolean gncEmployeeGetActive (GncEmployee *employee) +{ + if (!employee) return FALSE; + return employee->active; +} + +gboolean gncEmployeeIsDirty (GncEmployee *employee) +{ + if (!employee) return FALSE; + return (employee->dirty || gncAddressIsDirty (employee->addr)); +} + +void gncEmployeeCommitEdit (GncEmployee *employee) +{ + + /* XXX COMMIT TO DATABASE */ + employee->dirty = FALSE; +} + +/* Other functions */ + +static gint gncEmployeeSortFunc (gconstpointer a, gconstpointer b) { + GncEmployee *ea = (GncEmployee *) a; + GncEmployee *eb = (GncEmployee *) b; + return(strcmp(ea->username, eb->username)); +} + +/* Package-Private functions */ + +static void gncEmployeeAdd (GncEmployee *employee) +{ + GHashTable *ht = gncBusinessEntityTable (employee->business, + GNC_EMPLOYEE_MODULE_NAME); + if (ht) + g_hash_table_insert (ht, &employee->guid, employee); +} + +static void gncEmployeeRemove (GncEmployee *employee) +{ + GHashTable *ht = gncBusinessEntityTable (employee->business, + GNC_EMPLOYEE_MODULE_NAME); + if (ht) + g_hash_table_remove (ht, &employee->guid); +} + +struct _iterate { + GList *list; + gboolean show_all; +}; + +static void get_list (gpointer key, gpointer item, gpointer arg) +{ + struct _iterate *iter = arg; + GncEmployee *employee = item; + + if (iter->show_all || gncEmployeeGetActive (employee)) { + iter->list = g_list_insert_sorted (iter->list, employee, gncEmployeeSortFunc); + } +} + +static GList * _gncEmployeeGetList (GncBusiness *bus, gboolean show_all) +{ + GHashTable *ht; + struct _iterate iter; + + if (!bus) return NULL; + + iter.list = NULL; + iter.show_all = show_all; + + ht = gncBusinessEntityTable (bus, GNC_EMPLOYEE_MODULE_NAME); + if (ht) + g_hash_table_foreach (ht, get_list, &iter); + + return iter.list; +} + +static const char * _gncEmployeePrintable (gpointer item) +{ + GncEmployee *v; + + if (!item) return NULL; + + v = item; + return v->username; +} + +static void _gncEmployeeDestroy (GncBusiness *bus) +{ + if (!bus) return; + + /* XXX: should we be sure to destroy all the employee objects? */ +} + +static GncBusinessObject gncEmployeeDesc = { + GNC_BUSINESS_VERSION, + GNC_EMPLOYEE_MODULE_NAME, + "Employee", + _gncEmployeeDestroy, + _gncEmployeeGetList, + _gncEmployeePrintable +}; + +gboolean gncEmployeeRegister (void) +{ + return gncBusinessRegister (&gncEmployeeDesc); +} + +static gint lastEmployee = 2; + +gint gncEmployeeNextID (GncBusiness *business) +{ + return ++lastEmployee; /* XXX: Look into Database! */ +} diff --git a/src/business/business-core/gncEmployee.h b/src/business/business-core/gncEmployee.h new file mode 100644 index 0000000000..8b41714074 --- /dev/null +++ b/src/business/business-core/gncEmployee.h @@ -0,0 +1,50 @@ +/* + * gncEmployee.h -- the Core Employee Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_EMPLOYEE_H_ +#define GNC_EMPLOYEE_H_ + +struct _gncEmployee; +typedef struct _gncEmployee GncEmployee; + +#include "gncBusiness.h" +#include "gncAddress.h" + +#define GNC_EMPLOYEE_MODULE_NAME "gncEmployee" + +/* Create/Destroy Functions */ + +GncEmployee *gncEmployeeCreate (GncBusiness *business); +void gncEmployeeDestroy (GncEmployee *employee); + +/* Set Functions */ + +void gncEmployeeSetID (GncEmployee *employee, const char *id); +void gncEmployeeSetUsername (GncEmployee *employee, const char *username); +void gncEmployeeSetLanguage (GncEmployee *employee, const char *language); +void gncEmployeeSetAcl (GncEmployee *employee, const char *acl); +void gncEmployeeSetWorkday (GncEmployee *employee, gnc_numeric workday); +void gncEmployeeSetRate (GncEmployee *employee, gnc_numeric rate); +void gncEmployeeSetActive (GncEmployee *employee, gboolean active); + +/* Get Functions */ + +GncBusiness * gncEmployeeGetBusiness (GncEmployee *employee); +const GUID * gncEmployeeGetGUID (GncEmployee *employee); +const char * gncEmployeeGetID (GncEmployee *employee); +const char * gncEmployeeGetUsername (GncEmployee *employee); +GncAddress * gncEmployeeGetAddr (GncEmployee *employee); +const char * gncEmployeeGetLanguage (GncEmployee *employee); +const char * gncEmployeeGetAcl (GncEmployee *employee); +gnc_numeric gncEmployeeGetWorkday (GncEmployee *employee); +gnc_numeric gncEmployeeGetRate (GncEmployee *employee); +gboolean gncEmployeeGetActive (GncEmployee *employee); + +gboolean gncEmployeeIsDirty (GncEmployee *employee); + +void gncEmployeeCommitEdit (GncEmployee *employee); + +#endif /* GNC_EMPLOYEE_H_ */ diff --git a/src/business/business-core/gncEmployeeP.h b/src/business/business-core/gncEmployeeP.h new file mode 100644 index 0000000000..8ea1516fbe --- /dev/null +++ b/src/business/business-core/gncEmployeeP.h @@ -0,0 +1,17 @@ +/* + * gncEmployeeP.h -- the Core Employee Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_EMPLOYEEP_H_ +#define GNC_EMPLOYEEP_H_ + +#include "gncBusiness.h" +#include "gncEmployee.h" + +gboolean gncEmployeeRegister (void); +gint gncEmployeeNextID (GncBusiness *business); +void gncEmployeeSetGUID (GncEmployee *employee, const GUID *guid); + +#endif /* GNC_EMPLOYEEP_H_ */ diff --git a/src/business/business-core/gncJob.c b/src/business/business-core/gncJob.c new file mode 100644 index 0000000000..927e3c750d --- /dev/null +++ b/src/business/business-core/gncJob.c @@ -0,0 +1,276 @@ +/* + * gncJob.c -- the Core Job Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include +#include + +#include "guid.h" +#include "messages.h" + +#include "gnc-numeric.h" +#include "gncJob.h" +#include "gncJobP.h" +#include "gncCustomer.h" + +struct _gncJob { + GncBusiness * business; + GUID guid; + char * id; + char * name; + char * desc; + GncCustomer * cust; + gboolean active; + gboolean dirty; +}; + +static void _gncJobAdd (GncJob *job); +static void _gncJobRemove (GncJob *job); + +#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)); + +/* Create/Destroy Functions */ + +GncJob *gncJobCreate (GncBusiness *business) +{ + GncJob *job; + + if (!business) return NULL; + + job = g_new0 (GncJob, 1); + job->business = business; + job->dirty = FALSE; + + job->id = CACHE_INSERT (""); + job->name = CACHE_INSERT (""); + job->desc = CACHE_INSERT (""); + job->cust = NULL; + job->active = TRUE; + + guid_new (&job->guid); + _gncJobAdd (job); + + return job; +} + +void gncJobDestroy (GncJob *job) +{ + if (!job) return; + + CACHE_REMOVE (job->id); + CACHE_REMOVE (job->name); + CACHE_REMOVE (job->desc); + + if (job->cust) + gncCustomerRemoveJob (job->cust, job); + + _gncJobRemove (job); + + g_free (job); +} + +/* Set Functions */ + +#define SET_STR(member, str) { \ + char * tmp; \ + \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } + +void gncJobSetID (GncJob *job, const char *id) +{ + if (!job) return; + if (!id) return; + SET_STR(job->id, id); + job->dirty = TRUE; +} + +void gncJobSetName (GncJob *job, const char *name) +{ + if (!job) return; + if (!name) return; + SET_STR(job->name, name); + job->dirty = TRUE; +} + +void gncJobSetDesc (GncJob *job, const char *desc) +{ + if (!job) return; + if (!desc) return; + SET_STR(job->desc, desc); + job->dirty = TRUE; +} + +void gncJobSetGUID (GncJob *job, const GUID *guid) +{ + if (!job) return; + if (!guid) return; + if (guid_equal (guid, &job->guid)) return; + + _gncJobRemove (job); + job->guid = *guid; + _gncJobAdd (job); +} + +void gncJobSetCustomer (GncJob *job, GncCustomer *cust) +{ + if (!job) return; + if (!cust) return; + if (cust == job->cust) return; + /* XXX: Fail if we have ANY orders or invoices */ + + if (cust) + gncCustomerRemoveJob (job->cust, job); + job->cust = cust; + gncCustomerAddJob (cust, job); + + job->dirty = TRUE; +} + +void gncJobSetActive (GncJob *job, gboolean active) +{ + if (!job) return; + if (active == job->active) return; + job->active = active; + job->dirty = TRUE; +} + +void gncJobCommitEdit (GncJob *job) +{ + /* XXX: COMMIT TO DATABASE */ + job->dirty = FALSE; +} + +/* Get Functions */ + +GncBusiness * gncJobGetBusiness (GncJob *job) +{ + if (!job) return NULL; + return job->business; +} + +const char * gncJobGetID (GncJob *job) +{ + if (!job) return NULL; + return job->id; +} + +const char * gncJobGetName (GncJob *job) +{ + if (!job) return NULL; + return job->name; +} + +const char * gncJobGetDesc (GncJob *job) +{ + if (!job) return NULL; + return job->desc; +} + +GncCustomer * gncJobGetCustomer (GncJob *job) +{ + if (!job) return NULL; + return job->cust; +} + +const GUID * gncJobGetGUID (GncJob *job) +{ + if (!job) return NULL; + return &job->guid; +} + +gboolean gncJobGetActive (GncJob *job) +{ + if (!job) return FALSE; + return job->active; +} + +gboolean gncJobIsDirty (GncJob *job) +{ + if (!job) return FALSE; + return job->dirty; +} + +/* Other functions */ + +gint gncJobSortFunc (gconstpointer a, gconstpointer b) { + GncJob *ja = (GncJob *) a; + GncJob *jb = (GncJob *) b; + + if (!a || !b) return 0; + + return (strcmp(ja->id, jb->id)); +} + + +/* Package-Private functions */ + +static void _gncJobAdd (GncJob *job) +{ + GHashTable *ht = gncBusinessEntityTable (job->business, + GNC_JOB_MODULE_NAME); + if (ht) + g_hash_table_insert (ht, &job->guid, job); +} + +static void _gncJobRemove (GncJob *job) +{ + GHashTable *ht = gncBusinessEntityTable (job->business, + GNC_JOB_MODULE_NAME); + if (ht) + g_hash_table_remove (ht, &job->guid); +} + +static GList * _gncJobGetList (GncBusiness *obj, gboolean show_all) +{ + + if (!obj) return NULL; + + /* XXX */ + return NULL; +} + +static const char * _gncJobPrintable (gpointer item) +{ + GncJob *c; + + if (!item) return NULL; + + c = item; + return c->name; +} + +static void _gncJobDestroy (GncBusiness *obj) +{ + if (!obj) return; + + /* XXX: should we be sure to destroy all the job objects? */ +} + +static GncBusinessObject gncJobDesc = { + GNC_BUSINESS_VERSION, + GNC_JOB_MODULE_NAME, + "Job", + _gncJobDestroy, + NULL, + _gncJobPrintable +}; + +gboolean gncJobRegister (void) +{ + return gncBusinessRegister (&gncJobDesc); +} + +static gint lastJob = 57; + +gint gncJobNextID (GncBusiness *business) +{ + return ++lastJob; /* XXX: Look into Database! */ +} diff --git a/src/business/business-core/gncJob.h b/src/business/business-core/gncJob.h new file mode 100644 index 0000000000..1a7f6542f0 --- /dev/null +++ b/src/business/business-core/gncJob.h @@ -0,0 +1,50 @@ +/* + * gncJob.h -- the Core Job Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_JOB_H_ +#define GNC_JOB_H_ + +struct _gncJob; +typedef struct _gncJob GncJob; + +#include "gncBusiness.h" +#include "gncAddress.h" +#include "gncCustomer.h" + +#define GNC_JOB_MODULE_NAME "gncJob" + +/* Create/Destroy Functions */ + +GncJob *gncJobCreate (GncBusiness *business); +void gncJobDestroy (GncJob *job); + +/* Set Functions */ + +void gncJobSetID (GncJob *job, const char *id); +void gncJobSetName (GncJob *job, const char *username); +void gncJobSetDesc (GncJob *job, const char *language); +void gncJobSetCustomer (GncJob *job, GncCustomer *customer); +void gncJobSetActive (GncJob *job, gboolean active); + +void gncJobCommitEdit (GncJob *job); + +/* Get Functions */ + +GncBusiness * gncJobGetBusiness (GncJob *job); +const GUID * gncJobGetGUID (GncJob *job); +const char * gncJobGetID (GncJob *job); +const char * gncJobGetName (GncJob *job); +const char * gncJobGetDesc (GncJob *job); +GncCustomer * gncJobGetCustomer (GncJob *job); +gboolean gncJobGetActive (GncJob *job); + +gboolean gncJobIsDirty (GncJob *job); + +/* Other functions */ + +gint gncJobSortFunc (gconstpointer a, gconstpointer b); + +#endif /* GNC_JOB_H_ */ diff --git a/src/business/business-core/gncJobP.h b/src/business/business-core/gncJobP.h new file mode 100644 index 0000000000..0a96d02249 --- /dev/null +++ b/src/business/business-core/gncJobP.h @@ -0,0 +1,17 @@ +/* + * gncJobP.h -- the Core Job Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_JOBP_H_ +#define GNC_JOBP_H_ + +#include "gncBusiness.h" +#include "gncJob.h" + +gboolean gncJobRegister (void); +gint gncJobNextID (GncBusiness *business); +void gncJobSetGUID (GncJob *job, const GUID *guid); + +#endif /* GNC_JOBP_H_ */ diff --git a/src/business/business-core/gncVendor.c b/src/business/business-core/gncVendor.c new file mode 100644 index 0000000000..de915912ff --- /dev/null +++ b/src/business/business-core/gncVendor.c @@ -0,0 +1,310 @@ +/* + * gncVendor.c -- the Core Vendor Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include +#include + +#include "guid.h" +#include "messages.h" + +#include "gncVendor.h" +#include "gncVendorP.h" +#include "gncAddress.h" +#include "gncBusiness.h" + +struct _gncVendor { + GncBusiness * business; + GUID guid; + char * id; + char * name; + char * notes; + GncAddress * addr; + gint terms; + gboolean taxincluded; + gboolean active; + gboolean dirty; +}; + +#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)); + +static void gncVendorAdd (GncVendor *vendor); +static void gncVendorRemove (GncVendor *vendor); + +/* Create/Destroy Functions */ + +GncVendor *gncVendorCreate (GncBusiness *business) +{ + GncVendor *vendor; + + if (!business) return NULL; + + vendor = g_new0 (GncVendor, 1); + vendor->business = business; + vendor->dirty = FALSE; + vendor->id = CACHE_INSERT (""); + vendor->name = CACHE_INSERT (""); + vendor->notes = CACHE_INSERT (""); + vendor->addr = gncAddressCreate (business); + vendor->terms = 0; + vendor->taxincluded = FALSE; + vendor->active = TRUE; + + guid_new (&vendor->guid); + + gncVendorAdd (vendor); + + return vendor; +} + +void gncVendorDestroy (GncVendor *vendor) +{ + if (!vendor) return; + + CACHE_REMOVE (vendor->id); + CACHE_REMOVE (vendor->name); + CACHE_REMOVE (vendor->notes); + gncAddressDestroy (vendor->addr); + + gncVendorRemove (vendor); + + g_free (vendor); +} + +/* Set Functions */ + +#define SET_STR(member, str) { \ + char * tmp; \ + \ + if (!strcmp (member, str)) return; \ + tmp = CACHE_INSERT (str); \ + CACHE_REMOVE (member); \ + member = tmp; \ + } + +void gncVendorSetID (GncVendor *vendor, const char *id) +{ + if (!vendor) return; + if (!id) return; + SET_STR(vendor->id, id); + vendor->dirty = TRUE; +} + +void gncVendorSetName (GncVendor *vendor, const char *name) +{ + if (!vendor) return; + if (!name) return; + SET_STR(vendor->name, name); + vendor->dirty = TRUE; +} + +void gncVendorSetNotes (GncVendor *vendor, const char *notes) +{ + if (!vendor) return; + if (!notes) return; + SET_STR(vendor->notes, notes); + vendor->dirty = TRUE; +} + +void gncVendorSetGUID (GncVendor *vendor, const GUID *guid) +{ + if (!vendor || !guid) return; + if (guid_equal (guid, &vendor->guid)) return; + gncVendorRemove (vendor); + vendor->guid = *guid; + gncVendorAdd (vendor); +} + +void gncVendorSetTerms (GncVendor *vendor, gint terms) +{ + if (!vendor) return; + if (terms == vendor->terms) return; + vendor->terms = terms; + vendor->dirty = TRUE; +} + +void gncVendorSetTaxIncluded (GncVendor *vendor, gboolean taxincl) +{ + if (!vendor) return; + if (taxincl == vendor->taxincluded) return; + vendor->taxincluded = taxincl; + vendor->dirty = TRUE; +} + +void gncVendorSetActive (GncVendor *vendor, gboolean active) +{ + if (!vendor) return; + if (active == vendor->active) return; + vendor->active = active; + vendor->dirty = TRUE; +} + +/* Get Functions */ + +GncBusiness * gncVendorGetBusiness (GncVendor *vendor) +{ + if (!vendor) return NULL; + return vendor->business; +} + +const GUID * gncVendorGetGUID (GncVendor *vendor) +{ + if (!vendor) return NULL; + return &vendor->guid; +} + +const char * gncVendorGetID (GncVendor *vendor) +{ + if (!vendor) return NULL; + return vendor->id; +} + +const char * gncVendorGetName (GncVendor *vendor) +{ + if (!vendor) return NULL; + return vendor->name; +} + +GncAddress * gncVendorGetAddr (GncVendor *vendor) +{ + if (!vendor) return NULL; + return vendor->addr; +} + +const char * gncVendorGetNotes (GncVendor *vendor) +{ + if (!vendor) return NULL; + return vendor->notes; +} + +gint gncVendorGetTerms (GncVendor *vendor) +{ + if (!vendor) return 0; + return vendor->terms; +} + +gboolean gncVendorGetTaxIncluded (GncVendor *vendor) +{ + if (!vendor) return FALSE; + return vendor->taxincluded; +} + +gboolean gncVendorGetActive (GncVendor *vendor) +{ + if (!vendor) return FALSE; + return vendor->active; +} + +gboolean gncVendorIsDirty (GncVendor *vendor) +{ + if (!vendor) return FALSE; + return (vendor->dirty || gncAddressIsDirty (vendor->addr)); +} + +void gncVendorCommitEdit (GncVendor *vendor) +{ + + /* XXX COMMIT TO DATABASE */ + vendor->dirty = FALSE; +} + +/* Other functions */ + +static gint gncVendorSortFunc (gconstpointer a, gconstpointer b) { + GncVendor *va = (GncVendor *) a; + GncVendor *vb = (GncVendor *) b; + return(strcmp(va->name, vb->name)); +} + +/* Package-Private functions */ + +static void gncVendorAdd (GncVendor *vendor) +{ + GHashTable *ht = gncBusinessEntityTable (vendor->business, + GNC_VENDOR_MODULE_NAME); + if (ht) + g_hash_table_insert (ht, &vendor->guid, vendor); +} + +static void gncVendorRemove (GncVendor *vendor) +{ + GHashTable *ht = gncBusinessEntityTable (vendor->business, + GNC_VENDOR_MODULE_NAME); + if (ht) + g_hash_table_remove (ht, &vendor->guid); +} + +struct _iterate { + GList *list; + gboolean show_all; +}; + +static void get_list (gpointer key, gpointer item, gpointer arg) +{ + struct _iterate *iter = arg; + GncVendor *vendor = item; + + if (iter->show_all || gncVendorGetActive (vendor)) { + iter->list = g_list_insert_sorted (iter->list, vendor, gncVendorSortFunc); + } +} + +static GList * _gncVendorGetList (GncBusiness *bus, gboolean show_all) +{ + GHashTable *ht; + struct _iterate iter; + + if (!bus) return NULL; + + iter.list = NULL; + iter.show_all = show_all; + + ht = gncBusinessEntityTable (bus, GNC_VENDOR_MODULE_NAME); + if (ht) + g_hash_table_foreach (ht, get_list, &iter); + + return iter.list; +} + +static const char * _gncVendorPrintable (gpointer item) +{ + GncVendor *v; + + if (!item) return NULL; + + v = item; + return v->name; +} + +static void _gncVendorDestroy (GncBusiness *obj) +{ + if (!obj) return; + + /* XXX: should we be sure to destroy all the vendor objects? */ +} + +static GncBusinessObject gncVendorDesc = { + GNC_BUSINESS_VERSION, + GNC_VENDOR_MODULE_NAME, + "Vendor", + _gncVendorDestroy, + _gncVendorGetList, + _gncVendorPrintable +}; + +gboolean gncVendorRegister (void) +{ + return gncBusinessRegister (&gncVendorDesc); +} + +static gint lastVendor = 17; + +gint gncVendorNextID (GncBusiness *business) +{ + return ++lastVendor; /* XXX: Look into Database! */ +} diff --git a/src/business/business-core/gncVendor.h b/src/business/business-core/gncVendor.h new file mode 100644 index 0000000000..abad1ad881 --- /dev/null +++ b/src/business/business-core/gncVendor.h @@ -0,0 +1,48 @@ +/* + * gncVendor.h -- the Core Vendor Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_VENDOR_H_ +#define GNC_VENDOR_H_ + +struct _gncVendor; +typedef struct _gncVendor GncVendor; + +#include "gncBusiness.h" +#include "gncAddress.h" + +#define GNC_VENDOR_MODULE_NAME "gncVendor" + +/* Create/Destroy Functions */ + +GncVendor *gncVendorCreate (GncBusiness *business); +void gncVendorDestroy (GncVendor *vendor); + +/* Set Functions */ + +void gncVendorSetID (GncVendor *vendor, const char *id); +void gncVendorSetName (GncVendor *vendor, const char *name); +void gncVendorSetNotes (GncVendor *vendor, const char *notes); +void gncVendorSetTerms (GncVendor *vendor, gint terms); +void gncVendorSetTaxIncluded (GncVendor *vendor, gboolean taxincl); +void gncVendorSetActive (GncVendor *vendor, gboolean active); + +void gncVendorCommitEdit (GncVendor *vendor); + +/* Get Functions */ + +GncBusiness * gncVendorGetBusiness (GncVendor *vendor); +const GUID * gncVendorGetGUID (GncVendor *vendor); +const char * gncVendorGetID (GncVendor *vendor); +const char * gncVendorGetName (GncVendor *vendor); +GncAddress * gncVendorGetAddr (GncVendor *vendor); +const char * gncVendorGetNotes (GncVendor *vendor); +gint gncVendorGetTerms (GncVendor *vendor); +gboolean gncVendorGetTaxIncluded (GncVendor *vendor); +gboolean gncVendorGetActive (GncVendor *vendor); + +gboolean gncVendorIsDirty (GncVendor *vendor); + +#endif /* GNC_VENDOR_H_ */ diff --git a/src/business/business-core/gncVendorP.h b/src/business/business-core/gncVendorP.h new file mode 100644 index 0000000000..141c5c80ab --- /dev/null +++ b/src/business/business-core/gncVendorP.h @@ -0,0 +1,17 @@ +/* + * gncVendorP.h -- the Core Vendor Interface + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_VENDORP_H_ +#define GNC_VENDORP_H_ + +#include "gncBusiness.h" +#include "gncVendor.h" + +gboolean gncVendorRegister (void); +gint gncVendorNextID (GncBusiness *business); +void gncVendorSetGUID (GncVendor *vendor, const GUID *guid); + +#endif /* GNC_VENDORP_H_ */ diff --git a/src/business/business-core/gw-business-core-spec.scm b/src/business/business-core/gw-business-core-spec.scm new file mode 100644 index 0000000000..55780eb6ab --- /dev/null +++ b/src/business/business-core/gw-business-core-spec.scm @@ -0,0 +1,107 @@ +;;; -*-scheme-*- +(use-modules (g-wrap)) + +(debug-set! maxdepth 100000) +(debug-set! stack 2000000) + +(define-module (g-wrapped gw-business-core-spec) + :use-module (g-wrap)) + +(use-modules (g-wrapped gw-engine-spec)) + +(let ((mod (gw:new-module "gw-business-core"))) + (define (standard-c-call-gen result func-call-code) + (list (gw:result-get-c-name result) " = " func-call-code ";\n")) + + (define (add-standard-result-handlers! type c->scm-converter) + (define (standard-pre-handler result) + (let* ((ret-type-name (gw:result-get-proper-c-type-name result)) + (ret-var-name (gw:result-get-c-name result))) + (list "{\n" + " " ret-type-name " " ret-var-name ";\n"))) + + (gw:type-set-pre-call-result-ccodegen! type standard-pre-handler) + + (gw:type-set-post-call-result-ccodegen! + type + (lambda (result) + (let* ((scm-name (gw:result-get-scm-name result)) + (c-name (gw:result-get-c-name result))) + (list + (c->scm-converter scm-name c-name) + " }\n"))))) + + (gw:module-depends-on mod "gw-runtime") + (gw:module-depends-on mod "gw-engine") + + (gw:module-set-guile-module! mod '(g-wrapped gw-business-core)) + + (gw:module-set-declarations-ccodegen! + mod + (lambda (client-only?) + (list + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + ))) + + (gw:module-set-init-ccodegen! + mod + (lambda (client-only?) + (if client-only? + '() + (gw:inline-scheme '(use-modules (gnucash business-core)))))) + + ;; The core Business Object + + (gw:wrap-non-native-type mod ' "GncBusiness*" + "const GncBusiness*") + + ;; The core Business Object Types + ;; XXX: Need to add lists of all of these! + + (gw:wrap-non-native-type mod ' "GncAddress*" + "const GncAddress*") + (gw:wrap-non-native-type mod ' "GncCustomer*" + "const GncCustomer*") + (gw:wrap-non-native-type mod ' "GncEmployee*" + "const GncEmployee*") + (gw:wrap-non-native-type mod ' "GncJob*" + "const GncJob*") + (gw:wrap-non-native-type mod ' "GncVendor*" + "const GncVendor*") + + ;; + ;; gncBusiness.h + ;; + + (gw:wrap-function + mod + 'gnc:business-create + ' + "gncBusinessCreate" + '(( session)) + "Return a newly-created GncBusiness state object.") + + (gw:wrap-function + mod + 'gnc:business-destroy + ' + "gncBusinessDestroy" + '(( business)) + "Destroy a GncBusiness object") + + ;; gncAddress.h + + ;; gncCustomer.h + + ;; gncEmployee.h + + ;; gncJob.h + + ;; gncVendor.h + +) diff --git a/src/business/business-core/test/.cvsignore b/src/business/business-core/test/.cvsignore new file mode 100644 index 0000000000..98e7edb996 --- /dev/null +++ b/src/business/business-core/test/.cvsignore @@ -0,0 +1,7 @@ +Makefile +test-address +test-business +test-customer +test-employee +test-job +test-vendor diff --git a/src/business/business-core/test/Makefile.am b/src/business/business-core/test/Makefile.am new file mode 100644 index 0000000000..6892bb7255 --- /dev/null +++ b/src/business/business-core/test/Makefile.am @@ -0,0 +1,42 @@ + +AM_CFLAGS = \ + -I${top_srcdir}/src/gnc-module \ + -I${top_srcdir}/src/test-core \ + -I${top_srcdir}/src/engine \ + -I.. \ + ${GUILE_INCS} \ + ${GLIB_CFLAGS} + +LDADD = \ + ${top_srcdir}/src/gnc-module/libgncmodule.la \ + ${top_srcdir}/src/test-core/libgncmod-test.la \ + ${top_srcdir}/src/engine/libgncmod-engine.la \ + ${top_srcdir}/src/engine/libgw-engine.la \ + ../libgncmod-business-core.la \ + ../libgw-business-core.la \ + ${GLIB_LIBS} \ + -lltdl + +TESTS = \ + test-business \ + test-address \ + test-customer \ + test-vendor \ + test-employee \ + test-job + +TESTS_ENVIRONMENT = \ + GNC_MODULE_PATH="..:${top_srcdir}/src/engine" \ + GUILE_LOAD_PATH="${G_WRAP_MODULE_DIR}:..:../../../gnc-module:${top_srcdir}/src/scm" \ + LTDL_LIBRARY_PATH=${top_srcdir}/src/gnc-module:..:${top_srcdir}/src/engine \ + LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:..:${top_srcdir}/src/engine:${top_srcdir}/src/gnc-module + +noinst_PROGRAMS = \ + test-business \ + test-address \ + test-customer \ + test-vendor \ + test-employee \ + test-job + +EXTRA_DIST = diff --git a/src/business/business-core/test/test-address.c b/src/business/business-core/test/test-address.c new file mode 100644 index 0000000000..9dfb1fbbd6 --- /dev/null +++ b/src/business/business-core/test/test-address.c @@ -0,0 +1,77 @@ +#include +#include + +#include "guid.h" +#include "gnc-module.h" +#include "gnc-engine-util.h" + +#include "gncBusiness.h" +#include "gncAddress.h" +#include "test-stuff.h" + +static void +test_string_fcn (GncAddress *address, const char *message, + void (*set) (GncAddress *, const char *str), + const char * (*get)(const GncAddress *)); + +static void +test_address (void) +{ + GncBusiness *bus; + GncAddress *address; + + bus = gncBusinessCreate ((GNCSession *)1); + + /* Test creation/destruction */ + { + do_test (gncAddressCreate (NULL) == NULL, "address create NULL"); + address = gncAddressCreate (bus); + do_test (address != NULL, "address create"); + + gncAddressDestroy (address); + success ("create/destroy"); + } + + /* Test setting routines */ + { + address = gncAddressCreate (bus); + test_string_fcn (address, "Name", gncAddressSetName, gncAddressGetName); + test_string_fcn (address, "Addr1", gncAddressSetAddr1, gncAddressGetAddr1); + test_string_fcn (address, "Addr2", gncAddressSetAddr2, gncAddressGetAddr2); + test_string_fcn (address, "Addr3", gncAddressSetAddr3, gncAddressGetAddr3); + test_string_fcn (address, "Addr4", gncAddressSetAddr4, gncAddressGetAddr4); + test_string_fcn (address, "Phone", gncAddressSetPhone, gncAddressGetPhone); + test_string_fcn (address, "Fax", gncAddressSetFax, gncAddressGetFax); + test_string_fcn (address, "Email", gncAddressSetEmail, gncAddressGetEmail); + } +} + +static void +test_string_fcn (GncAddress *address, const char *message, + void (*set) (GncAddress *, const char *str), + const char * (*get)(const GncAddress *)) +{ + char const *str = get_random_string (); + + do_test (!gncAddressIsDirty (address), "test if start dirty"); + set (address, str); + do_test (gncAddressIsDirty (address), "test dirty later"); + do_test (safe_strcmp (get (address), str) == 0, message); + gncAddressClearDirty (address); +} + +static void +main_helper (int argc, char **argv) +{ + gnc_module_load("gnucash/business-core", 0); + test_address(); + print_test_results(); + exit(get_rv()); +} + +int +main (int argc, char **argv) +{ + gh_enter (argc, argv, main_helper); + return 0; +} diff --git a/src/business/business-core/test/test-business.c b/src/business/business-core/test/test-business.c new file mode 100644 index 0000000000..d047f43742 --- /dev/null +++ b/src/business/business-core/test/test-business.c @@ -0,0 +1,195 @@ +#include +#include + +#include "guid.h" +#include "gnc-module.h" +#include "gnc-engine-util.h" +#include "messages.h" + +#include "gncBusiness.h" +#include "test-stuff.h" + +#define TEST_MODULE_NAME "business-test" +#define TEST_MODULE_DESC "Test Business" + +static GList * get_list (GncBusiness *, gboolean show_all); +static const char * printable (gpointer obj); +static void test_printable (GncBusiness *bus, const char *name, gpointer obj); + +static GncBusinessObject bus_obj = { + GNC_BUSINESS_VERSION, + TEST_MODULE_NAME, + TEST_MODULE_DESC, + NULL, /* destroy */ + get_list, + printable, +}; + +static void test_business (void) +{ + GncBusiness *bus; + + /* Test the global registration and lookup functions */ + { + do_test (!gncBusinessRegister (NULL), "register NULL"); + do_test (gncBusinessRegister (&bus_obj), "register test object"); + do_test (!gncBusinessRegister (&bus_obj), "register test object again"); + do_test (gncBusinessLookup (TEST_MODULE_NAME) == &bus_obj, + "lookup our installed object"); + do_test (gncBusinessLookup ("snm98sn snml say dyikh9y9ha") == NULL, + "lookup non-existant business object"); + + do_test (!safe_strcmp (gncBusinessGetTypeLabel (TEST_MODULE_NAME), + _(TEST_MODULE_DESC)), + "test description return"); + } + + /* Test creation and session handling */ + { + bus = gncBusinessCreate (NULL); + do_test (bus == NULL, "business create NULL"); + bus = gncBusinessCreate ((GNCSession *)1); + do_test (bus != NULL, "business create non-NULL"); + + do_test (gncBusinessGetSession (NULL) == NULL, + "business get session NULL"); + do_test (gncBusinessGetSession (bus) == (GNCSession *)1, + "business get session"); + + gncBusinessDestroy (bus); + success ("business create and destroy"); + } + + /* Test the entity tables */ + { + GUID guid; + gpointer ptr, res; + GHashTable *ht; + + bus = gncBusinessCreate ((GNCSession *)1); + do_test (gncBusinessEntityTable (NULL, NULL) == NULL, + "business entity table NULL NULL"); + do_test (gncBusinessEntityTable (NULL, TEST_MODULE_NAME) == NULL, + "business entity table NULL module_name"); + do_test (gncBusinessEntityTable (bus, NULL) == NULL, + "business entity table bus NULL"); + ht = gncBusinessEntityTable (bus, TEST_MODULE_NAME); + do_test (ht != NULL, "business entity table bus, module_name"); + + guid_new (&guid); + + /* Check the lookup functions before we add anything to the table */ + do_test (gncBusinessLookupGUID (NULL, NULL, NULL) == NULL, + "business: lookupGUID: NULL, NULL, NULL"); + do_test (gncBusinessLookupGUID (NULL, NULL, &guid) == NULL, + "business: lookupGUID: NULL, NULL, guid"); + do_test (gncBusinessLookupGUID (NULL, TEST_MODULE_NAME, NULL) == NULL, + "business: lookupGUID: NULL, mod_name, NULL"); + do_test (gncBusinessLookupGUID (NULL, TEST_MODULE_NAME, &guid) == NULL, + "business: lookupGUID: NULL, mod_name, guid"); + do_test (gncBusinessLookupGUID (bus, NULL, NULL) == NULL, + "business: lookupGUID: bus, NULL, NULL"); + do_test (gncBusinessLookupGUID (bus, NULL, &guid) == NULL, + "business: lookupGUID: bus, NULL, guid"); + do_test (gncBusinessLookupGUID (bus, TEST_MODULE_NAME, NULL) == NULL, + "business: lookupGUID: bus, mod_name, NULL"); + do_test (gncBusinessLookupGUID (bus, TEST_MODULE_NAME, &guid) == NULL, + "business: lookupGUID: bus, mod_name, guid"); + + /* Now add to the table and look up again */ + ptr = get_random_string (); + g_hash_table_insert (ht, &guid, ptr); + + /* now let's see if we can look for it */ + do_test (gncBusinessLookupGUID (NULL, NULL, NULL) == NULL, + "business: lookupGUID(2): NULL, NULL, NULL"); + do_test (gncBusinessLookupGUID (NULL, NULL, &guid) == NULL, + "business: lookupGUID(2): NULL, NULL, guid"); + do_test (gncBusinessLookupGUID (NULL, TEST_MODULE_NAME, NULL) == NULL, + "business: lookupGUID(2): NULL, mod_name, NULL"); + do_test (gncBusinessLookupGUID (NULL, TEST_MODULE_NAME, &guid) == NULL, + "business: lookupGUID(2): NULL, mod_name, guid"); + do_test (gncBusinessLookupGUID (bus, NULL, NULL) == NULL, + "business: lookupGUID(2): bus, NULL, NULL"); + do_test (gncBusinessLookupGUID (bus, NULL, &guid) == NULL, + "business: lookupGUID(2): bus, NULL, guid"); + do_test (gncBusinessLookupGUID (bus, TEST_MODULE_NAME, NULL) == NULL, + "business: lookupGUID(2): bus, mod_name, NULL"); + res = gncBusinessLookupGUID (bus, TEST_MODULE_NAME, &guid); + do_test (res != NULL, "business: lookupGUID(2): bus, mod_name, guid"); + do_test (res == ptr, "business: lookupGUID(2): check the same pointer"); + + test_printable (bus, TEST_MODULE_NAME, ptr); + } +} + +static GList * +get_list (GncBusiness *bus, gboolean show_all) +{ + do_test (bus != NULL, "get_list: NULL business"); + success ("called get_list callback"); + return ((GList *)1); +} + +static const char * +printable (gpointer obj) +{ + do_test (obj != NULL, "printable: object is NULL"); + success ("called printable callback"); + return ((const char *)obj); +} + +static void +test_get_list (GncBusiness *bus, const char *name) +{ + GList *res; + + do_test (gncBusinessGetList (NULL, NULL, FALSE) == NULL, + "business: GetList: NULL, NULL, FALSE"); + do_test (gncBusinessGetList (NULL, name, FALSE) == NULL, + "business: GetList: NULL, mod_name, FALSE"); + do_test (gncBusinessGetList (bus, NULL, FALSE) == NULL, + "business: GetList: bus, NULL, FALSE"); + res = gncBusinessGetList (bus, name, FALSE); + do_test (res != NULL, "business: GetList: bus, mod_name, FALSE"); +} + +static void +test_printable (GncBusiness *bus, const char *name, gpointer obj) +{ + const char *res; + + do_test (gncBusinessPrintable (NULL, NULL, NULL) == NULL, + "business: Printable: NULL, NULL, NULL"); + do_test (gncBusinessPrintable (NULL, NULL, obj) == NULL, + "business: Printable: NULL, NULL, object"); + do_test (gncBusinessPrintable (NULL, name, NULL) == NULL, + "business: Printable: NULL, mod_name, NULL"); + do_test (gncBusinessPrintable (NULL, name, obj) == NULL, + "business: Printable: NULL, mod_name, object"); + do_test (gncBusinessPrintable (bus, NULL, NULL) == NULL, + "business: Printable: bus, NULL, NULL"); + do_test (gncBusinessPrintable (bus, NULL, obj) == NULL, + "business: Printable: bus, NULL, object"); + do_test (gncBusinessPrintable (bus, name, NULL) == NULL, + "business: Printable: bus, mod_name, NULL"); + + res = gncBusinessPrintable (bus, name, obj); + do_test (res != NULL, "business: Printable: bus, mod_name, object"); +} + +static void +main_helper (int argc, char **argv) +{ + gnc_module_load("gnucash/business-core", 0); + test_business(); + print_test_results(); + exit(get_rv()); +} + +int +main (int argc, char **argv) +{ + gh_enter (argc, argv, main_helper); + return 0; +} diff --git a/src/business/business-core/test/test-customer.c b/src/business/business-core/test/test-customer.c new file mode 100644 index 0000000000..29e89adbdc --- /dev/null +++ b/src/business/business-core/test/test-customer.c @@ -0,0 +1,196 @@ +#include +#include + +#include "guid.h" +#include "gnc-module.h" +#include "gnc-engine-util.h" + +#include "gncBusiness.h" +#include "gncCustomer.h" +#include "gncCustomerP.h" +#include "test-stuff.h" + +static int count = 0; + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, const char *str), + const char * (*get)(GncCustomer *)); + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, gnc_numeric), + gnc_numeric (*get)(GncCustomer *)); + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, gboolean), + gboolean (*get) (GncCustomer *)); + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, gint), + gint (*get) (GncCustomer *)); + +static void +test_customer (void) +{ + GncBusiness *bus; + GncCustomer *customer; + + bus = gncBusinessCreate ((GNCSession *)1); + + /* Test creation/destruction */ + { + do_test (gncCustomerCreate (NULL) == NULL, "customer create NULL"); + customer = gncCustomerCreate (bus); + do_test (customer != NULL, "customer create"); + do_test (gncCustomerGetBusiness (customer) == bus, + "getbusiness"); + + gncCustomerDestroy (customer); + success ("create/destroy"); + } + + /* Test setting/getting routines; does the active flag get set right? */ + { + GUID guid; + + test_string_fcn (bus, "Id", gncCustomerSetID, gncCustomerGetID); + test_string_fcn (bus, "Name", gncCustomerSetName, gncCustomerGetName); + test_string_fcn (bus, "Notes", gncCustomerSetNotes, gncCustomerGetNotes); + + test_gint_fcn (bus, "Terms", gncCustomerSetTerms, gncCustomerGetTerms); + + test_numeric_fcn (bus, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount); + test_numeric_fcn (bus, "Credit", gncCustomerSetCredit, gncCustomerGetCredit); + + test_bool_fcn (bus, "TaxIncluded", gncCustomerSetTaxIncluded, gncCustomerGetTaxIncluded); + test_bool_fcn (bus, "Active", gncCustomerSetActive, gncCustomerGetActive); + + do_test (gncCustomerGetAddr (customer) != NULL, "Addr"); + do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr"); + + guid_new (&guid); + customer = gncCustomerCreate (bus); count++; + gncCustomerSetGUID (customer, &guid); + do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare"); + } + { + GList *list; + + list = gncBusinessGetList (bus, GNC_CUSTOMER_MODULE_NAME, TRUE); + do_test (list != NULL, "getList all"); + do_test (g_list_length (list) == count, "correct length: all"); + g_list_free (list); + + list = gncBusinessGetList (bus, GNC_CUSTOMER_MODULE_NAME, FALSE); + do_test (list != NULL, "getList active"); + do_test (g_list_length (list) == 1, "correct length: active"); + g_list_free (list); + } + { + const char *str = get_random_string(); + const char *res; + + gncCustomerSetName (customer, str); + res = gncBusinessPrintable (bus, GNC_CUSTOMER_MODULE_NAME, customer); + do_test (res != NULL, "Printable NULL?"); + do_test (safe_strcmp (str, res) == 0, "Printable equals"); + } + + do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty"); + + /* Test the Entity Table */ + { + const GUID *guid; + + guid = gncCustomerGetGUID (customer); + do_test (gncBusinessLookupGUID (bus, GNC_CUSTOMER_MODULE_NAME, guid) + == customer, "Entity Table"); + } + + /* Note: JobList is tested from the Job tests */ +} + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, const char *str), + const char * (*get)(GncCustomer *)) +{ + GncCustomer *customer = gncCustomerCreate (bus); + char const *str = get_random_string (); + + do_test (!gncCustomerIsDirty (customer), "test if start dirty"); + set (customer, str); + do_test (gncCustomerIsDirty (customer), "test dirty later"); + do_test (safe_strcmp (get (customer), str) == 0, message); + gncCustomerSetActive (customer, FALSE); + count++; +} + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, gnc_numeric), + gnc_numeric (*get)(GncCustomer *)) +{ + GncCustomer *customer = gncCustomerCreate (bus); + gnc_numeric num = gnc_numeric_create (17, 1); + + do_test (!gncCustomerIsDirty (customer), "test if start dirty"); + set (customer, num); + do_test (gncCustomerIsDirty (customer), "test dirty later"); + do_test (gnc_numeric_equal (get (customer), num), message); + gncCustomerSetActive (customer, FALSE); + count++; +} + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, gboolean), + gboolean (*get) (GncCustomer *)) +{ + GncCustomer *customer = gncCustomerCreate (bus); + gboolean num = get_random_boolean (); + + do_test (!gncCustomerIsDirty (customer), "test if start dirty"); + set (customer, FALSE); + set (customer, TRUE); + set (customer, num); + do_test (gncCustomerIsDirty (customer), "test dirty later"); + do_test (get (customer) == num, message); + gncCustomerSetActive (customer, FALSE); + count++; +} + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncCustomer *, gint), + gint (*get) (GncCustomer *)) +{ + GncCustomer *customer = gncCustomerCreate (bus); + gint num = 17; + + do_test (!gncCustomerIsDirty (customer), "test if start dirty"); + set (customer, num); + do_test (gncCustomerIsDirty (customer), "test dirty later"); + do_test (get (customer) == num, message); + gncCustomerSetActive (customer, FALSE); + count++; +} + +static void +main_helper (int argc, char **argv) +{ + gnc_module_load("gnucash/business-core", 0); + test_customer(); + print_test_results(); + exit(get_rv()); +} + +int +main (int argc, char **argv) +{ + gh_enter (argc, argv, main_helper); + return 0; +} diff --git a/src/business/business-core/test/test-employee.c b/src/business/business-core/test/test-employee.c new file mode 100644 index 0000000000..a5e889dbd8 --- /dev/null +++ b/src/business/business-core/test/test-employee.c @@ -0,0 +1,180 @@ +#include +#include + +#include "guid.h" +#include "gnc-module.h" +#include "gnc-engine-util.h" + +#include "gncBusiness.h" +#include "gncEmployee.h" +#include "gncEmployeeP.h" +#include "test-stuff.h" + +static int count = 0; + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, const char *str), + const char * (*get)(GncEmployee *)); + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, gnc_numeric), + gnc_numeric (*get)(GncEmployee *)); + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, gboolean), + gboolean (*get) (GncEmployee *)); + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, gint), + gint (*get) (GncEmployee *)); + +static void +test_employee (void) +{ + GncBusiness *bus; + GncEmployee *employee; + + bus = gncBusinessCreate ((GNCSession *)1); + + /* Test creation/destruction */ + { + do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL"); + employee = gncEmployeeCreate (bus); + do_test (employee != NULL, "employee create"); + do_test (gncEmployeeGetBusiness (employee) == bus, + "getbusiness"); + + gncEmployeeDestroy (employee); + success ("create/destroy"); + } + + /* Test setting/getting routines; does the active flag get set right? */ + { + GUID guid; + + test_string_fcn (bus, "Id", gncEmployeeSetID, gncEmployeeGetID); + test_string_fcn (bus, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername); + test_string_fcn (bus, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage); + test_string_fcn (bus, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl); + + test_numeric_fcn (bus, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday); + test_numeric_fcn (bus, "Rate", gncEmployeeSetRate, gncEmployeeGetRate); + + test_bool_fcn (bus, "Active", gncEmployeeSetActive, gncEmployeeGetActive); + + do_test (gncEmployeeGetAddr (employee) != NULL, "Addr"); + + guid_new (&guid); + employee = gncEmployeeCreate (bus); count++; + gncEmployeeSetGUID (employee, &guid); + do_test (guid_equal (&guid, gncEmployeeGetGUID (employee)), "guid compare"); + } + { + GList *list; + + list = gncBusinessGetList (bus, GNC_EMPLOYEE_MODULE_NAME, TRUE); + do_test (list != NULL, "getList all"); + do_test (g_list_length (list) == count, "correct length: all"); + g_list_free (list); + + list = gncBusinessGetList (bus, GNC_EMPLOYEE_MODULE_NAME, FALSE); + do_test (list != NULL, "getList active"); + do_test (g_list_length (list) == 1, "correct length: active"); + g_list_free (list); + } + { + const char *str = get_random_string(); + const char *res; + + gncEmployeeSetUsername (employee, str); + res = gncBusinessPrintable (bus, GNC_EMPLOYEE_MODULE_NAME, employee); + do_test (res != NULL, "Printable NULL?"); + do_test (safe_strcmp (str, res) == 0, "Printable equals"); + } +} + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, const char *str), + const char * (*get)(GncEmployee *)) +{ + GncEmployee *employee = gncEmployeeCreate (bus); + char const *str = get_random_string (); + + do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); + set (employee, str); + do_test (gncEmployeeIsDirty (employee), "test dirty later"); + do_test (safe_strcmp (get (employee), str) == 0, message); + gncEmployeeSetActive (employee, FALSE); + count++; +} + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, gnc_numeric), + gnc_numeric (*get)(GncEmployee *)) +{ + GncEmployee *employee = gncEmployeeCreate (bus); + gnc_numeric num = gnc_numeric_create (17, 1); + + do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); + set (employee, num); + do_test (gncEmployeeIsDirty (employee), "test dirty later"); + do_test (gnc_numeric_equal (get (employee), num), message); + gncEmployeeSetActive (employee, FALSE); + count++; +} + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, gboolean), + gboolean (*get) (GncEmployee *)) +{ + GncEmployee *employee = gncEmployeeCreate (bus); + gboolean num = get_random_boolean (); + + do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); + set (employee, FALSE); + set (employee, TRUE); + set (employee, num); + do_test (gncEmployeeIsDirty (employee), "test dirty later"); + do_test (get (employee) == num, message); + gncEmployeeSetActive (employee, FALSE); + count++; +} + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncEmployee *, gint), + gint (*get) (GncEmployee *)) +{ + GncEmployee *employee = gncEmployeeCreate (bus); + gint num = 17; + + do_test (!gncEmployeeIsDirty (employee), "test if start dirty"); + set (employee, num); + do_test (gncEmployeeIsDirty (employee), "test dirty later"); + do_test (get (employee) == num, message); + gncEmployeeSetActive (employee, FALSE); + count++; +} + +static void +main_helper (int argc, char **argv) +{ + gnc_module_load("gnucash/business-core", 0); + test_employee(); + print_test_results(); + exit(get_rv()); +} + +int +main (int argc, char **argv) +{ + gh_enter (argc, argv, main_helper); + return 0; +} diff --git a/src/business/business-core/test/test-job.c b/src/business/business-core/test/test-job.c new file mode 100644 index 0000000000..b644bae1e5 --- /dev/null +++ b/src/business/business-core/test/test-job.c @@ -0,0 +1,191 @@ +#include +#include + +#include "guid.h" +#include "gnc-module.h" +#include "gnc-engine-util.h" + +#include "gncBusiness.h" +#include "gncJob.h" +#include "gncJobP.h" +#include "test-stuff.h" + +static int count = 0; + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, const char *str), + const char * (*get)(GncJob *)); + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, gnc_numeric), + gnc_numeric (*get)(GncJob *)); + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, gboolean), + gboolean (*get) (GncJob *)); + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, gint), + gint (*get) (GncJob *)); + +static void +test_job (void) +{ + GncBusiness *bus; + GncJob *job; + + bus = gncBusinessCreate ((GNCSession *)1); + + /* Test creation/destruction */ + { + do_test (gncJobCreate (NULL) == NULL, "job create NULL"); + job = gncJobCreate (bus); + do_test (job != NULL, "job create"); + do_test (gncJobGetBusiness (job) == bus, + "getbusiness"); + + gncJobDestroy (job); + success ("create/destroy"); + } + + /* Test setting/getting routines; does the active flag get set right? */ + { + GUID guid; + + test_string_fcn (bus, "Id", gncJobSetID, gncJobGetID); + test_string_fcn (bus, "Name", gncJobSetName, gncJobGetName); + test_string_fcn (bus, "Desc", gncJobSetDesc, gncJobGetDesc); + + test_bool_fcn (bus, "Active", gncJobSetActive, gncJobGetActive); + + guid_new (&guid); + job = gncJobCreate (bus); count++; + gncJobSetGUID (job, &guid); + do_test (guid_equal (&guid, gncJobGetGUID (job)), "guid compare"); + } +#if 0 + { + GList *list; + + list = gncBusinessGetList (bus, GNC_JOB_MODULE_NAME, TRUE); + do_test (list != NULL, "getList all"); + do_test (g_list_length (list) == count, "correct length: all"); + g_list_free (list); + + list = gncBusinessGetList (bus, GNC_JOB_MODULE_NAME, FALSE); + do_test (list != NULL, "getList active"); + do_test (g_list_length (list) == 1, "correct length: active"); + g_list_free (list); + } +#endif + { + const char *str = get_random_string(); + const char *res; + + gncJobSetName (job, str); + res = gncBusinessPrintable (bus, GNC_JOB_MODULE_NAME, job); + do_test (res != NULL, "Printable NULL?"); + do_test (safe_strcmp (str, res) == 0, "Printable equals"); + } + { + GList *list; + GncCustomer *cust = gncCustomerCreate (bus); + + do_test (gncCustomerGetJoblist (cust, TRUE) == NULL, "empty list at start"); + gncJobSetCustomer (job, cust); + list = gncCustomerGetJoblist (cust, FALSE); + do_test (list != NULL, "added to cust"); + do_test (g_list_length (list) == 1, "correct joblist length"); + do_test (list->data == job, "verify job in list"); + gncJobSetActive (job, FALSE); + list = gncCustomerGetJoblist (cust, FALSE); + do_test (list == NULL, "no active jobs"); + list = gncCustomerGetJoblist (cust, TRUE); + do_test (list != NULL, "all jobs"); + gncJobDestroy (job); + list = gncCustomerGetJoblist (cust, TRUE); + do_test (list == NULL, "no more jobs"); + } +} + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, const char *str), + const char * (*get)(GncJob *)) +{ + GncJob *job = gncJobCreate (bus); + char const *str = get_random_string (); + + do_test (!gncJobIsDirty (job), "test if start dirty"); + set (job, str); + do_test (gncJobIsDirty (job), "test dirty later"); + do_test (safe_strcmp (get (job), str) == 0, message); + gncJobSetActive (job, FALSE); count++; +} + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, gnc_numeric), + gnc_numeric (*get)(GncJob *)) +{ + GncJob *job = gncJobCreate (bus); + gnc_numeric num = gnc_numeric_create (17, 1); + + do_test (!gncJobIsDirty (job), "test if start dirty"); + set (job, num); + do_test (gncJobIsDirty (job), "test dirty later"); + do_test (gnc_numeric_equal (get (job), num), message); + gncJobSetActive (job, FALSE); count++; +} + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, gboolean), + gboolean (*get) (GncJob *)) +{ + GncJob *job = gncJobCreate (bus); + gboolean num = get_random_boolean (); + + do_test (!gncJobIsDirty (job), "test if start dirty"); + set (job, FALSE); + set (job, TRUE); + set (job, num); + do_test (gncJobIsDirty (job), "test dirty later"); + do_test (get (job) == num, message); + gncJobSetActive (job, FALSE); count++; +} + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncJob *, gint), + gint (*get) (GncJob *)) +{ + GncJob *job = gncJobCreate (bus); + gint num = 17; + + do_test (!gncJobIsDirty (job), "test if start dirty"); + set (job, num); + do_test (gncJobIsDirty (job), "test dirty later"); + do_test (get (job) == num, message); + gncJobSetActive (job, FALSE); count++; +} + +static void +main_helper (int argc, char **argv) +{ + gnc_module_load("gnucash/business-core", 0); + test_job(); + print_test_results(); + exit(get_rv()); +} + +int +main (int argc, char **argv) +{ + gh_enter (argc, argv, main_helper); + return 0; +} diff --git a/src/business/business-core/test/test-vendor.c b/src/business/business-core/test/test-vendor.c new file mode 100644 index 0000000000..6bdd96ea07 --- /dev/null +++ b/src/business/business-core/test/test-vendor.c @@ -0,0 +1,175 @@ +#include +#include + +#include "guid.h" +#include "gnc-module.h" +#include "gnc-engine-util.h" + +#include "gncBusiness.h" +#include "gncVendor.h" +#include "gncVendorP.h" +#include "test-stuff.h" + +static int count = 0; + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, const char *str), + const char * (*get)(GncVendor *)); + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, gnc_numeric), + gnc_numeric (*get)(GncVendor *)); + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, gboolean), + gboolean (*get) (GncVendor *)); + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, gint), + gint (*get) (GncVendor *)); + +static void +test_vendor (void) +{ + GncBusiness *bus; + GncVendor *vendor; + + bus = gncBusinessCreate ((GNCSession *)1); + + /* Test creation/destruction */ + { + do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL"); + vendor = gncVendorCreate (bus); + do_test (vendor != NULL, "vendor create"); + do_test (gncVendorGetBusiness (vendor) == bus, + "getbusiness"); + + gncVendorDestroy (vendor); + success ("create/destroy"); + } + + /* Test setting/getting routines; does the active flag get set right? */ + { + GUID guid; + + test_string_fcn (bus, "Id", gncVendorSetID, gncVendorGetID); + test_string_fcn (bus, "Name", gncVendorSetName, gncVendorGetName); + test_string_fcn (bus, "Notes", gncVendorSetNotes, gncVendorGetNotes); + + test_gint_fcn (bus, "Terms", gncVendorSetTerms, gncVendorGetTerms); + + test_bool_fcn (bus, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded); + test_bool_fcn (bus, "Active", gncVendorSetActive, gncVendorGetActive); + + do_test (gncVendorGetAddr (vendor) != NULL, "Addr"); + + guid_new (&guid); + vendor = gncVendorCreate (bus); count++; + gncVendorSetGUID (vendor, &guid); + do_test (guid_equal (&guid, gncVendorGetGUID (vendor)), "guid compare"); + } + { + GList *list; + + list = gncBusinessGetList (bus, GNC_VENDOR_MODULE_NAME, TRUE); + do_test (list != NULL, "getList all"); + do_test (g_list_length (list) == count, "correct length: all"); + g_list_free (list); + + list = gncBusinessGetList (bus, GNC_VENDOR_MODULE_NAME, FALSE); + do_test (list != NULL, "getList active"); + do_test (g_list_length (list) == 1, "correct length: active"); + g_list_free (list); + } + { + const char *str = get_random_string(); + const char *res; + + gncVendorSetName (vendor, str); + res = gncBusinessPrintable (bus, GNC_VENDOR_MODULE_NAME, vendor); + do_test (res != NULL, "Printable NULL?"); + do_test (safe_strcmp (str, res) == 0, "Printable equals"); + } +} + +static void +test_string_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, const char *str), + const char * (*get)(GncVendor *)) +{ + GncVendor *vendor = gncVendorCreate (bus); + char const *str = get_random_string (); + + do_test (!gncVendorIsDirty (vendor), "test if start dirty"); + set (vendor, str); + do_test (gncVendorIsDirty (vendor), "test dirty later"); + do_test (safe_strcmp (get (vendor), str) == 0, message); + gncVendorSetActive (vendor, FALSE); count++; +} + +static void +test_numeric_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, gnc_numeric), + gnc_numeric (*get)(GncVendor *)) +{ + GncVendor *vendor = gncVendorCreate (bus); + gnc_numeric num = gnc_numeric_create (17, 1); + + do_test (!gncVendorIsDirty (vendor), "test if start dirty"); + set (vendor, num); + do_test (gncVendorIsDirty (vendor), "test dirty later"); + do_test (gnc_numeric_equal (get (vendor), num), message); + gncVendorSetActive (vendor, FALSE); count++; +} + +static void +test_bool_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, gboolean), + gboolean (*get) (GncVendor *)) +{ + GncVendor *vendor = gncVendorCreate (bus); + gboolean num = get_random_boolean (); + + do_test (!gncVendorIsDirty (vendor), "test if start dirty"); + set (vendor, FALSE); + set (vendor, TRUE); + set (vendor, num); + do_test (gncVendorIsDirty (vendor), "test dirty later"); + do_test (get (vendor) == num, message); + gncVendorSetActive (vendor, FALSE); count++; +} + +static void +test_gint_fcn (GncBusiness *bus, const char *message, + void (*set) (GncVendor *, gint), + gint (*get) (GncVendor *)) +{ + GncVendor *vendor = gncVendorCreate (bus); + gint num = 17; + + do_test (!gncVendorIsDirty (vendor), "test if start dirty"); + set (vendor, num); + do_test (gncVendorIsDirty (vendor), "test dirty later"); + do_test (get (vendor) == num, message); + gncVendorSetActive (vendor, FALSE); count++; +} + +static void +main_helper (int argc, char **argv) +{ + gnc_module_load("gnucash/business-core", 0); + test_vendor(); + print_test_results(); + exit(get_rv()); +} + +int +main (int argc, char **argv) +{ + gh_enter (argc, argv, main_helper); + return 0; +} diff --git a/src/business/business-gnome/.cvsignore b/src/business/business-gnome/.cvsignore new file mode 100644 index 0000000000..4fb78db4aa --- /dev/null +++ b/src/business/business-gnome/.cvsignore @@ -0,0 +1,6 @@ +.scm-links +Makefile +gw-business-gnome.c +gw-business-gnome.h +gw-business-gnome.html +gw-business-gnome.scm diff --git a/src/business/business-gnome/Makefile.am b/src/business/business-gnome/Makefile.am new file mode 100644 index 0000000000..34e0af30dd --- /dev/null +++ b/src/business/business-gnome/Makefile.am @@ -0,0 +1,92 @@ +pkglib_LTLIBRARIES = libgncmod-business-gnome.la libgw-business-gnome.la + +AM_CFLAGS = \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/engine \ + -I${top_srcdir}/src/gnc-module \ + -I${top_srcdir}/src/gnome-utils \ + -I${top_srcdir}/src/gnome \ + -I${top_srcdir}/src/app-utils \ + -I${top_srcdir}/src/business/business-core \ + ${GUILE_INCS} \ + ${GNOME_INCLUDEDIR} \ + ${GLADE_CFLAGS} \ + ${GTKHTML_CFLAGS} \ + ${G_WRAP_COMPILE_ARGS} \ + ${GLIB_CFLAGS} \ + -I${top_srcdir}/src/register/ledger-core \ + -I${top_srcdir}/src/register/register-core + +libgncmod_business_gnome_la_SOURCES = \ + businessmod-gnome.c \ + business-chooser.c \ + dialog-customer.c \ + dialog-employee.c \ + dialog-job.c \ + dialog-job-select.c \ + dialog-vendor.c + +noinst_HEADERS = \ + business-chooser.h \ + dialog-customer.h \ + dialog-employee.h \ + dialog-job.h \ + dialog-job-select.h \ + dialog-vendor.h + +libgncmod_business_gnome_la_LDFLAGS = -module + +libgncmod_business_gnome_la_LIBADD = \ + ../business-core/libgncmod-business-core.la \ + ${top_srcdir}/src/gnc-module/libgncmodule.la \ + ${top_srcdir}/src/engine/libgncmod-engine.la \ + ${top_srcdir}/src/app-utils/libgncmod-app-utils.la \ + ${top_srcdir}/src/gnome-utils/libgncmod-gnome-utils.la \ + ${GUILE_LIBS} \ + ${GNOMEUI_LIBS} \ + ${G_WRAP_LINK_ARGS} \ + ${GLIB_LIBS} \ + ${EFENCE_LIBS} + + +libgw_business_gnome_la_SOURCES = gw-business-gnome.c +libgw_business_gnome_la_LDFLAGS = -module ${G_WRAP_LINK_ARGS} + +gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash +gncmod_DATA = business-gnome.scm + +gladedir = $(GNC_GLADE_DIR) +glade_DATA = \ + business-chooser.glade \ + customer.glade \ + employee.glade \ + job.glade \ + vendor.glade + +EXTRA_DIST = $(glade_DATA) + +gwmoddir = ${GNC_GWRAP_LIBDIR} +gwmod_DATA = \ + gw-business-gnome.scm \ + gw-business-gnome-spec.scm + +.scm-links: + rm -f gnucash g-wrapped + ln -sf . gnucash + ln -sf . g-wrapped + touch .scm-links + +gncmod-business-gnome.c: gw-business-gnome.h + +gw-business-gnome.scm gw-business-gnome.c gw-business-gnome.h: .scm-links gw-business-gnome-spec.scm + FLAVOR=gnome guile -c \ + "(set! %load-path (cons \"${G_WRAP_MODULE_DIR}\" %load-path)) \ + (set! %load-path (cons \"${PWD}\" %load-path)) \ + (set! %load-path (cons \"../business-core\" %load-path)) \ + (set! %load-path (cons \"../../engine\" %load-path)) \ + (set! %load-path (cons \"../../gnome\" %load-path)) \ + (primitive-load \"./gw-business-gnome-spec.scm\") \ + (gw:generate-module \"gw-business-gnome\")" + +BUILT_SOURCES = gw-business-gnome.scm gw-business-gnome.c gw-business-gnome.h +CLEANFILES = gw-business-gnome.scm gw-business-gnome.c gw-business-gnome.h gw-business-gnome.html diff --git a/src/business/business-gnome/business-chooser.c b/src/business/business-gnome/business-chooser.c new file mode 100644 index 0000000000..1de38da51c --- /dev/null +++ b/src/business/business-gnome/business-chooser.c @@ -0,0 +1,249 @@ +/* + * business-chooser.c -- General Selection Dialog for GNC Business Objects + * + * Written By: Derek Atkins + * Copyright (C) 2001 + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "gnc-ui.h" +#include "gnc-gui-query.h" + +#include "gncBusiness.h" +#include "business-chooser.h" + +struct business_chooser_window { + GtkWidget * dialog; + GtkWidget * choice_combo; + GtkWidget * choice_entry; + GtkWidget * showall_check; + + GncBusiness * business; + const GncBusinessObject * obj_type; + gnc_business_chooser_new_cb new_cb; + gnc_business_chooser_edit_cb edit_cb; + gpointer cb_arg; + + gpointer selected; +}; + + +static void +chooser_choice_changed_cb(GtkList *list, GtkWidget *li, gpointer user_data) +{ + struct business_chooser_window * w = user_data; + + w->selected = gtk_object_get_data (GTK_OBJECT (li), "list-item-pointer"); +} + +static void +update_selection_picker (struct business_chooser_window *w) +{ + GList *objs, *iterator; + GtkWidget *li; + GList *obj_list; + gpointer selected; + gboolean show_all = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (w->showall_check)); + + /* Clear out the existing choices */ + gtk_list_clear_items (GTK_LIST (GTK_COMBO (w->choice_combo)->list), 0, -1); + + /* Save the existing selection */ + selected = w->selected; + + /* Get the list of objects */ + obj_list = (*(w->obj_type->get_list))(w->business, show_all); + + /* Build a list of strings (objs is pre-sorted, so keep the order!) */ + for (iterator = obj_list; iterator; iterator = iterator->next) { + const gchar *label = (*(w->obj_type->printable))(iterator->data); + + li = gtk_list_item_new_with_label (label); + gtk_object_set_data (GTK_OBJECT (li), "list-item-pointer", iterator->data); + gtk_widget_show (li); + gtk_container_add (GTK_CONTAINER (GTK_COMBO (w->choice_combo)->list), li); + } + + /* revert the existing selection */ + w->selected = selected; + + /* If no selection, choose the first one in the list */ + if (!w->selected && obj_list) + w->selected = obj_list->data; + + /* XXX: Should we verify that w->selected is a memeber of obj_list? */ + + /* And set the current-selected item */ + gtk_entry_set_text (GTK_ENTRY (w->choice_entry), + ((w->selected) ? + (*(w->obj_type->printable))(w->selected) : "")); + + g_list_free (obj_list); +} + +static void +gnc_ui_business_chooser_ok_cb(GtkButton * button, gpointer user_data) +{ + struct business_chooser_window * w = user_data; + + if(w->selected) { + gnome_dialog_close(GNOME_DIALOG (w->dialog)); + } else { + gnc_warning_dialog(_("You must make a selection.\n" + "To create a new one, click \"New\"")); + } +} + +static void +gnc_ui_business_chooser_new_cb(GtkButton * button, gpointer user_data) +{ + struct business_chooser_window * w = user_data; + + if (w->new_cb) { + gpointer new_selection; + GtkWidget *toplevel; + + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); + new_selection = (*(w->new_cb))(w->cb_arg, toplevel); + + if (new_selection) { + w->selected = new_selection; + update_selection_picker (w); + } + } +} + +static void +gnc_ui_business_chooser_edit_cb(GtkButton * button, gpointer user_data) +{ + struct business_chooser_window * w = user_data; + + if (! w->selected) { + gnc_warning_dialog(_("You must choose a selection to edit.\n")); + return; + } + + if (w->edit_cb) { + GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); + (*(w->edit_cb))(w->cb_arg, w->selected, toplevel); + } + + update_selection_picker (w); +} + +static void +gnc_ui_business_chooser_cancel_cb(GtkButton * button, gpointer user_data) +{ + struct business_chooser_window * w = user_data; + + if (w) + gnome_dialog_close(GNOME_DIALOG (w->dialog)); +} + +static void +gnc_ui_business_chooser_showall_toggled_cb(GtkCheckButton * entry, + gpointer user_data) +{ + struct business_chooser_window * w = user_data; + + update_selection_picker (w); +} + +static gint +business_chooser_close (GnomeDialog *dialog, gpointer data) +{ + gtk_main_quit (); + return FALSE; +} + +gpointer +gnc_ui_business_chooser_new (GtkWidget * parent, + gpointer orig_sel, + GncBusiness *business, const char *type_name, + gnc_business_chooser_new_cb new_cb, + gnc_business_chooser_edit_cb edit_cb, + gpointer cbarg) +{ + struct business_chooser_window * win = + g_new0(struct business_chooser_window, 1); + GladeXML *xml; + GtkWidget *choice_name_label; + gpointer retval; + + if (!business || !type_name) return NULL; + + xml = gnc_glade_xml_new ("business-chooser.glade", + "Business Chooser Dialog"); + + /* Grab the widgets */ + + win->dialog = glade_xml_get_widget (xml, "Business Chooser Dialog"); + win->choice_combo = glade_xml_get_widget (xml, "choice_combo"); + win->choice_entry = glade_xml_get_widget (xml, "choice_entry"); + win->showall_check = glade_xml_get_widget (xml, "showall_check"); + + /* Set the label */ + choice_name_label = glade_xml_get_widget (xml, "choice_name_label"); + gtk_label_set_text (GTK_LABEL (choice_name_label), + gncBusinessGetTypeLabel (type_name)); + + if(parent) { + gnome_dialog_set_parent(GNOME_DIALOG(win->dialog), GTK_WINDOW(parent)); + } + + /* Setup the signals */ + glade_xml_signal_connect_data + (xml, "gnc_ui_business_chooser_ok_cb", + GTK_SIGNAL_FUNC (gnc_ui_business_chooser_ok_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_business_chooser_new_cb", + GTK_SIGNAL_FUNC (gnc_ui_business_chooser_new_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_business_chooser_edit_cb", + GTK_SIGNAL_FUNC (gnc_ui_business_chooser_edit_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_business_chooser_cancel_cb", + GTK_SIGNAL_FUNC (gnc_ui_business_chooser_cancel_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_business_chooser_showall_toggled_cb", + GTK_SIGNAL_FUNC (gnc_ui_business_chooser_showall_toggled_cb), win); + + gtk_signal_connect (GTK_OBJECT (GTK_COMBO (win->choice_combo)->list), + "select-child", + GTK_SIGNAL_FUNC(chooser_choice_changed_cb), win); + + gtk_signal_connect (GTK_OBJECT(win->dialog), "close", + GTK_SIGNAL_FUNC(business_chooser_close), win); + + /* Save the callbacks */ + win->business = business; + win->obj_type = gncBusinessLookup (type_name); + win->new_cb = new_cb; + win->edit_cb = edit_cb; + win->cb_arg = cbarg; + + /* Setup the menu */ + win->selected = orig_sel; + update_selection_picker (win); + + /* Run the widget */ + gtk_window_set_modal(GTK_WINDOW(win->dialog), TRUE); + gtk_widget_show (win->dialog); + gtk_main(); + + /* And exit */ + retval = win->selected; + g_free(win); + + return retval; +} + diff --git a/src/business/business-gnome/business-chooser.glade b/src/business/business-gnome/business-chooser.glade new file mode 100644 index 0000000000..092fae15fd --- /dev/null +++ b/src/business/business-gnome/business-chooser.glade @@ -0,0 +1,209 @@ + + + + + Business-chooser + business-chooser + + src + pixmaps + C + True + True + False + False + False + False + + + + GnomeDialog + Business Chooser Dialog + Chooser + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + True + False + False + False + + + GtkVBox + GnomeDialog:vbox + vbox1 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + hbuttonbox1 + GTK_BUTTONBOX_SPREAD + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button1 + True + True + + clicked + gnc_ui_business_chooser_ok_cb + Business_Chooser_Dialog + Sat, 10 Nov 2001 23:06:48 GMT + + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button2 + True + True + + clicked + gnc_ui_business_chooser_new_cb + Business_Chooser_Dialog + Sat, 10 Nov 2001 23:07:01 GMT + + + + + + GtkButton + button3 + True + True + + clicked + gnc_ui_business_chooser_edit_cb + Business_Chooser_Dialog + Sun, 11 Nov 2001 02:16:31 GMT + + + + + + GtkButton + button4 + True + True + + clicked + gnc_ui_business_chooser_cancel_cb + Business_Chooser_Dialog + Sat, 10 Nov 2001 23:07:12 GMT + + GNOME_STOCK_BUTTON_CANCEL + + + + + GtkVBox + vbox3 + False + 0 + + 0 + False + False + + + + GtkCheckButton + showall_check + True + + toggled + gnc_ui_business_chooser_showall_toggled_cb + Business_Chooser_Dialog + Thu, 15 Nov 2001 15:49:23 GMT + + + False + True + + 0 + False + False + + + + + GtkHBox + hbox2 + False + 0 + + 0 + True + True + + + + GtkLabel + choice_name_label + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 3 + False + False + + + + + GtkCombo + choice_combo + 250 + True + True + False + True + False + + + 3 + True + True + + + + GtkEntry + GtkCombo:entry + choice_entry + True + False + True + 0 + + + + + + + + + diff --git a/src/business/business-gnome/business-chooser.h b/src/business/business-gnome/business-chooser.h new file mode 100644 index 0000000000..5b8739bfe6 --- /dev/null +++ b/src/business/business-gnome/business-chooser.h @@ -0,0 +1,35 @@ +/* + * business-chooser.h -- General Selection Dialog for GNC Business Objects + * + * Written By: Derek Atkins + * Copyright (C) 2001 + */ + +#ifndef GNC_BUSINESS_CHOOSER_H_ +#define GNC_BUSINESS_CHOOSER_H_ + +/* + * Generic function to choose business objects. This function + * is only called from within the business objects, but is made + * available here so other objects can use it. You provide the + * original selection, the Object Type Name (as registered), + * callbacks to call to create a new object or to edit an existing + * one, and a callback argument that is passed to the callbacks. + * + * Note that if a callback function is NULL, the associated button + * will still be clickable but will do nothing. XXXX -- this is a bug + */ + +typedef gpointer (*gnc_business_chooser_new_cb)(gpointer cbarg, GtkWidget *toplevel); +typedef void (*gnc_business_chooser_edit_cb)(gpointer cbarg, gpointer sel_obj, GtkWidget *toplevel); + +gpointer +gnc_ui_business_chooser_new (GtkWidget * parent, + gpointer orig_sel, + GncBusiness *business, const char *type_name, + gnc_business_chooser_new_cb new_cb, + gnc_business_chooser_edit_cb edit_cb, + gpointer cbarg); + + +#endif /* GNC_BUSINESS_CHOOSER_H_ */ diff --git a/src/business/business-gnome/business-gnome.scm b/src/business/business-gnome/business-gnome.scm new file mode 100644 index 0000000000..4535b89cb2 --- /dev/null +++ b/src/business/business-gnome/business-gnome.scm @@ -0,0 +1 @@ +(define-module (gnucash business-gnome)) diff --git a/src/business/business-gnome/businessmod-gnome.c b/src/business/business-gnome/businessmod-gnome.c new file mode 100644 index 0000000000..08f3125525 --- /dev/null +++ b/src/business/business-gnome/businessmod-gnome.c @@ -0,0 +1,54 @@ +/********************************************************************* + * businessmod-core.c + * module definition/initialization for the Business GNOME UI module + * + * Copyright (c) 2001 Derek Atkins + *********************************************************************/ + +#include +#include +#include + +#include "gnc-module.h" +#include "gnc-module-api.h" +#include "gw-business-gnome.h" + +/* version of the gnc module system interface we require */ +int gnc_module_system_interface = 0; + +/* module versioning uses libtool semantics. */ +int gnc_module_current = 0; +int gnc_module_revision = 0; +int gnc_module_age = 0; + +char * +gnc_module_path(void) +{ + return g_strdup("gnucash/business-gnome"); +} + +char * +gnc_module_description(void) +{ + return g_strdup("The Gnucash business module GNOME UI"); +} + +int +gnc_module_init(int refcount) +{ + /* load business-core: we depend on it */ + if (!gnc_module_load ("gnucash/business-core", 0)) { + return FALSE; + } + + gh_eval_str("(use-modules (g-wrapped gw-business-gnome))"); + gh_eval_str("(use-modules (gnucash business-gnome))"); + + return TRUE; +} + +int +gnc_module_end(int refcount) { + return TRUE; +} + diff --git a/src/business/business-gnome/customer.glade b/src/business/business-gnome/customer.glade new file mode 100644 index 0000000000..fb9852605f --- /dev/null +++ b/src/business/business-gnome/customer.glade @@ -0,0 +1,1138 @@ + + + + + Customer + customer + + src + pixmaps + C + True + True + False + False + False + False + + + + GnomeDialog + Customer Dialog + New Customer + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox1 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button4 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button5 + True + True + GNOME_STOCK_BUTTON_CANCEL + + + + GtkButton + button6 + True + True + GNOME_STOCK_BUTTON_HELP + + + + + GtkNotebook + notebook1 + True + True + True + GTK_POS_TOP + False + 2 + 2 + False + + 0 + True + True + + + + GtkVBox + vbox2 + False + 0 + + + GtkFrame + frame1 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkHBox + hbox2 + 2 + False + 0 + + + GtkVBox + vbox11 + True + 0 + + 0 + False + False + + + + GtkLabel + label1 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label19 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkCheckButton + active_check + True + + True + True + + 0 + False + False + + + + + + GtkVBox + vbox12 + True + 0 + + 0 + True + True + + + + GtkEntry + id_entry + 50 + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + company_entry + 158 + True + True + True + 0 + + + 0 + True + False + + + + + GtkLabel + label26 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + + + GtkFrame + frame2 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + False + + + + GtkHBox + hbox3 + 200 + False + 0 + + + GtkVBox + vbox5 + 3 + True + 0 + + 3 + False + True + + + + GtkLabel + label3 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label4 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label23 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label24 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label25 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label5 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label6 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label7 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + GtkVBox + vbox6 + 3 + True + 0 + + 0 + True + True + + + + GtkEntry + name_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr1_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr2_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr3_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr4_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + phone_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + fax_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + email_entry + True + True + True + 0 + + + 0 + False + False + + + + + + + + GtkFrame + frame4 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkScrolledWindow + scrolledwindow1 + 3 + GTK_POLICY_NEVER + GTK_POLICY_ALWAYS + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + + GtkText + notes_text + 15 + True + True + + + + + + + + GtkLabel + Notebook:tab + label9 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkVBox + vbox13 + False + 0 + + + GtkFrame + frame3 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + True + + + + GtkHBox + hbox6 + False + 0 + + + GtkVBox + vbox7 + True + 0 + + 0 + False + False + + + + GtkLabel + label8 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label10 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label11 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkCheckButton + tax_included_check + 3 + True + + False + True + + 0 + False + False + + + + + + GtkVBox + vbox13 + 3 + True + 0 + + 0 + True + True + + + + GtkHBox + terms_box + False + 0 + + 0 + True + True + + + + Placeholder + + + + + GtkHBox + discount_box + False + 0 + + 0 + False + False + + + + Placeholder + + + + + GtkHBox + credit_box + False + 0 + + 0 + True + True + + + + Placeholder + + + + + GtkLabel + label32 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + + + Placeholder + + + + + GtkLabel + Notebook:tab + label33 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkVBox + vbox9 + False + 0 + + + GtkFrame + frame5 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + False + + + + GtkHBox + hbox5 + False + 0 + + + GtkVBox + vbox8 + 4 + True + 0 + + 3 + False + True + + + + GtkLabel + label14 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label15 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label20 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label21 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label22 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label16 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label17 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label18 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + GtkVBox + vbox9 + 3 + True + 0 + + 3 + True + True + + + + GtkEntry + shipname_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipaddr1_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipaddr2_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipaddr3_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipaddr4_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipphone_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipfax_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + shipemail_entry + True + True + True + 0 + + + 0 + False + False + + + + + + + + Placeholder + + + + Placeholder + + + + + GtkLabel + Notebook:tab + label12 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + + diff --git a/src/business/business-gnome/dialog-customer.c b/src/business/business-gnome/dialog-customer.c new file mode 100644 index 0000000000..4624a42345 --- /dev/null +++ b/src/business/business-gnome/dialog-customer.c @@ -0,0 +1,683 @@ +/* + * dialog-customer.c -- Dialog for Customer entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "global-options.h" +#include "gnc-amount-edit.h" +#include "gnc-component-manager.h" +#include "gnc-ui.h" +#include "gnc-gui-query.h" +#include "gnc-ui-util.h" +#include "gnc-engine-util.h" +#include "window-help.h" + +#include "gncBusiness.h" +#include "gncAddress.h" +#include "gncCustomer.h" +#include "gncCustomerP.h" + +#include "dialog-customer.h" +#include "business-chooser.h" + +#define DIALOG_NEW_CUSTOMER_CM_CLASS "dialog-new-customer" +#define DIALOG_EDIT_CUSTOMER_CM_CLASS "dialog-edit-customer" + +typedef enum +{ + NEW_CUSTOMER, + EDIT_CUSTOMER +} CustomerDialogType; + +struct _customer_select_window { + GncBusiness * business; +}; + +typedef struct _customer_window { + GtkWidget * dialog; + + GtkWidget * id_entry; + GtkWidget * company_entry; + + GtkWidget * name_entry; + GtkWidget * addr1_entry; + GtkWidget * addr2_entry; + GtkWidget * addr3_entry; + GtkWidget * addr4_entry; + GtkWidget * phone_entry; + GtkWidget * fax_entry; + GtkWidget * email_entry; + + GtkWidget * shipname_entry; + GtkWidget * shipaddr1_entry; + GtkWidget * shipaddr2_entry; + GtkWidget * shipaddr3_entry; + GtkWidget * shipaddr4_entry; + GtkWidget * shipphone_entry; + GtkWidget * shipfax_entry; + GtkWidget * shipemail_entry; + + GtkWidget * terms_amount; + GtkWidget * discount_amount; + GtkWidget * credit_amount; + + GtkWidget * active_check; + GtkWidget * taxincluded_check; + GtkWidget * notes_text; + + CustomerDialogType dialog_type; + GUID customer_guid; + gint component_id; + GncBusiness * business; + GncCustomer * created_customer; + +} CustomerWindow; + +static GncCustomer * +cw_get_customer (CustomerWindow *cw) +{ + if (!cw) + return NULL; + + return gncBusinessLookupGUID (cw->business, GNC_CUSTOMER_MODULE_NAME, + &cw->customer_guid); +} + +static void gnc_ui_to_customer (CustomerWindow *cw, GncCustomer *cust) +{ + GncAddress *addr, *shipaddr; + gnc_numeric num; + + addr = gncCustomerGetAddr (cust); + shipaddr = gncCustomerGetShipAddr (cust); + + gnc_suspend_gui_refresh (); + + gncCustomerSetID (cust, gtk_editable_get_chars + (GTK_EDITABLE (cw->id_entry), 0, -1)); + gncCustomerSetName (cust, gtk_editable_get_chars + (GTK_EDITABLE (cw->company_entry), 0, -1)); + + gncAddressSetName (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->name_entry), 0, -1)); + gncAddressSetAddr1 (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->addr1_entry), 0, -1)); + gncAddressSetAddr2 (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->addr2_entry), 0, -1)); + gncAddressSetAddr3 (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->addr3_entry), 0, -1)); + gncAddressSetAddr4 (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->addr4_entry), 0, -1)); + gncAddressSetPhone (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->phone_entry), 0, -1)); + gncAddressSetFax (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->fax_entry), 0, -1)); + gncAddressSetEmail (addr, gtk_editable_get_chars + (GTK_EDITABLE (cw->email_entry), 0, -1)); + + gncAddressSetName (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipname_entry), 0, -1)); + gncAddressSetAddr1 (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipaddr1_entry), 0, -1)); + gncAddressSetAddr2 (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipaddr2_entry), 0, -1)); + gncAddressSetAddr3 (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipaddr3_entry), 0, -1)); + gncAddressSetAddr4 (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipaddr4_entry), 0, -1)); + gncAddressSetPhone (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipphone_entry), 0, -1)); + gncAddressSetFax (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipfax_entry), 0, -1)); + gncAddressSetEmail (shipaddr, gtk_editable_get_chars + (GTK_EDITABLE (cw->shipemail_entry), 0, -1)); + + gncCustomerSetActive (cust, gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (cw->active_check))); + gncCustomerSetTaxIncluded (cust, gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (cw->taxincluded_check))); + gncCustomerSetNotes (cust, gtk_editable_get_chars + (GTK_EDITABLE (cw->notes_text), 0, -1)); + + /* Parse and set the terms, discount, and credit amounts */ + num = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (cw->terms_amount)); + gncCustomerSetTerms (cust, gnc_numeric_num (num)); + gncCustomerSetDiscount (cust, gnc_amount_edit_get_amount + (GNC_AMOUNT_EDIT (cw->discount_amount))); + gncCustomerSetCredit (cust, gnc_amount_edit_get_amount + (GNC_AMOUNT_EDIT (cw->credit_amount))); + + gncCustomerCommitEdit (cust); + gnc_resume_gui_refresh (); +} + +static gboolean check_edit_amount (GtkWidget *dialog, GtkWidget *amount, + gnc_numeric *min, gnc_numeric *max, + const char * error_message) +{ + if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount))) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + /* We've got a valid-looking number; check mix/max */ + if (min || max) { + gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount)); + if ((min && gnc_numeric_compare (*min, val) > 0) || + (max && gnc_numeric_compare (val, *max) > 0)) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + } + return FALSE; +} + +static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry, + const char * error_message) +{ + const char *res = gtk_entry_get_text (GTK_ENTRY (entry)); + if (safe_strcmp (res, "") == 0) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + return FALSE; +} + +static void +gnc_customer_window_ok_cb (GtkWidget *widget, gpointer data) +{ + CustomerWindow *cw = data; + char *res; + GncCustomer *cust; + gnc_numeric min, max; + + /* Check for valid id */ + if (check_entry_nonempty (cw->dialog, cw->id_entry, + _("The Customer must be given an ID."))) + return; + + /* Check for valid company name */ + if (check_entry_nonempty (cw->dialog, cw->company_entry, + _("You must enter a company name."))) + return; + + /* Make sure we have an address */ + if (check_entry_nonempty (cw->dialog, cw->addr1_entry, NULL) && + check_entry_nonempty (cw->dialog, cw->addr2_entry, NULL) && + check_entry_nonempty (cw->dialog, cw->addr3_entry, NULL) && + check_entry_nonempty (cw->dialog, cw->addr4_entry, NULL)) { + const char *msg = _("You must enter a billing address."); + gnc_error_dialog_parented (GTK_WINDOW (cw->dialog), msg); + return; + } + + /* Verify terms, discount, and credit are valid (or empty) */ + min = gnc_numeric_zero (); + max = gnc_numeric_create (100, 1); + if (check_edit_amount (cw->dialog, cw->terms_amount, &min, NULL, + _("Terms must be a positive integer or " + "you must leave it blank."))) + return; + + if (check_edit_amount (cw->dialog, cw->discount_amount, &min, &max, + _("Discount percentage must be between 0-100 " + "or you must leave it blank."))) + return; + + if (check_edit_amount (cw->dialog, cw->credit_amount, &min, NULL, + _("Credit must be a positive amount or " + "you must leave it blank."))) + return; + + /* Now save it off */ + { + GncCustomer *customer = cw_get_customer (cw); + if (customer) { + gnc_ui_to_customer (cw, customer); + } + cw->created_customer = customer; + cw->customer_guid = *xaccGUIDNULL (); + } + + gnc_close_gui_component (cw->component_id); +} + +static void +gnc_customer_window_cancel_cb (GtkWidget *widget, gpointer data) +{ + CustomerWindow *cw = data; + + gnc_close_gui_component (cw->component_id); +} + +static void +gnc_customer_window_help_cb (GtkWidget *widget, gpointer data) +{ + CustomerWindow *cw = data; + char *help_file = ""; /* xxx */ + + helpWindow(NULL, NULL, help_file); +} + +static void +gnc_customer_window_destroy_cb (GtkWidget *widget, gpointer data) +{ + CustomerWindow *cw = data; + GncCustomer *customer = cw_get_customer (cw); + + gnc_suspend_gui_refresh (); + + if (cw->dialog_type == NEW_CUSTOMER && customer != NULL) { + gncCustomerDestroy (customer); + cw->customer_guid = *xaccGUIDNULL (); + } + + gnc_unregister_gui_component (cw->component_id); + gnc_resume_gui_refresh (); + + g_free (cw); +} + +static void +gnc_customer_name_changed_cb (GtkWidget *widget, gpointer data) +{ + CustomerWindow *cw = data; + char *name, *id, *fullname, *title; + + if (!cw) + return; + + name = gtk_entry_get_text (GTK_ENTRY (cw->name_entry)); + if (!name || *name == '\0') + name = _(""); + + id = gtk_entry_get_text (GTK_ENTRY (cw->id_entry)); + + fullname = g_strconcat (name, " (", id, ")", NULL); + + if (cw->dialog_type == EDIT_CUSTOMER) + title = g_strconcat (_("Edit Customer"), " - ", fullname, NULL); + else + title = g_strconcat (_("New Customer"), " - ", fullname, NULL); + + gtk_window_set_title (GTK_WINDOW (cw->dialog), title); + + g_free (fullname); + g_free (title); +} + +static int +gnc_customer_on_close_cb (GnomeDialog *dialog, gpointer data) +{ + CustomerWindow *cw; + GncCustomer **created_customer = data; + + if (data) { + cw = gtk_object_get_data (GTK_OBJECT (dialog), "dialog_info"); + *created_customer = cw->created_customer; + } + + gtk_main_quit (); + + return FALSE; +} + +static void +gnc_customer_window_close_handler (gpointer user_data) +{ + CustomerWindow *cw = user_data; + + gnome_dialog_close (GNOME_DIALOG (cw->dialog)); +} + +static void +gnc_customer_window_refresh_handler (GHashTable *changes, gpointer user_data) +{ + CustomerWindow *cw = user_data; + const EventInfo *info; + GncCustomer *customer = cw_get_customer (cw); + + /* If there isn't a customer behind us, close down */ + if (!customer) { + gnc_close_gui_component (cw->component_id); + return; + } + + /* Next, close if this is a destroy event */ + if (changes) { + info = gnc_gui_get_entity_events (changes, &cw->customer_guid); + if (info && (info->event_mask & GNC_EVENT_DESTROY)) { + gnc_close_gui_component (cw->component_id); + return; + } + } +} + +static CustomerWindow * +gnc_customer_new_window (GtkWidget *parent, GncBusiness *bus, + GncCustomer *cust) +{ + CustomerWindow *cw; + GladeXML *xml; + GtkWidget *hbox, *edit; + GnomeDialog *cwd; + gnc_commodity *commodity; + GNCPrintAmountInfo print_info; + + cw = g_new0 (CustomerWindow, 1); + + cw->business = bus; + + /* Find the dialog */ + xml = gnc_glade_xml_new ("customer.glade", "Customer Dialog"); + cw->dialog = glade_xml_get_widget (xml, "Customer Dialog"); + cwd = GNOME_DIALOG (cw->dialog); + + gtk_object_set_data (GTK_OBJECT (cw->dialog), "dialog_info", cw); + + /* default to ok */ + gnome_dialog_set_default (cwd, 0); + + if (parent) + gnome_dialog_set_parent (cwd, GTK_WINDOW (parent)); + + /* Get entry points */ + cw->id_entry = glade_xml_get_widget (xml, "id_entry"); + cw->company_entry = glade_xml_get_widget (xml, "company_entry"); + + cw->name_entry = glade_xml_get_widget (xml, "name_entry"); + cw->addr1_entry = glade_xml_get_widget (xml, "addr1_entry"); + cw->addr2_entry = glade_xml_get_widget (xml, "addr2_entry"); + cw->addr3_entry = glade_xml_get_widget (xml, "addr3_entry"); + cw->addr4_entry = glade_xml_get_widget (xml, "addr4_entry"); + cw->phone_entry = glade_xml_get_widget (xml, "phone_entry"); + cw->fax_entry = glade_xml_get_widget (xml, "fax_entry"); + cw->email_entry = glade_xml_get_widget (xml, "email_entry"); + + cw->shipname_entry = glade_xml_get_widget (xml, "shipname_entry"); + cw->shipaddr1_entry = glade_xml_get_widget (xml, "shipaddr1_entry"); + cw->shipaddr2_entry = glade_xml_get_widget (xml, "shipaddr2_entry"); + cw->shipaddr3_entry = glade_xml_get_widget (xml, "shipaddr3_entry"); + cw->shipaddr4_entry = glade_xml_get_widget (xml, "shipaddr4_entry"); + cw->shipphone_entry = glade_xml_get_widget (xml, "shipphone_entry"); + cw->shipfax_entry = glade_xml_get_widget (xml, "shipfax_entry"); + cw->shipemail_entry = glade_xml_get_widget (xml, "shipemail_entry"); + + cw->active_check = glade_xml_get_widget (xml, "active_check"); + cw->taxincluded_check = glade_xml_get_widget (xml, "tax_included_check"); + cw->notes_text = glade_xml_get_widget (xml, "notes_text"); + + /* TERMS: Integer Value */ + edit = gnc_amount_edit_new(); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); + print_info = gnc_integral_print_info (); + gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); + gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 1); + cw->terms_amount = edit; + gtk_widget_show (edit); + + hbox = glade_xml_get_widget (xml, "terms_box"); + gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + + /* DISCOUNT: Percentage Value */ + edit = gnc_amount_edit_new(); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); + print_info.max_decimal_places = 5; + gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); + gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000); + cw->discount_amount = edit; + gtk_widget_show (edit); + + hbox = glade_xml_get_widget (xml, "discount_box"); + gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + + /* CREDIT: Monetary Value */ + edit = gnc_amount_edit_new(); + commodity = gnc_default_currency (); + print_info = gnc_commodity_print_info (commodity, FALSE); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); + gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); + gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), + gnc_commodity_get_fraction (commodity)); + cw->credit_amount = edit; + gtk_widget_show (edit); + + hbox = glade_xml_get_widget (xml, "credit_box"); + gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + + /* Setup Dialog for Editing */ + gnome_dialog_set_default (cwd, 0); + + /* Attach to default button */ + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->id_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->company_entry)); + + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->name_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->addr1_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->addr2_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->addr3_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->addr4_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->phone_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->fax_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->email_entry)); + + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipname_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipaddr1_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipaddr2_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipaddr3_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipaddr4_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipphone_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipfax_entry)); + gnome_dialog_editable_enters (cwd, GTK_EDITABLE (cw->shipemail_entry)); + + /* Set focus to company name */ + gtk_widget_grab_focus (cw->company_entry); + + /* Setup signals */ + gnome_dialog_button_connect + (cwd, 0, GTK_SIGNAL_FUNC(gnc_customer_window_ok_cb), cw); + gnome_dialog_button_connect + (cwd, 1, GTK_SIGNAL_FUNC(gnc_customer_window_cancel_cb), cw); + gnome_dialog_button_connect + (cwd, 2, GTK_SIGNAL_FUNC(gnc_customer_window_help_cb), cw); + + gtk_signal_connect (GTK_OBJECT (cw->dialog), "destroy", + GTK_SIGNAL_FUNC(gnc_customer_window_destroy_cb), cw); + + gtk_signal_connect(GTK_OBJECT (cw->id_entry), "changed", + GTK_SIGNAL_FUNC(gnc_customer_name_changed_cb), cw); + + gtk_signal_connect(GTK_OBJECT (cw->company_entry), "changed", + GTK_SIGNAL_FUNC(gnc_customer_name_changed_cb), cw); + + /* Setup initial values */ + if (cust != NULL) { + GncAddress *addr, *shipaddr; + const char *string; + gint pos = 0; + + cw->dialog_type = EDIT_CUSTOMER; + cw->customer_guid = *gncCustomerGetGUID (cust); + + addr = gncCustomerGetAddr (cust); + shipaddr = gncCustomerGetShipAddr (cust); + + gtk_entry_set_text (GTK_ENTRY (cw->id_entry), gncCustomerGetID (cust)); + gtk_entry_set_editable (GTK_ENTRY (cw->id_entry), FALSE); + + gtk_entry_set_text (GTK_ENTRY (cw->company_entry), gncCustomerGetName (cust)); + + /* Setup Address */ + gtk_entry_set_text (GTK_ENTRY (cw->name_entry), gncAddressGetName (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->addr1_entry), gncAddressGetAddr1 (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->addr2_entry), gncAddressGetAddr2 (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->addr3_entry), gncAddressGetAddr3 (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->addr4_entry), gncAddressGetAddr4 (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->phone_entry), gncAddressGetPhone (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->fax_entry), gncAddressGetFax (addr)); + gtk_entry_set_text (GTK_ENTRY (cw->email_entry), gncAddressGetEmail (addr)); + + /* Setup Ship-to Address */ + gtk_entry_set_text (GTK_ENTRY (cw->shipname_entry), gncAddressGetName (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipaddr1_entry), gncAddressGetAddr1 (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipaddr2_entry), gncAddressGetAddr2 (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipaddr3_entry), gncAddressGetAddr3 (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipaddr4_entry), gncAddressGetAddr4 (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipphone_entry), gncAddressGetPhone (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipfax_entry), gncAddressGetFax (shipaddr)); + gtk_entry_set_text (GTK_ENTRY (cw->shipemail_entry), gncAddressGetEmail (shipaddr)); + + /* Set toggle buttons */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->active_check), + gncCustomerGetActive (cust)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cw->taxincluded_check), + gncCustomerGetTaxIncluded (cust)); + + string = gncCustomerGetNotes (cust); + gtk_editable_delete_text (GTK_EDITABLE (cw->notes_text), 0, -1); + gtk_editable_insert_text (GTK_EDITABLE (cw->notes_text), string, + strlen(string), &pos); + + cw->component_id = + gnc_register_gui_component (DIALOG_EDIT_CUSTOMER_CM_CLASS, + gnc_customer_window_refresh_handler, + gnc_customer_window_close_handler, + cw); + } else { + gnc_numeric num; + cust = gncCustomerCreate (bus); + cw->customer_guid = *gncCustomerGetGUID (cust); + + cw->dialog_type = NEW_CUSTOMER; + gtk_entry_set_text (GTK_ENTRY (cw->id_entry), + g_strdup_printf ("%.6d", gncCustomerNextID(bus))); + cw->component_id = + gnc_register_gui_component (DIALOG_NEW_CUSTOMER_CM_CLASS, + gnc_customer_window_refresh_handler, + gnc_customer_window_close_handler, + cw); + } + + + /* I know that cust exists here -- either passed in or just created */ + { + gnc_numeric terms; + + /* Set the Terms, Discount, and Credit amounts */ + terms = gnc_numeric_create (gncCustomerGetTerms (cust), 1); + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->terms_amount), terms); + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->discount_amount), + gncCustomerGetDiscount (cust)); + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (cw->credit_amount), + gncCustomerGetCredit (cust)); + } + + gnc_gui_component_watch_entity_type (cw->component_id, + GNC_ID_NONE, + GNC_EVENT_MODIFY | GNC_EVENT_DESTROY); + + gtk_widget_show_all (cw->dialog); + + return cw; +} + +GncCustomer * +gnc_customer_new (GtkWidget *parent, GncBusiness *bus) +{ + CustomerWindow *cw; + GncCustomer *created_customer = NULL; + + /* Make sure required options exist */ + if (!bus) return NULL; + + cw = gnc_customer_new_window (parent, bus, NULL); + + gtk_signal_connect (GTK_OBJECT (cw->dialog), "close", + GTK_SIGNAL_FUNC (gnc_customer_on_close_cb), + &created_customer); + + gtk_window_set_modal (GTK_WINDOW (cw->dialog), TRUE); + + gtk_main (); + + return created_customer; +} + +void +gnc_customer_edit (GtkWidget *parent, GncCustomer *cust) +{ + CustomerWindow *cw; + + if (!cust) return; + + cw = gnc_customer_new_window (parent, gncCustomerGetBusiness(cust), cust); + + gtk_signal_connect (GTK_OBJECT (cw->dialog), "close", + GTK_SIGNAL_FUNC (gnc_customer_on_close_cb), + NULL); + + gtk_window_set_modal (GTK_WINDOW (cw->dialog), TRUE); + + gtk_main (); + + return; +} + +/* Functions for widgets for customer selection */ + +static gpointer gnc_customer_edit_new_cb (gpointer arg, GtkWidget *toplevel) +{ + struct _customer_select_window *sw = arg; + + if (!arg) return NULL; + + return gnc_customer_new (toplevel, sw->business); +} + +static void gnc_customer_edit_edit_cb (gpointer arg, gpointer obj, GtkWidget *toplevel) +{ + GncCustomer *cust = obj; + struct _customer_select_window *sw = arg; + + if (!arg || !obj) return; + + gnc_customer_edit (toplevel, cust); +} + +gpointer gnc_customer_edit_new_select (gpointer bus, gpointer cust, + GtkWidget *toplevel) +{ + GncBusiness *business = bus; + struct _customer_select_window sw; + + g_return_val_if_fail (bus != NULL, NULL); + + sw.business = business; + + return + gnc_ui_business_chooser_new (toplevel, cust, + business, GNC_CUSTOMER_MODULE_NAME, + gnc_customer_edit_new_cb, + gnc_customer_edit_edit_cb, &sw); +} + +gpointer gnc_customer_edit_new_edit (gpointer bus, gpointer cust, + GtkWidget *toplevel) +{ + GncBusiness *busiess = bus; + GncCustomer *customer = cust; + + g_return_val_if_fail (cust != NULL, NULL); + + gnc_customer_edit (toplevel, cust); + return cust; +} diff --git a/src/business/business-gnome/dialog-customer.h b/src/business/business-gnome/dialog-customer.h new file mode 100644 index 0000000000..3538fca99d --- /dev/null +++ b/src/business/business-gnome/dialog-customer.h @@ -0,0 +1,27 @@ +/* + * dialog-customer.h -- Dialog(s) for Customer search and entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + + +#ifndef GNC_DIALOG_CUSTOMER_H_ +#define GNC_DIALOG_CUSTOMER_H_ + +/* Functions to create and edit customers */ +GncCustomer * gnc_customer_new (GtkWidget *parent, GncBusiness *bus); +void gnc_customer_edit (GtkWidget *parent, GncCustomer *cust); + +/* Callbacks to select a customer that match the necessary functions + * for use with the gnc_general_select widget. + * + * new_select provides a selection and the ability to create and edit + * customers. + * new_edit provides only the ability to edit the current selection + */ +gpointer gnc_customer_edit_new_select (gpointer bus, gpointer c, + GtkWidget *toplevel); +gpointer gnc_customer_edit_new_edit (gpointer bus, gpointer cust, + GtkWidget *toplevel); + +#endif /* GNC_DIALOG_CUSTOMER_H_ */ diff --git a/src/business/business-gnome/dialog-employee.c b/src/business/business-gnome/dialog-employee.c new file mode 100644 index 0000000000..35512011e2 --- /dev/null +++ b/src/business/business-gnome/dialog-employee.c @@ -0,0 +1,590 @@ +/* + * dialog-employee.c -- Dialog for Employee entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "global-options.h" +#include "gnc-amount-edit.h" +#include "gnc-component-manager.h" +#include "gnc-ui.h" +#include "gnc-gui-query.h" +#include "gnc-ui-util.h" +#include "gnc-engine-util.h" +#include "window-help.h" + +#include "gncBusiness.h" +#include "gncAddress.h" +#include "gncEmployee.h" +#include "gncEmployeeP.h" + +#include "dialog-employee.h" +#include "business-chooser.h" + +#define DIALOG_NEW_EMPLOYEE_CM_CLASS "dialog-new-employee" +#define DIALOG_EDIT_EMPLOYEE_CM_CLASS "dialog-edit-employee" + +typedef enum +{ + NEW_EMPLOYEE, + EDIT_EMPLOYEE +} EmployeeDialogType; + +struct _employee_select_window { + GncBusiness * business; +}; + +typedef struct _employee_window { + GtkWidget * dialog; + + GtkWidget * id_entry; + GtkWidget * username_entry; + + GtkWidget * name_entry; + GtkWidget * addr1_entry; + GtkWidget * addr2_entry; + GtkWidget * addr3_entry; + GtkWidget * addr4_entry; + GtkWidget * phone_entry; + GtkWidget * fax_entry; + GtkWidget * email_entry; + + GtkWidget * language_entry; + + GtkWidget * workday_amount; + GtkWidget * rate_amount; + + GtkWidget * active_check; + + /* ACL? */ + + EmployeeDialogType dialog_type; + GUID employee_guid; + gint component_id; + GncBusiness * business; + GncEmployee * created_employee; + +} EmployeeWindow; + +static GncEmployee * +ew_get_employee (EmployeeWindow *ew) +{ + if (!ew) + return NULL; + + return gncBusinessLookupGUID (ew->business, GNC_EMPLOYEE_MODULE_NAME, + &ew->employee_guid); +} + +static void gnc_ui_to_employee (EmployeeWindow *ew, GncEmployee *employee) +{ + GncAddress *addr; + gnc_numeric num; + + addr = gncEmployeeGetAddr (employee); + + gnc_suspend_gui_refresh (); + + gncEmployeeSetID (employee, gtk_editable_get_chars + (GTK_EDITABLE (ew->id_entry), 0, -1)); + gncEmployeeSetUsername (employee, gtk_editable_get_chars + (GTK_EDITABLE (ew->username_entry), 0, -1)); + + gncAddressSetName (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->name_entry), 0, -1)); + gncAddressSetAddr1 (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->addr1_entry), 0, -1)); + gncAddressSetAddr2 (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->addr2_entry), 0, -1)); + gncAddressSetAddr3 (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->addr3_entry), 0, -1)); + gncAddressSetAddr4 (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->addr4_entry), 0, -1)); + gncAddressSetPhone (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->phone_entry), 0, -1)); + gncAddressSetFax (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->fax_entry), 0, -1)); + gncAddressSetEmail (addr, gtk_editable_get_chars + (GTK_EDITABLE (ew->email_entry), 0, -1)); + + gncEmployeeSetActive (employee, gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (ew->active_check))); + gncEmployeeSetLanguage (employee, gtk_editable_get_chars + (GTK_EDITABLE (ew->language_entry), 0, -1)); + + /* Parse and set the workday and rate amounts */ + gncEmployeeSetWorkday (employee, gnc_amount_edit_get_amount + (GNC_AMOUNT_EDIT (ew->workday_amount))); + gncEmployeeSetRate (employee, gnc_amount_edit_get_amount + (GNC_AMOUNT_EDIT (ew->rate_amount))); + + gncEmployeeCommitEdit (employee); + gnc_resume_gui_refresh (); +} + +static gboolean check_edit_amount (GtkWidget *dialog, GtkWidget *amount, + gnc_numeric *min, gnc_numeric *max, + const char * error_message) +{ + if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount))) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + /* We've got a valid-looking number; check mix/max */ + if (min || max) { + gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount)); + if ((min && gnc_numeric_compare (*min, val) > 0) || + (max && gnc_numeric_compare (val, *max) > 0)) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + } + return FALSE; +} + +static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry, + const char * error_message) +{ + const char *res = gtk_entry_get_text (GTK_ENTRY (entry)); + if (safe_strcmp (res, "") == 0) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + return FALSE; +} + +static void +gnc_employee_window_ok_cb (GtkWidget *widget, gpointer data) +{ + EmployeeWindow *ew = data; + char *res; + GncEmployee *employee; + gnc_numeric min, max; + + /* Check for valid id */ + if (check_entry_nonempty (ew->dialog, ew->id_entry, + _("The Employee must be given an ID."))) + return; + + /* Check for valid username */ + if (check_entry_nonempty (ew->dialog, ew->username_entry, + _("You must enter a username."))) + return; + + /* Check for valid username */ + if (check_entry_nonempty (ew->dialog, ew->name_entry, + _("You must enter the employee's name."))) + return; + + /* Make sure we have an address */ + if (check_entry_nonempty (ew->dialog, ew->addr1_entry, NULL) && + check_entry_nonempty (ew->dialog, ew->addr2_entry, NULL) && + check_entry_nonempty (ew->dialog, ew->addr3_entry, NULL) && + check_entry_nonempty (ew->dialog, ew->addr4_entry, NULL)) { + const char *msg = _("You must enter an address."); + gnc_error_dialog_parented (GTK_WINDOW (ew->dialog), msg); + return; + } + + /* Now save it off */ + { + GncEmployee *employee = ew_get_employee (ew); + if (employee) { + gnc_ui_to_employee (ew, employee); + } + ew->created_employee = employee; + ew->employee_guid = *xaccGUIDNULL (); + } + + gnc_close_gui_component (ew->component_id); +} + +static void +gnc_employee_window_cancel_cb (GtkWidget *widget, gpointer data) +{ + EmployeeWindow *ew = data; + + gnc_close_gui_component (ew->component_id); +} + +static void +gnc_employee_window_help_cb (GtkWidget *widget, gpointer data) +{ + EmployeeWindow *ew = data; + char *help_file = ""; /* xxx */ + + helpWindow(NULL, NULL, help_file); +} + +static void +gnc_employee_window_destroy_cb (GtkWidget *widget, gpointer data) +{ + EmployeeWindow *ew = data; + GncEmployee *employee = ew_get_employee (ew); + + gnc_suspend_gui_refresh (); + + if (ew->dialog_type == NEW_EMPLOYEE && employee != NULL) { + gncEmployeeDestroy (employee); + ew->employee_guid = *xaccGUIDNULL (); + } + + gnc_unregister_gui_component (ew->component_id); + gnc_resume_gui_refresh (); + + g_free (ew); +} + +static void +gnc_employee_name_changed_cb (GtkWidget *widget, gpointer data) +{ + EmployeeWindow *ew = data; + char *name, *id, *fullname, *title; + + if (!ew) + return; + + name = gtk_entry_get_text (GTK_ENTRY (ew->name_entry)); + if (!name || *name == '\0') + name = _(""); + + id = gtk_entry_get_text (GTK_ENTRY (ew->id_entry)); + + fullname = g_strconcat (name, " (", id, ")", NULL); + + if (ew->dialog_type == EDIT_EMPLOYEE) + title = g_strconcat (_("Edit Employee"), " - ", fullname, NULL); + else + title = g_strconcat (_("New Employee"), " - ", fullname, NULL); + + gtk_window_set_title (GTK_WINDOW (ew->dialog), title); + + g_free (fullname); + g_free (title); +} + +static int +gnc_employee_on_close_cb (GnomeDialog *dialog, gpointer data) +{ + EmployeeWindow *ew; + GncEmployee **created_employee = data; + + if (data) { + ew = gtk_object_get_data (GTK_OBJECT (dialog), "dialog_info"); + *created_employee = ew->created_employee; + } + + gtk_main_quit (); + + return FALSE; +} + +static void +gnc_employee_window_close_handler (gpointer user_data) +{ + EmployeeWindow *ew = user_data; + + gnome_dialog_close (GNOME_DIALOG (ew->dialog)); +} + +static void +gnc_employee_window_refresh_handler (GHashTable *changes, gpointer user_data) +{ + EmployeeWindow *ew = user_data; + const EventInfo *info; + GncEmployee *employee = ew_get_employee (ew); + + /* If there isn't a employee behind us, close down */ + if (!employee) { + gnc_close_gui_component (ew->component_id); + return; + } + + /* Next, close if this is a destroy event */ + if (changes) { + info = gnc_gui_get_entity_events (changes, &ew->employee_guid); + if (info && (info->event_mask & GNC_EVENT_DESTROY)) { + gnc_close_gui_component (ew->component_id); + return; + } + } +} + +static EmployeeWindow * +gnc_employee_new_window (GtkWidget *parent, GncBusiness *bus, + GncEmployee *employee) +{ + EmployeeWindow *ew; + GladeXML *xml; + GtkWidget *hbox, *edit; + GnomeDialog *ewd; + gnc_commodity *commodity; + GNCPrintAmountInfo print_info; + + ew = g_new0 (EmployeeWindow, 1); + + ew->business = bus; + + /* Find the dialog */ + xml = gnc_glade_xml_new ("employee.glade", "Employee Dialog"); + ew->dialog = glade_xml_get_widget (xml, "Employee Dialog"); + ewd = GNOME_DIALOG (ew->dialog); + + gtk_object_set_data (GTK_OBJECT (ew->dialog), "dialog_info", ew); + + /* default to ok */ + gnome_dialog_set_default (ewd, 0); + + if (parent) + gnome_dialog_set_parent (ewd, GTK_WINDOW (parent)); + + /* Get entry points */ + ew->id_entry = glade_xml_get_widget (xml, "id_entry"); + ew->username_entry = glade_xml_get_widget (xml, "username_entry"); + + ew->name_entry = glade_xml_get_widget (xml, "name_entry"); + ew->addr1_entry = glade_xml_get_widget (xml, "addr1_entry"); + ew->addr2_entry = glade_xml_get_widget (xml, "addr2_entry"); + ew->addr3_entry = glade_xml_get_widget (xml, "addr3_entry"); + ew->addr4_entry = glade_xml_get_widget (xml, "addr4_entry"); + ew->phone_entry = glade_xml_get_widget (xml, "phone_entry"); + ew->fax_entry = glade_xml_get_widget (xml, "fax_entry"); + ew->email_entry = glade_xml_get_widget (xml, "email_entry"); + + ew->language_entry = glade_xml_get_widget (xml, "language_entry"); + ew->active_check = glade_xml_get_widget (xml, "active_check"); + + /* WORKDAY: Value */ + edit = gnc_amount_edit_new(); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); + print_info = gnc_integral_print_info (); + print_info.max_decimal_places = 5; + gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); + gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 100000); + ew->workday_amount = edit; + gtk_widget_show (edit); + + hbox = glade_xml_get_widget (xml, "hours_hbox"); + gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + + /* RATE: Monetary Value */ + edit = gnc_amount_edit_new(); + commodity = gnc_default_currency (); + print_info = gnc_commodity_print_info (commodity, FALSE); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); + gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); + gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), + gnc_commodity_get_fraction (commodity)); + ew->rate_amount = edit; + gtk_widget_show (edit); + + hbox = glade_xml_get_widget (xml, "rate_hbox"); + gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + + /* Setup Dialog for Editing */ + gnome_dialog_set_default (ewd, 0); + + /* Attach to default button */ + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->id_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->username_entry)); + + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->name_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->addr1_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->addr2_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->addr3_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->addr4_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->phone_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->fax_entry)); + gnome_dialog_editable_enters (ewd, GTK_EDITABLE (ew->email_entry)); + + /* Set focus to username */ + gtk_widget_grab_focus (ew->username_entry); + + /* Setup signals */ + gnome_dialog_button_connect + (ewd, 0, GTK_SIGNAL_FUNC(gnc_employee_window_ok_cb), ew); + gnome_dialog_button_connect + (ewd, 1, GTK_SIGNAL_FUNC(gnc_employee_window_cancel_cb), ew); + gnome_dialog_button_connect + (ewd, 2, GTK_SIGNAL_FUNC(gnc_employee_window_help_cb), ew); + + gtk_signal_connect (GTK_OBJECT (ew->dialog), "destroy", + GTK_SIGNAL_FUNC(gnc_employee_window_destroy_cb), ew); + + gtk_signal_connect(GTK_OBJECT (ew->id_entry), "changed", + GTK_SIGNAL_FUNC(gnc_employee_name_changed_cb), ew); + + gtk_signal_connect(GTK_OBJECT (ew->username_entry), "changed", + GTK_SIGNAL_FUNC(gnc_employee_name_changed_cb), ew); + + /* Setup initial values */ + if (employee != NULL) { + GncAddress *addr; + const char *string; + gint pos = 0; + + ew->dialog_type = EDIT_EMPLOYEE; + ew->employee_guid = *gncEmployeeGetGUID (employee); + + addr = gncEmployeeGetAddr (employee); + + gtk_entry_set_text (GTK_ENTRY (ew->id_entry), gncEmployeeGetID (employee)); + gtk_entry_set_editable (GTK_ENTRY (ew->id_entry), FALSE); + + gtk_entry_set_text (GTK_ENTRY (ew->username_entry), gncEmployeeGetUsername (employee)); + + /* Setup Address */ + gtk_entry_set_text (GTK_ENTRY (ew->name_entry), gncAddressGetName (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->addr1_entry), gncAddressGetAddr1 (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->addr2_entry), gncAddressGetAddr2 (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->addr3_entry), gncAddressGetAddr3 (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->addr4_entry), gncAddressGetAddr4 (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->phone_entry), gncAddressGetPhone (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->fax_entry), gncAddressGetFax (addr)); + gtk_entry_set_text (GTK_ENTRY (ew->email_entry), gncAddressGetEmail (addr)); + + gtk_entry_set_text (GTK_ENTRY (ew->language_entry), + gncEmployeeGetLanguage (employee)); + + /* Set toggle buttons */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ew->active_check), + gncEmployeeGetActive (employee)); + + ew->component_id = + gnc_register_gui_component (DIALOG_EDIT_EMPLOYEE_CM_CLASS, + gnc_employee_window_refresh_handler, + gnc_employee_window_close_handler, + ew); + } else { + gnc_numeric num; + employee = gncEmployeeCreate (bus); + ew->employee_guid = *gncEmployeeGetGUID (employee); + + ew->dialog_type = NEW_EMPLOYEE; + gtk_entry_set_text (GTK_ENTRY (ew->id_entry), + g_strdup_printf ("%.6d", gncEmployeeNextID(bus))); + ew->component_id = + gnc_register_gui_component (DIALOG_NEW_EMPLOYEE_CM_CLASS, + gnc_employee_window_refresh_handler, + gnc_employee_window_close_handler, + ew); + } + + + /* I know that employee exists here -- either passed in or just created */ + /* Set the workday and rate values */ + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ew->workday_amount), + gncEmployeeGetWorkday (employee)); + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (ew->rate_amount), + gncEmployeeGetRate (employee)); + + /* XXX: Set the ACL */ + + gnc_gui_component_watch_entity_type (ew->component_id, + GNC_ID_NONE, + GNC_EVENT_MODIFY | GNC_EVENT_DESTROY); + + gtk_widget_show_all (ew->dialog); + + return ew; +} + +GncEmployee * +gnc_employee_new (GtkWidget *parent, GncBusiness *bus) +{ + EmployeeWindow *ew; + GncEmployee *created_employee = NULL; + + /* Make sure required options exist */ + if (!bus) return NULL; + + ew = gnc_employee_new_window (parent, bus, NULL); + + gtk_signal_connect (GTK_OBJECT (ew->dialog), "close", + GTK_SIGNAL_FUNC (gnc_employee_on_close_cb), + &created_employee); + + gtk_window_set_modal (GTK_WINDOW (ew->dialog), TRUE); + + gtk_main (); + + return created_employee; +} + +void +gnc_employee_edit (GtkWidget *parent, GncEmployee *employee) +{ + EmployeeWindow *ew; + + if (!employee) return; + + ew = gnc_employee_new_window (parent, gncEmployeeGetBusiness(employee), employee); + + gtk_signal_connect (GTK_OBJECT (ew->dialog), "close", + GTK_SIGNAL_FUNC (gnc_employee_on_close_cb), + NULL); + + gtk_window_set_modal (GTK_WINDOW (ew->dialog), TRUE); + + gtk_main (); + + return; +} + +/* Functions for widgets for employee selection */ + +static gpointer gnc_employee_edit_new_cb (gpointer arg, GtkWidget *toplevel) +{ + struct _employee_select_window *sw = arg; + + if (!arg) return NULL; + + return gnc_employee_new (toplevel, sw->business); +} + +static void gnc_employee_edit_edit_cb (gpointer arg, gpointer obj, GtkWidget *toplevel) +{ + GncEmployee *employee = obj; + struct _employee_select_window *sw = arg; + + if (!arg || !obj) return; + + gnc_employee_edit (toplevel, employee); +} + +gpointer gnc_employee_edit_new_select (gpointer bus, gpointer employee, + GtkWidget *toplevel) +{ + GncBusiness *business = bus; + struct _employee_select_window sw; + + g_return_val_if_fail (bus != NULL, NULL); + + sw.business = business; + + return + gnc_ui_business_chooser_new (toplevel, employee, + business, GNC_EMPLOYEE_MODULE_NAME, + gnc_employee_edit_new_cb, + gnc_employee_edit_edit_cb, &sw); +} + +gpointer gnc_employee_edit_new_edit (gpointer bus, gpointer v, + GtkWidget *toplevel) +{ + GncBusiness *busiess = bus; + GncEmployee *employee = v; + + g_return_val_if_fail (employee != NULL, NULL); + + gnc_employee_edit (toplevel, employee); + return employee; +} diff --git a/src/business/business-gnome/dialog-employee.h b/src/business/business-gnome/dialog-employee.h new file mode 100644 index 0000000000..6ea10e3421 --- /dev/null +++ b/src/business/business-gnome/dialog-employee.h @@ -0,0 +1,27 @@ +/* + * dialog-employee.h -- Dialog(s) for Employee search and entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + + +#ifndef GNC_DIALOG_EMPLOYEE_H_ +#define GNC_DIALOG_EMPLOYEE_H_ + +/* Functions to create and edit employees */ +GncEmployee * gnc_employee_new (GtkWidget *parent, GncBusiness *bus); +void gnc_employee_edit (GtkWidget *parent, GncEmployee *employee); + +/* Callbacks to select a employee that match the necessary functions + * for use with the gnc_general_select widget. + * + * new_select provides a selection and the ability to create and edit + * employees. + * new_edit provides only the ability to edit the current selection + */ +gpointer gnc_employee_edit_new_select (gpointer bus, gpointer c, + GtkWidget *toplevel); +gpointer gnc_employee_edit_new_edit (gpointer bus, gpointer employee, + GtkWidget *toplevel); + +#endif /* GNC_DIALOG_EMPLOYEE_H_ */ diff --git a/src/business/business-gnome/dialog-job-select.c b/src/business/business-gnome/dialog-job-select.c new file mode 100644 index 0000000000..21aa608256 --- /dev/null +++ b/src/business/business-gnome/dialog-job-select.c @@ -0,0 +1,344 @@ +/* + * dialog-job-select.c -- Job Selection Dialog for GNC Business Objects + * + * Written By: Derek Atkins + * Copyright (C) 2001 + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "gnc-ui.h" +#include "gnc-gui-query.h" + +#include "gncBusiness.h" +#include "gncCustomer.h" +#include "gncJob.h" +#include "dialog-job-select.h" +#include "dialog-job.h" + +struct select_job_window { + GtkWidget * dialog; + GtkWidget * customer_combo; + GtkWidget * customer_entry; + GtkWidget * job_combo; + GtkWidget * job_entry; + GtkWidget * showcust_check; + GtkWidget * showjobs_check; + + GncBusiness * business; + GncCustomer * customer; + GncJob * job; + + const GncBusinessObject *job_type, *cust_type; +}; + + +static void +update_job_select_picker (struct select_job_window *w) +{ + GList *objs = NULL, *iterator; + GtkWidget *li; + GncJob *saved_job; + gboolean show_all = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (w->showjobs_check)); + + /* Clear out the existing choices */ + gtk_list_clear_items (GTK_LIST (GTK_COMBO (w->job_combo)->list), 0, -1); + + /* Get the list of objects */ + if (w->customer == NULL) { + w->job = NULL; + } else { + /* Save the current job */ + saved_job = w->job; + + objs = gncCustomerGetJoblist (w->customer, show_all); + + /* Build a list of strings (objs is pre-sorted, so keep the order!) */ + for (iterator = objs; iterator; iterator = iterator->next) { + const gchar *label = (*(w->job_type->printable))(iterator->data); + + li = gtk_list_item_new_with_label (label); + gtk_object_set_data (GTK_OBJECT (li), "item-list-pointer", iterator->data); + gtk_widget_show (li); + gtk_container_add (GTK_CONTAINER (GTK_COMBO (w->job_combo)->list), li); + } + + /* And revert */ + w->job = saved_job; + } + + /* No job list. Eit */ + if (!objs) + w->job = NULL; + + else if (g_list_index (objs, w->job) == -1) { + /* job doesn't exist anymore!?! Choose something reasonable */ + w->job = objs->data; + } + + /* And set the text label */ + { + const char * label; + if (w->job) + label = (*(w->job_type->printable))(w->job); + else + label = ""; + + gtk_entry_set_text (GTK_ENTRY (w->job_entry), label); + } + + g_list_free (objs); +} + +static void +update_customer_select_picker (struct select_job_window *w) +{ + GList *custs, *iterator; + GtkWidget *li; + GncCustomer * saved_cust; + gboolean show_all = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (w->showcust_check)); + + /* Clear out the existing choices */ + gtk_list_clear_items (GTK_LIST (GTK_COMBO (w->customer_combo)->list), 0, -1); + + /* Save the existing selection */ + saved_cust = w->customer; + + /* Get the list of objects */ + custs = (*(w->cust_type->get_list))(w->business, show_all); + + /* Build a list of strings (objs is pre-sorted, so keep the order!) */ + for (iterator = custs; iterator; iterator = iterator->next) { + const gchar *label = (*(w->cust_type->printable))(iterator->data); + + li = gtk_list_item_new_with_label (label); + gtk_object_set_data (GTK_OBJECT (li), "item-list-pointer", iterator->data); + gtk_widget_show (li); + gtk_container_add (GTK_CONTAINER (GTK_COMBO (w->customer_combo)->list), li); + } + + /* Revert the saved customer */ + w->customer = saved_cust; + + if (! custs) { + /* no customers -- update the job picker (it will clear itself) */ + + w->customer = NULL; + update_job_select_picker (w); + + } else if (g_list_index (custs, w->customer) == -1) { + /* customer doesn't exist anymore!?! Clear out the job, too */ + + w->customer = custs->data; + update_job_select_picker (w); + } + + /* And now set the current-selected item */ + { + const char * label; + + if (w->customer) + label = (*(w->cust_type->printable))(w->customer); + else + label = ""; + + gtk_entry_set_text (GTK_ENTRY (w->customer_entry), label); + } + + g_list_free (custs); +} + +static void +select_job_customer_changed_cb(GtkList *list, GtkWidget *li, + gpointer user_data) +{ + struct select_job_window * w = user_data; + GList *node; + + if (!li) + return; + + w->customer = gtk_object_get_data (GTK_OBJECT (li), "item-list-pointer"); + w->job = NULL; + update_job_select_picker (w); +} + +static void +select_job_job_changed_cb(GtkList *list, GtkWidget *li, gpointer user_data) +{ + struct select_job_window * w = user_data; + GList *node; + + if (!li) + return; + + w->job = gtk_object_get_data (GTK_OBJECT (li), "item-list-pointer"); +} + +static void +gnc_ui_select_job_ok_cb(GtkButton * button, gpointer user_data) +{ + struct select_job_window * w = user_data; + + if(w->job) { + gnome_dialog_close(GNOME_DIALOG (w->dialog)); + } else { + gnc_warning_dialog(_("You must select a job.\n" + "To create a new one, click \"New\"")); + } +} + +static void +gnc_ui_select_job_new_cb(GtkButton * button, gpointer user_data) +{ + struct select_job_window * w = user_data; + GncJob * new_selection = gnc_job_new (w->dialog, w->business, w->customer); + + if (new_selection) { + w->customer = gncJobGetCustomer (new_selection); + update_customer_select_picker (w); + w->job = new_selection; + update_job_select_picker (w); + } +} + +static void +gnc_ui_select_job_edit_cb(GtkButton * button, gpointer user_data) +{ + struct select_job_window * w = user_data; + + if (w->job == NULL) + return; + + gnc_job_edit (w->dialog, w->job); + w->customer = gncJobGetCustomer (w->job); + update_customer_select_picker (w); + update_job_select_picker (w); +} + +static void +gnc_ui_select_job_cancel_cb(GtkButton * button, gpointer user_data) +{ + struct select_job_window * w = user_data; + + if (w) + gnome_dialog_close(GNOME_DIALOG (w->dialog)); +} + +static void +gnc_ui_select_job_showcust_toggled_cb(GtkCheckButton * entry, + gpointer user_data) +{ + struct select_job_window * w = user_data; + + update_customer_select_picker (w); +} + +static void +gnc_ui_select_job_showjobs_toggled_cb(GtkCheckButton * entry, + gpointer user_data) +{ + struct select_job_window * w = user_data; + + update_job_select_picker (w); +} + +static gint +select_job_close (GnomeDialog *dialog, gpointer data) +{ + gtk_main_quit (); + return FALSE; +} + +GncJob * +gnc_ui_select_job_new (GtkWidget * parent, GncBusiness *business, + GncCustomer *cust, GncJob *job) +{ + struct select_job_window * win = + g_new0(struct select_job_window, 1); + GladeXML *xml; + GtkWidget *choice_name_label; + GncJob *retval; + + g_return_val_if_fail (business != NULL, NULL); + win->business = business; + + win->cust_type = gncBusinessLookup (GNC_CUSTOMER_MODULE_NAME); + win->job_type = gncBusinessLookup (GNC_JOB_MODULE_NAME); + + xml = gnc_glade_xml_new ("job.glade", + "Job Selector Dialog"); + + /* Grab the widgets */ + + win->dialog = glade_xml_get_widget (xml, "Job Selector Dialog"); + win->customer_combo = glade_xml_get_widget (xml, "customer_combo"); + win->customer_entry = glade_xml_get_widget (xml, "customer_entry"); + win->showcust_check = glade_xml_get_widget (xml, "showcust_check"); + win->job_combo = glade_xml_get_widget (xml, "job_combo"); + win->job_entry = glade_xml_get_widget (xml, "job_entry"); + win->showjobs_check = glade_xml_get_widget (xml, "showjobs_check"); + + if(parent) { + gnome_dialog_set_parent(GNOME_DIALOG(win->dialog), GTK_WINDOW(parent)); + } + + /* Setup the signals */ + glade_xml_signal_connect_data + (xml, "gnc_ui_select_job_ok_cb", + GTK_SIGNAL_FUNC (gnc_ui_select_job_ok_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_select_job_new_cb", + GTK_SIGNAL_FUNC (gnc_ui_select_job_new_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_select_job_edit_cb", + GTK_SIGNAL_FUNC (gnc_ui_select_job_edit_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_select_job_cancel_cb", + GTK_SIGNAL_FUNC (gnc_ui_select_job_cancel_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_select_job_showjobs_toggled_cb", + GTK_SIGNAL_FUNC (gnc_ui_select_job_showjobs_toggled_cb), win); + + glade_xml_signal_connect_data + (xml, "gnc_ui_select_job_showcust_toggled_cb", + GTK_SIGNAL_FUNC (gnc_ui_select_job_showcust_toggled_cb), win); + + gtk_signal_connect (GTK_OBJECT (GTK_COMBO (win->customer_combo)->list), + "select-child", + GTK_SIGNAL_FUNC(select_job_customer_changed_cb), win); + + gtk_signal_connect (GTK_OBJECT (GTK_COMBO (win->job_combo)->list), + "select-child", + GTK_SIGNAL_FUNC(select_job_job_changed_cb), win); + + gtk_signal_connect (GTK_OBJECT(win->dialog), "close", + GTK_SIGNAL_FUNC(select_job_close), win); + + /* Setup the menu */ + win->customer = cust; + update_customer_select_picker (win); + win->job = job; + update_job_select_picker (win); + + /* Run the widget */ + gtk_window_set_modal(GTK_WINDOW(win->dialog), TRUE); + gtk_widget_show (win->dialog); + gtk_main(); + + /* exit */ + retval = win->job; + g_free(win); + + return retval; +} + diff --git a/src/business/business-gnome/dialog-job-select.h b/src/business/business-gnome/dialog-job-select.h new file mode 100644 index 0000000000..2e0da95e08 --- /dev/null +++ b/src/business/business-gnome/dialog-job-select.h @@ -0,0 +1,18 @@ +/* + * dialog-job-select.h -- Job Selection Dialog for GNC Business Objects + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + + +#ifndef GNC_DIALOG_JOB_SELECT_H_ +#define GNC_DIALOG_JOB_SELECT_H_ + +/* Create a dialog to select a job based upon potentially-existing + * customer and jobs. Allows creation of both jobs and customers. + */ +GncJob * +gnc_ui_select_job_new (GtkWidget * parent, GncBusiness *business, + GncCustomer *cust, GncJob *job); + +#endif /* GNC_DIALOG_JOB_SELECT_H_ */ diff --git a/src/business/business-gnome/dialog-job.c b/src/business/business-gnome/dialog-job.c new file mode 100644 index 0000000000..78239c61d5 --- /dev/null +++ b/src/business/business-gnome/dialog-job.c @@ -0,0 +1,461 @@ +/* + * dialog-job.c -- Dialog for Job entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "gnc-component-manager.h" +#include "gnc-ui.h" +#include "gnc-gui-query.h" +#include "gnc-engine-util.h" +#include "window-help.h" + +#include "gncBusiness.h" +#include "gncCustomer.h" +#include "gncJob.h" +#include "gncJobP.h" + +#include "gnc-general-select.h" +#include "dialog-customer.h" +#include "business-chooser.h" +#include "dialog-job-select.h" + +#define DIALOG_NEW_JOB_CM_CLASS "dialog-new-job" +#define DIALOG_EDIT_JOB_CM_CLASS "dialog-edit-job" + +typedef enum +{ + NEW_JOB, + EDIT_JOB +} JobDialogType; + +struct _job_select_window { + GtkWidget * toplevel; + GncBusiness * business; +}; + +typedef struct _job_window { + GtkWidget * dialog; + GtkWidget * id_entry; + GtkWidget * cust_edit; + GtkWidget * name_entry; + GtkWidget * desc_entry; + GtkWidget * active_check; + + JobDialogType dialog_type; + GUID job_guid; + gint component_id; + GncBusiness * business; + GncJob * created_job; + + GNCGeneralSelectGetStringCB cust_print; + +} JobWindow; + +static GncJob * +jw_get_job (JobWindow *jw) +{ + if (!jw) + return NULL; + + return gncBusinessLookupGUID (jw->business, GNC_JOB_MODULE_NAME, + &jw->job_guid); +} + +static void gnc_ui_to_job (JobWindow *jw, GncJob *job) +{ + gnc_suspend_gui_refresh (); + gncJobSetID (job, gtk_editable_get_chars (GTK_EDITABLE (jw->id_entry), + 0, -1)); + gncJobSetName (job, gtk_editable_get_chars (GTK_EDITABLE (jw->name_entry), + 0, -1)); + gncJobSetDesc (job, gtk_editable_get_chars (GTK_EDITABLE (jw->desc_entry), + 0, -1)); + gncJobSetActive (job, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON + (jw->active_check))); + { + GncCustomer *old = gncJobGetCustomer (job); + GncCustomer *new = gnc_general_select_get_selected (GNC_GENERAL_SELECT + (jw->cust_edit)); + if (old != new) + gncJobSetCustomer (job, new); + } + + gncJobCommitEdit (job); + gnc_resume_gui_refresh (); +} + +static void +gnc_job_window_ok_cb (GtkWidget *widget, gpointer data) +{ + JobWindow *jw = data; + char *res; + GncCustomer *cust; + + /* Check for valid id */ + res = gtk_entry_get_text (GTK_ENTRY (jw->id_entry)); + if (safe_strcmp (res, "") == 0) { + const char *message = _("The Job must be given an ID."); + gnc_error_dialog_parented(GTK_WINDOW(jw->dialog), message); + return; + } + + /* Check for valid name */ + res = gtk_entry_get_text (GTK_ENTRY (jw->name_entry)); + if (safe_strcmp (res, "") == 0) { + const char *message = _("The Job must be given a name."); + gnc_error_dialog_parented(GTK_WINDOW(jw->dialog), message); + return; + } + + /* Check for customer */ + cust = gnc_general_select_get_selected (GNC_GENERAL_SELECT (jw->cust_edit)); + if (!cust) { + const char *message = _("You must choose a customer."); + gnc_error_dialog_parented(GTK_WINDOW(jw->dialog), message); + return; + } + + /* Now save it off */ + { + GncJob *job = jw_get_job (jw); + if (job) { + gnc_ui_to_job (jw, job); + } + jw->created_job = job; + jw->job_guid = *xaccGUIDNULL (); + } + + gnc_close_gui_component (jw->component_id); +} + +static void +gnc_job_window_cancel_cb (GtkWidget *widget, gpointer data) +{ + JobWindow *jw = data; + + gnc_close_gui_component (jw->component_id); +} + +static void +gnc_job_window_help_cb (GtkWidget *widget, gpointer data) +{ + JobWindow *jw = data; + char *help_file = ""; /* xxx */ + + /* XXX */ + + helpWindow(NULL, NULL, help_file); +} + +static void +gnc_job_window_destroy_cb (GtkWidget *widget, gpointer data) +{ + JobWindow *jw = data; + GncJob *job = jw_get_job (jw); + + gnc_suspend_gui_refresh (); + + if (jw->dialog_type == NEW_JOB && job != NULL) { + gncJobDestroy (job); + jw->job_guid = *xaccGUIDNULL (); + } + + gnc_unregister_gui_component (jw->component_id); + gnc_resume_gui_refresh (); + + g_free (jw); +} + +static void +gnc_job_name_changed_cb (GtkWidget *widget, gpointer data) +{ + JobWindow *jw = data; + char *name, *id, *fullname, *title; + + if (!jw) + return; + + name = gtk_entry_get_text (GTK_ENTRY (jw->name_entry)); + if (!name || *name == '\0') + name = _(""); + + id = gtk_entry_get_text (GTK_ENTRY (jw->id_entry)); + + fullname = g_strconcat (name, " (", id, ")", NULL); + + if (jw->dialog_type == EDIT_JOB) + title = g_strconcat (_("Edit Job"), " - ", fullname, NULL); + else + title = g_strconcat (_("New Job"), " - ", fullname, NULL); + + gtk_window_set_title (GTK_WINDOW (jw->dialog), title); + + g_free (fullname); + g_free (title); +} + +static int +gnc_job_on_close_cb (GnomeDialog *dialog, gpointer data) +{ + JobWindow *jw; + GncJob **created_job = data; + + if (data) { + jw = gtk_object_get_data (GTK_OBJECT (dialog), "dialog_info"); + *created_job = jw->created_job; + } + + gtk_main_quit (); + + return FALSE; +} + +static void +gnc_job_window_close_handler (gpointer user_data) +{ + JobWindow *jw = user_data; + + gnome_dialog_close (GNOME_DIALOG (jw->dialog)); +} + +static void +gnc_job_window_refresh_handler (GHashTable *changes, gpointer user_data) +{ + JobWindow *jw = user_data; + const EventInfo *info; + GncJob *job = jw_get_job (jw); + + /* If there isn't a job behind us, close down */ + if (!job) { + gnc_close_gui_component (jw->component_id); + return; + } + + /* Next, close if this is a destroy event */ + if (changes) { + info = gnc_gui_get_entity_events (changes, &jw->job_guid); + if (info && (info->event_mask & GNC_EVENT_DESTROY)) { + gnc_close_gui_component (jw->component_id); + return; + } + } +} + +static JobWindow * +gnc_job_new_window (GtkWidget *parent, GncBusiness *bus, GncCustomer *cust, + GncJob *job) +{ + JobWindow *jw; + GladeXML *xml; + GtkWidget *cust_box; + GnomeDialog *jwd; + GtkObject *jwo; + + jw = g_new0 (JobWindow, 1); + jw->business = bus; + + /* Load the XML */ + xml = gnc_glade_xml_new ("job.glade", "Job Dialog"); + + /* Find the dialog */ + jw->dialog = glade_xml_get_widget (xml, "Job Dialog"); + jwo = GTK_OBJECT (jw->dialog); + jwd = GNOME_DIALOG (jwo); + + gtk_object_set_data (jwo, "dialog_info", jw); + + /* default to ok XXX */ + gnome_dialog_set_default (jwd, 0); + + if (parent) + gnome_dialog_set_parent (jwd, GTK_WINDOW (parent)); + + /* Get entry points */ + jw->id_entry = glade_xml_get_widget (xml, "id_entry"); + jw->name_entry = glade_xml_get_widget (xml, "name_entry"); + jw->desc_entry = glade_xml_get_widget (xml, "desc_entry"); + jw->active_check = glade_xml_get_widget (xml, "active_check"); + + cust_box = glade_xml_get_widget (xml, "customer_hbox"); + + /* Setup signals (XXX) */ + gnome_dialog_button_connect (jwd, 0, + GTK_SIGNAL_FUNC(gnc_job_window_ok_cb), jw); + gnome_dialog_button_connect (jwd, 1, + GTK_SIGNAL_FUNC(gnc_job_window_cancel_cb), jw); + gnome_dialog_button_connect (jwd, 2, + GTK_SIGNAL_FUNC(gnc_job_window_help_cb), jw); + + gtk_signal_connect (jwo, "destroy", + GTK_SIGNAL_FUNC(gnc_job_window_destroy_cb), jw); + + gtk_signal_connect(GTK_OBJECT (jw->id_entry), "changed", + GTK_SIGNAL_FUNC(gnc_job_name_changed_cb), jw); + + gtk_signal_connect(GTK_OBJECT (jw->name_entry), "changed", + GTK_SIGNAL_FUNC(gnc_job_name_changed_cb), jw); + + /* grab the printable routine */ + { + const GncBusinessObject *obj = + gncBusinessLookup (GNC_CUSTOMER_MODULE_NAME); + if (!obj) + printf ("NO CUSTOMER OBJECT LOADED"); + jw->cust_print = obj->printable; + } + + /* Attach to default button */ + gnome_dialog_editable_enters (jwd, GTK_EDITABLE (jw->id_entry)); + gnome_dialog_editable_enters (jwd, GTK_EDITABLE (jw->name_entry)); + gnome_dialog_editable_enters (jwd, GTK_EDITABLE (jw->desc_entry)); + + /* Start at the name */ + gtk_widget_grab_focus (jw->name_entry); + + /* Set initial entries */ + if (job != NULL) { + jw->job_guid = *gncJobGetGUID (job); + + jw->dialog_type = EDIT_JOB; + jw->cust_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_EDIT, + jw->cust_print, + gnc_customer_edit_new_edit, bus); + gtk_box_pack_start(GTK_BOX(cust_box), jw->cust_edit, TRUE, TRUE, 0); + + gtk_entry_set_text (GTK_ENTRY (jw->id_entry), gncJobGetID (job)); + gtk_entry_set_editable (GTK_ENTRY (jw->id_entry), FALSE); + gtk_entry_set_text (GTK_ENTRY (jw->name_entry), gncJobGetName (job)); + gtk_entry_set_text (GTK_ENTRY (jw->desc_entry), gncJobGetDesc (job)); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (jw->active_check), + gncJobGetActive (job)); + gnc_general_select_set_selected (GNC_GENERAL_SELECT(jw->cust_edit), + gncJobGetCustomer(job)); + + jw->component_id = gnc_register_gui_component (DIALOG_EDIT_JOB_CM_CLASS, + gnc_job_window_refresh_handler, + gnc_job_window_close_handler, + jw); + } else { + job = gncJobCreate (bus); + jw->job_guid = *gncJobGetGUID (job); + + jw->dialog_type = NEW_JOB; + jw->cust_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT, + jw->cust_print, + gnc_customer_edit_new_select, bus); + gtk_box_pack_start(GTK_BOX(cust_box), jw->cust_edit, TRUE, TRUE, 0); + + gtk_entry_set_text (GTK_ENTRY (jw->id_entry), + g_strdup_printf ("%.6d", gncJobNextID(bus))); + + gnc_general_select_set_selected (GNC_GENERAL_SELECT(jw->cust_edit), + cust); + jw->component_id = gnc_register_gui_component (DIALOG_NEW_JOB_CM_CLASS, + gnc_job_window_refresh_handler, + gnc_job_window_close_handler, + jw); + } + + gnc_job_name_changed_cb (NULL, jw); + gnc_gui_component_watch_entity_type (jw->component_id, + GNC_ID_NONE, + GNC_EVENT_MODIFY | GNC_EVENT_DESTROY); + + gtk_widget_show_all (jw->dialog); + + return jw; +} + +GncJob * +gnc_job_new (GtkWidget *parent, GncBusiness *bus, GncCustomer *customer) +{ + JobWindow *jw; + GncJob *created_job = NULL; + + /* Make sure required options exist */ + if (!bus) return NULL; + + jw = gnc_job_new_window (parent, bus, customer, NULL); + + gtk_signal_connect (GTK_OBJECT (jw->dialog), "close", + GTK_SIGNAL_FUNC (gnc_job_on_close_cb), &created_job); + + gtk_window_set_modal (GTK_WINDOW (jw->dialog), TRUE); + + gtk_main (); + + return created_job; +} + +void +gnc_job_edit (GtkWidget *parent, GncJob *job) +{ + JobWindow *jw; + + if (!job) return; + + jw = gnc_job_new_window (parent, gncJobGetBusiness(job), + gncJobGetCustomer(job), job); + + gtk_signal_connect (GTK_OBJECT (jw->dialog), "close", + GTK_SIGNAL_FUNC (gnc_job_on_close_cb), NULL); + + gtk_window_set_modal (GTK_WINDOW (jw->dialog), TRUE); + + gtk_main (); + + return; +} + +/* Functions for widgets for job selection */ + +static gpointer gnc_job_edit_new_cb (gpointer arg) +{ + struct _job_select_window *sw = arg; + + return gnc_job_new (sw->toplevel, sw->business, NULL); +} + +static void gnc_job_edit_edit_cb (gpointer arg, gpointer obj) +{ + GncJob *job = obj; + struct _job_select_window *sw = arg; + + g_return_if_fail (arg != NULL); + g_return_if_fail (obj != NULL); + + gnc_job_edit (sw->toplevel, job); +} + +gpointer gnc_job_edit_new_select (gpointer job, GtkWidget *toplevel, + GncCustomer *cust) +{ + GncBusiness *business; + GncJob *j = job; + struct _job_select_window sw; + + if (!cust) return NULL; + + business = gncCustomerGetBusiness (cust); + sw.toplevel = toplevel; + sw.business = business; + + + return + gnc_ui_select_job_new (toplevel, business, cust, j); + + /* + return + gnc_ui_business_chooser_new (toplevel, job, + gncBusinessLookup (business, + GNC_JOB_MODULE_NAME), + gnc_job_edit_new_cb, + gnc_job_edit_edit_cb, &sw, cust); + */ +} diff --git a/src/business/business-gnome/dialog-job.h b/src/business/business-gnome/dialog-job.h new file mode 100644 index 0000000000..b48ac9040a --- /dev/null +++ b/src/business/business-gnome/dialog-job.h @@ -0,0 +1,22 @@ +/* + * dialog-job.h -- Dialog(s) for Job search and entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + + +#ifndef GNC_DIALOG_JOB_H_ +#define GNC_DIALOG_JOB_H_ + +/* Functions to create and edit jobs */ +GncJob * gnc_job_new (GtkWidget *parent, GncBusiness *bus, GncCustomer *cust); +void gnc_job_edit (GtkWidget *parent, GncJob *job); + +/* Callback to choose a job from a customer, for use with the + * general-select widget. Provides both "new" and "edit" buttons. + */ +gpointer gnc_job_edit_new_select (gpointer start_job, + GtkWidget *toplevel, + GncCustomer *cust); + +#endif /* GNC_DIALOG_JOB_H_ */ diff --git a/src/business/business-gnome/dialog-vendor.c b/src/business/business-gnome/dialog-vendor.c new file mode 100644 index 0000000000..d1f0bb0884 --- /dev/null +++ b/src/business/business-gnome/dialog-vendor.c @@ -0,0 +1,580 @@ +/* + * dialog-vendor.c -- Dialog for Vendor entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "global-options.h" +#include "gnc-amount-edit.h" +#include "gnc-component-manager.h" +#include "gnc-ui.h" +#include "gnc-gui-query.h" +#include "gnc-ui-util.h" +#include "gnc-engine-util.h" +#include "window-help.h" + +#include "gncBusiness.h" +#include "gncAddress.h" +#include "gncVendor.h" +#include "gncVendorP.h" + +#include "dialog-vendor.h" +#include "business-chooser.h" + +#define DIALOG_NEW_VENDOR_CM_CLASS "dialog-new-vendor" +#define DIALOG_EDIT_VENDOR_CM_CLASS "dialog-edit-vendor" + +typedef enum +{ + NEW_VENDOR, + EDIT_VENDOR +} VendorDialogType; + +struct _vendor_select_window { + GncBusiness * business; +}; + +typedef struct _vendor_window { + GtkWidget * dialog; + + GtkWidget * id_entry; + GtkWidget * company_entry; + + GtkWidget * name_entry; + GtkWidget * addr1_entry; + GtkWidget * addr2_entry; + GtkWidget * addr3_entry; + GtkWidget * addr4_entry; + GtkWidget * phone_entry; + GtkWidget * fax_entry; + GtkWidget * email_entry; + + GtkWidget * terms_amount; + + GtkWidget * active_check; + GtkWidget * taxincluded_check; + GtkWidget * notes_text; + + VendorDialogType dialog_type; + GUID vendor_guid; + gint component_id; + GncBusiness * business; + GncVendor * created_vendor; + +} VendorWindow; + +static GncVendor * +vw_get_vendor (VendorWindow *vw) +{ + if (!vw) + return NULL; + + return gncBusinessLookupGUID (vw->business, GNC_VENDOR_MODULE_NAME, + &vw->vendor_guid); +} + +static void gnc_ui_to_vendor (VendorWindow *vw, GncVendor *vendor) +{ + GncAddress *addr; + gnc_numeric num; + + addr = gncVendorGetAddr (vendor); + + gnc_suspend_gui_refresh (); + + gncVendorSetID (vendor, gtk_editable_get_chars + (GTK_EDITABLE (vw->id_entry), 0, -1)); + gncVendorSetName (vendor, gtk_editable_get_chars + (GTK_EDITABLE (vw->company_entry), 0, -1)); + + gncAddressSetName (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->name_entry), 0, -1)); + gncAddressSetAddr1 (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->addr1_entry), 0, -1)); + gncAddressSetAddr2 (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->addr2_entry), 0, -1)); + gncAddressSetAddr3 (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->addr3_entry), 0, -1)); + gncAddressSetAddr4 (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->addr4_entry), 0, -1)); + gncAddressSetPhone (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->phone_entry), 0, -1)); + gncAddressSetFax (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->fax_entry), 0, -1)); + gncAddressSetEmail (addr, gtk_editable_get_chars + (GTK_EDITABLE (vw->email_entry), 0, -1)); + + gncVendorSetActive (vendor, gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (vw->active_check))); + gncVendorSetTaxIncluded (vendor, gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON (vw->taxincluded_check))); + gncVendorSetNotes (vendor, gtk_editable_get_chars + (GTK_EDITABLE (vw->notes_text), 0, -1)); + + /* Parse and set the terms, discount, and credit amounts */ + num = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (vw->terms_amount)); + gncVendorSetTerms (vendor, gnc_numeric_num (num)); + + gncVendorCommitEdit (vendor); + gnc_resume_gui_refresh (); +} + +static gboolean check_edit_amount (GtkWidget *dialog, GtkWidget *amount, + gnc_numeric *min, gnc_numeric *max, + const char * error_message) +{ + if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (amount))) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + /* We've got a valid-looking number; check mix/max */ + if (min || max) { + gnc_numeric val = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (amount)); + if ((min && gnc_numeric_compare (*min, val) > 0) || + (max && gnc_numeric_compare (val, *max) > 0)) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + } + return FALSE; +} + +static gboolean check_entry_nonempty (GtkWidget *dialog, GtkWidget *entry, + const char * error_message) +{ + const char *res = gtk_entry_get_text (GTK_ENTRY (entry)); + if (safe_strcmp (res, "") == 0) { + if (error_message) + gnc_error_dialog_parented (GTK_WINDOW (dialog), error_message); + return TRUE; + } + return FALSE; +} + +static void +gnc_vendor_window_ok_cb (GtkWidget *widget, gpointer data) +{ + VendorWindow *vw = data; + char *res; + GncVendor *vendor; + gnc_numeric min, max; + + /* Check for valid id */ + if (check_entry_nonempty (vw->dialog, vw->id_entry, + _("The Vendor must be given an ID."))) + return; + + /* Check for valid company name */ + if (check_entry_nonempty (vw->dialog, vw->company_entry, + _("You must enter a company name."))) + return; + + /* Make sure we have an address */ + if (check_entry_nonempty (vw->dialog, vw->addr1_entry, NULL) && + check_entry_nonempty (vw->dialog, vw->addr2_entry, NULL) && + check_entry_nonempty (vw->dialog, vw->addr3_entry, NULL) && + check_entry_nonempty (vw->dialog, vw->addr4_entry, NULL)) { + const char *msg = _("You must enter a payment address."); + gnc_error_dialog_parented (GTK_WINDOW (vw->dialog), msg); + return; + } + + /* Verify terms are valid (or empty) */ + min = gnc_numeric_zero (); + if (check_edit_amount (vw->dialog, vw->terms_amount, &min, NULL, + _("Terms must be a positive integer or " + "you must leave it blank."))) + return; + + /* Now save it off */ + { + GncVendor *vendor = vw_get_vendor (vw); + if (vendor) { + gnc_ui_to_vendor (vw, vendor); + } + vw->created_vendor = vendor; + vw->vendor_guid = *xaccGUIDNULL (); + } + + gnc_close_gui_component (vw->component_id); +} + +static void +gnc_vendor_window_cancel_cb (GtkWidget *widget, gpointer data) +{ + VendorWindow *vw = data; + + gnc_close_gui_component (vw->component_id); +} + +static void +gnc_vendor_window_help_cb (GtkWidget *widget, gpointer data) +{ + VendorWindow *vw = data; + char *help_file = ""; /* xxx */ + + helpWindow(NULL, NULL, help_file); +} + +static void +gnc_vendor_window_destroy_cb (GtkWidget *widget, gpointer data) +{ + VendorWindow *vw = data; + GncVendor *vendor = vw_get_vendor (vw); + + gnc_suspend_gui_refresh (); + + if (vw->dialog_type == NEW_VENDOR && vendor != NULL) { + gncVendorDestroy (vendor); + vw->vendor_guid = *xaccGUIDNULL (); + } + + gnc_unregister_gui_component (vw->component_id); + gnc_resume_gui_refresh (); + + g_free (vw); +} + +static void +gnc_vendor_name_changed_cb (GtkWidget *widget, gpointer data) +{ + VendorWindow *vw = data; + char *name, *id, *fullname, *title; + + if (!vw) + return; + + name = gtk_entry_get_text (GTK_ENTRY (vw->name_entry)); + if (!name || *name == '\0') + name = _(""); + + id = gtk_entry_get_text (GTK_ENTRY (vw->id_entry)); + + fullname = g_strconcat (name, " (", id, ")", NULL); + + if (vw->dialog_type == EDIT_VENDOR) + title = g_strconcat (_("Edit Vendor"), " - ", fullname, NULL); + else + title = g_strconcat (_("New Vendor"), " - ", fullname, NULL); + + gtk_window_set_title (GTK_WINDOW (vw->dialog), title); + + g_free (fullname); + g_free (title); +} + +static int +gnc_vendor_on_close_cb (GnomeDialog *dialog, gpointer data) +{ + VendorWindow *vw; + GncVendor **created_vendor = data; + + if (data) { + vw = gtk_object_get_data (GTK_OBJECT (dialog), "dialog_info"); + *created_vendor = vw->created_vendor; + } + + gtk_main_quit (); + + return FALSE; +} + +static void +gnc_vendor_window_close_handler (gpointer user_data) +{ + VendorWindow *vw = user_data; + + gnome_dialog_close (GNOME_DIALOG (vw->dialog)); +} + +static void +gnc_vendor_window_refresh_handler (GHashTable *changes, gpointer user_data) +{ + VendorWindow *vw = user_data; + const EventInfo *info; + GncVendor *vendor = vw_get_vendor (vw); + + /* If there isn't a vendor behind us, close down */ + if (!vendor) { + gnc_close_gui_component (vw->component_id); + return; + } + + /* Next, close if this is a destroy event */ + if (changes) { + info = gnc_gui_get_entity_events (changes, &vw->vendor_guid); + if (info && (info->event_mask & GNC_EVENT_DESTROY)) { + gnc_close_gui_component (vw->component_id); + return; + } + } +} + +static VendorWindow * +gnc_vendor_new_window (GtkWidget *parent, GncBusiness *bus, + GncVendor *vendor) +{ + VendorWindow *vw; + GladeXML *xml; + GtkWidget *hbox, *edit; + GnomeDialog *vwd; + gnc_commodity *commodity; + GNCPrintAmountInfo print_info; + + vw = g_new0 (VendorWindow, 1); + + vw->business = bus; + + /* Find the dialog */ + xml = gnc_glade_xml_new ("vendor.glade", "Vendor Dialog"); + vw->dialog = glade_xml_get_widget (xml, "Vendor Dialog"); + vwd = GNOME_DIALOG (vw->dialog); + + gtk_object_set_data (GTK_OBJECT (vw->dialog), "dialog_info", vw); + + /* default to ok */ + gnome_dialog_set_default (vwd, 0); + + if (parent) + gnome_dialog_set_parent (vwd, GTK_WINDOW (parent)); + + /* Get entry points */ + vw->id_entry = glade_xml_get_widget (xml, "id_entry"); + vw->company_entry = glade_xml_get_widget (xml, "company_entry"); + + vw->name_entry = glade_xml_get_widget (xml, "name_entry"); + vw->addr1_entry = glade_xml_get_widget (xml, "addr1_entry"); + vw->addr2_entry = glade_xml_get_widget (xml, "addr2_entry"); + vw->addr3_entry = glade_xml_get_widget (xml, "addr3_entry"); + vw->addr4_entry = glade_xml_get_widget (xml, "addr4_entry"); + vw->phone_entry = glade_xml_get_widget (xml, "phone_entry"); + vw->fax_entry = glade_xml_get_widget (xml, "fax_entry"); + vw->email_entry = glade_xml_get_widget (xml, "email_entry"); + + vw->active_check = glade_xml_get_widget (xml, "active_check"); + vw->taxincluded_check = glade_xml_get_widget (xml, "tax_included_check"); + vw->notes_text = glade_xml_get_widget (xml, "notes_text"); + + /* TERMS: Integer Value */ + edit = gnc_amount_edit_new(); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (edit), TRUE); + print_info = gnc_integral_print_info (); + gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (edit), print_info); + gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (edit), 1); + vw->terms_amount = edit; + gtk_widget_show (edit); + + hbox = glade_xml_get_widget (xml, "terms_box"); + gtk_box_pack_start (GTK_BOX (hbox), edit, TRUE, TRUE, 0); + + /* Setup Dialog for Editing */ + gnome_dialog_set_default (vwd, 0); + + /* Attach to default button */ + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->id_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->company_entry)); + + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->name_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->addr1_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->addr2_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->addr3_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->addr4_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->phone_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->fax_entry)); + gnome_dialog_editable_enters (vwd, GTK_EDITABLE (vw->email_entry)); + + /* Set focus to company name */ + gtk_widget_grab_focus (vw->company_entry); + + /* Setup signals */ + gnome_dialog_button_connect + (vwd, 0, GTK_SIGNAL_FUNC(gnc_vendor_window_ok_cb), vw); + gnome_dialog_button_connect + (vwd, 1, GTK_SIGNAL_FUNC(gnc_vendor_window_cancel_cb), vw); + gnome_dialog_button_connect + (vwd, 2, GTK_SIGNAL_FUNC(gnc_vendor_window_help_cb), vw); + + gtk_signal_connect (GTK_OBJECT (vw->dialog), "destroy", + GTK_SIGNAL_FUNC(gnc_vendor_window_destroy_cb), vw); + + gtk_signal_connect(GTK_OBJECT (vw->id_entry), "changed", + GTK_SIGNAL_FUNC(gnc_vendor_name_changed_cb), vw); + + gtk_signal_connect(GTK_OBJECT (vw->company_entry), "changed", + GTK_SIGNAL_FUNC(gnc_vendor_name_changed_cb), vw); + + /* Setup initial values */ + if (vendor != NULL) { + GncAddress *addr; + const char *string; + gint pos = 0; + + vw->dialog_type = EDIT_VENDOR; + vw->vendor_guid = *gncVendorGetGUID (vendor); + + addr = gncVendorGetAddr (vendor); + + gtk_entry_set_text (GTK_ENTRY (vw->id_entry), gncVendorGetID (vendor)); + gtk_entry_set_editable (GTK_ENTRY (vw->id_entry), FALSE); + + gtk_entry_set_text (GTK_ENTRY (vw->company_entry), gncVendorGetName (vendor)); + + /* Setup Address */ + gtk_entry_set_text (GTK_ENTRY (vw->name_entry), gncAddressGetName (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->addr1_entry), gncAddressGetAddr1 (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->addr2_entry), gncAddressGetAddr2 (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->addr3_entry), gncAddressGetAddr3 (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->addr4_entry), gncAddressGetAddr4 (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->phone_entry), gncAddressGetPhone (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->fax_entry), gncAddressGetFax (addr)); + gtk_entry_set_text (GTK_ENTRY (vw->email_entry), gncAddressGetEmail (addr)); + + /* Set toggle buttons */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vw->active_check), + gncVendorGetActive (vendor)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vw->taxincluded_check), + gncVendorGetTaxIncluded (vendor)); + + string = gncVendorGetNotes (vendor); + gtk_editable_delete_text (GTK_EDITABLE (vw->notes_text), 0, -1); + gtk_editable_insert_text (GTK_EDITABLE (vw->notes_text), string, + strlen(string), &pos); + + vw->component_id = + gnc_register_gui_component (DIALOG_EDIT_VENDOR_CM_CLASS, + gnc_vendor_window_refresh_handler, + gnc_vendor_window_close_handler, + vw); + } else { + gnc_numeric num; + vendor = gncVendorCreate (bus); + vw->vendor_guid = *gncVendorGetGUID (vendor); + + vw->dialog_type = NEW_VENDOR; + gtk_entry_set_text (GTK_ENTRY (vw->id_entry), + g_strdup_printf ("%.6d", gncVendorNextID(bus))); + vw->component_id = + gnc_register_gui_component (DIALOG_NEW_VENDOR_CM_CLASS, + gnc_vendor_window_refresh_handler, + gnc_vendor_window_close_handler, + vw); + } + + + /* I know that vendor exists here -- either passed in or just created */ + { + gnc_numeric terms; + + /* Set the Terms amounts */ + terms = gnc_numeric_create (gncVendorGetTerms (vendor), 1); + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (vw->terms_amount), terms); + } + + gnc_gui_component_watch_entity_type (vw->component_id, + GNC_ID_NONE, + GNC_EVENT_MODIFY | GNC_EVENT_DESTROY); + + gtk_widget_show_all (vw->dialog); + + return vw; +} + +GncVendor * +gnc_vendor_new (GtkWidget *parent, GncBusiness *bus) +{ + VendorWindow *vw; + GncVendor *created_vendor = NULL; + + /* Make sure required options exist */ + if (!bus) return NULL; + + vw = gnc_vendor_new_window (parent, bus, NULL); + + gtk_signal_connect (GTK_OBJECT (vw->dialog), "close", + GTK_SIGNAL_FUNC (gnc_vendor_on_close_cb), + &created_vendor); + + gtk_window_set_modal (GTK_WINDOW (vw->dialog), TRUE); + + gtk_main (); + + return created_vendor; +} + +void +gnc_vendor_edit (GtkWidget *parent, GncVendor *vendor) +{ + VendorWindow *vw; + + if (!vendor) return; + + vw = gnc_vendor_new_window (parent, gncVendorGetBusiness(vendor), vendor); + + gtk_signal_connect (GTK_OBJECT (vw->dialog), "close", + GTK_SIGNAL_FUNC (gnc_vendor_on_close_cb), + NULL); + + gtk_window_set_modal (GTK_WINDOW (vw->dialog), TRUE); + + gtk_main (); + + return; +} + +/* Functions for widgets for vendor selection */ + +static gpointer gnc_vendor_edit_new_cb (gpointer arg, GtkWidget *toplevel) +{ + struct _vendor_select_window *sw = arg; + + if (!arg) return NULL; + + return gnc_vendor_new (toplevel, sw->business); +} + +static void gnc_vendor_edit_edit_cb (gpointer arg, gpointer obj, GtkWidget *toplevel) +{ + GncVendor *vendor = obj; + struct _vendor_select_window *sw = arg; + + if (!arg || !obj) return; + + gnc_vendor_edit (toplevel, vendor); +} + +gpointer gnc_vendor_edit_new_select (gpointer bus, gpointer vendor, + GtkWidget *toplevel) +{ + GncBusiness *business = bus; + struct _vendor_select_window sw; + + g_return_val_if_fail (bus != NULL, NULL); + + sw.business = business; + + return + gnc_ui_business_chooser_new (toplevel, vendor, + business, GNC_VENDOR_MODULE_NAME, + gnc_vendor_edit_new_cb, + gnc_vendor_edit_edit_cb, &sw); +} + +gpointer gnc_vendor_edit_new_edit (gpointer bus, gpointer v, + GtkWidget *toplevel) +{ + GncBusiness *busiess = bus; + GncVendor *vendor = v; + + g_return_val_if_fail (vendor != NULL, NULL); + + gnc_vendor_edit (toplevel, vendor); + return vendor; +} diff --git a/src/business/business-gnome/dialog-vendor.h b/src/business/business-gnome/dialog-vendor.h new file mode 100644 index 0000000000..9c8f331dde --- /dev/null +++ b/src/business/business-gnome/dialog-vendor.h @@ -0,0 +1,27 @@ +/* + * dialog-vendor.h -- Dialog(s) for Vendor search and entry + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + + +#ifndef GNC_DIALOG_VENDOR_H_ +#define GNC_DIALOG_VENDOR_H_ + +/* Functions to create and edit vendors */ +GncVendor * gnc_vendor_new (GtkWidget *parent, GncBusiness *bus); +void gnc_vendor_edit (GtkWidget *parent, GncVendor *vendor); + +/* Callbacks to select a vendor that match the necessary functions + * for use with the gnc_general_select widget. + * + * new_select provides a selection and the ability to create and edit + * vendors. + * new_edit provides only the ability to edit the current selection + */ +gpointer gnc_vendor_edit_new_select (gpointer bus, gpointer c, + GtkWidget *toplevel); +gpointer gnc_vendor_edit_new_edit (gpointer bus, gpointer vendor, + GtkWidget *toplevel); + +#endif /* GNC_DIALOG_VENDOR_H_ */ diff --git a/src/business/business-gnome/employee.glade b/src/business/business-gnome/employee.glade new file mode 100644 index 0000000000..a02a238537 --- /dev/null +++ b/src/business/business-gnome/employee.glade @@ -0,0 +1,797 @@ + + + + + Employee + employee + + src + pixmaps + C + True + True + False + False + False + False + + + + GnomeDialog + Employee Dialog + New Employee + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox1 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button4 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button5 + True + True + GNOME_STOCK_BUTTON_CANCEL + + + + GtkButton + button6 + True + True + GNOME_STOCK_BUTTON_HELP + + + + + GtkNotebook + notebook1 + True + True + True + GTK_POS_TOP + False + 2 + 2 + False + + 0 + True + True + + + + GtkVBox + vbox2 + False + 0 + + + GtkFrame + frame1 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkHBox + hbox2 + 2 + False + 0 + + + GtkVBox + vbox11 + True + 0 + + 0 + False + False + + + + GtkLabel + label1 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label19 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkCheckButton + active_check + True + + True + True + + 0 + False + False + + + + + + GtkVBox + vbox12 + True + 0 + + 0 + True + True + + + + GtkEntry + id_entry + 50 + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + username_entry + 158 + True + True + True + 0 + + + 0 + True + False + + + + + GtkLabel + label26 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + + + GtkFrame + frame2 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + False + + + + GtkHBox + hbox3 + 200 + False + 0 + + + GtkVBox + vbox5 + 3 + True + 0 + + 3 + False + True + + + + GtkLabel + label3 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label4 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label23 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label24 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label25 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label5 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label6 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label7 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + GtkVBox + vbox6 + 3 + True + 0 + + 0 + True + True + + + + GtkEntry + name_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr1_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr2_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr3_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr4_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + phone_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + fax_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + email_entry + True + True + True + 0 + + + 0 + False + False + + + + + + + + GtkFrame + frame4 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox14 + False + 0 + + + GtkHBox + hbox7 + 2 + False + 0 + + 0 + True + True + + + + GtkLabel + label34 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + language_entry + 50 + True + True + True + 0 + + + 0 + False + True + + + + + + + + GtkFrame + frame5 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox15 + 2 + True + 2 + + + GtkHBox + hbox8 + False + 0 + + 0 + True + True + + + + GtkLabel + label35 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkHBox + hours_hbox + False + 0 + + 0 + False + True + + + + Placeholder + + + + + + GtkHBox + hbox9 + False + 0 + + 0 + True + True + + + + GtkLabel + label36 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkHBox + rate_hbox + False + 0 + + 0 + False + True + + + + Placeholder + + + + + + + + + GtkLabel + Notebook:tab + label9 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkVBox + vbox13 + False + 0 + + + GtkFrame + frame3 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox16 + False + 0 + + + Placeholder + + + + + + + GtkLabel + Notebook:tab + label33 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + + diff --git a/src/business/business-gnome/gnc-business-utils.c b/src/business/business-gnome/gnc-business-utils.c new file mode 100644 index 0000000000..47d8506629 --- /dev/null +++ b/src/business/business-gnome/gnc-business-utils.c @@ -0,0 +1,19 @@ +/* + * gnc-business-utils.c -- Utilities for the Business UI + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#include "config.h" + +#include + +#include "dialog-utils.h" +#include "gnc-ui.h" + +#include "gncBusiness.h" +#include "gncCustomer.h" +#include "gncJob.h" + +#include "gnc-business-utils.h" + diff --git a/src/business/business-gnome/gnc-business-utils.h b/src/business/business-gnome/gnc-business-utils.h new file mode 100644 index 0000000000..ffd6ace480 --- /dev/null +++ b/src/business/business-gnome/gnc-business-utils.h @@ -0,0 +1,11 @@ +/* + * gnc-business-utils.h -- Utilities for the Business UI + * Copyright (C) 2001 Derek Atkins + * Author: Derek Atkins + */ + +#ifndef GNC_BUSINESS_UTILS_H_ +#define GNC_BUSINESS_UTILS_H_ + + +#endif /* GNC_BUSINESS_UTILS_H_ */ diff --git a/src/business/business-gnome/gw-business-gnome-spec.scm b/src/business/business-gnome/gw-business-gnome-spec.scm new file mode 100644 index 0000000000..9ead85b563 --- /dev/null +++ b/src/business/business-gnome/gw-business-gnome-spec.scm @@ -0,0 +1,183 @@ +;;; -*-scheme-*- +(use-modules (g-wrap)) + +(debug-set! maxdepth 100000) +(debug-set! stack 2000000) + +(define-module (g-wrapped gw-business-gnome-spec) + :use-module (g-wrap)) + +(use-modules (g-wrapped gw-business-core-spec)) +(use-modules (g-wrapped gw-gnc-spec)) + +(let ((mod (gw:new-module "gw-business-gnome"))) + (define (standard-c-call-gen result func-call-code) + (list (gw:result-get-c-name result) " = " func-call-code ";\n")) + + (define (add-standard-result-handlers! type c->scm-converter) + (define (standard-pre-handler result) + (let* ((ret-type-name (gw:result-get-proper-c-type-name result)) + (ret-var-name (gw:result-get-c-name result))) + (list "{\n" + " " ret-type-name " " ret-var-name ";\n"))) + + (gw:type-set-pre-call-result-ccodegen! type standard-pre-handler) + + (gw:type-set-post-call-result-ccodegen! + type + (lambda (result) + (let* ((scm-name (gw:result-get-scm-name result)) + (c-name (gw:result-get-c-name result))) + (list + (c->scm-converter scm-name c-name) + " }\n"))))) + + (gw:module-depends-on mod "gw-runtime") + (gw:module-depends-on mod "gw-business-core") + (gw:module-depends-on mod "gw-gnc") + + (gw:module-set-guile-module! mod '(g-wrapped gw-business-gnome)) + + (gw:module-set-declarations-ccodegen! + mod + (lambda (client-only?) + (list + "#include \n" + "#include \n" + "#include \n" + "#include \n" + "#include \n" + ))) + + (gw:module-set-init-ccodegen! + mod + (lambda (client-only?) + (if client-only? + '() + (gw:inline-scheme '(use-modules (gnucash business-gnome)))))) + + ;; + ;; dialog-customer.h + ;; + + (gw:wrap-function + mod + 'gnc:customer-new + ' + "gnc_customer_new" + '(( parent) ( business)) + "Dialog: create a new GncCustomer. Parent may be NULL.") + + (gw:wrap-function + mod + 'gnc:customer-edit + ' + "gnc_customer_edit" + '(( parent) ( customer)) + "Dialog: Edit a GncCustomer. Parent may be NULL.") + + + (gw:wrap-function + mod + 'gnc:customer-select + ' + "gnc_customer_edit_new_select" + '(( business) ( start_selection) + ( parent)) + "Dialog: Select a GncCustomer. Parent and start_selection may be NULL.") + + ;; + ;; dialog-employee.h + ;; + + (gw:wrap-function + mod + 'gnc:employee-new + ' + "gnc_employee_new" + '(( parent) ( business)) + "Dialog: create a new GncEmployee. Parent may be NULL.") + + (gw:wrap-function + mod + 'gnc:employee-edit + ' + "gnc_employee_edit" + '(( parent) ( employee)) + "Dialog: Edit a GncEmployee. Parent may be NULL.") + + + (gw:wrap-function + mod + 'gnc:employee-select + ' + "gnc_employee_edit_new_select" + '(( business) ( start_selection) + ( parent)) + "Dialog: Select a GncEmployee. Parent and start_selection may be NULL.") + + ;; + ;; dialog-job.h + ;; + + (gw:wrap-function + mod + 'gnc:job-new + ' + "gnc_job_new" + '(( parent) ( business_state) + ( default_customer)) + "Dialog: create a new GncJob. Parent and Customer may be NULL.") + + (gw:wrap-function + mod + 'gnc:job-edit + ' + "gnc_job_edit" + '(( parent) ( job)) + "Dialog: Edit a GncJob. Parent may be NULL.") + + ;; + ;; dialog-job-select.h + ;; + + (gw:wrap-function + mod + 'gnc:job-select + ' + "gnc_ui_select_job_new" + '(( parent) ( business) + ( cust) ( job)) + "Dialog: Select a new job. Parent and Customer may be NULL.") + + ;; + ;; dialog-vendor.h + ;; + + (gw:wrap-function + mod + 'gnc:vendor-new + ' + "gnc_vendor_new" + '(( parent) ( business)) + "Dialog: create a new GncVendor. Parent may be NULL.") + + (gw:wrap-function + mod + 'gnc:vendor-edit + ' + "gnc_vendor_edit" + '(( parent) ( vendor)) + "Dialog: Edit a GncVendor. Parent may be NULL.") + + + (gw:wrap-function + mod + 'gnc:vendor-select + ' + "gnc_vendor_edit_new_select" + '(( business) ( start_selection) + ( parent)) + "Dialog: Select a GncVendor. Parent and start_selection may be NULL.") + +) diff --git a/src/business/business-gnome/job.glade b/src/business/business-gnome/job.glade new file mode 100644 index 0000000000..b843c064fc --- /dev/null +++ b/src/business/business-gnome/job.glade @@ -0,0 +1,715 @@ + + + + + Job + job + + src + pixmaps + C + True + True + False + False + False + False + + + + GnomeDialog + Job Dialog + Job Dialog + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox2 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area2 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button8 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button9 + True + True + GNOME_STOCK_BUTTON_CANCEL + + + + GtkButton + button10 + True + True + GNOME_STOCK_BUTTON_HELP + + + + + GtkVBox + vbox1 + False + 0 + + 0 + True + True + + + + GtkFrame + frame1 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox4 + 3 + True + 0 + + + GtkHBox + hbox1 + False + 0 + + 0 + True + True + + + + GtkLabel + label1 + 75 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + id_entry + 50 + True + True + True + 0 + + + 0 + False + True + + + + + + GtkHBox + hbox2 + False + 0 + + 0 + True + True + + + + GtkLabel + label2 + 75 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkHBox + customer_hbox + False + 0 + + 0 + True + True + + + + Placeholder + + + + + + + + GtkFrame + frame2 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkVBox + vbox5 + 3 + True + 0 + + + GtkHBox + hbox3 + False + 0 + + 0 + True + True + + + + GtkLabel + label3 + 100 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + name_entry + True + True + True + 0 + + + 0 + True + True + + + + + + GtkHBox + hbox4 + False + 0 + + 0 + True + True + + + + GtkLabel + label4 + 100 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkEntry + desc_entry + True + True + True + 0 + + + 0 + True + True + + + + + + + + GtkFrame + frame3 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkCheckButton + active_check + True + + True + True + + + + + + + + GnomeDialog + Job Selector Dialog + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox3 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area3 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button14 + True + True + + clicked + gnc_ui_select_job_ok_cb + Job_Selector_Dialog + Sun, 11 Nov 2001 03:08:59 GMT + + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button18 + True + True + + clicked + gnc_ui_select_job_new_cb + Job_Selector_Dialog + Sun, 11 Nov 2001 03:09:14 GMT + + + + + + GtkButton + button20 + True + True + + clicked + gnc_ui_select_job_edit_cb + Job_Selector_Dialog + Tue, 13 Nov 2001 22:24:22 GMT + + + + + + GtkButton + button21 + True + True + + clicked + gnc_ui_select_job_cancel_cb + Job_Selector_Dialog + Tue, 13 Nov 2001 22:24:33 GMT + + GNOME_STOCK_BUTTON_CANCEL + + + + + GtkVBox + vbox11 + False + 0 + + 0 + True + True + + + + GtkHBox + hbox7 + True + 0 + + 0 + True + True + + + + GtkTable + table2 + 2 + 2 + False + 0 + 0 + + 0 + False + False + + + + GtkLabel + label6 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 0 + 0 + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + False + + + + + GtkLabel + label5 + + GTK_JUSTIFY_CENTER + False + 1 + 0.5 + 0 + 0 + + 0 + 1 + 0 + 1 + 0 + 0 + False + False + False + False + True + False + + + + + GtkCombo + customer_combo + True + False + False + True + False + + + 1 + 2 + 0 + 1 + 0 + 0 + False + False + False + False + False + False + + + + GtkEntry + GtkCombo:entry + customer_entry + True + + changed + gnc_ui_select_job_customer_changed_cb + Commodity_Selector_Dialog + Tue, 13 Nov 2001 22:25:09 GMT + + False + True + 0 + + + + + + GtkCombo + job_combo + True + False + False + True + False + + + 1 + 2 + 1 + 2 + 0 + 0 + False + False + False + False + False + False + + + + GtkEntry + GtkCombo:entry + job_entry + True + False + True + 0 + + + + + + + + + GtkVBox + vbox10 + False + 0 + + 0 + True + True + + + + GtkHBox + hbox6 + True + 0 + + 0 + True + True + + + + GtkTable + table1 + 2 + 1 + False + 0 + 0 + + 0 + False + False + + + + GtkCheckButton + showcust_check + True + + toggled + gnc_ui_select_job_showcust_toggled_cb + Job_Selector_Dialog + Sun, 11 Nov 2001 04:48:09 GMT + + + False + True + + 0 + 1 + 0 + 1 + 0 + 0 + False + False + False + False + True + False + + + + + GtkCheckButton + showjobs_check + True + + toggled + gnc_ui_select_job_showjobs_toggled_cb + Job_Selector_Dialog + Sun, 11 Nov 2001 03:19:10 GMT + + + False + True + + 0 + 1 + 1 + 2 + 0 + 0 + False + False + False + False + True + False + + + + + + + + + diff --git a/src/business/business-gnome/vendor.glade b/src/business/business-gnome/vendor.glade new file mode 100644 index 0000000000..cf42ac3953 --- /dev/null +++ b/src/business/business-gnome/vendor.glade @@ -0,0 +1,741 @@ + + + + + Vendor + vendor + + src + pixmaps + C + True + True + False + False + False + False + + + + GnomeDialog + Vendor Dialog + New Vendor + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox1 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button4 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button5 + True + True + GNOME_STOCK_BUTTON_CANCEL + + + + GtkButton + button6 + True + True + GNOME_STOCK_BUTTON_HELP + + + + + GtkNotebook + notebook1 + True + True + True + GTK_POS_TOP + False + 2 + 2 + False + + 0 + True + True + + + + GtkVBox + vbox2 + False + 0 + + + GtkFrame + frame1 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkHBox + hbox2 + 2 + False + 0 + + + GtkVBox + vbox11 + True + 0 + + 0 + False + False + + + + GtkLabel + label1 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label19 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkCheckButton + active_check + True + + True + True + + 0 + False + False + + + + + + GtkVBox + vbox12 + True + 0 + + 0 + True + True + + + + GtkEntry + id_entry + 50 + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + company_entry + 158 + True + True + True + 0 + + + 0 + True + False + + + + + GtkLabel + label26 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + + + GtkFrame + frame2 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + False + + + + GtkHBox + hbox3 + 200 + False + 0 + + + GtkVBox + vbox5 + 3 + True + 0 + + 3 + False + True + + + + GtkLabel + label3 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label4 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label23 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label24 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label25 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label5 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label6 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label7 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + GtkVBox + vbox6 + 3 + True + 0 + + 0 + True + True + + + + GtkEntry + name_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr1_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr2_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr3_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + addr4_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + phone_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + fax_entry + True + True + True + 0 + + + 0 + False + False + + + + + GtkEntry + email_entry + True + True + True + 0 + + + 0 + False + False + + + + + + + + GtkFrame + frame4 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + True + True + + + + GtkScrolledWindow + scrolledwindow1 + 3 + GTK_POLICY_NEVER + GTK_POLICY_ALWAYS + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS + + + GtkText + notes_text + 15 + True + True + + + + + + + + GtkLabel + Notebook:tab + label9 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + GtkVBox + vbox13 + False + 0 + + + GtkFrame + frame3 + 3 + + 0 + GTK_SHADOW_ETCHED_IN + + 0 + False + True + + + + GtkHBox + hbox6 + False + 0 + + + GtkVBox + vbox7 + True + 0 + + 0 + False + False + + + + GtkLabel + label8 + + GTK_JUSTIFY_RIGHT + False + 1 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkCheckButton + tax_included_check + 3 + True + + False + True + + 0 + False + False + + + + + + GtkVBox + vbox13 + 3 + True + 0 + + 0 + True + True + + + + GtkHBox + terms_box + False + 0 + + 0 + True + True + + + + Placeholder + + + + + GtkLabel + label32 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + + + Placeholder + + + + + GtkLabel + Notebook:tab + label33 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + + + + + diff --git a/src/gnc-module/Makefile.am b/src/gnc-module/Makefile.am index 7800299c93..deac94ba38 100644 --- a/src/gnc-module/Makefile.am +++ b/src/gnc-module/Makefile.am @@ -9,16 +9,16 @@ libgncmodule_la_SOURCES = gnc-module.c libgncmodule_la_LDFLAGS = -module libgncmodule_la_LIBADD = \ ${G_WRAP_LINK_ARGS} \ - ${GLIB_LIBS} \ ${GUILE_LIBS} \ + ${GLIB_LIBS} \ -lltdl libgw_gnc_module_la_SOURCES = gw-gnc-module.c libgw_gnc_module_la_LDFLAGS = -module libgw_gnc_module_la_LIBADD = libgncmodule.la \ ${G_WRAP_LINK_ARGS} \ - ${GLIB_LIBS} \ - ${GUILE_LIBS} + ${GUILE_LIBS} \ + ${GLIB_LIBS} gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash gncmod_DATA = gnc-module.scm diff --git a/src/gnome-utils/Makefile.am b/src/gnome-utils/Makefile.am index d23887aba7..5c7d744ebd 100644 --- a/src/gnome-utils/Makefile.am +++ b/src/gnome-utils/Makefile.am @@ -78,6 +78,7 @@ libgncmod_gnome_utils_la_LIBADD = \ ${top_srcdir}/src/calculation/libgncmod-calculation.la \ ${top_srcdir}/src/network-utils/libgncmod-network-utils.la \ ${top_srcdir}/src/app-utils/libgncmod-app-utils.la \ + ${GUILE_LIBS} \ ${GUPPI_LIBS} \ ${GNOMEUI_LIBS} \ ${GNOME_LIBDIR} \ diff --git a/src/gnome-utils/dialog-options.c b/src/gnome-utils/dialog-options.c index 8192e89ea9..198435a2ea 100644 --- a/src/gnome-utils/dialog-options.c +++ b/src/gnome-utils/dialog-options.c @@ -1458,8 +1458,10 @@ gnc_option_set_ui_widget(GNCOption *option, g_free(colon_name); enclosing = gtk_hbox_new(FALSE, 5); - value = gnc_general_select_new(gnc_commodity_edit_get_string, - gnc_commodity_edit_new_select); + value = gnc_general_select_new(GNC_GENERAL_SELECT_TYPE_SELECT, + gnc_commodity_edit_get_string, + gnc_commodity_edit_new_select, + NULL); gnc_option_set_widget (option, value); gnc_option_set_ui_value(option, FALSE); diff --git a/src/gnome-utils/gnc-commodity-edit.c b/src/gnome-utils/gnc-commodity-edit.c index 2f153f89b7..8df28b3519 100644 --- a/src/gnome-utils/gnc-commodity-edit.c +++ b/src/gnome-utils/gnc-commodity-edit.c @@ -44,9 +44,11 @@ const char * gnc_commodity_edit_get_string (gpointer ptr) return gnc_commodity_get_printname(comm); } -gpointer gnc_commodity_edit_new_select (gpointer ptr, GtkWidget *toplevel) +gpointer gnc_commodity_edit_new_select (gpointer arg, gpointer ptr, + GtkWidget *toplevel) { gnc_commodity * comm = (gnc_commodity *)ptr; + arg; return gnc_ui_select_commodity_modal(comm, toplevel); } diff --git a/src/gnome-utils/gnc-commodity-edit.h b/src/gnome-utils/gnc-commodity-edit.h index 477f86601a..2b4a33f0b1 100644 --- a/src/gnome-utils/gnc-commodity-edit.h +++ b/src/gnome-utils/gnc-commodity-edit.h @@ -38,8 +38,13 @@ /* Callback function to return the printable string of a commodity */ const char * gnc_commodity_edit_get_string (gpointer ptr); -/* Callback function to popup a new selection (modal) dialog */ -gpointer gnc_commodity_edit_new_select (gpointer ptr, GtkWidget *toplevel); +/* Callback function to popup a new selection (modal) dialog. + * + * NOTE: The argument here is ignored, so you can safely set the + * cb_arg to NULL when you create the general_select widget + */ +gpointer gnc_commodity_edit_new_select (gpointer arg, gpointer ptr, + GtkWidget *toplevel); #endif diff --git a/src/gnome-utils/gnc-general-select.c b/src/gnome-utils/gnc-general-select.c index c2798f4d34..4972ede509 100644 --- a/src/gnome-utils/gnc-general-select.c +++ b/src/gnome-utils/gnc-general-select.c @@ -163,7 +163,8 @@ select_cb(GtkButton * button, gpointer user_data) toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button)); - new_selection = (gsl->new_select)(gsl->selected_item, toplevel); + new_selection = (gsl->new_select)(gsl->cb_arg, gsl->selected_item, + toplevel); /* NULL return means cancel; no change */ if (new_selection == NULL) @@ -173,14 +174,18 @@ select_cb(GtkButton * button, gpointer user_data) } static void -create_children (GNCGeneralSelect *gsl) +create_children (GNCGeneralSelect *gsl, GNCGeneralSelectType type) { gsl->entry = gtk_entry_new (); gtk_entry_set_editable (GTK_ENTRY (gsl->entry), FALSE); gtk_box_pack_start (GTK_BOX (gsl), gsl->entry, TRUE, TRUE, 0); gtk_widget_show (gsl->entry); - gsl->button = gtk_button_new_with_label (_("Select...")); + if (type == GNC_GENERAL_SELECT_TYPE_SELECT) + gsl->button = gtk_button_new_with_label (_("Select...")); + else if (type == GNC_GENERAL_SELECT_TYPE_EDIT) + gsl->button = gtk_button_new_with_label (_("Edit...")); + gtk_box_pack_start (GTK_BOX (gsl), gsl->button, FALSE, FALSE, 0); gtk_signal_connect (GTK_OBJECT (gsl->button), "clicked", select_cb, gsl); @@ -196,8 +201,10 @@ create_children (GNCGeneralSelect *gsl) * Returns a GNCGeneralSelect widget. */ GtkWidget * -gnc_general_select_new (GNCGeneralSelectGetStringCB get_string, - GNCGeneralSelectNewSelectCB new_select) +gnc_general_select_new (GNCGeneralSelectType type, + GNCGeneralSelectGetStringCB get_string, + GNCGeneralSelectNewSelectCB new_select, + gpointer cb_arg) { GNCGeneralSelect *gsl; g_return_val_if_fail (get_string != NULL, NULL); @@ -205,9 +212,10 @@ gnc_general_select_new (GNCGeneralSelectGetStringCB get_string, gsl = gtk_type_new (gnc_general_select_get_type ()); - create_children (gsl); + create_children (gsl, type); gsl->get_string = get_string; gsl->new_select = new_select; + gsl->cb_arg = cb_arg; return GTK_WIDGET (gsl); } diff --git a/src/gnome-utils/gnc-general-select.h b/src/gnome-utils/gnc-general-select.h index 0ecf3cec49..2868ec9e0d 100644 --- a/src/gnome-utils/gnc-general-select.h +++ b/src/gnome-utils/gnc-general-select.h @@ -40,6 +40,14 @@ BEGIN_GNOME_DECLS #define GNC_GENERAL_SELECT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_general_select_get_type(), GNCGeneralSelectClass) #define GNC_IS_GENERAL_SELECT(obj) GTK_CHECK_TYPE (obj, gnc_general_select_get_type ()) +typedef const char * (*GNCGeneralSelectGetStringCB) (gpointer); +typedef gpointer (*GNCGeneralSelectNewSelectCB) (gpointer cbarg, gpointer default_selection, GtkWidget *parent); + +typedef enum { + GNC_GENERAL_SELECT_TYPE_SELECT = 1, + GNC_GENERAL_SELECT_TYPE_EDIT = 2 +} GNCGeneralSelectType; + typedef struct { GtkHBox hbox; @@ -48,8 +56,9 @@ typedef struct { gpointer selected_item; - const char * (*get_string) (gpointer ptr); - gpointer (*new_select) (gpointer ptr, GtkWidget *toplevel); + GNCGeneralSelectGetStringCB get_string; + GNCGeneralSelectNewSelectCB new_select; + gpointer cb_arg; } GNCGeneralSelect; typedef struct { @@ -58,11 +67,11 @@ typedef struct { void (*changed) (GNCGeneralSelect *edit); } GNCGeneralSelectClass; -typedef const char * (*GNCGeneralSelectGetStringCB) (gpointer); -typedef gpointer (*GNCGeneralSelectNewSelectCB) (gpointer, GtkWidget *); -GtkWidget *gnc_general_select_new (GNCGeneralSelectGetStringCB get_string, - GNCGeneralSelectNewSelectCB new_select); +GtkWidget *gnc_general_select_new (GNCGeneralSelectType type, + GNCGeneralSelectGetStringCB get_string, + GNCGeneralSelectNewSelectCB new_select, + gpointer cb_arg); void gnc_general_select_set_selected (GNCGeneralSelect *gsl, gpointer selected); gpointer gnc_general_select_get_selected (GNCGeneralSelect *gsl); diff --git a/src/gnome/dialog-price-editor.c b/src/gnome/dialog-price-editor.c index 5ebd62b214..42970cc665 100644 --- a/src/gnome/dialog-price-editor.c +++ b/src/gnome/dialog-price-editor.c @@ -800,8 +800,10 @@ gnc_price_dialog_create (PricesDialog *pdb_dialog) box = glade_xml_get_widget (xml, "commodity_box"); - w = gnc_general_select_new (gnc_commodity_edit_get_string, - gnc_commodity_edit_new_select); + w = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT, + gnc_commodity_edit_get_string, + gnc_commodity_edit_new_select, + NULL); pdb_dialog->commodity_edit = w; gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0); gtk_widget_show (w); diff --git a/src/gnome/druid-hierarchy.c b/src/gnome/druid-hierarchy.c index 65f189d694..978163564e 100644 --- a/src/gnome/druid-hierarchy.c +++ b/src/gnome/druid-hierarchy.c @@ -107,8 +107,10 @@ get_commodity_editor(void) GNCGeneralSelect *cur_editor; cur_editor = - GNC_GENERAL_SELECT (gnc_general_select_new(gnc_commodity_edit_get_string, - gnc_commodity_edit_new_select)); + GNC_GENERAL_SELECT (gnc_general_select_new(GNC_GENERAL_SELECT_TYPE_SELECT, + gnc_commodity_edit_get_string, + gnc_commodity_edit_new_select, + NULL)); gtk_widget_show (GTK_WIDGET(cur_editor)); gnc_general_select_set_selected (cur_editor, gnc_locale_default_currency()); diff --git a/src/import-export/binary-import/Makefile.am b/src/import-export/binary-import/Makefile.am index bac658b3c8..da425505be 100644 --- a/src/import-export/binary-import/Makefile.am +++ b/src/import-export/binary-import/Makefile.am @@ -37,9 +37,9 @@ libgncmod_binary_import_la_LIBADD = \ ${top_srcdir}/src/app-utils/libgncmod-app-utils.la \ ${top_srcdir}/src/app-file/libgncmod-app-file.la \ ${top_srcdir}/src/gnome-utils/libgncmod-gnome-utils.la \ + ${GUILE_LIBS} \ ${GNOMEUI_LIBS} \ ${GNOME_LIBDIR} \ - ${GUILE_LIBS} \ ${GLIB_LIBS} libgw_binary_import_la_SOURCES = gw-binary-import.c diff --git a/src/import-export/qif-import/Makefile.am b/src/import-export/qif-import/Makefile.am index 58566081ec..4dcb78aac1 100644 --- a/src/import-export/qif-import/Makefile.am +++ b/src/import-export/qif-import/Makefile.am @@ -18,10 +18,11 @@ libgncmod_qif_import_la_LIBADD = \ ${top_srcdir}/src/app-file/libgncmod-app-file.la \ ${top_srcdir}/src/gnc-module/libgncmodule.la \ ${top_srcdir}/src/engine/libgncmod-engine.la \ + ${GUILE_LIBS} \ ${GNOME_LIBS} \ ${GLADE_LIBS} \ - ${GLIB_LIBS} \ - ${GUILE_LIBS} + ${GLIB_LIBS} + gncscmmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash/import-export gncscmmod_DATA = qif-import.scm diff --git a/src/report/report-system/Makefile.am b/src/report/report-system/Makefile.am index 02176789af..b7897d9207 100644 --- a/src/report/report-system/Makefile.am +++ b/src/report/report-system/Makefile.am @@ -13,8 +13,8 @@ gncinclude_HEADERS = \ libgncmod_report_system_la_LDFLAGS = -module libgncmod_report_system_la_LIBADD = \ ${top_srcdir}/src/gnc-module/libgncmodule.la \ - ${GLIB_LIBS} \ - ${GUILE_LIBS} + ${GUILE_LIBS} \ + ${GLIB_LIBS} AM_CFLAGS = -I${top_srcdir}/src/gnc-module ${GLIB_CFLAGS} ${GUILE_INCS} diff --git a/src/scm/extensions.scm b/src/scm/extensions.scm index c2a459fadc..bb3542ced5 100644 --- a/src/scm/extensions.scm +++ b/src/scm/extensions.scm @@ -54,11 +54,77 @@ (define (gnc:make-separator path) (gnc:make-extension 'separator #f #f path #f)) +(gnc:module-load "gnucash/business-gnome" 0) + +(define gnc:extensions-temp-business #f) + +(define (gnc:extensions-get-business) + (if gnc:extensions-temp-business + gnc:extensions-temp-business + (begin + (set! gnc:extensions-temp-business (gnc:business-create + (gnc:get-current-session))) + gnc:extensions-temp-business))) (define (gnc:extensions-menu-setup) (define menu (gnc:make-menu "Extensions" (list "_Settings"))) + + (define new-job-item + (gnc:make-menu-item (N_ "Test New Job Dialog") + (N_ "Test New Job Dialog") + (list "Extensions" "") + (lambda () + (gnc:job-new #f (gnc:extensions-get-business) + #f)))) + + (define select-job-item + (gnc:make-menu-item (N_ "Test Job Selection Dialog") + (N_ "Test Job Selection Dialog") + (list "Extensions" "") + (lambda () + (gnc:job-select #f (gnc:extensions-get-business) + #f #f)))) + + (define new-vendor-item + (gnc:make-menu-item (N_ "Test New Vendor Dialog") + (N_ "Test New Vendor Dialog") + (list "Extensions" "") + (lambda () + (gnc:vendor-new #f (gnc:extensions-get-business))))) + + + (define select-vendor-item + (gnc:make-menu-item (N_ "Test Vendor Selection Dialog") + (N_ "Test Vendor Selection Dialog") + (list "Extensions" "") + (lambda () + (gnc:vendor-select (gnc:extensions-get-business) + #f #f)))) + + (define new-employee-item + (gnc:make-menu-item (N_ "Test New Employee Dialog") + (N_ "Test New Employee Dialog") + (list "Extensions" "") + (lambda () + (gnc:employee-new #f (gnc:extensions-get-business))))) + + + (define select-employee-item + (gnc:make-menu-item (N_ "Test Employee Selection Dialog") + (N_ "Test Employee Selection Dialog") + (list "Extensions" "") + (lambda () + (gnc:employee-select (gnc:extensions-get-business) + #f #f)))) + (gnc:add-extension menu) + (gnc:add-extension select-employee-item) + (gnc:add-extension new-employee-item) + (gnc:add-extension select-vendor-item) + (gnc:add-extension new-vendor-item) + (gnc:add-extension select-job-item) + (gnc:add-extension new-job-item) ) (if (gnc:debugging?) diff --git a/src/tax/us/Makefile.am b/src/tax/us/Makefile.am index c3912b780f..ad7e5d9259 100644 --- a/src/tax/us/Makefile.am +++ b/src/tax/us/Makefile.am @@ -7,8 +7,8 @@ libgncmod_tax_us_la_SOURCES = \ libgncmod_tax_us_la_LDFLAGS = -module libgncmod_tax_us_la_LIBADD = \ - ${GLIB_LIBS} \ - ${GUILE_LIBS} + ${GUILE_LIBS} \ + ${GLIB_LIBS} AM_CFLAGS = -I${top_srcdir}/src/gnc-module ${GLIB_CFLAGS} ${GUILE_INCS}